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 [ 159.13 KiB | Viewed 1040 times ]
Thank you!