I wrote this code and it worked fine at first but then I began having trouble when i added a second part to it. the code is meant to rotate the camera in a circle around an object. It is able to rotate around the y-axis, but when i tried having it rotate around the x-axis it began to function strangely. also the speeds when you rotate are faster one way than the other and slower at certain points. help is greatly appreciated. here is my code
#include "DarkGDK.h"
void rotatecameraaroundobjectY(int id, int distance, float speed)
{
dbPositionCamera(dbObjectPositionX(id), dbCameraPositionY(), dbObjectPositionZ(id));
int camx=dbCameraPositionX();
int camz=dbCameraPositionZ();
float x=dbSin(dbCameraAngleY()+180-speed)* distance;
float z=dbCos(dbCameraAngleY()+180-speed)* distance;
dbPositionCamera ( camx+x, dbCameraPositionY(), camz+z );
dbPointCamera(dbObjectPositionX(id), dbCameraPositionY(id), dbObjectPositionZ(id));
}
void rotatecameraaroundobjectX(int id, int distance, float speed)
{
dbPositionCamera(dbCameraPositionX(), dbObjectPositionY(id), dbObjectPositionZ(id));
int camy=dbCameraPositionY();
int camz=dbCameraPositionZ();
float z=dbSin(dbCameraAngleX()+180-speed)* distance;
float y=dbCos(dbCameraAngleX()+180-speed)* distance;
dbPositionCamera ( dbCameraPositionX(), camy+y, camz+z );
dbPointCamera(dbObjectPositionX(id), dbCameraPositionY(id), dbObjectPositionZ(id));
}
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbLoadImage("cube.bmp",1);
dbMakeObjectCube(1,100);
dbTextureObject (1, 1);
while ( LoopGDK ( ) )
{
if( dbUpKey() )
{rotatecameraaroundobjectX(1, 300, 1);}
if( dbDownKey() )
{rotatecameraaroundobjectX(1, 300, -1);}
if( dbRightKey() )
{rotatecameraaroundobjectY(1, 300, 1);}
if( dbLeftKey() )
{rotatecameraaroundobjectY(1, 300, -1);}
dbSync ( );
}
return;
}