Okay. Here's the broken code.
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(16)) //Q
{
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(44)) //Z
{
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, 0, 1, 0 );
dbMakeVector3( 1002 );
dbCrossProductVector3( 1002, 1000, 1001 );
xvel += acceleration * dbXVector3(1002);
yvel += acceleration * dbYVector3(1002);
zvel += acceleration * dbZVector3(1002);
}
if(dbKeyState(32)) //D
{
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);
}
Basically I'm using dbPickScreen(middle.of.screen); to get a unit vector pointed in the direction the camera is pointed. I want the spaceship to accelerate to the right and left (when a & d are pressed, respectively), and to do that I need a unit vector pointed to the left of the direction that the camera is pointed.
I also need to do this for arbitrary objects, for which there is no dbPickScreen function! That is to say, 3d objects with arbitrary yaw & pitch rotations applied to them...I need a vector pointed to the right and a vector pointed up of the direction these objects are facing. Unit vectors are preferred, so I can plug them into my 3D math functions to calculate the newtonian physics of space flight.