add input
add time
This commit is contained in:
+64
-15
@@ -31,12 +31,23 @@ void Mesh::update(FLOAT dt)
|
||||
static FLOAT x = 0.0f;
|
||||
static FLOAT y = 0.0f;
|
||||
static FLOAT z = 0.0f;
|
||||
static FLOAT pitch = 0.0f;
|
||||
static FLOAT pitch = XM_PIDIV4;
|
||||
static FLOAT yaw = 0.0f;
|
||||
static FLOAT roll = 0.0f;
|
||||
static FLOAT roll = XM_PIDIV4;
|
||||
static FLOAT scale = 1.0f;
|
||||
|
||||
yaw += 0.01f;
|
||||
yaw += 1.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('Q') & 0x8000) z -= move;
|
||||
if (GetAsyncKeyState('E') & 0x8000) z += move;
|
||||
|
||||
XMMATRIX translationMatrix = XMMatrixTranslation(x, y, z);
|
||||
XMMATRIX rotationMatrix = XMMatrixRotationRollPitchYaw(pitch, yaw, roll);
|
||||
@@ -69,7 +80,7 @@ void Mesh::deInit()
|
||||
UINT Mesh::createVertexBuffer(IDirect3DDevice9* pD3DDevice)
|
||||
{
|
||||
// 1. define mesh structure
|
||||
_vertexCount = 4;
|
||||
_vertexCount = 8;
|
||||
_vertexStride = sizeof(Vertex);
|
||||
|
||||
// 2. create vertex buffer WITHOUT data
|
||||
@@ -110,12 +121,25 @@ UINT Mesh::createVertexBuffer(IDirect3DDevice9* pD3DDevice)
|
||||
//pVertices[2] = Vertex(-0.5f, -0.5f, 0.0f);
|
||||
//pVertices[3] = Vertex(0.5f, -0.5f, 0.0f);
|
||||
|
||||
// quad with trianglefan
|
||||
// quad with trianglelist & index buffer
|
||||
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 trianglefan
|
||||
//// quad with trianglelist & index buffer
|
||||
//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);
|
||||
|
||||
// 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);
|
||||
|
||||
// back
|
||||
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);
|
||||
|
||||
hr = _pVertexBuffer->Unlock();
|
||||
CheckFailed(hr, 320);
|
||||
@@ -127,7 +151,7 @@ UINT Mesh::createVertexBuffer(IDirect3DDevice9* pD3DDevice)
|
||||
|
||||
UINT Mesh::createIndexBuffer(IDirect3DDevice9* pD3DDevice)
|
||||
{
|
||||
_indexCount = 6; // triangle * 3
|
||||
_indexCount = 36; // triangle * 3
|
||||
|
||||
HRESULT hr = pD3DDevice->CreateIndexBuffer(
|
||||
_indexCount * sizeof(WORD),
|
||||
@@ -143,13 +167,38 @@ UINT Mesh::createIndexBuffer(IDirect3DDevice9* pD3DDevice)
|
||||
hr = _pIndexBuffer->Lock(0, 0, reinterpret_cast<void**>(&pIndices), 0);
|
||||
CheckFailed(hr, 340);
|
||||
|
||||
// quad
|
||||
// triangle 1
|
||||
pIndices[0] = 0; pIndices[1] = 1; pIndices[2] = 2;
|
||||
//// quad
|
||||
//// triangle 1
|
||||
//pIndices[0] = 0; pIndices[1] = 1; pIndices[2] = 2;
|
||||
|
||||
// triangle 2
|
||||
//// triangle 2
|
||||
//pIndices[3] = 0; pIndices[4] = 2; pIndices[5] = 3;
|
||||
|
||||
// cube
|
||||
// front
|
||||
pIndices[0] = 0; pIndices[1] = 1; pIndices[2] = 2;
|
||||
pIndices[3] = 0; pIndices[4] = 2; pIndices[5] = 3;
|
||||
|
||||
// back
|
||||
pIndices[6] = 4; pIndices[7] = 5; pIndices[8] = 6;
|
||||
pIndices[9] = 4; pIndices[10] = 6; pIndices[11] = 7;
|
||||
|
||||
// left
|
||||
pIndices[12] = 5; pIndices[13] = 0; pIndices[14] = 3;
|
||||
pIndices[15] = 5; pIndices[16] = 3; pIndices[17] = 6;
|
||||
|
||||
// right
|
||||
pIndices[18] = 1; pIndices[19] = 4; pIndices[20] = 7;
|
||||
pIndices[21] = 1; pIndices[22] = 7; pIndices[23] = 2;
|
||||
|
||||
// top
|
||||
pIndices[24] = 5; pIndices[25] = 4; pIndices[26] = 1;
|
||||
pIndices[27] = 5; pIndices[28] = 1; pIndices[29] = 0;
|
||||
|
||||
// bottom
|
||||
pIndices[30] = 3; pIndices[31] = 2; pIndices[32] = 7;
|
||||
pIndices[33] = 3; pIndices[34] = 7; pIndices[35] = 6;
|
||||
|
||||
hr = _pIndexBuffer->Unlock();
|
||||
CheckFailed(hr, 350);
|
||||
|
||||
|
||||
@@ -1,12 +1,31 @@
|
||||
#include "Time.h"
|
||||
#if _DEBUG
|
||||
#include <string>
|
||||
#endif // _DEBUG
|
||||
|
||||
UINT Time::init()
|
||||
{
|
||||
_lastFrame = CLOCK::now();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Time::update()
|
||||
{
|
||||
TIMEPOINT now = CLOCK::now();
|
||||
SECONDS diff = now - _lastFrame;
|
||||
_lastFrame = now;
|
||||
_deltaTime = diff.count();
|
||||
|
||||
#ifdef _DEBUG
|
||||
#ifdef UNICODE
|
||||
wstring output = L"fps: " + to_wstring(1 / _deltaTime) + L"\n";
|
||||
OutputDebugString(output.c_str());
|
||||
#else // !UNICODE
|
||||
string output = "fps: " + to_string(1 / _deltaTime) + "\n";
|
||||
OutputDebugString(output.c_str());
|
||||
#endif // UNICODE
|
||||
#endif // DEBUG
|
||||
}
|
||||
|
||||
void Time::deInit()
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef chrono::steady_clock CLOCK;
|
||||
typedef CLOCK::time_point TIMEPOINT;
|
||||
typedef chrono::duration<FLOAT> SECONDS;
|
||||
|
||||
class Time
|
||||
{
|
||||
public:
|
||||
@@ -15,5 +19,6 @@ public:
|
||||
|
||||
private:
|
||||
FLOAT _deltaTime = 0.0f;
|
||||
TIMEPOINT _lastFrame = {};
|
||||
};
|
||||
|
||||
|
||||
@@ -63,6 +63,13 @@ int WINAPI WinMain(
|
||||
// 8. run application
|
||||
while (window.run())
|
||||
{
|
||||
if (GetAsyncKeyState(VK_F1) & 0x8000) d3d.getDevice()->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
|
||||
if (GetAsyncKeyState(VK_F2) & 0x8000) d3d.getDevice()->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
|
||||
if (GetAsyncKeyState(VK_F3) & 0x8000) d3d.getDevice()->SetRenderState(D3DRS_FILLMODE, D3DFILL_POINT);
|
||||
if (GetAsyncKeyState(VK_F4) & 0x8000) d3d.getDevice()->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
|
||||
if (GetAsyncKeyState(VK_F5) & 0x8000) d3d.getDevice()->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
|
||||
if (GetAsyncKeyState(VK_F6) & 0x8000) d3d.getDevice()->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
|
||||
|
||||
// 8.1. update objects
|
||||
time.update();
|
||||
mesh.update(time.getDeltaTime());
|
||||
|
||||
Reference in New Issue
Block a user