Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Sep 02, 2011 4:55 pm 
Offline

Joined: Fri Sep 02, 2011 4:45 pm
Posts: 1
Hello, I have a noob question. this is my first project with bullet physics.
I am making a simple iPad prototype using cocos3D.

I have 2 simple cube meshes of size (1,1,1), which I clone and assign rigid bodies to them:

btCollisionShape *shape = new btBoxShape(btVector3(.5 ,.5 ,.5 ));

The way I setup the rigid body for each of them:

btScalar mass=5;
btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(_cc3BlockNode.quaternion.x,_cc3BlockNode.quaternion.y,_cc3BlockNode.quaternion.z,_cc3BlockNode.quaternion.w),
btVector3(_cc3BlockNode.position.x , _cc3BlockNode.position.y , _cc3BlockNode.position.z )));

// Create a rigid body
btVector3 localInertia(0, 0, 0);
shape->calculateLocalInertia(mass, localInertia);

btRigidBody::btRigidBodyConstructionInfo bodyDescriptor(mass,motionState,shape,localInertia);
btRigidBody * rigidBody =new btRigidBody(bodyDescriptor);
rigidBody->setRestitution(btScalar(.4));
rigidBody->setActivationState(DISABLE_DEACTIVATION);
rigidBody->setDamping(0.4,0.4);
rigidBody->setFriction(btScalar(1));

gravity is -9.8




after world tick the properties are read back to the CC3nodes:

_discreteDynamicsWorld->stepSimulation(timeInterval, 200);
object.rigidBody->getMotionState()->getWorldTransform(gTrans);
btVector3 gPos = gTrans.getOrigin();
btVector3 axis = gTrans.getRotation().getAxis();
float angle = gTrans.getRotation().getAngle();
CC3Vector4 quaternion;
float sinAngle;
angle *= 0.5f;
axis = axis.normalized();
sinAngle = sin(angle);
quaternion.x = (axis.getX() * sinAngle);
quaternion.y = (axis.getY() * sinAngle);
quaternion.z = (axis.getZ() * sinAngle);
quaternion.w = cos(angle);

_cc3BlockNode.location = CC3VectorMake(gPos.getX() , gPos.getY() , gPos.getZ() );
_cc3BlockNode.quaternion = quaternion;


works decent, except, sometimes, when the block is positioned at an angle towards another block's surface, that angle goes inside of another block. Please, see the reference image:

Attachment:
Screen Shot 2011-09-02 at 12.11.29 PM.png
Screen Shot 2011-09-02 at 12.11.29 PM.png [ 159.13 KiB | Viewed 1041 times ]


Thank you!


Top
 Profile  
 
PostPosted: Fri Sep 02, 2011 11:59 pm 
Offline
Site Admin
User avatar

Joined: Sun Jun 26, 2005 6:43 pm
Posts: 3744
Location: California, USA
You don't need to convert from matrix to quaternion, try to get the quaterion directly from Bullet.

Code:
btVector3 gPos = gTrans.getOrigin();
btQuaternion gOrn = gTrans.getRotation();


Hope this helps,
Erwin


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group