# 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.

## 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 on other sites
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 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 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.

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5
gaxio
13

• 24
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631734
• Total Posts
3001933
×