His suggestion actually IS the simple way, because you won't have to deal with any trigonometry, can let the D3DX matrix library do all the work for you and fix your movement problem in one step. It just requires reading up on transformation matrices and vector math. Considering that these things are pretty much the absolute core of any 3D game or application you won't get around learning to love those anyway.
Does that mean that I don't actually need the formula?
If I don't then I'll just say hallelujah and ask.. how would I handle
everything I need with the D3DX library?
With trigonometry, I managed to get SOMETHING like what I wanted,
but it's still complete bull**** what's going on in my program.
Here's the code I came up with:
D3DXMATRIX matView; // the view transform matrix
static float MouseSpeed = 0.0075f;
if (keystate[DIK_F1])
{
MouseSpeed += 0.0001f;
}
else if (keystate[DIK_F2])
{
if (MouseSpeed > 0.0001f)
{
MouseSpeed -= 0.0001f;
}
}
static float AngleX = 4.7f; AngleX -= mousestate.lX * MouseSpeed; //increase = left
static float AngleY = 4.7f; AngleY -= mousestate.lY * MouseSpeed; //increase = up
static float LookX = 0.0f;
static float LookY = 0.0f;
static float LookZ = 0.0f;
static float MoveX = 0.0f;
static float MoveY = 1.0f;
static float MoveZ = 0.0f;
//in order for the camera to keep looking in the same direction
LookX = cos(AngleX) * sin(AngleY);
LookY = cos(AngleY);
LookZ = (sin(AngleX) * sin(AngleY));
FileInputZ = LookZ;
FileWrite ();
if (LookZ > 0) //looking infront of center
{
if(keystate[DIK_A] & 0x80)
{
MoveX -= 0.3f;
}
if(keystate[DIK_D] & 0x80)
{
MoveX += 0.3f;
}
if(keystate[DIK_S] & 0x80)
{
MoveZ -= 0.3f;
}
if(keystate[DIK_W] & 0x80)
{
// MoveZ += 0.3f;
MoveZ += (sin(AngleX) * sin(AngleY));
MoveY += cos(AngleY) ; //too fast
MoveX += cos(AngleX) * sin(AngleY);
}
}
if (LookZ < 0) //if looking behind the center
{
if(keystate[DIK_A] & 0x80)
{
MoveX += 0.3f;
}
if(keystate[DIK_D] & 0x80)
{
MoveX -= 0.3f;
}
if(keystate[DIK_S] & 0x80)
{
MoveZ += 0.3f;
}
if(keystate[DIK_W] & 0x80)
{
//MoveZ -= 0.3f;
MoveZ += (sin(AngleX) * sin(AngleY));
MoveY += cos(AngleY) ; //too fast
MoveX += cos(AngleX) * sin(AngleY);
}
}
D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (MoveX, MoveY, MoveZ), // the camera position
&D3DXVECTOR3 (LookX + MoveX, LookY + MoveY, LookZ + MoveZ), // the look-at position + to go along with movement
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f)); // the up direction
d3ddev->SetTransform(D3DTS_VIEW, &matView); // set the view transform to matView
D3DXMATRIX matProjection; // the projection transform matrix
D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45), // the horizontal field of view
(FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio
1.0f, // the near view-plane
1000.0f); // the far view-plane
d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection); // set the projection