View Full Version : Problems Using and Implementing Sine and Cosine

NewbieGP

10-23-2003, 10:57 PM

Hi i have a problem with coordinate systems. I need to know how to use Sine and Cosine to rotate a local coordinate system (an object) around the global coordinate system. I need to do this and then make it move around on the global coordinate system and still make it rotate and set a new direction from its local axis. Much like a race car driving around on a track. It turns around its own axis, and moves forward and back on the track. Ive been sitting with this problem for like half a year, reading message boards and stuff and i just cant get it right. Please help.

yaro_dup1

10-23-2003, 11:01 PM

Did you try to do this with OpenGL functions like glRotatef, glTranslatef, and other modelview matrix operations? It'll be easier for you I think.

NewbieGP

10-25-2003, 12:21 AM

Yea but the problem is that if i have this object i can only rotate around the global axis at whatever point im translating. then i can move forth and back on the different axes but when i rotate again i just rotate around my original spawn point. i have found a way to rotate around the local axis, using pushmatrix and popmatrix but i can still only translate forth and back on the original axis.

I cant make a new "center" and translate from there, and that is what i want. To make the object the center of the translation processes, including its current rotation. so when logically moving along the Y axis, if i had been rotating 90 degrees, the Y axis would actually be moving on the X axis at my new center point.

[This message has been edited by NewbieGP (edited 10-25-2003).]

chowe6685

10-25-2003, 05:25 AM

store the position of the object as an coordinate pair (x,y) as aligned with the global axis. Then if it moves a distance d at an angle theta: (x',y') its new position is just

x' = x+d*cos(theta)

y' = y+d*sin(theta)

you may have to play with the details as the exact code depends on how you have the rotation angle aligned, but thats the basic idea

NewbieGP

10-28-2003, 10:03 PM

I dont know what theta means but i guess it means angle. Anyway i did the math on a paper and it made no sense, assuming that 0 degrees equals the positive x axis by default (dont know if this matters). For example i tried setting a point x=0 and y=2 and then moving to 315 degrees (45 degrees the opposite way). Then i set d=2 assuming d means distance, and i got some really wierd coordinates ending up with x'= 1,41 and y'= -2,82. it makes no sense at all as since it should have moved 2 units at 315 degrees. thus y' should not be higher than 2, because it then moves longer than its real distance.

Hope anyone can help me if you understand what i say http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by NewbieGP (edited 10-29-2003).]

[This message has been edited by NewbieGP (edited 10-29-2003).]

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.