#1 2015-03-16 02:32:13


World to local space Matrices

So I am working to integrate bullet physics (working off the other posted code). Bullet uses a world coordinates which are located in the center of the object. The object for the sake of this example, is a 8 x 8 x 8 unit cube (the default cube located in default model slot 0).  There is a zradius difference between my model and bullets model. Meaning it is half of the radius of the object higher (+ z) than it should be.
Shown in pictures below:

The orange bounds box is the bullet aabb, the cube is the render spot and the fireball is where the center origin is.

So far what i have done which seem to work in most simple rotation cases is to take:

code wrote:

vec a(0, 0, zradius/2)        //move the cube in the direction i want to achieve in local space (down).
a.rotation_around_z(yaw) //create the rotation a = origin of object
a.add(o)                         //then translate the object to the correct spot in space;

the orange represents the bullet aabb the model represents the render place and the red green and blue lines represent xyz accordingly (local space based on the models rotation).


I do this and everything seems to work in most cases, save when rotating in odd number of ways (like along multiple axis). I was reading on the web that you should use matrices but i'm not positive how or in what order to use them.

So I assume a dev will have to answer this because it hast to do with the higher level working of the actual engine, but I need either how to create a rotation matrix and translate it to the proper coordinates. Or how to move the model Matrix so that it starts or the origin is set to be in the center of the model.   


I've tried, using a rotation matrix using Matrix4 class call then rotating it using rotate around x y z. then the matrix4 translate command. But i don't know how to convert this to a vec or vec4. and then using that as the base. I do believe that's the algorithm i need to use to finish this equation.

Last edited by chasester1 (2015-03-16 02:40:58)


Board footer