diff --git a/DX11Starter.vcxproj b/DX11Starter.vcxproj
index eafecb3..e3338d0 100644
--- a/DX11Starter.vcxproj
+++ b/DX11Starter.vcxproj
@@ -124,17 +124,21 @@
+
+
+
+
diff --git a/DX11Starter.vcxproj.filters b/DX11Starter.vcxproj.filters
index a9a657e..0ee7d77 100644
--- a/DX11Starter.vcxproj.filters
+++ b/DX11Starter.vcxproj.filters
@@ -33,6 +33,12 @@
Source Files
+
+ Source Files
+
+
+ Source Files
+
@@ -53,6 +59,12 @@
Header Files
+
+ Header Files
+
+
+ Header Files
+
diff --git a/Game.cpp b/Game.cpp
index 4d2b457..8b80135 100644
--- a/Game.cpp
+++ b/Game.cpp
@@ -197,6 +197,18 @@ void Game::CreateBasicGeometry()
std::make_shared(verts2, 04, ind2, 06, device, context),
std::make_shared(verts3, 06, ind3, 12, device, context),
};
+
+ entities = {
+ std::make_shared(shapes[0]),
+ std::make_shared(shapes[0]),
+ std::make_shared(shapes[0]),
+ std::make_shared(shapes[1]),
+ std::make_shared(shapes[1]),
+ std::make_shared(shapes[1]),
+ std::make_shared(shapes[2]),
+ std::make_shared(shapes[2]),
+ std::make_shared(shapes[2]),
+ };
}
@@ -225,26 +237,8 @@ void Game::Update(float deltaTime, float totalTime)
// --------------------------------------------------------
void Game::Draw(float deltaTime, float totalTime)
{
- // create constant buffer
- VertexShaderExternalData vsData;
- vsData.colorTint = XMFLOAT4(1.0f, 0.5f, 0.5f, 1.0f);
- vsData.offset = XMFLOAT3(0.25f, 0.0f, 0.0f);
-
- // copy constant buffer to resource
- D3D11_MAPPED_SUBRESOURCE mappedBuffer = {};
- context->Map(constantBufferVS.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedBuffer);
- memcpy(mappedBuffer.pData, &vsData, sizeof(vsData));
- context->Unmap(constantBufferVS.Get(), 0);
-
- // bind constant buffer
- context->VSSetConstantBuffers(
- 0, // which slot (register) to bind buffer to?
- 1, // how many are we activating? can do multiple at once?
- constantBufferVS.GetAddressOf() // Array of buffers (or address of one)
- );
-
// Background color (Cornflower Blue in this case) for clearing
- const float color[4] = { 0.4f, 0.6f, 0.75f, 0.0f };
+ static const float color[4] = { 0.4f, 0.6f, 0.75f, 0.0f };
// Clear the render target and depth buffer (erases what's on the screen)
// - Do this ONCE PER FRAME
@@ -256,25 +250,41 @@ void Game::Draw(float deltaTime, float totalTime)
1.0f,
0);
-
- // Set the vertex and pixel shaders to use for the next Draw() command
- // - These don't technically need to be set every frame
- // - Once you start applying different shaders to different objects,
- // you'll need to swap the current shaders before each draw
- context->VSSetShader(vertexShader.Get(), 0, 0);
- context->PSSetShader(pixelShader.Get(), 0, 0);
-
-
- // Ensure the pipeline knows how to interpret the data (numbers)
- // from the vertex buffer.
- // - If all of your 3D models use the exact same vertex layout,
- // this could simply be done once in Init()
- // - However, this isn't always the case (but might be for this course)
- context->IASetInputLayout(inputLayout.Get());
-
- for (int i = 0; i < shapes.size(); ++i)
+ for (auto entity : entities)
{
- shapes[i]->Draw();
+ // create constant buffer
+ VertexShaderExternalData vsData;
+ vsData.colorTint = XMFLOAT4(1.0f, 0.5f, 0.5f, 1.0f);
+ vsData.world = entity->GetTransform()->GetWorldMatrix();
+
+ // copy constant buffer to resource
+ D3D11_MAPPED_SUBRESOURCE mappedBuffer = {};
+ context->Map(constantBufferVS.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedBuffer);
+ memcpy(mappedBuffer.pData, &vsData, sizeof(vsData));
+ context->Unmap(constantBufferVS.Get(), 0);
+
+ // bind constant buffer
+ context->VSSetConstantBuffers(
+ 0, // which slot (register) to bind buffer to?
+ 1, // how many are we activating? can do multiple at once?
+ constantBufferVS.GetAddressOf() // Array of buffers (or address of one)
+ );
+
+ // Set the vertex and pixel shaders to use for the next Draw() command
+ // - These don't technically need to be set every frame
+ // - Once you start applying different shaders to different objects,
+ // you'll need to swap the current shaders before each draw
+ context->VSSetShader(vertexShader.Get(), 0, 0);
+ context->PSSetShader(pixelShader.Get(), 0, 0);
+
+ // Ensure the pipeline knows how to interpret the data (numbers)
+ // from the vertex buffer.
+ // - If all of your 3D models use the exact same vertex layout,
+ // this could simply be done once in Init()
+ // - However, this isn't always the case (but might be for this course)
+ context->IASetInputLayout(inputLayout.Get());
+
+ entity->GetMesh()->Draw();
}
// Present the back buffer to the user
diff --git a/Game.h b/Game.h
index f18370b..0aa6992 100644
--- a/Game.h
+++ b/Game.h
@@ -2,6 +2,7 @@
#include "DXCore.h"
#include "Mesh.h"
+#include "Entity.h"
#include
#include // Used for ComPtr - a smart pointer for COM objects
#include
@@ -43,6 +44,8 @@ private:
// Temporary A2 shapes
std::vector> shapes;
+ // Temporary A3 entities;
+ std::vector> entities;
Microsoft::WRL::ComPtr constantBufferVS;
};
diff --git a/Transform.h b/Transform.h
index 359b24d..fa98c4d 100644
--- a/Transform.h
+++ b/Transform.h
@@ -22,7 +22,6 @@ public:
void Rotate(float _pitch, float _yaw, float _roll);
void Scale(float _x, float _y, float _z);
-
private:
DirectX::XMFLOAT3 position;
DirectX::XMFLOAT3 eulerAngles;