Simulator.h

Go to the documentation of this file.
00001 /*************************************************************************
00002 *                                                                       *
00003 * Open Physics Abstraction Layer                                        *
00004 * Copyright (C) 2004-2005                                               *
00005 * Alan Fischer  alan.fischer@gmail.com                                  *
00006 * Andres Reinot  andres@reinot.com                                      *
00007 * Tyler Streeter  tylerstreeter@gmail.com                               *
00008 * All rights reserved.                                                  *
00009 * Web: opal.sourceforge.net                                             *
00010 *                                                                       *
00011 * This library is free software; you can redistribute it and/or         *
00012 * modify it under the terms of EITHER:                                  *
00013 *   (1) The GNU Lesser General Public License as published by the Free  *
00014 *       Software Foundation; either version 2.1 of the License, or (at  *
00015 *       your option) any later version. The text of the GNU Lesser      *
00016 *       General Public License is included with this library in the     *
00017 *       file license-LGPL.txt.                                          *
00018 *   (2) The BSD-style license that is included with this library in     *
00019 *       the file license-BSD.txt.                                       *
00020 *                                                                       *
00021 * This library is distributed in the hope that it will be useful,       *
00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
00024 * license-LGPL.txt and license-BSD.txt for more details.                *
00025 *                                                                       *
00026 *************************************************************************/
00027 
00028 #ifndef OPAL_SIMULATOR_H
00029 #define OPAL_SIMULATOR_H
00030 
00031 // project headers
00032 #include "Defines.h"
00033 #include "Motor.h"
00034 #include "Joint.h"
00035 #include "Solid.h"
00036 #include "Space.h"
00037 #include "Blueprint.h"
00038 #include "Sensor.h"
00039 #include "Vec3r.h"
00040 
00041 namespace opal
00042 {
00043         class AttractorMotor;
00044         class GearedMotor;
00045         class ServoMotor;
00046         class SpringMotor;
00047         class ThrusterMotor;
00048         class VelocityMotor;
00049         class AccelerationSensor;
00050         class InclineSensor;
00051         class RaycastSensor;
00052         class VolumeSensor;
00053         class BlueprintInstance;
00054         class PostStepEventHandler;
00055         struct RaycastResult;
00056         struct VolumeQueryResult;
00057 
00059         class SimulatorData
00060         {
00061                 public:
00063                         SimulatorData()
00064                         {
00065                                 useOctreeInsteadHash = false;
00066 
00067                                 // octree defaults
00068                                 worldSize = Vec3r( 1000, 1000, 1000 );
00069                                 octreeDepth = 7;
00070                                 worldCenter = Vec3r( 0, 0, 0 );
00071 
00072                                 // hash defaults
00073                                 hashMinLevel = -5;
00074                                 hashMaxLevel = 9;
00075                         }
00076 
00078                         /*
00079                         SimulatorData( SimulatorData & copy )
00080                         {
00081                             useOctreeInsteadHash = copy.useOctreeInsteadHash;
00082 
00083                             // octree defaults
00084                             worldSize = copy.worldSize;
00085                             octreeDepth = copy.octreeDepth;
00086                             worldCenter = copy.worldCenter;
00087 
00088                             // hash defaults
00089                             hashMinLevel = copy.hashMinLevel;
00090                             hashMaxLevel = copy.hashMaxLevel;
00091                         }*/
00092 
00096                         bool useOctreeInsteadHash;
00097 
00099                         Vec3r worldSize;
00100 
00102                         Vec3r worldCenter;
00103 
00105                         int octreeDepth;
00106 
00108                         int hashMinLevel;
00109 
00111                         int hashMaxLevel;
00112         };
00113 
00118         class Simulator
00119         {
00120                 public:
00121                         Simulator();
00122 
00123                         virtual void initData( SimulatorData data );
00124 
00128                         virtual void OPAL_CALL destroy() = 0;
00129 
00156                         virtual bool OPAL_CALL simulate( real dt );
00157 
00160                         virtual void OPAL_CALL setStepSize( real stepSize );
00161 
00163                         virtual real OPAL_CALL getStepSize();
00164 
00165                         // post events
00166 
00168 
00171                         virtual void OPAL_CALL addPostStepEventHandler(
00172                             PostStepEventHandler * eventHandler );
00173 
00175                         virtual void OPAL_CALL removePostStepEventHandler(
00176                             PostStepEventHandler * eventHandler );
00177 
00179                         virtual size_t OPAL_CALL getNumPostStepEventHandlers() const;
00180 
00183                         virtual PostStepEventHandler* OPAL_CALL
00184                         getPostStepEventHandler( unsigned int id ) const;
00185 
00186                         // global collision events
00187 
00189 
00192                         virtual void OPAL_CALL addGlobalCollisionEventHandler(
00193                             CollisionEventHandler * eventHandler );
00194 
00196                         virtual void OPAL_CALL removeGlobalCollisionEventHandler(
00197                             CollisionEventHandler * eventHandler );
00198 
00200                         virtual size_t OPAL_CALL getNumGlobalCollisionEventHandlers() const;
00201 
00204                         virtual CollisionEventHandler* OPAL_CALL
00205                         getGlobalCollisionEventHandler( unsigned int id ) const;
00206 
00212                         virtual void OPAL_CALL instantiateBlueprint(
00213                             BlueprintInstance& instance, const Blueprint& bp,
00214                             const Matrix44r& offset = Matrix44r(), real scale = 1 );
00215 
00217                         virtual void OPAL_CALL setGravity( const Vec3r& gravity ) = 0;
00218 
00220                         virtual Vec3r OPAL_CALL getGravity() const = 0;
00221 
00224                         virtual void OPAL_CALL setSolverAccuracy( SolverAccuracyLevel level );
00225 
00227                         virtual SolverAccuracyLevel OPAL_CALL getSolverAccuracy() const;
00228 
00231                         virtual void OPAL_CALL setMaxCorrectingVel( real vel );
00232 
00235                         virtual real OPAL_CALL getMaxCorrectingVel() const;
00236 
00240                         virtual void OPAL_CALL setMaxContacts( unsigned int mc );
00241 
00244                         virtual unsigned int OPAL_CALL getMaxContacts() const;
00245 
00248                         //virtual void OPAL_CALL setMaxLinearVel(real max);
00249 
00252                         //virtual real OPAL_CALL getMaxLinearVel()const;
00253 
00256                         //virtual void OPAL_CALL setMaxAngularVel(real max);
00257 
00260                         //virtual real OPAL_CALL getMaxAngularVel()const;
00261 
00265                         virtual void OPAL_CALL setUserData( void* data );
00266 
00268                         virtual void* OPAL_CALL getUserData();
00269 
00279                         virtual void OPAL_CALL setupContactGroups( unsigned int group0,
00280                                 unsigned int group1, bool makeContacts );
00281 
00287                         virtual void OPAL_CALL setupContactGroup( unsigned int group,
00288                                 bool makeContacts );
00289 
00292                         virtual bool OPAL_CALL groupsMakeContacts( unsigned int group0,
00293                                 unsigned int group1 );
00294 
00299                         virtual void OPAL_CALL setStaticSleepingContactsEnabled( bool enable );
00300 
00303                         virtual bool OPAL_CALL areStaticSleepingContactsEnabled();
00304 
00305                         // SOLIDS
00306 
00308                         virtual Solid* OPAL_CALL createSolid() = 0;
00309 
00311                         virtual Solid* OPAL_CALL createPlane( real a, real b, real c, real d,
00312                                                               const Material& m = defaults::shape::material );
00313 
00315                         virtual unsigned int OPAL_CALL getNumSolids() const;
00316 
00318                         virtual Solid* OPAL_CALL getSolid( unsigned int i ) const;
00319 
00323                         virtual void OPAL_CALL destroySolid( Solid* s );
00324 
00326                         virtual void OPAL_CALL destroyAllSolids();
00327 
00328                         // JOINTS
00329 
00331                         virtual Joint* OPAL_CALL createJoint() = 0;
00332 
00335                         virtual void OPAL_CALL destroyJoint( Joint* j );
00336 
00338                         virtual void OPAL_CALL destroyAllJoints();
00339 
00340                         // MOTORS
00341 
00343                         virtual ThrusterMotor* OPAL_CALL createThrusterMotor();
00344 
00346                         virtual VelocityMotor* OPAL_CALL createVelocityMotor();
00347 
00349                         virtual GearedMotor* OPAL_CALL createGearedMotor();
00350 
00352                         virtual ServoMotor* OPAL_CALL createServoMotor();
00353 
00355                         virtual AttractorMotor* OPAL_CALL createAttractorMotor();
00356 
00358                         virtual SpringMotor* OPAL_CALL createSpringMotor();
00359 
00362                         //virtual void OPAL_CALL registerCustomMotor(Motor* m);
00363 
00365                         virtual void OPAL_CALL destroyMotor( Motor* m );
00366 
00368                         virtual void OPAL_CALL destroyAllMotors();
00369 
00370                         // SENSORS
00371 
00373                         virtual AccelerationSensor* OPAL_CALL createAccelerationSensor();
00374 
00376                         virtual InclineSensor* OPAL_CALL createInclineSensor();
00377 
00379                         virtual RaycastSensor* OPAL_CALL createRaycastSensor();
00380 
00382                         virtual VolumeSensor* OPAL_CALL createVolumeSensor();
00383 
00385                         virtual void OPAL_CALL destroySensor( Sensor* s );
00386 
00388                         virtual void OPAL_CALL destroyAllSensors();
00389 
00390                         // SPACES
00391 
00394                         virtual Space* OPAL_CALL createSpace() = 0;
00395 
00396                         virtual Space* OPAL_CALL getRootSpace();
00397 
00401                         virtual std::vector<RaycastResult> & OPAL_CALL internal_fireRay(
00402                             const Rayr& r, real length, const Solid* attachedSolid,
00403                             unsigned int rayContactGroup ) = 0;
00404 
00406                         virtual const VolumeQueryResult& OPAL_CALL internal_queryVolume(
00407                             const Solid* volume, const Solid* attachedSolid ) = 0;
00408 
00410                         virtual unsigned long int OPAL_CALL
00411                         internal_getContactGroupFlags( unsigned int groupNum ) const;
00412 
00414                         virtual void OPAL_CALL internal_recordCollision( const CollisionEvent & event );
00415 
00416                 protected:
00417                         virtual ~Simulator();
00418 
00422                         virtual void stepPhysics() = 0;
00423 
00425                         void addSolid( Solid* s );
00426 
00428                         void removeSolid( Solid* s );
00429 
00431                         void addJoint( Joint* j );
00432 
00434                         void removeJoint( Joint* j );
00435 
00437                         void addMotor( Motor* m );
00438 
00440                         void removeMotor( Motor* m );
00441 
00443                         void addSensor( Sensor* s );
00444 
00446                         void removeSensor( Sensor* s );
00447 
00449                         void addSpace( Space* s );
00450 
00453                         void destroyGarbage();
00454 
00457                         real mStepSize;
00458 
00462                         real mTimeBuffer;
00463 
00466                         SolverAccuracyLevel mSolverAccuracyLevel;
00467 
00470                         void* mUserData;
00471 
00474                         //real mMaxLinearVel;
00475 
00478                         //real mMaxAngularVel;
00479 
00481                         std::vector<Solid*> mSolidList;
00482 
00484                         std::vector<Joint*> mJointList;
00485 
00487                         std::vector<Motor*> mMotorList;
00488 
00490                         std::vector<Sensor*> mSensorList;
00491 
00494                         bool mIsSolidDestructionSafe;
00495 
00498                         bool mIsJointDestructionSafe;
00499 
00501                         std::vector<Solid*> mSolidGarbageList;
00502 
00504                         std::vector<Joint*> mJointGarbageList;
00505 
00508                         std::vector<Space*> mSpaceList;
00509 
00511                         Space * mRootSpace;
00512 
00515                         unsigned long int mContactGroupFlags[ 32 ];
00516 
00519                         bool mStaticSleepingContactsEnabled;
00520 
00522                         std::vector<PostStepEventHandler *> mPostStepEventHandlers;
00523 
00525                         std::vector<CollisionEventHandler *> mCollisionEventHandlers;
00526 
00529                         real mMaxCorrectingVel;
00530 
00533                         unsigned int mMaxContacts;
00534 
00536                         SimulatorData mData;
00537 
00538                 private:
00539         };
00540 }
00541 
00542 #endif
00543 

Generated on Tue May 16 17:49:52 2006 for OPAL by  doxygen 1.4.6-NO