update Game to use new Entity code
This commit is contained in:
parent
ff0d41c301
commit
09f84f9b03
5 changed files with 66 additions and 38 deletions
|
@ -124,17 +124,21 @@
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="DXCore.cpp" />
|
<ClCompile Include="DXCore.cpp" />
|
||||||
|
<ClCompile Include="Entity.cpp" />
|
||||||
<ClCompile Include="Game.cpp" />
|
<ClCompile Include="Game.cpp" />
|
||||||
<ClCompile Include="Input.cpp" />
|
<ClCompile Include="Input.cpp" />
|
||||||
<ClCompile Include="Main.cpp" />
|
<ClCompile Include="Main.cpp" />
|
||||||
<ClCompile Include="Mesh.cpp" />
|
<ClCompile Include="Mesh.cpp" />
|
||||||
|
<ClCompile Include="Transform.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="BufferStructs.h" />
|
<ClInclude Include="BufferStructs.h" />
|
||||||
<ClInclude Include="DXCore.h" />
|
<ClInclude Include="DXCore.h" />
|
||||||
|
<ClInclude Include="Entity.h" />
|
||||||
<ClInclude Include="Game.h" />
|
<ClInclude Include="Game.h" />
|
||||||
<ClInclude Include="Input.h" />
|
<ClInclude Include="Input.h" />
|
||||||
<ClInclude Include="Mesh.h" />
|
<ClInclude Include="Mesh.h" />
|
||||||
|
<ClInclude Include="Transform.h" />
|
||||||
<ClInclude Include="Vertex.h" />
|
<ClInclude Include="Vertex.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -33,6 +33,12 @@
|
||||||
<ClCompile Include="Mesh.cpp">
|
<ClCompile Include="Mesh.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Transform.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Entity.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Vertex.h">
|
<ClInclude Include="Vertex.h">
|
||||||
|
@ -53,6 +59,12 @@
|
||||||
<ClInclude Include="BufferStructs.h">
|
<ClInclude Include="BufferStructs.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Transform.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Entity.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<FxCompile Include="PixelShader.hlsl">
|
<FxCompile Include="PixelShader.hlsl">
|
||||||
|
|
48
Game.cpp
48
Game.cpp
|
@ -197,6 +197,18 @@ void Game::CreateBasicGeometry()
|
||||||
std::make_shared<Mesh>(verts2, 04, ind2, 06, device, context),
|
std::make_shared<Mesh>(verts2, 04, ind2, 06, device, context),
|
||||||
std::make_shared<Mesh>(verts3, 06, ind3, 12, device, context),
|
std::make_shared<Mesh>(verts3, 06, ind3, 12, device, context),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
entities = {
|
||||||
|
std::make_shared<Entity>(shapes[0]),
|
||||||
|
std::make_shared<Entity>(shapes[0]),
|
||||||
|
std::make_shared<Entity>(shapes[0]),
|
||||||
|
std::make_shared<Entity>(shapes[1]),
|
||||||
|
std::make_shared<Entity>(shapes[1]),
|
||||||
|
std::make_shared<Entity>(shapes[1]),
|
||||||
|
std::make_shared<Entity>(shapes[2]),
|
||||||
|
std::make_shared<Entity>(shapes[2]),
|
||||||
|
std::make_shared<Entity>(shapes[2]),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -225,10 +237,25 @@ void Game::Update(float deltaTime, float totalTime)
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
void Game::Draw(float deltaTime, float totalTime)
|
void Game::Draw(float deltaTime, float totalTime)
|
||||||
{
|
{
|
||||||
|
// Background color (Cornflower Blue in this case) for clearing
|
||||||
|
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
|
||||||
|
// - At the beginning of Draw (before drawing *anything*)
|
||||||
|
context->ClearRenderTargetView(backBufferRTV.Get(), color);
|
||||||
|
context->ClearDepthStencilView(
|
||||||
|
depthStencilView.Get(),
|
||||||
|
D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL,
|
||||||
|
1.0f,
|
||||||
|
0);
|
||||||
|
|
||||||
|
for (auto entity : entities)
|
||||||
|
{
|
||||||
// create constant buffer
|
// create constant buffer
|
||||||
VertexShaderExternalData vsData;
|
VertexShaderExternalData vsData;
|
||||||
vsData.colorTint = XMFLOAT4(1.0f, 0.5f, 0.5f, 1.0f);
|
vsData.colorTint = XMFLOAT4(1.0f, 0.5f, 0.5f, 1.0f);
|
||||||
vsData.offset = XMFLOAT3(0.25f, 0.0f, 0.0f);
|
vsData.world = entity->GetTransform()->GetWorldMatrix();
|
||||||
|
|
||||||
// copy constant buffer to resource
|
// copy constant buffer to resource
|
||||||
D3D11_MAPPED_SUBRESOURCE mappedBuffer = {};
|
D3D11_MAPPED_SUBRESOURCE mappedBuffer = {};
|
||||||
|
@ -243,20 +270,6 @@ void Game::Draw(float deltaTime, float totalTime)
|
||||||
constantBufferVS.GetAddressOf() // Array of buffers (or address of one)
|
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 };
|
|
||||||
|
|
||||||
// Clear the render target and depth buffer (erases what's on the screen)
|
|
||||||
// - Do this ONCE PER FRAME
|
|
||||||
// - At the beginning of Draw (before drawing *anything*)
|
|
||||||
context->ClearRenderTargetView(backBufferRTV.Get(), color);
|
|
||||||
context->ClearDepthStencilView(
|
|
||||||
depthStencilView.Get(),
|
|
||||||
D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL,
|
|
||||||
1.0f,
|
|
||||||
0);
|
|
||||||
|
|
||||||
|
|
||||||
// Set the vertex and pixel shaders to use for the next Draw() command
|
// Set the vertex and pixel shaders to use for the next Draw() command
|
||||||
// - These don't technically need to be set every frame
|
// - These don't technically need to be set every frame
|
||||||
// - Once you start applying different shaders to different objects,
|
// - Once you start applying different shaders to different objects,
|
||||||
|
@ -264,7 +277,6 @@ void Game::Draw(float deltaTime, float totalTime)
|
||||||
context->VSSetShader(vertexShader.Get(), 0, 0);
|
context->VSSetShader(vertexShader.Get(), 0, 0);
|
||||||
context->PSSetShader(pixelShader.Get(), 0, 0);
|
context->PSSetShader(pixelShader.Get(), 0, 0);
|
||||||
|
|
||||||
|
|
||||||
// Ensure the pipeline knows how to interpret the data (numbers)
|
// Ensure the pipeline knows how to interpret the data (numbers)
|
||||||
// from the vertex buffer.
|
// from the vertex buffer.
|
||||||
// - If all of your 3D models use the exact same vertex layout,
|
// - If all of your 3D models use the exact same vertex layout,
|
||||||
|
@ -272,9 +284,7 @@ void Game::Draw(float deltaTime, float totalTime)
|
||||||
// - However, this isn't always the case (but might be for this course)
|
// - However, this isn't always the case (but might be for this course)
|
||||||
context->IASetInputLayout(inputLayout.Get());
|
context->IASetInputLayout(inputLayout.Get());
|
||||||
|
|
||||||
for (int i = 0; i < shapes.size(); ++i)
|
entity->GetMesh()->Draw();
|
||||||
{
|
|
||||||
shapes[i]->Draw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present the back buffer to the user
|
// Present the back buffer to the user
|
||||||
|
|
3
Game.h
3
Game.h
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "DXCore.h"
|
#include "DXCore.h"
|
||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
|
#include "Entity.h"
|
||||||
#include <DirectXMath.h>
|
#include <DirectXMath.h>
|
||||||
#include <wrl/client.h> // Used for ComPtr - a smart pointer for COM objects
|
#include <wrl/client.h> // Used for ComPtr - a smart pointer for COM objects
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -43,6 +44,8 @@ private:
|
||||||
|
|
||||||
// Temporary A2 shapes
|
// Temporary A2 shapes
|
||||||
std::vector<std::shared_ptr<Mesh>> shapes;
|
std::vector<std::shared_ptr<Mesh>> shapes;
|
||||||
|
// Temporary A3 entities;
|
||||||
|
std::vector<std::shared_ptr<Entity>> entities;
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<ID3D11Buffer> constantBufferVS;
|
Microsoft::WRL::ComPtr<ID3D11Buffer> constantBufferVS;
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,7 +22,6 @@ public:
|
||||||
void Rotate(float _pitch, float _yaw, float _roll);
|
void Rotate(float _pitch, float _yaw, float _roll);
|
||||||
void Scale(float _x, float _y, float _z);
|
void Scale(float _x, float _y, float _z);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DirectX::XMFLOAT3 position;
|
DirectX::XMFLOAT3 position;
|
||||||
DirectX::XMFLOAT3 eulerAngles;
|
DirectX::XMFLOAT3 eulerAngles;
|
||||||
|
|
Reference in a new issue