#include "Camera.h" #include using namespace DirectX; UINT Camera::init(UINT width, UINT height) { // view matrix XMVECTOR position = XMVectorSet(0.0f, 0.0f, -2.0f, 0.0f); // camera position XMVECTOR forward = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f); // camera forward vector XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); // camera up vector XMMATRIX viewMatrix = XMMatrixLookToLH(position, forward, up); XMStoreFloat4x4(reinterpret_cast(&_viewMatrix), viewMatrix); // projection matrix FLOAT fov = XM_PI * 0.3333333f; // field of view angle in radians FLOAT aspectRatio = static_cast(width) / static_cast(height); // CAUTION: UINT / UINT => UINT FLOAT nearClippingPlane = 0.3f; FLOAT farClippingPlane = 20.0f; XMMATRIX projectionMatrix = XMMatrixPerspectiveFovLH(fov, aspectRatio, nearClippingPlane, farClippingPlane); XMStoreFloat4x4(reinterpret_cast(&_projectionMatrix), projectionMatrix); return 0; } void Camera::update(FLOAT dt, IDirect3DDevice9* pD3DDevice) { pD3DDevice->SetTransform(D3DTS_VIEW, &_viewMatrix); pD3DDevice->SetTransform(D3DTS_PROJECTION, &_projectionMatrix); } void Camera::deInit() { }