Commit 57d362d4 authored by Administrator's avatar Administrator
Browse files

added Section module

parent 140b1eca
......@@ -133,13 +133,13 @@ void Box::Update(float dt) noexcept
//dz = dt * 10.0f;
}
void Box::UpdateCamera(float sin, float cos) noexcept
{
using namespace DirectX;
upDirection = XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f);
focusPosition = XMVectorZero();
eyePosition = XMVectorSet(20.0f * sin, 10.0f, -20.0f * cos, 1.0f);
};
//void Box::UpdateCamera(float sin, float cos) noexcept
//{
// using namespace DirectX;
// upDirection = XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f);
// focusPosition = XMVectorZero();
// eyePosition = XMVectorSet(20.0f * sin, 10.0f, -20.0f * cos, 1.0f);
//};
DirectX::XMMATRIX Box::GetTransformXM() const noexcept
{
......
......@@ -7,7 +7,8 @@ class Box : public Drawable
public:
Box(Graphics& gfx, float position[][3], float color[][3], Logger& logger);
void Update(float dt) noexcept override;
void UpdateCamera(float sin, float cos) noexcept;
//void UpdateCamera(float sin, float cos) noexcept;
//void SetCamera(DirectX::XMVECTOR upDirection, DirectX::XMVECTOR eyePosition, DirectX::XMVECTOR focusPosition) noexcept;
DirectX::XMMATRIX GetTransformXM() const noexcept override;
private:
// positional
......@@ -18,8 +19,4 @@ private:
float dx = 0.0f;
float dy = 0.0f;
float dz = 0.0f;
// for camera
DirectX::XMVECTOR upDirection;
DirectX::XMVECTOR eyePosition;
DirectX::XMVECTOR focusPosition;
};
\ No newline at end of file
......@@ -31,3 +31,30 @@ void Drawable::AddIndexBuffer(std::unique_ptr<IndexBuffer> ibuf) noexcept
pIndexBuffer = ibuf.get();
binds.push_back(std::move(ibuf));
}
void Drawable::SetCamera(
Logger& logger,
DirectX::XMVECTOR eyePosition,
DirectX::XMVECTOR focusPosition,
DirectX::XMVECTOR upDirection) noexcept
{
using namespace DirectX;
this->eyePosition = eyePosition;
this->focusPosition = focusPosition;
this->upDirection = upDirection;
/*this->upDirection = XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f);
this->focusPosition = XMVectorZero();
this->eyePosition = XMVectorSet(20.0f * sinValue, 10.0f, -20.0f * cosValue, 1.0f);
XMFLOAT4 upDirection4;
XMFLOAT4 eyePosition4;
XMFLOAT4 focusPosition4;
XMStoreFloat4(&upDirection4, this->upDirection);
XMStoreFloat4(&eyePosition4, this->eyePosition);
XMStoreFloat4(&focusPosition4, this->focusPosition);
logger.PutLog("Drawable::SetCamera", "upDirection: {" + std::to_string(upDirection4.x) + ", " + std::to_string(upDirection4.y) + ", " + std::to_string(upDirection4.z) + ", " + std::to_string(upDirection4.w) + "}");
logger.PutLog("Drawable::SetCamera", "eyePosition: {" + std::to_string(eyePosition4.x) + ", " + std::to_string(eyePosition4.y) + ", " + std::to_string(eyePosition4.z) + ", " + std::to_string(eyePosition4.w) + "}");
logger.PutLog("Drawable::SetCamera", "focusPosition: {" + std::to_string(focusPosition4.x) + ", " + std::to_string(focusPosition4.y) + ", " + std::to_string(focusPosition4.z) + ", " + std::to_string(focusPosition4.w) + "}");*/
};
\ No newline at end of file
......@@ -18,6 +18,11 @@ public:
void Draw(Graphics& gfx, Logger& logger) const noexcept;
virtual void Update(float dt) noexcept = 0;
void SetCamera(
Logger& logger,
DirectX::XMVECTOR eyePosition,
DirectX::XMVECTOR focusPosition,
DirectX::XMVECTOR upDirection) noexcept;
void AddBind(std::unique_ptr<Bindable> bind) noexcept;
void AddIndexBuffer(std::unique_ptr<class IndexBuffer> ibuf) noexcept;
void ExecuteBind(Graphics& gfx, Logger& logger) noexcept;
......@@ -25,4 +30,9 @@ public:
private:
const IndexBuffer* pIndexBuffer = nullptr;
std::vector<std::unique_ptr<Bindable>> binds;
protected:
// for camera
DirectX::XMVECTOR upDirection;
DirectX::XMVECTOR eyePosition;
DirectX::XMVECTOR focusPosition;
};
\ No newline at end of file
#pragma once
#include "Ground.h"
Ground::Ground(Graphics & gfx, Logger & logger) noexcept
{
// Init a 11 X 11 area as ground
for (int i = -5; i < 6; i++)
{
for (int j = -5; j < 6; j++)
{
float boxPos[8][3] =
{
// left bottom back
{ -1.0f + i, -1.0f, -1.0f + j },
// right bottom back
{ 1.0f + i, -1.0f, -1.0f + j },
// left top back
{ -1.0f + i, 1.0f, -1.0f + j },
// right top back
{ 1.0f + i, 1.0f, -1.0f + j },
// left bottom front
{ -1.0f + i, -1.0f, 1.0f + j },
// right bottom front
{ 1.0f + i, -1.0f, 1.0f + j },
// left top front
{ -1.0f + i, 1.0f, 1.0f + j },
// right top front
{ 1.0f + i, 1.0f, 1.0f + j },
};
float boxCol[6][3] =
{
{ 0.0f, 1.0f, 0.0f }, // Green
{ 1.0f, 1.0f, 0.0f }, // Yellow
{ 1.0f, 0.0f, 0.0f }, // Red
{ 0.0f, 0.0f, 1.0f }, // Blue
{ 0.0f, 1.0f, 1.0f }, // Cyan
{ 1.0f, 0.0f, 1.0f }, // Magenta
};
shapes.push_back(std::make_unique<Box>(gfx, boxPos, boxCol, logger));
}
}
//float boxPos2[8][3] =
//{
// // left bottom back
// { -1.0f, -1.0f + 5.0f, -1.0f },
// // right bottom back
// { 1.0f, -1.0f + 5.0f, -1.0f },
// // left top back
// { -1.0f, 1.0f + 5.0f, -1.0f },
// // right top back
// { 1.0f, 1.0f + 5.0f, -1.0f },
// // left bottom front
// { -1.0f, -1.0f + 5.0f, 1.0f },
// // right bottom front
// { 1.0f, -1.0f + 5.0f, 1.0f },
// // left top front
// { -1.0f, 1.0f + 5.0f, 1.0f },
// // right top front
// { 1.0f, 1.0f + 5.0f, 1.0f },
//};
//float boxCol2[6][3] =
//{
// { 0.0f, 1.0f, 0.0f }, // Green
// { 1.0f, 1.0f, 0.0f }, // Yellow
// { 1.0f, 0.0f, 0.0f }, // Red
// { 0.0f, 0.0f, 1.0f }, // Blue
// { 0.0f, 1.0f, 1.0f }, // Cyan
// { 1.0f, 0.0f, 1.0f }, // Magenta
//};
//shapes.push_back(std::make_unique<Box>(gfx, boxPos2, boxCol2, logger));
//float boxPos3[8][3] =
//{
// // left bottom back
// { -1.0f, -1.0f - 5.0f, -1.0f },
// // right bottom back
// { 1.0f, -1.0f - 5.0f, -1.0f },
// // left top back
// { -1.0f, 1.0f - 5.0f, -1.0f },
// // right top back
// { 1.0f, 1.0f - 5.0f, -1.0f },
// // left bottom front
// { -1.0f, -1.0f - 5.0f, 1.0f },
// // right bottom front
// { 1.0f, -1.0f - 5.0f, 1.0f },
// // left top front
// { -1.0f, 1.0f - 5.0f, 1.0f },
// // right top front
// { 1.0f, 1.0f - 5.0f, 1.0f },
//};
//float boxCol3[6][3] =
//{
// { 0.0f, 1.0f, 0.0f }, // Green
// { 1.0f, 1.0f, 0.0f }, // Yellow
// { 1.0f, 0.0f, 0.0f }, // Red
// { 0.0f, 0.0f, 1.0f }, // Blue
// { 0.0f, 1.0f, 1.0f }, // Cyan
// { 1.0f, 0.0f, 1.0f }, // Magenta
//};
//shapes.push_back(std::make_unique<Box>(gfx, boxPos3, boxCol3, logger));
};
#pragma once
#include "Section.h"
class Ground : public Section
{
public:
Ground(Graphics& gfx, Logger& logger) noexcept;
};
\ No newline at end of file
......@@ -132,10 +132,12 @@
<ClCompile Include="ConstantBuffer.h" />
<ClCompile Include="Drawable.cpp" />
<ClCompile Include="Graphics.cpp" />
<ClCompile Include="Ground.cpp" />
<ClCompile Include="IndexBuffer.cpp" />
<ClCompile Include="InputLayout.cpp" />
<ClCompile Include="Logger.cpp" />
<ClCompile Include="PixelShader.cpp" />
<ClCompile Include="Section.cpp" />
<ClCompile Include="Timer.cpp" />
<ClCompile Include="Topology.cpp" />
<ClCompile Include="TransformCBuf.cpp" />
......@@ -169,10 +171,12 @@
<ClInclude Include="Box.h" />
<ClInclude Include="Drawable.h" />
<ClInclude Include="Graphics.h" />
<ClInclude Include="Ground.h" />
<ClInclude Include="IndexBuffer.h" />
<ClInclude Include="InputLayout.h" />
<ClInclude Include="Logger.h" />
<ClInclude Include="PixelShader.h" />
<ClInclude Include="Section.h" />
<ClInclude Include="Structs.h" />
<ClInclude Include="Timer.h" />
<ClInclude Include="Topology.h" />
......
......@@ -34,6 +34,12 @@
<Filter Include="Source Files\Common">
<UniqueIdentifier>{aaf941b8-e05d-4faa-a18c-4ccb5206d8dc}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Scenes">
<UniqueIdentifier>{8d28f9c0-053d-4ed1-a72f-89bce089dc66}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Scenes">
<UniqueIdentifier>{8f6ea4b7-1762-4def-8d85-fc7cf5d7d9ed}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="WinMain.cpp">
......@@ -84,6 +90,12 @@
<ClCompile Include="Box.cpp">
<Filter>Source Files\Drawables</Filter>
</ClCompile>
<ClCompile Include="Section.cpp">
<Filter>Source Files\Scenes</Filter>
</ClCompile>
<ClCompile Include="Ground.cpp">
<Filter>Source Files\Scenes</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<FxCompile Include="PixelShader.hlsl">
......@@ -139,5 +151,11 @@
<ClInclude Include="Box.h">
<Filter>Header Files\Drawables</Filter>
</ClInclude>
<ClInclude Include="Section.h">
<Filter>Header Files\Scenes</Filter>
</ClInclude>
<ClInclude Include="Ground.h">
<Filter>Header Files\Scenes</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
#pragma once
#include "Section.h"
#include "Drawable.h"
void Section::SetCamera(
Logger& logger,
DirectX::XMVECTOR upDirection,
DirectX::XMVECTOR eyePosition,
DirectX::XMVECTOR focusPosition) noexcept
{
for (auto& shape : shapes)
{
shape->SetCamera(logger, upDirection, eyePosition, focusPosition);
}
};
void Section::DrawShapes(
Graphics& gfx,
Logger& logger) noexcept
{
for (auto& shape : shapes)
{
// shape->Update(dt); TODO
shape->ExecuteBind(gfx, logger);
shape->Draw(gfx, logger);
}
};
\ No newline at end of file
#pragma once
#include "Box.h"
#include <vector>
#include "Graphics.h"
#include "Logger.h"
#include "Drawable.h"
class Section
{
public:
Section() = default;
Section(const Section&) = delete;
void SetCamera(
Logger& logger,
DirectX::XMVECTOR upDirection,
DirectX::XMVECTOR eyePosition,
DirectX::XMVECTOR focusPosition) noexcept;
void DrawShapes(
Graphics& gfx,
Logger& logger) noexcept;
~Section() = default;
protected:
std::vector<std::unique_ptr<Drawable>> shapes;
};
\ No newline at end of file
......@@ -137,7 +137,6 @@ void Triangle::Update(float dt) noexcept
dz = dt;
}
DirectX::XMMATRIX Triangle::GetTransformXM() const noexcept
{
/*return DirectX::XMMatrixRotationRollPitchYaw(pitch, yaw, roll) *
......
......@@ -28,6 +28,8 @@ Logger logger("log.txt");
#include <cmath>
#include "Ground.h"
/************************************
* 1.1 CreateDeviceAndSwapChain
************************************/
......@@ -691,18 +693,6 @@ int WINAPI WinMain(HINSTANCE hInstance,
Graphics gfx(hWnd);
gfx.SetProjection(DirectX::XMMatrixPerspectiveLH(1.0f, 3.0f / 4.0f, 0.5f, 40.0f));
float triPos[3][3] =
{
{0.0f, 1.0f, -1.1f},
{1.0f, -1.0f, -1.1f},
{-1.0f, -1.0f, -1.1f}
};
float triCol[1][3] =
{
{1.0f, 0.2f, 0.0f}
};
Triangle tri(gfx, triPos, triCol, logger);
std::vector<std::unique_ptr<Box>> boxes;
for (int i = -5; i < 6; i++)
{
......@@ -740,6 +730,7 @@ int WINAPI WinMain(HINSTANCE hInstance,
boxes.push_back(std::make_unique<Box>(gfx, boxPos, boxCol, logger));
}
}
Ground ground(gfx, logger);
double seed = 0;
seed = int(seed) % 10000;
......@@ -772,24 +763,20 @@ int WINAPI WinMain(HINSTANCE hInstance,
gfx.RendorFrame();
seed++;
auto dt = sin(seed / 5000);
auto dt = sin(seed / 1000);
logger.PutLog("seed", std::to_string(seed));
logger.PutLog("dt", std::to_string(dt));
auto sinValue = sin(seed / 5000);
auto cosValue = cos(seed / 5000);
auto sinValue = sin(seed / 1000);
auto cosValue = cos(seed / 1000);
for (auto& box : boxes)
{
box->Update(dt);
box->UpdateCamera(sinValue, cosValue);
box->ExecuteBind(gfx, logger);
box->Draw(gfx, logger);
}
// Set camera
DirectX::XMVECTOR eyePosition = DirectX::XMVectorSet(20.0f * sinValue, 10.0f, -20.0f * cosValue, 1.0f);
DirectX::XMVECTOR focusPosition = DirectX::XMVectorZero();
DirectX::XMVECTOR upDirection = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f);
//tri.Update(dt);
//tri.ExecuteBind(gfx, logger);
//tri.Draw(gfx, logger);
ground.SetCamera(logger, eyePosition, focusPosition, upDirection);
ground.DrawShapes(gfx, logger);
gfx.EndFrame();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment