Left hand coordinates with right hand rotations?

This topic is 2537 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm porting out a engine from a program called Game Maker. It uses left handed coordinates and right handed rotations and that has become a problem. I use a left handed coordinate system so rotations are backwards. I tried setting z to -1 which works but then my camera draws every thing backwards (unless I shouldn't be setting the view matrix as the world matrix in d3dxsprite). So how do I implement this?

PS:
I us D3DXMatrixTransformation2D to handle the rotation and translations, so would that mean I would have to build my own rotation matrix?

Share on other sites
After hours of research on how transformations work, I found that I an going to have to break down the D3DXMatrixTransformation2D function, which is just makes a call to D3DXMatrixTransformation (and does some other simple calculations). So I came up with this:

 //Method #1 D3DXMATRIX rotation; D3DXMatrixIdentity( &rotation); float c = cos(degtorad(angle)); float s = sin(degtorad(angle)); rotation._11 = c; rotation._12 = -s; rotation._13 = 0; rotation._14 = 0; rotation._21 = s; rotation._22 = c; rotation._23 = 0; rotation._24 = 0; rotation._31 = 0; rotation._32 = 0; rotation._33 = 1; rotation._34 = 0; rotation._41 = 0; rotation._42 = 0; rotation._43 = 0; rotation._44 = 1; 

It rotates counter-clockwise, but not at a center point. My sprite orbits the origin (0, 0) an passes through the point where it's supposed to draw at. I was able to move the origin using a conjugation method, but it this time it rotated at the corner on the center point.

So I came up with this after more research:

 //Method #2 D3DXMATRIX rotation; D3DXMatrixIdentity( &rotation); D3DXVECTOR3 v; D3DXVec3Normalize( &v, &D3DXVECTOR3( CenterPointX, CenterPointY, 1)); float c = cos(degtorad(angle)); float s = sin(degtorad(angle)); float t = 1.0f - c; rotation._11 = (t*(v.x*v.x))+c; rotation._12 = (t*v.x*v.y)-(s*v.z); rotation._13 = (t*v.x*v.z)+(s*v.y); rotation._14 = 0; rotation._21 = (t*v.x*v.y)+(s*v.z); rotation._22 = (t*(v.y*v.y))+c; rotation._23 = (t*v.y*v.z)-(s*v.x); rotation._24 = 0; rotation._31 = (t*v.x*v.z)-(s*v.y); rotation._32 = (t*v.y*v.z)+(s*v.x); rotation._33 = (t*(v.z*v.z))+c; rotation._34 = 0; rotation._41 = 0; rotation._42 = 0; rotation._43 = 0; rotation._44 = 1; 

Now it rotates around the center point, but it also seems to rotate around each axis. I only need it to rotate on the Z-Axis.

Can anyone help me with this?

sources:
http://mathforum.org...view/69806.html
http://msdn.microsof...v=VS.85%29.aspx
http://wine.sourcear..._8c-source.html
http://www.fastgraph...mes/3drotation/

Share on other sites
One thing you can do, is just use the inverse of the angle. So instead of this:

 float c = cos(degtorad(angle)); 

you could just do this:

 float c = cos(degtorad(-angle)); 

Wherever you call a function with the angle of rotation, just put a minus sign in front of it

D3DXMatrixTransformation2D, instead of passing the regular angle to the function, pass -angle

Share on other sites

One thing you can do, is just use the inverse of the angle. So instead of this:

 float c = cos(degtorad(angle)); 

you could just do this:

 float c = cos(degtorad(-angle)); 

Wherever you call a function with the angle of rotation, just put a minus sign in front of it

D3DXMatrixTransformation2D, instead of passing the regular angle to the function, pass -angle

**face palm**

That also works! thanks!

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
13
5. 5
frob
12

• 9
• 9
• 11
• 11
• 23
• Forum Statistics

• Total Topics
633664
• Total Posts
3013238
×