#### Archived

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

# Manual rotation of a quad

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

## 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 on other sites
When you say manual rotation, do you mean without the use of matrices? If you can use them, it would make it a lot easier

##### 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 setup0      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 on other sites
Ugh, thanks Eamonn I found the problem. I had:
y = x * sin(r) - y * cos(r)

##### Share on other sites
Is there anyway to correctly rotate without centering the primitives at the origin first, then translating it back?

##### 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 on other sites
But I''d like to not have to center it at the origin first :/ seems like an unecessary step if I don''t need to do it.

1. 1
Rutin
69
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633421
• Total Posts
3011797
• ### Who's Online (See full list)

There are no registered users currently online

×