Made the move from sourceforge to googlecode (no svn sync any longer)
Fixed BulletColladaConverter load/save Removed btTypedUserInfo Added btHashMap Fixed btCapsuleShape
This commit is contained in:
@@ -17,12 +17,62 @@ subject to the following restrictions:
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btHashMap.h"
|
||||
|
||||
class OurValue
|
||||
{
|
||||
int m_uid;
|
||||
|
||||
public:
|
||||
OurValue(const btVector3& initialPos)
|
||||
:m_position(initialPos)
|
||||
{
|
||||
static int gUid=0;
|
||||
m_uid=gUid;
|
||||
gUid++;
|
||||
}
|
||||
|
||||
btVector3 m_position;
|
||||
int getUid() const
|
||||
{
|
||||
return m_uid;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
GLDebugDrawer gDebugDrawer;
|
||||
|
||||
///testing the btHashMap
|
||||
btHashMap<btHashKey<OurValue>,OurValue> map;
|
||||
|
||||
OurValue value1(btVector3(2,3,4));
|
||||
btHashKey<OurValue> key1(value1.getUid());
|
||||
map.insert(key1,value1);
|
||||
|
||||
|
||||
OurValue value2(btVector3(5,6,7));
|
||||
btHashKey<OurValue> key2(value2.getUid());
|
||||
map.insert(key2,value2);
|
||||
|
||||
|
||||
{
|
||||
OurValue value3(btVector3(7,8,9));
|
||||
btHashKey<OurValue> key3(value3.getUid());
|
||||
map.insert(key3,value3);
|
||||
}
|
||||
|
||||
|
||||
map.remove(key2);
|
||||
|
||||
const OurValue* ourPtr = map.find(key1);
|
||||
for (int i=0;i<map.size();i++)
|
||||
{
|
||||
OurValue* tmp = map.getAtIndex(i);
|
||||
//printf("tmp value=%f,%f,%f\n",tmp->m_position.getX(),tmp->m_position.getY(),tmp->m_position.getZ());
|
||||
}
|
||||
|
||||
BasicDemo ccdDemo;
|
||||
ccdDemo.initPhysics();
|
||||
ccdDemo.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
|
||||
|
||||
@@ -180,7 +180,25 @@ void ColladaDemo::keyboardCallback(unsigned char key, int x, int y)
|
||||
{
|
||||
//save a COLLADA .dae physics snapshot
|
||||
if (gColladaConverter)
|
||||
gColladaConverter->save();
|
||||
{
|
||||
if (gColladaConverter->getLastFileName())
|
||||
{
|
||||
//deal with the name pre/post fixing etc.
|
||||
char saveName[550];
|
||||
static int saveCount=1;
|
||||
sprintf(saveName,"%s%i",gColladaConverter->getLastFileName(),saveCount++);
|
||||
char* name = &saveName[0];
|
||||
if (name[0] == '/')
|
||||
{
|
||||
name = &saveName[1];
|
||||
}
|
||||
gColladaConverter->save(name);
|
||||
|
||||
} else
|
||||
{
|
||||
gColladaConverter->save("brandNew.dae");
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
DemoApplication::keyboardCallback(key,x,y);
|
||||
|
||||
@@ -14,16 +14,12 @@ subject to the following restrictions:
|
||||
*/
|
||||
|
||||
/* Some TODO items:
|
||||
* Figure out why velocity loading is not working
|
||||
* Output convex hull geometry for every single shape
|
||||
* fix naming conflicts with BulletUnnamed-* across executions -> need to generate a real unique name.
|
||||
* double check geometry sharing
|
||||
* handle the case that the user is already using btTypedUserInfo
|
||||
* cleanup all of the btTypedUserInfos that we create
|
||||
*/
|
||||
|
||||
|
||||
#include <string>
|
||||
#include "LinearMath/btTypedUserInfo.h"
|
||||
#include "ColladaConverter.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "dae.h"
|
||||
@@ -50,51 +46,8 @@ subject to the following restrictions:
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#define BT_RIGIDBODY_COLLADA_INFO_TYPE 0xdeed
|
||||
class btRigidBodyColladaInfo : public btTypedUserInfo
|
||||
{
|
||||
public:
|
||||
domNode* m_node;
|
||||
domRigid_body* m_rigidBody;
|
||||
domInstance_rigid_body* m_instanceRigidBody;
|
||||
|
||||
btRigidBodyColladaInfo (domNode* node, domRigid_body* rigidBody, domInstance_rigid_body* instanceRigidBody) : btTypedUserInfo()
|
||||
{
|
||||
m_node = node;
|
||||
m_rigidBody = rigidBody;
|
||||
m_instanceRigidBody = instanceRigidBody;
|
||||
setType (BT_RIGIDBODY_COLLADA_INFO_TYPE);
|
||||
}
|
||||
};
|
||||
|
||||
#define BT_RIGID_CONSTRAINT_COLLADA_INFO_TYPE 0xcead
|
||||
class btRigidConstraintColladaInfo : public btTypedUserInfo
|
||||
{
|
||||
public:
|
||||
domRigid_constraint* m_rigidConstraint;
|
||||
|
||||
btRigidConstraintColladaInfo (domRigid_constraint* rigidConstraint) : btTypedUserInfo ()
|
||||
{
|
||||
m_rigidConstraint = rigidConstraint;
|
||||
setType (BT_RIGID_CONSTRAINT_COLLADA_INFO_TYPE);
|
||||
}
|
||||
};
|
||||
|
||||
#define BT_SHAPE_COLLADA_INFO_TYPE 0xbead
|
||||
class btShapeColladaInfo : public btTypedUserInfo
|
||||
{
|
||||
public:
|
||||
domGeometry* m_geometry;
|
||||
btShapeColladaInfo (domGeometry* geometry) : btTypedUserInfo ()
|
||||
{
|
||||
m_geometry = geometry;
|
||||
setType (BT_SHAPE_COLLADA_INFO_TYPE);
|
||||
}
|
||||
};
|
||||
|
||||
char* getLastFileName();
|
||||
char* fixFileName(const char* lpCmdLine);
|
||||
//todo: sort out this domInstance_rigid_bodyRef forward definition, put it in the headerfile and make it virtual (make code more re-usable)
|
||||
|
||||
struct btRigidBodyInput
|
||||
{
|
||||
@@ -121,6 +74,25 @@ struct btRigidBodyOutput
|
||||
};
|
||||
|
||||
|
||||
int btRigidBodyColladaInfo::getUid()
|
||||
{
|
||||
return m_body->getBroadphaseProxy()->getUid();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int btRigidConstraintColladaInfo::getUid()
|
||||
{
|
||||
if (m_typedConstraint->getUid()==-1)
|
||||
{
|
||||
static int gConstraintUidGenerator=5;
|
||||
m_typedConstraint->setUserConstraintId(gConstraintUidGenerator);
|
||||
gConstraintUidGenerator++;
|
||||
}
|
||||
return m_typedConstraint->getUid();
|
||||
}
|
||||
|
||||
|
||||
|
||||
domMatrix_Array emptyMatrixArray;
|
||||
|
||||
@@ -643,13 +615,27 @@ domNode* ColladaConverter::findNode (const char* nodeName)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
btRigidBodyColladaInfo* ColladaConverter::findRigidBodyColladaInfo(const btRigidBody* body)
|
||||
{
|
||||
///we assume that the btRigidBody getUid matches btRigidBodyColladaInfo getUid
|
||||
|
||||
int uid = body->getBroadphaseProxy()->getUid();
|
||||
btHashKeyPtr<btRigidBodyColladaInfo*> tmpKey(uid);
|
||||
btRigidBodyColladaInfo** rbciPtr = this->m_rbUserInfoHashMap.find(tmpKey);
|
||||
btRigidBodyColladaInfo* rbci = NULL;
|
||||
if (rbciPtr)
|
||||
{
|
||||
rbci = *rbciPtr;
|
||||
}
|
||||
return rbci;
|
||||
}
|
||||
|
||||
domNode* ColladaConverter::findNode (btRigidBody* rb)
|
||||
{
|
||||
if (rb->getTypedUserInfo())
|
||||
|
||||
btRigidBodyColladaInfo* rbci = findRigidBodyColladaInfo(rb);
|
||||
if (rbci)
|
||||
{
|
||||
btTypedUserInfo* tui = rb->getTypedUserInfo ();
|
||||
btAssert (tui->getType() == BT_RIGIDBODY_COLLADA_INFO_TYPE);
|
||||
btRigidBodyColladaInfo* rbci = (btRigidBodyColladaInfo*)tui;
|
||||
return rbci->m_node;
|
||||
}
|
||||
return NULL;
|
||||
@@ -679,14 +665,12 @@ domRigid_body* ColladaConverter::findRigid_body (const char* rigidbodyName)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
domRigid_body* ColladaConverter::findRigid_body (btRigidBody* rb)
|
||||
domRigid_body* ColladaConverter::findRigid_body (const btRigidBody* rb)
|
||||
{
|
||||
if (rb->getTypedUserInfo ())
|
||||
btRigidBodyColladaInfo* rbci = findRigidBodyColladaInfo(rb);
|
||||
if (rbci)
|
||||
{
|
||||
btTypedUserInfo* tui = rb->getTypedUserInfo ();
|
||||
btAssert (tui->getType() == BT_RIGIDBODY_COLLADA_INFO_TYPE);
|
||||
btRigidBodyColladaInfo* rbci = (btRigidBodyColladaInfo*)tui;
|
||||
return rbci->m_rigidBody;
|
||||
return rbci->m_domRigidBody;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -713,11 +697,9 @@ domInstance_rigid_body* ColladaConverter::findRigid_body_instance (const char* n
|
||||
|
||||
domInstance_rigid_body* ColladaConverter::findRigid_body_instance (btRigidBody* rb)
|
||||
{
|
||||
if (rb->getTypedUserInfo ())
|
||||
btRigidBodyColladaInfo* rbci = findRigidBodyColladaInfo(rb);
|
||||
if (rbci)
|
||||
{
|
||||
btTypedUserInfo* tui = rb->getTypedUserInfo ();
|
||||
btAssert (tui->getType() == BT_RIGIDBODY_COLLADA_INFO_TYPE);
|
||||
btRigidBodyColladaInfo* rbci = (btRigidBodyColladaInfo*)tui;
|
||||
return rbci->m_instanceRigidBody;
|
||||
}
|
||||
return NULL;
|
||||
@@ -748,14 +730,32 @@ domRigid_constraint* ColladaConverter::findRigid_constraint (const char* constra
|
||||
return NULL;
|
||||
}
|
||||
|
||||
btRigidConstraintColladaInfo* ColladaConverter::findRigidConstraintColladaInfo(btTypedConstraint* constraint)
|
||||
{
|
||||
///we assume that the btTypedConstraint getUid matches btRigidConstraintColladaInfo getUid
|
||||
int uid = constraint->getUid();
|
||||
if (uid==-1)
|
||||
return NULL;//not in the map
|
||||
|
||||
btHashKeyPtr<btRigidConstraintColladaInfo*> tmpKey(uid);
|
||||
btRigidConstraintColladaInfo** rbciPtr = this->m_constraintUserInfoHashMap.find(tmpKey);
|
||||
btRigidConstraintColladaInfo* rbci = NULL;
|
||||
if (rbciPtr)
|
||||
{
|
||||
rbci = *rbciPtr;
|
||||
}
|
||||
return rbci;
|
||||
|
||||
}
|
||||
|
||||
domRigid_constraint* ColladaConverter::findRigid_constraint (btTypedConstraint* constraint)
|
||||
{
|
||||
if (constraint->getTypedUserInfo ())
|
||||
|
||||
btRigidConstraintColladaInfo* rcci = findRigidConstraintColladaInfo(constraint);
|
||||
|
||||
if (rcci)
|
||||
{
|
||||
btTypedUserInfo* tui = constraint->getTypedUserInfo ();
|
||||
btAssert (tui->getType () == BT_RIGID_CONSTRAINT_COLLADA_INFO_TYPE);
|
||||
btRigidConstraintColladaInfo* rcci = (btRigidConstraintColladaInfo*)tui;
|
||||
return rcci->m_rigidConstraint;
|
||||
return rcci->m_domRigidConstraint;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -777,18 +777,17 @@ domGeometry* ColladaConverter::findGeometry (const char* shapeName)
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
domGeometry* ColladaConverter::findGeometry (btCollisionShape* shape)
|
||||
{
|
||||
if (shape->getTypedUserInfo ())
|
||||
{
|
||||
btTypedUserInfo* tui = shape->getTypedUserInfo ();
|
||||
btAssert (tui->getType () == BT_SHAPE_COLLADA_INFO_TYPE);
|
||||
btShapeColladaInfo* sci = (btShapeColladaInfo*)tui;
|
||||
return sci->m_geometry;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void ColladaConverter::prepareConstraints(ConstraintInput& input)
|
||||
@@ -824,10 +823,9 @@ void ColladaConverter::prepareConstraints(ConstraintInput& input)
|
||||
for (int i=0;i<getNumRigidBodies();i++)
|
||||
{
|
||||
btRigidBody* body = getRigidBody (i);
|
||||
btTypedUserInfo* tui = body->getTypedUserInfo();
|
||||
btAssert (tui->getType () == BT_RIGIDBODY_COLLADA_INFO_TYPE);
|
||||
btRigidBodyColladaInfo* rbci = (btRigidBodyColladaInfo*)tui;
|
||||
domRigid_body* domRigidBody = rbci->m_rigidBody;
|
||||
domRigid_body* domRigidBody = findRigid_body(body);
|
||||
btAssert(domRigidBody);
|
||||
|
||||
const char* name = domRigidBody->getSid();
|
||||
if (name)
|
||||
{
|
||||
@@ -971,8 +969,9 @@ void ColladaConverter::prepareConstraints(ConstraintInput& input)
|
||||
}
|
||||
|
||||
// XXX: User must free this name before destroy the constraint
|
||||
btTypedUserInfo* tui = new btRigidConstraintColladaInfo (rigidConstraintRef);
|
||||
constraint->setTypedUserInfo (tui);
|
||||
btRigidConstraintColladaInfo* tui = new btRigidConstraintColladaInfo (constraint,rigidConstraintRef, constraintRef);
|
||||
m_constraintUserInfoHashMap.insert(btHashKeyPtr<btRigidConstraintColladaInfo*>(tui->getUid()),tui);
|
||||
|
||||
printf("Added constraint %s to the world\n", rigidConstraintRef->getSid());
|
||||
} else
|
||||
{
|
||||
@@ -1035,8 +1034,9 @@ void ColladaConverter::PreparePhysicsObject(struct btRigidBodyInput& input, bool
|
||||
btRigidBody* body= createRigidBody(isDynamics,mass,startTransform,colShape);
|
||||
if (body)
|
||||
{
|
||||
btTypedUserInfo* tui = new btRigidBodyColladaInfo (input.m_nodeRef, input.m_rigidBodyRef2, input.m_instanceRigidBodyRef);
|
||||
body->setTypedUserInfo (tui);
|
||||
btRigidBodyColladaInfo* tui = new btRigidBodyColladaInfo (body,input.m_nodeRef, input.m_rigidBodyRef2, input.m_instanceRigidBodyRef);
|
||||
m_rbUserInfoHashMap.insert(btHashKeyPtr<btRigidBodyColladaInfo*>(tui->getUid()),tui);
|
||||
|
||||
/* if the body is dynamic restore it's velocity */
|
||||
if (body->getInvMass() != 0.0)
|
||||
{
|
||||
@@ -1622,8 +1622,8 @@ void ColladaConverter::buildShape (btCollisionShape* shape, void* collada_shape,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ColladaConverter::addRigidBody (btRigidBody* rb, const char* nodeName, const char* shapeName)
|
||||
|
||||
domRigid_body* ColladaConverter::addRigidBody (btRigidBody* rb, const char* nodeName, const char* shapeName)
|
||||
{
|
||||
btCollisionShape* shape = rb->getCollisionShape ();
|
||||
char bodyName[512];
|
||||
@@ -1664,15 +1664,19 @@ ColladaConverter::addRigidBody (btRigidBody* rb, const char* nodeName, const cha
|
||||
mi->setUrl (material_name);
|
||||
// collision shape
|
||||
|
||||
domRigid_body::domTechnique_common::domShape* colladaShape = (domRigid_body::domTechnique_common::domShape*)common->createAndPlace (COLLADA_ELEMENT_SHAPE);
|
||||
domRigid_body::domTechnique_common::domShape* colladaShape = (domRigid_body::domTechnique_common::domShape*)common->createAndPlace (COLLADA_ELEMENT_SHAPE);
|
||||
buildShape (shape, colladaShape, shapeName);
|
||||
|
||||
return colladaRigidBody;
|
||||
}
|
||||
|
||||
void ColladaConverter::addNode (btRigidBody* rb, const char* nodeName, const char* shapeName)
|
||||
|
||||
domNode* ColladaConverter::addNode (btRigidBody* rb, const char* nodeName, const char* shapeName)
|
||||
{
|
||||
domVisual_scene* vscene = getDefaultVisualScene ();
|
||||
|
||||
domNode* node = (domNode*)vscene->createAndPlace (COLLADA_ELEMENT_NODE);
|
||||
|
||||
node->setId (nodeName);
|
||||
node->setName (nodeName);
|
||||
|
||||
@@ -1714,18 +1718,20 @@ void ColladaConverter::addNode (btRigidBody* rb, const char* nodeName, const cha
|
||||
</instance_geometry>
|
||||
*/
|
||||
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
void ColladaConverter::addConstraint (btTypedConstraint* constraint, const char* constraintName)
|
||||
|
||||
domRigid_constraint* ColladaConverter::addConstraint (btTypedConstraint* constraint, const char* constraintName)
|
||||
{
|
||||
if (!constraint->getConstraintType() != D6_CONSTRAINT_TYPE)
|
||||
return;
|
||||
return NULL;
|
||||
|
||||
btGeneric6DofConstraint* g6c = (btGeneric6DofConstraint*)constraint;
|
||||
const btRigidBody& rb1 = g6c->getRigidBodyA ();
|
||||
const btRigidBody& rb2 = g6c->getRigidBodyB ();
|
||||
bool single = rb2.getTypedUserInfo() == NULL || rb2.getTypedUserInfo()->getPrivatePointer () == NULL;
|
||||
|
||||
bool single = (findRigid_body(&rb2)==NULL);
|
||||
|
||||
domPhysics_model* physicsModel = getDefaultPhysicsModel ();
|
||||
domRigid_constraint* domRigidConstraint = (domRigid_constraint*)physicsModel->createAndPlace (COLLADA_ELEMENT_RIGID_CONSTRAINT);
|
||||
@@ -1733,10 +1739,9 @@ void ColladaConverter::addConstraint (btTypedConstraint* constraint, const char*
|
||||
domRigidConstraint->setSid (constraintName);
|
||||
if (single)
|
||||
{
|
||||
btTypedUserInfo* tui = rb1.getTypedUserInfo();
|
||||
btAssert (tui->getType () == BT_RIGIDBODY_COLLADA_INFO_TYPE);
|
||||
btRigidBodyColladaInfo* rbci = (btRigidBodyColladaInfo*)tui;
|
||||
domRigid_body* domRigidBody = rbci->m_rigidBody;
|
||||
domRigid_body* domRigidBody = findRigid_body(&rb1);
|
||||
btAssert(domRigidBody);
|
||||
|
||||
const char* name = domRigidBody->getName();
|
||||
btTransform rb1Frame = g6c->getFrameOffsetA ();
|
||||
printf("Joint with single body: %s\n", name);
|
||||
@@ -1769,16 +1774,8 @@ void ColladaConverter::addConstraint (btTypedConstraint* constraint, const char*
|
||||
|
||||
}
|
||||
} else {
|
||||
btTypedUserInfo* tui1 = rb1.getTypedUserInfo();
|
||||
btTypedUserInfo* tui2 = rb2.getTypedUserInfo();
|
||||
btAssert (tui1->getType () == BT_RIGIDBODY_COLLADA_INFO_TYPE);
|
||||
btAssert (tui2->getType () == BT_RIGIDBODY_COLLADA_INFO_TYPE);
|
||||
|
||||
btRigidBodyColladaInfo* rbci1 = (btRigidBodyColladaInfo*)tui1;
|
||||
domRigid_body* domRigidBody1 = rbci1->m_rigidBody;
|
||||
|
||||
btRigidBodyColladaInfo* rbci2 = (btRigidBodyColladaInfo*)tui2;
|
||||
domRigid_body* domRigidBody2 = rbci2->m_rigidBody;
|
||||
domRigid_body* domRigidBody1 = findRigid_body(&rb1);
|
||||
domRigid_body* domRigidBody2 = findRigid_body(&rb2);
|
||||
|
||||
const char* name1 = domRigidBody1->getName();
|
||||
const char* name2 = domRigidBody2->getName();
|
||||
@@ -1876,17 +1873,18 @@ void ColladaConverter::addConstraint (btTypedConstraint* constraint, const char*
|
||||
max->getValue().set (1, limit->m_upperLimit[1]);
|
||||
max->getValue().set (2, limit->m_upperLimit[2]);
|
||||
}
|
||||
return domRigidConstraint;
|
||||
}
|
||||
|
||||
void ColladaConverter::addConstraintInstance (btTypedConstraint* constraint, const char* constraintName)
|
||||
domInstance_rigid_constraint* ColladaConverter::addConstraintInstance (btTypedConstraint* constraint, const char* constraintName)
|
||||
{
|
||||
domInstance_physics_model* mi = getDefaultInstancePhysicsModel ();
|
||||
domInstance_rigid_constraint* rci = (domInstance_rigid_constraint*)mi->createAndPlace (COLLADA_ELEMENT_INSTANCE_RIGID_CONSTRAINT);
|
||||
rci->setConstraint (constraintName);
|
||||
return rci;
|
||||
}
|
||||
|
||||
|
||||
void ColladaConverter::addRigidBodyInstance (btRigidBody* rb, const char* nodeName)
|
||||
domInstance_rigid_body* ColladaConverter::addRigidBodyInstance (btRigidBody* rb, const char* nodeName)
|
||||
{
|
||||
char targetName[512];
|
||||
char bodyName[512];
|
||||
@@ -1910,6 +1908,7 @@ void ColladaConverter::addRigidBodyInstance (btRigidBody* rb, const char* nodeNa
|
||||
btVector3 btLv = rb->getLinearVelocity ();
|
||||
lv->getValue().set3 (btLv[0], btLv[1], btLv[2]);
|
||||
}
|
||||
return rbi;
|
||||
}
|
||||
|
||||
void ColladaConverter::addMaterial (btRigidBody* rb, const char* nodeName)
|
||||
@@ -2037,15 +2036,12 @@ ColladaConverter::updateConstraint (btTypedConstraint* constraint, domRigid_cons
|
||||
btGeneric6DofConstraint* g6c = (btGeneric6DofConstraint*)constraint;
|
||||
const btRigidBody& rb1 = g6c->getRigidBodyA ();
|
||||
const btRigidBody& rb2 = g6c->getRigidBodyB ();
|
||||
bool single = rb2.getTypedUserInfo() == NULL || rb2.getTypedUserInfo()->getPrivatePointer () == NULL;
|
||||
bool single = (findRigid_body(&rb2)==NULL);
|
||||
|
||||
if (single)
|
||||
{
|
||||
printf("Joint with single body\n");
|
||||
btTypedUserInfo* tui = rb1.getTypedUserInfo();
|
||||
btAssert (tui->getType () == BT_RIGIDBODY_COLLADA_INFO_TYPE);
|
||||
btRigidBodyColladaInfo* rbci = (btRigidBodyColladaInfo*)tui;
|
||||
domRigid_body* domRigidBody = rbci->m_rigidBody;
|
||||
domRigid_body* domRigidBody = findRigid_body(&rb1);
|
||||
const char* name = domRigidBody->getSid();
|
||||
btTransform rb1Frame = g6c->getFrameOffsetA ();
|
||||
domRigid_constraint::domAttachmentRef attachment = daeSafeCast<domRigid_constraint::domAttachment>(rigidConstraint->createAndPlace (COLLADA_ELEMENT_ATTACHMENT));
|
||||
@@ -2078,17 +2074,8 @@ ColladaConverter::updateConstraint (btTypedConstraint* constraint, domRigid_cons
|
||||
}
|
||||
} else {
|
||||
printf("Joint attached to two bodies\n");
|
||||
|
||||
btTypedUserInfo* tui1 = rb1.getTypedUserInfo();
|
||||
btTypedUserInfo* tui2 = rb2.getTypedUserInfo();
|
||||
btAssert (tui1->getType () == BT_RIGIDBODY_COLLADA_INFO_TYPE);
|
||||
btAssert (tui2->getType () == BT_RIGIDBODY_COLLADA_INFO_TYPE);
|
||||
|
||||
btRigidBodyColladaInfo* rbci1 = (btRigidBodyColladaInfo*)tui1;
|
||||
domRigid_body* domRigidBody1 = rbci1->m_rigidBody;
|
||||
|
||||
btRigidBodyColladaInfo* rbci2 = (btRigidBodyColladaInfo*)tui2;
|
||||
domRigid_body* domRigidBody2 = rbci2->m_rigidBody;
|
||||
domRigid_body* domRigidBody1 = findRigid_body(&rb1);
|
||||
domRigid_body* domRigidBody2 = findRigid_body(&rb2);
|
||||
|
||||
const char* name1 = domRigidBody1->getSid();
|
||||
const char* name2 = domRigidBody2->getSid();
|
||||
@@ -2208,14 +2195,13 @@ void ColladaConverter::syncOrAddRigidBody (btRigidBody* body)
|
||||
char nodeNameGen[512];
|
||||
char shapeNameGen[512];
|
||||
|
||||
domNode* dNode=NULL;
|
||||
domRigid_body* dRigidBody=NULL;
|
||||
domInstance_rigid_body* dInstanceRigidBody=NULL;
|
||||
|
||||
printf("New body\n");
|
||||
btCollisionShape* shape = body->getCollisionShape ();
|
||||
|
||||
if (body->getTypedUserInfo() != NULL && body->getTypedUserInfo()->getName() != NULL)
|
||||
nodeName = body->getTypedUserInfo()->getName ();
|
||||
|
||||
if (shape->getTypedUserInfo() && shape->getTypedUserInfo()->getName())
|
||||
shapeName = body->getTypedUserInfo ()->getName();
|
||||
|
||||
if (!nodeName)
|
||||
{
|
||||
@@ -2248,48 +2234,57 @@ void ColladaConverter::syncOrAddRigidBody (btRigidBody* body)
|
||||
{
|
||||
char concaveShapeName[256];
|
||||
sprintf(concaveShapeName,"RenderMesh%s",shapeName);
|
||||
addNode (body, nodeName, concaveShapeName);
|
||||
dNode = addNode (body, nodeName, concaveShapeName);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
addNode (body, nodeName, shapeName);
|
||||
dNode = addNode (body, nodeName, shapeName);
|
||||
}
|
||||
};
|
||||
|
||||
addMaterial (body, nodeName);
|
||||
addRigidBody (body, nodeName, shapeName);
|
||||
addRigidBodyInstance (body, nodeName);
|
||||
|
||||
dRigidBody = addRigidBody (body, nodeName, shapeName);
|
||||
dInstanceRigidBody = addRigidBodyInstance (body, nodeName);
|
||||
|
||||
|
||||
btRigidBodyColladaInfo* value = new btRigidBodyColladaInfo(body,dNode,dRigidBody,dInstanceRigidBody);
|
||||
m_rbUserInfoHashMap.insert(btHashKeyPtr<btRigidBodyColladaInfo*>(value->getUid()),value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ColladaConverter::syncOrAddConstraint (btTypedConstraint* constraint)
|
||||
{
|
||||
domRigid_constraintRef rigidConstraint = findRigid_constraint (constraint);
|
||||
return;
|
||||
|
||||
|
||||
static int random_node_name_key = 0;
|
||||
if (rigidConstraint)
|
||||
{
|
||||
updateConstraint (constraint, rigidConstraint);
|
||||
} else {
|
||||
btTypedUserInfo* tui = constraint->getTypedUserInfo ();
|
||||
|
||||
|
||||
char namebuf[512];
|
||||
const char* constraintName = NULL;
|
||||
if (tui)
|
||||
{
|
||||
btAssert (tui->getType () == BT_RIGID_CONSTRAINT_COLLADA_INFO_TYPE);
|
||||
if (tui->getName())
|
||||
constraintName = tui->getName();
|
||||
}
|
||||
if (!constraintName)
|
||||
{
|
||||
// generate one
|
||||
sprintf(&namebuf[0], "BulletUnnamedConstraint-%d", random_node_name_key);
|
||||
constraintName = &namebuf[0];
|
||||
}
|
||||
addConstraint (constraint, constraintName);
|
||||
addConstraintInstance (constraint, constraintName);
|
||||
|
||||
domRigid_constraint* dRigidConstraint = addConstraint (constraint, constraintName);
|
||||
if (!dRigidConstraint)
|
||||
return;
|
||||
|
||||
domInstance_rigid_constraint* dInstanceRigidConstraint = addConstraintInstance (constraint, constraintName);
|
||||
|
||||
btRigidConstraintColladaInfo* value = new btRigidConstraintColladaInfo(constraint,dRigidConstraint,dInstanceRigidConstraint);
|
||||
this->m_constraintUserInfoHashMap.insert(btHashKeyPtr<btRigidConstraintColladaInfo*>(value->getUid()),value);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2378,18 +2373,6 @@ bool ColladaConverter::save(const char* filename)
|
||||
}
|
||||
|
||||
{
|
||||
//let the user deal with the name pre/post fixing etc.
|
||||
/*
|
||||
char saveName[550];
|
||||
static int saveCount=1;
|
||||
sprintf(saveName,"%s%i",getLastFileName(),saveCount++);
|
||||
char* name = &saveName[0];
|
||||
if (name[0] == '/')
|
||||
{
|
||||
name = &saveName[1];
|
||||
}
|
||||
*/
|
||||
|
||||
m_collada->saveAs (filename);
|
||||
}
|
||||
#if 0
|
||||
@@ -2513,23 +2496,28 @@ bool ColladaConverter::save(const char* filename)
|
||||
}
|
||||
|
||||
//some code that de-mangles the windows filename passed in as argument
|
||||
char cleaned_filename[513];
|
||||
char* getLastFileName()
|
||||
|
||||
|
||||
char* ColladaConverter::getLastFileName()
|
||||
{
|
||||
return cleaned_filename;
|
||||
return m_cleaned_filename;
|
||||
}
|
||||
|
||||
|
||||
char* fixFileName(const char* lpCmdLine)
|
||||
char* ColladaConverter::fixFileName(const char* lpCmdLine)
|
||||
{
|
||||
|
||||
for (int i=0;i<513;i++)
|
||||
{
|
||||
m_cleaned_filename[i]=0;
|
||||
}
|
||||
|
||||
// We might get a windows-style path on the command line, this can mess up the DOM which expects
|
||||
// all paths to be URI's. This block of code does some conversion to try and make the input
|
||||
// compliant without breaking the ability to accept a properly formatted URI. Right now this only
|
||||
// displays the first filename
|
||||
const char *in = lpCmdLine;
|
||||
char* out = cleaned_filename;
|
||||
char* out = m_cleaned_filename;
|
||||
*out = '\0';
|
||||
// If the first character is a ", skip it (filenames with spaces in them are quoted)
|
||||
if(*in == '\"')
|
||||
@@ -2560,8 +2548,8 @@ char* fixFileName(const char* lpCmdLine)
|
||||
out++;
|
||||
}
|
||||
|
||||
cleaned_filename[i+1] = '\0';
|
||||
return cleaned_filename;
|
||||
|
||||
return m_cleaned_filename;
|
||||
}
|
||||
|
||||
|
||||
@@ -2792,7 +2780,7 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
|
||||
|
||||
//btTriangleMeshShape
|
||||
}
|
||||
rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
|
||||
//rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
|
||||
|
||||
}
|
||||
} else
|
||||
@@ -2835,7 +2823,7 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
|
||||
if (numAddedVerts > 0)
|
||||
{
|
||||
rbOutput.m_colShape = convexHull;
|
||||
rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
|
||||
//rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
|
||||
} else
|
||||
{
|
||||
delete convexHull;
|
||||
@@ -2983,7 +2971,7 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
|
||||
if (convexHullShape->getNumVertices())
|
||||
{
|
||||
rbOutput.m_colShape = convexHullShape;
|
||||
rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
|
||||
//rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
|
||||
printf("created convexHullShape with %i points\n",convexHullShape->getNumVertices());
|
||||
} else
|
||||
{
|
||||
@@ -3144,3 +3132,74 @@ btVector3 ColladaConverter::getGravity ()
|
||||
{
|
||||
return m_dynamicsWorld->getGravity ();
|
||||
}
|
||||
|
||||
|
||||
void ColladaConverter::registerRigidBody(btRigidBody* body, const char* name)
|
||||
{
|
||||
|
||||
btRigidBodyColladaInfo* rbci = findRigidBodyColladaInfo(body);
|
||||
|
||||
if (!rbci)
|
||||
{
|
||||
syncOrAddRigidBody (body);
|
||||
rbci = findRigidBodyColladaInfo(body);
|
||||
}
|
||||
|
||||
// update dom
|
||||
char bodyName[512];
|
||||
snprintf(&bodyName[0], 512, "%s-RigidBody", name);
|
||||
rbci->m_domRigidBody->setSid (bodyName);
|
||||
rbci->m_domRigidBody->setName (bodyName);
|
||||
rbci->m_node->setId (name);
|
||||
rbci->m_node->setName (name);
|
||||
rbci->m_instanceRigidBody->setBody (bodyName);
|
||||
daeURI uri;
|
||||
uri.setElement( rbci->m_node );
|
||||
uri.resolveURI();
|
||||
rbci->m_instanceRigidBody->setTarget (uri);
|
||||
|
||||
|
||||
int i;
|
||||
for (i = 0; i < body->getNumConstraintRefs(); i++)
|
||||
{
|
||||
btTypedConstraint* constraint = body->getConstraintRef (i);
|
||||
|
||||
// not support by the dom
|
||||
if (!constraint->getConstraintType() != D6_CONSTRAINT_TYPE)
|
||||
continue;
|
||||
|
||||
btRigidConstraintColladaInfo* rcci = findRigidConstraintColladaInfo(constraint);
|
||||
|
||||
// not added to the dom yet
|
||||
if (!rcci)
|
||||
continue;
|
||||
|
||||
domRigid_constraint* rigidConstraint = rcci->m_domRigidConstraint;
|
||||
|
||||
if (&constraint->getRigidBodyA() == body)
|
||||
{
|
||||
domRigid_constraint::domRef_attachment* refAttachment = (domRigid_constraint::domRef_attachment*)rigidConstraint->getRef_attachment();
|
||||
refAttachment->setRigid_body (bodyName);
|
||||
} else if (&constraint->getRigidBodyB() == body) {
|
||||
domRigid_constraint::domAttachment* attachment = (domRigid_constraint::domAttachment*)rigidConstraint->getAttachment ();
|
||||
attachment->setRigid_body (bodyName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ColladaConverter::registerConstraint(btTypedConstraint* constraint, const char* name)
|
||||
{
|
||||
|
||||
btRigidConstraintColladaInfo* rcci = findRigidConstraintColladaInfo(constraint);
|
||||
if (!rcci)
|
||||
{
|
||||
syncOrAddConstraint (constraint);
|
||||
rcci = findRigidConstraintColladaInfo(constraint);
|
||||
}
|
||||
|
||||
rcci->m_domRigidConstraint->setName(name);
|
||||
rcci->m_domRigidConstraint->setSid(name);
|
||||
rcci->m_domInstanceRigidConstraint->setConstraint (name);
|
||||
}
|
||||
|
||||
@@ -20,20 +20,86 @@ subject to the following restrictions:
|
||||
|
||||
#include "LinearMath/btTransform.h"
|
||||
#include "LinearMath/btVector3.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "LinearMath/btHashMap.h"
|
||||
|
||||
class btCollisionShape;
|
||||
class btRigidBody;
|
||||
class btTypedConstraint;
|
||||
class btDynamicsWorld;
|
||||
class ConstraintInput;
|
||||
class btRigidBodyColladaInfo;
|
||||
|
||||
class btRigidBodyColladaInfo
|
||||
{
|
||||
public:
|
||||
class domNode* m_node;
|
||||
class domRigid_body* m_domRigidBody;
|
||||
class domInstance_rigid_body* m_instanceRigidBody;
|
||||
btRigidBody* m_body;
|
||||
|
||||
int getUid();
|
||||
|
||||
btRigidBodyColladaInfo (btRigidBody* body, domNode* node, domRigid_body* rigidBody, domInstance_rigid_body* instanceRigidBody)
|
||||
{
|
||||
m_body = body;
|
||||
m_node = node;
|
||||
m_domRigidBody = rigidBody;
|
||||
m_instanceRigidBody = instanceRigidBody;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class btRigidConstraintColladaInfo
|
||||
{
|
||||
public:
|
||||
btTypedConstraint* m_typedConstraint;
|
||||
class domRigid_constraint* m_domRigidConstraint;
|
||||
class domInstance_rigid_constraint* m_domInstanceRigidConstraint;
|
||||
|
||||
int getUid();
|
||||
|
||||
btRigidConstraintColladaInfo (btTypedConstraint* constraint, domRigid_constraint* rigidConstraint, domInstance_rigid_constraint* domInstanceRigidConstraint)
|
||||
{
|
||||
m_typedConstraint = constraint;
|
||||
m_domRigidConstraint = rigidConstraint;
|
||||
m_domInstanceRigidConstraint = domInstanceRigidConstraint;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
|
||||
class btShapeColladaInfo
|
||||
{
|
||||
public:
|
||||
domGeometry* m_geometry;
|
||||
|
||||
int getUid();
|
||||
|
||||
btShapeColladaInfo (domGeometry* geometry) : btTypedUserInfo ()
|
||||
{
|
||||
m_geometry = geometry;
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
///ColladaConverter helps converting the physics assets from COLLADA DOM into physics objects
|
||||
class ColladaConverter
|
||||
{
|
||||
char m_cleaned_filename[513];
|
||||
|
||||
protected:
|
||||
|
||||
btDynamicsWorld* m_dynamicsWorld;
|
||||
|
||||
btHashMap<btHashKeyPtr<btRigidBodyColladaInfo*>,btRigidBodyColladaInfo*> m_rbUserInfoHashMap;
|
||||
btHashMap<btHashKeyPtr<btRigidConstraintColladaInfo*>,btRigidConstraintColladaInfo*> m_constraintUserInfoHashMap;
|
||||
|
||||
|
||||
class DAE* m_collada;
|
||||
class domCOLLADA* m_dom;
|
||||
char* m_filename;
|
||||
@@ -50,6 +116,9 @@ protected:
|
||||
|
||||
bool convert ();
|
||||
|
||||
btRigidBodyColladaInfo* findRigidBodyColladaInfo(const btRigidBody* body);
|
||||
btRigidConstraintColladaInfo* findRigidConstraintColladaInfo(btTypedConstraint* constraint);
|
||||
|
||||
/* Searches based on matching name/id */
|
||||
class domNode* findNode (const char* nodeName);
|
||||
class domRigid_body* findRigid_body (const char* rigidBodyName);
|
||||
@@ -57,12 +126,11 @@ protected:
|
||||
class domRigid_constraint* findRigid_constraint (const char* constraintName);
|
||||
class domGeometry* findGeometry (const char* shapeName);
|
||||
|
||||
/* Use btTypedUserInfo->getPrivatePointer() */
|
||||
class domNode* findNode (btRigidBody* rb);
|
||||
class domRigid_body* findRigid_body (btRigidBody* rb);
|
||||
class domRigid_body* findRigid_body (const btRigidBody* rb);
|
||||
class domInstance_rigid_body* findRigid_body_instance (btRigidBody* rb);
|
||||
class domRigid_constraint* findRigid_constraint (btTypedConstraint* constraint);
|
||||
class domGeometry* findGeometry (btCollisionShape* shape);
|
||||
//class domGeometry* findGeometry (btCollisionShape* shape);
|
||||
|
||||
/* These are the locations that NEW elements will be added to */
|
||||
class domLibrary_geometries* getDefaultGeomLib ();
|
||||
@@ -79,12 +147,12 @@ protected:
|
||||
void addConvexHull (btCollisionShape* shape, const char* nodeName);
|
||||
void addConvexMesh (btCollisionShape* shape, const char* nodeName);
|
||||
void addConcaveMesh(btCollisionShape* shape, const char* nodeName);
|
||||
void addNode (btRigidBody* body, const char* nodeName, const char* shapeName);
|
||||
void addConstraint (btTypedConstraint* constraint, const char* constraintName);
|
||||
void addConstraintInstance (btTypedConstraint* constraint, const char* constraintName);
|
||||
class domNode* addNode (btRigidBody* body, const char* nodeName, const char* shapeName);
|
||||
class domRigid_constraint* addConstraint (btTypedConstraint* constraint, const char* constraintName);
|
||||
class domInstance_rigid_constraint* addConstraintInstance (btTypedConstraint* constraint, const char* constraintName);
|
||||
void addMaterial (btRigidBody* body, const char* nodeName);
|
||||
void addRigidBody (btRigidBody* body, const char* nodeName, const char* shapeName);
|
||||
void addRigidBodyInstance (btRigidBody* body, const char* nodeName);
|
||||
class domRigid_body* addRigidBody (btRigidBody* body, const char* nodeName, const char* shapeName);
|
||||
class domInstance_rigid_body* addRigidBodyInstance (btRigidBody* body, const char* nodeName);
|
||||
|
||||
void updateRigidBodyPosition (btRigidBody* body, class domNode* node);
|
||||
void updateRigidBodyVelocity (btRigidBody* body);
|
||||
@@ -121,6 +189,11 @@ public:
|
||||
return m_use4componentVertices;
|
||||
}
|
||||
|
||||
void registerRigidBody(btRigidBody* body, const char* name);
|
||||
void deRegisterRigidBody(btRigidBody* body);
|
||||
|
||||
void registerConstraint(btTypedConstraint* constraint, const char* name);
|
||||
void deRegisterConstraint(btTypedConstraint* constraint);
|
||||
|
||||
|
||||
///those virtuals are called by load and save.
|
||||
@@ -148,6 +221,10 @@ public:
|
||||
{
|
||||
};
|
||||
|
||||
char* getLastFileName();
|
||||
|
||||
char* fixFileName(const char* lpCmdLine);
|
||||
|
||||
};
|
||||
|
||||
#endif //COLLADA_CONVERTER_H
|
||||
|
||||
@@ -134,8 +134,23 @@ void SpuCollisionTaskProcess::issueTask2()
|
||||
unsigned int taskId;
|
||||
unsigned int outputSize;
|
||||
|
||||
|
||||
for (int i=0;i<m_maxNumOutstandingTasks;i++)
|
||||
{
|
||||
if (m_taskBusy[i])
|
||||
{
|
||||
taskId = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
btAssert(taskId>=0);
|
||||
|
||||
|
||||
m_threadInterface->waitForResponse(&taskId, &outputSize);
|
||||
|
||||
// printf("issueTask taskId %d completed, numBusy=%d\n",taskId,m_numBusyTasks);
|
||||
|
||||
//printf("PPU: after issue, received event: %u %d\n", taskId, outputSize);
|
||||
|
||||
//postProcess(taskId, outputSize);
|
||||
@@ -251,15 +266,27 @@ SpuCollisionTaskProcess::flush2()
|
||||
while(m_numBusyTasks > 0)
|
||||
{
|
||||
// Consolidating SPU code
|
||||
unsigned int taskId;
|
||||
unsigned int taskId=-1;
|
||||
unsigned int outputSize;
|
||||
|
||||
for (int i=0;i<m_maxNumOutstandingTasks;i++)
|
||||
{
|
||||
if (m_taskBusy[i])
|
||||
{
|
||||
taskId = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
btAssert(taskId>=0);
|
||||
|
||||
|
||||
{
|
||||
|
||||
// SPURS support.
|
||||
m_threadInterface->waitForResponse(&taskId, &outputSize);
|
||||
}
|
||||
|
||||
// printf("flush2 taskId %d completed, numBusy =%d \n",taskId,m_numBusyTasks);
|
||||
//printf("PPU: flushing, received event: %u %d\n", taskId, outputSize);
|
||||
|
||||
//postProcess(taskId, outputSize);
|
||||
|
||||
@@ -540,6 +540,15 @@ SpuSolverTaskDesc* SolverTaskScheduler::getTask()
|
||||
unsigned int taskId;
|
||||
unsigned int outputSize;
|
||||
|
||||
for (int i=0;i<m_maxNumOutstandingTasks;i++)
|
||||
{
|
||||
if (m_taskBusy[i])
|
||||
{
|
||||
taskId = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_threadInterface->waitForResponse(&taskId, &outputSize);
|
||||
|
||||
m_taskBusy[taskId] = false;
|
||||
@@ -575,6 +584,14 @@ void SolverTaskScheduler::flushTasks()
|
||||
{
|
||||
unsigned int taskId;
|
||||
unsigned int outputSize;
|
||||
for (int i=0;i<m_maxNumOutstandingTasks;i++)
|
||||
{
|
||||
if (m_taskBusy[i])
|
||||
{
|
||||
taskId = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_threadInterface->waitForResponse(&taskId, &outputSize);
|
||||
|
||||
|
||||
@@ -87,6 +87,14 @@ void SpuRaycastTaskProcess::issueTask2()
|
||||
unsigned int taskId;
|
||||
unsigned int outputSize;
|
||||
|
||||
for (int i=0;i<m_maxNumOutstandingTasks;i++)
|
||||
{
|
||||
if (m_taskBusy[i])
|
||||
{
|
||||
taskId = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_threadInterface->waitForResponse(&taskId, &outputSize);
|
||||
|
||||
//printf("PPU: after issue, received event: %u %d\n", taskId, outputSize);
|
||||
@@ -154,6 +162,15 @@ SpuRaycastTaskProcess::flush2()
|
||||
unsigned int taskId;
|
||||
unsigned int outputSize;
|
||||
|
||||
for (int i=0;i<m_maxNumOutstandingTasks;i++)
|
||||
{
|
||||
if (m_taskBusy[i])
|
||||
{
|
||||
taskId = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//printf("Busy tasks... %d\n", m_numBusyTasks);
|
||||
|
||||
{
|
||||
|
||||
@@ -138,6 +138,14 @@ void SpuSampleTaskProcess::issueTask(void* sampleMainMemPtr,int sampleValue)
|
||||
unsigned int taskId;
|
||||
unsigned int outputSize;
|
||||
|
||||
for (int i=0;i<m_maxNumOutstandingTasks;i++)
|
||||
{
|
||||
if (m_taskBusy[i])
|
||||
{
|
||||
taskId = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_threadInterface->waitForResponse(&taskId, &outputSize);
|
||||
|
||||
//printf("PPU: after issue, received event: %u %d\n", taskId, outputSize);
|
||||
@@ -182,6 +190,14 @@ void SpuSampleTaskProcess::flush()
|
||||
unsigned int taskId;
|
||||
unsigned int outputSize;
|
||||
|
||||
for (int i=0;i<m_maxNumOutstandingTasks;i++)
|
||||
{
|
||||
if (m_taskBusy[i])
|
||||
{
|
||||
taskId = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
{
|
||||
|
||||
m_threadInterface->waitForResponse(&taskId, &outputSize);
|
||||
|
||||
@@ -99,9 +99,9 @@ BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||
int m_uniqueId;//m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc.
|
||||
int m_unusedPadding; //making the structure 16 bytes, better for alignment etc.
|
||||
|
||||
SIMD_FORCE_INLINE int getUid()
|
||||
SIMD_FORCE_INLINE int getUid() const
|
||||
{
|
||||
return m_uniqueId;//(int)this;
|
||||
return m_uniqueId;
|
||||
}
|
||||
|
||||
//used for memory pools
|
||||
|
||||
@@ -138,6 +138,11 @@ btBroadphasePair* btOverlappingPairCache::findPair(btBroadphaseProxy* proxy0, bt
|
||||
|
||||
int hash = getHash(proxyId1, proxyId2) & (m_overlappingPairArray.capacity()-1);
|
||||
|
||||
if (hash >= m_hashTable.size())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int index = m_hashTable[hash];
|
||||
while (index != BT_NULL_PAIR && equalsPair(m_overlappingPairArray[index], proxyId1, proxyId2) == false)
|
||||
{
|
||||
|
||||
@@ -26,7 +26,6 @@ btCollisionObject::btCollisionObject()
|
||||
m_deactivationTime(btScalar(0.)),
|
||||
m_friction(btScalar(0.5)),
|
||||
m_restitution(btScalar(0.)),
|
||||
m_typedUserInfo (NULL),
|
||||
m_userObjectPointer(0),
|
||||
m_internalOwner(0),
|
||||
m_hitFraction(btScalar(1.)),
|
||||
|
||||
@@ -27,7 +27,6 @@ subject to the following restrictions:
|
||||
|
||||
struct btBroadphaseProxy;
|
||||
class btCollisionShape;
|
||||
class btTypedUserInfo;
|
||||
#include "LinearMath/btMotionState.h"
|
||||
#include "LinearMath/btAlignedAllocator.h"
|
||||
|
||||
@@ -70,8 +69,6 @@ protected:
|
||||
///m_internalOwner is reserved to point to Bullet's btRigidBody. Don't use this, use m_userObjectPointer instead.
|
||||
void* m_internalOwner;
|
||||
|
||||
btTypedUserInfo* m_typedUserInfo;
|
||||
|
||||
///time of impact calculation
|
||||
btScalar m_hitFraction;
|
||||
|
||||
@@ -337,15 +334,6 @@ public:
|
||||
m_userObjectPointer = userPointer;
|
||||
}
|
||||
|
||||
btTypedUserInfo* getTypedUserInfo () const
|
||||
{
|
||||
return m_typedUserInfo;
|
||||
}
|
||||
|
||||
void setTypedUserInfo (btTypedUserInfo* typedUserInfo)
|
||||
{
|
||||
m_typedUserInfo = typedUserInfo;
|
||||
}
|
||||
|
||||
inline bool checkCollideWith(btCollisionObject* co)
|
||||
{
|
||||
|
||||
@@ -112,7 +112,6 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, i
|
||||
btCollisionShape* tmpShape = ob->getCollisionShape();
|
||||
|
||||
//copy over user pointers to temporary shape
|
||||
tm.setTypedUserInfo(tmpShape->getTypedUserInfo());
|
||||
tm.setUserPointer(tmpShape->getUserPointer());
|
||||
|
||||
ob->setCollisionShape( &tm );
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
virtual void getAabb (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
|
||||
{
|
||||
btVector3 halfExtents(getRadius(),getRadius(),getRadius());
|
||||
halfExtents[m_upAxis] = getRadius()*btScalar(2.0) + btScalar(0.5)*getHalfHeight();
|
||||
halfExtents[m_upAxis] = getRadius() + getHalfHeight();
|
||||
btMatrix3x3 abs_b = t.getBasis().absolute();
|
||||
btPoint3 center = t.getOrigin();
|
||||
btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents));
|
||||
|
||||
@@ -16,7 +16,6 @@ subject to the following restrictions:
|
||||
#ifndef COLLISION_SHAPE_H
|
||||
#define COLLISION_SHAPE_H
|
||||
|
||||
class btTypedUserInfo;
|
||||
#include "LinearMath/btTransform.h"
|
||||
#include "LinearMath/btVector3.h"
|
||||
#include "LinearMath/btMatrix3x3.h"
|
||||
@@ -28,11 +27,10 @@ class btCollisionShape
|
||||
{
|
||||
|
||||
void* m_userPointer;
|
||||
btTypedUserInfo* m_typedUserInfo;
|
||||
|
||||
public:
|
||||
|
||||
btCollisionShape() : m_userPointer(0), m_typedUserInfo (0)
|
||||
btCollisionShape() : m_userPointer(0)
|
||||
{
|
||||
}
|
||||
virtual ~btCollisionShape()
|
||||
@@ -105,15 +103,6 @@ public:
|
||||
return m_userPointer;
|
||||
}
|
||||
|
||||
btTypedUserInfo* getTypedUserInfo () const
|
||||
{
|
||||
return m_typedUserInfo;
|
||||
}
|
||||
|
||||
void setTypedUserInfo (btTypedUserInfo* typedUserInfo)
|
||||
{
|
||||
m_typedUserInfo = typedUserInfo;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //COLLISION_SHAPE_H
|
||||
|
||||
@@ -83,6 +83,7 @@ class btStridingMeshInterface
|
||||
m_scaling = scaling;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ btTypedConstraint::btTypedConstraint(btTypedConstraintType type)
|
||||
:m_userConstraintType(-1),
|
||||
m_userConstraintId(-1),
|
||||
m_constraintType (type),
|
||||
m_typedUserInfo(0),
|
||||
m_rbA(s_fixed),
|
||||
m_rbB(s_fixed),
|
||||
m_appliedImpulse(btScalar(0.))
|
||||
@@ -33,7 +32,6 @@ m_appliedImpulse(btScalar(0.))
|
||||
btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA)
|
||||
:m_userConstraintType(-1),
|
||||
m_userConstraintId(-1),
|
||||
m_typedUserInfo(0),
|
||||
m_constraintType (type),
|
||||
m_rbA(rbA),
|
||||
m_rbB(s_fixed),
|
||||
@@ -47,7 +45,6 @@ m_appliedImpulse(btScalar(0.))
|
||||
btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA,btRigidBody& rbB)
|
||||
:m_userConstraintType(-1),
|
||||
m_userConstraintId(-1),
|
||||
m_typedUserInfo(0),
|
||||
m_constraintType (type),
|
||||
m_rbA(rbA),
|
||||
m_rbB(rbB),
|
||||
|
||||
@@ -17,7 +17,6 @@ subject to the following restrictions:
|
||||
#define TYPED_CONSTRAINT_H
|
||||
|
||||
class btRigidBody;
|
||||
class btTypedUserInfo;
|
||||
#include "LinearMath/btScalar.h"
|
||||
|
||||
enum btTypedConstraintType
|
||||
@@ -34,7 +33,6 @@ class btTypedConstraint
|
||||
{
|
||||
int m_userConstraintType;
|
||||
int m_userConstraintId;
|
||||
btTypedUserInfo* m_typedUserInfo;
|
||||
|
||||
btTypedConstraintType m_constraintType;
|
||||
|
||||
@@ -100,6 +98,13 @@ public:
|
||||
{
|
||||
return m_userConstraintId;
|
||||
}
|
||||
|
||||
///unique id is needed by the btHashMap during serialization
|
||||
int getUid() const
|
||||
{
|
||||
return m_userConstraintId;
|
||||
}
|
||||
|
||||
btScalar getAppliedImpulse() const
|
||||
{
|
||||
return m_appliedImpulse;
|
||||
@@ -110,15 +115,6 @@ public:
|
||||
return m_constraintType;
|
||||
}
|
||||
|
||||
btTypedUserInfo* getTypedUserInfo () const
|
||||
{
|
||||
return m_typedUserInfo;
|
||||
}
|
||||
|
||||
void setTypedUserInfo (btTypedUserInfo* typedUserInfo)
|
||||
{
|
||||
m_typedUserInfo = typedUserInfo;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //TYPED_CONSTRAINT_H
|
||||
|
||||
301
src/LinearMath/btHashMap.h
Normal file
301
src/LinearMath/btHashMap.h
Normal file
@@ -0,0 +1,301 @@
|
||||
#ifndef BT_HASH_MAP_H
|
||||
#define BT_HASH_MAP_H
|
||||
|
||||
#include "btAlignedObjectArray.h"
|
||||
|
||||
const int BT_HASH_NULL=0xffffffff;
|
||||
|
||||
template <class Value>
|
||||
class btHashKey
|
||||
{
|
||||
int m_uid;
|
||||
public:
|
||||
|
||||
btHashKey(int uid)
|
||||
:m_uid(uid)
|
||||
{
|
||||
}
|
||||
|
||||
int getUid() const
|
||||
{
|
||||
return m_uid;
|
||||
}
|
||||
|
||||
//to our success
|
||||
SIMD_FORCE_INLINE unsigned int getHash()const
|
||||
{
|
||||
int key = m_uid;
|
||||
// Thomas Wang's hash
|
||||
key += ~(key << 15);
|
||||
key ^= (key >> 10);
|
||||
key += (key << 3);
|
||||
key ^= (key >> 6);
|
||||
key += ~(key << 11);
|
||||
key ^= (key >> 16);
|
||||
return key;
|
||||
}
|
||||
|
||||
btHashKey getKey(const Value& value) const
|
||||
{
|
||||
return btHashKey(value.getUid());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class Value>
|
||||
class btHashKeyPtr
|
||||
{
|
||||
int m_uid;
|
||||
public:
|
||||
|
||||
btHashKeyPtr(int uid)
|
||||
:m_uid(uid)
|
||||
{
|
||||
}
|
||||
|
||||
int getUid() const
|
||||
{
|
||||
return m_uid;
|
||||
}
|
||||
|
||||
//to our success
|
||||
SIMD_FORCE_INLINE unsigned int getHash()const
|
||||
{
|
||||
int key = m_uid;
|
||||
// Thomas Wang's hash
|
||||
key += ~(key << 15);
|
||||
key ^= (key >> 10);
|
||||
key += (key << 3);
|
||||
key ^= (key >> 6);
|
||||
key += ~(key << 11);
|
||||
key ^= (key >> 16);
|
||||
return key;
|
||||
}
|
||||
|
||||
btHashKeyPtr getKey(const Value& value) const
|
||||
{
|
||||
return btHashKeyPtr(value->getUid());
|
||||
}
|
||||
};
|
||||
|
||||
template <class Key, class Value>
|
||||
class btHashMap
|
||||
{
|
||||
|
||||
btAlignedObjectArray<int> m_hashTable;
|
||||
btAlignedObjectArray<int> m_next;
|
||||
btAlignedObjectArray<Value> m_valueArray;
|
||||
|
||||
|
||||
|
||||
void growTables(const Key& key)
|
||||
{
|
||||
int newCapacity = m_valueArray.capacity();
|
||||
|
||||
if (m_hashTable.size() < newCapacity)
|
||||
{
|
||||
//grow hashtable and next table
|
||||
int curHashtableSize = m_hashTable.size();
|
||||
|
||||
m_hashTable.resize(newCapacity);
|
||||
m_next.resize(newCapacity);
|
||||
|
||||
int i;
|
||||
|
||||
for (i= 0; i < newCapacity; ++i)
|
||||
{
|
||||
m_hashTable[i] = BT_HASH_NULL;
|
||||
}
|
||||
for (i = 0; i < newCapacity; ++i)
|
||||
{
|
||||
m_next[i] = BT_HASH_NULL;
|
||||
}
|
||||
|
||||
for(i=0;i<curHashtableSize;i++)
|
||||
{
|
||||
const Value& value = m_valueArray[i];
|
||||
|
||||
int hashValue = key.getKey(value).getHash() & (m_valueArray.capacity()-1); // New hash value with new mask
|
||||
m_next[i] = m_hashTable[hashValue];
|
||||
m_hashTable[hashValue] = i;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void insert(const Key& key, const Value& value) {
|
||||
int hash = key.getHash() & (m_valueArray.capacity()-1);
|
||||
//don't add it if it is already there
|
||||
if (find(key))
|
||||
{
|
||||
return;
|
||||
}
|
||||
int count = m_valueArray.size();
|
||||
int oldCapacity = m_valueArray.capacity();
|
||||
m_valueArray.push_back(value);
|
||||
int newCapacity = m_valueArray.capacity();
|
||||
if (oldCapacity < newCapacity)
|
||||
{
|
||||
growTables(key);
|
||||
//hash with new capacity
|
||||
hash = key.getHash() & (m_valueArray.capacity()-1);
|
||||
}
|
||||
m_next[count] = m_hashTable[hash];
|
||||
m_hashTable[hash] = count;
|
||||
}
|
||||
|
||||
void remove(const Key& key) {
|
||||
|
||||
int hash = key.getHash() & (m_valueArray.capacity()-1);
|
||||
|
||||
int pairIndex = findIndex(key);
|
||||
|
||||
if (pairIndex ==BT_HASH_NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the pair from the hash table.
|
||||
int index = m_hashTable[hash];
|
||||
btAssert(index != BT_HASH_NULL);
|
||||
|
||||
int previous = BT_HASH_NULL;
|
||||
while (index != pairIndex)
|
||||
{
|
||||
previous = index;
|
||||
index = m_next[index];
|
||||
}
|
||||
|
||||
if (previous != BT_HASH_NULL)
|
||||
{
|
||||
btAssert(m_next[previous] == pairIndex);
|
||||
m_next[previous] = m_next[pairIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_hashTable[hash] = m_next[pairIndex];
|
||||
}
|
||||
|
||||
// We now move the last pair into spot of the
|
||||
// pair being removed. We need to fix the hash
|
||||
// table indices to support the move.
|
||||
|
||||
int lastPairIndex = m_valueArray.size() - 1;
|
||||
|
||||
// If the removed pair is the last pair, we are done.
|
||||
if (lastPairIndex == pairIndex)
|
||||
{
|
||||
m_valueArray.pop_back();
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the last pair from the hash table.
|
||||
const Value* lastValue = &m_valueArray[lastPairIndex];
|
||||
int lastHash = key.getKey(*lastValue).getHash() & (m_valueArray.capacity()-1);
|
||||
|
||||
index = m_hashTable[lastHash];
|
||||
btAssert(index != BT_HASH_NULL);
|
||||
|
||||
previous = BT_HASH_NULL;
|
||||
while (index != lastPairIndex)
|
||||
{
|
||||
previous = index;
|
||||
index = m_next[index];
|
||||
}
|
||||
|
||||
if (previous != BT_HASH_NULL)
|
||||
{
|
||||
btAssert(m_next[previous] == lastPairIndex);
|
||||
m_next[previous] = m_next[lastPairIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_hashTable[lastHash] = m_next[lastPairIndex];
|
||||
}
|
||||
|
||||
// Copy the last pair into the remove pair's spot.
|
||||
m_valueArray[pairIndex] = m_valueArray[lastPairIndex];
|
||||
|
||||
// Insert the last pair into the hash table
|
||||
m_next[pairIndex] = m_hashTable[lastHash];
|
||||
m_hashTable[lastHash] = pairIndex;
|
||||
|
||||
m_valueArray.pop_back();
|
||||
|
||||
}
|
||||
|
||||
|
||||
int size() const
|
||||
{
|
||||
return m_valueArray.size();
|
||||
}
|
||||
|
||||
const Value* getAtIndex(int index) const
|
||||
{
|
||||
btAssert(index < m_valueArray.size());
|
||||
|
||||
return &m_valueArray[index];
|
||||
}
|
||||
|
||||
Value* getAtIndex(int index)
|
||||
{
|
||||
btAssert(index < m_valueArray.size());
|
||||
|
||||
return &m_valueArray[index];
|
||||
}
|
||||
|
||||
Value* operator[](const Key& key) {
|
||||
return find(key);
|
||||
}
|
||||
|
||||
const Value* find(const Key& key) const
|
||||
{
|
||||
int index = findIndex(key);
|
||||
if (index == BT_HASH_NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return &m_valueArray[index];
|
||||
}
|
||||
|
||||
Value* find(const Key& key)
|
||||
{
|
||||
int index = findIndex(key);
|
||||
if (index == BT_HASH_NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return &m_valueArray[index];
|
||||
}
|
||||
|
||||
|
||||
int findIndex(const Key& key) const
|
||||
{
|
||||
int hash = key.getHash() & (m_valueArray.capacity()-1);
|
||||
|
||||
if (hash >= m_hashTable.size())
|
||||
{
|
||||
return BT_HASH_NULL;
|
||||
}
|
||||
|
||||
int index = m_hashTable[hash];
|
||||
while ((index != BT_HASH_NULL) && (key.getUid() == key.getKey(m_valueArray[index]).getUid()) == false)
|
||||
{
|
||||
index = m_next[index];
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
m_hashTable.clear();
|
||||
m_next.clear();
|
||||
m_valueArray.clear();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //BT_HASH_MAP_H
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2008 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 BT_TYPE_USER_INFO_H
|
||||
#define BT_TYPE_USER_INFO_H
|
||||
|
||||
class btTypedUserInfo
|
||||
{
|
||||
protected:
|
||||
int m_type;
|
||||
char* m_name;
|
||||
void* m_userPointer;
|
||||
|
||||
/* Only systems internal to Bullet are allowed
|
||||
* to use this pointer
|
||||
*/
|
||||
void* m_privatePointer;
|
||||
public:
|
||||
btTypedUserInfo ()
|
||||
{
|
||||
m_type = 0;
|
||||
m_name = 0;
|
||||
m_userPointer = 0;
|
||||
m_privatePointer = 0;
|
||||
}
|
||||
|
||||
virtual ~btTypedUserInfo () {};
|
||||
|
||||
int getType () { return m_type; }
|
||||
void setType (int type) { m_type = type; }
|
||||
|
||||
char* getName () { return m_name; }
|
||||
void setName (char* name) { m_name = name; }
|
||||
|
||||
void* getUserPointer () { return m_userPointer; }
|
||||
void setUserPointer (void* userPointer) { m_userPointer = userPointer; }
|
||||
|
||||
void* getPrivatePointer () { return m_privatePointer; }
|
||||
void setPrivatePointer (void* privatePointer) { m_privatePointer = privatePointer; }
|
||||
};
|
||||
|
||||
#endif //BT_TYPE_USER_INFO_H
|
||||
Reference in New Issue
Block a user