38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
#include "Camera.h"
|
|
|
|
#include <DirectXMath.h>
|
|
|
|
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<XMFLOAT4X4*>(&_viewMatrix), viewMatrix);
|
|
|
|
// projection matrix
|
|
FLOAT fov = XM_PI * 0.3333333f; // field of view
|
|
FLOAT aspectRatio = static_cast<FLOAT>(width) / static_cast<FLOAT>(height); // CAUTION: UINT / UINT => UINT
|
|
FLOAT nearClippingPlane = 0.3f;
|
|
FLOAT farClippingPlane = 100.0f;
|
|
|
|
XMMATRIX projectionMatrix = XMMatrixPerspectiveFovLH(fov, aspectRatio, nearClippingPlane, farClippingPlane);
|
|
XMStoreFloat4x4(reinterpret_cast<XMFLOAT4X4*>(&_projectionMatrix), projectionMatrix);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void Camera::update(FLOAT dt, IDirect3DDevice9* pD3DDevice)
|
|
{
|
|
pD3DDevice->SetTransform(D3DTS_VIEW, &_viewMatrix);
|
|
pD3DDevice->SetTransform(D3DTS_PROJECTION, &_projectionMatrix);
|
|
}
|
|
|
|
void Camera::deInit()
|
|
{
|
|
}
|