Added: mesh transformation

Added: input
Added: texture shader
This commit is contained in:
2026-10-13 18:30:21 +02:00
parent d2a487a4f6
commit 13691e3da3
14 changed files with 1371 additions and 20 deletions
+31 -11
View File
@@ -19,6 +19,27 @@ UINT Mesh::init(ID3D11Device* pD3DDevice)
void Mesh::update(FLOAT dt)
{
static float x = 0.0f;
static float y = 0.0f;
static float z = 0.0f;
static float rotZ = 0.0f;
//rotZ += XM_PIDIV4 * dt;
float move = 10.0f * dt;
if (GetAsyncKeyState(VK_LEFT) & 0x8000 || GetAsyncKeyState('A') & 0x8000) x -= move;
if (GetAsyncKeyState(VK_RIGHT) & 0x8000 || GetAsyncKeyState('D') & 0x8000) x += move;
if (GetAsyncKeyState(VK_UP) & 0x8000 || GetAsyncKeyState('W') & 0x8000) y += move;
if (GetAsyncKeyState(VK_DOWN) & 0x8000 || GetAsyncKeyState('S') & 0x8000) y -= move;
if (GetAsyncKeyState(VK_SUBTRACT) & 0x8000 || GetAsyncKeyState('Q') & 0x8000) z -= move;
if (GetAsyncKeyState(VK_ADD) & 0x8000 || GetAsyncKeyState('E') & 0x8000) z += move;
XMMATRIX translation = XMMatrixTranslation(x, y, z);
XMMATRIX rotation = XMMatrixRotationRollPitchYaw(0.0f, 0.0f, rotZ);
XMMATRIX scale = XMMatrixScaling(1.0f, 1.0f, 1.0f);
XMStoreFloat4x4(&_worldMatrix, scale * rotation * translation);
}
void Mesh::render(ID3D11DeviceContext* pD3DDeviceContext)
@@ -58,21 +79,20 @@ void Mesh::deInit()
UINT Mesh::createVertexBuffer(ID3D11Device* pD3DDevice)
{
// TODO: create a quad (square)
// TODO: create a cube
// 1. define the structure (vertices)
Vertex vertices[] = {
// triangle
Vertex(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f), // 0
Vertex(1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f), // 1
Vertex(-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f) // 2
//Vertex(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f), // 0
//Vertex(1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f), // 1
//Vertex(-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f) // 2
// quad
//Vertex(-0.5f, 0.5f, 0.0f),
//Vertex(0.5f, 0.5f, 0.0f),
//Vertex(0.5f, -0.5f, 0.0f),
//Vertex(-0.5f, -0.5f, 0.0f)
Vertex(-0.5f, 0.5f, 0.0f, 0.0f, 0.0f),
Vertex(0.5f, 0.5f, 0.0f, 1.0f, 0.0f),
Vertex(0.5f, -0.5f, 0.0f, 1.0f, 1.0f),
Vertex(-0.5f, -0.5f, 0.0f, 0.0f, 1.0f)
};
_vertexCount = std::size(vertices);
@@ -98,11 +118,11 @@ UINT Mesh::createIndexBuffer(ID3D11Device* pD3DDevice)
{
USHORT indices[] = {
// triangles
0, 1, 2
//0, 1, 2
// quad
//0, 1, 2,
//0, 2, 3
0, 1, 2,
0, 2, 3
};
_indexCount = std::size(indices);