btBoxShape rotation

rawtass
Posts: 8
Joined: Sun Dec 30, 2012 8:56 pm

btBoxShape rotation

Post by rawtass »

A very basic question. How do I rotate my btBoxShape using the model matrix I currently have?

In my "OpenGL code" I rotate my changing the model view matrix with the code (glm math library):

Code: Select all

glm::mat4 model; model = glm::rotate(model, angle, v);
How can I convert this to a

Code: Select all

btTransform transform;
which I pass on to my MotionState initialization? (Which I assume is what I need to do?)
rawtass
Posts: 8
Joined: Sun Dec 30, 2012 8:56 pm

Re: btBoxShape rotation

Post by rawtass »

I think I found ONE solution to this by converting my glm::mat4 to a quaternion, before extracting euler angles and converting this to radians before setting the btTransform with the btQuaternion created with eulerAngles.

Code: Select all

btTransform transform;
btQuaternion qtn;

transform.setIdentity();
transform.setOrigin(btVector3(mesh->transform->origin.x, mesh->transform->origin.y, mesh->transform->origin.z));
glm::quat qt = glm::quat_cast(mesh->transform->model);
glm::vec3 eulerAngles = glm::eulerAngles(qt) * 3.14159f / 180.f;
qtn.setEuler(eulerAngles.x, eulerAngles.y , eulerAngles.z);
transform.setRotation(qtn);
However, there has to be a more elegant solution then this??
Nickert
Posts: 25
Joined: Sat Dec 29, 2012 7:20 pm

Re: btBoxShape rotation

Post by Nickert »

You perhaps extract the quaternion-values from your matrix and use that to initialize the btQuaternion? Saves the conversion to euler angles, which is probably a real good thing.