Index: build/SConstruct =================================================================== --- build/SConstruct (revision 0) +++ build/SConstruct (revision 0) @@ -0,0 +1,226 @@ +# Below are the only things that should need to change + +# These are the header files required to build the library (all in +# /include/aicore). The second member of each pair indicates whether +# there is a corresponding src file in /src. This may be used at a +# latter date to improve the DRY quality of the library by +# auto-generating the master header (aicore.h) +src_names = [ + # Core services & execution management + ('precision', False), + + ('core', True), + ('timing', True), + ('aimath', False), + + # World interfacing + ('action', True), + + # Movement + ('location', True), + ('kinematic', True), + ('steering', True), + ('steerpipe', True), + + # Pathfinding + + # Decision making + ('dectree', True), + ('basesm', True), + ('sm', True), + ('markovsm', True), + + # Tactics and strategy + + # Learning + ('learning', True), + ('qlearning', True), + ] + +# These are the sources files used to build each demo (all in /src/demos) +demo_common = ['common/gl/main', 'common/gl/app'] + +# This is a list of triples consisting of a demo name, whether the +# main app files are needed, and the cpp files that are used to build +# the demo. The demo name is also a subdirectory of /src/demos/ where +# the following cpp files are found +demo_names = [ + ('c03_steering', True, ['steering_demo']), + ('c03_kinematic', True, ['kinematic_demo']), + ('c03_flocking', True, ['flocking_demo', 'flock_steer']), + ('c03_priority', True, ['priority_demo']), + ('c03_pipeline', True, ['pipeline_demo']), + + ('c05_dectree', False, ['dectree_demo']), + ('c05_randectree', False, ['randectree_demo']), + ('c05_sm', False, ['sm_demo']), + ('c05_markovsm', False, ['markovsm_demo']), + ('c05_action', False, ['action_demo']), + + ('c07_simpleq', False, ['simpleq_demo']), + ] + + + +# System settings +SConsignFile() + + +# Now the build proper + +# Create the list of source and object files for the library +src_files = [ + '../src/'+src+'.cpp' + for src, has_cpp in src_names + if has_cpp + ] + +# Create the compilation environment to include the relevant files +env = Environment(CPPPATH="../include") + +# Link them into a library +Default(env.StaticLibrary('../lib/aicore', src_files)) + +# Now find the common location of stuff for the demo +common_src = ['../src/demos/'+src+'.cpp' for src in demo_common] + +if env['PLATFORM'] is 'darwin': + env.Append(FRAMEWORKS = ['GLUT', 'OpenGL']) +elif env['PLATFORM'] is 'win32': + env.Append(LIBS = ['opengl32', 'glut32']) +else: + env.Append(LIBS = ['GL', 'glut']) + +env.Append(LIBS=['aicore']) + +# And build each demo +for demo, use_common, files in demo_names: + + # Include the common files, if they are needed + if use_common: + all_src = common_src[:] + else: + all_src = [] + + # Add the demo-specific files + all_src += ['../src/demos/'+demo+'/'+src+'.cpp' for src in files] + + Default(env.Program('../bin/'+demo, + source=all_src, + LIBPATH='../lib')) + + + +# Below are the only things that should need to change + +# These are the header files required to build the library (all in +# /include/aicore). The second member of each pair indicates whether +# there is a corresponding src file in /src. This may be used at a +# latter date to improve the DRY quality of the library by +# auto-generating the master header (aicore.h) +src_names = [ + # Core services & execution management + ('precision', False), + + ('core', True), + ('timing', True), + ('aimath', False), + + # World interfacing + ('action', True), + + # Movement + ('location', True), + ('kinematic', True), + ('steering', True), + ('steerpipe', True), + + # Pathfinding + + # Decision making + ('dectree', True), + ('basesm', True), + ('sm', True), + ('markovsm', True), + + # Tactics and strategy + + # Learning + ('learning', True), + ('qlearning', True), + ] + +# These are the sources files used to build each demo (all in /src/demos) +demo_common = ['common/gl/main', 'common/gl/app'] + +# This is a list of triples consisting of a demo name, whether the +# main app files are needed, and the cpp files that are used to build +# the demo. The demo name is also a subdirectory of /src/demos/ where +# the following cpp files are found +demo_names = [ + ('c03_steering', True, ['steering_demo']), + ('c03_kinematic', True, ['kinematic_demo']), + ('c03_flocking', True, ['flocking_demo', 'flock_steer']), + ('c03_priority', True, ['priority_demo']), + ('c03_pipeline', True, ['pipeline_demo']), + + ('c05_dectree', False, ['dectree_demo']), + ('c05_randectree', False, ['randectree_demo']), + ('c05_sm', False, ['sm_demo']), + ('c05_markovsm', False, ['markovsm_demo']), + ('c05_action', False, ['action_demo']), + + ('c07_simpleq', False, ['simpleq_demo']), + ] + + + +# System settings +SConsignFile() + + +# Now the build proper + +# Create the list of source and object files for the library +src_files = [ + '../src/'+src+'.cpp' + for src, has_cpp in src_names + if has_cpp + ] + +# Create the compilation environment to include the relevant files +env = Environment(CPPPATH="../include") + +# Link them into a library +Default(env.StaticLibrary('../lib/aicore', src_files)) + +# Now find the common location of stuff for the demo +common_src = ['../src/demos/'+src+'.cpp' for src in demo_common] + +if env['PLATFORM'] is 'darwin': + env.Append(FRAMEWORKS = ['GLUT', 'OpenGL']) +elif env['PLATFORM'] is 'win32': + env.Append(LIBS = ['opengl32', 'glut32']) +else: + env.Append(LIBS = ['GL', 'glut']) + +env.Append(LIBS=['aicore']) + +# And build each demo +for demo, use_common, files in demo_names: + + # Include the common files, if they are needed + if use_common: + all_src = common_src[:] + else: + all_src = [] + + # Add the demo-specific files + all_src += ['../src/demos/'+demo+'/'+src+'.cpp' for src in files] + + Default(env.Program('../bin/'+demo, + source=all_src, + LIBPATH='../lib')) + + + Index: include/aicore/precision.h =================================================================== --- include/aicore/precision.h (revision 7) +++ include/aicore/precision.h (working copy) @@ -144,6 +144,9 @@ /** 180/pi */ const real M_180_PI = (real)57.2957795130823208767; +#ifdef _WIN32 + /* These constants cause name collision in gcc/g++ */ + /** pi */ const real M_PI = (real)3.14159265358979323846; @@ -158,6 +161,7 @@ /** 2/pi */ const real M_2_PI = (real)0.63661977236758134308; +#endif //_WIN32 /* @} */ } Index: include/aicore/learning.h =================================================================== --- include/aicore/learning.h (revision 7) +++ include/aicore/learning.h (working copy) @@ -171,7 +171,7 @@ /** * Creates a new problem with the given data. */ - ArrayBasedLearningProblem::ArrayBasedLearningProblem( + ArrayBasedLearningProblem( unsigned stateCount, unsigned actionsPerState, unsigned *destination, Index: include/aicore/steerpipe.h =================================================================== --- include/aicore/steerpipe.h (revision 7) +++ include/aicore/steerpipe.h (working copy) @@ -98,7 +98,7 @@ class SteeringPipeComponent { protected: - friend SteeringPipe; + friend class SteeringPipe; SteeringPipe *pipe; }; Index: include/aicore/kinematic.h =================================================================== --- include/aicore/kinematic.h (revision 7) +++ include/aicore/kinematic.h (working copy) @@ -1,144 +1,144 @@ -/* - * Defines the classes used for kinematic movement. - * - * Part of the Artificial Intelligence for Games system. - * - * Copyright (c) Ian Millington 2003-2006. All Rights Reserved. - * - * This software is distributed under licence. Use of this software - * implies agreement with all terms and conditions of the accompanying - * software licence. - */ - -/** - * @file - * - * Holds kinematic movement algorithms. Kinematic movement is movement - * that doesn't take momentum or inertia into consideration: - * characters have position but not velocity, and if they decide to - * move, then their target velocity is instantly reached. This is in - * contrast to dynamic movement, where (like the real world) movement - * is achieved by applying acceleration to change velocity. Kinematic - * movement is very useful because human beings can accelerate very - * rapidly and have a relatively small top speed. - */ -#ifndef AICORE_KINEMATIC_H -#define AICORE_KINEMATIC_H - -namespace aicore -{ - /** - * The base class for all kinematic movement behaviours. - */ - class KinematicMovement - { - public: - /** - * The character who is moving. - */ - Location *character; - - /** - * The maximum movement speed of the character. - */ - real maxSpeed; - - /** - * Works out the desired steering and writes it into the given - * steering output structure. - */ - virtual void getSteering(SteeringOutput* output) const = 0; - }; - - /** - * This is a base class that adds a target vector to its parent - * class definition. - */ - class TargetedKinematicMovement : public KinematicMovement - { - public: - /** - * The target may be any vector (i.e. it might be something - * that has no orientation, such as a point in space). - */ - Vector3 *target; - }; - - - // Concrete classes - - /** - * Kinematic seek moves at full speed towards its target at each - * frame. - */ - class KinematicSeek : public TargetedKinematicMovement - { - public: - /** - * Works out the desired steering and writes it into the given - * steering output structure. - */ - virtual void getSteering(SteeringOutput* output) const; - }; - - /** - * Flee seeks to maximise the distance from the target. - */ - class KinematicFlee : public KinematicSeek - { - public: - /** - * Works out the desired steering and writes it into the given - * steering output structure. - */ - virtual void getSteering(SteeringOutput* output) const; - }; - - /** - * Kinematic arrive behaves just like seek unless it is close to - * the target, in which case it moves slower and eventually stops. - */ - class KinematicArrive : public TargetedKinematicMovement - { - public: - /** - * At each step the character tries to reach its target in - * this duration. This means it moves more slowly when nearby. - */ - real timeToTarget; - - /** - * If the character is closer than this to the target, it will - * not attempt to move. - */ - real radius; - - /** - * Works out the desired steering and writes it into the given - * steering output structure. - */ - virtual void getSteering(SteeringOutput* output) const; - }; - - /** - * Wander changes the orientation by a random amount then moves - * the character forwards. - */ - class KinematicWander : public KinematicMovement - { - public: - /** - * The maximum rate at which the character can turn. - */ - real maxRotation; - - /** - * Works out the desired steering and writes it into the given - * steering output structure. - */ - virtual void getSteering(SteeringOutput* output) const; - }; - -}; // end of namespace - -#endif // AICORE_KINEMATIC_H +/* + * Defines the classes used for kinematic movement. + * + * Part of the Artificial Intelligence for Games system. + * + * Copyright (c) Ian Millington 2003-2006. All Rights Reserved. + * + * This software is distributed under licence. Use of this software + * implies agreement with all terms and conditions of the accompanying + * software licence. + */ + +/** + * @file + * + * Holds kinematic movement algorithms. Kinematic movement is movement + * that doesn't take momentum or inertia into consideration: + * characters have position but not velocity, and if they decide to + * move, then their target velocity is instantly reached. This is in + * contrast to dynamic movement, where (like the real world) movement + * is achieved by applying acceleration to change velocity. Kinematic + * movement is very useful because human beings can accelerate very + * rapidly and have a relatively small top speed. + */ +#ifndef AICORE_KINEMATIC_H +#define AICORE_KINEMATIC_H + +namespace aicore +{ + /** + * The base class for all kinematic movement behaviours. + */ + class KinematicMovement + { + public: + /** + * The character who is moving. + */ + Location *character; + + /** + * The maximum movement speed of the character. + */ + real maxSpeed; + + /** + * Works out the desired steering and writes it into the given + * steering output structure. + */ + virtual void getSteering(SteeringOutput* output) const = 0; + }; + + /** + * This is a base class that adds a target vector to its parent + * class definition. + */ + class TargetedKinematicMovement : public KinematicMovement + { + public: + /** + * The target may be any vector (i.e. it might be something + * that has no orientation, such as a point in space). + */ + Vector3 *target; + }; + + + // Concrete classes + + /** + * Kinematic seek moves at full speed towards its target at each + * frame. + */ + class KinematicSeek : public TargetedKinematicMovement + { + public: + /** + * Works out the desired steering and writes it into the given + * steering output structure. + */ + virtual void getSteering(SteeringOutput* output) const; + }; + + /** + * Flee seeks to maximise the distance from the target. + */ + class KinematicFlee : public KinematicSeek + { + public: + /** + * Works out the desired steering and writes it into the given + * steering output structure. + */ + virtual void getSteering(SteeringOutput* output) const; + }; + + /** + * Kinematic arrive behaves just like seek unless it is close to + * the target, in which case it moves slower and eventually stops. + */ + class KinematicArrive : public TargetedKinematicMovement + { + public: + /** + * At each step the character tries to reach its target in + * this duration. This means it moves more slowly when nearby. + */ + real timeToTarget; + + /** + * If the character is closer than this to the target, it will + * not attempt to move. + */ + real radius; + + /** + * Works out the desired steering and writes it into the given + * steering output structure. + */ + virtual void getSteering(SteeringOutput* output) const; + }; + + /** + * Wander changes the orientation by a random amount then moves + * the character forwards. + */ + class KinematicWander : public KinematicMovement + { + public: + /** + * The maximum rate at which the character can turn. + */ + real maxRotation; + + /** + * Works out the desired steering and writes it into the given + * steering output structure. + */ + virtual void getSteering(SteeringOutput* output) const; + }; + +}; // end of namespace + +#endif // AICORE_KINEMATIC_H Index: include/gl/glut.h =================================================================== --- include/gl/glut.h (revision 7) +++ include/gl/glut.h (working copy) @@ -1,486 +1,486 @@ -#ifndef __glut_h__ -#define __glut_h__ - -/* Copyright (c) Mark J. Kilgard, 1994, 1995, 1996. */ - -/* This program is freely distributable without licensing fees and is - provided without guarantee or warrantee expressed or implied. This - program is -not- in the public domain. */ - -#if defined(WIN32) -#include -#pragma warning (disable:4244) /* disable bogus conversion warnings */ -#endif -#include -#include - -/* define APIENTRY and CALLBACK to null string if we aren't on Win32 */ -#if !defined(WIN32) -#define APIENTRY -#define CALLBACK -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/** - GLUT API revision history: - - GLUT_API_VERSION is updated to reflect incompatible GLUT - API changes (interface changes, semantic changes, deletions, - or additions). - - GLUT_API_VERSION=1 First public release of GLUT. 11/29/94 - - GLUT_API_VERSION=2 Added support for OpenGL/GLX multisampling, - extension. Supports new input devices like tablet, dial and button - box, and Spaceball. Easy to query OpenGL extensions. - - GLUT_API_VERSION=3 glutMenuStatus added. - - GLUT_API_VERSION=4 glutInitDisplayString, glutWarpPointer, - glutBitmapLength, glutStrokeLength, glutWindowStatusFunc, dynamic - video resize subAPI, glutPostWindowRedisplay (NOT FINALIZED!). -**/ -#ifndef GLUT_API_VERSION /* allow this to be overriden */ -#define GLUT_API_VERSION 3 -#endif - -/** - GLUT implementation revision history: - - GLUT_XLIB_IMPLEMENTATION is updated to reflect both GLUT - API revisions and implementation revisions (ie, bug fixes). - - GLUT_XLIB_IMPLEMENTATION=1 mjk's first public release of - GLUT Xlib-based implementation. 11/29/94 - - GLUT_XLIB_IMPLEMENTATION=2 mjk's second public release of - GLUT Xlib-based implementation providing GLUT version 2 - interfaces. - - GLUT_XLIB_IMPLEMENTATION=3 mjk's GLUT 2.2 images. 4/17/95 - - GLUT_XLIB_IMPLEMENTATION=4 mjk's GLUT 2.3 images. 6/?/95 - - GLUT_XLIB_IMPLEMENTATION=5 mjk's GLUT 3.0 images. 10/?/95 - - GLUT_XLIB_IMPLEMENTATION=7 mjk's GLUT 3.1+ with glutWarpPoitner. 7/24/96 - - GLUT_XLIB_IMPLEMENTATION=8 mjk's GLUT 3.1+ with glutWarpPoitner - and video resize. 1/3/97 - - GLUT_XLIB_IMPLEMENTATION=9 mjk's GLUT 3.4 release with early GLUT 4 routines. - - GLUT_XLIB_IMPLEMENTATION=11 Mesa 2.5's GLUT 3.6 release. - - GLUT_XLIB_IMPLEMENTATION=12 mjk's GLUT 3.6 release with early GLUT 4 routines + signal handling. -**/ -#ifndef GLUT_XLIB_IMPLEMENTATION /* Allow this to be overriden. */ -#define GLUT_XLIB_IMPLEMENTATION 12 -#endif - -/* Display mode bit masks. */ -#define GLUT_RGB 0 -#define GLUT_RGBA GLUT_RGB -#define GLUT_INDEX 1 -#define GLUT_SINGLE 0 -#define GLUT_DOUBLE 2 -#define GLUT_ACCUM 4 -#define GLUT_ALPHA 8 -#define GLUT_DEPTH 16 -#define GLUT_STENCIL 32 -#if (GLUT_API_VERSION >= 2) -#define GLUT_MULTISAMPLE 128 -#define GLUT_STEREO 256 -#endif -#if (GLUT_API_VERSION >= 3) -#define GLUT_LUMINANCE 512 -#endif - -/* Mouse buttons. */ -#define GLUT_LEFT_BUTTON 0 -#define GLUT_MIDDLE_BUTTON 1 -#define GLUT_RIGHT_BUTTON 2 - -/* Mouse button state. */ -#define GLUT_DOWN 0 -#define GLUT_UP 1 - -#if (GLUT_API_VERSION >= 2) -/* function keys */ -#define GLUT_KEY_F1 1 -#define GLUT_KEY_F2 2 -#define GLUT_KEY_F3 3 -#define GLUT_KEY_F4 4 -#define GLUT_KEY_F5 5 -#define GLUT_KEY_F6 6 -#define GLUT_KEY_F7 7 -#define GLUT_KEY_F8 8 -#define GLUT_KEY_F9 9 -#define GLUT_KEY_F10 10 -#define GLUT_KEY_F11 11 -#define GLUT_KEY_F12 12 -/* directional keys */ -#define GLUT_KEY_LEFT 100 -#define GLUT_KEY_UP 101 -#define GLUT_KEY_RIGHT 102 -#define GLUT_KEY_DOWN 103 -#define GLUT_KEY_PAGE_UP 104 -#define GLUT_KEY_PAGE_DOWN 105 -#define GLUT_KEY_HOME 106 -#define GLUT_KEY_END 107 -#define GLUT_KEY_INSERT 108 -#endif - -/* Entry/exit state. */ -#define GLUT_LEFT 0 -#define GLUT_ENTERED 1 - -/* Menu usage state. */ -#define GLUT_MENU_NOT_IN_USE 0 -#define GLUT_MENU_IN_USE 1 - -/* Visibility state. */ -#define GLUT_NOT_VISIBLE 0 -#define GLUT_VISIBLE 1 - -/* Window status state. */ -#define GLUT_HIDDEN 0 -#define GLUT_FULLY_RETAINED 1 -#define GLUT_PARTIALLY_RETAINED 2 -#define GLUT_FULLY_COVERED 3 - -/* Color index component selection values. */ -#define GLUT_RED 0 -#define GLUT_GREEN 1 -#define GLUT_BLUE 2 - -/* Layers for use. */ -#define GLUT_NORMAL 0 -#define GLUT_OVERLAY 1 - -#if defined(WIN32) -/* Stroke font constants (use these in GLUT program). */ -#define GLUT_STROKE_ROMAN ((void*)0) -#define GLUT_STROKE_MONO_ROMAN ((void*)1) - -/* Bitmap font constants (use these in GLUT program). */ -#define GLUT_BITMAP_9_BY_15 ((void*)2) -#define GLUT_BITMAP_8_BY_13 ((void*)3) -#define GLUT_BITMAP_TIMES_ROMAN_10 ((void*)4) -#define GLUT_BITMAP_TIMES_ROMAN_24 ((void*)5) -#if (GLUT_API_VERSION >= 3) -#define GLUT_BITMAP_HELVETICA_10 ((void*)6) -#define GLUT_BITMAP_HELVETICA_12 ((void*)7) -#define GLUT_BITMAP_HELVETICA_18 ((void*)8) -#endif -#else -/* Stroke font opaque addresses (use constants instead in source code). */ -extern void *glutStrokeRoman; -extern void *glutStrokeMonoRoman; - -/* Stroke font constants (use these in GLUT program). */ -#define GLUT_STROKE_ROMAN (&glutStrokeRoman) -#define GLUT_STROKE_MONO_ROMAN (&glutStrokeMonoRoman) - -/* Bitmap font opaque addresses (use constants instead in source code). */ -extern void *glutBitmap9By15; -extern void *glutBitmap8By13; -extern void *glutBitmapTimesRoman10; -extern void *glutBitmapTimesRoman24; -extern void *glutBitmapHelvetica10; -extern void *glutBitmapHelvetica12; -extern void *glutBitmapHelvetica18; - -/* Bitmap font constants (use these in GLUT program). */ -#define GLUT_BITMAP_9_BY_15 (&glutBitmap9By15) -#define GLUT_BITMAP_8_BY_13 (&glutBitmap8By13) -#define GLUT_BITMAP_TIMES_ROMAN_10 (&glutBitmapTimesRoman10) -#define GLUT_BITMAP_TIMES_ROMAN_24 (&glutBitmapTimesRoman24) -#if (GLUT_API_VERSION >= 3) -#define GLUT_BITMAP_HELVETICA_10 (&glutBitmapHelvetica10) -#define GLUT_BITMAP_HELVETICA_12 (&glutBitmapHelvetica12) -#define GLUT_BITMAP_HELVETICA_18 (&glutBitmapHelvetica18) -#endif -#endif - -/* glutGet parameters. */ -#define GLUT_WINDOW_X 100 -#define GLUT_WINDOW_Y 101 -#define GLUT_WINDOW_WIDTH 102 -#define GLUT_WINDOW_HEIGHT 103 -#define GLUT_WINDOW_BUFFER_SIZE 104 -#define GLUT_WINDOW_STENCIL_SIZE 105 -#define GLUT_WINDOW_DEPTH_SIZE 106 -#define GLUT_WINDOW_RED_SIZE 107 -#define GLUT_WINDOW_GREEN_SIZE 108 -#define GLUT_WINDOW_BLUE_SIZE 109 -#define GLUT_WINDOW_ALPHA_SIZE 110 -#define GLUT_WINDOW_ACCUM_RED_SIZE 111 -#define GLUT_WINDOW_ACCUM_GREEN_SIZE 112 -#define GLUT_WINDOW_ACCUM_BLUE_SIZE 113 -#define GLUT_WINDOW_ACCUM_ALPHA_SIZE 114 -#define GLUT_WINDOW_DOUBLEBUFFER 115 -#define GLUT_WINDOW_RGBA 116 -#define GLUT_WINDOW_PARENT 117 -#define GLUT_WINDOW_NUM_CHILDREN 118 -#define GLUT_WINDOW_COLORMAP_SIZE 119 -#if (GLUT_API_VERSION >= 2) -#define GLUT_WINDOW_NUM_SAMPLES 120 -#define GLUT_WINDOW_STEREO 121 -#endif -#if (GLUT_API_VERSION >= 3) -#define GLUT_WINDOW_CURSOR 122 -#endif -#define GLUT_SCREEN_WIDTH 200 -#define GLUT_SCREEN_HEIGHT 201 -#define GLUT_SCREEN_WIDTH_MM 202 -#define GLUT_SCREEN_HEIGHT_MM 203 -#define GLUT_MENU_NUM_ITEMS 300 -#define GLUT_DISPLAY_MODE_POSSIBLE 400 -#define GLUT_INIT_WINDOW_X 500 -#define GLUT_INIT_WINDOW_Y 501 -#define GLUT_INIT_WINDOW_WIDTH 502 -#define GLUT_INIT_WINDOW_HEIGHT 503 -#define GLUT_INIT_DISPLAY_MODE 504 -#if (GLUT_API_VERSION >= 2) -#define GLUT_ELAPSED_TIME 700 -#endif - -#if (GLUT_API_VERSION >= 2) -/* glutDeviceGet parameters. */ -#define GLUT_HAS_KEYBOARD 600 -#define GLUT_HAS_MOUSE 601 -#define GLUT_HAS_SPACEBALL 602 -#define GLUT_HAS_DIAL_AND_BUTTON_BOX 603 -#define GLUT_HAS_TABLET 604 -#define GLUT_NUM_MOUSE_BUTTONS 605 -#define GLUT_NUM_SPACEBALL_BUTTONS 606 -#define GLUT_NUM_BUTTON_BOX_BUTTONS 607 -#define GLUT_NUM_DIALS 608 -#define GLUT_NUM_TABLET_BUTTONS 609 -#endif - -#if (GLUT_API_VERSION >= 3) -/* glutLayerGet parameters. */ -#define GLUT_OVERLAY_POSSIBLE 800 -#define GLUT_LAYER_IN_USE 801 -#define GLUT_HAS_OVERLAY 802 -#define GLUT_TRANSPARENT_INDEX 803 -#define GLUT_NORMAL_DAMAGED 804 -#define GLUT_OVERLAY_DAMAGED 805 - -#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) -/* glutVideoResizeGet parameters. */ -#define GLUT_VIDEO_RESIZE_POSSIBLE 900 -#define GLUT_VIDEO_RESIZE_IN_USE 901 -#define GLUT_VIDEO_RESIZE_X_DELTA 902 -#define GLUT_VIDEO_RESIZE_Y_DELTA 903 -#define GLUT_VIDEO_RESIZE_WIDTH_DELTA 904 -#define GLUT_VIDEO_RESIZE_HEIGHT_DELTA 905 -#define GLUT_VIDEO_RESIZE_X 906 -#define GLUT_VIDEO_RESIZE_Y 907 -#define GLUT_VIDEO_RESIZE_WIDTH 908 -#define GLUT_VIDEO_RESIZE_HEIGHT 909 -#endif - -/* glutUseLayer parameters. */ -#define GLUT_NORMAL 0 -#define GLUT_OVERLAY 1 - -/* glutGetModifiers return mask. */ -#define GLUT_ACTIVE_SHIFT 1 -#define GLUT_ACTIVE_CTRL 2 -#define GLUT_ACTIVE_ALT 4 - -/* glutSetCursor parameters. */ -/* Basic arrows. */ -#define GLUT_CURSOR_RIGHT_ARROW 0 -#define GLUT_CURSOR_LEFT_ARROW 1 -/* Symbolic cursor shapes. */ -#define GLUT_CURSOR_INFO 2 -#define GLUT_CURSOR_DESTROY 3 -#define GLUT_CURSOR_HELP 4 -#define GLUT_CURSOR_CYCLE 5 -#define GLUT_CURSOR_SPRAY 6 -#define GLUT_CURSOR_WAIT 7 -#define GLUT_CURSOR_TEXT 8 -#define GLUT_CURSOR_CROSSHAIR 9 -/* Directional cursors. */ -#define GLUT_CURSOR_UP_DOWN 10 -#define GLUT_CURSOR_LEFT_RIGHT 11 -/* Sizing cursors. */ -#define GLUT_CURSOR_TOP_SIDE 12 -#define GLUT_CURSOR_BOTTOM_SIDE 13 -#define GLUT_CURSOR_LEFT_SIDE 14 -#define GLUT_CURSOR_RIGHT_SIDE 15 -#define GLUT_CURSOR_TOP_LEFT_CORNER 16 -#define GLUT_CURSOR_TOP_RIGHT_CORNER 17 -#define GLUT_CURSOR_BOTTOM_RIGHT_CORNER 18 -#define GLUT_CURSOR_BOTTOM_LEFT_CORNER 19 -/* Inherit from parent window. */ -#define GLUT_CURSOR_INHERIT 100 -/* Blank cursor. */ -#define GLUT_CURSOR_NONE 101 -/* Fullscreen crosshair (if available). */ -#define GLUT_CURSOR_FULL_CROSSHAIR 102 -#endif - -/* GLUT initialization sub-API. */ -extern void APIENTRY glutInit(int *argcp, char **argv); -extern void APIENTRY glutInitDisplayMode(unsigned int mode); -#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) -extern void APIENTRY glutInitDisplayString(const char *string); -#endif -extern void APIENTRY glutInitWindowPosition(int x, int y); -extern void APIENTRY glutInitWindowSize(int width, int height); -extern void APIENTRY glutMainLoop(void); - -/* GLUT window sub-API. */ -extern int APIENTRY glutCreateWindow(const char *title); -extern int APIENTRY glutCreateSubWindow(int win, int x, int y, int width, int height); -extern void APIENTRY glutDestroyWindow(int win); -extern void APIENTRY glutPostRedisplay(void); -#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 11) -extern void APIENTRY glutPostWindowRedisplay(int win); -#endif -extern void APIENTRY glutSwapBuffers(void); -extern int APIENTRY glutGetWindow(void); -extern void APIENTRY glutSetWindow(int win); -extern void APIENTRY glutSetWindowTitle(const char *title); -extern void APIENTRY glutSetIconTitle(const char *title); -extern void APIENTRY glutPositionWindow(int x, int y); -extern void APIENTRY glutReshapeWindow(int width, int height); -extern void APIENTRY glutPopWindow(void); -extern void APIENTRY glutPushWindow(void); -extern void APIENTRY glutIconifyWindow(void); -extern void APIENTRY glutShowWindow(void); -extern void APIENTRY glutHideWindow(void); -#if (GLUT_API_VERSION >= 3) -extern void APIENTRY glutFullScreen(void); -extern void APIENTRY glutSetCursor(int cursor); -#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) -extern void APIENTRY glutWarpPointer(int x, int y); -#endif - -/* GLUT overlay sub-API. */ -extern void APIENTRY glutEstablishOverlay(void); -extern void APIENTRY glutRemoveOverlay(void); -extern void APIENTRY glutUseLayer(GLenum layer); -extern void APIENTRY glutPostOverlayRedisplay(void); -#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 11) -extern void APIENTRY glutPostWindowOverlayRedisplay(int win); -#endif -extern void APIENTRY glutShowOverlay(void); -extern void APIENTRY glutHideOverlay(void); -#endif - -/* GLUT menu sub-API. */ -extern int APIENTRY glutCreateMenu(void (*)(int)); -extern void APIENTRY glutDestroyMenu(int menu); -extern int APIENTRY glutGetMenu(void); -extern void APIENTRY glutSetMenu(int menu); -extern void APIENTRY glutAddMenuEntry(const char *label, int value); -extern void APIENTRY glutAddSubMenu(const char *label, int submenu); -extern void APIENTRY glutChangeToMenuEntry(int item, const char *label, int value); -extern void APIENTRY glutChangeToSubMenu(int item, const char *label, int submenu); -extern void APIENTRY glutRemoveMenuItem(int item); -extern void APIENTRY glutAttachMenu(int button); -extern void APIENTRY glutDetachMenu(int button); - -/* GLUT sub-API. */ -extern void APIENTRY glutDisplayFunc(void (*)(void)); -extern void APIENTRY glutReshapeFunc(void (*)(int width, int height)); -extern void APIENTRY glutKeyboardFunc(void (*)(unsigned char key, int x, int y)); -extern void APIENTRY glutMouseFunc(void (*)(int button, int state, int x, int y)); -extern void APIENTRY glutMotionFunc(void (*)(int x, int y)); -extern void APIENTRY glutPassiveMotionFunc(void (*)(int x, int y)); -extern void APIENTRY glutEntryFunc(void (*)(int state)); -extern void APIENTRY glutVisibilityFunc(void (*)(int state)); -extern void APIENTRY glutIdleFunc(void (*)(void)); -extern void APIENTRY glutTimerFunc(unsigned int millis, void (*)(int value), int value); -extern void APIENTRY glutMenuStateFunc(void (*)(int state)); -#if (GLUT_API_VERSION >= 2) -extern void APIENTRY glutSpecialFunc(void (*)(int key, int x, int y)); -extern void APIENTRY glutSpaceballMotionFunc(void (*)(int x, int y, int z)); -extern void APIENTRY glutSpaceballRotateFunc(void (*)(int x, int y, int z)); -extern void APIENTRY glutSpaceballButtonFunc(void (*)(int button, int state)); -extern void APIENTRY glutButtonBoxFunc(void (*)(int button, int state)); -extern void APIENTRY glutDialsFunc(void (*)(int dial, int value)); -extern void APIENTRY glutTabletMotionFunc(void (*)(int x, int y)); -extern void APIENTRY glutTabletButtonFunc(void (*)(int button, int state, int x, int y)); -#if (GLUT_API_VERSION >= 3) -extern void APIENTRY glutMenuStatusFunc(void (*)(int status, int x, int y)); -extern void APIENTRY glutOverlayDisplayFunc(void (*)(void)); -#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) -extern void APIENTRY glutWindowStatusFunc(void (*)(int state)); -#endif -#endif -#endif - -/* GLUT color index sub-API. */ -extern void APIENTRY glutSetColor(int, GLfloat red, GLfloat green, GLfloat blue); -extern GLfloat APIENTRY glutGetColor(int ndx, int component); -extern void APIENTRY glutCopyColormap(int win); - -/* GLUT state retrieval sub-API. */ -extern int APIENTRY glutGet(GLenum type); -extern int APIENTRY glutDeviceGet(GLenum type); -#if (GLUT_API_VERSION >= 2) -/* GLUT extension support sub-API */ -extern int APIENTRY glutExtensionSupported(const char *name); -#endif -#if (GLUT_API_VERSION >= 3) -extern int APIENTRY glutGetModifiers(void); -extern int APIENTRY glutLayerGet(GLenum type); -#endif - -/* GLUT font sub-API */ -extern void APIENTRY glutBitmapCharacter(void *font, int character); -extern int APIENTRY glutBitmapWidth(void *font, int character); -extern void APIENTRY glutStrokeCharacter(void *font, int character); -extern int APIENTRY glutStrokeWidth(void *font, int character); -#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) -extern int APIENTRY glutBitmapLength(void *font, const unsigned char *string); -extern int APIENTRY glutStrokeLength(void *font, const unsigned char *string); -#endif - -/* GLUT pre-built models sub-API */ -extern void APIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks); -extern void APIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); -extern void APIENTRY glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks); -extern void APIENTRY glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks); -extern void APIENTRY glutWireCube(GLdouble size); -extern void APIENTRY glutSolidCube(GLdouble size); -extern void APIENTRY glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings); -extern void APIENTRY glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings); -extern void APIENTRY glutWireDodecahedron(void); -extern void APIENTRY glutSolidDodecahedron(void); -extern void APIENTRY glutWireTeapot(GLdouble size); -extern void APIENTRY glutSolidTeapot(GLdouble size); -extern void APIENTRY glutWireOctahedron(void); -extern void APIENTRY glutSolidOctahedron(void); -extern void APIENTRY glutWireTetrahedron(void); -extern void APIENTRY glutSolidTetrahedron(void); -extern void APIENTRY glutWireIcosahedron(void); -extern void APIENTRY glutSolidIcosahedron(void); - -#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) -/* GLUT video resize sub-API. */ -extern int APIENTRY glutVideoResizeGet(GLenum param); -extern void APIENTRY glutSetupVideoResizing(void); -extern void APIENTRY glutStopVideoResizing(void); -extern void APIENTRY glutVideoResize(int x, int y, int width, int height); -extern void APIENTRY glutVideoPan(int x, int y, int width, int height); - -/* GLUT debugging sub-API. */ -extern void APIENTRY glutReportErrors(void); -#endif - -#ifdef __cplusplus -} - -#endif -#endif /* __glut_h__ */ +#ifndef __glut_h__ +#define __glut_h__ + +/* Copyright (c) Mark J. Kilgard, 1994, 1995, 1996. */ + +/* This program is freely distributable without licensing fees and is + provided without guarantee or warrantee expressed or implied. This + program is -not- in the public domain. */ + +#if defined(WIN32) +#include +#pragma warning (disable:4244) /* disable bogus conversion warnings */ +#endif +#include +#include + +/* define APIENTRY and CALLBACK to null string if we aren't on Win32 */ +#if !defined(WIN32) +#define APIENTRY +#define CALLBACK +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + GLUT API revision history: + + GLUT_API_VERSION is updated to reflect incompatible GLUT + API changes (interface changes, semantic changes, deletions, + or additions). + + GLUT_API_VERSION=1 First public release of GLUT. 11/29/94 + + GLUT_API_VERSION=2 Added support for OpenGL/GLX multisampling, + extension. Supports new input devices like tablet, dial and button + box, and Spaceball. Easy to query OpenGL extensions. + + GLUT_API_VERSION=3 glutMenuStatus added. + + GLUT_API_VERSION=4 glutInitDisplayString, glutWarpPointer, + glutBitmapLength, glutStrokeLength, glutWindowStatusFunc, dynamic + video resize subAPI, glutPostWindowRedisplay (NOT FINALIZED!). +**/ +#ifndef GLUT_API_VERSION /* allow this to be overriden */ +#define GLUT_API_VERSION 3 +#endif + +/** + GLUT implementation revision history: + + GLUT_XLIB_IMPLEMENTATION is updated to reflect both GLUT + API revisions and implementation revisions (ie, bug fixes). + + GLUT_XLIB_IMPLEMENTATION=1 mjk's first public release of + GLUT Xlib-based implementation. 11/29/94 + + GLUT_XLIB_IMPLEMENTATION=2 mjk's second public release of + GLUT Xlib-based implementation providing GLUT version 2 + interfaces. + + GLUT_XLIB_IMPLEMENTATION=3 mjk's GLUT 2.2 images. 4/17/95 + + GLUT_XLIB_IMPLEMENTATION=4 mjk's GLUT 2.3 images. 6/?/95 + + GLUT_XLIB_IMPLEMENTATION=5 mjk's GLUT 3.0 images. 10/?/95 + + GLUT_XLIB_IMPLEMENTATION=7 mjk's GLUT 3.1+ with glutWarpPoitner. 7/24/96 + + GLUT_XLIB_IMPLEMENTATION=8 mjk's GLUT 3.1+ with glutWarpPoitner + and video resize. 1/3/97 + + GLUT_XLIB_IMPLEMENTATION=9 mjk's GLUT 3.4 release with early GLUT 4 routines. + + GLUT_XLIB_IMPLEMENTATION=11 Mesa 2.5's GLUT 3.6 release. + + GLUT_XLIB_IMPLEMENTATION=12 mjk's GLUT 3.6 release with early GLUT 4 routines + signal handling. +**/ +#ifndef GLUT_XLIB_IMPLEMENTATION /* Allow this to be overriden. */ +#define GLUT_XLIB_IMPLEMENTATION 12 +#endif + +/* Display mode bit masks. */ +#define GLUT_RGB 0 +#define GLUT_RGBA GLUT_RGB +#define GLUT_INDEX 1 +#define GLUT_SINGLE 0 +#define GLUT_DOUBLE 2 +#define GLUT_ACCUM 4 +#define GLUT_ALPHA 8 +#define GLUT_DEPTH 16 +#define GLUT_STENCIL 32 +#if (GLUT_API_VERSION >= 2) +#define GLUT_MULTISAMPLE 128 +#define GLUT_STEREO 256 +#endif +#if (GLUT_API_VERSION >= 3) +#define GLUT_LUMINANCE 512 +#endif + +/* Mouse buttons. */ +#define GLUT_LEFT_BUTTON 0 +#define GLUT_MIDDLE_BUTTON 1 +#define GLUT_RIGHT_BUTTON 2 + +/* Mouse button state. */ +#define GLUT_DOWN 0 +#define GLUT_UP 1 + +#if (GLUT_API_VERSION >= 2) +/* function keys */ +#define GLUT_KEY_F1 1 +#define GLUT_KEY_F2 2 +#define GLUT_KEY_F3 3 +#define GLUT_KEY_F4 4 +#define GLUT_KEY_F5 5 +#define GLUT_KEY_F6 6 +#define GLUT_KEY_F7 7 +#define GLUT_KEY_F8 8 +#define GLUT_KEY_F9 9 +#define GLUT_KEY_F10 10 +#define GLUT_KEY_F11 11 +#define GLUT_KEY_F12 12 +/* directional keys */ +#define GLUT_KEY_LEFT 100 +#define GLUT_KEY_UP 101 +#define GLUT_KEY_RIGHT 102 +#define GLUT_KEY_DOWN 103 +#define GLUT_KEY_PAGE_UP 104 +#define GLUT_KEY_PAGE_DOWN 105 +#define GLUT_KEY_HOME 106 +#define GLUT_KEY_END 107 +#define GLUT_KEY_INSERT 108 +#endif + +/* Entry/exit state. */ +#define GLUT_LEFT 0 +#define GLUT_ENTERED 1 + +/* Menu usage state. */ +#define GLUT_MENU_NOT_IN_USE 0 +#define GLUT_MENU_IN_USE 1 + +/* Visibility state. */ +#define GLUT_NOT_VISIBLE 0 +#define GLUT_VISIBLE 1 + +/* Window status state. */ +#define GLUT_HIDDEN 0 +#define GLUT_FULLY_RETAINED 1 +#define GLUT_PARTIALLY_RETAINED 2 +#define GLUT_FULLY_COVERED 3 + +/* Color index component selection values. */ +#define GLUT_RED 0 +#define GLUT_GREEN 1 +#define GLUT_BLUE 2 + +/* Layers for use. */ +#define GLUT_NORMAL 0 +#define GLUT_OVERLAY 1 + +#if defined(WIN32) +/* Stroke font constants (use these in GLUT program). */ +#define GLUT_STROKE_ROMAN ((void*)0) +#define GLUT_STROKE_MONO_ROMAN ((void*)1) + +/* Bitmap font constants (use these in GLUT program). */ +#define GLUT_BITMAP_9_BY_15 ((void*)2) +#define GLUT_BITMAP_8_BY_13 ((void*)3) +#define GLUT_BITMAP_TIMES_ROMAN_10 ((void*)4) +#define GLUT_BITMAP_TIMES_ROMAN_24 ((void*)5) +#if (GLUT_API_VERSION >= 3) +#define GLUT_BITMAP_HELVETICA_10 ((void*)6) +#define GLUT_BITMAP_HELVETICA_12 ((void*)7) +#define GLUT_BITMAP_HELVETICA_18 ((void*)8) +#endif +#else +/* Stroke font opaque addresses (use constants instead in source code). */ +extern void *glutStrokeRoman; +extern void *glutStrokeMonoRoman; + +/* Stroke font constants (use these in GLUT program). */ +#define GLUT_STROKE_ROMAN (&glutStrokeRoman) +#define GLUT_STROKE_MONO_ROMAN (&glutStrokeMonoRoman) + +/* Bitmap font opaque addresses (use constants instead in source code). */ +extern void *glutBitmap9By15; +extern void *glutBitmap8By13; +extern void *glutBitmapTimesRoman10; +extern void *glutBitmapTimesRoman24; +extern void *glutBitmapHelvetica10; +extern void *glutBitmapHelvetica12; +extern void *glutBitmapHelvetica18; + +/* Bitmap font constants (use these in GLUT program). */ +#define GLUT_BITMAP_9_BY_15 (&glutBitmap9By15) +#define GLUT_BITMAP_8_BY_13 (&glutBitmap8By13) +#define GLUT_BITMAP_TIMES_ROMAN_10 (&glutBitmapTimesRoman10) +#define GLUT_BITMAP_TIMES_ROMAN_24 (&glutBitmapTimesRoman24) +#if (GLUT_API_VERSION >= 3) +#define GLUT_BITMAP_HELVETICA_10 (&glutBitmapHelvetica10) +#define GLUT_BITMAP_HELVETICA_12 (&glutBitmapHelvetica12) +#define GLUT_BITMAP_HELVETICA_18 (&glutBitmapHelvetica18) +#endif +#endif + +/* glutGet parameters. */ +#define GLUT_WINDOW_X 100 +#define GLUT_WINDOW_Y 101 +#define GLUT_WINDOW_WIDTH 102 +#define GLUT_WINDOW_HEIGHT 103 +#define GLUT_WINDOW_BUFFER_SIZE 104 +#define GLUT_WINDOW_STENCIL_SIZE 105 +#define GLUT_WINDOW_DEPTH_SIZE 106 +#define GLUT_WINDOW_RED_SIZE 107 +#define GLUT_WINDOW_GREEN_SIZE 108 +#define GLUT_WINDOW_BLUE_SIZE 109 +#define GLUT_WINDOW_ALPHA_SIZE 110 +#define GLUT_WINDOW_ACCUM_RED_SIZE 111 +#define GLUT_WINDOW_ACCUM_GREEN_SIZE 112 +#define GLUT_WINDOW_ACCUM_BLUE_SIZE 113 +#define GLUT_WINDOW_ACCUM_ALPHA_SIZE 114 +#define GLUT_WINDOW_DOUBLEBUFFER 115 +#define GLUT_WINDOW_RGBA 116 +#define GLUT_WINDOW_PARENT 117 +#define GLUT_WINDOW_NUM_CHILDREN 118 +#define GLUT_WINDOW_COLORMAP_SIZE 119 +#if (GLUT_API_VERSION >= 2) +#define GLUT_WINDOW_NUM_SAMPLES 120 +#define GLUT_WINDOW_STEREO 121 +#endif +#if (GLUT_API_VERSION >= 3) +#define GLUT_WINDOW_CURSOR 122 +#endif +#define GLUT_SCREEN_WIDTH 200 +#define GLUT_SCREEN_HEIGHT 201 +#define GLUT_SCREEN_WIDTH_MM 202 +#define GLUT_SCREEN_HEIGHT_MM 203 +#define GLUT_MENU_NUM_ITEMS 300 +#define GLUT_DISPLAY_MODE_POSSIBLE 400 +#define GLUT_INIT_WINDOW_X 500 +#define GLUT_INIT_WINDOW_Y 501 +#define GLUT_INIT_WINDOW_WIDTH 502 +#define GLUT_INIT_WINDOW_HEIGHT 503 +#define GLUT_INIT_DISPLAY_MODE 504 +#if (GLUT_API_VERSION >= 2) +#define GLUT_ELAPSED_TIME 700 +#endif + +#if (GLUT_API_VERSION >= 2) +/* glutDeviceGet parameters. */ +#define GLUT_HAS_KEYBOARD 600 +#define GLUT_HAS_MOUSE 601 +#define GLUT_HAS_SPACEBALL 602 +#define GLUT_HAS_DIAL_AND_BUTTON_BOX 603 +#define GLUT_HAS_TABLET 604 +#define GLUT_NUM_MOUSE_BUTTONS 605 +#define GLUT_NUM_SPACEBALL_BUTTONS 606 +#define GLUT_NUM_BUTTON_BOX_BUTTONS 607 +#define GLUT_NUM_DIALS 608 +#define GLUT_NUM_TABLET_BUTTONS 609 +#endif + +#if (GLUT_API_VERSION >= 3) +/* glutLayerGet parameters. */ +#define GLUT_OVERLAY_POSSIBLE 800 +#define GLUT_LAYER_IN_USE 801 +#define GLUT_HAS_OVERLAY 802 +#define GLUT_TRANSPARENT_INDEX 803 +#define GLUT_NORMAL_DAMAGED 804 +#define GLUT_OVERLAY_DAMAGED 805 + +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) +/* glutVideoResizeGet parameters. */ +#define GLUT_VIDEO_RESIZE_POSSIBLE 900 +#define GLUT_VIDEO_RESIZE_IN_USE 901 +#define GLUT_VIDEO_RESIZE_X_DELTA 902 +#define GLUT_VIDEO_RESIZE_Y_DELTA 903 +#define GLUT_VIDEO_RESIZE_WIDTH_DELTA 904 +#define GLUT_VIDEO_RESIZE_HEIGHT_DELTA 905 +#define GLUT_VIDEO_RESIZE_X 906 +#define GLUT_VIDEO_RESIZE_Y 907 +#define GLUT_VIDEO_RESIZE_WIDTH 908 +#define GLUT_VIDEO_RESIZE_HEIGHT 909 +#endif + +/* glutUseLayer parameters. */ +#define GLUT_NORMAL 0 +#define GLUT_OVERLAY 1 + +/* glutGetModifiers return mask. */ +#define GLUT_ACTIVE_SHIFT 1 +#define GLUT_ACTIVE_CTRL 2 +#define GLUT_ACTIVE_ALT 4 + +/* glutSetCursor parameters. */ +/* Basic arrows. */ +#define GLUT_CURSOR_RIGHT_ARROW 0 +#define GLUT_CURSOR_LEFT_ARROW 1 +/* Symbolic cursor shapes. */ +#define GLUT_CURSOR_INFO 2 +#define GLUT_CURSOR_DESTROY 3 +#define GLUT_CURSOR_HELP 4 +#define GLUT_CURSOR_CYCLE 5 +#define GLUT_CURSOR_SPRAY 6 +#define GLUT_CURSOR_WAIT 7 +#define GLUT_CURSOR_TEXT 8 +#define GLUT_CURSOR_CROSSHAIR 9 +/* Directional cursors. */ +#define GLUT_CURSOR_UP_DOWN 10 +#define GLUT_CURSOR_LEFT_RIGHT 11 +/* Sizing cursors. */ +#define GLUT_CURSOR_TOP_SIDE 12 +#define GLUT_CURSOR_BOTTOM_SIDE 13 +#define GLUT_CURSOR_LEFT_SIDE 14 +#define GLUT_CURSOR_RIGHT_SIDE 15 +#define GLUT_CURSOR_TOP_LEFT_CORNER 16 +#define GLUT_CURSOR_TOP_RIGHT_CORNER 17 +#define GLUT_CURSOR_BOTTOM_RIGHT_CORNER 18 +#define GLUT_CURSOR_BOTTOM_LEFT_CORNER 19 +/* Inherit from parent window. */ +#define GLUT_CURSOR_INHERIT 100 +/* Blank cursor. */ +#define GLUT_CURSOR_NONE 101 +/* Fullscreen crosshair (if available). */ +#define GLUT_CURSOR_FULL_CROSSHAIR 102 +#endif + +/* GLUT initialization sub-API. */ +extern void APIENTRY glutInit(int *argcp, char **argv); +extern void APIENTRY glutInitDisplayMode(unsigned int mode); +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) +extern void APIENTRY glutInitDisplayString(const char *string); +#endif +extern void APIENTRY glutInitWindowPosition(int x, int y); +extern void APIENTRY glutInitWindowSize(int width, int height); +extern void APIENTRY glutMainLoop(void); + +/* GLUT window sub-API. */ +extern int APIENTRY glutCreateWindow(const char *title); +extern int APIENTRY glutCreateSubWindow(int win, int x, int y, int width, int height); +extern void APIENTRY glutDestroyWindow(int win); +extern void APIENTRY glutPostRedisplay(void); +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 11) +extern void APIENTRY glutPostWindowRedisplay(int win); +#endif +extern void APIENTRY glutSwapBuffers(void); +extern int APIENTRY glutGetWindow(void); +extern void APIENTRY glutSetWindow(int win); +extern void APIENTRY glutSetWindowTitle(const char *title); +extern void APIENTRY glutSetIconTitle(const char *title); +extern void APIENTRY glutPositionWindow(int x, int y); +extern void APIENTRY glutReshapeWindow(int width, int height); +extern void APIENTRY glutPopWindow(void); +extern void APIENTRY glutPushWindow(void); +extern void APIENTRY glutIconifyWindow(void); +extern void APIENTRY glutShowWindow(void); +extern void APIENTRY glutHideWindow(void); +#if (GLUT_API_VERSION >= 3) +extern void APIENTRY glutFullScreen(void); +extern void APIENTRY glutSetCursor(int cursor); +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) +extern void APIENTRY glutWarpPointer(int x, int y); +#endif + +/* GLUT overlay sub-API. */ +extern void APIENTRY glutEstablishOverlay(void); +extern void APIENTRY glutRemoveOverlay(void); +extern void APIENTRY glutUseLayer(GLenum layer); +extern void APIENTRY glutPostOverlayRedisplay(void); +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 11) +extern void APIENTRY glutPostWindowOverlayRedisplay(int win); +#endif +extern void APIENTRY glutShowOverlay(void); +extern void APIENTRY glutHideOverlay(void); +#endif + +/* GLUT menu sub-API. */ +extern int APIENTRY glutCreateMenu(void (*)(int)); +extern void APIENTRY glutDestroyMenu(int menu); +extern int APIENTRY glutGetMenu(void); +extern void APIENTRY glutSetMenu(int menu); +extern void APIENTRY glutAddMenuEntry(const char *label, int value); +extern void APIENTRY glutAddSubMenu(const char *label, int submenu); +extern void APIENTRY glutChangeToMenuEntry(int item, const char *label, int value); +extern void APIENTRY glutChangeToSubMenu(int item, const char *label, int submenu); +extern void APIENTRY glutRemoveMenuItem(int item); +extern void APIENTRY glutAttachMenu(int button); +extern void APIENTRY glutDetachMenu(int button); + +/* GLUT sub-API. */ +extern void APIENTRY glutDisplayFunc(void (*)(void)); +extern void APIENTRY glutReshapeFunc(void (*)(int width, int height)); +extern void APIENTRY glutKeyboardFunc(void (*)(unsigned char key, int x, int y)); +extern void APIENTRY glutMouseFunc(void (*)(int button, int state, int x, int y)); +extern void APIENTRY glutMotionFunc(void (*)(int x, int y)); +extern void APIENTRY glutPassiveMotionFunc(void (*)(int x, int y)); +extern void APIENTRY glutEntryFunc(void (*)(int state)); +extern void APIENTRY glutVisibilityFunc(void (*)(int state)); +extern void APIENTRY glutIdleFunc(void (*)(void)); +extern void APIENTRY glutTimerFunc(unsigned int millis, void (*)(int value), int value); +extern void APIENTRY glutMenuStateFunc(void (*)(int state)); +#if (GLUT_API_VERSION >= 2) +extern void APIENTRY glutSpecialFunc(void (*)(int key, int x, int y)); +extern void APIENTRY glutSpaceballMotionFunc(void (*)(int x, int y, int z)); +extern void APIENTRY glutSpaceballRotateFunc(void (*)(int x, int y, int z)); +extern void APIENTRY glutSpaceballButtonFunc(void (*)(int button, int state)); +extern void APIENTRY glutButtonBoxFunc(void (*)(int button, int state)); +extern void APIENTRY glutDialsFunc(void (*)(int dial, int value)); +extern void APIENTRY glutTabletMotionFunc(void (*)(int x, int y)); +extern void APIENTRY glutTabletButtonFunc(void (*)(int button, int state, int x, int y)); +#if (GLUT_API_VERSION >= 3) +extern void APIENTRY glutMenuStatusFunc(void (*)(int status, int x, int y)); +extern void APIENTRY glutOverlayDisplayFunc(void (*)(void)); +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) +extern void APIENTRY glutWindowStatusFunc(void (*)(int state)); +#endif +#endif +#endif + +/* GLUT color index sub-API. */ +extern void APIENTRY glutSetColor(int, GLfloat red, GLfloat green, GLfloat blue); +extern GLfloat APIENTRY glutGetColor(int ndx, int component); +extern void APIENTRY glutCopyColormap(int win); + +/* GLUT state retrieval sub-API. */ +extern int APIENTRY glutGet(GLenum type); +extern int APIENTRY glutDeviceGet(GLenum type); +#if (GLUT_API_VERSION >= 2) +/* GLUT extension support sub-API */ +extern int APIENTRY glutExtensionSupported(const char *name); +#endif +#if (GLUT_API_VERSION >= 3) +extern int APIENTRY glutGetModifiers(void); +extern int APIENTRY glutLayerGet(GLenum type); +#endif + +/* GLUT font sub-API */ +extern void APIENTRY glutBitmapCharacter(void *font, int character); +extern int APIENTRY glutBitmapWidth(void *font, int character); +extern void APIENTRY glutStrokeCharacter(void *font, int character); +extern int APIENTRY glutStrokeWidth(void *font, int character); +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) +extern int APIENTRY glutBitmapLength(void *font, const unsigned char *string); +extern int APIENTRY glutStrokeLength(void *font, const unsigned char *string); +#endif + +/* GLUT pre-built models sub-API */ +extern void APIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks); +extern void APIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); +extern void APIENTRY glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks); +extern void APIENTRY glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks); +extern void APIENTRY glutWireCube(GLdouble size); +extern void APIENTRY glutSolidCube(GLdouble size); +extern void APIENTRY glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings); +extern void APIENTRY glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings); +extern void APIENTRY glutWireDodecahedron(void); +extern void APIENTRY glutSolidDodecahedron(void); +extern void APIENTRY glutWireTeapot(GLdouble size); +extern void APIENTRY glutSolidTeapot(GLdouble size); +extern void APIENTRY glutWireOctahedron(void); +extern void APIENTRY glutSolidOctahedron(void); +extern void APIENTRY glutWireTetrahedron(void); +extern void APIENTRY glutSolidTetrahedron(void); +extern void APIENTRY glutWireIcosahedron(void); +extern void APIENTRY glutSolidIcosahedron(void); + +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) +/* GLUT video resize sub-API. */ +extern int APIENTRY glutVideoResizeGet(GLenum param); +extern void APIENTRY glutSetupVideoResizing(void); +extern void APIENTRY glutStopVideoResizing(void); +extern void APIENTRY glutVideoResize(int x, int y, int width, int height); +extern void APIENTRY glutVideoPan(int x, int y, int width, int height); + +/* GLUT debugging sub-API. */ +extern void APIENTRY glutReportErrors(void); +#endif + +#ifdef __cplusplus +} + +#endif +#endif /* __glut_h__ */ Index: src/demos/c03_flocking/flocking_demo.cpp =================================================================== --- src/demos/c03_flocking/flocking_demo.cpp (revision 7) +++ src/demos/c03_flocking/flocking_demo.cpp (working copy) @@ -12,12 +12,24 @@ #include #include -#include +#ifdef __APPLE__ + #include + #include +#else + #include +#endif + #include #include "../common/gl/app.h" #include "flock_steer.h" +#ifdef _WIN32 +#define PI aicore::M_PI +#else +#define PI M_PI +#endif + // This is the size of the world in both directions from 0 (i.e. from // -WORLD_SIZE to +WORLD_SIZE) #define WORLD_SIZE 50 @@ -85,7 +97,7 @@ kinematic[i].position.x = aicore::randomBinomial(WORLD_SIZE); kinematic[i].position.y = (aicore::real)0; kinematic[i].position.z = aicore::randomBinomial(WORLD_SIZE); - kinematic[i].orientation = aicore::randomReal(aicore::M_PI); + kinematic[i].orientation = aicore::randomReal(PI); kinematic[i].velocity.x = aicore::randomBinomial((aicore::real)1.0); kinematic[i].velocity.y = (aicore::real)0; kinematic[i].velocity.z = aicore::randomReal((aicore::real)25.0); Index: src/demos/c03_flocking/flock_steer.cpp =================================================================== --- src/demos/c03_flocking/flock_steer.cpp (revision 7) +++ src/demos/c03_flocking/flock_steer.cpp (working copy) @@ -9,6 +9,9 @@ * implies agreement with all terms and conditions of the accompanying * software licence. */ + +#include // for memset + #include "flock_steer.h" Flock::Flock() @@ -161,4 +164,4 @@ output->linear.normalise(); output->linear *= maxAcceleration; } -} \ No newline at end of file +} Index: src/demos/c03_steering/steering_demo.cpp =================================================================== --- src/demos/c03_steering/steering_demo.cpp (revision 7) +++ src/demos/c03_steering/steering_demo.cpp (working copy) @@ -9,10 +9,16 @@ * implies agreement with all terms and conditions of the accompanying * software licence. */ -#include -#include +#include +#include -#include +#ifdef __APPLE__ + #include + #include +#else + #include +#endif + #include #include "../common/gl/app.h" Index: src/demos/c03_priority/priority_demo.cpp =================================================================== --- src/demos/c03_priority/priority_demo.cpp (revision 7) +++ src/demos/c03_priority/priority_demo.cpp (working copy) @@ -12,11 +12,23 @@ #include #include -#include +#ifdef __APPLE__ + #include + #include +#else + #include +#endif + #include #include "../common/gl/app.h" +#ifdef _WIN32 +#define PI aicore::M_PI +#else +#define PI M_PI +#endif + // This is the size of the world in both directions from 0 (i.e. from // -WORLD_SIZE to +WORLD_SIZE) #define WORLD_SIZE 50 @@ -73,7 +85,7 @@ kinematic->position.x = aicore::randomBinomial((aicore::real)5.0); kinematic->position.y = (aicore::real)0; kinematic->position.z = aicore::randomBinomial((aicore::real)5.0); - kinematic->orientation = aicore::randomReal(aicore::M_PI); + kinematic->orientation = aicore::randomReal(PI); kinematic->velocity.x = aicore::randomBinomial((aicore::real)1.0); kinematic->velocity.y = (aicore::real)0; kinematic->velocity.z = aicore::randomReal((aicore::real)5.0); Index: src/demos/common/gl/app.cpp =================================================================== --- src/demos/common/gl/app.cpp (revision 7) +++ src/demos/common/gl/app.cpp (working copy) @@ -10,7 +10,14 @@ * software licence. */ #include -#include + +#ifdef __APPLE__ + #include + #include +#else + #include +#endif + #include "app.h" Application::Application() Index: src/demos/common/gl/main.cpp =================================================================== --- src/demos/common/gl/main.cpp (revision 7) +++ src/demos/common/gl/main.cpp (working copy) @@ -10,7 +10,12 @@ * software licence. */ -#include +#ifdef __APPLE__ + #include + #include +#else + #include +#endif // Include the general application structure. #include "app.h" Index: src/demos/c03_kinematic/kinematic_demo.cpp =================================================================== --- src/demos/c03_kinematic/kinematic_demo.cpp (revision 7) +++ src/demos/c03_kinematic/kinematic_demo.cpp (working copy) @@ -12,11 +12,23 @@ #include #include -#include +#ifdef __APPLE__ + #include + #include +#else + #include +#endif + #include #include "../common/gl/app.h" +#ifdef _WIN32 +#define PI aicore::M_PI +#else +#define PI M_PI +#endif + // This is the size of the world in both directions from 0 (i.e. from // -WORLD_SIZE to +WORLD_SIZE) #define WORLD_SIZE 50 @@ -93,7 +105,7 @@ wander[i].character = &location[i]; wander[i].maxSpeed = (aicore::real)10.0; - wander[i].maxRotation = (aicore::real)8.0 * aicore::M_PI; + wander[i].maxRotation = (aicore::real)8.0 * PI; } // Set the current behaviours Index: src/demos/c03_pipeline/pipeline_demo.cpp =================================================================== --- src/demos/c03_pipeline/pipeline_demo.cpp (revision 7) +++ src/demos/c03_pipeline/pipeline_demo.cpp (working copy) @@ -12,11 +12,23 @@ #include #include -#include +#ifdef __APPLE__ + #include + #include +#else + #include +#endif + #include #include "../common/gl/app.h" +#ifdef _WIN32 +#define PI aicore::M_PI +#else +#define PI M_PI +#endif + // This is the size of the world in both directions from 0 (i.e. from // -WORLD_SIZE to +WORLD_SIZE) #define WORLD_SIZE 50 @@ -78,7 +90,7 @@ kinematic->position.x = aicore::randomBinomial((aicore::real)5.0); kinematic->position.y = (aicore::real)0; kinematic->position.z = aicore::randomBinomial((aicore::real)5.0); - kinematic->orientation = aicore::randomReal(aicore::M_PI); + kinematic->orientation = aicore::randomReal(PI); kinematic->velocity.x = aicore::randomBinomial((aicore::real)1.0); kinematic->velocity.y = (aicore::real)0; kinematic->velocity.z = aicore::randomReal((aicore::real)5.0); Index: src/timing.cpp =================================================================== --- src/timing.cpp (revision 7) +++ src/timing.cpp (working copy) @@ -3,7 +3,8 @@ * * Part of the Artificial Intelligence for Games system. * - * Copyright (c) Ian Millington 2003-2006. All Rights Reserved. + * Copyright (c) Ian Millington 2003-2009. All Rights Reserved. + * Copyright (c) Renato Cunha 2009. All Rights Reserved. * * This software is distributed under licence. Use of this software * implies agreement with all terms and conditions of the accompanying @@ -12,6 +13,7 @@ #include +#ifdef _WIN32 // Import the high performance timer (c. 4ms). #include #include @@ -150,4 +152,138 @@ timingData = NULL; } +#else + +// else, for now, means UNIX/POSIX with the Gnu Compiler Collection +#include + +namespace aicore +{ + + // start stores the time (since epoch) of the last call to initTime + // and is used to calculate the current time. A struct timeval has + // two fields: one to store the number of seconds and another to store + // the number of microseconds since the last second. + struct timeval start; + + // Internal time and clock access functions + unsigned systemTime() + { + struct timeval current; + gettimeofday(¤t, NULL); // The NULL here is because timezones + // doesn't matter to us + + return (current.tv_sec - start.tv_sec) * 1e3 + + (current.tv_usec - start.tv_usec) * 1e-3; + } + + unsigned TimingData::getTime() + { + return systemTime(); + } + + unsigned long systemClock() + { + unsigned a, d; + + __asm__ volatile("rdtsc" : "=a" (a), "=d" (d)); + + return ((unsigned long long)a) | (((unsigned long long)d) << 32);; + } + + unsigned long TimingData::getClock() + { + return systemClock(); + } + + // Sets up the timing system and registers the performance timer. + void initTime() + { + gettimeofday(&start, NULL); + } + + // Holds the global frame time that is passed around + static TimingData *timingData = NULL; + + // Retrieves the global frame info instance + TimingData& TimingData::get() + { + return (TimingData&)*timingData; + } + + // Updates the global frame information. Should be called once per frame. + void TimingData::update() + { + if (!timingData) return; + + // Advance the frame number. + if (!timingData->isPaused) + { + timingData->frameNumber++; + } + + // Update the timing information. + unsigned thisTime = systemTime(); + timingData->lastFrameDuration = thisTime - + timingData->lastFrameTimestamp; + timingData->lastFrameTimestamp = thisTime; + + // Update the tick information. + unsigned long thisClock = systemClock(); + timingData->lastFrameClockTicks = + thisClock - timingData->lastFrameClockstamp; + timingData->lastFrameClockstamp = thisClock; + + // Update the RWA frame rate if we are able to. + if (timingData->frameNumber > 1) { + if (timingData->averageFrameDuration <= 0) + { + timingData->averageFrameDuration = + (double)timingData->lastFrameDuration; + } + else + { + // RWA over 100 frames. + timingData->averageFrameDuration *= 0.99; + timingData->averageFrameDuration += + 0.01 * (double)timingData->lastFrameDuration; + + // Invert to get FPS + timingData->fps = + (float)(1000.0/timingData->averageFrameDuration); + } + } + } + + void TimingData::init() + { + // Set up the timing system. + initTime(); + + // Create the frame info object + if (!timingData) timingData = new TimingData(); + + // Set up the frame info structure. + timingData->frameNumber = 0; + + timingData->lastFrameTimestamp = systemTime(); + timingData->lastFrameDuration = 0; + + timingData->lastFrameClockstamp = systemClock(); + timingData->lastFrameClockTicks = 0; + + timingData->isPaused = false; + + timingData->averageFrameDuration = 0; + timingData->fps = 0; + } + + void TimingData::deinit() + { + delete timingData; + timingData = NULL; + } + +#endif //_WIN32 + }; // end of namespace Index: src/core.cpp =================================================================== --- src/core.cpp (revision 7) +++ src/core.cpp (working copy) @@ -9,6 +9,8 @@ * implies agreement with all terms and conditions of the accompanying * software licence. */ +#include + #include namespace aicore