Commit 140b1eca authored by Administrator's avatar Administrator
Browse files

made camera moving. init multiple boxes.

parent 0f114ee2
...@@ -128,11 +128,19 @@ void Box::Update(float dt) noexcept ...@@ -128,11 +128,19 @@ void Box::Update(float dt) noexcept
theta += dtheta * dt; theta += dtheta * dt;
phi += dphi * dt; phi += dphi * dt;
chi += dchi * dt;*/ chi += dchi * dt;*/
dx = dt; //dx = dt;
dy = dt; //dy = dt;
dz = dt; //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);
};
DirectX::XMMATRIX Box::GetTransformXM() const noexcept DirectX::XMMATRIX Box::GetTransformXM() const noexcept
{ {
/*return DirectX::XMMatrixRotationRollPitchYaw(pitch, yaw, roll) * /*return DirectX::XMMatrixRotationRollPitchYaw(pitch, yaw, roll) *
...@@ -140,14 +148,6 @@ DirectX::XMMATRIX Box::GetTransformXM() const noexcept ...@@ -140,14 +148,6 @@ DirectX::XMMATRIX Box::GetTransformXM() const noexcept
DirectX::XMMatrixRotationRollPitchYaw(theta, phi, chi) * DirectX::XMMatrixRotationRollPitchYaw(theta, phi, chi) *
DirectX::XMMatrixTranslation(0.0f, 0.0f, 20.0f);*/ DirectX::XMMatrixTranslation(0.0f, 0.0f, 20.0f);*/
using namespace DirectX;
XMVECTOR upDirection, eyePosition, focusPosition;
// Setup the vector that points upwards.
upDirection = XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f);
focusPosition = XMVectorZero();
eyePosition = XMVectorSet(5.0f, 5.0f, -5.0f, 1.0f);
return return
DirectX::XMMatrixTranslation(dx, dy, dz) DirectX::XMMatrixTranslation(dx, dy, dz)
* DirectX::XMMatrixLookAtLH(eyePosition, focusPosition, upDirection); * DirectX::XMMatrixLookAtLH(eyePosition, focusPosition, upDirection);
......
...@@ -7,6 +7,7 @@ class Box : public Drawable ...@@ -7,6 +7,7 @@ class Box : public Drawable
public: public:
Box(Graphics& gfx, float position[][3], float color[][3], Logger& logger); Box(Graphics& gfx, float position[][3], float color[][3], Logger& logger);
void Update(float dt) noexcept override; void Update(float dt) noexcept override;
void UpdateCamera(float sin, float cos) noexcept;
DirectX::XMMATRIX GetTransformXM() const noexcept override; DirectX::XMMATRIX GetTransformXM() const noexcept override;
private: private:
// positional // positional
...@@ -17,4 +18,8 @@ private: ...@@ -17,4 +18,8 @@ private:
float dx = 0.0f; float dx = 0.0f;
float dy = 0.0f; float dy = 0.0f;
float dz = 0.0f; float dz = 0.0f;
// for camera
DirectX::XMVECTOR upDirection;
DirectX::XMVECTOR eyePosition;
DirectX::XMVECTOR focusPosition;
}; };
\ No newline at end of file
...@@ -703,36 +703,43 @@ int WINAPI WinMain(HINSTANCE hInstance, ...@@ -703,36 +703,43 @@ int WINAPI WinMain(HINSTANCE hInstance,
}; };
Triangle tri(gfx, triPos, triCol, logger); Triangle tri(gfx, triPos, triCol, logger);
float boxPos[8][3] = std::vector<std::unique_ptr<Box>> boxes;
for (int i = -5; i < 6; i++)
{ {
// left bottom back for (int j = -5; j < 6; j++)
{ -1.0f, -1.0f, -1.0f }, {
// right bottom back float boxPos[8][3] =
{ 1.0f, -1.0f, -1.0f }, {
// left top back // left bottom back
{ -1.0f, 1.0f, -1.0f }, { -1.0f + i, -1.0f, -1.0f + j },
// right top back // right bottom back
{ 1.0f, 1.0f, -1.0f }, { 1.0f + i, -1.0f, -1.0f + j },
// left top back
// left bottom front { -1.0f + i, 1.0f, -1.0f + j },
{ -1.0f, -1.0f, 1.0f }, // right top back
// right bottom front { 1.0f + i, 1.0f, -1.0f + j },
{ 1.0f, -1.0f, 1.0f },
// left top front // left bottom front
{ -1.0f, 1.0f, 1.0f }, { -1.0f + i, -1.0f, 1.0f + j },
// right top front // right bottom front
{ 1.0f, 1.0f, 1.0f }, { 1.0f + i, -1.0f, 1.0f + j },
}; // left top front
float boxCol[6][3] = { -1.0f + i, 1.0f, 1.0f + j },
{ // right top front
{ 0.0f, 1.0f, 0.0f }, // Green { 1.0f + i, 1.0f, 1.0f + j },
{ 1.0f, 1.0f, 0.0f }, // Yellow };
{ 1.0f, 0.0f, 0.0f }, // Red float boxCol[6][3] =
{ 0.0f, 0.0f, 1.0f }, // Blue {
{ 0.0f, 1.0f, 1.0f }, // Cyan { 0.0f, 1.0f, 0.0f }, // Green
{ 1.0f, 0.0f, 1.0f }, // Magenta { 1.0f, 1.0f, 0.0f }, // Yellow
}; { 1.0f, 0.0f, 0.0f }, // Red
Box box(gfx, boxPos, boxCol, logger); { 0.0f, 0.0f, 1.0f }, // Blue
{ 0.0f, 1.0f, 1.0f }, // Cyan
{ 1.0f, 0.0f, 1.0f }, // Magenta
};
boxes.push_back(std::make_unique<Box>(gfx, boxPos, boxCol, logger));
}
}
double seed = 0; double seed = 0;
seed = int(seed) % 10000; seed = int(seed) % 10000;
...@@ -765,13 +772,20 @@ int WINAPI WinMain(HINSTANCE hInstance, ...@@ -765,13 +772,20 @@ int WINAPI WinMain(HINSTANCE hInstance,
gfx.RendorFrame(); gfx.RendorFrame();
seed++; seed++;
auto dt = sin(seed / 2000); auto dt = sin(seed / 5000);
logger.PutLog("seed", std::to_string(seed)); logger.PutLog("seed", std::to_string(seed));
logger.PutLog("dt", std::to_string(dt)); logger.PutLog("dt", std::to_string(dt));
box.Update(dt); auto sinValue = sin(seed / 5000);
box.ExecuteBind(gfx, logger); auto cosValue = cos(seed / 5000);
box.Draw(gfx, logger);
for (auto& box : boxes)
{
box->Update(dt);
box->UpdateCamera(sinValue, cosValue);
box->ExecuteBind(gfx, logger);
box->Draw(gfx, logger);
}
//tri.Update(dt); //tri.Update(dt);
//tri.ExecuteBind(gfx, logger); //tri.ExecuteBind(gfx, logger);
......
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