[Opal-commits] opal/samples/simple BoxEntity.h,NONE,1.1 CapsuleEntity.h,NONE,1.1 Entity.h,NONE,1.1 S
Status: Inactive
Brought to you by:
tylerstreeter
Update of /cvsroot/opal/opal/samples/simple In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7464/samples/simple Added Files: BoxEntity.h CapsuleEntity.h Entity.h SConstruct SphereEntity.h Timer.h main.cpp simple.sln simple.suo simple.vcproj Log Message: Added 'simple' sample app. --- NEW FILE: main.cpp --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ // -------------------------------- // OPAL 'Simple' sample application // -------------------------------- // This sample application is intended for people who are new to OPAL (or // to simulated physics in general). It starts with a simple scene and // allows the user to create new physical objects via keypresses. This // application is very basic and contains extremely verbose comments. // Feel free to use this as a starting point for your own OPAL applications, // if you'd like. // // This application uses OpenGL for rendering and SDL (www.libsdl.org) for // cross-platform input handling and window management (note that SDL is // required in order to build this sample). It uses a very minimal set of // classes to connect the OPAL Solids with drawable objects ('Entity' is a // base class for physically simulated drawable objects, such as the // included 'BoxEntity,' 'SphereEntity,' and 'CapsuleEntity' classes. // 'Timer' is a simple class used to measure elapsed time between frames.) #include <opal/opal.h> #include <sdl/SDL.h> #include "Timer.h" #include "BoxEntity.h" #include "SphereEntity.h" #include "CapsuleEntity.h" // A global list of all the drawable objects. std::vector<opalSamples::Entity*> gEntities; // A global pointer to the OPAL Simulator. opal::Simulator* gSimulator = NULL; // Used to determine when to quit. bool gQuit = false; // Used to keep track of when the simulation is paused. bool gPaused = false; // Dimensions of the ground platform. Used when creating the ground // platform and when determining random positions of new objects. opal::Vec3r gGroundDimensions(25, 5, 25); // Creates a window with an OpenGL context. void setupWindow(); // Destroys the OpenGL window. void destroyWindow(); // Gets new input from the user. Returns false if we should quit. bool processInput(); // Creates a random object at a semi-random location in the scene. void createRandomObject(); /// Returns a random real value between min and max using a uniform /// probability distribution. opal::real randomRealUniform(opal::real min, opal::real max); int main(int argc, char **argv) { // 1. Setup a window with an OpenGL context so we can see what's // happening. setupWindow(); // 2. Create a Simulator. This will enable us to create other OPAL // objects. As the name implies, it also simulates the interactions // among the various objects it contains. Also, we set the gravity // vector to be something other than the default (0, 0, 0). gSimulator = opal::createSimulator(); gSimulator->setGravity(opal::Vec3r(0, (opal::real)-9.81, 0)); // 3. Create some initial Solids and Entities, and connect each // Solid to an Entity. Solids can move around and collide with // other Solids, but they're essentially invisible without some sort // of visual representation. The Entity class used in this // sample represents drawable objects that can be associated with // Solids, thus making it possible to see how the Solids are moving // and interacting. (Of course you could run a simulation without // any visuals if you wanted.) Note that the visual representation // doesn't have to match the physical representation exactly: you // could have an intricate visual mesh for a simulated // television object and use a simple box shape for its physical // representation. Also note that there is not a strict one-to-one // relationship between Solids and Entities; since a Solid can have // multiple OPAL Shapes attached to it, one Solid could use // multiple Entities: one for each Shape. opal::Solid* platformSolid = gSimulator->createSolid(); // Make the platform Solid static. Dynamic Solids can move; static // Solids cannot. platformSolid->setStatic(true); // Add a box Shape to the Solid. Shapes describe a Solid's physical // boundaries. A Solid can use any number of Shapes, and each Shape // can be offset from the Solid's center. opal::BoxShapeData boxShape; boxShape.dimensions = gGroundDimensions; platformSolid->addShape(boxShape); // Make an Entity for the ground platform, set its visual dimensions to // match the physical box, attach it to the Solid, and add it to our // global list of Entities so it can get drawn. opalSamples::BoxEntity* groundEntity = new opalSamples::BoxEntity(); groundEntity->setDimensions(boxShape.dimensions); groundEntity->attachToSolid(platformSolid); gEntities.push_back(groundEntity); // 4. Make a Timer object to track elapsed time between frames. opalSamples::Timer timer; // 5. Start the main loop. while (!gQuit) { // 5a. Find out how much time has elapsed since the last time we // were here (i.e. the duration of the previous frame). opal::real dt = (opal::real)timer.getElapsedSeconds(); // 5b. Check for user input. gQuit = processInput(); // 5c. Now call 'simulate.' This will perform collision detection // and advance the simulation ahead by the given amount of time. // We will pass in the duration of the previous frame. This is // a fairly common way to visualize real-time simulations. (Note // that internally, the Simulator breaks the given time interval // into small, constant-sized steps and processes them iteratively. // Most real-time physics simulations need constant step sizes in // order to produce stable, repeatable results.) Note how we can // pause the simulation by simply not telling the Simulator to // advance. if (!gPaused) { gSimulator->simulate(dt); } // 5d. Clear the OpenGL color and depth buffers, and position/orient // the camera before drawing the Entities. In this application we // simply set it to the same position/orientation each frame. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); float camPos[3] = {0, 5, 40}; glTranslatef(-camPos[0], -camPos[1], -camPos[2]); glRotatef(10, 1, 0, 0); // 5e. Redraw the updated Entities using the latest // positions and orientations of the Solids. std::vector<opalSamples::Entity*>::iterator iter; for (iter = gEntities.begin(); iter != gEntities.end(); ++iter) { (*iter)->draw(); } // 5f. Do OpenGL swap buffers (via SDL). SDL_GL_SwapBuffers(); } // 6. Destroy the Entities. while (!gEntities.empty()) { delete gEntities.back(); gEntities.pop_back(); } // 7. Destroy the Simulator. This will automatically destroy everything // contained within the Simulator. gSimulator->destroy(); return 0; } void setupWindow() { // Setup SDL. unsigned int windowWidth = 800; unsigned int windowHeight = 600; float aspectRatio = (float)windowWidth / (float)windowHeight; if (SDL_Init(SDL_INIT_VIDEO) < 0) { std::cerr << "SDL initialization failed: " << SDL_GetError() << std::endl; SDL_Quit(); return; } // Enable double buffering. SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_Surface *SDLSurface = SDL_SetVideoMode(windowWidth, windowHeight, 0, SDL_OPENGL|SDL_RESIZABLE); if (NULL == SDLSurface) { fprintf(stderr, "Video mode initialization failed: %s\n", SDL_GetError()); SDL_Quit(); return; } // Set key repeat rate (initial delay and interval between repeats, // both in milliseconds). SDL_EnableKeyRepeat(50, 50); // Setup OpenGL. glClearColor(0.9f, 0.9f, 0.8f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(0.0f, 0.0f, 0.0f); glViewport(0, 0, windowWidth, windowHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(40.0f, aspectRatio, 1, 5000.0f); glMatrixMode(GL_MODELVIEW); glEnable(GL_DEPTH_TEST); // Don't draw the back of faces. glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glEnable(GL_NORMALIZE); // Don't light the back of faces. glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0); glEnable(GL_LIGHTING); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Create a light source. GLfloat ambient[] = {0.5f, 0.5f, 0.3f, 1.0f}; GLfloat diffuse[] = {0.9f, 0.9f, 0.9f, 1.0f}; GLfloat specular[] = {1.0f, 1.0f, 1.0f, 1.0f}; GLfloat light_position[] = {-50, 10, 50, 0.0f}; glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, specular); glLightfv(GL_LIGHT0, GL_POSITION, light_position); } void destroyWindow() { if(SDL_WasInit(SDL_INIT_VIDEO)) { SDL_Quit(); } } bool processInput() { bool quit = false; SDL_Event event; // Wandle events until the SDL event queue is empty. while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_KEYDOWN: { switch(event.key.keysym.sym) { case SDLK_ESCAPE: quit = true; break; case SDLK_q: quit = true; break; case SDLK_p: // Pauses the simulation. gPaused = !gPaused; break; case SDLK_SPACE: createRandomObject(); break; default: break; } break; } case SDL_QUIT: { quit = true; break; } default: break; } } return quit; } void createRandomObject() { // Create a new Solid. opal::Solid* solid = gSimulator->createSolid(); opalSamples::Entity* entity = NULL; // Choose a random initial position. opal::real xMax = (opal::real)0.5 * gGroundDimensions[0]; opal::real zMax = (opal::real)0.5 * gGroundDimensions[2]; opal::Point3r pos(randomRealUniform(-xMax, xMax), 15, randomRealUniform(-zMax, zMax)); solid->setPosition(pos); // Choose a random type of object. unsigned int numObjectTypes = 3; int objectType = (int)(numObjectTypes * rand() / (RAND_MAX + 1.0)); // Add Shapes to the Solid and attach an Entity. The Shapes and // visual representation depend on the object type. switch(objectType) { case 0: { // Simple box. opal::BoxShapeData boxShape; boxShape.dimensions[0] = randomRealUniform((opal::real)0.5, (opal::real)5); boxShape.dimensions[1] = randomRealUniform((opal::real)0.5, (opal::real)5); boxShape.dimensions[2] = randomRealUniform((opal::real)0.5, (opal::real)5); solid->addShape(boxShape); entity = new opalSamples::BoxEntity(); ((opalSamples::BoxEntity*)entity)->setDimensions( boxShape.dimensions); entity->attachToSolid(solid); break; } case 1: { // Simple sphere. // TODO opal::BoxShapeData boxShape; boxShape.dimensions[0] = randomRealUniform((opal::real)0.5, (opal::real)5); boxShape.dimensions[1] = randomRealUniform((opal::real)0.5, (opal::real)5); boxShape.dimensions[2] = randomRealUniform((opal::real)0.5, (opal::real)5); solid->addShape(boxShape); entity = new opalSamples::BoxEntity(); ((opalSamples::BoxEntity*)entity)->setDimensions( boxShape.dimensions); entity->attachToSolid(solid); break; } case 2: { // Simple capsule. // TODO opal::BoxShapeData boxShape; boxShape.dimensions[0] = randomRealUniform((opal::real)0.5, (opal::real)5); boxShape.dimensions[1] = randomRealUniform((opal::real)0.5, (opal::real)5); boxShape.dimensions[2] = randomRealUniform((opal::real)0.5, (opal::real)5); solid->addShape(boxShape); entity = new opalSamples::BoxEntity(); ((opalSamples::BoxEntity*)entity)->setDimensions( boxShape.dimensions); entity->attachToSolid(solid); break; } default: assert(false); } // Add the new Entity to the global list so it can get drawn. gEntities.push_back(entity); } opal::real randomRealUniform(opal::real min, opal::real max) { return (opal::real)rand() / RAND_MAX * (max - min) + min; } --- NEW FILE: BoxEntity.h --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ #ifndef OPAL_SAMPLES_BOX_ENTITY_H #define OPAL_SAMPLES_BOX_ENTITY_H #include "Entity.h" namespace opalSamples { /// A drawable box object that can be attached to an OPAL Solid. class BoxEntity : public Entity { public: BoxEntity() { mDimensions.set(1, 1, 1); } virtual ~BoxEntity() {} void setDimensions(const opal::Vec3r& dim) { mDimensions = dim; } virtual void drawGeometry() { opal::real halfx = (opal::real)0.5 * mDimensions[0]; opal::real halfy = (opal::real)0.5 * mDimensions[1]; opal::real halfz = (opal::real)0.5 * mDimensions[2]; glBegin(GL_QUADS); // Left side. glNormal3f(-1, 0, 0); glVertex3f(-halfx, -halfy, halfz); glVertex3f(-halfx, halfy, halfz); glVertex3f(-halfx, halfy, -halfz); glVertex3f(-halfx, -halfy, -halfz); // Back side. glNormal3f(0, 0, -1); glVertex3f(-halfx, -halfy, -halfz); glVertex3f(-halfx, halfy, -halfz); glVertex3f(halfx, halfy, -halfz); glVertex3f(halfx, -halfy, -halfz); // Right side. glNormal3f(1, 0, 0); glVertex3f(halfx, -halfy, -halfz); glVertex3f(halfx, halfy, -halfz); glVertex3f(halfx, halfy, halfz); glVertex3f(halfx, -halfy, halfz); // Front side. glNormal3f(0, 0, 1); glVertex3f(halfx, -halfy, halfz); glVertex3f(halfx, halfy, halfz); glVertex3f(-halfx, halfy, halfz); glVertex3f(-halfx, -halfy, halfz); // Top side. glNormal3f(0, 1, 0); glVertex3f(halfx, halfy, halfz); glVertex3f(halfx, halfy, -halfz); glVertex3f(-halfx, halfy, -halfz); glVertex3f(-halfx, halfy, halfz); // Bottom side. glNormal3f(0, -1, 0); glVertex3f(-halfx, -halfy, halfz); glVertex3f(-halfx, -halfy, -halfz); glVertex3f(halfx, -halfy, -halfz); glVertex3f(halfx, -halfy, halfz); glEnd(); } protected: /// The visual box's dimensions. opal::Vec3r mDimensions; }; } #endif --- NEW FILE: CapsuleEntity.h --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ #ifndef OPAL_SAMPLES_CAPSULE_ENTITY_H #define OPAL_SAMPLES_CAPSULE_ENTITY_H #include "Entity.h" namespace opalSamples { /// A drawable capsule object that can be attached to an OPAL Solid. class CapsuleEntity : public Entity { public: CapsuleEntity() { mRadius = 1; mLength = 2; mQuadric = gluNewQuadric(); } virtual ~CapsuleEntity() { gluDeleteQuadric(mQuadric); } void setDimensions(opal::real radius, opal::real length) { mRadius = radius; mLength = length; } virtual void drawGeometry() { glPushMatrix(); glTranslatef(0.0, 0.0, (opal::real)0.5 * -mLength); gluSphere(mQuadric, mRadius, 20, 20); gluCylinder(mQuadric, mRadius, mRadius, mLength, 20, 20); glTranslatef(0.0, 0.0, mLength); gluSphere(mQuadric, mRadius, 20, 20); glPopMatrix(); } protected: /// The visual capsule's radius. opal::real mRadius; /// The visual capsule's length. opal::real mLength; /// A GLU quadric object used to generate curved meshes. GLUquadricObj* mQuadric; }; } #endif --- NEW FILE: Timer.h --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ #ifndef OPAL_SAMPLES_TIMER_H #define OPAL_SAMPLES_TIMER_H #include <sys/timeb.h> namespace opalSamples { /// A simple timer used to measure elapsed time between successive /// calls to its main function. class Timer { public: Timer() { reset(); } /// Resets the timer. void reset() { timeb timeBuffer; ftime(&timeBuffer); lastTime = timeBuffer.time; lastTime += timeBuffer.millitm * 0.001; } /// Returns the amount of elapsed time since the previous call to /// this function (or the last call to 'reset,' if that was more /// recent). double getElapsedSeconds() { timeb timeBuffer; ftime(&timeBuffer); double currentTime = timeBuffer.time; currentTime += timeBuffer.millitm * 0.001; double elapsedSeconds = currentTime - lastTime; lastTime = currentTime; return elapsedSeconds; } private: double lastTime; }; } #endif --- NEW FILE: simple.sln --- Microsoft Visual Studio Solution File, Format Version 8.00 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "simple", "simple.vcproj", "{79955DA4-1E44-4CDB-83D1-C2E2A56DF1A6}" ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject Global GlobalSection(SolutionConfiguration) = preSolution Debug = Debug Release = Release EndGlobalSection GlobalSection(ProjectConfiguration) = postSolution {79955DA4-1E44-4CDB-83D1-C2E2A56DF1A6}.Debug.ActiveCfg = Debug|Win32 {79955DA4-1E44-4CDB-83D1-C2E2A56DF1A6}.Debug.Build.0 = Debug|Win32 {79955DA4-1E44-4CDB-83D1-C2E2A56DF1A6}.Release.ActiveCfg = Release|Win32 {79955DA4-1E44-4CDB-83D1-C2E2A56DF1A6}.Release.Build.0 = Release|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection GlobalSection(ExtensibilityAddIns) = postSolution EndGlobalSection EndGlobal --- NEW FILE: SConstruct --- import os sources = Split(""" main.cpp """) # Setup options opts = Options() opts.AddOptions( PathOption('extra_include_path', 'Additional include directory', '.'), PathOption('extra_lib_path', 'Additional lib directory', '.')) env = Environment( ENV = os.environ, LIBS = ['opal-ode', 'OgreMain'], options = opts ) env.Append(CPPPATH = env['extra_include_path'], LIBPATH = env['extra_lib_path']) if env['PLATFORM'] != 'win32': env.Append(CXXFLAGS = ['-DGCC_3_1', '-DEXT_HASH']) # Build the executable. exe = env.Program('playpen', sources) # Install the executable. inst = env.Install('../bin/release', exe) # Tell scons to build and install the executable by default. env.Default(exe) env.Default(inst) --- NEW FILE: simple.vcproj --- <?xml version="1.0" encoding="Windows-1252"?> <VisualStudioProject ProjectType="Visual C++" Version="7.10" Name="simple" ProjectGUID="{79955DA4-1E44-4CDB-83D1-C2E2A56DF1A6}" Keyword="Win32Proj"> <Platforms> <Platform Name="Win32"/> </Platforms> <Configurations> <Configuration Name="Debug|Win32" OutputDirectory="Debug" IntermediateDirectory="Debug" ConfigurationType="1" CharacterSet="2"> <Tool Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="" PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="3" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" DebugInformationFormat="3"/> <Tool Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" AdditionalDependencies="opengl32.lib glu32.lib SDL.lib SDLmain.lib opal-ode_d.lib" OutputFile="../bin/Debug/simple.exe" LinkIncremental="2" AdditionalLibraryDirectories="" GenerateDebugInformation="TRUE" ProgramDatabaseFile="$(OutDir)/simple.pdb" SubSystem="1" StackReserveSize="10000000" TargetMachine="1"/> <Tool Name="VCMIDLTool"/> <Tool Name="VCPostBuildEventTool"/> <Tool Name="VCPreBuildEventTool"/> <Tool Name="VCPreLinkEventTool"/> <Tool Name="VCResourceCompilerTool"/> <Tool Name="VCWebServiceProxyGeneratorTool"/> <Tool Name="VCXMLDataGeneratorTool"/> <Tool Name="VCWebDeploymentTool"/> <Tool Name="VCManagedWrapperGeneratorTool"/> <Tool Name="VCAuxiliaryManagedWrapperGeneratorTool"/> </Configuration> <Configuration Name="Release|Win32" OutputDirectory="Release" IntermediateDirectory="Release" ConfigurationType="1" CharacterSet="2"> <Tool Name="VCCLCompilerTool" GlobalOptimizations="TRUE" InlineFunctionExpansion="2" FavorSizeOrSpeed="1" AdditionalIncludeDirectories="" PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" RuntimeLibrary="2" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" DebugInformationFormat="3"/> <Tool Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" AdditionalDependencies="opengl32.lib glu32.lib SDL.lib SDLmain.lib opal-ode.lib" OutputFile="../bin/Release/simple.exe" LinkIncremental="1" AdditionalLibraryDirectories="" GenerateDebugInformation="TRUE" SubSystem="1" StackReserveSize="10000000" OptimizeReferences="2" EnableCOMDATFolding="2" TargetMachine="1"/> <Tool Name="VCMIDLTool"/> <Tool Name="VCPostBuildEventTool"/> <Tool Name="VCPreBuildEventTool"/> <Tool Name="VCPreLinkEventTool"/> <Tool Name="VCResourceCompilerTool"/> <Tool Name="VCWebServiceProxyGeneratorTool"/> <Tool Name="VCXMLDataGeneratorTool"/> <Tool Name="VCWebDeploymentTool"/> <Tool Name="VCManagedWrapperGeneratorTool"/> <Tool Name="VCAuxiliaryManagedWrapperGeneratorTool"/> </Configuration> </Configurations> <References> </References> <Files> <Filter Name="Source Files" Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> <File RelativePath=".\main.cpp"> </File> </Filter> <Filter Name="Header Files" Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> <File RelativePath=".\BoxEntity.h"> </File> <File RelativePath=".\CapsuleEntity.h"> </File> <File RelativePath=".\Entity.h"> </File> <File RelativePath=".\SphereEntity.h"> </File> <File RelativePath=".\Timer.h"> </File> </Filter> </Files> <Globals> </Globals> </VisualStudioProject> --- NEW FILE: SphereEntity.h --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ #ifndef OPAL_SAMPLES_SPHERE_ENTITY_H #define OPAL_SAMPLES_SPHERE_ENTITY_H #include "Entity.h" namespace opalSamples { /// A drawable sphere object that can be attached to an OPAL Solid. class SphereEntity : public Entity { public: SphereEntity() { mRadius = 1; mQuadric = gluNewQuadric(); } virtual ~SphereEntity() { gluDeleteQuadric(mQuadric); } void setRadius(opal::real radius) { mRadius = radius; } virtual void drawGeometry() { gluSphere(mQuadric, mRadius, 20, 20); } protected: /// The visual sphere's radius. opal::real mRadius; /// A GLU quadric object used to generate curved meshes. GLUquadricObj* mQuadric; }; } #endif --- NEW FILE: simple.suo --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Entity.h --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ #ifndef OPAL_SAMPLES_ENTITY_H #define OPAL_SAMPLES_ENTITY_H //#include <math.h> #include <opal/opal.h> #ifdef WIN32 #include <windows.h> #endif #include <GL/gl.h> #include <GL/glu.h> namespace opalSamples { /// A drawable object that can be attached to an OPAL Solid. class Entity { public: Entity() { mSolid = NULL; mColor[0] = 0.5f; mColor[1] = 0.5f; mColor[2] = 0.5f; mColor[3] = 1.0f; } virtual ~Entity() {} /// Draws the object. Does nothing until after being attached to a /// Solid. virtual void draw() { if (!mSolid) { // Don't do anything if the Entity hasn't been attached // to a Solid yet. return; } // Set the material color for this object. glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mColor); glPushMatrix(); // Move to the Solids position/orientation. glMultMatrixf(mSolid->getTransform().getData()); // Apply the offset from the Solid's transform. glMultMatrixf(mOffset.getData()); // Draw the actual geometry. drawGeometry(); glPopMatrix(); } /// Attaches the Entity to an OPAL Solid. The offset can be used to /// draw the Entity away from the Solid's center (e.g. when multiple /// Entities are attached to a single Solid, possibly to represent /// multiple physical Shapes). void attachToSolid(opal::Solid* solid, const opal::Matrix44r& offset = opal::Matrix44r()) { mSolid = solid; mOffset = offset; } void setColor(float red, float green, float blue) { mColor[0] = red; mColor[1] = green; mColor[2] = blue; } protected: /// Draws the actual geometry used for the Entity's visual /// representation. virtual void drawGeometry() = 0; private: /// Pointer to the Solid to which this Entity is attached. opal::Solid* mSolid; /// The offset of this Entity from the Solid's base transform. opal::Matrix44r mOffset; /// The Entity's color. float mColor[4]; }; } #endif |