Problems Using and Implementing Sine and Cosine

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.

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.

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

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+dcos(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

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

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

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