So far I have only been able to update the position of the collision object(box) with the object(cube), but have only been able to either receive collisions, and the collision shape conforms to the alignment of the box (non-rotating), or tracks with the position of the object, but only the collision shape rotates,not the object.
The second behavior I achieved, was all collision shapes would align perfectly with their respective objects, but would not update movement, position or rotation from the physics engine, only by directly setting their respective x,y,z positions.
A common problem I witnessed, was the lack of setting the local inertia, which I have done. In my update, I assign setEulerZYX() from the rotation x,y and z to my btQuaternion, then because I am using glm as my math library, I assign the btQuaternion x,y,z,w to the glm quarternion x,y,z,w(I need to do this to glm::mat4_cast() to my local rotate matrix)
After this I assign the btTransform x,y,z to the glm::vec3 position x,y,z (which I use in my local translate matrix), then I call setRotation() on my btTransform by parsing in my btQuaternion, and finally call setCenterOfMassTransform() on the rigid body, parsing in the btTransform.
If I remove the call to setCenterOfMassTransform(), the collision shapes ignore their respective objects, and I can view the collision shapes behaving as expected and reacting to each other with the debug view activated.
I want the objects to react to the physics and the collision shapes to align to the orientation and track their positions, with users enabled the ability to move them if so desired, any thoughts on what I am doing wrong here or any further insights would be greatly appreciated.
Code exert from my update call:
Code: Select all
//Set the euler angles from the user-input x,y,z to orientate the object
qOrientation.setEulerZYX(rotZ, rotY, rotX);
//Assign the quartonian for use with glm matrices
orientation.x = qOrientation.x();
orientation.y = qOrientation.y();
orientation.z = qOrientation.z();
orientation.w = qOrientation.w();
/********************************************
//Test code to assign collision shape position to the object
btVector3 point;
point = rigidBody->getCenterOfMassPosition();
positon.x = trans.getOrigin().getX();
positon.y = trans.getOrigin().getY();
positon.z = trans.getOrigin().getZ();
trans.setOrigin(point);
*********************************************/
trans.setRotation(qOrientation);
rigidBody->setCenterOfMassTransform(trans);
//Combine the matrices together
model = worldTranslate * localRotate * localScale;
worldTranslate = localTranslate;
//Cast orientation to the matrix for use
localRotate = glm::mat4_cast(orientation);
localScale = glm::scale(glm::mat4(1.0f), glm::vec3(scale.x,scale.y,scale.z));
localTranslate = glm::translate(glm::mat4(1.0f),glm::vec3(positon.x,positon.y,positon.z));