Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
hw3d
Commits
38ba0d3d
Commit
38ba0d3d
authored
Mar 03, 2019
by
chili
Browse files
skinned cube
parent
44b02568
Changes
7
Hide whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
38ba0d3d
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include "Pyramid.h"
#include "Pyramid.h"
#include "Box.h"
#include "Box.h"
#include "Sheet.h"
#include "Sheet.h"
#include "SkinnedBox.h"
#include <memory>
#include <memory>
#include <algorithm>
#include <algorithm>
#include "ChiliMath.h"
#include "ChiliMath.h"
...
@@ -46,6 +47,11 @@ App::App()
...
@@ -46,6 +47,11 @@ App::App()
gfx
,
rng
,
adist
,
ddist
,
gfx
,
rng
,
adist
,
ddist
,
odist
,
rdist
odist
,
rdist
);
);
case
4
:
return
std
::
make_unique
<
SkinnedBox
>
(
gfx
,
rng
,
adist
,
ddist
,
odist
,
rdist
);
default:
default:
assert
(
false
&&
"bad drawable type in factory"
);
assert
(
false
&&
"bad drawable type in factory"
);
return
{};
return
{};
...
@@ -61,12 +67,11 @@ App::App()
...
@@ -61,12 +67,11 @@ App::App()
std
::
uniform_real_distribution
<
float
>
bdist
{
0.4
f
,
3.0
f
};
std
::
uniform_real_distribution
<
float
>
bdist
{
0.4
f
,
3.0
f
};
std
::
uniform_int_distribution
<
int
>
latdist
{
5
,
20
};
std
::
uniform_int_distribution
<
int
>
latdist
{
5
,
20
};
std
::
uniform_int_distribution
<
int
>
longdist
{
10
,
40
};
std
::
uniform_int_distribution
<
int
>
longdist
{
10
,
40
};
std
::
uniform_int_distribution
<
int
>
typedist
{
0
,
3
};
std
::
uniform_int_distribution
<
int
>
typedist
{
0
,
4
};
};
};
Factory
f
(
wnd
.
Gfx
()
);
drawables
.
reserve
(
nDrawables
);
drawables
.
reserve
(
nDrawables
);
std
::
generate_n
(
std
::
back_inserter
(
drawables
),
nDrawables
,
f
);
std
::
generate_n
(
std
::
back_inserter
(
drawables
),
nDrawables
,
Factory
{
wnd
.
Gfx
()
}
);
wnd
.
Gfx
().
SetProjection
(
DirectX
::
XMMatrixPerspectiveLH
(
1.0
f
,
3.0
f
/
4.0
f
,
0.5
f
,
40.0
f
)
);
wnd
.
Gfx
().
SetProjection
(
DirectX
::
XMMatrixPerspectiveLH
(
1.0
f
,
3.0
f
/
4.0
f
,
0.5
f
,
40.0
f
)
);
}
}
...
...
hw3d/Cube.h
View file @
38ba0d3d
#pragma once
#pragma once
#include "IndexedTriangleList.h"
#include "IndexedTriangleList.h"
#include <DirectXMath.h>
#include <DirectXMath.h>
#include <initializer_list>
class
Cube
class
Cube
{
{
...
@@ -12,23 +13,18 @@ public:
...
@@ -12,23 +13,18 @@ public:
constexpr
float
side
=
1.0
f
/
2.0
f
;
constexpr
float
side
=
1.0
f
/
2.0
f
;
std
::
vector
<
dx
::
XMFLOAT3
>
vertices
;
std
::
vector
<
V
>
vertices
(
8
);
vertices
.
emplace_back
(
-
side
,
-
side
,
-
side
);
// 0
vertices
[
0
].
pos
=
{
-
side
,
-
side
,
-
side
};
vertices
.
emplace_back
(
side
,
-
side
,
-
side
);
// 1
vertices
[
1
].
pos
=
{
side
,
-
side
,
-
side
};
vertices
.
emplace_back
(
-
side
,
side
,
-
side
);
// 2
vertices
[
2
].
pos
=
{
-
side
,
side
,
-
side
};
vertices
.
emplace_back
(
side
,
side
,
-
side
);
// 3
vertices
[
3
].
pos
=
{
side
,
side
,
-
side
};
vertices
.
emplace_back
(
-
side
,
-
side
,
side
);
// 4
vertices
[
4
].
pos
=
{
-
side
,
-
side
,
side
};
vertices
.
emplace_back
(
side
,
-
side
,
side
);
// 5
vertices
[
5
].
pos
=
{
side
,
-
side
,
side
};
vertices
.
emplace_back
(
-
side
,
side
,
side
);
// 6
vertices
[
6
].
pos
=
{
-
side
,
side
,
side
};
vertices
.
emplace_back
(
side
,
side
,
side
);
// 7
vertices
[
7
].
pos
=
{
side
,
side
,
side
};
std
::
vector
<
V
>
verts
(
vertices
.
size
()
);
for
(
size_t
i
=
0
;
i
<
vertices
.
size
();
i
++
)
{
verts
[
i
].
pos
=
vertices
[
i
];
}
return
{
return
{
std
::
move
(
verts
),{
std
::
move
(
vert
ice
s
),{
0
,
2
,
1
,
2
,
3
,
1
,
0
,
2
,
1
,
2
,
3
,
1
,
1
,
3
,
5
,
3
,
7
,
5
,
1
,
3
,
5
,
3
,
7
,
5
,
2
,
6
,
3
,
3
,
6
,
7
,
2
,
6
,
3
,
3
,
6
,
7
,
...
@@ -38,4 +34,53 @@ public:
...
@@ -38,4 +34,53 @@ public:
}
}
};
};
}
}
template
<
class
V
>
static
IndexedTriangleList
<
V
>
MakeSkinned
()
{
namespace
dx
=
DirectX
;
constexpr
float
side
=
1.0
f
/
2.0
f
;
std
::
vector
<
V
>
vertices
(
14
);
vertices
[
0
].
pos
=
{
-
side
,
-
side
,
-
side
};
vertices
[
0
].
tex
=
{
2.0
f
/
3.0
f
,
0.0
f
/
4.0
f
};
vertices
[
1
].
pos
=
{
side
,
-
side
,
-
side
};
vertices
[
1
].
tex
=
{
1.0
f
/
3.0
f
,
0.0
f
/
4.0
f
};
vertices
[
2
].
pos
=
{
-
side
,
side
,
-
side
};
vertices
[
2
].
tex
=
{
2.0
f
/
3.0
f
,
1.0
f
/
4.0
f
};
vertices
[
3
].
pos
=
{
side
,
side
,
-
side
};
vertices
[
3
].
tex
=
{
1.0
f
/
3.0
f
,
1.0
f
/
4.0
f
};
vertices
[
4
].
pos
=
{
-
side
,
-
side
,
side
};
vertices
[
4
].
tex
=
{
2.0
f
/
3.0
f
,
3.0
f
/
4.0
f
};
vertices
[
5
].
pos
=
{
side
,
-
side
,
side
};
vertices
[
5
].
tex
=
{
1.0
f
/
3.0
f
,
3.0
f
/
4.0
f
};
vertices
[
6
].
pos
=
{
-
side
,
side
,
side
};
vertices
[
6
].
tex
=
{
2.0
f
/
3.0
f
,
2.0
f
/
4.0
f
};
vertices
[
7
].
pos
=
{
side
,
side
,
side
};
vertices
[
7
].
tex
=
{
1.0
f
/
3.0
f
,
2.0
f
/
4.0
f
};
vertices
[
8
].
pos
=
{
-
side
,
-
side
,
-
side
};
vertices
[
8
].
tex
=
{
2.0
f
/
3.0
f
,
4.0
f
/
4.0
f
};
vertices
[
9
].
pos
=
{
side
,
-
side
,
-
side
};
vertices
[
9
].
tex
=
{
1.0
f
/
3.0
f
,
4.0
f
/
4.0
f
};
vertices
[
10
].
pos
=
{
-
side
,
-
side
,
-
side
};
vertices
[
10
].
tex
=
{
3.0
f
/
3.0
f
,
1.0
f
/
4.0
f
};
vertices
[
11
].
pos
=
{
-
side
,
-
side
,
side
};
vertices
[
11
].
tex
=
{
3.0
f
/
3.0
f
,
2.0
f
/
4.0
f
};
vertices
[
12
].
pos
=
{
side
,
-
side
,
-
side
};
vertices
[
12
].
tex
=
{
0.0
f
/
3.0
f
,
1.0
f
/
4.0
f
};
vertices
[
13
].
pos
=
{
side
,
-
side
,
side
};
vertices
[
13
].
tex
=
{
0.0
f
/
3.0
f
,
2.0
f
/
4.0
f
};
return
{
std
::
move
(
vertices
),{
0
,
2
,
1
,
2
,
3
,
1
,
4
,
8
,
5
,
5
,
8
,
9
,
2
,
6
,
3
,
3
,
6
,
7
,
4
,
5
,
7
,
4
,
7
,
6
,
2
,
10
,
11
,
2
,
11
,
6
,
12
,
3
,
7
,
12
,
7
,
13
}
};
}
};
};
\ No newline at end of file
hw3d/Images/cube.png
0 → 100644
View file @
38ba0d3d
16.2 KB
hw3d/SkinnedBox.cpp
0 → 100644
View file @
38ba0d3d
#include "SkinnedBox.h"
#include "BindableBase.h"
#include "GraphicsThrowMacros.h"
#include "Cube.h"
#include "Surface.h"
#include "Texture.h"
SkinnedBox
::
SkinnedBox
(
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
)
:
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
;
struct
{
float
u
;
float
v
;
}
tex
;
};
const
auto
model
=
Cube
::
MakeSkinned
<
Vertex
>
();
AddStaticBind
(
std
::
make_unique
<
VertexBuffer
>
(
gfx
,
model
.
vertices
)
);
AddStaticBind
(
std
::
make_unique
<
Texture
>
(
gfx
,
Surface
::
FromFile
(
"Images
\\
cube.png"
)
)
);
auto
pvs
=
std
::
make_unique
<
VertexShader
>
(
gfx
,
L"TextureVS.cso"
);
auto
pvsbc
=
pvs
->
GetBytecode
();
AddStaticBind
(
std
::
move
(
pvs
)
);
AddStaticBind
(
std
::
make_unique
<
PixelShader
>
(
gfx
,
L"TexturePS.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
},
{
"TexCoord"
,
0
,
DXGI_FORMAT_R32G32_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
)
);
}
void
SkinnedBox
::
Update
(
float
dt
)
noexcept
{
roll
+=
droll
*
dt
;
pitch
+=
dpitch
*
dt
;
yaw
+=
dyaw
*
dt
;
theta
+=
dtheta
*
dt
;
phi
+=
dphi
*
dt
;
chi
+=
dchi
*
dt
;
}
DirectX
::
XMMATRIX
SkinnedBox
::
GetTransformXM
()
const
noexcept
{
namespace
dx
=
DirectX
;
return
dx
::
XMMatrixRotationRollPitchYaw
(
pitch
,
yaw
,
roll
)
*
dx
::
XMMatrixTranslation
(
r
,
0.0
f
,
0.0
f
)
*
dx
::
XMMatrixRotationRollPitchYaw
(
theta
,
phi
,
chi
)
*
dx
::
XMMatrixTranslation
(
0.0
f
,
0.0
f
,
20.0
f
);
}
hw3d/SkinnedBox.h
0 → 100644
View file @
38ba0d3d
#pragma once
#pragma once
#include "DrawableBase.h"
class
SkinnedBox
:
public
DrawableBase
<
SkinnedBox
>
{
public:
SkinnedBox
(
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
);
void
Update
(
float
dt
)
noexcept
override
;
DirectX
::
XMMATRIX
GetTransformXM
()
const
noexcept
override
;
private:
// positional
float
r
;
float
roll
=
0.0
f
;
float
pitch
=
0.0
f
;
float
yaw
=
0.0
f
;
float
theta
;
float
phi
;
float
chi
;
// speed (delta/s)
float
droll
;
float
dpitch
;
float
dyaw
;
float
dtheta
;
float
dphi
;
float
dchi
;
};
\ No newline at end of file
hw3d/hw3d.vcxproj
View file @
38ba0d3d
...
@@ -166,6 +166,7 @@
...
@@ -166,6 +166,7 @@
<ClCompile
Include=
"Pyramid.cpp"
/>
<ClCompile
Include=
"Pyramid.cpp"
/>
<ClCompile
Include=
"Sampler.cpp"
/>
<ClCompile
Include=
"Sampler.cpp"
/>
<ClCompile
Include=
"Sheet.cpp"
/>
<ClCompile
Include=
"Sheet.cpp"
/>
<ClCompile
Include=
"SkinnedBox.cpp"
/>
<ClCompile
Include=
"Surface.cpp"
/>
<ClCompile
Include=
"Surface.cpp"
/>
<ClCompile
Include=
"Texture.cpp"
/>
<ClCompile
Include=
"Texture.cpp"
/>
<ClCompile
Include=
"Topology.cpp"
/>
<ClCompile
Include=
"Topology.cpp"
/>
...
@@ -208,6 +209,7 @@
...
@@ -208,6 +209,7 @@
<ClInclude
Include=
"resource.h"
/>
<ClInclude
Include=
"resource.h"
/>
<ClInclude
Include=
"Sampler.h"
/>
<ClInclude
Include=
"Sampler.h"
/>
<ClInclude
Include=
"Sheet.h"
/>
<ClInclude
Include=
"Sheet.h"
/>
<ClInclude
Include=
"SkinnedBox.h"
/>
<ClInclude
Include=
"Sphere.h"
/>
<ClInclude
Include=
"Sphere.h"
/>
<ClInclude
Include=
"Surface.h"
/>
<ClInclude
Include=
"Surface.h"
/>
<ClInclude
Include=
"Texture.h"
/>
<ClInclude
Include=
"Texture.h"
/>
...
...
hw3d/hw3d.vcxproj.filters
View file @
38ba0d3d
...
@@ -123,6 +123,9 @@
...
@@ -123,6 +123,9 @@
<ClCompile
Include=
"Sampler.cpp"
>
<ClCompile
Include=
"Sampler.cpp"
>
<Filter>
Source Files\Bindable
</Filter>
<Filter>
Source Files\Bindable
</Filter>
</ClCompile>
</ClCompile>
<ClCompile
Include=
"SkinnedBox.cpp"
>
<Filter>
Source Files\Drawable
</Filter>
</ClCompile>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ClInclude
Include=
"WindowsMessageMap.h"
>
<ClInclude
Include=
"WindowsMessageMap.h"
>
...
@@ -248,6 +251,9 @@
...
@@ -248,6 +251,9 @@
<ClInclude
Include=
"Sampler.h"
>
<ClInclude
Include=
"Sampler.h"
>
<Filter>
Header Files\Bindable
</Filter>
<Filter>
Header Files\Bindable
</Filter>
</ClInclude>
</ClInclude>
<ClInclude
Include=
"SkinnedBox.h"
>
<Filter>
Header Files\Drawable
</Filter>
</ClInclude>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ResourceCompile
Include=
"hw3d.rc"
>
<ResourceCompile
Include=
"hw3d.rc"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment