Jump to content
  • Advertisement

Archived

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

Zorbfish

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.

If you intended to correct an error in the post then please contact us.

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
Advertisement
<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
Is there anyway to correctly rotate without centering the primitives at the origin first, then translating it back?

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

Share this post


Link to post
Share on other sites

  • 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!