Issue with time to load many rigid bodies
Posted: Mon Nov 17, 2014 11:21 pm
I am having a problem with trying to add many rigid bodies for some reason the more I add the slower it gets to keep adding more (and I got a lot to add) is this a normal issue?
I am new to Bullet so I am hoping someone can take a look at this issue and figure out what I am doing wrong here or if there is a better way to this.
A bit more of an explanation of what this is for is for the GTA mod San Andreas Multiplayer and issue we have is there is currently no way to detect world collisions so this is being developed as a plugin to address that issue by using raytest. All the testing is working fine and indeed in game using the raytest is working perfectly against the few added objects. It's really only when I start adding thousands of rigid bodies the problem comes up any ideas would be appreciated thanks!
Thanks a lot for looking at this problem.
I am new to Bullet so I am hoping someone can take a look at this issue and figure out what I am doing wrong here or if there is a better way to this.
A bit more of an explanation of what this is for is for the GTA mod San Andreas Multiplayer and issue we have is there is currently no way to detect world collisions so this is being developed as a plugin to address that issue by using raytest. All the testing is working fine and indeed in game using the raytest is working perfectly against the few added objects. It's really only when I start adding thousands of rigid bodies the problem comes up any ideas would be appreciated thanks!
Code: Select all
btRigidBody* addCollsionSphere(const btQuaternion& sphereRot, const btVector3& sphereOffset, const btVector3& spherePos, const btScalar sphereRadius)
{
// Translate rotation
btVector3 NewPoint;
NewPoint = transformPoint(sphereRot, sphereOffset);
btSphereShape* sphere = new btSphereShape(sphereRadius);
// Add offsets
NewPoint += spherePos;
// Set the default motion
btDefaultMotionState* sphereposition = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), NewPoint));
// Contruction body for the box
btRigidBody::btRigidBodyConstructionInfo sphereRigidBodyCI(0, sphereposition, sphere, btVector3(0, 0, 0));
// Create the rigid body
btRigidBody* rigidBody = new btRigidBody(sphereRigidBodyCI);
dynamicsWorld->addRigidBody(rigidBody);
return rigidBody;
}
btRigidBody* addCollisionBox(const btQuaternion& boxRotation, const btVector3& boxMinXYZ, const btVector3& boxMaxXYZ, const btVector3& boxPos)
{
btVector3 boxCenter;
btVector3 boxSize;
// Calculate box center
boxCenter = (boxMinXYZ + boxMaxXYZ) / 2;
// Calculate box size
boxSize = (boxMaxXYZ - boxMinXYZ) / 2;
// Translate rotation
btVector3 NewPoint;
NewPoint = transformPoint(boxRotation, boxCenter);
// Add offsets
NewPoint += boxPos;
// Create a box shape
btBoxShape* box = new btBoxShape(boxSize);
// Set the default motion
btDefaultMotionState* boxposition = new btDefaultMotionState(btTransform(boxRotation, NewPoint));
// Contruction body for the box
btRigidBody::btRigidBodyConstructionInfo boxRigidBodyCI(0, boxposition, box, btVector3(0, 0, 0));
// Create the rigid body
btRigidBody* rigidBody = new btRigidBody(boxRigidBodyCI);
dynamicsWorld->addRigidBody(rigidBody);
return rigidBody;
}
btRigidBody* addCollisionMesh(const btQuaternion& meshRotation, const btVector3& meshPos, const struct trianglebtVector triangles[], const int size)
{
// Create a triangular mesh
btTriangleMesh* trimesh = new btTriangleMesh();
for (int i = 0; i < size; i++)
{
// Add triangle faces
trimesh->addTriangle(triangles[i].p1, triangles[i].p2, triangles[i].p3);
}
// Instantiate a triangular mesh shape
btBvhTriangleMeshShape* shape = new btBvhTriangleMeshShape(trimesh, true);
// Set the default motion
btDefaultMotionState* shapeposition = new btDefaultMotionState(btTransform(meshRotation, meshPos));
// Contruction body for the shape
btRigidBody::btRigidBodyConstructionInfo shapeRigidBodyCI(0, shapeposition, shape, btVector3(0, 0, 0));
// Create the rigid body
btRigidBody* rigidBody = new btRigidBody(shapeRigidBodyCI);
dynamicsWorld->addRigidBody(rigidBody);
return rigidBody;
}