View Full Version : Moving to the pointed direction

09-16-2005, 01:27 PM
Hi everybody...
Im new on all this and Im having troubles...

I want to do a program with a triangle controled by the user....Its supposed that it can rotate and move at any point in the window.
The triangle can only be moved forward to the direction pointed by one vertex....for example

/\ <----this one
/ \
/ \

At this time I can rotate the triangle in his own center, but I cant make it move to the direction pointed by that vertex....How can I do that??
I have 2 ideas...
The first one:
I think I can make a lot of "if" instructions and ask for the "angle" so that, I could make a diferent glTranslate instruction for every angle...but I think that should be very ineficient...

The second one..
I think I can use the Math.h sin and cos functions to make the triangle move but I have been trying this and the triangle only does it well in some angles...
How can I correct this??
Is there another way to do it?

Your help will be very apreciated...

09-16-2005, 09:11 PM
Add a translate call to the desired position of the triangle.

Store the translate position in memory, x, y

Increment x & y by the sine and cosine of the current angle of rotation remembering to convert to radians if using libmath.

Make sure you rotate and translate in the correct order.