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
theta += dtheta * dt;
phi += dphi * dt;
chi += dchi * dt;*/
dx = dt;
dy = dt;
dz = dt;
//dx = dt;
//dy = 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
{
/*return DirectX::XMMatrixRotationRollPitchYaw(pitch, yaw, roll) *
......@@ -140,14 +148,6 @@ DirectX::XMMATRIX Box::GetTransformXM() const noexcept
DirectX::XMMatrixRotationRollPitchYaw(theta, phi, chi) *
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
DirectX::XMMatrixTranslation(dx, dy, dz)
* DirectX::XMMatrixLookAtLH(eyePosition, focusPosition, upDirection);
......
......@@ -7,6 +7,7 @@ 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;
DirectX::XMMATRIX GetTransformXM() const noexcept override;
private:
// positional
......@@ -17,4 +18,8 @@ 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
......@@ -703,25 +703,30 @@ int WINAPI WinMain(HINSTANCE hInstance,
};
Triangle tri(gfx, triPos, triCol, logger);
std::vector<std::unique_ptr<Box>> boxes;
for (int i = -5; i < 6; i++)
{
for (int j = -5; j < 6; j++)
{
float boxPos[8][3] =
{
// left bottom back
{ -1.0f, -1.0f, -1.0f },
{ -1.0f + i, -1.0f, -1.0f + j },
// right bottom back
{ 1.0f, -1.0f, -1.0f },
{ 1.0f + i, -1.0f, -1.0f + j },
// left top back
{ -1.0f, 1.0f, -1.0f },
{ -1.0f + i, 1.0f, -1.0f + j },
// right top back
{ 1.0f, 1.0f, -1.0f },
{ 1.0f + i, 1.0f, -1.0f + j },
// left bottom front
{ -1.0f, -1.0f, 1.0f },
{ -1.0f + i, -1.0f, 1.0f + j },
// right bottom front
{ 1.0f, -1.0f, 1.0f },
{ 1.0f + i, -1.0f, 1.0f + j },
// left top front
{ -1.0f, 1.0f, 1.0f },
{ -1.0f + i, 1.0f, 1.0f + j },
// right top front
{ 1.0f, 1.0f, 1.0f },
{ 1.0f + i, 1.0f, 1.0f + j },
};
float boxCol[6][3] =
{
......@@ -732,7 +737,9 @@ int WINAPI WinMain(HINSTANCE hInstance,
{ 0.0f, 1.0f, 1.0f }, // Cyan
{ 1.0f, 0.0f, 1.0f }, // Magenta
};
Box box(gfx, boxPos, boxCol, logger);
boxes.push_back(std::make_unique<Box>(gfx, boxPos, boxCol, logger));
}
}
double seed = 0;
seed = int(seed) % 10000;
......@@ -765,13 +772,20 @@ int WINAPI WinMain(HINSTANCE hInstance,
gfx.RendorFrame();
seed++;
auto dt = sin(seed / 2000);
auto dt = sin(seed / 5000);
logger.PutLog("seed", std::to_string(seed));
logger.PutLog("dt", std::to_string(dt));
box.Update(dt);
box.ExecuteBind(gfx, logger);
box.Draw(gfx, logger);
auto sinValue = sin(seed / 5000);
auto cosValue = cos(seed / 5000);
for (auto& box : boxes)
{
box->Update(dt);
box->UpdateCamera(sinValue, cosValue);
box->ExecuteBind(gfx, logger);
box->Draw(gfx, logger);
}
//tri.Update(dt);
//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