Showing posts with label View. Show all posts
Showing posts with label View. Show all posts

Thursday, April 14, 2011

Camera

This tutorial will demonstrate the use of camera

To create a camera, we need three vectors: up, right and look-at. Generally up vector is always set to (0.0f, 1.0f, 0.0f) and right and look-at vectors are set as follows (1.0f, 0.0f, 0.0f) and (0.0f, 1.0f, 0.0f). We will use these three vectors to create a view transformation matrix.

Before doing so we need to create a perspective projection matrix. We can create a left-handed perspective projection matrix using XMMatrixPerspectiveFovLH as follows:

float fAspectRatio = window_width / window_height; // Set window_width and window_height
XMMATRIX oProjectionMatrix = XMMatrixPerspectiveFovLH (XM_PI * 0.5f, // FOV

fAspectRatio, // Aspect ratio
0.01f, // Distance to near clipping plane
10000.0f); // Distance to far clipping plane

Now, it's time to create a left-handed view transformation matrix

XMMATRIX oViewMatrix = XMMatrixLookAtLH(XMVECTOR(0.0f, 0.0f, 0.0f, 0.0f), XMVECTOR(0.0f, 1.0f, 0.0f, 0.0f), XMVECTOR(0.0f, 1.0f, 0.0f, 0.0f));

Bind the above view transformation matrix to look at the objects in your game