more fixes, related to introduction of btMotionState, and using realtime timestep

This commit is contained in:
ejcoumans
2006-10-18 04:01:07 +00:00
parent 3a6942fb91
commit 33b3ec94f1
7 changed files with 38 additions and 18 deletions

View File

@@ -63,6 +63,10 @@ void BasicDemo::clientMoveAndDisplay()
//simple dynamics world doesn't handle fixed-time-stepping
float ms = m_clock.getTimeMilliseconds();
m_clock.reset();
float minFPS = 1000.f/60.f;
if (ms > minFPS)
ms = minFPS;
if (m_dynamicsWorld)
m_dynamicsWorld->stepSimulation(ms / 1000.f);

View File

@@ -185,7 +185,9 @@ void BspDemo::clientMoveAndDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_dynamicsWorld->stepSimulation(deltaTime);
float dt = m_clock.getTimeMilliseconds() * 0.001f;
m_clock.reset();
m_dynamicsWorld->stepSimulation(dt);
renderme();

View File

@@ -29,6 +29,7 @@ subject to the following restrictions:
#include "BulletCollision/CollisionShapes/btTriangleMeshShape.h"
//#include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h"
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
#include "LinearMath/btDefaultMotionState.h"
@@ -542,14 +543,18 @@ void ColladaConverter::prepareConstraints(ConstraintInput& input)
for (int i=0;i<m_numObjects;i++)
{
char* bodyName = (char*)m_rigidBodies[i]->m_userObjectPointer;
if (!strcmp(bodyName,orgUri0))
if (m_rigidBodies[i]->m_userObjectPointer)
{
body0=m_rigidBodies[i];
}
if (!strcmp(bodyName,orgUri1))
{
body1=m_rigidBodies[i];
btDefaultMotionState* ms = (btDefaultMotionState*)m_rigidBodies[i]->m_userObjectPointer;
char* bodyName = (char*)ms->m_userPointer;
if (!strcmp(bodyName,orgUri0))
{
body0=m_rigidBodies[i];
}
if (!strcmp(bodyName,orgUri1))
{
body1=m_rigidBodies[i];
}
}
}
@@ -700,10 +705,11 @@ void ColladaConverter::PreparePhysicsObject(struct btRigidBodyInput& input, bool
btRigidBody* body= createRigidBody(isDynamics,mass,startTransform,colShape);
if (body)
if (body && body->m_userObjectPointer)
{
//for bodyName lookup in constraints
body->m_userObjectPointer = (void*)input.m_bodyName;
btDefaultMotionState* ms = (btDefaultMotionState*)body->m_userObjectPointer;
ms->m_userPointer = (void*)input.m_bodyName;
m_rigidBodies[m_numObjects] = body;
m_numObjects++;
}

View File

@@ -181,9 +181,10 @@ void ConcaveDemo::clientMoveAndDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float deltaTime = 1.f/60.f;
m_dynamicsWorld->stepSimulation(deltaTime);
float dt = m_clock.getTimeMilliseconds() * 0.001f;
m_clock.reset();
m_dynamicsWorld->stepSimulation(dt);
renderme();

View File

@@ -30,7 +30,7 @@ static const int NUM_TRIANGLES=4;
btVector3 gVertices[NUM_VERTICES];
int gIndices[NUM_TRIANGLES*3];
const float TRIANGLE_SIZE=20.f;
const float TRIANGLE_SIZE=10.f;
///User can override this material combiner by implementing gContactAddedCallback and setting body0->m_collisionFlags |= btCollisionObject::customMaterialCallback;
@@ -143,9 +143,12 @@ void UserCollisionAlgorithm::clientMoveAndDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float deltaTime = 1.f/60.f;
float dt = m_clock.getTimeMilliseconds() * 0.001f;
m_clock.reset();
m_dynamicsWorld->stepSimulation(deltaTime);
m_dynamicsWorld->stepSimulation(dt);
renderme();

View File

@@ -96,7 +96,9 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
(m_body1->m_collisionFlags & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)))
{
//experimental feature info, for per-triangle material etc.
(*gContactAddedCallback)(newPt,m_body0,m_partId0,m_index0,m_body1,m_partId1,m_index1);
btCollisionObject* obj0 = isSwapped? m_body1 : m_body0;
btCollisionObject* obj1 = isSwapped? m_body0 : m_body1;
(*gContactAddedCallback)(newPt,obj0,m_partId0,m_index0,obj1,m_partId1,m_index1);
}
m_manifoldPtr->AddManifoldPoint(newPt);

View File

@@ -7,11 +7,13 @@ struct btDefaultMotionState : public btMotionState
btTransform m_graphicsWorldTrans;
btTransform m_centerOfMassOffset;
btTransform m_startWorldTrans;
void* m_userPointer;
btDefaultMotionState(const btTransform& startTrans,const btTransform& centerOfMassOffset = btTransform::getIdentity())
: m_graphicsWorldTrans(startTrans),
m_centerOfMassOffset(centerOfMassOffset),
m_startWorldTrans(startTrans)
m_startWorldTrans(startTrans),
m_userPointer(0)
{
}