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:
@@ -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