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
b3fc5123
Commit
b3fc5123
authored
May 12, 2019
by
chili
Browse files
basic ass test w/ drawable
parent
0d9e4a84
Changes
5
Hide whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
b3fc5123
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include "Cylinder.h"
#include "Cylinder.h"
#include "Pyramid.h"
#include "Pyramid.h"
#include "SkinnedBox.h"
#include "SkinnedBox.h"
#include "AssTest.h"
#include <memory>
#include <memory>
#include <algorithm>
#include <algorithm>
#include "ChiliMath.h"
#include "ChiliMath.h"
...
@@ -22,12 +23,6 @@ App::App()
...
@@ -22,12 +23,6 @@ App::App()
wnd
(
800
,
600
,
"The Donkey Fart Box"
),
wnd
(
800
,
600
,
"The Donkey Fart Box"
),
light
(
wnd
.
Gfx
()
)
light
(
wnd
.
Gfx
()
)
{
{
Assimp
::
Importer
imp
;
auto
model
=
imp
.
ReadFile
(
"models
\\
suzanne.obj"
,
aiProcess_Triangulate
|
aiProcess_JoinIdenticalVertices
);
class
Factory
class
Factory
{
{
public:
public:
...
@@ -61,6 +56,11 @@ App::App()
...
@@ -61,6 +56,11 @@ App::App()
gfx
,
rng
,
adist
,
ddist
,
gfx
,
rng
,
adist
,
ddist
,
odist
,
rdist
odist
,
rdist
);
);
case
4
:
return
std
::
make_unique
<
AssTest
>
(
gfx
,
rng
,
adist
,
ddist
,
odist
,
rdist
,
mat
,
1.5
f
);
default:
default:
assert
(
false
&&
"impossible drawable option in factory"
);
assert
(
false
&&
"impossible drawable option in factory"
);
return
{};
return
{};
...
@@ -69,7 +69,7 @@ App::App()
...
@@ -69,7 +69,7 @@ App::App()
private:
private:
Graphics
&
gfx
;
Graphics
&
gfx
;
std
::
mt19937
rng
{
std
::
random_device
{}()
};
std
::
mt19937
rng
{
std
::
random_device
{}()
};
std
::
uniform_int_distribution
<
int
>
sdist
{
0
,
3
};
std
::
uniform_int_distribution
<
int
>
sdist
{
0
,
4
};
std
::
uniform_real_distribution
<
float
>
adist
{
0.0
f
,
PI
*
2.0
f
};
std
::
uniform_real_distribution
<
float
>
adist
{
0.0
f
,
PI
*
2.0
f
};
std
::
uniform_real_distribution
<
float
>
ddist
{
0.0
f
,
PI
*
0.5
f
};
std
::
uniform_real_distribution
<
float
>
ddist
{
0.0
f
,
PI
*
0.5
f
};
std
::
uniform_real_distribution
<
float
>
odist
{
0.0
f
,
PI
*
0.08
f
};
std
::
uniform_real_distribution
<
float
>
odist
{
0.0
f
,
PI
*
0.08
f
};
...
...
hw3d/AssTest.cpp
0 → 100644
View file @
b3fc5123
#include "AssTest.h"
#include "BindableBase.h"
#include "GraphicsThrowMacros.h"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
AssTest
::
AssTest
(
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
,
DirectX
::
XMFLOAT3
material
,
float
scale
)
:
TestObject
(
gfx
,
rng
,
adist
,
ddist
,
odist
,
rdist
)
{
namespace
dx
=
DirectX
;
if
(
!
IsStaticInitialized
()
)
{
struct
Vertex
{
dx
::
XMFLOAT3
pos
;
dx
::
XMFLOAT3
n
;
};
Assimp
::
Importer
imp
;
const
auto
pModel
=
imp
.
ReadFile
(
"models
\\
suzanne.obj"
,
aiProcess_Triangulate
|
aiProcess_JoinIdenticalVertices
);
const
auto
pMesh
=
pModel
->
mMeshes
[
0
];
std
::
vector
<
Vertex
>
vertices
;
vertices
.
reserve
(
pMesh
->
mNumVertices
);
for
(
unsigned
int
i
=
0
;
i
<
pMesh
->
mNumVertices
;
i
++
)
{
vertices
.
push_back
(
{
{
pMesh
->
mVertices
[
i
].
x
*
scale
,
pMesh
->
mVertices
[
i
].
y
*
scale
,
pMesh
->
mVertices
[
i
].
z
*
scale
},
*
reinterpret_cast
<
dx
::
XMFLOAT3
*>
(
&
pMesh
->
mNormals
[
i
])
}
);
}
std
::
vector
<
unsigned
short
>
indices
;
indices
.
reserve
(
pMesh
->
mNumFaces
*
3
);
for
(
unsigned
int
i
=
0
;
i
<
pMesh
->
mNumFaces
;
i
++
)
{
const
auto
&
face
=
pMesh
->
mFaces
[
i
];
assert
(
face
.
mNumIndices
==
3
);
indices
.
push_back
(
face
.
mIndices
[
0
]
);
indices
.
push_back
(
face
.
mIndices
[
1
]
);
indices
.
push_back
(
face
.
mIndices
[
2
]
);
}
AddStaticBind
(
std
::
make_unique
<
VertexBuffer
>
(
gfx
,
vertices
)
);
AddStaticIndexBuffer
(
std
::
make_unique
<
IndexBuffer
>
(
gfx
,
indices
)
);
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"
)
);
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
)
);
struct
PSMaterialConstant
{
DirectX
::
XMFLOAT3
color
;
float
specularIntensity
=
0.6
f
;
float
specularPower
=
30.0
f
;
float
padding
[
3
];
}
pmc
;
pmc
.
color
=
material
;
AddStaticBind
(
std
::
make_unique
<
PixelConstantBuffer
<
PSMaterialConstant
>>
(
gfx
,
pmc
,
1u
)
);
}
else
{
SetIndexFromStatic
();
}
AddBind
(
std
::
make_unique
<
TransformCbuf
>
(
gfx
,
*
this
)
);
}
hw3d/AssTest.h
0 → 100644
View file @
b3fc5123
#pragma once
#include "TestObject.h"
#include "ConstantBuffers.h"
class
AssTest
:
public
TestObject
<
AssTest
>
{
public:
AssTest
(
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
,
DirectX
::
XMFLOAT3
material
,
float
scale
);
};
\ No newline at end of file
hw3d/hw3d.vcxproj
View file @
b3fc5123
...
@@ -92,6 +92,7 @@
...
@@ -92,6 +92,7 @@
</ItemDefinitionGroup>
</ItemDefinitionGroup>
<ItemGroup>
<ItemGroup>
<ClCompile
Include=
"App.cpp"
/>
<ClCompile
Include=
"App.cpp"
/>
<ClCompile
Include=
"AssTest.cpp"
/>
<ClCompile
Include=
"Bindable.cpp"
/>
<ClCompile
Include=
"Bindable.cpp"
/>
<ClCompile
Include=
"Box.cpp"
/>
<ClCompile
Include=
"Box.cpp"
/>
<ClCompile
Include=
"Camera.cpp"
/>
<ClCompile
Include=
"Camera.cpp"
/>
...
@@ -133,6 +134,7 @@
...
@@ -133,6 +134,7 @@
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ClInclude
Include=
"App.h"
/>
<ClInclude
Include=
"App.h"
/>
<ClInclude
Include=
"AssTest.h"
/>
<ClInclude
Include=
"Bindable.h"
/>
<ClInclude
Include=
"Bindable.h"
/>
<ClInclude
Include=
"BindableBase.h"
/>
<ClInclude
Include=
"BindableBase.h"
/>
<ClInclude
Include=
"Box.h"
/>
<ClInclude
Include=
"Box.h"
/>
...
...
hw3d/hw3d.vcxproj.filters
View file @
b3fc5123
...
@@ -159,6 +159,9 @@
...
@@ -159,6 +159,9 @@
<ClCompile
Include=
"Cylinder.cpp"
>
<ClCompile
Include=
"Cylinder.cpp"
>
<Filter>
Source Files\Drawable
</Filter>
<Filter>
Source Files\Drawable
</Filter>
</ClCompile>
</ClCompile>
<ClCompile
Include=
"AssTest.cpp"
>
<Filter>
Source Files\Drawable
</Filter>
</ClCompile>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ClInclude
Include=
"WindowsMessageMap.h"
>
<ClInclude
Include=
"WindowsMessageMap.h"
>
...
@@ -320,6 +323,9 @@
...
@@ -320,6 +323,9 @@
<ClInclude
Include=
"Cylinder.h"
>
<ClInclude
Include=
"Cylinder.h"
>
<Filter>
Header Files\Drawable
</Filter>
<Filter>
Header Files\Drawable
</Filter>
</ClInclude>
</ClInclude>
<ClInclude
Include=
"AssTest.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