-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBox.cpp
More file actions
89 lines (76 loc) · 2.18 KB
/
Box.cpp
File metadata and controls
89 lines (76 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "Box.h"
#include "VoxaNovusBindableBase.h"
#include "VoxaNovusGfxExceptionMacros.h"
#include "Cube.h"
namespace dx = DirectX;
Box::Box(Graphics& gfx,
std::mt19937& rng,
std::uniform_real_distribution<float>& adist,
std::uniform_real_distribution<float>& ddist,
std::uniform_real_distribution<float>& odist,
std::uniform_real_distribution<float>& rdist,
std::uniform_real_distribution<float>& bdist)
:
r(rdist(rng)),
droll(ddist(rng)),
dpitch(ddist(rng)),
dyaw(ddist(rng)),
dphi(odist(rng)),
dtheta(odist(rng)),
dchi(odist(rng)),
chi(adist(rng)),
theta(adist(rng)),
phi(adist(rng))
{
namespace dx = DirectX;
if (!IsStaticInitialized())
{
struct Vertex
{
dx::XMFLOAT3 pos;
dx::XMFLOAT3 n;
};
auto model = Cube::MakeIndependent<Vertex>();
model.SetNormalsIndependentFlat();
AddStaticBind(std::make_unique<VertexBuffer>(gfx, model.vertices));
auto pvs = std::make_unique<VertexShader>(gfx, L"PhongVS.cso");
auto pvsbc = pvs->GetBytecode();
AddStaticBind(std::move(pvs));
AddStaticBind(std::make_unique<PixelShader>(gfx, L"PhongPS.cso"));
AddStaticIndexBuffer(std::make_unique<IndexBuffer>(gfx, model.indices));
const std::vector<D3D11_INPUT_ELEMENT_DESC> ied =
{
{ "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
{ "Normal",0,DXGI_FORMAT_R32G32B32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0 },
};
AddStaticBind(std::make_unique<InputLayout>(gfx, ied, pvsbc));
AddStaticBind(std::make_unique<Topology>(gfx, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST));
}
else
{
SetIndexFromStatic();
}
AddBind(std::make_unique<TransformCbuf>(gfx, *this));
// model deformation transform (per instance, not stored as bind)
dx::XMStoreFloat3x3(
&mt,
dx::XMMatrixScaling(1.0f, 1.0f, bdist(rng))
);
}
void Box::Update(float dt) noexcept
{
roll += droll * dt;
pitch += dpitch * dt;
yaw += dyaw * dt;
theta += dtheta * dt;
phi += dphi * dt;
chi += dchi * dt;
}
DirectX::XMMATRIX Box::GetTransformXM() const noexcept
{
namespace dx = DirectX;
return dx::XMLoadFloat3x3(&mt) *
dx::XMMatrixRotationRollPitchYaw(pitch, yaw, roll) *
dx::XMMatrixTranslation(r, 0.0f, 0.0f) *
dx::XMMatrixRotationRollPitchYaw(theta, phi, chi);
}