Rotate, using Sin, Cin??? Help!

I have this cube in space and I can rotate it around its access but I want to be able to move the cube in the lcoation that its facing. Someone told me that I have to use cin, sin to find out what axies to move it on. Say I moved my object so its facing 45 degrees from the origin, the cube would have to move along the X and Z axis.

Any have any ideas?

you have to transform the vector your cube moves along in objectspace into worldspace by applying the orientation matrix of the cube to the vector of moving. add it to the cube’s position and that’s it. no sin or cos needed except for building rotation matricies, but this is handled by OpenGL.

Could you give me an example?

If you ever happen to need some elements of the transformation matrix, you should work on your own copy and load it up every frame, since downloading matrices is said to be very slow. When you have got the matrix (well you CAN use glGetFloat to get it), the local axes are the columns of the matrix. x are elements 0,1,2,3 y 4,5,6,7 and z 8,9,10,11. One of these vectors is probably the vector you want the cube move along.

ok, based on your first post to this thread, you seem to be looking for just the polar to cartesian formulas.

if theta = 45.0, then
xPos += sin( theta ) * movement_offset;
yPos += cos( theta ) * movement_offset;

( it might be the other way around, i.e. switch the cos and sin, I can never remember this until I start testing it )

This usually isn’t the best way to do this, though, since trig functions are some of the slowest around. You might want to consider using linear approximations, lookup tables, or just work with the matrices themselves.


[This message has been edited by lpVoid (edited 02-09-2001).]

[This message has been edited by lpVoid (edited 02-09-2001).]

Look-up tables are easy to use. Technically, you can get away with one table of values, with 0 <= range < 180 degrees, o 0 <= range < pi radians. To evaluate from 180 to 360 degrees (or pi to 2*pi) just flip the sign. And sin(x) == cos(x-90 degrees) == cos(x - pi/2), which is why you’d only need one table.