Jump to content
  • Advertisement


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


Rotation and Translation of Objects.

This topic is 5282 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

I just finished my 72 hour game, but I have a slight problem with some theory I tried to put into it, but didn't work... In OpenGL, I was trying to do:
    glTranslatef(locX, locY, 0.0f);
    glRotatef(angle, 0.0f, 0.0f, 1.0f);
            glVertex2f(-32.0f, -32.0f);
            glVertex2f(32.0f,  -32.0f);
            glVertex2f(32.0f,   32.0f);
            glVertex2f(-32.0f,  32.0f);
It worked, but I would like to use a Vector Array, which means I need to rotate and translate my object manually. Here is what I came up with...
//determain rotation on a unit vector.
x = cos(angle) + sin(angle)
y = -sin(angle) + cos(angle)

//translate it to the correct distances...
x *=32
y *=32
//translate and draw
       glVertex2f(locX-x, locY+y);
       glVertex2f(locX+x, locY+y);
       glVertex2f(locX+x, locY-y);
       glVertex2f(locX-x, locY-y);
It is a rotation around the Z, then a translation to the correct point. In my head, it should be a square at the correct point, but for some reason, it turned into a rectangle, and the texture always faces up. Can someone see where I went wrong with this, and why? ~~~~~ "One Reality is worth one thousand dreams" Download and play Slime King I. [edited by - dede on January 6, 2004 2:55:04 AM] [edited by - dede on January 6, 2004 6:21:13 AM]

Share this post

Link to post
Share on other sites
Hi dede

Your problem is that you''re only calculating one axis vector. For placing a point in 2d you need 2 axes, right?

So use the following as your axes
axis1 = (x,y)
axis2 = (-y,x)

Now all your points are linear combinations of axis1 and axis2 (which you can now think of as x and y axes respectively). A linear combination means that you just add a multiple of each to obtain your new point.

so, your new points would now become
point1 = 1.axis1 + 0.axis2
point2 = 0.axis1 + 1.axis2
point3 = -1.axis1 + 0.axis2
point4 = 0.axis1 - 1.axis2

so applying this, try:

glVertex2f(locX+x, locY+y);
glVertex2f(locX-y, locY+x);
glVertex2f(locX-x, locY-y);
glVertex2f(locX+y, locY-x);

The problem with the above example is that it will probably end up being exactly 45 degrees offset from what you want. If you are keen, try the following which is probably what you wanted to start off with.

point1 = 1.axis1 - 1.axis2
point2 = 1.axis1 + 1.axis2
point3 = -1.axis1 + 1.axis2
point4 = -1.axis1 - 1.axis2

Hope that helped.

Share this post

Link to post
Share on other sites
Thank you, It sorta works correct now. I still have to play with it to figure out exactly what you did, but at least when I''m finished, my theory will be alittle better.

"One Reality is worth one thousand dreams"
Download and play Slime King I.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!