Updated RecastDemo to SDL2
* Renamed a bunch of variables in main.cpp to be more descriptive. * Removed unnecessary SDLMain.h and SDLMain.m OSX objective-c class as well as the plist, strings, xib and icns files, which are not needed. * included cstdio in imguiRenderGL since SDL2 doesn't do it for us. * Updated premake5 script to support SDL2 and to set the debug directory, as well as copy the SDL2.dll to the target directory on Windows. * Updated readme with more descriptive, platform-specific demo project setup instructions * Updated appveyor build script to build vs2015 as well. * Updated Travis build script to build SDL2 from source, because they use Ubuntu 12.04 which doesn't have the libsdl2-dev package in its repositories.
This commit is contained in:
parent
43a20cce42
commit
2eb3abfb60
18
.travis.yml
18
.travis.yml
@ -2,12 +2,6 @@ sudo: false
|
||||
|
||||
language: cpp
|
||||
|
||||
# Install SDL 1.2 development libraries.
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libsdl1.2-dev
|
||||
|
||||
# Build with gcc and clang.
|
||||
compiler:
|
||||
- gcc
|
||||
@ -20,6 +14,18 @@ env:
|
||||
- CONFIGURATION=release
|
||||
|
||||
install:
|
||||
# Download and build SDL2 from source.
|
||||
- mkdir dummyprefix
|
||||
- export PREFIX=$PWD/dummyprefix
|
||||
- export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
|
||||
- export PATH=$PATH:$PWD/dummyprefix/bin
|
||||
- wget https://www.libsdl.org/release/SDL2-2.0.4.tar.gz -O SDL2.tar.gz
|
||||
- tar -xzf SDL2.tar.gz
|
||||
- cd SDL2-2.0.4
|
||||
- ./configure --prefix=$PREFIX
|
||||
- make -j5
|
||||
- make install
|
||||
- cd ..
|
||||
# Download and build premake5 from source; the Travis environment doesn't have the right version of glibc6 for the prebuilt binaries to work.
|
||||
- wget https://github.com/premake/premake-core/releases/download/v5.0.0-alpha6/premake-5.0.0-alpha6-src.zip -O premake.zip
|
||||
- unzip premake.zip
|
||||
|
27
README.md
27
README.md
@ -40,28 +40,39 @@ You can find a comprehensive demo project in RecastDemo folder. It is a kitchen
|
||||
|
||||
### Building RecastDemo
|
||||
|
||||
RecastDemo uses [premake5](http://premake.github.io/) to build platform specific projects. Download it and make sure it's available on your path, or specify the path to it. To build *RecastDemo*, in your favorite terminal navigate into the `RecastDemo` folder, then:
|
||||
RecastDemo uses [premake5](http://premake.github.io/) to build platform specific projects. Download it and make sure it's available on your path, or specify the path to it.
|
||||
|
||||
- *OS X*: `premake5 xcode4`
|
||||
- *Windows*: `"premake5" vs2015`
|
||||
- *Linux*: `premake5 gmake`
|
||||
#### Linux
|
||||
|
||||
See premake5 documentation for full list of supported build file types. The projects will be created in `RecastDemo/Build` folder. And after you have compiled the project, the *RecastDemo* executable will be located in `RecastDemo/Bin` folder.
|
||||
- Install SDl2 and its dependencies according to your distro's guidelines.
|
||||
- run `premake5 gmake` from the `RecastDemo` folder.
|
||||
- `cd Build/gmake` then `make`
|
||||
- Run `RecastDemo\Bin\RecastDemo`
|
||||
|
||||
*Note:* On Windows, please use x86 version of the SDL.dll to run the demo Application.
|
||||
#### OSX
|
||||
|
||||
- Grab the latest SDL2 development library dmg from [here](https://www.libsdl.org/download-2.0.php) and place `SDL2.framework` in `/Library/Frameworks/`
|
||||
- Navigate to the `RecastDemo` folder and run `premake5 xcode4`
|
||||
- Open `Build/xcode4/recastnavigation.xcworkspace`
|
||||
- Select the "RecastDemo" project in the left pane, go to the "BuildPhases" tab and expand "Link Binary With Libraries"
|
||||
- Remove the existing entry for SDL2 (it should have a white box icon) and re-add it by hitting the plus, selecting "Add Other", and selecting `/Library/Frameworks/SDL2.framework`. It should now have a suitcase icon.
|
||||
- Set the RecastDemo project as the target and build.
|
||||
|
||||
#### Windows
|
||||
|
||||
- Grab the latest SDL2 development library release from [here](https://www.libsdl.org/download-2.0.php) and unzip it `RecastDemo\Contrib`. Rename the SDL folder such that the path `RecastDemo\Contrib\SDL\lib\x86` is valid.
|
||||
- Run `"premake5" vs2015` from the `RecastDemo` folder
|
||||
- Open the solution, build, and run.
|
||||
|
||||
## Integrating with your own project
|
||||
|
||||
It is recommended to add the source directories `DebugUtils`, `Detour`, `DetourCrowd`, `DetourTileCache`, and `Recast` into your own project depending on which parts of the project you need. For example your level building tool could include DebugUtils, Recast, and Detour, and your game runtime could just include Detour.
|
||||
|
||||
|
||||
## Discuss
|
||||
|
||||
- Discuss Recast & Detour: http://groups.google.com/group/recastnavigation
|
||||
- Development blog: http://digestingduck.blogspot.com/
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Recast & Detour is licensed under ZLib license, see License.txt for more information.
|
||||
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -1,11 +0,0 @@
|
||||
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
|
||||
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
|
||||
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
|
||||
|
||||
Feel free to customize this file to suit your needs
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface SDLMain : NSObject
|
||||
@end
|
@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>Icon.icns</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.yourcompany.${PRODUCT_NAME:identifier}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>MainMenu</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
@ -23,6 +23,11 @@
|
||||
#include <float.h>
|
||||
#include "SDL.h"
|
||||
#include "SDL_opengl.h"
|
||||
#ifdef __APPLE__
|
||||
# include <OpenGL/glu.h>
|
||||
#else
|
||||
# include <GL/glu.h>
|
||||
#endif
|
||||
#include "imgui.h"
|
||||
#include "CrowdTool.h"
|
||||
#include "InputGeom.h"
|
||||
@ -38,7 +43,6 @@
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
|
||||
static bool isectSegAABB(const float* sp, const float* sq,
|
||||
const float* amin, const float* amax,
|
||||
float& tmin, float& tmax)
|
||||
|
@ -23,6 +23,11 @@
|
||||
#include <string.h>
|
||||
#include "SDL.h"
|
||||
#include "SDL_opengl.h"
|
||||
#ifdef __APPLE__
|
||||
# include <OpenGL/glu.h>
|
||||
#else
|
||||
# include <GL/glu.h>
|
||||
#endif
|
||||
#include "imgui.h"
|
||||
#include "NavMeshTesterTool.h"
|
||||
#include "Sample.h"
|
||||
|
@ -23,6 +23,11 @@
|
||||
#include <float.h>
|
||||
#include "SDL.h"
|
||||
#include "SDL_opengl.h"
|
||||
#ifdef __APPLE__
|
||||
# include <OpenGL/glu.h>
|
||||
#else
|
||||
# include <GL/glu.h>
|
||||
#endif
|
||||
#include "imgui.h"
|
||||
#include "OffMeshConnectionTool.h"
|
||||
#include "InputGeom.h"
|
||||
|
@ -1,384 +0,0 @@
|
||||
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
|
||||
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
|
||||
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
|
||||
|
||||
Feel free to customize this file to suit your needs
|
||||
*/
|
||||
|
||||
#import "SDL.h"
|
||||
#import "SDLMain.h"
|
||||
#import <sys/param.h> /* for MAXPATHLEN */
|
||||
#import <unistd.h>
|
||||
|
||||
/* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
|
||||
but the method still is there and works. To avoid warnings, we declare
|
||||
it ourselves here. */
|
||||
@interface NSApplication(SDL_Missing_Methods)
|
||||
- (void)setAppleMenu:(NSMenu *)menu;
|
||||
@end
|
||||
|
||||
/* Use this flag to determine whether we use SDLMain.nib or not */
|
||||
#define SDL_USE_NIB_FILE 0
|
||||
|
||||
/* Use this flag to determine whether we use CPS (docking) or not */
|
||||
#define SDL_USE_CPS 1
|
||||
#ifdef SDL_USE_CPS
|
||||
/* Portions of CPS.h */
|
||||
typedef struct CPSProcessSerNum
|
||||
{
|
||||
UInt32 lo;
|
||||
UInt32 hi;
|
||||
} CPSProcessSerNum;
|
||||
|
||||
extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
|
||||
extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
|
||||
extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
|
||||
|
||||
#endif /* SDL_USE_CPS */
|
||||
|
||||
static int gArgc;
|
||||
static char **gArgv;
|
||||
static BOOL gFinderLaunch;
|
||||
static BOOL gCalledAppMainline = FALSE;
|
||||
|
||||
static NSString *getApplicationName(void)
|
||||
{
|
||||
NSDictionary *dict;
|
||||
NSString *appName = 0;
|
||||
|
||||
/* Determine the application name */
|
||||
dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
|
||||
if (dict)
|
||||
appName = [dict objectForKey: @"CFBundleName"];
|
||||
|
||||
if (![appName length])
|
||||
appName = [[NSProcessInfo processInfo] processName];
|
||||
|
||||
return appName;
|
||||
}
|
||||
|
||||
#if SDL_USE_NIB_FILE
|
||||
/* A helper category for NSString */
|
||||
@interface NSString (ReplaceSubString)
|
||||
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
|
||||
@end
|
||||
#endif
|
||||
|
||||
@interface SDLApplication : NSApplication
|
||||
@end
|
||||
|
||||
@implementation SDLApplication
|
||||
/* Invoked from the Quit menu item */
|
||||
- (void)terminate:(id)sender
|
||||
{
|
||||
/* Post a SDL_QUIT event */
|
||||
SDL_Event event;
|
||||
event.type = SDL_QUIT;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
@end
|
||||
|
||||
/* The main class of the application, the application's delegate */
|
||||
@implementation SDLMain
|
||||
|
||||
/* Set the working directory to the .app's parent directory */
|
||||
- (void) setupWorkingDirectory:(BOOL)shouldChdir
|
||||
{
|
||||
if (shouldChdir)
|
||||
{
|
||||
char parentdir[MAXPATHLEN];
|
||||
CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
|
||||
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
|
||||
if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) {
|
||||
assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
|
||||
}
|
||||
CFRelease(url);
|
||||
CFRelease(url2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if SDL_USE_NIB_FILE
|
||||
|
||||
/* Fix menu to contain the real app name instead of "SDL App" */
|
||||
- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
|
||||
{
|
||||
NSRange aRange;
|
||||
NSEnumerator *enumerator;
|
||||
NSMenuItem *menuItem;
|
||||
|
||||
aRange = [[aMenu title] rangeOfString:@"SDL App"];
|
||||
if (aRange.length != 0)
|
||||
[aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
|
||||
|
||||
enumerator = [[aMenu itemArray] objectEnumerator];
|
||||
while ((menuItem = [enumerator nextObject]))
|
||||
{
|
||||
aRange = [[menuItem title] rangeOfString:@"SDL App"];
|
||||
if (aRange.length != 0)
|
||||
[menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
|
||||
if ([menuItem hasSubmenu])
|
||||
[self fixMenu:[menuItem submenu] withAppName:appName];
|
||||
}
|
||||
[ aMenu sizeToFit ];
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void setApplicationMenu(void)
|
||||
{
|
||||
/* warning: this code is very odd */
|
||||
NSMenu *appleMenu;
|
||||
NSMenuItem *menuItem;
|
||||
NSString *title;
|
||||
NSString *appName;
|
||||
|
||||
appName = getApplicationName();
|
||||
appleMenu = [[NSMenu alloc] initWithTitle:@""];
|
||||
|
||||
/* Add menu items */
|
||||
title = [@"About " stringByAppendingString:appName];
|
||||
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
|
||||
|
||||
[appleMenu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
title = [@"Hide " stringByAppendingString:appName];
|
||||
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
|
||||
|
||||
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
|
||||
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
|
||||
|
||||
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
|
||||
|
||||
[appleMenu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
title = [@"Quit " stringByAppendingString:appName];
|
||||
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
|
||||
|
||||
|
||||
/* Put menu into the menubar */
|
||||
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
|
||||
[menuItem setSubmenu:appleMenu];
|
||||
[[NSApp mainMenu] addItem:menuItem];
|
||||
|
||||
/* Tell the application object that this is now the application menu */
|
||||
[NSApp setAppleMenu:appleMenu];
|
||||
|
||||
/* Finally give up our references to the objects */
|
||||
[appleMenu release];
|
||||
[menuItem release];
|
||||
}
|
||||
|
||||
/* Create a window menu */
|
||||
static void setupWindowMenu(void)
|
||||
{
|
||||
NSMenu *windowMenu;
|
||||
NSMenuItem *windowMenuItem;
|
||||
NSMenuItem *menuItem;
|
||||
|
||||
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
|
||||
|
||||
/* "Minimize" item */
|
||||
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
|
||||
[windowMenu addItem:menuItem];
|
||||
[menuItem release];
|
||||
|
||||
/* Put menu into the menubar */
|
||||
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
|
||||
[windowMenuItem setSubmenu:windowMenu];
|
||||
[[NSApp mainMenu] addItem:windowMenuItem];
|
||||
|
||||
/* Tell the application object that this is now the window menu */
|
||||
[NSApp setWindowsMenu:windowMenu];
|
||||
|
||||
/* Finally give up our references to the objects */
|
||||
[windowMenu release];
|
||||
[windowMenuItem release];
|
||||
}
|
||||
|
||||
/* Replacement for NSApplicationMain */
|
||||
static void CustomApplicationMain (int argc, char **argv)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
SDLMain *sdlMain;
|
||||
|
||||
/* Ensure the application object is initialised */
|
||||
[SDLApplication sharedApplication];
|
||||
|
||||
#ifdef SDL_USE_CPS
|
||||
{
|
||||
CPSProcessSerNum PSN;
|
||||
/* Tell the dock about us */
|
||||
if (!CPSGetCurrentProcess(&PSN))
|
||||
if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
|
||||
if (!CPSSetFrontProcess(&PSN))
|
||||
[SDLApplication sharedApplication];
|
||||
}
|
||||
#endif /* SDL_USE_CPS */
|
||||
|
||||
/* Set up the menubar */
|
||||
[NSApp setMainMenu:[[NSMenu alloc] init]];
|
||||
setApplicationMenu();
|
||||
setupWindowMenu();
|
||||
|
||||
/* Create SDLMain and make it the app delegate */
|
||||
sdlMain = [[SDLMain alloc] init];
|
||||
[NSApp setDelegate:sdlMain];
|
||||
|
||||
/* Start the main event loop */
|
||||
[NSApp run];
|
||||
|
||||
[sdlMain release];
|
||||
[pool release];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Catch document open requests...this lets us notice files when the app
|
||||
* was launched by double-clicking a document, or when a document was
|
||||
* dragged/dropped on the app's icon. You need to have a
|
||||
* CFBundleDocumentsType section in your Info.plist to get this message,
|
||||
* apparently.
|
||||
*
|
||||
* Files are added to gArgv, so to the app, they'll look like command line
|
||||
* arguments. Previously, apps launched from the finder had nothing but
|
||||
* an argv[0].
|
||||
*
|
||||
* This message may be received multiple times to open several docs on launch.
|
||||
*
|
||||
* This message is ignored once the app's mainline has been called.
|
||||
*/
|
||||
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
||||
{
|
||||
const char *temparg;
|
||||
size_t arglen;
|
||||
char *arg;
|
||||
char **newargv;
|
||||
|
||||
if (!gFinderLaunch) /* MacOS is passing command line args. */
|
||||
return FALSE;
|
||||
|
||||
if (gCalledAppMainline) /* app has started, ignore this document. */
|
||||
return FALSE;
|
||||
|
||||
temparg = [filename UTF8String];
|
||||
arglen = SDL_strlen(temparg) + 1;
|
||||
arg = (char *) SDL_malloc(arglen);
|
||||
if (arg == NULL)
|
||||
return FALSE;
|
||||
|
||||
newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
|
||||
if (newargv == NULL)
|
||||
{
|
||||
SDL_free(arg);
|
||||
return FALSE;
|
||||
}
|
||||
gArgv = newargv;
|
||||
|
||||
SDL_strlcpy(arg, temparg, arglen);
|
||||
gArgv[gArgc++] = arg;
|
||||
gArgv[gArgc] = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* Called when the internal event loop has just started running */
|
||||
- (void) applicationDidFinishLaunching: (NSNotification *) note
|
||||
{
|
||||
int status;
|
||||
|
||||
/* Set the working directory to the .app's parent directory */
|
||||
[self setupWorkingDirectory:gFinderLaunch];
|
||||
|
||||
#if SDL_USE_NIB_FILE
|
||||
/* Set the main menu to contain the real app name instead of "SDL App" */
|
||||
[self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
|
||||
#endif
|
||||
|
||||
/* Hand off to main application code */
|
||||
gCalledAppMainline = TRUE;
|
||||
status = SDL_main (gArgc, gArgv);
|
||||
|
||||
/* We're done, thank you for playing */
|
||||
exit(status);
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSString (ReplaceSubString)
|
||||
|
||||
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
|
||||
{
|
||||
unsigned int bufferSize;
|
||||
unsigned int selfLen = [self length];
|
||||
unsigned int aStringLen = [aString length];
|
||||
unichar *buffer;
|
||||
NSRange localRange;
|
||||
NSString *result;
|
||||
|
||||
bufferSize = selfLen + aStringLen - aRange.length;
|
||||
buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
|
||||
|
||||
/* Get first part into buffer */
|
||||
localRange.location = 0;
|
||||
localRange.length = aRange.location;
|
||||
[self getCharacters:buffer range:localRange];
|
||||
|
||||
/* Get middle part into buffer */
|
||||
localRange.location = 0;
|
||||
localRange.length = aStringLen;
|
||||
[aString getCharacters:(buffer+aRange.location) range:localRange];
|
||||
|
||||
/* Get last part into buffer */
|
||||
localRange.location = aRange.location + aRange.length;
|
||||
localRange.length = selfLen - localRange.location;
|
||||
[self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
|
||||
|
||||
/* Build output string */
|
||||
result = [NSString stringWithCharacters:buffer length:bufferSize];
|
||||
|
||||
NSDeallocateMemoryPages(buffer, bufferSize);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
#ifdef main
|
||||
# undef main
|
||||
#endif
|
||||
|
||||
|
||||
/* Main entry point to executable - should *not* be SDL_main! */
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* Copy the arguments into a global variable */
|
||||
/* This is passed if we are launched by double-clicking */
|
||||
if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
|
||||
gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
|
||||
gArgv[0] = argv[0];
|
||||
gArgv[1] = NULL;
|
||||
gArgc = 1;
|
||||
gFinderLaunch = YES;
|
||||
} else {
|
||||
int i;
|
||||
gArgc = argc;
|
||||
gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
|
||||
for (i = 0; i <= argc; i++)
|
||||
gArgv[i] = argv[i];
|
||||
gFinderLaunch = NO;
|
||||
}
|
||||
|
||||
#if SDL_USE_NIB_FILE
|
||||
[SDLApplication poseAsClass:[NSApplication class]];
|
||||
NSApplicationMain (argc, argv);
|
||||
#else
|
||||
CustomApplicationMain (argc, argv);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
@ -24,6 +24,11 @@
|
||||
#include <new>
|
||||
#include "SDL.h"
|
||||
#include "SDL_opengl.h"
|
||||
#ifdef __APPLE__
|
||||
# include <OpenGL/glu.h>
|
||||
#else
|
||||
# include <GL/glu.h>
|
||||
#endif
|
||||
#include "imgui.h"
|
||||
#include "InputGeom.h"
|
||||
#include "Sample.h"
|
||||
@ -1508,4 +1513,4 @@ void Sample_TempObstacles::loadAll(const char* path)
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,11 @@
|
||||
#include <string.h>
|
||||
#include "SDL.h"
|
||||
#include "SDL_opengl.h"
|
||||
#ifdef __APPLE__
|
||||
# include <OpenGL/glu.h>
|
||||
#else
|
||||
# include <GL/glu.h>
|
||||
#endif
|
||||
#include "imgui.h"
|
||||
#include "InputGeom.h"
|
||||
#include "Sample.h"
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "SlideShow.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <SDL_opengl.h>
|
||||
#include "SDL_opengl.h"
|
||||
//#define STBI_HEADER_FILE_ONLY
|
||||
#include "stb_image.h"
|
||||
|
||||
|
@ -26,6 +26,11 @@
|
||||
#include "DetourCommon.h"
|
||||
#include "SDL.h"
|
||||
#include "SDL_opengl.h"
|
||||
#ifdef __APPLE__
|
||||
# include <OpenGL/glu.h>
|
||||
#else
|
||||
# include <GL/glu.h>
|
||||
#endif
|
||||
#include "imgui.h"
|
||||
#include "PerfTimer.h"
|
||||
|
||||
|
@ -17,7 +17,8 @@
|
||||
//
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include "imgui.h"
|
||||
#include "SDL.h"
|
||||
#include "SDL_opengl.h"
|
||||
|
@ -16,20 +16,27 @@
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <cstdio>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_opengl.h"
|
||||
#ifdef __APPLE__
|
||||
# include <OpenGL/glu.h>
|
||||
#else
|
||||
# include <GL/glu.h>
|
||||
#endif
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imguiRenderGL.h"
|
||||
|
||||
#include "Recast.h"
|
||||
#include "RecastDebugDraw.h"
|
||||
#include "InputGeom.h"
|
||||
#include "TestCase.h"
|
||||
#include "Filelist.h"
|
||||
#include "SlideShow.h"
|
||||
|
||||
#include "Sample_SoloMesh.h"
|
||||
#include "Sample_TileMesh.h"
|
||||
#include "Sample_TempObstacles.h"
|
||||
@ -45,12 +52,10 @@ struct SampleItem
|
||||
Sample* (*create)();
|
||||
const char* name;
|
||||
};
|
||||
|
||||
Sample* createSolo() { return new Sample_SoloMesh(); }
|
||||
Sample* createTile() { return new Sample_TileMesh(); }
|
||||
Sample* createTempObstacle() { return new Sample_TempObstacles(); }
|
||||
Sample* createDebug() { return new Sample_Debug(); }
|
||||
|
||||
static SampleItem g_samples[] =
|
||||
{
|
||||
{ createSolo, "Solo Mesh" },
|
||||
@ -58,65 +63,65 @@ static SampleItem g_samples[] =
|
||||
{ createTempObstacle, "Temp Obstacles" },
|
||||
// { createDebug, "Debug" },
|
||||
};
|
||||
static const int g_nsamples = sizeof(g_samples)/sizeof(SampleItem);
|
||||
|
||||
static const int g_nsamples = sizeof(g_samples) / sizeof(SampleItem);
|
||||
|
||||
int main(int /*argc*/, char** /*argv*/)
|
||||
{
|
||||
// Init SDL
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
|
||||
{
|
||||
printf("Could not initialise SDL\n");
|
||||
printf("Could not initialise SDL.\nError: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Center window
|
||||
char env[] = "SDL_VIDEO_CENTERED=1";
|
||||
putenv(env);
|
||||
|
||||
// Init OpenGL
|
||||
// Enable depth buffer.
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||
|
||||
// Set color channel depth.
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
|
||||
//#ifndef WIN32
|
||||
|
||||
// 4x MSAA.
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
|
||||
//#endif
|
||||
|
||||
const SDL_VideoInfo* vi = SDL_GetVideoInfo();
|
||||
SDL_DisplayMode displayMode;
|
||||
SDL_GetCurrentDisplayMode(0, &displayMode);
|
||||
|
||||
bool presentationMode = false;
|
||||
|
||||
int width, height;
|
||||
SDL_Surface* screen = 0;
|
||||
|
||||
Uint32 flags = SDL_WINDOW_OPENGL;
|
||||
int width;
|
||||
int height;
|
||||
if (presentationMode)
|
||||
{
|
||||
width = vi->current_w;
|
||||
height = vi->current_h;
|
||||
screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL|SDL_FULLSCREEN);
|
||||
// Create a fullscreen window at the native resolution.
|
||||
width = displayMode.w;
|
||||
height = displayMode.h;
|
||||
flags |= SDL_WINDOW_FULLSCREEN;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = rcMin(vi->current_w, (int)(vi->current_h * 16.0 / 9.0));
|
||||
width = width - 80;
|
||||
height = vi->current_h - 80;
|
||||
screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL);
|
||||
{
|
||||
float aspect = 16.0f / 9.0f;
|
||||
width = rcMin(displayMode.w, (int)(displayMode.h * aspect)) - 80;
|
||||
height = displayMode.h - 80;
|
||||
}
|
||||
|
||||
if (!screen)
|
||||
SDL_Window* window;
|
||||
SDL_Renderer* renderer;
|
||||
int errorCode = SDL_CreateWindowAndRenderer(width, height, flags, &window, &renderer);
|
||||
|
||||
if (errorCode != 0 || !window || !renderer)
|
||||
{
|
||||
printf("Could not initialise SDL opengl\n");
|
||||
printf("Could not initialise SDL opengl\nError: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
SDL_GL_CreateContext(window);
|
||||
|
||||
SDL_WM_SetCaption("Recast Demo", 0);
|
||||
|
||||
if (!imguiRenderGLInit("DroidSans.ttf"))
|
||||
{
|
||||
printf("Could not init GUI renderer.\n");
|
||||
@ -126,19 +131,24 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
|
||||
float t = 0.0f;
|
||||
float timeAcc = 0.0f;
|
||||
Uint32 lastTime = SDL_GetTicks();
|
||||
int mx = 0, my = 0;
|
||||
float rx = 45;
|
||||
float ry = -45;
|
||||
Uint32 prevFrameTime = SDL_GetTicks();
|
||||
int mousePos[2] = {0, 0};
|
||||
float origMousePos[2] = {0, 0}; // Used to compute mouse movement totals across frames.
|
||||
|
||||
float cameraEulers[] = {45, -45};
|
||||
float cameraPos[] = {0, 0, 0};
|
||||
float camr = 1000;
|
||||
float origCameraEulers[] = {0, 0}; // Used to compute rotational changes across frames.
|
||||
|
||||
float moveW = 0, moveS = 0, moveA = 0, moveD = 0;
|
||||
float camx = 0, camy = 0, camz = 0, camr = 1000;
|
||||
float origrx = 0, origry = 0;
|
||||
int origx = 0, origy = 0;
|
||||
|
||||
float scrollZoom = 0;
|
||||
bool rotate = false;
|
||||
bool movedDuringRotate = false;
|
||||
float rays[3], raye[3];
|
||||
float rayStart[3];
|
||||
float rayEnd[3];
|
||||
bool mouseOverMenu = false;
|
||||
|
||||
bool showMenu = !presentationMode;
|
||||
bool showLog = false;
|
||||
bool showTools = true;
|
||||
@ -146,6 +156,7 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
bool showSample = false;
|
||||
bool showTestCases = false;
|
||||
|
||||
// Window scroll positions.
|
||||
int propScroll = 0;
|
||||
int logScroll = 0;
|
||||
int toolsScroll = 0;
|
||||
@ -155,8 +166,8 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
FileList files;
|
||||
char meshName[128] = "Choose Mesh...";
|
||||
|
||||
float mpos[3] = {0,0,0};
|
||||
bool mposSet = false;
|
||||
float markerPosition[3] = {0, 0, 0};
|
||||
bool markerPositionSet = false;
|
||||
|
||||
SlideShow slideShow;
|
||||
slideShow.init("slides/");
|
||||
@ -167,22 +178,22 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
|
||||
BuildContext ctx;
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
float fogCol[4] = { 0.32f, 0.31f, 0.30f, 1.0f };
|
||||
// Fog.
|
||||
float fogColor[4] = { 0.32f, 0.31f, 0.30f, 1.0f };
|
||||
glEnable(GL_FOG);
|
||||
glFogi(GL_FOG_MODE, GL_LINEAR);
|
||||
glFogf(GL_FOG_START, camr*0.1f);
|
||||
glFogf(GL_FOG_END, camr*1.25f);
|
||||
glFogfv(GL_FOG_COLOR, fogCol);
|
||||
glFogf(GL_FOG_START, camr * 0.1f);
|
||||
glFogf(GL_FOG_END, camr * 1.25f);
|
||||
glFogfv(GL_FOG_COLOR, fogColor);
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
bool done = false;
|
||||
while(!done)
|
||||
{
|
||||
// Handle input events.
|
||||
int mscroll = 0;
|
||||
int mouseScroll = 0;
|
||||
bool processHitTest = false;
|
||||
bool processHitTestShift = false;
|
||||
SDL_Event event;
|
||||
@ -258,18 +269,18 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
// Reset camera and fog to match the mesh bounds.
|
||||
if (bmin && bmax)
|
||||
{
|
||||
camr = sqrtf(rcSqr(bmax[0]-bmin[0]) +
|
||||
rcSqr(bmax[1]-bmin[1]) +
|
||||
rcSqr(bmax[2]-bmin[2])) / 2;
|
||||
camx = (bmax[0] + bmin[0]) / 2 + camr;
|
||||
camy = (bmax[1] + bmin[1]) / 2 + camr;
|
||||
camz = (bmax[2] + bmin[2]) / 2 + camr;
|
||||
camr = sqrtf(rcSqr(bmax[0] - bmin[0]) +
|
||||
rcSqr(bmax[1] - bmin[1]) +
|
||||
rcSqr(bmax[2] - bmin[2])) / 2;
|
||||
cameraPos[0] = (bmax[0] + bmin[0]) / 2 + camr;
|
||||
cameraPos[1] = (bmax[1] + bmin[1]) / 2 + camr;
|
||||
cameraPos[2] = (bmax[2] + bmin[2]) / 2 + camr;
|
||||
camr *= 3;
|
||||
}
|
||||
rx = 45;
|
||||
ry = -45;
|
||||
glFogf(GL_FOG_START, camr*0.2f);
|
||||
glFogf(GL_FOG_END, camr*1.25f);
|
||||
cameraEulers[0] = 45;
|
||||
cameraEulers[1] = -45;
|
||||
glFogf(GL_FOG_START, camr * 0.2f);
|
||||
glFogf(GL_FOG_END, camr * 1.25f);
|
||||
}
|
||||
}
|
||||
else if (event.key.keysym.sym == SDLK_RIGHT)
|
||||
@ -281,7 +292,32 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
slideShow.prevSlide();
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case SDL_MOUSEWHEEL:
|
||||
if (event.wheel.y < 0)
|
||||
{
|
||||
// wheel down
|
||||
if (mouseOverMenu)
|
||||
{
|
||||
mouseScroll++;
|
||||
}
|
||||
else
|
||||
{
|
||||
scrollZoom += 1.0f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mouseOverMenu)
|
||||
{
|
||||
mouseScroll--;
|
||||
}
|
||||
else
|
||||
{
|
||||
scrollZoom -= 1.0f;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if (event.button.button == SDL_BUTTON_RIGHT)
|
||||
{
|
||||
@ -290,25 +326,11 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
// Rotate view
|
||||
rotate = true;
|
||||
movedDuringRotate = false;
|
||||
origx = mx;
|
||||
origy = my;
|
||||
origrx = rx;
|
||||
origry = ry;
|
||||
origMousePos[0] = mousePos[0];
|
||||
origMousePos[1] = mousePos[1];
|
||||
origCameraEulers[0] = cameraEulers[0];
|
||||
origCameraEulers[1] = cameraEulers[1];
|
||||
}
|
||||
}
|
||||
else if (event.button.button == SDL_BUTTON_WHEELUP)
|
||||
{
|
||||
if (mouseOverMenu)
|
||||
mscroll--;
|
||||
else
|
||||
scrollZoom -= 1.0f;
|
||||
}
|
||||
else if (event.button.button == SDL_BUTTON_WHEELDOWN)
|
||||
{
|
||||
if (mouseOverMenu)
|
||||
mscroll++;
|
||||
else
|
||||
scrollZoom += 1.0f;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -338,16 +360,19 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
mx = event.motion.x;
|
||||
my = height-1 - event.motion.y;
|
||||
mousePos[0] = event.motion.x;
|
||||
mousePos[1] = height-1 - event.motion.y;
|
||||
|
||||
if (rotate)
|
||||
{
|
||||
int dx = mx - origx;
|
||||
int dy = my - origy;
|
||||
rx = origrx - dy*0.25f;
|
||||
ry = origry + dx*0.25f;
|
||||
if (dx*dx+dy*dy > 3*3)
|
||||
int dx = mousePos[0] - origMousePos[0];
|
||||
int dy = mousePos[1] - origMousePos[1];
|
||||
cameraEulers[0] = origCameraEulers[0] - dy * 0.25f;
|
||||
cameraEulers[1] = origCameraEulers[1] + dx * 0.25f;
|
||||
if (dx * dx + dy * dy > 3 * 3)
|
||||
{
|
||||
movedDuringRotate = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@ -360,42 +385,41 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char mbut = 0;
|
||||
if (SDL_GetMouseState(0,0) & SDL_BUTTON_LMASK)
|
||||
mbut |= IMGUI_MBUT_LEFT;
|
||||
if (SDL_GetMouseState(0,0) & SDL_BUTTON_RMASK)
|
||||
mbut |= IMGUI_MBUT_RIGHT;
|
||||
unsigned char mouseButtonMask = 0;
|
||||
if (SDL_GetMouseState(0, 0) & SDL_BUTTON_LMASK)
|
||||
mouseButtonMask |= IMGUI_MBUT_LEFT;
|
||||
if (SDL_GetMouseState(0, 0) & SDL_BUTTON_RMASK)
|
||||
mouseButtonMask |= IMGUI_MBUT_RIGHT;
|
||||
|
||||
Uint32 time = SDL_GetTicks();
|
||||
float dt = (time - lastTime) / 1000.0f;
|
||||
lastTime = time;
|
||||
Uint32 time = SDL_GetTicks();
|
||||
float dt = (time - prevFrameTime) / 1000.0f;
|
||||
prevFrameTime = time;
|
||||
|
||||
t += dt;
|
||||
|
||||
|
||||
// Hit test mesh.
|
||||
if (processHitTest && geom && sample)
|
||||
{
|
||||
float hitt;
|
||||
bool hit = geom->raycastMesh(rays, raye, hitt);
|
||||
float hitTime;
|
||||
bool hit = geom->raycastMesh(rayStart, rayEnd, hitTime);
|
||||
|
||||
if (hit)
|
||||
{
|
||||
if (SDL_GetModState() & KMOD_CTRL)
|
||||
{
|
||||
// Marker
|
||||
mposSet = true;
|
||||
mpos[0] = rays[0] + (raye[0] - rays[0])*hitt;
|
||||
mpos[1] = rays[1] + (raye[1] - rays[1])*hitt;
|
||||
mpos[2] = rays[2] + (raye[2] - rays[2])*hitt;
|
||||
markerPositionSet = true;
|
||||
markerPosition[0] = rayStart[0] + (rayEnd[0] - rayStart[0]) * hitTime;
|
||||
markerPosition[1] = rayStart[1] + (rayEnd[1] - rayStart[1]) * hitTime;
|
||||
markerPosition[2] = rayStart[2] + (rayEnd[2] - rayStart[2]) * hitTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
float pos[3];
|
||||
pos[0] = rays[0] + (raye[0] - rays[0])*hitt;
|
||||
pos[1] = rays[1] + (raye[1] - rays[1])*hitt;
|
||||
pos[2] = rays[2] + (raye[2] - rays[2])*hitt;
|
||||
sample->handleClick(rays, pos, processHitTestShift);
|
||||
pos[0] = rayStart[0] + (rayEnd[0] - rayStart[0]) * hitTime;
|
||||
pos[1] = rayStart[1] + (rayEnd[1] - rayStart[1]) * hitTime;
|
||||
pos[2] = rayStart[2] + (rayEnd[2] - rayStart[2]) * hitTime;
|
||||
sample->handleClick(rayStart, pos, processHitTestShift);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -403,94 +427,99 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
if (SDL_GetModState() & KMOD_CTRL)
|
||||
{
|
||||
// Marker
|
||||
mposSet = false;
|
||||
markerPositionSet = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update sample simulation.
|
||||
const float SIM_RATE = 20;
|
||||
const float DELTA_TIME = 1.0f/SIM_RATE;
|
||||
timeAcc = rcClamp(timeAcc+dt, -1.0f, 1.0f);
|
||||
const float DELTA_TIME = 1.0f / SIM_RATE;
|
||||
timeAcc = rcClamp(timeAcc + dt, -1.0f, 1.0f);
|
||||
int simIter = 0;
|
||||
while (timeAcc > DELTA_TIME)
|
||||
{
|
||||
timeAcc -= DELTA_TIME;
|
||||
if (simIter < 5)
|
||||
if (simIter < 5 && sample)
|
||||
{
|
||||
if (sample)
|
||||
sample->handleUpdate(DELTA_TIME);
|
||||
sample->handleUpdate(DELTA_TIME);
|
||||
}
|
||||
simIter++;
|
||||
}
|
||||
|
||||
// Clamp the framerate so that we do not hog all the CPU.
|
||||
const float MIN_FRAME_TIME = 1.0f/40.0f;
|
||||
const float MIN_FRAME_TIME = 1.0f / 40.0f;
|
||||
if (dt < MIN_FRAME_TIME)
|
||||
{
|
||||
int ms = (int)((MIN_FRAME_TIME - dt)*1000.0f);
|
||||
int ms = (int)((MIN_FRAME_TIME - dt) * 1000.0f);
|
||||
if (ms > 10) ms = 10;
|
||||
if (ms >= 0)
|
||||
SDL_Delay(ms);
|
||||
if (ms >= 0) SDL_Delay(ms);
|
||||
}
|
||||
|
||||
|
||||
// Update and render
|
||||
// Set the viewport.
|
||||
glViewport(0, 0, width, height);
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
|
||||
// Clear the screen
|
||||
glClearColor(0.3f, 0.3f, 0.32f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
// Render 3d
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// Compute the projection matrix.
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(50.0f, (float)width/(float)height, 1.0f, camr);
|
||||
GLdouble projectionMatrix[16];
|
||||
glGetDoublev(GL_PROJECTION_MATRIX, projectionMatrix);
|
||||
|
||||
// Compute the modelview matrix.
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glRotatef(rx,1,0,0);
|
||||
glRotatef(ry,0,1,0);
|
||||
glTranslatef(-camx, -camy, -camz);
|
||||
glRotatef(cameraEulers[0], 1, 0, 0);
|
||||
glRotatef(cameraEulers[1], 0, 1, 0);
|
||||
glTranslatef(-cameraPos[0], -cameraPos[1], -cameraPos[2]);
|
||||
GLdouble modelviewMatrix[16];
|
||||
glGetDoublev(GL_MODELVIEW_MATRIX, modelviewMatrix);
|
||||
|
||||
// Get hit ray position and direction.
|
||||
GLdouble proj[16];
|
||||
GLdouble model[16];
|
||||
GLint view[4];
|
||||
glGetDoublev(GL_PROJECTION_MATRIX, proj);
|
||||
glGetDoublev(GL_MODELVIEW_MATRIX, model);
|
||||
glGetIntegerv(GL_VIEWPORT, view);
|
||||
GLdouble x, y, z;
|
||||
gluUnProject(mx, my, 0.0f, model, proj, view, &x, &y, &z);
|
||||
rays[0] = (float)x; rays[1] = (float)y; rays[2] = (float)z;
|
||||
gluUnProject(mx, my, 1.0f, model, proj, view, &x, &y, &z);
|
||||
raye[0] = (float)x; raye[1] = (float)y; raye[2] = (float)z;
|
||||
gluUnProject(mousePos[0], mousePos[1], 0.0f, modelviewMatrix, projectionMatrix, viewport, &x, &y, &z);
|
||||
rayStart[0] = (float)x;
|
||||
rayStart[1] = (float)y;
|
||||
rayStart[2] = (float)z;
|
||||
gluUnProject(mousePos[0], mousePos[1], 1.0f, modelviewMatrix, projectionMatrix, viewport, &x, &y, &z);
|
||||
rayEnd[0] = (float)x;
|
||||
rayEnd[1] = (float)y;
|
||||
rayEnd[2] = (float)z;
|
||||
|
||||
// Handle keyboard movement.
|
||||
Uint8* keystate = SDL_GetKeyState(NULL);
|
||||
moveW = rcClamp(moveW + dt * 4 * (keystate[SDLK_w] ? 1 : -1), 0.0f, 1.0f);
|
||||
moveS = rcClamp(moveS + dt * 4 * (keystate[SDLK_s] ? 1 : -1), 0.0f, 1.0f);
|
||||
moveA = rcClamp(moveA + dt * 4 * (keystate[SDLK_a] ? 1 : -1), 0.0f, 1.0f);
|
||||
moveD = rcClamp(moveD + dt * 4 * (keystate[SDLK_d] ? 1 : -1), 0.0f, 1.0f);
|
||||
const Uint8* keystate = SDL_GetKeyboardState(NULL);
|
||||
moveW = rcClamp(moveW + dt * 4 * (keystate[SDL_SCANCODE_W] ? 1 : -1), 0.0f, 1.0f);
|
||||
moveA = rcClamp(moveA + dt * 4 * (keystate[SDL_SCANCODE_A] ? 1 : -1), 0.0f, 1.0f);
|
||||
moveS = rcClamp(moveS + dt * 4 * (keystate[SDL_SCANCODE_S] ? 1 : -1), 0.0f, 1.0f);
|
||||
moveD = rcClamp(moveD + dt * 4 * (keystate[SDL_SCANCODE_D] ? 1 : -1), 0.0f, 1.0f);
|
||||
|
||||
float keybSpeed = 22.0f;
|
||||
if (SDL_GetModState() & KMOD_SHIFT)
|
||||
{
|
||||
keybSpeed *= 4.0f;
|
||||
}
|
||||
|
||||
float movex = (moveD - moveA) * keybSpeed * dt;
|
||||
float movey = (moveS - moveW) * keybSpeed * dt;
|
||||
|
||||
movey += scrollZoom * 2.0f;
|
||||
float movey = (moveS - moveW) * keybSpeed * dt + scrollZoom * 2.0f;
|
||||
scrollZoom = 0;
|
||||
|
||||
camx += movex * (float)model[0];
|
||||
camy += movex * (float)model[4];
|
||||
camz += movex * (float)model[8];
|
||||
cameraPos[0] += movex * (float)modelviewMatrix[0];
|
||||
cameraPos[1] += movex * (float)modelviewMatrix[4];
|
||||
cameraPos[2] += movex * (float)modelviewMatrix[8];
|
||||
|
||||
camx += movey * (float)model[2];
|
||||
camy += movey * (float)model[6];
|
||||
camz += movey * (float)model[10];
|
||||
cameraPos[0] += movey * (float)modelviewMatrix[2];
|
||||
cameraPos[1] += movey * (float)modelviewMatrix[6];
|
||||
cameraPos[2] += movey * (float)modelviewMatrix[10];
|
||||
|
||||
glEnable(GL_FOG);
|
||||
|
||||
@ -511,15 +540,15 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
|
||||
mouseOverMenu = false;
|
||||
|
||||
imguiBeginFrame(mx,my,mbut,mscroll);
|
||||
imguiBeginFrame(mousePos[0], mousePos[1], mouseButtonMask, mouseScroll);
|
||||
|
||||
if (sample)
|
||||
{
|
||||
sample->handleRenderOverlay((double*)proj, (double*)model, (int*)view);
|
||||
sample->handleRenderOverlay((double*)projectionMatrix, (double*)modelviewMatrix, (int*)viewport);
|
||||
}
|
||||
if (test)
|
||||
{
|
||||
if (test->handleRenderOverlay((double*)proj, (double*)model, (int*)view))
|
||||
if (test->handleRenderOverlay((double*)projectionMatrix, (double*)modelviewMatrix, (int*)viewport))
|
||||
mouseOverMenu = true;
|
||||
}
|
||||
|
||||
@ -664,13 +693,13 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
camr = sqrtf(rcSqr(bmax[0]-bmin[0]) +
|
||||
rcSqr(bmax[1]-bmin[1]) +
|
||||
rcSqr(bmax[2]-bmin[2])) / 2;
|
||||
camx = (bmax[0] + bmin[0]) / 2 + camr;
|
||||
camy = (bmax[1] + bmin[1]) / 2 + camr;
|
||||
camz = (bmax[2] + bmin[2]) / 2 + camr;
|
||||
cameraPos[0] = (bmax[0] + bmin[0]) / 2 + camr;
|
||||
cameraPos[1] = (bmax[1] + bmin[1]) / 2 + camr;
|
||||
cameraPos[2] = (bmax[2] + bmin[2]) / 2 + camr;
|
||||
camr *= 3;
|
||||
}
|
||||
rx = 45;
|
||||
ry = -45;
|
||||
cameraEulers[0] = 45;
|
||||
cameraEulers[1] = -45;
|
||||
glFogf(GL_FOG_START, camr*0.1f);
|
||||
glFogf(GL_FOG_END, camr*1.25f);
|
||||
}
|
||||
@ -682,7 +711,7 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
if (showLevels)
|
||||
{
|
||||
static int levelScroll = 0;
|
||||
if (imguiBeginScrollArea("Choose Level", width-10-250-10-200, height-10-450, 200, 450, &levelScroll))
|
||||
if (imguiBeginScrollArea("Choose Level", width - 10 - 250 - 10 - 200, height - 10 - 450, 200, 450, &levelScroll))
|
||||
mouseOverMenu = true;
|
||||
|
||||
int levelToLoad = -1;
|
||||
@ -740,15 +769,15 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
camr = sqrtf(rcSqr(bmax[0]-bmin[0]) +
|
||||
rcSqr(bmax[1]-bmin[1]) +
|
||||
rcSqr(bmax[2]-bmin[2])) / 2;
|
||||
camx = (bmax[0] + bmin[0]) / 2 + camr;
|
||||
camy = (bmax[1] + bmin[1]) / 2 + camr;
|
||||
camz = (bmax[2] + bmin[2]) / 2 + camr;
|
||||
cameraPos[0] = (bmax[0] + bmin[0]) / 2 + camr;
|
||||
cameraPos[1] = (bmax[1] + bmin[1]) / 2 + camr;
|
||||
cameraPos[2] = (bmax[2] + bmin[2]) / 2 + camr;
|
||||
camr *= 3;
|
||||
}
|
||||
rx = 45;
|
||||
ry = -45;
|
||||
glFogf(GL_FOG_START, camr*0.1f);
|
||||
glFogf(GL_FOG_END, camr*1.25f);
|
||||
cameraEulers[0] = 45;
|
||||
cameraEulers[1] = -45;
|
||||
glFogf(GL_FOG_START, camr * 0.1f);
|
||||
glFogf(GL_FOG_END, camr * 1.25f);
|
||||
}
|
||||
}
|
||||
|
||||
@ -854,18 +883,18 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
// Reset camera and fog to match the mesh bounds.
|
||||
if (bmin && bmax)
|
||||
{
|
||||
camr = sqrtf(rcSqr(bmax[0]-bmin[0]) +
|
||||
rcSqr(bmax[1]-bmin[1]) +
|
||||
rcSqr(bmax[2]-bmin[2])) / 2;
|
||||
camx = (bmax[0] + bmin[0]) / 2 + camr;
|
||||
camy = (bmax[1] + bmin[1]) / 2 + camr;
|
||||
camz = (bmax[2] + bmin[2]) / 2 + camr;
|
||||
camr = sqrtf(rcSqr(bmax[0] - bmin[0]) +
|
||||
rcSqr(bmax[1] - bmin[1]) +
|
||||
rcSqr(bmax[2] - bmin[2])) / 2;
|
||||
cameraPos[0] = (bmax[0] + bmin[0]) / 2 + camr;
|
||||
cameraPos[1] = (bmax[1] + bmin[1]) / 2 + camr;
|
||||
cameraPos[2] = (bmax[2] + bmin[2]) / 2 + camr;
|
||||
camr *= 3;
|
||||
}
|
||||
rx = 45;
|
||||
ry = -45;
|
||||
glFogf(GL_FOG_START, camr*0.2f);
|
||||
glFogf(GL_FOG_END, camr*1.25f);
|
||||
cameraEulers[0] = 45;
|
||||
cameraEulers[1] = -45;
|
||||
glFogf(GL_FOG_START, camr * 0.2f);
|
||||
glFogf(GL_FOG_END, camr * 1.25f);
|
||||
}
|
||||
|
||||
// Do the tests.
|
||||
@ -881,17 +910,17 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
// Log
|
||||
if (showLog && showMenu)
|
||||
{
|
||||
if (imguiBeginScrollArea("Log", 250+20, 10, width - 300 - 250, 200, &logScroll))
|
||||
if (imguiBeginScrollArea("Log", 250 + 20, 10, width - 300 - 250, 200, &logScroll))
|
||||
mouseOverMenu = true;
|
||||
for (int i = 0; i < ctx.getLogCount(); ++i)
|
||||
imguiLabel(ctx.getLogText(i));
|
||||
imguiEndScrollArea();
|
||||
}
|
||||
|
||||
// Tools
|
||||
// Left column tools menu
|
||||
if (!showTestCases && showTools && showMenu) // && geom && sample)
|
||||
{
|
||||
if (imguiBeginScrollArea("Tools", 10, 10, 250, height-20, &toolsScroll))
|
||||
if (imguiBeginScrollArea("Tools", 10, 10, 250, height - 20, &toolsScroll))
|
||||
mouseOverMenu = true;
|
||||
|
||||
if (sample)
|
||||
@ -903,8 +932,8 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
slideShow.updateAndDraw(dt, (float)width, (float)height);
|
||||
|
||||
// Marker
|
||||
if (mposSet && gluProject((GLdouble)mpos[0], (GLdouble)mpos[1], (GLdouble)mpos[2],
|
||||
model, proj, view, &x, &y, &z))
|
||||
if (markerPositionSet && gluProject((GLdouble)markerPosition[0], (GLdouble)markerPosition[1], (GLdouble)markerPosition[2],
|
||||
modelviewMatrix, projectionMatrix, viewport, &x, &y, &z))
|
||||
{
|
||||
// Draw marker circle
|
||||
glLineWidth(5.0f);
|
||||
@ -926,7 +955,7 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
imguiRenderGLDraw();
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
SDL_GL_SwapBuffers();
|
||||
SDL_GL_SwapWindow(window);
|
||||
}
|
||||
|
||||
imguiRenderGLDestroy();
|
||||
|
@ -17,10 +17,10 @@ solution "recastnavigation"
|
||||
flags {
|
||||
"ExtraWarnings",
|
||||
"FloatFast",
|
||||
"NoExceptions",
|
||||
"NoRTTI",
|
||||
"Symbols"
|
||||
}
|
||||
exceptionhandling "Off"
|
||||
rtti "Off"
|
||||
|
||||
-- debug configs
|
||||
configuration "Debug*"
|
||||
@ -135,12 +135,12 @@ project "RecastDemo"
|
||||
-- linux library cflags and libs
|
||||
configuration { "linux", "gmake" }
|
||||
buildoptions {
|
||||
"`pkg-config --cflags sdl`",
|
||||
"`pkg-config --cflags sdl2`",
|
||||
"`pkg-config --cflags gl`",
|
||||
"`pkg-config --cflags glu`"
|
||||
}
|
||||
linkoptions {
|
||||
"`pkg-config --libs sdl`",
|
||||
"`pkg-config --libs sdl2`",
|
||||
"`pkg-config --libs gl`",
|
||||
"`pkg-config --libs glu`"
|
||||
}
|
||||
@ -149,30 +149,26 @@ project "RecastDemo"
|
||||
configuration { "windows" }
|
||||
includedirs { "../RecastDemo/Contrib/SDL/include" }
|
||||
libdirs { "../RecastDemo/Contrib/SDL/lib/x86" }
|
||||
debugdir "../RecastDemo/Bin/"
|
||||
links {
|
||||
"opengl32",
|
||||
"glu32",
|
||||
"sdlmain",
|
||||
"sdl"
|
||||
"opengl32",
|
||||
"SDL2",
|
||||
"SDL2main",
|
||||
}
|
||||
postbuildcommands {
|
||||
-- Copy the SDL2 dll to the Bin folder.
|
||||
"{COPY} %{wks.location}../../Contrib/SDL/lib/x86/SDL2.dll %{cfg.targetdir}"
|
||||
}
|
||||
|
||||
-- mac includes and libs
|
||||
configuration { "macosx" }
|
||||
kind "ConsoleApp" -- xcode4 failes to run the project if using WindowedApp
|
||||
includedirs { "/Library/Frameworks/SDL.framework/Headers" }
|
||||
includedirs { "/Library/Frameworks/SDL2.framework/Headers" }
|
||||
buildoptions { "-Wunused-value -Wshadow -Wreorder -Wsign-compare -Wall" }
|
||||
links {
|
||||
"OpenGL.framework",
|
||||
"/Library/Frameworks/SDL.framework",
|
||||
"SDL2.framework",
|
||||
"Cocoa.framework",
|
||||
}
|
||||
|
||||
files {
|
||||
"../RecastDemo/Include/SDLMain.h",
|
||||
"../RecastDemo/Source/SDLMain.m",
|
||||
-- These don't seem to work in xcode4 target yet.
|
||||
-- "Info.plist",
|
||||
-- "Icon.icns",
|
||||
-- "English.lproj/InfoPlist.strings",
|
||||
-- "English.lproj/MainMenu.xib",
|
||||
}
|
||||
|
11
appveyor.yml
11
appveyor.yml
@ -7,21 +7,20 @@ environment:
|
||||
matrix:
|
||||
- TOOLSET: vs2010
|
||||
- TOOLSET: vs2013
|
||||
# Can't use vs2015 toolset yet as it appears SDL 1.2 has some link errors with it.
|
||||
# - TOOLSET: vs2015
|
||||
- TOOLSET: vs2015
|
||||
|
||||
install:
|
||||
# Download Premake
|
||||
- ps: Start-FileDownload 'https://github.com/premake/premake-core/releases/download/v5.0.0-alpha6/premake-5.0.0-alpha6-windows.zip' 'premake.zip'
|
||||
- ps: Start-FileDownload 'https://github.com/premake/premake-core/releases/download/v5.0.0-alpha7/premake-5.0.0-alpha7-windows.zip' 'premake.zip'
|
||||
|
||||
# Extract it in-place; premake5.exe is at the top level.
|
||||
- 7z x premake.zip
|
||||
|
||||
# Download SDL.
|
||||
- ps: Start-FileDownload 'https://www.libsdl.org/release/SDL-devel-1.2.15-VC.zip' 'RecastDemo/Contrib/SDL.zip'
|
||||
- ps: Start-FileDownload 'https://www.libsdl.org/release/SDL2-devel-2.0.4-VC.zip' 'RecastDemo/Contrib/SDL.zip'
|
||||
|
||||
# Extract it and put it in the right place.
|
||||
- cd RecastDemo/Contrib && 7z x SDL.zip && mv SDL-1.2.15 SDL && cd ../..
|
||||
# Extract it, put it in the right place, and rename it.
|
||||
- cd RecastDemo/Contrib && 7z x SDL.zip && ren SDL2-2.0.4 SDL && cd ../..
|
||||
|
||||
# Generate solution files using premake.
|
||||
- cd RecastDemo && "../premake5.exe" %TOOLSET% && cd ..
|
||||
|
Loading…
x
Reference in New Issue
Block a user