more fixes, related to introduction of btMotionState, and using realtime timestep
This commit is contained in:
@@ -63,6 +63,10 @@ void BasicDemo::clientMoveAndDisplay()
|
|||||||
//simple dynamics world doesn't handle fixed-time-stepping
|
//simple dynamics world doesn't handle fixed-time-stepping
|
||||||
float ms = m_clock.getTimeMilliseconds();
|
float ms = m_clock.getTimeMilliseconds();
|
||||||
m_clock.reset();
|
m_clock.reset();
|
||||||
|
float minFPS = 1000.f/60.f;
|
||||||
|
if (ms > minFPS)
|
||||||
|
ms = minFPS;
|
||||||
|
|
||||||
if (m_dynamicsWorld)
|
if (m_dynamicsWorld)
|
||||||
m_dynamicsWorld->stepSimulation(ms / 1000.f);
|
m_dynamicsWorld->stepSimulation(ms / 1000.f);
|
||||||
|
|
||||||
|
|||||||
@@ -185,7 +185,9 @@ void BspDemo::clientMoveAndDisplay()
|
|||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
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();
|
renderme();
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ subject to the following restrictions:
|
|||||||
#include "BulletCollision/CollisionShapes/btTriangleMeshShape.h"
|
#include "BulletCollision/CollisionShapes/btTriangleMeshShape.h"
|
||||||
//#include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h"
|
//#include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h"
|
||||||
#include "BulletCollision/CollisionShapes/btCompoundShape.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++)
|
for (int i=0;i<m_numObjects;i++)
|
||||||
{
|
{
|
||||||
char* bodyName = (char*)m_rigidBodies[i]->m_userObjectPointer;
|
if (m_rigidBodies[i]->m_userObjectPointer)
|
||||||
if (!strcmp(bodyName,orgUri0))
|
|
||||||
{
|
{
|
||||||
body0=m_rigidBodies[i];
|
btDefaultMotionState* ms = (btDefaultMotionState*)m_rigidBodies[i]->m_userObjectPointer;
|
||||||
}
|
char* bodyName = (char*)ms->m_userPointer;
|
||||||
if (!strcmp(bodyName,orgUri1))
|
if (!strcmp(bodyName,orgUri0))
|
||||||
{
|
{
|
||||||
body1=m_rigidBodies[i];
|
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);
|
btRigidBody* body= createRigidBody(isDynamics,mass,startTransform,colShape);
|
||||||
if (body)
|
if (body && body->m_userObjectPointer)
|
||||||
{
|
{
|
||||||
//for bodyName lookup in constraints
|
//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_rigidBodies[m_numObjects] = body;
|
||||||
m_numObjects++;
|
m_numObjects++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,9 +181,10 @@ void ConcaveDemo::clientMoveAndDisplay()
|
|||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
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();
|
renderme();
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ static const int NUM_TRIANGLES=4;
|
|||||||
|
|
||||||
btVector3 gVertices[NUM_VERTICES];
|
btVector3 gVertices[NUM_VERTICES];
|
||||||
int gIndices[NUM_TRIANGLES*3];
|
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;
|
///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);
|
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();
|
renderme();
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,9 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
|
|||||||
(m_body1->m_collisionFlags & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)))
|
(m_body1->m_collisionFlags & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)))
|
||||||
{
|
{
|
||||||
//experimental feature info, for per-triangle material etc.
|
//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);
|
m_manifoldPtr->AddManifoldPoint(newPt);
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ struct btDefaultMotionState : public btMotionState
|
|||||||
btTransform m_graphicsWorldTrans;
|
btTransform m_graphicsWorldTrans;
|
||||||
btTransform m_centerOfMassOffset;
|
btTransform m_centerOfMassOffset;
|
||||||
btTransform m_startWorldTrans;
|
btTransform m_startWorldTrans;
|
||||||
|
void* m_userPointer;
|
||||||
|
|
||||||
btDefaultMotionState(const btTransform& startTrans,const btTransform& centerOfMassOffset = btTransform::getIdentity())
|
btDefaultMotionState(const btTransform& startTrans,const btTransform& centerOfMassOffset = btTransform::getIdentity())
|
||||||
: m_graphicsWorldTrans(startTrans),
|
: m_graphicsWorldTrans(startTrans),
|
||||||
m_centerOfMassOffset(centerOfMassOffset),
|
m_centerOfMassOffset(centerOfMassOffset),
|
||||||
m_startWorldTrans(startTrans)
|
m_startWorldTrans(startTrans),
|
||||||
|
m_userPointer(0)
|
||||||
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user