Mesh Collision detect problem

Please don't post Bullet support questions here, use the above forums instead.
Tarinee
Posts: 1
Joined: Sat Sep 11, 2010 6:33 pm

Mesh Collision detect problem

Post by Tarinee »

Hi,
First sorry for my English (It's not good).I'm a new in 3d graphic and bullet physics and now I use bullet in my project.In the project I integrate ARToolKit and Bullet together.
This is my code in bullet part.

REAL gVertices2[NUM_VERTICES * 3] = {


-20, 0, 20, 20 ,0 ,20, 20, 0 ,-20, -20, 0 ,-20, -20, 25, 20, 20 ,25, 20, 20 ,25 ,-20, -20, 25, -20


};

int gIndices2[NUM_TRIANGLES][3] = {

0, 1, 5, 0, 5, 4, 1, 2, 6, 1, 6, 5, 2, 3, 7,
2, 7, 6, 3, 0, 4, 3, 4, 7, 2, 0, 3,
1, 0, 2, 6, 7, 4,5, 6, 4

};


//***************************THE TRIMESH********************************************//

// ============================================================================
// Functions
// ============================================================================
void InitBullet()
{

btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btBroadphaseInterface* broadphase = new btSimpleBroadphase();
btConstraintSolver* constraintSolver = new btSequentialImpulseConstraintSolver();
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,constraintSolver,collisionConfiguration);

dynamicsWorld->setGravity(btVector3(0,0,10));


/// ++++++++++++++++++ Craete Ground ++++++++++++++++++

btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(2000.),btScalar(2000.),btScalar(20.)));

btAlignedObjectArray<btCollisionShape*> collisionShapes;

collisionShapes.push_back(groundShape);

btTransform groundTransform;
groundTransform.setIdentity(); // Set Identity matrix

groundTransform.setOrigin(btVector3(0,0,groundPosi));

{
btScalar mass(0.);

//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);

btVector3 localInertia(0,0,0);
if (isDynamic)
groundShape->calculateLocalInertia(mass,localInertia);

//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);

//add the body to the dynamics world
dynamicsWorld->addRigidBody(body);

}

///++++++++++++++ Create object 1 ++++++++++++++ Kanji

{
// create trimesh
btCollisionShape * m_trimeshShape;
btTriangleIndexVertexArray* indexVertexArrays = new btTriangleIndexVertexArray(NUM_TRIANGLES,
&gIndices2[0][0],3*sizeof(int), NUM_VERTICES,(REAL*) &gVertices2[0],sizeof(REAL)*3);
btGImpactMeshShape * trimesh = new btGImpactMeshShape(indexVertexArrays);
trimesh->setLocalScaling(btVector3(1,1,1));
trimesh->updateBound();
m_trimeshShape = trimesh;

//register algorithm

btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(dynamicsWorld ->getDispatcher());
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);


float mass = 4.f;
btTransform startTransform;
startTransform.setIdentity();
btVector3 localInertia(0.0,0.0,0.0);
startTransform.setOrigin(btVector3(0,0,initHigh));
m_trimeshShape->calculateLocalInertia(mass,localInertia);


//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,m_trimeshShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
body->setCollisionFlags(0);
body->setRestitution(btScalar(1.0f));
body->setActivationState(DISABLE_DEACTIVATION);

dynamicsWorld->addRigidBody(body);

}
///++++++++++++++ Create object 2 ++++++++++++++

{
// create trimesh
btCollisionShape * m_trimeshShape;
btTriangleIndexVertexArray* indexVertexArrays = new btTriangleIndexVertexArray(NUM_TRIANGLES,
&gIndices2[0][0],3*sizeof(int), NUM_VERTICES,(REAL*) &gVertices2[0],sizeof(REAL)*3);
btGImpactMeshShape * trimesh = new btGImpactMeshShape(indexVertexArrays);
trimesh->setLocalScaling(btVector3(1.f,1.f,1.f));
trimesh->updateBound();
m_trimeshShape = trimesh;

//register algorithm

btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(dynamicsWorld ->getDispatcher());
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);


float mass = 4.f;
btTransform startTransform;
startTransform.setIdentity();
btVector3 localInertia(0.0,0.0,0.0);
m_trimeshShape->calculateLocalInertia(mass,localInertia);
startTransform.setRotation((btQuaternion(0,0,0,1)));

//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,m_trimeshShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);

body->setLinearVelocity(btVector3(0,0,0));
body->setFriction(btScalar(15.0f));
body->setAngularVelocity(btVector3(0,0,0));

dynamicsWorld->addRigidBody(body);

}


}
For this code I created 2 rectangle ( collision object ) by btTriangleIndexVertexArray , render this graphic by vrml viewer (the project included openVRML) and update position and rotation of the graphics
by get position and rotation from bullet object.After that I test to move 1'st rectangle to hit the second along x-axis.I think of it correct the 2'nd rectangle should move along only x-axis but I found
it rotate and move in 3 axis.It's not correct? and What wrong? Help me please.
Please see VDO

[color=#FF40BF]http://www.dailymotion.c ... ch[/color]


The Left rectangle , position and rotation of this object can change by keyboard but the position and rotation of right rectangle depend on bullet object.