Jump to content
  • Advertisement
Sign in to follow this  

using matrices in 2d -rhw

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've just been testing out some 2d quads and was wondering how to use matrices to rotate them. I realise the XYZRHW FVF means the vertices are already transformed, but I thought maybe you could apply a matrix before filling the vertex buffer, ie applying it diretly to the vertex struct, so, [code/] D3DMATRIX *QuadMatrix; QuadVertex = {{1.0f, 1.0f, etc ....}}// fill in the Vertex struct float *RotationAngle; float GetRotationAngle(float *RotAngle); // input/get an angle & return to RotationAngle. D3DMatrixRotationY(&QuadMatrix, &RotationAngle);//transform the matrix //apply matrix results to the x & y vertices. QaudVertex[0].x = QuadMatrix-> _22; //which matrix values? QaudVertex[0].y = QuadMatrix-> _23; //which matrix values? QaudVertex[1].x = QuadMatrix-> _22; QaudVertex[1].y = QuadMatrix-> _23; QaudVertex[2].x = QuadMatrix-> _22; QaudVertex[2].y = QuadMatrix-> _23; QaudVertex[3].x = QuadMatrix-> _22; QaudVertex[3].y = QuadMatrix-> _23; After this you would do the rest as normal, is this ok? Would I need to use D3DMatrixRotationX as well and use for the x values? Another thing I wanted to know is are the sin & cosine functions built into the matrix or the D3D matrix function, as in D3DMatrixRotationY etc. Thanks for any help or insight. edit Ah I just saw D3DXMatrixTransformation2D in another post, this might be ok, can this be used with xyzrhw though? I wanted to stick to rhw at the moment [Edited by - Stevieboy on September 27, 2004 7:04:34 PM]

Share this post

Link to post
Share on other sites
Nope it can't be used with RHW. You still have to modulate each vertex. You're on the right track though. You can use D3DXMatrixTransformation2D to create the matrix. Then just multiply the matrix by each vertex. It's simple matrix math, so don't try to make it too complicated.

[x', y', z', 1] = [x, y, z, 1] * [Matrix]

where Matrix is defined with _RC (row column) elements.

x' = x*Matrix._11 + y*Matrix._21 + z*Matrix._31 + 1*Matrix._41;
y' = x*Matrix._12 + y*Matrix._22 + z*Matrix._32 + 1*Matrix._42;
z' = x*Matrix._13 + y*Matrix._23 + z*Matrix._33 + 1*Matrix._43;
1 better equal 1;

If you check that out, you can see the last term goes to 0 for x', y', and z'. So, just use the first three terms.

You'll be rotating around the z-axis, so the matrix will look as follows:

[ cos(theta) sin(theta) 0 0 ]
[ -sin(theta) cos(theta) 0 0 ]
[ 0 0 1 0 ]
[ 0 0 0 1 ]

As you can see, z' will be z since column 3 has 0's for x and y. I think I've done this right, but I'm sure it will be corrected if not. :)

Good luck,

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!