add input

add time
add vertex color
This commit is contained in:
2025-09-24 11:44:51 +02:00
parent faa9b71510
commit c9e9dcf572
5 changed files with 51 additions and 15 deletions
+24 -12
View File
@@ -28,15 +28,27 @@ UINT Mesh::init(IDirect3DDevice9* pD3DDevice)
void Mesh::update(FLOAT dt)
{
static FLOAT x = 0.0f;
static FLOAT y = 0.0f;
static FLOAT z = 0.0f;
static FLOAT pitch = XM_PIDIV4; // x axis
static FLOAT yaw = XM_PIDIV4; // y axis
static FLOAT roll = XM_PIDIV4; // z axis
static FLOAT scale = 1.0f;
yaw += 0.01f;
//scale += 0.001f;
yaw += 1.0f * dt;
//scale += 0.001f * dt;
XMMATRIX translationMatrix = XMMatrixTranslation(0.0f, 0.0f, 0.0f);
FLOAT move = 1.0f * dt;
if (GetAsyncKeyState(VK_LEFT) & 0x8000) x -= move;
if (GetAsyncKeyState(VK_RIGHT) & 0x8000) x += move;
if (GetAsyncKeyState(VK_DOWN) & 0x8000) y -= move;
if (GetAsyncKeyState(VK_UP) & 0x8000) y += move;
if (GetAsyncKeyState('E') & 0x8000) z -= move;
if (GetAsyncKeyState('Q') & 0x8000) z += move;
XMMATRIX translationMatrix = XMMatrixTranslation(x, y, z);
XMMATRIX scaleMatrix = XMMatrixScaling(scale, scale, scale);
XMMATRIX rotationMatrix = XMMatrixRotationRollPitchYaw(pitch, yaw, roll);
@@ -121,16 +133,16 @@ UINT Mesh::createVertexBuffer(IDirect3DDevice9* pD3DDevice)
// cube
// front
pVertices[0] = Vertex(-0.5f, 0.5f, -0.5f);
pVertices[1] = Vertex(0.5f, 0.5f, -0.5f);
pVertices[2] = Vertex(0.5f, -0.5f, -0.5f);
pVertices[3] = Vertex(-0.5f, -0.5f, -0.5f);
pVertices[0] = Vertex(-0.5f, 0.5f, -0.5f, 255, 0, 0);
pVertices[1] = Vertex(0.5f, 0.5f, -0.5f, 0, 255, 0);
pVertices[2] = Vertex(0.5f, -0.5f, -0.5f, 0, 0, 255);
pVertices[3] = Vertex(-0.5f, -0.5f, -0.5f, 255, 0, 255);
// front
pVertices[4] = Vertex(0.5f, 0.5f, 0.5f);
pVertices[5] = Vertex(-0.5f, 0.5f, 0.5f);
pVertices[6] = Vertex(-0.5f, -0.5f, 0.5f);
pVertices[7] = Vertex(0.5f, -0.5f, 0.5f);
// back
pVertices[4] = Vertex(0.5f, 0.5f, 0.5f, 255, 255, 0);
pVertices[5] = Vertex(-0.5f, 0.5f, 0.5f, 0, 255, 255);
pVertices[6] = Vertex(-0.5f, -0.5f, 0.5f, 0, 0, 0);
pVertices[7] = Vertex(0.5f, -0.5f, 0.5f, 200, 200, 200);
hr = _pVertexBuffer->Unlock(); // transfer vertex buffer back from cpu memory to video memory
CheckFailed(hr, 320);