Add transformations
Add input Add time Add vertex colors
This commit is contained in:
+41
-4
@@ -2,6 +2,10 @@
|
||||
#include "Utilities.h"
|
||||
#include "Vertex.h"
|
||||
|
||||
#include <DirectXMath.h>
|
||||
|
||||
using namespace DirectX;
|
||||
|
||||
UINT Mesh::init(IDirect3DDevice9* pD3DDevice)
|
||||
{
|
||||
UINT error = 0;
|
||||
@@ -12,11 +16,37 @@ UINT Mesh::init(IDirect3DDevice9* pD3DDevice)
|
||||
error = createIndexBuffer(pD3DDevice);
|
||||
CheckError(error);
|
||||
|
||||
XMMATRIX identity = XMMatrixIdentity();
|
||||
XMFLOAT4X4 w;
|
||||
XMStoreFloat4x4(&w, identity);
|
||||
_worldMatrix = *reinterpret_cast<D3DMATRIX*>(&w);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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 += 0.0f * dt;
|
||||
|
||||
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(VK_SUBTRACT) & 0x8000) z -= move;
|
||||
if (GetAsyncKeyState(VK_ADD) & 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(reinterpret_cast<XMFLOAT4X4*>(&_worldMatrix), scale * rotation * translation);
|
||||
}
|
||||
|
||||
void Mesh::render(IDirect3DDevice9* pD3DDevice)
|
||||
@@ -25,6 +55,7 @@ void Mesh::render(IDirect3DDevice9* pD3DDevice)
|
||||
pD3DDevice->SetStreamSource(0, _pVertexBuffer, 0, _vertexStride);
|
||||
pD3DDevice->SetIndices(_pIndexBuffer);
|
||||
pD3DDevice->SetFVF(FVF);
|
||||
pD3DDevice->SetTransform(D3DTS_WORLD, &_worldMatrix);
|
||||
|
||||
// draw call
|
||||
pD3DDevice->DrawIndexedPrimitive(
|
||||
@@ -74,10 +105,16 @@ UINT Mesh::createVertexBuffer(IDirect3DDevice9* pD3DDevice)
|
||||
//pVertices[2] = Vertex(-1.0f, -1.0f, 0.0f);
|
||||
|
||||
// quad
|
||||
pVertices[0] = Vertex(-0.5f, 0.5f, 0.0f);
|
||||
pVertices[1] = Vertex(0.5f, 0.5f, 0.0f);
|
||||
pVertices[2] = Vertex(0.5f, -0.5f, 0.0f);
|
||||
pVertices[3] = Vertex(-0.5f, -0.5f, 0.0f);
|
||||
//pVertices[0] = Vertex(-0.5f, 0.5f, 0.0f);
|
||||
//pVertices[1] = Vertex(0.5f, 0.5f, 0.0f);
|
||||
//pVertices[2] = Vertex(0.5f, -0.5f, 0.0f);
|
||||
//pVertices[3] = Vertex(-0.5f, -0.5f, 0.0f);
|
||||
|
||||
// quad with color
|
||||
pVertices[0] = Vertex(-0.5f, 0.5f, 0.0f, 255, 0, 0);
|
||||
pVertices[1] = Vertex(0.5f, 0.5f, 0.0f, 0, 255, 0);
|
||||
pVertices[2] = Vertex(0.5f, -0.5f, 0.0f, 255, 0, 255);
|
||||
pVertices[3] = Vertex(-0.5f, -0.5f, 0.0f, 0, 0, 255);
|
||||
|
||||
hr = _pVertexBuffer->Unlock();
|
||||
CheckFailed(hr, 320);
|
||||
|
||||
Reference in New Issue
Block a user