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:
Thank you!
Cocos3D: btBoxShape overlaps edges on collision - noob
-
- Posts: 1
- Joined: Fri Sep 02, 2011 4:45 pm
Cocos3D: btBoxShape overlaps edges on collision - noob
You do not have the required permissions to view the files attached to this post.
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Cocos3D: btBoxShape overlaps edges on collision - noob
You don't need to convert from matrix to quaternion, try to get the quaterion directly from Bullet.
Hope this helps,
Erwin
Code: Select all
btVector3 gPos = gTrans.getOrigin();
btQuaternion gOrn = gTrans.getRotation();
Erwin