To move an object in the direction of an angle, there are 2 equations for 2d and 3 for 3d (one for each axis).
Bear in mind that the code below assumes all the angles you have start at 12 o'clock and increase clockwise.
For 2D, the equations look like this
float Angle; //this is our angle
float Distance; //this is how far we want the object to move at one frame
float NewXPosition = OldXPosition + (Distance * dbSin(Angle));
//You have to subtract from the old Y position because upwards is negative in 2D
float NewYPosition = OldYPosition - (Distance * dbCos(Angle));
For 3D, you have to modify the X and Z movements because they will differ depending on how far up or down the direction is. In a 3D case, two angles will do; one for looking up and down (AngleX, a rotation on the X axis) and one for looking side to side (AngleY, rotation on the Y axis). Ultimately, your final direction is calculated by applying the X rotation first (rotating an axis-aligned object from a side perspective) and then the Y rotation (rotating what we have now from bird's eye veiw), and finally the Z rotation (rotating what we have now from directly behind; screws things up, so leave it 0).
Here are the equations:
float AngleX; //Up and Down angle
float AngleY; //Left and Right angle
float Distance; //how far to move in one frame
//the Y position is easiest to calculate with these two angles
//move the object according to the angle that has to do with up/down, which is the X angle
float NewYPosition = OldYPosition + (Distance * dbCos(AngleX));
//now for the X and Z positions, multiply the number we add to the old positions by the sine of AngleX# to get the correct distance
float NewXPosition = OldXPosition + ( (Distance * dbSin(AngleY)) * dbSin(AngleX) );
float NewZPosition = OldZPosition + ( (Distance * dbCos(AngleY)) * dbSin(AngleX) );
To remember which trigonometric function does what, here's a simple demo program that shows what the sine and cosine are of a DGDK angle.
//DarkGDK with C++
#include "DarkGDK.h"
void DarkGDK( void )
{
dbSyncOn( ); dbSyncRate( 60 );
dbDisableEscapekey( );
float Angle,Distance;
Angle = 0.0
Distance = dbScreenHeight( ) / 4.0f;
while( LoopGDK( ) )
//Clear the screen
dbCLS( );
//Update the angle
Angle = dbWrapValue( Angle + 1.0f );
//Draw the axes
dbInk( 0xFF0000AA, 0 );
dbLine( dbScreenWidth( )/2, 0, dbScreenWidth( )/2, ScreenHeight( ) );
dbLine( 0, dbScreenHeight( )/2, dbScreenWidth( ), dbScreenHeight( )/2 );
//Draw the circle
dbCircle( dbScreenWidth( )/2, dbScreenHeight( )/2, Distance );
//Draw the angle line
dbInk( 0xFFAAAAAA, 0 );
dbLine( dbScreenWidth( )/2, dbScreenHeight( )/2, dbScreenWidth( )/2 + (Distance * dbSin(Angle)), dbScreenHeight( )/2 - (Distance * dbCos(Angle)) );
//Draw the Sine
dbInk( 0xFFFF0000, 0 );
dbLine( dbScreenWidth( )/2, dbScreenHeight( )/2 - (Distance * dbCos(Angle)), dbScreenWidth( )/2 + (Distance * dbSin(Angle)), dbScreenHeight( )/2 - (Distance * dbCos(Angle)) );
//Draw the Cosine
dbInk( 0xFF00FF88, 0 );
dbLine( dbScreenWidth( )/2 + (Distance * dbSin(Angle)), dbScreenHeight( )/2, dbScreenWidth( )/2 + (Distance * dbSin(Angle)), dbScreenHeight( )/2 - (Distance * dbCos(Angle)) );
//Text
dbInk( 0xFFAAAAAA, 0 );
dbText( 5,25,"Grey line is the angle" );
dbInk( 0xFFFF0000, 0 );
dbText( 5,45,"Red line is the Sine of the angle" );
dbInk( 0xFF00FF88, 0 );
dbText( 5,65,"Teel line is the Cosine of the angle" );
//Render
dbSync( );
}
}
Remember those old guys? They made epic renders, I think one of them was called DaVinci, and all they used was MS Paint. Sometimes it's just skill....