Add transformation

Add input
Add time
Add vertex colors
This commit is contained in:
2026-11-16 12:10:00 +01:00
parent 17b18859b3
commit b84f9c1052
7 changed files with 102 additions and 10 deletions
+28 -1
View File
@@ -1,7 +1,34 @@
#include "Camera.h"
#include <DirectXMath.h>
UINT Camera::init(UINT width, UINT height)
using namespace DirectX;
UINT Camera::init(IDirect3DDevice9* pD3DDevice, UINT width, UINT height)
{
// view matrix
XMVECTOR position = XMVectorSet(0.0f, 0.0f, -2.0f, 0.0f);
XMVECTOR forward = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);
XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
XMMATRIX lookTo = XMMatrixLookToLH(position, forward, up);
XMFLOAT4X4 v;
XMStoreFloat4x4(&v, lookTo);
_viewMatrix = *reinterpret_cast<D3DMATRIX*>(&v);
// projection matrix
float fov = XMConvertToRadians(60.0f);
float aspectRatio = static_cast<float>(width) / static_cast<float>(height);
float nearClippingPlane = 0.3f;
float farClippingPlane = 100.0f;
XMMATRIX perspective = XMMatrixPerspectiveFovLH(fov, aspectRatio, nearClippingPlane, farClippingPlane);
XMFLOAT4X4 p;
XMStoreFloat4x4(&p, perspective);
_projectionMatrix = *reinterpret_cast<D3DMATRIX*>(&p);
pD3DDevice->SetTransform(D3DTS_VIEW, &_viewMatrix);
pD3DDevice->SetTransform(D3DTS_PROJECTION, &_projectionMatrix);
return 0;
}