Hello everyone,
The practice which i'm working in, aim to using trigonometry to rotate 3d model with mouse, i almost finished all source code to achieve this task, although that, the model still not rotate, i hope someone tell me where is my mistake:
this is my code
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
// the maximum rate to 60 which means the maximum frame rate will
// be set at 60 frames per second
dbSyncOn ( );
dbSyncRate ( 60 );
dbAutoCamOff ( );
// move our camera back so we can view the objects
dbMakeCamera ( 1 );
dbPositionCamera ( 1, 0, 0, -250 );
dbPointCamera ( 0, 0, 0 );
// load and position 3d model
dbLoadObject ( "models/player.x",1 );
dbPositionObject ( 1, 0, 0, 0 );
// now we come to our main loop, we call LoopGDK so some internal
// work can be carried out by the GDK
while ( LoopGDK ( ) )
{
// put mouse coordinates in variables
int nMX = 0;
int nMY = 0;
nMX = dbMouseX();
nMY = dbMouseY();
// put model coordinates in variables
int nPX = 0;
int nPY = 0;
nPX = dbObjectPositionX ( 1 );
nPY = dbObjectPositionY ( 1 );
// put x axis coordinates in variables
int nAxisX = 0;
int nAxisY = 0;
// calculate the distance between mouse and x axis
int nDis = 0;
nDis = dbSQRT ( (nMY - nAxisY)^2 + (nMX - nAxisX)^2);
// calculate the distance between mouse and model
int nDis02 = 0;
int nAngle = 0;
nDis02 = dbSQRT ( (nMY - nPY)^2 + (nMX - nPX)^2);
nAngle = dbSin (nDis/nDis02);
// rotate the model with update angle
dbRotateObject(1, 0, 0, nAngle);
// here we make a call to update the contents of the screen
dbSync ( );
}
// before quitting delete our objects
for ( int i = 1; i < 50; i++ )
dbDeleteObject ( i );
// and now everything is ready to return back to Windows
return;
}