Archived

This topic is now archived and is closed to further replies.

Zorbfish

Manual rotation of a quad

Recommended Posts

Background: I''ve searched and tested this for awhile and haven''t gotten anywhere. I''m using indexed triangle lists and a left hand orthogonal projection, which is different from most articles I''ve read (I didn''t think it would matter though).
I''m using the usual vertice setup
0      1
|------|      Indice setup 0, 1, 2, 1, 2, 3
|    / |
|   /  |
|  /   |
| /    |
|------|
2      3
I''ve tried the the formulas provided in Focus on 2D in 3D example 7.01 and it didn''t work. The closest I''ve gotten to rotating the quad was with Eamonn Doherty''s rotation formulas. Rotations about the Z axis were correct for angles 0, 90, 180,and 270. But I''m afraid the other angles of rotation seemed to rotate the quad along the lines x = y,and x = -y. If anyone could help with the formulas (no you don''t have to give them to me, even a helpful hint in the right direction is appreciated).

Share this post


Link to post
Share on other sites
<SPAN CLASS=smallfont>quote:
Original post by Zorbfish
Background: I've searched and tested this for awhile and haven't gotten anywhere. I'm using indexed triangle lists and a left hand orthogonal projection, which is different from most articles I've read (I didn't think it would matter though).


I'm using the usual vertice setup
0 1
|------| Indice setup 0, 1, 2, 1, 2, 3
| / |
| / |
| / |
| / |
|------|
2 3



I've tried the the formulas provided in Focus on 2D in 3D example 7.01 and it didn't work.

The closest I've gotten to rotating the quad was with Eamonn Doherty's rotation formulas. Rotations about the Z axis were correct for angles 0, 90, 180,and 270. But I'm afraid the other angles of rotation seemed to rotate the quad along the lines x = y,and x = -y.

If anyone could help with the formulas (no you don't have to give them to me, even a helpful hint in the right direction is appreciated).
</SPAN>

Hmm.. in my quad rotation code, I used a different vertex setup:

0 1
|------|
| / |
| / |
| / |
| / |
|------|
3 2

The code works well enough for me (it seems to go off by a pixel occasionally, but that's probably because of rounding errors introduced by the flooring that occurs in the float->int conversion).

The basic idea behind the rotation is pretty easy. You'll probably be able to come up with a much better implementation than mine.

- Translate the vertices so the origin is at the desired point of rotation relative to the vertices
- Apply the following formulas to the coordinates of each vertex:
x = x * cos(r) - y * sin(r)
y = x * sin(r) + y * cos(r)
- Translate the vertices back so the original point of rotation is restored

You've probably found this formula already, but maybe your implementation didn't work? Make sure there is no off-by-1 error introduced early in the formula. This happened to me on my first few attempts at rotation, and it really threw the whole thing off.

[Edited by - glassJAw on October 21, 2009 10:02:52 AM]

Share this post


Link to post
Share on other sites
Off the top of my head, you could save one step by just centering the mesh at the origin in the vertex buffer when you create it. Then you could always just perform a rotation and then translate it...without having to put it at the origin every rotation.

Good luck,
Chris

Share this post


Link to post
Share on other sites