Jump to content
  • Advertisement
Sign in to follow this  
Photon Man

Rotation & Translation on Textured Quads

This topic is 3315 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

I have a textured quad, (obviously four vertexes, one for each corner) that I want rotated. I already have a function that spins the quad by its center axis, but every time (while it is rotating) I try to translate it, it either shrinks or grows in size! So I need a math function that takes each of the four vertexes, (say you know the x, y, width, and height) and translates it, while rotating by its center axis. (Or simply, Moves the rotating quad without size or weird errors.) Thanks! Note: I'm using DX 9.0, and defined the vertexes like this:
   
      // the top left vertex       // the top right vertex
      vertex[0].x        /*&*/      vertex[1].width

      // the bottom left vertex       // the bottom right vertex
      vertex[2].y        /*&*/      vertex[3].height


///// What the Texture quads look like in action
//
//    0--------1
//    |       /|
//    |      / |  
//    |     /  | 
//    |    #   |  
//    |   /    |
//    |  /     |         
//    | /      |      
//    2--------3
//
//    # = Center Axis

///// This is the desired result
//
//   x = 0                          x = 100
//   y = 0                to        y = 0
//   rot = 20;//degrees             rot = 0;
//
//   0--------1                  0--------1
//   \       | \                 |       /|
//    \      |  \                |      / |  
//     \     |   \      ->       |     /  | 
//      \    #    \              |    #   |  
//       \   |     \             |   /    |
//        \  |      \            |  /     |         
//         \ |       \           | /      |      
//          2--------3           2--------3
//

Share this post


Link to post
Share on other sites
Advertisement
Wait... do you want rotation, or shear? What you're showing there is shear.

Assuming it's the picture that's off and you do want rotation, multiplying each vertex by a rotation matrix should be sufficient. If you're having problems with that, you should post your code.

Share this post


Link to post
Share on other sites

//
// x = 0 x = 100
// y = 0 to y = 0
// rot = 20;//degrees rot = 0;
//
// ----1 0--------1
// 0---- | \ | /|
// \ | \ | / |
// \ | \ -> | / |
// \ # \ | # |
// \ | \ | / |
// \ | \ | / |
// \ | \ | / |
// \| ----3 2--------3
// 2----

// New code //

// Rotate the vertexes individualy
for (int curr_vert = 0; curr_vert < 4; ++curr_vert)
{
float xr = 0;
float yr = 0;


// perform rotation
xr = (float)vertices[curr_vert].x * cos(rotate) -
(float)vertices[curr_vert].y * sin(rotate);

yr = (float)vertices[curr_vert].x * sin(rotate) +
(float)vertices[curr_vert].y * cos(rotate);


vertices[curr_vert].x = xr;
vertices[curr_vert].y = yr;


} // end for curr_vert



Every time I put this it rotates with x = 0 & y = 0 as the axis. How do I get the axis in the center? (obviously I use the width, and height, but I can't seem to find where to put them in the code above.)

Share this post


Link to post
Share on other sites
Easiest way is to subtract the center from the vertices first, then add it back afterward. Alternatively you can multiply the transformation matrices together and multiply the vertices by the resultant matrix, but that's trickier to do if you aren't actually using a vector math library.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!