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:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user