Manual rotation of a quad

Started by
5 comments, last by Zorbfish 20 years, 2 months ago
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).
Advertisement
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
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
<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]
Ugh, thanks Eamonn I found the problem. I had:
y = x * sin(r) - y * cos(r)
Is there anyway to correctly rotate without centering the primitives at the origin first, then translating it back?
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
Chris ByersMicrosoft DirectX MVP - 2005
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.

This topic is closed to new replies.

Advertisement