Sign in to follow this  
heh65532

transformation and projection matrixes

Recommended Posts

HI

I want to have matrix that makes the coordinates go X right and Y down. can someone provide me a matrix to do this?

If I understand correctly this matrix goes to setTransformMatrix() in libgdx.

sorry I'm not very good at matrixes.

 

thx!

 

Share this post


Link to post
Share on other sites

Simply, you have a vector in the xy plane, Vector (x, y, 0).  X and Y are some value.

You want to rotate on the Z axis effectively.  There are a few resources around, this is a great start even if its in opengl (http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/)

The libgdx example for creating a matrix is just down the page on this link -> https://github.com/libgdx/libgdx/wiki/Vectors,-matrices,-quaternions

Just remember, if you want to create any rotation and you have the normal (x) and the upvector (y), do the cross product and normalise the result.  You then have the rotation axis.  

Hope this helps, matrices are not too scary, in fact there is a lot of cool tricks you can do with them.

Share this post


Link to post
Share on other sites

Thanks ErnieDingo. I went through those links and I believe only thing I need is this:

matrix.setToRotation(new Vector3(0,0,1),-90);

It works but the problem I'm having is that now all the sprites get rendered sideways. I could just rotate them but I believe there is cleaner way of doing this with matrixes. Or is there?

 

thx!

Share this post


Link to post
Share on other sites
Yes. But first did you normalize the axis you got from the cross product? And have you rotated the sprite enough? Did you play with other values but -90?

Also. You can create another rotation matrix and multiply them together to align in the correct plane.

But the way i determine the correct facing for the rotation. I use billboards in my 3d game which are similar to sprites. You may need to take the normal of your sprite when created and determine the angle between it and your screen normal. Cross product the 2 normals use the Then create a rotation matrix using the normalized axis and the angle determined.

Good luck

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this