So I've loaded a 3d model named "robot.3DS". The camera is positioned so that you see the model looking down on it from the top (like in a strategy game). You can move the model forward pressing the shift key, you can move the camera forward, back and side to side using the arrow keys. And you can also rotate the model to the left using the space key.
The problem is that by default the model is facing up. So if i press shift the model will go up (i.e where the front of the model is pointing). However, if i rotate the model to the left, so it faces somewhere between left and up, if i press shift it will still go up (i.e not where the front of the model is pointing). I've tried to fix this but i haven't really figured out how to do it so I'd really appreciate some help.
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
dbLoadObject("robot.3DS", 1);
dbPositionObject(1, 20, -10, 50);
float x = 20;
float y = -10;
float z = 50;
int turnLeft = 0;
float cameraX = 20;
float cameraY = 100;
float cameraZ = -50;
dbPositionCamera(20, 100, -50);
// our main loop
dbXRotateCamera(70);
while ( LoopGDK ( ) )
{
if (dbDownKey())
{
cameraZ = cameraZ -5;
dbPositionCamera (cameraX, cameraY, cameraZ);
}
if (dbUpKey())
{
cameraZ = cameraZ +5;
dbPositionCamera (cameraX, cameraY, cameraZ);
}
if (dbRightKey())
{
cameraX = cameraX +5;
dbPositionCamera (cameraX, cameraY, cameraZ);
}
if (dbLeftKey())
{
cameraX = cameraX -5;
dbPositionCamera (cameraX, cameraY, cameraZ);
}
if (dbShiftKey())
{
if (turnLeft > 0)
{
x = x - 0.2;
turnLeft--;
}
z = z +0.2;
dbPositionObject(1, x, y, z);
}
if (dbSpaceKey())
{
dbRotateObject(1, dbObjectAngleX( 1 ), dbObjectAngleY( 1) -0.2, dbObjectAngleZ( 1 ));
turnLeft++;
}
// update the screen
dbSync ( );
}
// return back to windows
return;
}
Here is the model of the robot if you want to try it out.
http://files.filefront.com/robot3DS/;13357282;/fileinfo.html