more refactoring, removed PhysicsInterface, cleaned up demos to make use of btDynamicsWorld derived classes.
removed two cached optimizations, type in btTransform and cached inverse transform (todo: test performance impact) committed fixes that make the code adhere to 'who creates it, also destroys it'
This commit is contained in:
@@ -15,7 +15,6 @@ subject to the following restrictions:
|
||||
|
||||
#include "BspConverter.h"
|
||||
#include "BspLoader.h"
|
||||
#include "CcdPhysicsEnvironment.h"
|
||||
#include "LinearMath/btVector3.h"
|
||||
|
||||
void BspConverter::convertBsp(BspLoader& bspLoader,float scaling)
|
||||
|
||||
@@ -13,9 +13,6 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "CcdPhysicsEnvironment.h"
|
||||
#include "CcdPhysicsController.h"
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
@@ -31,7 +28,6 @@ subject to the following restrictions:
|
||||
#include "BspConverter.h"
|
||||
#endif //QUAKE_BSP_IMPORTING
|
||||
|
||||
#include "PHY_Pro.h"
|
||||
#include "BMF_Api.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
@@ -76,7 +72,9 @@ public:
|
||||
//this create an internal copy of the vertices
|
||||
btCollisionShape* shape = new btConvexHullShape(&vertices[0],vertices.size());
|
||||
|
||||
m_demoApp->localCreatePhysicsObject(isDynamic, mass, startTransform,shape);
|
||||
btRigidBody* body = m_demoApp->localCreateRigidBody(isDynamic, mass, startTransform,shape);
|
||||
assert(body);
|
||||
m_demoApp->getDynamicsWorld()->addCollisionObject( body );
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -124,6 +122,11 @@ int main(int argc,char** argv)
|
||||
return glutmain(argc, argv,640,480,"Bullet Quake BSP Physics Viewer http://bullet.sourceforge.net",bspDemo);
|
||||
}
|
||||
|
||||
BspDemo::~BspDemo()
|
||||
{
|
||||
delete m_dynamicsWorld;
|
||||
}
|
||||
|
||||
void BspDemo::initPhysics(char* bspfilename)
|
||||
{
|
||||
|
||||
@@ -132,16 +135,7 @@ void BspDemo::initPhysics(char* bspfilename)
|
||||
m_forwardAxis = 1;
|
||||
|
||||
///Setup a Physics Simulation Environment
|
||||
btCollisionDispatcher* dispatcher = new btCollisionDispatcher();
|
||||
btVector3 worldAabbMin(-10000,-10000,-10000);
|
||||
btVector3 worldAabbMax(10000,10000,10000);
|
||||
btOverlappingPairCache* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);
|
||||
//BroadphaseInterface* broadphase = new btSimpleBroadphase();
|
||||
m_physicsEnvironmentPtr = new CcdPhysicsEnvironment(dispatcher,broadphase);
|
||||
m_physicsEnvironmentPtr->setDeactivationTime(2.f);
|
||||
m_physicsEnvironmentPtr->setGravity(0,0,-10);
|
||||
m_physicsEnvironmentPtr->setDebugDrawer(&debugDrawer);
|
||||
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld();
|
||||
|
||||
|
||||
#ifdef QUAKE_BSP_IMPORTING
|
||||
@@ -192,7 +186,7 @@ void BspDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
m_physicsEnvironmentPtr->proceedDeltaTime(0.f,deltaTime);
|
||||
m_dynamicsWorld->stepSimulation(deltaTime);
|
||||
|
||||
renderme();
|
||||
|
||||
@@ -208,7 +202,7 @@ void BspDemo::displayCallback(void) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
m_physicsEnvironmentPtr->UpdateAabbs(deltaTime);
|
||||
//m_dynamicsWorld->UpdateAabbs(deltaTime);
|
||||
|
||||
renderme();
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ class BspDemo : public DemoApplication
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~BspDemo();
|
||||
|
||||
void initPhysics(char* bspfilename);
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
@@ -21,10 +21,8 @@ subject to the following restrictions:
|
||||
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
|
||||
#include "GLDebugDrawer.h"
|
||||
|
||||
#include "PHY_Pro.h"
|
||||
#include "BMF_Api.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
@@ -154,16 +152,9 @@ void CcdPhysicsDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
/*
|
||||
if (m_physicsEnvironmentPtr)
|
||||
{
|
||||
m_physicsEnvironmentPtr->UpdateAabbs(deltaTime);
|
||||
//draw contactpoints
|
||||
m_physicsEnvironmentPtr->CallbackTriggers();
|
||||
}
|
||||
*/
|
||||
|
||||
m_dynamicsWorld->updateAabbs();
|
||||
|
||||
|
||||
renderme();
|
||||
|
||||
glFlush();
|
||||
@@ -253,6 +244,8 @@ void CcdPhysicsDemo::initPhysics()
|
||||
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver);
|
||||
|
||||
m_dynamicsWorld->setDebugDrawer(&debugDrawer);
|
||||
|
||||
|
||||
#ifdef USER_DEFINED_FRICTION_MODEL
|
||||
btSequentialImpulseConstraintSolver* solver = (btSequentialImpulseConstraintSolver*) m_physicsEnvironmentPtr->GetConstraintSolver();
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "MyMotionState.h"
|
||||
#include "LinearMath/btPoint3.h"
|
||||
|
||||
MyMotionState::MyMotionState()
|
||||
{
|
||||
m_worldTransform.setIdentity();
|
||||
}
|
||||
|
||||
|
||||
MyMotionState::~MyMotionState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MyMotionState::getWorldPosition(float& posX,float& posY,float& posZ)
|
||||
{
|
||||
posX = m_worldTransform.getOrigin().x();
|
||||
posY = m_worldTransform.getOrigin().y();
|
||||
posZ = m_worldTransform.getOrigin().z();
|
||||
}
|
||||
|
||||
void MyMotionState::getWorldScaling(float& scaleX,float& scaleY,float& scaleZ)
|
||||
{
|
||||
scaleX = 1.;
|
||||
scaleY = 1.;
|
||||
scaleZ = 1.;
|
||||
}
|
||||
|
||||
void MyMotionState::getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)
|
||||
{
|
||||
quatIma0 = m_worldTransform.getRotation().x();
|
||||
quatIma1 = m_worldTransform.getRotation().y();
|
||||
quatIma2 = m_worldTransform.getRotation().z();
|
||||
quatReal = m_worldTransform.getRotation()[3];
|
||||
}
|
||||
|
||||
void MyMotionState::setWorldPosition(float posX,float posY,float posZ)
|
||||
{
|
||||
btPoint3 pos(posX,posY,posZ);
|
||||
m_worldTransform.setOrigin( pos );
|
||||
}
|
||||
|
||||
void MyMotionState::setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)
|
||||
{
|
||||
btQuaternion orn(quatIma0,quatIma1,quatIma2,quatReal);
|
||||
m_worldTransform.setRotation( orn );
|
||||
}
|
||||
|
||||
void MyMotionState::calculateWorldTransformations()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef MY_MOTIONSTATE_H
|
||||
#define MY_MOTIONSTATE_H
|
||||
|
||||
#include "PHY_IMotionState.h"
|
||||
#include <LinearMath/btTransform.h>
|
||||
|
||||
|
||||
class MyMotionState : public PHY_IMotionState
|
||||
|
||||
{
|
||||
public:
|
||||
MyMotionState();
|
||||
|
||||
virtual ~MyMotionState();
|
||||
|
||||
virtual void getWorldPosition(float& posX,float& posY,float& posZ);
|
||||
virtual void getWorldScaling(float& scaleX,float& scaleY,float& scaleZ);
|
||||
virtual void getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal);
|
||||
|
||||
virtual void setWorldPosition(float posX,float posY,float posZ);
|
||||
virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
|
||||
|
||||
virtual void calculateWorldTransformations();
|
||||
|
||||
btTransform m_worldTransform;
|
||||
|
||||
};
|
||||
|
||||
#endif //MY_MOTIONSTATE_H
|
||||
@@ -14,7 +14,7 @@ subject to the following restrictions:
|
||||
*/
|
||||
|
||||
#include "ColladaConverter.h"
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "dae.h"
|
||||
#include "dom/domCOLLADA.h"
|
||||
|
||||
@@ -27,10 +27,9 @@ subject to the following restrictions:
|
||||
#include "BulletCollision/CollisionShapes/btTriangleMesh.h"
|
||||
#include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btTriangleMeshShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h"
|
||||
//#include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h"
|
||||
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
|
||||
|
||||
#include "CcdPhysicsController.h"
|
||||
|
||||
|
||||
char* getLastFileName();
|
||||
@@ -537,18 +536,18 @@ void ColladaConverter::prepareConstraints(ConstraintInput& input)
|
||||
|
||||
daeString orgUri0 = attachRefBody->getRigid_body().getOriginalURI();
|
||||
daeString orgUri1 = attachBody1->getRigid_body().getOriginalURI();
|
||||
CcdPhysicsController* ctrl0=0,*ctrl1=0;
|
||||
btRigidBody* body0=0,*body1=0;
|
||||
|
||||
for (int i=0;i<m_numObjects;i++)
|
||||
{
|
||||
char* bodyName = (char*)m_physObjects[i]->getNewClientInfo();
|
||||
char* bodyName = (char*)m_rigidBodies[i]->m_userObjectPointer;
|
||||
if (!strcmp(bodyName,orgUri0))
|
||||
{
|
||||
ctrl0=m_physObjects[i];
|
||||
body0=m_rigidBodies[i];
|
||||
}
|
||||
if (!strcmp(bodyName,orgUri1))
|
||||
{
|
||||
ctrl1=m_physObjects[i];
|
||||
body1=m_rigidBodies[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -572,8 +571,7 @@ void ColladaConverter::prepareConstraints(ConstraintInput& input)
|
||||
btVector3 angularMax(coneMaxLimit.get(0),coneMaxLimit.get(1),coneMaxLimit.get(2));
|
||||
|
||||
{
|
||||
int constraintId;
|
||||
|
||||
|
||||
btTransform attachFrameRef0;
|
||||
attachFrameRef0 =
|
||||
GetbtTransformFromCOLLADA_DOM
|
||||
@@ -635,11 +633,11 @@ void ColladaConverter::prepareConstraints(ConstraintInput& input)
|
||||
}
|
||||
|
||||
|
||||
if (ctrl0 && ctrl1)
|
||||
if (body0&& body1)
|
||||
{
|
||||
constraintId = createUniversalD6Constraint(
|
||||
ctrl0,
|
||||
ctrl1,
|
||||
createUniversalD6Constraint(
|
||||
body0,
|
||||
body1,
|
||||
attachFrameRef0,
|
||||
attachFrameOther,
|
||||
linearLowerLimits,
|
||||
@@ -699,12 +697,12 @@ void ColladaConverter::PreparePhysicsObject(struct btRigidBodyInput& input, bool
|
||||
|
||||
|
||||
|
||||
CcdPhysicsController* ctrl = createPhysicsObject(isDynamics,mass,startTransform,colShape);
|
||||
if (ctrl)
|
||||
btRigidBody* body= createRigidBody(isDynamics,mass,startTransform,colShape);
|
||||
if (body)
|
||||
{
|
||||
//for bodyName lookup in constraints
|
||||
ctrl->setNewClientInfo((void*)input.m_bodyName);
|
||||
m_physObjects[m_numObjects] = ctrl;
|
||||
body->m_userObjectPointer = (void*)input.m_bodyName;
|
||||
m_rigidBodies[m_numObjects] = body;
|
||||
m_numObjects++;
|
||||
}
|
||||
|
||||
@@ -733,12 +731,8 @@ bool ColladaConverter::saveAs(const char* filename)
|
||||
|
||||
{
|
||||
|
||||
float np[3];
|
||||
btVector3 np = m_rigidBodies[i]->m_worldTransform.getOrigin();
|
||||
domFloat3 newPos = m_colladadomNodes[i]->getTranslate_array().get(0)->getValue();
|
||||
m_physObjects[i]->GetMotionState()->getWorldPosition(
|
||||
np[0],
|
||||
np[1],
|
||||
np[2]);
|
||||
newPos.set(0,np[0]);
|
||||
newPos.set(1,np[1]);
|
||||
newPos.set(2,np[2]);
|
||||
@@ -764,7 +758,7 @@ bool ColladaConverter::saveAs(const char* filename)
|
||||
}
|
||||
|
||||
{
|
||||
btQuaternion quat = m_physObjects[i]->getRigidBody()->getCenterOfMassTransform().getRotation();
|
||||
btQuaternion quat = m_rigidBodies[i]->getCenterOfMassTransform().getRotation();
|
||||
btVector3 axis(quat.getX(),quat.getY(),quat.getZ());
|
||||
axis[3] = 0.f;
|
||||
//check for axis length
|
||||
@@ -1059,7 +1053,11 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
|
||||
} else
|
||||
{
|
||||
printf("static concave triangle <mesh> added\n");
|
||||
rbOutput.m_colShape = new btTriangleMeshShape(trimesh);
|
||||
//rbOutput.m_colShape = new btTriangleMeshShape(trimesh);//btBvhTriangleMeshShape(trimesh);
|
||||
//rbOutput.m_colShape = new btBvhTriangleMeshShape(trimesh);
|
||||
rbOutput.m_colShape = new btConvexTriangleMeshShape(trimesh);
|
||||
|
||||
//btTriangleMeshShape
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,8 +22,9 @@ subject to the following restrictions:
|
||||
#include "LinearMath/btVector3.h"
|
||||
|
||||
class btCollisionShape;
|
||||
class PHY_IPhysicsController;
|
||||
class CcdPhysicsController;
|
||||
class btRigidBody;
|
||||
class btTypedConstraint;
|
||||
|
||||
class ConstraintInput;
|
||||
|
||||
//use some reasonable number here
|
||||
@@ -42,7 +43,7 @@ protected:
|
||||
const char* m_filename;
|
||||
|
||||
int m_numObjects;
|
||||
CcdPhysicsController* m_physObjects[COLLADA_CONVERTER_MAX_NUM_OBJECTS];
|
||||
btRigidBody* m_rigidBodies[COLLADA_CONVERTER_MAX_NUM_OBJECTS];
|
||||
|
||||
void PreparePhysicsObject(struct btRigidBodyInput& input, bool isDynamics, float mass,btCollisionShape* colShape);
|
||||
|
||||
@@ -66,8 +67,8 @@ public:
|
||||
bool convert();
|
||||
|
||||
///those 2 virtuals are called for each constraint/physics object
|
||||
virtual int createUniversalD6Constraint(
|
||||
class PHY_IPhysicsController* ctrlRef,class PHY_IPhysicsController* ctrlOther,
|
||||
virtual btTypedConstraint* createUniversalD6Constraint(
|
||||
class btRigidBody* body0,class btRigidBody* otherBody,
|
||||
btTransform& localAttachmentFrameRef,
|
||||
btTransform& localAttachmentOther,
|
||||
const btVector3& linearMinLimits,
|
||||
@@ -76,7 +77,7 @@ public:
|
||||
const btVector3& angularMaxLimits
|
||||
) = 0;
|
||||
|
||||
virtual CcdPhysicsController* createPhysicsObject(bool isDynamic,
|
||||
virtual btRigidBody* createRigidBody(bool isDynamic,
|
||||
float mass,
|
||||
const btTransform& startTransform,
|
||||
btCollisionShape* shape) = 0;
|
||||
|
||||
@@ -13,8 +13,6 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "CcdPhysicsEnvironment.h"
|
||||
#include "CcdPhysicsController.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
@@ -26,7 +24,7 @@ subject to the following restrictions:
|
||||
//COLLADA_DOM should compile under all platforms, and is enabled by default.
|
||||
|
||||
#include "ColladaConverter.h"
|
||||
#include "PHY_Pro.h"
|
||||
|
||||
#include "BMF_Api.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
@@ -35,6 +33,7 @@ float deltaTime = 1.f/60.f;
|
||||
#include "ColladaDemo.h"
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "GlutStuff.h"
|
||||
int maxObj = 1;
|
||||
|
||||
///custom version of the converter, that creates physics objects/constraints
|
||||
class MyColladaConverter : public ColladaConverter
|
||||
@@ -48,8 +47,8 @@ class MyColladaConverter : public ColladaConverter
|
||||
}
|
||||
|
||||
///those 2 virtuals are called for each constraint/physics object
|
||||
virtual int createUniversalD6Constraint(
|
||||
class PHY_IPhysicsController* ctrlRef,class PHY_IPhysicsController* ctrlOther,
|
||||
virtual btTypedConstraint* createUniversalD6Constraint(
|
||||
class btRigidBody* bodyRef,class btRigidBody* bodyOther,
|
||||
btTransform& localAttachmentFrameRef,
|
||||
btTransform& localAttachmentOther,
|
||||
const btVector3& linearMinLimits,
|
||||
@@ -58,30 +57,49 @@ class MyColladaConverter : public ColladaConverter
|
||||
const btVector3& angularMaxLimits
|
||||
)
|
||||
{
|
||||
return m_demoApp->getPhysicsEnvironment()->createUniversalD6Constraint(
|
||||
ctrlRef,ctrlOther,
|
||||
localAttachmentFrameRef,
|
||||
localAttachmentOther,
|
||||
linearMinLimits,
|
||||
linearMaxLimits,
|
||||
angularMinLimits,
|
||||
angularMaxLimits
|
||||
);
|
||||
if (bodyRef && bodyOther)
|
||||
{
|
||||
btGeneric6DofConstraint* genericConstraint = new btGeneric6DofConstraint(
|
||||
*bodyRef,*bodyOther,
|
||||
localAttachmentFrameRef,localAttachmentOther);
|
||||
|
||||
genericConstraint->setLinearLowerLimit(linearMinLimits);
|
||||
genericConstraint->setLinearUpperLimit(linearMaxLimits);
|
||||
genericConstraint->setAngularLowerLimit(angularMinLimits);
|
||||
genericConstraint->setAngularUpperLimit(angularMaxLimits);
|
||||
|
||||
m_demoApp->getDynamicsWorld()->addConstraint( genericConstraint );
|
||||
|
||||
return genericConstraint;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual CcdPhysicsController* createPhysicsObject(bool isDynamic,
|
||||
virtual btRigidBody* createRigidBody(bool isDynamic,
|
||||
float mass,
|
||||
const btTransform& startTransform,
|
||||
btCollisionShape* shape)
|
||||
{
|
||||
CcdPhysicsController* ctrl = m_demoApp->localCreatePhysicsObject(isDynamic, mass, startTransform,shape);
|
||||
return ctrl;
|
||||
if (!isDynamic)
|
||||
{
|
||||
printf("nondyna\n");
|
||||
} else
|
||||
{
|
||||
if (!maxObj)
|
||||
return 0;
|
||||
maxObj--;
|
||||
}
|
||||
|
||||
|
||||
btRigidBody* body = m_demoApp->localCreateRigidBody(isDynamic, mass, startTransform,shape);
|
||||
m_demoApp->getDynamicsWorld()->addCollisionObject(body);
|
||||
return body;
|
||||
}
|
||||
|
||||
|
||||
virtual void setGravity(const btVector3& grav)
|
||||
{
|
||||
m_demoApp->getPhysicsEnvironment()->setGravity(grav.getX(),grav.getY(),grav.getZ());
|
||||
m_demoApp->setGravity(grav);
|
||||
}
|
||||
virtual void setCameraInfo(const btVector3& camUp,int forwardAxis)
|
||||
{
|
||||
@@ -141,16 +159,11 @@ void ColladaDemo::initPhysics(const char* filename)
|
||||
m_cameraUp = btVector3(0,0,1);
|
||||
m_forwardAxis = 1;
|
||||
|
||||
///Setup a Physics Simulation Environment
|
||||
btCollisionDispatcher* dispatcher = new btCollisionDispatcher();
|
||||
btVector3 worldAabbMin(-10000,-10000,-10000);
|
||||
btVector3 worldAabbMax(10000,10000,10000);
|
||||
btOverlappingPairCache* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);
|
||||
//BroadphaseInterface* broadphase = new btSimpleBroadphase();
|
||||
m_physicsEnvironmentPtr = new CcdPhysicsEnvironment(dispatcher,broadphase);
|
||||
m_physicsEnvironmentPtr->setDeactivationTime(2.f);
|
||||
m_physicsEnvironmentPtr->setGravity(0,0,-10);
|
||||
m_physicsEnvironmentPtr->setDebugDrawer(&debugDrawer);
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld();
|
||||
//m_dynamicsWorld = new btSimpleDynamicsWorld();
|
||||
|
||||
m_dynamicsWorld->setDebugDrawer(&debugDrawer);
|
||||
|
||||
|
||||
MyColladaConverter* converter = new MyColladaConverter(this);
|
||||
|
||||
@@ -174,7 +187,7 @@ void ColladaDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
m_physicsEnvironmentPtr->proceedDeltaTime(0.f,deltaTime);
|
||||
m_dynamicsWorld->stepSimulation(deltaTime);
|
||||
|
||||
renderme();
|
||||
|
||||
@@ -190,7 +203,7 @@ void ColladaDemo::displayCallback(void) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
m_physicsEnvironmentPtr->UpdateAabbs(deltaTime);
|
||||
m_dynamicsWorld->updateAabbs();
|
||||
|
||||
renderme();
|
||||
|
||||
|
||||
@@ -13,13 +13,9 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "CcdPhysicsEnvironment.h"
|
||||
#include "CcdPhysicsController.h"
|
||||
#include "MyMotionState.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "PHY_Pro.h"
|
||||
#include "ConcaveDemo.h"
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "GlutStuff.h"
|
||||
@@ -159,30 +155,31 @@ void ConcaveDemo::initPhysics()
|
||||
|
||||
btOverlappingPairCache* broadphase = new btSimpleBroadphase();
|
||||
|
||||
|
||||
m_physicsEnvironmentPtr = new CcdPhysicsEnvironment(dispatcher,broadphase);
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld();
|
||||
|
||||
bool isDynamic = false;
|
||||
bool isDynamic = false;
|
||||
float mass = 0.f;
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(0,-2,0));
|
||||
startTransform.setOrigin(btVector3(0,0,0));
|
||||
|
||||
CcdPhysicsController* staticTrimesh = localCreatePhysicsObject(isDynamic, mass, startTransform,trimeshShape);
|
||||
btRigidBody* staticBody = localCreateRigidBody(isDynamic, mass, startTransform,trimeshShape);
|
||||
|
||||
staticBody->m_collisionFlags |=btCollisionObject::isStatic;
|
||||
|
||||
getDynamicsWorld()->addCollisionObject(staticBody);
|
||||
//enable custom material callback
|
||||
staticTrimesh->getRigidBody()->m_collisionFlags |= btCollisionObject::customMaterialCallback;
|
||||
staticBody->m_collisionFlags |= btCollisionObject::customMaterialCallback;
|
||||
|
||||
{
|
||||
for (int i=0;i<10;i++)
|
||||
{
|
||||
btCollisionShape* boxShape = new btBoxShape(btVector3(1,1,1));
|
||||
startTransform.setOrigin(btVector3(2*i,1,1));
|
||||
localCreatePhysicsObject(true, 1, startTransform,boxShape);
|
||||
getDynamicsWorld()->addCollisionObject(localCreateRigidBody(true, 1, startTransform,boxShape));
|
||||
}
|
||||
}
|
||||
m_physicsEnvironmentPtr->setGravity(-1,-10,1);
|
||||
|
||||
m_physicsEnvironmentPtr->setDebugDrawer(&debugDrawer);
|
||||
}
|
||||
|
||||
void ConcaveDemo::clientMoveAndDisplay()
|
||||
@@ -191,7 +188,7 @@ void ConcaveDemo::clientMoveAndDisplay()
|
||||
|
||||
float deltaTime = 1.f/60.f;
|
||||
|
||||
m_physicsEnvironmentPtr->proceedDeltaTime(0.f,deltaTime);
|
||||
m_dynamicsWorld->stepSimulation(deltaTime);
|
||||
|
||||
renderme();
|
||||
|
||||
@@ -202,7 +199,7 @@ void ConcaveDemo::clientMoveAndDisplay()
|
||||
|
||||
void ConcaveDemo::clientResetScene()
|
||||
{
|
||||
int numObj = m_physicsEnvironmentPtr->GetNumControllers();
|
||||
/*int numObj = m_physicsEnvironmentPtr->GetNumControllers();
|
||||
|
||||
//skip ground
|
||||
for (int i=1;i<numObj;i++)
|
||||
@@ -213,6 +210,8 @@ void ConcaveDemo::clientResetScene()
|
||||
ctrl->SetLinearVelocity(0,0,0,0);
|
||||
ctrl->SetAngularVelocity(0,0,0,0);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "MyMotionState.h"
|
||||
#include "LinearMath/btPoint3.h"
|
||||
|
||||
MyMotionState::MyMotionState()
|
||||
{
|
||||
m_worldTransform.setIdentity();
|
||||
}
|
||||
|
||||
|
||||
MyMotionState::~MyMotionState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MyMotionState::getWorldPosition(float& posX,float& posY,float& posZ)
|
||||
{
|
||||
posX = m_worldTransform.getOrigin().x();
|
||||
posY = m_worldTransform.getOrigin().y();
|
||||
posZ = m_worldTransform.getOrigin().z();
|
||||
}
|
||||
|
||||
void MyMotionState::getWorldScaling(float& scaleX,float& scaleY,float& scaleZ)
|
||||
{
|
||||
scaleX = 1.;
|
||||
scaleY = 1.;
|
||||
scaleZ = 1.;
|
||||
}
|
||||
|
||||
void MyMotionState::getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)
|
||||
{
|
||||
quatIma0 = m_worldTransform.getRotation().x();
|
||||
quatIma1 = m_worldTransform.getRotation().y();
|
||||
quatIma2 = m_worldTransform.getRotation().z();
|
||||
quatReal = m_worldTransform.getRotation()[3];
|
||||
}
|
||||
|
||||
void MyMotionState::setWorldPosition(float posX,float posY,float posZ)
|
||||
{
|
||||
btPoint3 pos(posX,posY,posZ);
|
||||
m_worldTransform.setOrigin( pos );
|
||||
}
|
||||
|
||||
void MyMotionState::setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)
|
||||
{
|
||||
btQuaternion orn(quatIma0,quatIma1,quatIma2,quatReal);
|
||||
m_worldTransform.setRotation( orn );
|
||||
}
|
||||
|
||||
void MyMotionState::calculateWorldTransformations()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef MY_MOTIONSTATE_H
|
||||
#define MY_MOTIONSTATE_H
|
||||
|
||||
#include "PHY_IMotionState.h"
|
||||
#include <LinearMath/btTransform.h>
|
||||
|
||||
|
||||
class MyMotionState : public PHY_IMotionState
|
||||
|
||||
{
|
||||
public:
|
||||
MyMotionState();
|
||||
|
||||
virtual ~MyMotionState();
|
||||
|
||||
virtual void getWorldPosition(float& posX,float& posY,float& posZ);
|
||||
virtual void getWorldScaling(float& scaleX,float& scaleY,float& scaleZ);
|
||||
virtual void getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal);
|
||||
|
||||
virtual void setWorldPosition(float posX,float posY,float posZ);
|
||||
virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
|
||||
|
||||
virtual void calculateWorldTransformations();
|
||||
|
||||
btTransform m_worldTransform;
|
||||
|
||||
};
|
||||
|
||||
#endif //MY_MOTIONSTATE_H
|
||||
@@ -13,15 +13,12 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "CcdPhysicsEnvironment.h"
|
||||
#include "CcdPhysicsController.h"
|
||||
#include "MyMotionState.h"
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
|
||||
#include "GLDebugDrawer.h"
|
||||
|
||||
#include "PHY_Pro.h"
|
||||
#include "BMF_Api.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
@@ -61,10 +58,7 @@ void ConstraintDemo::initPhysics()
|
||||
btOverlappingPairCache* broadphase = new btSimpleBroadphase();
|
||||
|
||||
|
||||
m_physicsEnvironmentPtr = new CcdPhysicsEnvironment(dispatcher,broadphase);
|
||||
m_physicsEnvironmentPtr->setDeactivationTime(0.f);
|
||||
m_physicsEnvironmentPtr->setGravity(0,-10,0);
|
||||
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld();
|
||||
|
||||
btCollisionShape* shape = new btBoxShape(btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS));
|
||||
btTransform trans;
|
||||
@@ -74,10 +68,12 @@ void ConstraintDemo::initPhysics()
|
||||
bool isDynamic = false;
|
||||
float mass = 1.f;
|
||||
|
||||
CcdPhysicsController* ctrl0 = localCreatePhysicsObject( isDynamic,mass,trans,shape);
|
||||
btRigidBody* body0 = localCreateRigidBody( isDynamic,mass,trans,shape);
|
||||
getDynamicsWorld()->addCollisionObject(body0);
|
||||
trans.setOrigin(btVector3(2*CUBE_HALF_EXTENTS,20,0));
|
||||
isDynamic = true;
|
||||
CcdPhysicsController* ctrl1 = localCreatePhysicsObject( isDynamic,mass,trans,shape);
|
||||
btRigidBody* body1 = localCreateRigidBody( isDynamic,mass,trans,shape);
|
||||
getDynamicsWorld()->addCollisionObject(body1);
|
||||
|
||||
|
||||
clientResetScene();
|
||||
@@ -85,21 +81,17 @@ void ConstraintDemo::initPhysics()
|
||||
{
|
||||
int constraintId;
|
||||
|
||||
float pivotX=CUBE_HALF_EXTENTS,
|
||||
pivotY=-CUBE_HALF_EXTENTS,
|
||||
pivotZ=-CUBE_HALF_EXTENTS;
|
||||
float axisX=0,axisY=0,axisZ=1;
|
||||
btVector3 pivotInA(CUBE_HALF_EXTENTS,-CUBE_HALF_EXTENTS,-CUBE_HALF_EXTENTS);
|
||||
btVector3 axisInA(0,0,1);
|
||||
|
||||
btVector3 pivotInB = body1 ? body1->getCenterOfMassTransform().inverse()(body0->getCenterOfMassTransform()(pivotInA)) : pivotInA;
|
||||
btVector3 axisInB = body1?
|
||||
(body1->getCenterOfMassTransform().getBasis().inverse()*(body1->getCenterOfMassTransform().getBasis() * axisInA)) :
|
||||
body0->getCenterOfMassTransform().getBasis() * axisInA;
|
||||
|
||||
constraintId =m_physicsEnvironmentPtr->createConstraint(
|
||||
ctrl0,
|
||||
ctrl1,
|
||||
PHY_POINT2POINT_CONSTRAINT,
|
||||
//PHY_GENERIC_6DOF_CONSTRAINT,//can leave any of the 6 degree of freedom 'free' or 'locked'
|
||||
//PHY_LINEHINGE_CONSTRAINT,
|
||||
pivotX,pivotY,pivotZ,
|
||||
axisX,axisY,axisZ
|
||||
);
|
||||
btTypedConstraint* p2p = new btPoint2PointConstraint(*body0,*body1,pivotInA,pivotInB);
|
||||
|
||||
m_dynamicsWorld->addConstraint(p2p);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -112,8 +104,7 @@ void ConstraintDemo::clientMoveAndDisplay()
|
||||
|
||||
float deltaTime = 1.f/60.f;
|
||||
|
||||
m_physicsEnvironmentPtr->proceedDeltaTime(0.f,deltaTime);
|
||||
|
||||
m_dynamicsWorld->stepSimulation(deltaTime);
|
||||
renderme();
|
||||
|
||||
glFlush();
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "MyMotionState.h"
|
||||
#include "LinearMath/btPoint3.h"
|
||||
|
||||
MyMotionState::MyMotionState()
|
||||
{
|
||||
m_worldTransform.setIdentity();
|
||||
}
|
||||
|
||||
|
||||
MyMotionState::~MyMotionState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MyMotionState::getWorldPosition(float& posX,float& posY,float& posZ)
|
||||
{
|
||||
posX = m_worldTransform.getOrigin().x();
|
||||
posY = m_worldTransform.getOrigin().y();
|
||||
posZ = m_worldTransform.getOrigin().z();
|
||||
}
|
||||
|
||||
void MyMotionState::getWorldScaling(float& scaleX,float& scaleY,float& scaleZ)
|
||||
{
|
||||
scaleX = 1.;
|
||||
scaleY = 1.;
|
||||
scaleZ = 1.;
|
||||
}
|
||||
|
||||
void MyMotionState::getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)
|
||||
{
|
||||
quatIma0 = m_worldTransform.getRotation().x();
|
||||
quatIma1 = m_worldTransform.getRotation().y();
|
||||
quatIma2 = m_worldTransform.getRotation().z();
|
||||
quatReal = m_worldTransform.getRotation()[3];
|
||||
}
|
||||
|
||||
void MyMotionState::setWorldPosition(float posX,float posY,float posZ)
|
||||
{
|
||||
btPoint3 pos(posX,posY,posZ);
|
||||
m_worldTransform.setOrigin( pos );
|
||||
}
|
||||
|
||||
void MyMotionState::setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)
|
||||
{
|
||||
btQuaternion orn(quatIma0,quatIma1,quatIma2,quatReal);
|
||||
m_worldTransform.setRotation( orn );
|
||||
}
|
||||
|
||||
void MyMotionState::calculateWorldTransformations()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef MY_MOTIONSTATE_H
|
||||
#define MY_MOTIONSTATE_H
|
||||
|
||||
#include "PHY_IMotionState.h"
|
||||
#include <LinearMath/btTransform.h>
|
||||
|
||||
|
||||
class MyMotionState : public PHY_IMotionState
|
||||
|
||||
{
|
||||
public:
|
||||
MyMotionState();
|
||||
|
||||
virtual ~MyMotionState();
|
||||
|
||||
virtual void getWorldPosition(float& posX,float& posY,float& posZ);
|
||||
virtual void getWorldScaling(float& scaleX,float& scaleY,float& scaleZ);
|
||||
virtual void getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal);
|
||||
|
||||
virtual void setWorldPosition(float posX,float posY,float posZ);
|
||||
virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
|
||||
|
||||
virtual void calculateWorldTransformations();
|
||||
|
||||
btTransform m_worldTransform;
|
||||
|
||||
};
|
||||
|
||||
#endif //MY_MOTIONSTATE_H
|
||||
@@ -16,18 +16,12 @@ subject to the following restrictions:
|
||||
#include "cd_wavefront.h"
|
||||
#include "ConvexBuilder.h"
|
||||
|
||||
|
||||
#include "CcdPhysicsEnvironment.h"
|
||||
#include "CcdPhysicsController.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
|
||||
#include "GLDebugDrawer.h"
|
||||
|
||||
|
||||
#include "PHY_Pro.h"
|
||||
#include "BMF_Api.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
@@ -90,16 +84,14 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
btOverlappingPairCache* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);
|
||||
//OverlappingPairCache* broadphase = new btSimpleBroadphase();
|
||||
|
||||
m_physicsEnvironmentPtr = new CcdPhysicsEnvironment(dispatcher,broadphase);
|
||||
m_physicsEnvironmentPtr->setDeactivationTime(2.f);
|
||||
|
||||
m_physicsEnvironmentPtr->setGravity(0,-10,0);
|
||||
btConstraintSolver* solver = new btSequentialImpulseConstraintSolver();
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver);
|
||||
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(0,-4,0));
|
||||
|
||||
localCreatePhysicsObject(false,0,startTransform,new btBoxShape(btVector3(30,2,30)));
|
||||
localCreateRigidBody(false,0,startTransform,new btBoxShape(btVector3(30,2,30)));
|
||||
|
||||
class MyConvexDecomposition : public ConvexDecomposition::ConvexDecompInterface
|
||||
{
|
||||
@@ -200,8 +192,8 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
btTransform trans;
|
||||
trans.setIdentity();
|
||||
trans.setOrigin(centroid);
|
||||
m_convexDemo->localCreatePhysicsObject(isDynamic, mass, trans,convexShape);
|
||||
|
||||
btRigidBody* body = m_convexDemo->localCreateRigidBody(isDynamic, mass, trans,convexShape);
|
||||
m_convexDemo->getDynamicsWorld()->addCollisionObject(body);
|
||||
mBaseCount+=result.mHullVcount; // advance the 'base index' counter.
|
||||
|
||||
|
||||
@@ -245,7 +237,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(20,2,0));
|
||||
|
||||
localCreatePhysicsObject(isDynamic, mass, startTransform,convexShape);
|
||||
localCreateRigidBody(isDynamic, mass, startTransform,convexShape);
|
||||
|
||||
}
|
||||
|
||||
@@ -296,7 +288,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
}
|
||||
|
||||
|
||||
m_physicsEnvironmentPtr->setDebugDrawer(&debugDrawer);
|
||||
m_dynamicsWorld->setDebugDrawer(&debugDrawer);
|
||||
|
||||
}
|
||||
|
||||
@@ -305,8 +297,7 @@ void ConvexDecompositionDemo::clientMoveAndDisplay()
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
|
||||
m_physicsEnvironmentPtr->proceedDeltaTime(0.f,deltaTime);
|
||||
m_dynamicsWorld->stepSimulation(deltaTime);
|
||||
|
||||
renderme();
|
||||
|
||||
@@ -322,7 +313,7 @@ void ConvexDecompositionDemo::displayCallback(void) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
m_physicsEnvironmentPtr->UpdateAabbs(deltaTime);
|
||||
m_dynamicsWorld->updateAabbs();
|
||||
|
||||
renderme();
|
||||
|
||||
|
||||
@@ -18,10 +18,7 @@ subject to the following restrictions:
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include "BulletDynamics/Dynamics/btDynamicsWorld.h"
|
||||
|
||||
#include "CcdPhysicsEnvironment.h"
|
||||
#include "CcdPhysicsController.h"
|
||||
#include "BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h"//picking
|
||||
#include "PHY_Pro.h"
|
||||
#include "BulletCollision/CollisionShapes/btCollisionShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btBoxShape.h"
|
||||
#include "GL_ShapeDrawer.h"
|
||||
@@ -31,8 +28,6 @@ subject to the following restrictions:
|
||||
|
||||
int numObjects = 0;
|
||||
const int maxNumObjects = 16384;
|
||||
DefaultMotionState ms[maxNumObjects];
|
||||
CcdPhysicsController* physObjects[maxNumObjects];
|
||||
btTransform startTransforms[maxNumObjects];
|
||||
btCollisionShape* gShapePtr[maxNumObjects];//1 rigidbody has 1 shape (no re-use of shapes)
|
||||
|
||||
@@ -40,9 +35,9 @@ btCollisionShape* gShapePtr[maxNumObjects];//1 rigidbody has 1 shape (no re-use
|
||||
DemoApplication::DemoApplication()
|
||||
//see btIDebugDraw.h for modes
|
||||
:
|
||||
m_physicsEnvironmentPtr(0),
|
||||
m_dynamicsWorld(0),
|
||||
m_pickConstraint(0),
|
||||
m_gravity(0,-10,0),
|
||||
m_cameraDistance(15.0),
|
||||
m_debugMode(0),
|
||||
m_ele(0.f),
|
||||
@@ -340,8 +335,7 @@ void DemoApplication::keyboardCallback(unsigned char key, int x, int y)
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_physicsEnvironmentPtr)
|
||||
m_physicsEnvironmentPtr->setDebugMode(m_debugMode);
|
||||
getDynamicsWorld()->getDebugDrawer()->setDebugMode(m_debugMode);
|
||||
|
||||
glutPostRedisplay();
|
||||
|
||||
@@ -411,27 +405,6 @@ void DemoApplication::shootBox(const btVector3& destination)
|
||||
body->setAngularVelocity(btVector3(0,0,0));
|
||||
}
|
||||
|
||||
if (m_physicsEnvironmentPtr)
|
||||
{
|
||||
bool isDynamic = true;
|
||||
float mass = 1.f;
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity();
|
||||
btVector3 camPos = getCameraPosition();
|
||||
startTransform.setOrigin(camPos);
|
||||
btCollisionShape* boxShape = new btBoxShape(btVector3(1.f,1.f,1.f));
|
||||
|
||||
CcdPhysicsController* newBox = localCreatePhysicsObject(isDynamic, mass, startTransform,boxShape);
|
||||
|
||||
btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]);
|
||||
linVel.normalize();
|
||||
linVel*=m_ShootBoxInitialSpeed;
|
||||
|
||||
newBox->setPosition(camPos[0],camPos[1],camPos[2]);
|
||||
newBox->setOrientation(0,0,0,1);
|
||||
newBox->SetLinearVelocity(linVel[0],linVel[1],linVel[2],false);
|
||||
newBox->SetAngularVelocity(0,0,0,false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -513,11 +486,9 @@ void DemoApplication::mouseFunc(int button, int state, int x, int y)
|
||||
if (rayCallback.HasHit())
|
||||
{
|
||||
|
||||
if (rayCallback.m_collisionObject->m_internalOwner)
|
||||
btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
|
||||
if (body)
|
||||
{
|
||||
btRigidBody* body = (btRigidBody*)rayCallback.m_collisionObject->m_internalOwner;
|
||||
if (body)
|
||||
{
|
||||
body->SetActivationState(ACTIVE_TAG);
|
||||
btVector3 impulse = rayTo;
|
||||
impulse.normalize();
|
||||
@@ -526,39 +497,10 @@ void DemoApplication::mouseFunc(int button, int state, int x, int y)
|
||||
btVector3 relPos = rayCallback.m_hitPointWorld - body->getCenterOfMassPosition();
|
||||
body->applyImpulse(impulse,relPos);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//apply an impulse
|
||||
if (m_physicsEnvironmentPtr)
|
||||
{
|
||||
float hit[3];
|
||||
float normal[3];
|
||||
PHY_IPhysicsController* hitObj = m_physicsEnvironmentPtr->rayTest(0,m_cameraPosition[0],m_cameraPosition[1],m_cameraPosition[2],rayTo.getX(),rayTo.getY(),rayTo.getZ(),hit[0],hit[1],hit[2],normal[0],normal[1],normal[2]);
|
||||
if (hitObj)
|
||||
{
|
||||
CcdPhysicsController* physCtrl = static_cast<CcdPhysicsController*>(hitObj);
|
||||
btRigidBody* body = physCtrl->getRigidBody();
|
||||
if (body)
|
||||
{
|
||||
body->SetActivationState(ACTIVE_TAG);
|
||||
btVector3 impulse = rayTo;
|
||||
impulse.normalize();
|
||||
float impulseStrength = 10.f;
|
||||
impulse *= impulseStrength;
|
||||
btVector3 relPos(
|
||||
hit[0] - body->getCenterOfMassPosition().getX(),
|
||||
hit[1] - body->getCenterOfMassPosition().getY(),
|
||||
hit[2] - body->getCenterOfMassPosition().getZ());
|
||||
|
||||
body->applyImpulse(impulse,relPos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else
|
||||
{
|
||||
@@ -581,10 +523,11 @@ void DemoApplication::mouseFunc(int button, int state, int x, int y)
|
||||
if (rayCallback.HasHit())
|
||||
{
|
||||
|
||||
if (rayCallback.m_collisionObject->m_internalOwner)
|
||||
|
||||
btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
|
||||
if (body)
|
||||
{
|
||||
btRigidBody* body = (btRigidBody*)rayCallback.m_collisionObject->m_internalOwner;
|
||||
if (body && !body->IsStatic())
|
||||
if (!body->IsStatic())
|
||||
{
|
||||
pickedBody = body;
|
||||
pickedBody->SetActivationState(DISABLE_DEACTIVATION);
|
||||
@@ -612,51 +555,6 @@ void DemoApplication::mouseFunc(int button, int state, int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
//add a point to point constraint for picking
|
||||
if (m_physicsEnvironmentPtr)
|
||||
{
|
||||
float hit[3];
|
||||
float normal[3];
|
||||
PHY_IPhysicsController* hitObj = m_physicsEnvironmentPtr->rayTest(0,m_cameraPosition[0],m_cameraPosition[1],m_cameraPosition[2],rayTo.getX(),rayTo.getY(),rayTo.getZ(),hit[0],hit[1],hit[2],normal[0],normal[1],normal[2]);
|
||||
if (hitObj)
|
||||
{
|
||||
|
||||
CcdPhysicsController* physCtrl = static_cast<CcdPhysicsController*>(hitObj);
|
||||
btRigidBody* body = physCtrl->getRigidBody();
|
||||
|
||||
if (body && !body->IsStatic())
|
||||
{
|
||||
pickedBody = body;
|
||||
pickedBody->SetActivationState(DISABLE_DEACTIVATION);
|
||||
|
||||
btVector3 pickPos(hit[0],hit[1],hit[2]);
|
||||
|
||||
btVector3 localPivot = body->getCenterOfMassTransform().inverse() * pickPos;
|
||||
|
||||
gPickingConstraintId = m_physicsEnvironmentPtr->createConstraint(physCtrl,0,PHY_POINT2POINT_CONSTRAINT,
|
||||
localPivot.getX(),
|
||||
localPivot.getY(),
|
||||
localPivot.getZ(),
|
||||
0,0,0);
|
||||
//printf("created constraint %i",gPickingConstraintId);
|
||||
|
||||
//save mouse position for dragging
|
||||
gOldPickingPos = rayTo;
|
||||
|
||||
|
||||
btVector3 eyePos(m_cameraPosition[0],m_cameraPosition[1],m_cameraPosition[2]);
|
||||
|
||||
gOldPickingDist = (pickPos-eyePos).length();
|
||||
|
||||
btPoint2PointConstraint* p2p = static_cast<btPoint2PointConstraint*>(m_physicsEnvironmentPtr->getConstraintById(gPickingConstraintId));
|
||||
if (p2p)
|
||||
{
|
||||
//very weak constraint for picking
|
||||
p2p->m_setting.m_tau = 0.1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
|
||||
@@ -671,17 +569,7 @@ void DemoApplication::mouseFunc(int button, int state, int x, int y)
|
||||
pickedBody = 0;
|
||||
}
|
||||
|
||||
if (gPickingConstraintId && m_physicsEnvironmentPtr)
|
||||
{
|
||||
m_physicsEnvironmentPtr->removeConstraint(gPickingConstraintId);
|
||||
//printf("removed constraint %i",gPickingConstraintId);
|
||||
gPickingConstraintId = 0;
|
||||
pickedBody->ForceActivationState(ACTIVE_TAG);
|
||||
pickedBody->m_deactivationTime = 0.f;
|
||||
pickedBody = 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -717,27 +605,7 @@ void DemoApplication::mouseMotionFunc(int x,int y)
|
||||
|
||||
}
|
||||
|
||||
if (gPickingConstraintId && m_physicsEnvironmentPtr)
|
||||
{
|
||||
|
||||
//move the constraint pivot
|
||||
|
||||
btPoint2PointConstraint* p2p = static_cast<btPoint2PointConstraint*>(m_physicsEnvironmentPtr->getConstraintById(gPickingConstraintId));
|
||||
if (p2p)
|
||||
{
|
||||
//keep it at the same picking distance
|
||||
|
||||
btVector3 newRayTo = getRayTo(x,y);
|
||||
btVector3 eyePos(m_cameraPosition[0],m_cameraPosition[1],m_cameraPosition[2]);
|
||||
btVector3 dir = newRayTo-eyePos;
|
||||
dir.normalize();
|
||||
dir *= gOldPickingDist;
|
||||
|
||||
btVector3 newPos = eyePos + dir;
|
||||
p2p->setPivotB(newPos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -753,82 +621,27 @@ btRigidBody* DemoApplication::localCreateRigidBody(bool isDynamic, float mass, c
|
||||
btRigidBody* body = new btRigidBody(massProps);
|
||||
body->m_collisionShape = shape;
|
||||
body->m_worldTransform = startTransform;
|
||||
body->m_internalOwner = body;
|
||||
body->setMassProps( mass, localInertia);
|
||||
body->setGravity(btVector3(0,-9.8f,0));
|
||||
|
||||
if (!isDynamic)
|
||||
{
|
||||
body->m_collisionFlags = btCollisionObject::isStatic;//??
|
||||
// body->getBroadphaseProxy()->m_collisionFilterGroup = 1;/btCcdConstructionInfo::StaticFilter;
|
||||
// body->getBroadphaseProxy()->m_collisionFilterMask = btCcdConstructionInfo::AllFilter ^ btCcdConstructionInfo::StaticFilter;
|
||||
body->setMassProps( 0.f, localInertia);
|
||||
} else
|
||||
{
|
||||
body->setMassProps( mass, localInertia);
|
||||
body->m_collisionFlags = 0;
|
||||
}
|
||||
|
||||
body->setGravity(m_gravity);
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
|
||||
|
||||
///Very basic import
|
||||
CcdPhysicsController* DemoApplication::localCreatePhysicsObject(bool isDynamic, float mass, const btTransform& startTransform,btCollisionShape* shape)
|
||||
{
|
||||
|
||||
startTransforms[numObjects] = startTransform;
|
||||
|
||||
btCcdConstructionInfo ccdObjectCi;
|
||||
ccdObjectCi.m_friction = 0.5f;
|
||||
|
||||
btTransform tr;
|
||||
tr.setIdentity();
|
||||
|
||||
int i = numObjects;
|
||||
{
|
||||
gShapePtr[i] = shape;
|
||||
gShapePtr[i]->setMargin(0.05f);
|
||||
|
||||
btQuaternion orn = startTransform.getRotation();
|
||||
|
||||
ms[i].setWorldOrientation(orn[0],orn[1],orn[2],orn[3]);
|
||||
ms[i].setWorldPosition(startTransform.getOrigin().getX(),startTransform.getOrigin().getY(),startTransform.getOrigin().getZ());
|
||||
|
||||
ccdObjectCi.m_MotionState = &ms[i];
|
||||
ccdObjectCi.m_gravity = btVector3(0,-9.8,0);
|
||||
ccdObjectCi.m_localInertiaTensor =btVector3(0,0,0);
|
||||
if (!isDynamic)
|
||||
{
|
||||
ccdObjectCi.m_mass = 0.f;
|
||||
ccdObjectCi.m_collisionFlags = btCollisionObject::isStatic;
|
||||
ccdObjectCi.m_collisionFilterGroup = btCcdConstructionInfo::StaticFilter;
|
||||
ccdObjectCi.m_collisionFilterMask = btCcdConstructionInfo::AllFilter ^ btCcdConstructionInfo::StaticFilter;
|
||||
}
|
||||
else
|
||||
{
|
||||
ccdObjectCi.m_mass = mass;
|
||||
ccdObjectCi.m_collisionFlags = 0;
|
||||
}
|
||||
|
||||
btVector3 localInertia(0.f,0.f,0.f);
|
||||
|
||||
if (isDynamic)
|
||||
{
|
||||
gShapePtr[i]->calculateLocalInertia(ccdObjectCi.m_mass,localInertia);
|
||||
}
|
||||
|
||||
ccdObjectCi.m_localInertiaTensor = localInertia;
|
||||
ccdObjectCi.m_collisionShape = gShapePtr[i];
|
||||
|
||||
|
||||
physObjects[i]= new CcdPhysicsController( ccdObjectCi);
|
||||
|
||||
// Only do CCD if motion in one timestep (1.f/60.f) exceeds CUBE_HALF_EXTENTS
|
||||
physObjects[i]->getRigidBody()->m_ccdSquareMotionTreshold = 0.f;
|
||||
|
||||
//Experimental: better estimation of CCD Time of Impact:
|
||||
//physObjects[i]->getRigidBody()->m_ccdSweptShereRadius = 0.5*CUBE_HALF_EXTENTS;
|
||||
|
||||
m_physicsEnvironmentPtr->addCcdPhysicsController( physObjects[i]);
|
||||
|
||||
}
|
||||
|
||||
//return newly created PhysicsController
|
||||
return physObjects[numObjects++];
|
||||
}
|
||||
|
||||
void DemoApplication::renderme()
|
||||
{
|
||||
@@ -950,192 +763,4 @@ void DemoApplication::renderme()
|
||||
|
||||
}
|
||||
|
||||
if (m_physicsEnvironmentPtr)
|
||||
{
|
||||
|
||||
if (getDebugMode() & btIDebugDraw::DBG_DisableBulletLCP)
|
||||
{
|
||||
//don't use Bullet, use quickstep
|
||||
m_physicsEnvironmentPtr->setSolverType(0);
|
||||
} else
|
||||
{
|
||||
//Bullet LCP solver
|
||||
m_physicsEnvironmentPtr->setSolverType(1);
|
||||
}
|
||||
|
||||
if (getDebugMode() & btIDebugDraw::DBG_EnableCCD)
|
||||
{
|
||||
m_physicsEnvironmentPtr->setCcdMode(3);
|
||||
} else
|
||||
{
|
||||
m_physicsEnvironmentPtr->setCcdMode(0);
|
||||
}
|
||||
|
||||
|
||||
bool isSatEnabled = (getDebugMode() & btIDebugDraw::DBG_EnableSatComparison);
|
||||
m_physicsEnvironmentPtr->EnableSatCollisionDetection(isSatEnabled);
|
||||
|
||||
|
||||
int numPhysicsObjects = m_physicsEnvironmentPtr->GetNumControllers();
|
||||
|
||||
int i;
|
||||
|
||||
for (i=0;i<numPhysicsObjects;i++)
|
||||
{
|
||||
|
||||
CcdPhysicsController* ctrl = m_physicsEnvironmentPtr->GetPhysicsController(i);
|
||||
btRigidBody* body = ctrl->getRigidBody();
|
||||
|
||||
body->m_worldTransform.getOpenGLMatrix( m );
|
||||
|
||||
btVector3 wireColor(1.f,1.0f,0.5f); //wants deactivation
|
||||
if (i & 1)
|
||||
{
|
||||
wireColor = btVector3(0.f,0.0f,1.f);
|
||||
}
|
||||
///color differently for active, sleeping, wantsdeactivation states
|
||||
if (ctrl->getRigidBody()->GetActivationState() == 1) //active
|
||||
{
|
||||
if (i & 1)
|
||||
{
|
||||
wireColor += btVector3 (1.f,0.f,0.f);
|
||||
} else
|
||||
{
|
||||
wireColor += btVector3 (.5f,0.f,0.f);
|
||||
}
|
||||
}
|
||||
if (ctrl->getRigidBody()->GetActivationState() == 2) //ISLAND_SLEEPING
|
||||
{
|
||||
if (i & 1)
|
||||
{
|
||||
wireColor += btVector3 (0.f,1.f, 0.f);
|
||||
} else
|
||||
{
|
||||
wireColor += btVector3 (0.f,0.5f,0.f);
|
||||
}
|
||||
}
|
||||
|
||||
char extraDebug[125];
|
||||
sprintf(extraDebug,"Island:%i, Body:%i",ctrl->getRigidBody()->m_islandTag1,ctrl->getRigidBody()->m_debugBodyId);
|
||||
ctrl->getRigidBody()->getCollisionShape()->setExtraDebugInfo(extraDebug);
|
||||
|
||||
float vec[16];
|
||||
btTransform ident;
|
||||
ident.setIdentity();
|
||||
ident.getOpenGLMatrix(vec);
|
||||
|
||||
|
||||
GL_ShapeDrawer::drawOpenGL(m,ctrl->getRigidBody()->getCollisionShape(),wireColor,getDebugMode());
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (!(getDebugMode() & btIDebugDraw::DBG_NoHelpText))
|
||||
{
|
||||
|
||||
float xOffset = 10.f;
|
||||
float yStart = 20.f;
|
||||
|
||||
float yIncr = -2.f;
|
||||
|
||||
char buf[124];
|
||||
|
||||
glColor3f(0, 0, 0);
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
|
||||
|
||||
if ( getDebugMode() & btIDebugDraw::DBG_ProfileTimings)
|
||||
{
|
||||
static int counter = 0;
|
||||
counter++;
|
||||
std::map<std::string, hidden::ProfileBlock*>::iterator iter;
|
||||
for (iter = btProfiler::mProfileBlocks.begin(); iter != btProfiler::mProfileBlocks.end(); ++iter)
|
||||
{
|
||||
char blockTime[128];
|
||||
sprintf(blockTime, "%s: %lf",&((*iter).first[0]),btProfiler::getBlockTime((*iter).first, btProfiler::BLOCK_CYCLE_SECONDS));//BLOCK_TOTAL_PERCENT));
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),blockTime);
|
||||
yStart += yIncr;
|
||||
|
||||
}
|
||||
}
|
||||
#endif //USE_QUICKPROF
|
||||
//profiling << btProfiler::createStatsString(btProfiler::BLOCK_TOTAL_PERCENT);
|
||||
//<< std::endl;
|
||||
|
||||
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"mouse to interact");
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"space to reset");
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"cursor keys and z,x to navigate");
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"i to toggle simulation, s single step");
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"q to quit");
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"d to toggle deactivation");
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"a to draw temporal AABBs");
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"h to toggle help text");
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
|
||||
bool useBulletLCP = !(getDebugMode() & btIDebugDraw::DBG_DisableBulletLCP);
|
||||
|
||||
bool useCCD = (getDebugMode() & btIDebugDraw::DBG_EnableCCD);
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"m Bullet GJK = %i",!isSatEnabled);
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"n Bullet LCP = %i",useBulletLCP);
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"1 CCD mode (adhoc) = %i",useCCD);
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"+- shooting speed = %10.2f",m_ShootBoxInitialSpeed);
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,8 +39,6 @@ subject to the following restrictions:
|
||||
#include "LinearMath/btMatrix3x3.h"
|
||||
#include "LinearMath/btTransform.h"
|
||||
|
||||
class CcdPhysicsEnvironment;
|
||||
class CcdPhysicsController;
|
||||
class btCollisionShape;
|
||||
class btDynamicsWorld;
|
||||
class btRigidBody;
|
||||
@@ -53,12 +51,13 @@ class DemoApplication
|
||||
|
||||
|
||||
///this is the most important class
|
||||
CcdPhysicsEnvironment* m_physicsEnvironmentPtr;
|
||||
|
||||
btDynamicsWorld* m_dynamicsWorld;
|
||||
|
||||
///constraint for mouse picking
|
||||
btTypedConstraint* m_pickConstraint;
|
||||
|
||||
btVector3 m_gravity;
|
||||
|
||||
float m_cameraDistance;
|
||||
int m_debugMode;
|
||||
|
||||
@@ -82,12 +81,16 @@ class DemoApplication
|
||||
bool m_idle;
|
||||
int m_lastKey;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
DemoApplication();
|
||||
|
||||
virtual ~DemoApplication();
|
||||
|
||||
btDynamicsWorld* getDynamicsWorld()
|
||||
{
|
||||
return m_dynamicsWorld;
|
||||
}
|
||||
|
||||
int getDebugMode()
|
||||
{
|
||||
@@ -99,10 +102,6 @@ class DemoApplication
|
||||
m_debugMode = mode;
|
||||
}
|
||||
|
||||
CcdPhysicsEnvironment* getPhysicsEnvironment()
|
||||
{
|
||||
return m_physicsEnvironmentPtr;
|
||||
}
|
||||
|
||||
void setCameraUp(const btVector3& camUp)
|
||||
{
|
||||
@@ -142,10 +141,12 @@ class DemoApplication
|
||||
///Demo functions
|
||||
void shootBox(const btVector3& destination);
|
||||
|
||||
void setGravity(const btVector3& grav)
|
||||
{
|
||||
m_gravity = grav;
|
||||
}
|
||||
btVector3 getRayTo(int x,int y);
|
||||
|
||||
CcdPhysicsController* localCreatePhysicsObject(bool isDynamic, float mass, const btTransform& startTransform,btCollisionShape* shape);
|
||||
|
||||
btRigidBody* localCreateRigidBody(bool isDynamic, float mass, const btTransform& startTransform,btCollisionShape* shape);
|
||||
|
||||
///callback methods by glut
|
||||
|
||||
@@ -226,7 +226,7 @@ void GL_ShapeDrawer::drawOpenGL(float* m, const btCollisionShape* shape, const b
|
||||
|
||||
gluCylinder(quadObj, radius, radius, 2.f*halfHeight, 15, 10);
|
||||
glPopMatrix();
|
||||
glEndList();
|
||||
gluDeleteQuadric(quadObj);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -13,12 +13,9 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "CcdPhysicsEnvironment.h"
|
||||
#include "CcdPhysicsController.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "PHY_Pro.h"
|
||||
#include "UserCollisionAlgorithm.h"
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "GlutStuff.h"
|
||||
@@ -129,7 +126,7 @@ void UserCollisionAlgorithm::initPhysics()
|
||||
dispatcher->registerCollisionCreateFunc(SPHERE_SHAPE_PROXYTYPE,SPHERE_SHAPE_PROXYTYPE,new btSphereSphereCollisionAlgorithm::CreateFunc);
|
||||
|
||||
|
||||
m_physicsEnvironmentPtr = new CcdPhysicsEnvironment(dispatcher,broadphase);
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase);
|
||||
|
||||
bool isDynamic = false;
|
||||
float mass = 0.f;
|
||||
@@ -137,21 +134,23 @@ void UserCollisionAlgorithm::initPhysics()
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(0,-2,0));
|
||||
|
||||
CcdPhysicsController* staticTrimesh = localCreatePhysicsObject(isDynamic, mass, startTransform,trimeshShape);
|
||||
btRigidBody* staticBody= localCreateRigidBody(isDynamic, mass, startTransform,trimeshShape);
|
||||
getDynamicsWorld()->addCollisionObject(staticBody);
|
||||
//enable custom material callback
|
||||
staticTrimesh->getRigidBody()->m_collisionFlags |= btCollisionObject::customMaterialCallback;
|
||||
staticBody->m_collisionFlags |= btCollisionObject::customMaterialCallback;
|
||||
|
||||
{
|
||||
for (int i=0;i<10;i++)
|
||||
{
|
||||
btCollisionShape* sphereShape = new btSphereShape(1);
|
||||
startTransform.setOrigin(btVector3(1,2*i,1));
|
||||
localCreatePhysicsObject(true, 1, startTransform,sphereShape);
|
||||
btRigidBody* body = localCreateRigidBody(true, 1, startTransform,sphereShape);
|
||||
getDynamicsWorld()->addCollisionObject(body);
|
||||
}
|
||||
}
|
||||
m_physicsEnvironmentPtr->setGravity(-1,-10,1);
|
||||
|
||||
m_physicsEnvironmentPtr->setDebugDrawer(&debugDrawer);
|
||||
|
||||
m_dynamicsWorld->setDebugDrawer(&debugDrawer);
|
||||
}
|
||||
|
||||
void UserCollisionAlgorithm::clientMoveAndDisplay()
|
||||
@@ -160,7 +159,7 @@ void UserCollisionAlgorithm::clientMoveAndDisplay()
|
||||
|
||||
float deltaTime = 1.f/60.f;
|
||||
|
||||
m_physicsEnvironmentPtr->proceedDeltaTime(0.f,deltaTime);
|
||||
m_dynamicsWorld->stepSimulation(deltaTime);
|
||||
|
||||
renderme();
|
||||
|
||||
@@ -171,6 +170,7 @@ void UserCollisionAlgorithm::clientMoveAndDisplay()
|
||||
|
||||
void UserCollisionAlgorithm::clientResetScene()
|
||||
{
|
||||
/*
|
||||
int numObj = m_physicsEnvironmentPtr->GetNumControllers();
|
||||
|
||||
//skip ground
|
||||
@@ -182,6 +182,8 @@ void UserCollisionAlgorithm::clientResetScene()
|
||||
ctrl->SetLinearVelocity(0,0,0,0);
|
||||
ctrl->SetAngularVelocity(0,0,0,0);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,8 +25,7 @@ btCollisionObject::btCollisionObject()
|
||||
m_ccdSweptShereRadius(0.f),
|
||||
m_ccdSquareMotionTreshold(0.f)
|
||||
{
|
||||
m_cachedInvertedWorldTransform.setIdentity();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -41,8 +41,6 @@ struct btCollisionObject
|
||||
//it can be either previous or future (predicted) transform
|
||||
btTransform m_interpolationWorldTransform;
|
||||
|
||||
btTransform m_cachedInvertedWorldTransform;
|
||||
|
||||
enum CollisionFlags
|
||||
{
|
||||
isStatic = 1,
|
||||
|
||||
@@ -123,7 +123,6 @@ void btCollisionWorld::performDiscreteCollisionDetection()
|
||||
btVector3 aabbMin,aabbMax;
|
||||
for (size_t i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
m_collisionObjects[i]->m_cachedInvertedWorldTransform = m_collisionObjects[i]->m_worldTransform.inverse();
|
||||
m_collisionObjects[i]->m_collisionShape->getAabb(m_collisionObjects[i]->m_worldTransform,aabbMin,aabbMax);
|
||||
m_broadphasePairCache->setAabb(m_collisionObjects[i]->m_broadphaseHandle,aabbMin,aabbMax);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ public:
|
||||
|
||||
struct LocalRayResult
|
||||
{
|
||||
LocalRayResult(const btCollisionObject* collisionObject,
|
||||
LocalRayResult(btCollisionObject* collisionObject,
|
||||
LocalShapeInfo* localShapeInfo,
|
||||
const btVector3& hitNormalLocal,
|
||||
float hitFraction)
|
||||
@@ -144,7 +144,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
const btCollisionObject* m_collisionObject;
|
||||
btCollisionObject* m_collisionObject;
|
||||
LocalShapeInfo* m_localShapeInfo;
|
||||
const btVector3& m_hitNormalLocal;
|
||||
float m_hitFraction;
|
||||
@@ -167,7 +167,7 @@ public:
|
||||
:m_closestHitFraction(1.f)
|
||||
{
|
||||
}
|
||||
virtual float AddSingleResult(const LocalRayResult& rayResult) = 0;
|
||||
virtual float AddSingleResult(LocalRayResult& rayResult) = 0;
|
||||
};
|
||||
|
||||
struct ClosestRayResultCallback : public RayResultCallback
|
||||
@@ -184,9 +184,9 @@ public:
|
||||
|
||||
btVector3 m_hitNormalWorld;
|
||||
btVector3 m_hitPointWorld;
|
||||
const btCollisionObject* m_collisionObject;
|
||||
btCollisionObject* m_collisionObject;
|
||||
|
||||
virtual float AddSingleResult(const LocalRayResult& rayResult)
|
||||
virtual float AddSingleResult(LocalRayResult& rayResult)
|
||||
{
|
||||
|
||||
//caller already does the filter on the m_closestHitFraction
|
||||
|
||||
@@ -217,8 +217,9 @@ float btConvexConcaveCollisionAlgorithm::calculateTimeOfImpact(btBroadphaseProxy
|
||||
//btVector3 to = convexbody->m_interpolationWorldTransform.getOrigin();
|
||||
//todo: only do if the motion exceeds the 'radius'
|
||||
|
||||
btTransform convexFromLocal = triBody->m_cachedInvertedWorldTransform * convexbody->m_worldTransform;
|
||||
btTransform convexToLocal = triBody->m_cachedInvertedWorldTransform * convexbody->m_interpolationWorldTransform;
|
||||
btTransform worldToLocalTrimesh = triBody->m_worldTransform.inverse();
|
||||
btTransform convexFromLocal = worldToLocalTrimesh * convexbody->m_worldTransform;
|
||||
btTransform convexToLocal = worldToLocalTrimesh * convexbody->m_interpolationWorldTransform;
|
||||
|
||||
struct LocalTriangleSphereCastCallback : public btTriangleCallback
|
||||
{
|
||||
|
||||
@@ -57,8 +57,8 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
|
||||
return;
|
||||
|
||||
|
||||
btTransform transAInv = m_body0->m_cachedInvertedWorldTransform;
|
||||
btTransform transBInv= m_body1->m_cachedInvertedWorldTransform;
|
||||
btTransform transAInv = m_body0->m_worldTransform.inverse();
|
||||
btTransform transBInv= m_body1->m_worldTransform.inverse();
|
||||
|
||||
//transAInv = m_body0->m_worldTransform.inverse();
|
||||
//transBInv= m_body1->m_worldTransform.inverse();
|
||||
|
||||
@@ -148,14 +148,12 @@ btVector3 btConvexTriangleMeshShape::localGetSupportingVertex(const btVector3& v
|
||||
int btConvexTriangleMeshShape::getNumVertices() const
|
||||
{
|
||||
//cache this?
|
||||
assert(0);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int btConvexTriangleMeshShape::getNumEdges() const
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BT_TRIANGLE_INDEX_VERTEX_ARRAY_H
|
||||
#define BT_TRIANGLE_INDEX_VERTEX_ARRAY_H
|
||||
|
||||
#include "btStridingMeshInterface.h"
|
||||
#include <vector>
|
||||
|
||||
@@ -76,3 +79,4 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#endif //BT_TRIANGLE_INDEX_VERTEX_ARRAY_H
|
||||
|
||||
@@ -16,6 +16,7 @@ subject to the following restrictions:
|
||||
|
||||
#include "btDiscreteDynamicsWorld.h"
|
||||
|
||||
|
||||
//collision detection
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btSimpleBroadphase.h"
|
||||
@@ -32,12 +33,14 @@ subject to the following restrictions:
|
||||
#include "BulletDynamics/Vehicle/btRaycastVehicle.h"
|
||||
#include "BulletDynamics/Vehicle/btVehicleRaycaster.h"
|
||||
#include "BulletDynamics/Vehicle/btWheelInfo.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld()
|
||||
:btDynamicsWorld(),
|
||||
m_constraintSolver(new btSequentialImpulseConstraintSolver)
|
||||
m_constraintSolver(new btSequentialImpulseConstraintSolver),
|
||||
m_debugDrawer(0)
|
||||
{
|
||||
m_islandManager = new btSimulationIslandManager();
|
||||
m_ownsIslandManager = true;
|
||||
@@ -47,11 +50,12 @@ m_constraintSolver(new btSequentialImpulseConstraintSolver)
|
||||
|
||||
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver)
|
||||
:btDynamicsWorld(dispatcher,pairCache),
|
||||
m_constraintSolver(constraintSolver)
|
||||
m_constraintSolver(constraintSolver? constraintSolver: new btSequentialImpulseConstraintSolver),
|
||||
m_debugDrawer(0)
|
||||
{
|
||||
m_islandManager = new btSimulationIslandManager();
|
||||
m_ownsIslandManager = true;
|
||||
m_ownsConstraintSolver = false;
|
||||
m_ownsConstraintSolver = (constraintSolver==0);
|
||||
}
|
||||
|
||||
|
||||
@@ -114,10 +118,9 @@ void btDiscreteDynamicsWorld::updateActivationState(float timeStep)
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
btCollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->m_internalOwner)
|
||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
||||
if (body)
|
||||
{
|
||||
btRigidBody* body = (btRigidBody*)colObj->m_internalOwner;
|
||||
|
||||
body->updateDeactivation(timeStep);
|
||||
|
||||
if (body->wantsSleeping())
|
||||
@@ -190,8 +193,8 @@ void btDiscreteDynamicsWorld::solveContactConstraints(btContactSolverInfo& solve
|
||||
|
||||
};
|
||||
|
||||
btIDebugDraw* debugDraw = 0;
|
||||
InplaceSolverIslandCallback solverCallback( solverInfo, m_constraintSolver, debugDraw);
|
||||
|
||||
InplaceSolverIslandCallback solverCallback( solverInfo, m_constraintSolver, m_debugDrawer);
|
||||
|
||||
|
||||
/// solve all the contact points and contact friction
|
||||
@@ -277,23 +280,60 @@ void btDiscreteDynamicsWorld::calculateSimulationIslands()
|
||||
Profiler::endBlock("IslandUnionFind");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
}
|
||||
|
||||
static void DrawAabb(btIDebugDraw* debugDrawer,const btVector3& from,const btVector3& to,const btVector3& color)
|
||||
{
|
||||
btVector3 halfExtents = (to-from)* 0.5f;
|
||||
btVector3 center = (to+from) *0.5f;
|
||||
int i,j;
|
||||
|
||||
btVector3 edgecoord(1.f,1.f,1.f),pa,pb;
|
||||
for (i=0;i<4;i++)
|
||||
{
|
||||
for (j=0;j<3;j++)
|
||||
{
|
||||
pa = btVector3(edgecoord[0]*halfExtents[0], edgecoord[1]*halfExtents[1],
|
||||
edgecoord[2]*halfExtents[2]);
|
||||
pa+=center;
|
||||
|
||||
int othercoord = j%3;
|
||||
edgecoord[othercoord]*=-1.f;
|
||||
pb = btVector3(edgecoord[0]*halfExtents[0], edgecoord[1]*halfExtents[1],
|
||||
edgecoord[2]*halfExtents[2]);
|
||||
pb+=center;
|
||||
|
||||
debugDrawer->drawLine(pa,pb,color);
|
||||
}
|
||||
edgecoord = btVector3(-1.f,-1.f,-1.f);
|
||||
if (i<3)
|
||||
edgecoord[i]*=-1.f;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void btDiscreteDynamicsWorld::updateAabbs()
|
||||
{
|
||||
btVector3 colorvec(1,0,0);
|
||||
btTransform predictedTrans;
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
btCollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->m_internalOwner)
|
||||
|
||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
||||
if (body)
|
||||
{
|
||||
btRigidBody* body = (btRigidBody*)colObj->m_internalOwner;
|
||||
if (body->IsActive() && (!body->IsStatic()))
|
||||
// if (body->IsActive() && (!body->IsStatic()))
|
||||
{
|
||||
btPoint3 minAabb,maxAabb;
|
||||
colObj->m_collisionShape->getAabb(colObj->m_worldTransform, minAabb,maxAabb);
|
||||
btSimpleBroadphase* bp = (btSimpleBroadphase*)m_broadphasePairCache;
|
||||
bp->setAabb(body->m_broadphaseHandle,minAabb,maxAabb);
|
||||
if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
|
||||
{
|
||||
DrawAabb(m_debugDrawer,minAabb,maxAabb,colorvec);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -305,9 +345,9 @@ void btDiscreteDynamicsWorld::integrateTransforms(float timeStep)
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
btCollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->m_internalOwner)
|
||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
||||
if (body)
|
||||
{
|
||||
btRigidBody* body = (btRigidBody*)colObj->m_internalOwner;
|
||||
if (body->IsActive() && (!body->IsStatic()))
|
||||
{
|
||||
body->predictIntegratedTransform(timeStep, predictedTrans);
|
||||
@@ -324,10 +364,9 @@ void btDiscreteDynamicsWorld::predictUnconstraintMotion(float timeStep)
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
btCollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->m_internalOwner)
|
||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
||||
if (body)
|
||||
{
|
||||
btRigidBody* body = (btRigidBody*)colObj->m_internalOwner;
|
||||
body->m_cachedInvertedWorldTransform = body->m_worldTransform.inverse();
|
||||
if (body->IsActive() && (!body->IsStatic()))
|
||||
{
|
||||
body->applyForces( timeStep);
|
||||
|
||||
@@ -25,6 +25,7 @@ class btSimulationIslandManager;
|
||||
class btTypedConstraint;
|
||||
struct btContactSolverInfo;
|
||||
class btRaycastVehicle;
|
||||
class btIDebugDraw;
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -40,6 +41,8 @@ protected:
|
||||
|
||||
std::vector<btTypedConstraint*> m_constraints;
|
||||
|
||||
btIDebugDraw* m_debugDrawer;
|
||||
|
||||
bool m_ownsIslandManager;
|
||||
bool m_ownsConstraintSolver;
|
||||
|
||||
@@ -49,8 +52,6 @@ protected:
|
||||
|
||||
void integrateTransforms(float timeStep);
|
||||
|
||||
void updateAabbs();
|
||||
|
||||
void calculateSimulationIslands();
|
||||
|
||||
void solveNoncontactConstraints(btContactSolverInfo& solverInfo);
|
||||
@@ -65,7 +66,7 @@ public:
|
||||
|
||||
|
||||
///this btDiscreteDynamicsWorld constructor gets created objects from the user, and will not delete those
|
||||
btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver);
|
||||
btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver=0);
|
||||
|
||||
///this btDiscreteDynamicsWorld will create and own dispatcher, pairCache and constraintSolver, and deletes it in the destructor.
|
||||
btDiscreteDynamicsWorld();
|
||||
@@ -74,6 +75,8 @@ public:
|
||||
|
||||
virtual void stepSimulation( float timeStep);
|
||||
|
||||
virtual void updateAabbs();
|
||||
|
||||
void addConstraint(btTypedConstraint* constraint);
|
||||
|
||||
void removeConstraint(btTypedConstraint* constraint);
|
||||
@@ -97,6 +100,16 @@ public:
|
||||
return this;
|
||||
}
|
||||
|
||||
virtual void setDebugDrawer(btIDebugDraw* debugDrawer)
|
||||
{
|
||||
m_debugDrawer = debugDrawer;
|
||||
}
|
||||
|
||||
virtual btIDebugDraw* getDebugDrawer()
|
||||
{
|
||||
return m_debugDrawer;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //BT_DISCRETE_DYNAMICS_WORLD_H
|
||||
|
||||
@@ -40,11 +40,16 @@ class btDynamicsWorld : public btCollisionWorld
|
||||
///stepSimulation proceeds the simulation over timeStep units
|
||||
virtual void stepSimulation( float timeStep) = 0;
|
||||
|
||||
virtual void updateAabbs() = 0;
|
||||
|
||||
virtual void addConstraint(btTypedConstraint* constraint) {};
|
||||
|
||||
virtual void removeConstraint(btTypedConstraint* constraint) {};
|
||||
|
||||
|
||||
virtual void setDebugDrawer(btIDebugDraw* debugDrawer) = 0;
|
||||
|
||||
virtual btIDebugDraw* getDebugDrawer() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif //BT_DYNAMICS_WORLD_H
|
||||
|
||||
@@ -48,6 +48,9 @@ btRigidBody::btRigidBody( const btMassProps& massProps,btScalar linearDamping,bt
|
||||
|
||||
m_debugBodyId = uniqueId++;
|
||||
|
||||
//m_internalOwner is to allow upcasting from collision object to rigid body
|
||||
m_internalOwner = this;
|
||||
|
||||
setMassProps(massProps.m_mass, massProps.m_inertiaLocal);
|
||||
setDamping(linearDamping, angularDamping);
|
||||
m_worldTransform.setIdentity();
|
||||
|
||||
@@ -65,6 +65,16 @@ public:
|
||||
|
||||
void proceedToTransform(const btTransform& newTrans);
|
||||
|
||||
///to keep collision detection and dynamics separate we don't store a rigidbody pointer
|
||||
///but a rigidbody is derived from btCollisionObject, so we can safely perform an upcast
|
||||
static const btRigidBody* upcast(const btCollisionObject* colObj)
|
||||
{
|
||||
return (const btRigidBody*)colObj->m_internalOwner;
|
||||
}
|
||||
static btRigidBody* upcast(btCollisionObject* colObj)
|
||||
{
|
||||
return (btRigidBody*)colObj->m_internalOwner;
|
||||
}
|
||||
|
||||
/// continuous collision detection needs prediction
|
||||
void predictIntegratedTransform(btScalar step, btTransform& predictedTransform) const;
|
||||
|
||||
@@ -24,14 +24,16 @@ subject to the following restrictions:
|
||||
|
||||
btSimpleDynamicsWorld::btSimpleDynamicsWorld()
|
||||
:m_constraintSolver(new btSequentialImpulseConstraintSolver),
|
||||
m_ownsConstraintSolver(true)
|
||||
m_ownsConstraintSolver(true),
|
||||
m_debugDrawer(0)
|
||||
{
|
||||
}
|
||||
|
||||
btSimpleDynamicsWorld::btSimpleDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver)
|
||||
:btDynamicsWorld(dispatcher,pairCache),
|
||||
m_constraintSolver(constraintSolver),
|
||||
m_ownsConstraintSolver(false)
|
||||
m_ownsConstraintSolver(false),
|
||||
m_debugDrawer(0)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -56,8 +58,8 @@ void btSimpleDynamicsWorld::stepSimulation(float timeStep)
|
||||
int numManifolds = m_dispatcher1->getNumManifolds();
|
||||
btContactSolverInfo infoGlobal;
|
||||
infoGlobal.m_timeStep = timeStep;
|
||||
btIDebugDraw* debugDrawer=0;
|
||||
m_constraintSolver->solveGroup(manifoldPtr, numManifolds,infoGlobal,debugDrawer);
|
||||
|
||||
m_constraintSolver->solveGroup(manifoldPtr, numManifolds,infoGlobal,m_debugDrawer);
|
||||
|
||||
///integrate transforms
|
||||
integrateTransforms(timeStep);
|
||||
@@ -74,9 +76,9 @@ void btSimpleDynamicsWorld::updateAabbs()
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
btCollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->m_internalOwner)
|
||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
||||
if (body)
|
||||
{
|
||||
btRigidBody* body = (btRigidBody*)colObj->m_internalOwner;
|
||||
if (body->IsActive() && (!body->IsStatic()))
|
||||
{
|
||||
btPoint3 minAabb,maxAabb;
|
||||
@@ -94,9 +96,9 @@ void btSimpleDynamicsWorld::integrateTransforms(float timeStep)
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
btCollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->m_internalOwner)
|
||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
||||
if (body)
|
||||
{
|
||||
btRigidBody* body = (btRigidBody*)colObj->m_internalOwner;
|
||||
if (body->IsActive() && (!body->IsStatic()))
|
||||
{
|
||||
body->predictIntegratedTransform(timeStep, predictedTrans);
|
||||
@@ -113,10 +115,9 @@ void btSimpleDynamicsWorld::predictUnconstraintMotion(float timeStep)
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
btCollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->m_internalOwner)
|
||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
||||
if (body)
|
||||
{
|
||||
btRigidBody* body = (btRigidBody*)colObj->m_internalOwner;
|
||||
body->m_cachedInvertedWorldTransform = body->m_worldTransform.inverse();
|
||||
if (body->IsActive() && (!body->IsStatic()))
|
||||
{
|
||||
body->applyForces( timeStep);
|
||||
|
||||
@@ -35,12 +35,13 @@ protected:
|
||||
|
||||
bool m_ownsConstraintSolver;
|
||||
|
||||
btIDebugDraw* m_debugDrawer;
|
||||
|
||||
void predictUnconstraintMotion(float timeStep);
|
||||
|
||||
void integrateTransforms(float timeStep);
|
||||
|
||||
void updateAabbs();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -54,6 +55,17 @@ public:
|
||||
|
||||
virtual void stepSimulation( float timeStep);
|
||||
|
||||
virtual void setDebugDrawer(btIDebugDraw* debugDrawer)
|
||||
{
|
||||
m_debugDrawer = debugDrawer;
|
||||
};
|
||||
|
||||
virtual btIDebugDraw* getDebugDrawer()
|
||||
{
|
||||
return m_debugDrawer;
|
||||
}
|
||||
|
||||
virtual void updateAabbs();
|
||||
};
|
||||
|
||||
#endif //BT_SIMPLE_DYNAMICS_WORLD_H
|
||||
|
||||
@@ -41,37 +41,26 @@ public:
|
||||
explicit SIMD_FORCE_INLINE btTransform(const btQuaternion& q,
|
||||
const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0)))
|
||||
: m_basis(q),
|
||||
m_origin(c),
|
||||
m_type(RIGID)
|
||||
m_origin(c)
|
||||
{}
|
||||
|
||||
explicit SIMD_FORCE_INLINE btTransform(const btMatrix3x3& b,
|
||||
const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0)),
|
||||
unsigned int type = AFFINE)
|
||||
: m_basis(b),
|
||||
m_origin(c),
|
||||
m_type(type)
|
||||
m_origin(c)
|
||||
{}
|
||||
|
||||
|
||||
SIMD_FORCE_INLINE void mult(const btTransform& t1, const btTransform& t2) {
|
||||
m_basis = t1.m_basis * t2.m_basis;
|
||||
m_origin = t1(t2.m_origin);
|
||||
m_type = t1.m_type | t2.m_type;
|
||||
}
|
||||
|
||||
void multInverseLeft(const btTransform& t1, const btTransform& t2) {
|
||||
btVector3 v = t2.m_origin - t1.m_origin;
|
||||
if (t1.m_type & SCALING) {
|
||||
btMatrix3x3 inv = t1.m_basis.inverse();
|
||||
m_basis = inv * t2.m_basis;
|
||||
m_origin = inv * v;
|
||||
}
|
||||
else {
|
||||
m_basis = btMultTransposeLeft(t1.m_basis, t2.m_basis);
|
||||
m_origin = v * t1.m_basis;
|
||||
}
|
||||
m_type = t1.m_type | t2.m_type;
|
||||
m_basis = btMultTransposeLeft(t1.m_basis, t2.m_basis);
|
||||
m_origin = v * t1.m_basis;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE btVector3 operator()(const btVector3& x) const
|
||||
@@ -102,7 +91,6 @@ public:
|
||||
{
|
||||
m_basis.setValue(m);
|
||||
m_origin.setValue(&m[12]);
|
||||
m_type = AFFINE;
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +114,6 @@ public:
|
||||
SIMD_FORCE_INLINE void setOrigin(const btVector3& origin)
|
||||
{
|
||||
m_origin = origin;
|
||||
m_type |= TRANSLATION;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE btVector3 invXform(const btVector3& inVec) const;
|
||||
@@ -136,50 +123,36 @@ public:
|
||||
SIMD_FORCE_INLINE void setBasis(const btMatrix3x3& basis)
|
||||
{
|
||||
m_basis = basis;
|
||||
m_type |= LINEAR;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void setRotation(const btQuaternion& q)
|
||||
{
|
||||
m_basis.setRotation(q);
|
||||
m_type = (m_type & ~LINEAR) | ROTATION;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void scale(const btVector3& scaling)
|
||||
{
|
||||
m_basis = m_basis.scaled(scaling);
|
||||
m_type |= SCALING;
|
||||
}
|
||||
|
||||
void setIdentity()
|
||||
{
|
||||
m_basis.setIdentity();
|
||||
m_origin.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0));
|
||||
m_type = 0x0;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE bool isIdentity() const { return m_type == 0x0; }
|
||||
|
||||
|
||||
btTransform& operator*=(const btTransform& t)
|
||||
{
|
||||
m_origin += m_basis * t.m_origin;
|
||||
m_basis *= t.m_basis;
|
||||
m_type |= t.m_type;
|
||||
return *this;
|
||||
}
|
||||
|
||||
btTransform inverse() const
|
||||
{
|
||||
if (m_type)
|
||||
{
|
||||
btMatrix3x3 inv = (m_type & SCALING) ?
|
||||
m_basis.inverse() :
|
||||
m_basis.transpose();
|
||||
|
||||
return btTransform(inv, inv * -m_origin, m_type);
|
||||
}
|
||||
|
||||
return *this;
|
||||
btMatrix3x3 inv = m_basis.transpose();
|
||||
return btTransform(inv, inv * -m_origin);
|
||||
}
|
||||
|
||||
btTransform inverseTimes(const btTransform& t) const;
|
||||
@@ -190,7 +163,6 @@ private:
|
||||
|
||||
btMatrix3x3 m_basis;
|
||||
btVector3 m_origin;
|
||||
unsigned int m_type;
|
||||
};
|
||||
|
||||
|
||||
@@ -205,25 +177,15 @@ SIMD_FORCE_INLINE btTransform
|
||||
btTransform::inverseTimes(const btTransform& t) const
|
||||
{
|
||||
btVector3 v = t.getOrigin() - m_origin;
|
||||
if (m_type & SCALING)
|
||||
{
|
||||
btMatrix3x3 inv = m_basis.inverse();
|
||||
return btTransform(inv * t.getBasis(), inv * v,
|
||||
m_type | t.m_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
return btTransform(m_basis.transposeTimes(t.m_basis),
|
||||
v * m_basis, m_type | t.m_type);
|
||||
}
|
||||
v * m_basis);
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE btTransform
|
||||
btTransform::operator*(const btTransform& t) const
|
||||
{
|
||||
return btTransform(m_basis * t.m_basis,
|
||||
(*this)(t.m_origin),
|
||||
m_type | t.m_type);
|
||||
(*this)(t.m_origin));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ subject to the following restrictions:
|
||||
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
||||
#include "BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h"
|
||||
#include "BulletDynamics/ConstraintSolver/btHingeConstraint.h"
|
||||
#include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h"
|
||||
|
||||
#include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"
|
||||
///Vehicle simulation, with wheel contact simulated by raycasts
|
||||
#include "BulletDynamics/Vehicle/btRaycastVehicle.h"
|
||||
|
||||
Reference in New Issue
Block a user