Hi, all, I find a very strange problem.
I use Bullet for my haptics-based simulation, OpenGL for graphics, OpenHaptics for Haptics, and Bullet for Collision detection and Physics.
All the source code is the same.
In Release Version, the software works well, no any problem.
But In Debug Version, the object can only move, no any rotation. I output the transform data from getWorldTransform(), the rotation data is almost zero.
What is the problem?
In release version, the linked libraries are: BulletCollision.lib, BulletDynamics.lib, BulletFileLoader.lib, BulletMultiThreaded.lib, BulletSoftBody.lib, BulletWorldImporter.lib, ConvexDecomposition.lib, GIMPACTUtils.lib, GLUI.lib, LinearMath.lib, OpenGLSupport.lib
And in debug version, the linked libraries are: BulletCollision_Debug.lib, BulletDynamics_Debug.lib, BulletFileLoader_Debug.lib, BulletMultiThreaded_Debug.lib, BulletSoftBody_Debug.lib, BulletWorldImporter_Debug.lib, ConvexDecomposition_Debug.lib, GIMPACTUtils_Debug.lib, GLUI_Debug.lib, LinearMath_Debug.lib, OpenGLSupport_Debug.lib
Everything is the same, somebody has idea?
Help........... thanks
Rotation Problem in Debug Version and Release Version
-
- Posts: 11
- Joined: Fri Oct 19, 2012 3:37 am
-
- Posts: 11
- Joined: Fri Oct 19, 2012 3:37 am
Re: Rotation Problem in Debug Version and Release Version
Hi, all, just now I find the problem.
I output the inertia value from the function: m_trimeshShape->calculateLocalInertia( mass, inertia );
In the release version, the inertia value is (0.11387,0.210512,0.114837,0), so it works, the rotation is correct, no problem.
In the debug version, the inertia value is (1.29361e+014, 1.29361e+014, 1.29361e+014, 0), this is not correct, so there is no any rotation. The problem is here.
But I do not know why the inertia value is different from the debug version and release version.
Here is my source code, my mesh is a concave object.
btRigidBody* BulletWrap::addTriangleMeshDynamicConcave(int numTriangles, int *indices, int numVertices, float *verts, btVector3 &position, btVector3
&inertia, btScalar mass, btScalar restitution, bool collision)
{
// create trimesh
btTriangleIndexVertexArray* indexVertexArrays = new btTriangleIndexVertexArray(numTriangles,indices,3*sizeof(int),numVertices, verts,3*sizeof(float));
btGImpactMeshShape * trimesh = new btGImpactMeshShape(indexVertexArrays);
trimesh->setLocalScaling(btVector3(1.f,1.f,1.f));
trimesh->updateBound();
btCollisionShape *m_trimeshShape = trimesh;
btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(m_world->getDispatcher());
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);
btTransform trans;
trans.setIdentity();
trans.setRotation(btQuaternion(btVector3(1,0.0,0.0),3.14));
trans.setOrigin( position );
inertia.setZero();
m_trimeshShape->calculateLocalInertia( mass, inertia ); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!problem is here
//inertia[0] = 0.113870; inertia[1] = 0.210512; inertia[2] = 0.114837; inertia[3] = 0.0;
std::cout<<inertia[0]<<", "<<inertia[1]<<", "<<inertia[2]<<", "<<inertia[3]<<"\n "<<std::endl;
btDefaultMotionState* motionstate = new btDefaultMotionState( trans );
btRigidBody* body = new btRigidBody( mass, motionstate, m_trimeshShape, inertia );
body->setRestitution( restitution );
m_world->addRigidBody( body );
body->setActivationState(ACTIVE_TAG);
body->setDamping(0.1,0.5);
if( collision )
m_collisionShapes.push_back(m_trimeshShape);
return body;
}
Then I call the function like this to add the concave meshi as rigid body.
addTriangleMeshDynamicConcave(objmodel->numtriangles, indices, objmodel->numvertices, objmodel->vertices, btVector3(-10.0,15.0,0.0), btVector3(0.0,0.0,0.0), 1.0/10.0, 0.0,true);
........
Does anybody know how to fix the problem?
I need help, thanks a lot.
I output the inertia value from the function: m_trimeshShape->calculateLocalInertia( mass, inertia );
In the release version, the inertia value is (0.11387,0.210512,0.114837,0), so it works, the rotation is correct, no problem.
In the debug version, the inertia value is (1.29361e+014, 1.29361e+014, 1.29361e+014, 0), this is not correct, so there is no any rotation. The problem is here.
But I do not know why the inertia value is different from the debug version and release version.
Here is my source code, my mesh is a concave object.
btRigidBody* BulletWrap::addTriangleMeshDynamicConcave(int numTriangles, int *indices, int numVertices, float *verts, btVector3 &position, btVector3
&inertia, btScalar mass, btScalar restitution, bool collision)
{
// create trimesh
btTriangleIndexVertexArray* indexVertexArrays = new btTriangleIndexVertexArray(numTriangles,indices,3*sizeof(int),numVertices, verts,3*sizeof(float));
btGImpactMeshShape * trimesh = new btGImpactMeshShape(indexVertexArrays);
trimesh->setLocalScaling(btVector3(1.f,1.f,1.f));
trimesh->updateBound();
btCollisionShape *m_trimeshShape = trimesh;
btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(m_world->getDispatcher());
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);
btTransform trans;
trans.setIdentity();
trans.setRotation(btQuaternion(btVector3(1,0.0,0.0),3.14));
trans.setOrigin( position );
inertia.setZero();
m_trimeshShape->calculateLocalInertia( mass, inertia ); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!problem is here
//inertia[0] = 0.113870; inertia[1] = 0.210512; inertia[2] = 0.114837; inertia[3] = 0.0;
std::cout<<inertia[0]<<", "<<inertia[1]<<", "<<inertia[2]<<", "<<inertia[3]<<"\n "<<std::endl;
btDefaultMotionState* motionstate = new btDefaultMotionState( trans );
btRigidBody* body = new btRigidBody( mass, motionstate, m_trimeshShape, inertia );
body->setRestitution( restitution );
m_world->addRigidBody( body );
body->setActivationState(ACTIVE_TAG);
body->setDamping(0.1,0.5);
if( collision )
m_collisionShapes.push_back(m_trimeshShape);
return body;
}
Then I call the function like this to add the concave meshi as rigid body.
addTriangleMeshDynamicConcave(objmodel->numtriangles, indices, objmodel->numvertices, objmodel->vertices, btVector3(-10.0,15.0,0.0), btVector3(0.0,0.0,0.0), 1.0/10.0, 0.0,true);
........
Does anybody know how to fix the problem?
I need help, thanks a lot.