Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef BULLETPHYSICS_H_
00014 #define BULLETPHYSICS_H_
00015
00016 #include "SimulatorConfig.h"
00017 #include "UWSimUtils.h"
00018
00019 #include <osgbDynamics/MotionState.h>
00020 #include <osgbCollision/CollisionShapes.h>
00021 #include <osgbCollision/Utils.h>
00022
00023 #include <btBulletDynamicsCommon.h>
00024 #include <iostream>
00025
00026 #include <osgOcean/OceanScene>
00027
00028 #include "BulletHfFluid/btHfFluidRigidDynamicsWorld.h"
00029 #include "BulletHfFluid/btHfFluidRigidCollisionConfiguration.h"
00030 #include "BulletHfFluid/btHfFluid.h"
00031 #include "BulletHfFluid/btHfFluidBuoyantConvexShape.h"
00032
00033
00034
00035 #define UWSIM_DEFAULT_GRAVITY btVector3(0,0,-1)
00036
00037
00038 enum CollisionTypes
00039 {
00040 COL_NOTHING = 0x00000000, COL_OBJECTS = 0x00000001, COL_VEHICLE = 0x00000010, COL_EVERYTHING = 0x11111111,
00041 };
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 class CollisionDataType : public osg::Referenced
00052 {
00053 public:
00054 CollisionDataType(std::string nam, std::string vehName, int isVehi)
00055 {
00056 vehicleName = vehName;
00057 name = nam;
00058 isVehicle = isVehi;
00059 }
00060 ;
00061 std::string getObjectName()
00062 {
00063 if (isVehicle)
00064 return vehicleName;
00065 else
00066 return name;
00067 }
00068 ;
00069 std::string name, vehicleName;
00070 int isVehicle;
00071
00072 };
00073
00074 class BulletPhysics : public osg::Referenced
00075 {
00076
00077 public:
00078 typedef enum
00079 {
00080 SHAPE_BOX, SHAPE_SPHERE, SHAPE_TRIMESH, SHAPE_COMPOUND_TRIMESH, SHAPE_COMPOUND_BOX, SHAPE_COMPOUND_CYLINDER
00081 } collisionShapeType_t;
00082
00083 btHfFluidRigidDynamicsWorld * dynamicsWorld;
00084
00085
00086 BulletPhysics(double configGravity[3], osgOcean::OceanTechnique* oceanSurf, PhysicsWater physicsWater);
00087
00088 void setGravity(btVector3 g)
00089 {
00090 dynamicsWorld->setGravity(g);
00091 }
00092 btRigidBody* addObject(osg::MatrixTransform *root, osg::Node *node, CollisionDataType * data,
00093 boost::shared_ptr<PhysicProperties> pp, osg::Node * colShape = NULL);
00094 btRigidBody* addFloatingObject(osg::MatrixTransform *root, osg::Node *node, CollisionDataType * data,
00095 boost::shared_ptr<PhysicProperties> pp, osg::Node * colShape = NULL);
00096
00097 void stepSimulation(btScalar timeStep, int maxSubSteps, btScalar fixedTimeStep);
00098 void printManifolds();
00099
00100 int getNumCollisions();
00101
00102 btRigidBody* copyObject(btRigidBody * copied);
00103 int physicsStep;
00104
00105 btPersistentManifold * getCollision(int i);
00106
00107 ~BulletPhysics()
00108 {
00109 }
00110 ;
00111
00112 private:
00113 btHfFluidRigidCollisionConfiguration * collisionConfiguration;
00114 btCollisionDispatcher * dispatcher;
00115 btConstraintSolver * solver;
00116 btBroadphaseInterface * inter;
00117 btHfFluid* fluid;
00118
00119 osgOcean::OceanTechnique* oceanSurface;
00120
00121 void cleanManifolds();
00122 btCollisionShape* GetCSFromOSG(osg::Node * node, collisionShapeType_t ctype);
00123 btConvexShape* GetConvexCSFromOSG(osg::Node * node, collisionShapeType_t ctype);
00124
00125 void updateOceanSurface();
00126
00127 };
00128
00129 #endif
00130