Hi
I'm struggling with collision detection. i've managed to perfect it in D3D, but now I've ported the code to GL, and have problems with Gl's inverted Z-axis. How can I convert my vectors to D3D style vectors ( Z is positive into screen )?
I get my View Position like follows:
float MoveToX = ViewXPos;
float MoveToY = ViewYPos;
float MoveToZ = ViewZPos;
float SS = 0;
if(Keyboard.isKeyDown(Keyboard.KEY_W))
{
MoveToY -= (float)Math.sin(Math.toRadians(ViewPitch)) * MovementSpeed;
SS = (float)Math.cos(Math.toRadians(ViewPitch)) * MovementSpeed;
MoveToX += (float)Math.sin(Math.toRadians(ViewYaw)) * SS;
MoveToZ -= (float)Math.cos(Math.toRadians(ViewYaw)) * SS;
}
if(Keyboard.isKeyDown(Keyboard.KEY_S))
{
MoveToY += (float)Math.sin(Math.toRadians(ViewPitch)) * MovementSpeed;
SS = (float)Math.cos(Math.toRadians(ViewPitch)) * MovementSpeed;
MoveToX -= (float)Math.sin(Math.toRadians(ViewYaw)) * SS;
MoveToZ += (float)Math.cos(Math.toRadians(ViewYaw)) * SS;
}
if(Keyboard.isKeyDown(Keyboard.KEY_A))
{
MoveToX -= (float)Math.sin(Math.toRadians(ViewYaw + 90)) * MovementSpeed;
MoveToZ += (float)Math.cos(Math.toRadians(ViewYaw + 90)) * MovementSpeed;
}
if(Keyboard.isKeyDown(Keyboard.KEY_D))
{
MoveToX += (float)Math.sin(Math.toRadians(ViewYaw + 90)) * MovementSpeed;
MoveToZ -= (float)Math.cos(Math.toRadians(ViewYaw + 90)) * MovementSpeed;
}
if(Keyboard.isKeyDown(Keyboard.KEY_SPACE))
{
MoveToY += MovementSpeed;
}
if(Keyboard.isKeyDown(Keyboard.KEY_LCONTROL))
{
MoveToY -= MovementSpeed;
}
then I calculate the vectors as follows:
Vector3f vEyePt = new Vector3f(ViewXPos,ViewYPos,ViewZPos);
Vector3f vVelocity = new Vector3f((MoveToX - ViewXPos),(MoveToY - ViewYPos), (MoveToZ - ViewZPos));
So any idea how? It's probably a math thing. The problem is also that the face normals are calculated according to a correct LH-structure meaning -1 is out of screen. So everything's a bit messed up.
Thanx for your help!