My last topic died, but since my last question was a bit off-topic I'll just go ahead and make a new one.
How would I go about setting the initial view direction? (Setting it in the code)
Given that I can't mess with the formula, I really have no idea.
Here's the code:
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 = 0.0f; AngleX += mousestate.lX * MouseSpeed;
static float AngleY = 0.0f; AngleY += mousestate.lY * MouseSpeed;
static float LookX = 0.0f;
static float LookY = 0.0f;
static float LookZ = 0.0f;
static float MoveX = 0.0f;
static float MoveY = 0.0f;
static float MoveZ = 0.0f;
if(keystate[DIK_A] & 0x80)
{
MoveX -= 0.3f;
}
if(keystate[DIK_D] & 0x80)
{
MoveX += 0.3f;
}
if(keystate[DIK_S] & 0x80)
{
MoveY -= 0.3f;
}
if(keystate[DIK_W] & 0x80)
{
MoveY += 0.3f;
}
LookX = cos(AngleX) * sin(AngleY);
LookY = sin(AngleY);
LookZ = sin(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