Collision shape and meshes question(directx)

a_asvsfs
Posts: 6
Joined: Fri Jun 26, 2009 7:12 pm

Collision shape and meshes question(directx)

Post by a_asvsfs »

hi,
im a beginner in Bullet
im using bullet with directx and have some problem with collision shape i dont know how to match collision shape size with my meshes size for example i have a boxshape collision for predefined mesh like teapot ...
second question is about integrating with directx ,im using motion state for translation and for rotation like following code(for test)

Code: Select all

      body1->getMotionState()->getWorldTransform(mytrans);
			
		
			btQuaternion qua;
			D3DXQUATERNION qIn;
			D3DXMATRIX rot;
			mytrans.getBasis().getRotation(qua);
			qIn.x=qua.getX();
			qIn.y=qua.getY();
			qIn.z=qua.getZ();
			qIn.w=qua.getW();
//rotation matrix 
			D3DXMatrixRotationQuaternion(&rot,&qIn);
			D3DXMATRIX mm;
//translation matrix
		D3DXMatrixTranslation(&mm,mytrans.getOrigin().getX(),mytrans.getOrigin().getY(),mytrans.getOrigin().getZ());
''mm'' is my final translation matrix to use in directx and ''rot'' for rotation
is there anything wrong?
B_old
Posts: 79
Joined: Tue Sep 26, 2006 1:10 pm

Re: Collision shape and meshes question(directx)

Post by B_old »

Often, the collision shape is only an approximation of the rendering shape. It can be anything you like.
Regarding your second question, I think you could do it a little bit easier. btTransform consists of an origin and a rotation, which you can use to directly construct your matrix.
One of the easiest methods I know of is to do use getOpenGLMatrix(), somewhat like this:

Code: Select all

body1->getMotionState()->getWorldTransform(mytrans)

btScalar m[16];

mytrans.getOpenGLMatrix(m);

D3DXMATRIX transform(m[0], m[1], m[2], 0.f,
                     m[4], m[5], m[6], 0.f,
                     m[8], m[9], m[10], 0.f
                     m[12], m[13], m[14], 1.f)
And then directly use that matrix.
a_asvsfs
Posts: 6
Joined: Fri Jun 26, 2009 7:12 pm

Re: Collision shape and meshes question(directx)

Post by a_asvsfs »

thx for reply
but about collision shape .. it could be a huge cube or a small cube how this collision shape match his self with my render shape? if i just use collision shapes they will fit them selves? and there is no need for me to do anything? like scaling or something...

for example when im making a new boxshape i must set its size ... how can i set it when i dont know my meshes size....?
B_old
Posts: 79
Joined: Tue Sep 26, 2006 1:10 pm

Re: Collision shape and meshes question(directx)

Post by B_old »

Personally I just match the collision shape with the render mesh per hand, because I always know what render meshes I will be using. And if the render mesh gets scaled I scale the collision shape accordingly.
Are you looking for a way to automatically construct collision shapes?
a_asvsfs
Posts: 6
Joined: Fri Jun 26, 2009 7:12 pm

Re: Collision shape and meshes question(directx)

Post by a_asvsfs »

i have still this problem ... for example i have a complex mesh and i want to make a collision shape (for example boxshape) i dont know how to set its size or bullet do it automatically !!
B_old
Posts: 79
Joined: Tue Sep 26, 2006 1:10 pm

Re: Collision shape and meshes question(directx)

Post by B_old »

Can you be a little bit clearer perhaps? btBoxShape(btVector3(x, y, z)): that way you can create a boxshape (which you seem to want) with the dimension (x, y, z). Is there a way for you to know those dimensions beforehand? I mean, if you know what complex mesh you are using, you should be able to choose plausible dimensions for the collision shape.
Maybe I totally misunderstand you though. :?