add world matrix
add view matrix add projection matrix
This commit is contained in:
+24
-1
@@ -1,12 +1,35 @@
|
||||
#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)
|
||||
void Camera::update(FLOAT dt, IDirect3DDevice9* pD3DDevice)
|
||||
{
|
||||
pD3DDevice->SetTransform(D3DTS_VIEW, &_viewMatrix);
|
||||
pD3DDevice->SetTransform(D3DTS_PROJECTION, &_projectionMatrix);
|
||||
}
|
||||
|
||||
void Camera::deInit()
|
||||
|
||||
Reference in New Issue
Block a user