It doesn't work...I tried lots of different numbers, but the direction of acceleration is not the correct direction! Also it seems that when the camera is rotated, the acceleration buttons accelerate in different directions with different camera rotations...is the basis of this approach (crossing <1,0,0> with the dbPickVector<> to accelerate right) correct, or did I just implement it wrong???? Here's my code:
while ( LoopGDK ( ) )
{
dbSync ( );
dbPositionCamera ( x, y, z );
dbTurnCameraRight(dbMouseMoveX());
dbPitchCameraDown(dbMouseMoveY());
if(dbKeyState( 17 )) //W
{
dbPickScreen(400,300,1);
xvel += acceleration * dbGetPickVectorX();
yvel += acceleration * dbGetPickVectorY();
zvel += acceleration * dbGetPickVectorZ();
}
if(dbKeyState( 31 )) //S
{
dbPickScreen(400,300,1);
xvel -= acceleration * dbGetPickVectorX();
yvel -= acceleration * dbGetPickVectorY();
zvel -= acceleration * dbGetPickVectorZ();
}
if(dbKeyState(32)) //D
{
dbPickScreen(400,300,1);
dbMakeVector3( 1000 );
dbSetVector3(1000, dbGetPickVectorX( ), dbGetPickVectorY( ), dbGetPickVectorZ( ) );
dbMakeVector3( 1001 );
dbSetVector3(1001, 1, 0, 0 );
dbMakeVector3( 1002 );
dbCrossProductVector3( 1002, 1000, 1001 );
xvel += acceleration * dbXVector3(1002);
yvel += acceleration * dbYVector3(1002);
zvel += acceleration * dbZVector3(1002);
}
if(dbKeyState(30)) //A
{
dbPickScreen(400,300,1);
dbMakeVector3( 1000 );
dbSetVector3(1000, dbGetPickVectorX( ), dbGetPickVectorY( ), dbGetPickVectorZ( ) );
dbMakeVector3( 1001 );
dbSetVector3(1001, 1, 0, 0 );
dbMakeVector3( 1002 );
dbCrossProductVector3( 1002, 1000, 1001 );
xvel -= acceleration * dbXVector3(1002);
yvel -= acceleration * dbYVector3(1002);
zvel -= acceleration * dbZVector3(1002);
}
if(dbKeyState(16)) //Q
{
dbPickScreen(400,300,1);
dbMakeVector3( 1000 );
dbSetVector3(1000, dbGetPickVectorX( ), dbGetPickVectorY( ), dbGetPickVectorZ( ) );
dbMakeVector3( 1001 );
dbSetVector3(1001, 0, 1, 0 );
dbMakeVector3( 1002 );
dbCrossProductVector3( 1002, 1000, 1001 );
xvel += acceleration * dbXVector3(1002);
yvel += acceleration * dbYVector3(1002);
zvel += acceleration * dbZVector3(1002);
}
if(dbKeyState(44)) //Z
{
dbPickScreen(400,300,1);
dbMakeVector3( 1000 );
dbSetVector3(1000, dbGetPickVectorX( ), dbGetPickVectorY( ), dbGetPickVectorZ( ) );
dbMakeVector3( 1001 );
dbSetVector3(1001, 0, 1, 0 );
dbMakeVector3( 1002 );
dbCrossProductVector3( 1002, 1000, 1001 );
xvel -= acceleration * dbXVector3(1002);
yvel -= acceleration * dbYVector3(1002);
zvel -= acceleration * dbZVector3(1002);
}
//detect collisions
x+=xvel;y+=yvel;z+=zvel;
}
Help! I'm so very bad at 3D math. Sorry about that.