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
99e15f43
Commit
99e15f43
authored
Aug 29, 2019
by
chili
Browse files
add nmap test cube / necessary changes
parent
27a08d83
Changes
9
Show whitespace changes
Inline
Side-by-side
hw3d/Cube.h
0 → 100644
View file @
99e15f43
#pragma once
#include <optional>
#include "Vertex.h"
#include "IndexedTriangleList.h"
#include <DirectXMath.h>
#include "ChiliMath.h"
#include <array>
class
Cube
{
public:
static
IndexedTriangleList
MakeIndependent
(
Dvtx
::
VertexLayout
layout
)
{
using
namespace
Dvtx
;
using
Type
=
Dvtx
::
VertexLayout
::
ElementType
;
constexpr
float
side
=
1.0
f
/
2.0
f
;
VertexBuffer
vertices
(
std
::
move
(
layout
),
24u
);
vertices
[
0
].
Attr
<
Type
::
Position3D
>
()
=
{
-
side
,
-
side
,
-
side
};
// 0 near side
vertices
[
1
].
Attr
<
Type
::
Position3D
>
()
=
{
side
,
-
side
,
-
side
};
// 1
vertices
[
2
].
Attr
<
Type
::
Position3D
>
()
=
{
-
side
,
side
,
-
side
};
// 2
vertices
[
3
].
Attr
<
Type
::
Position3D
>
()
=
{
side
,
side
,
-
side
};
// 3
vertices
[
4
].
Attr
<
Type
::
Position3D
>
()
=
{
-
side
,
-
side
,
side
};
// 4 far side
vertices
[
5
].
Attr
<
Type
::
Position3D
>
()
=
{
side
,
-
side
,
side
};
// 5
vertices
[
6
].
Attr
<
Type
::
Position3D
>
()
=
{
-
side
,
side
,
side
};
// 6
vertices
[
7
].
Attr
<
Type
::
Position3D
>
()
=
{
side
,
side
,
side
};
// 7
vertices
[
8
].
Attr
<
Type
::
Position3D
>
()
=
{
-
side
,
-
side
,
-
side
};
// 8 left side
vertices
[
9
].
Attr
<
Type
::
Position3D
>
()
=
{
-
side
,
side
,
-
side
};
// 9
vertices
[
10
].
Attr
<
Type
::
Position3D
>
()
=
{
-
side
,
-
side
,
side
};
// 10
vertices
[
11
].
Attr
<
Type
::
Position3D
>
()
=
{
-
side
,
side
,
side
};
// 11
vertices
[
12
].
Attr
<
Type
::
Position3D
>
()
=
{
side
,
-
side
,
-
side
};
// 12 right side
vertices
[
13
].
Attr
<
Type
::
Position3D
>
()
=
{
side
,
side
,
-
side
};
// 13
vertices
[
14
].
Attr
<
Type
::
Position3D
>
()
=
{
side
,
-
side
,
side
};
// 14
vertices
[
15
].
Attr
<
Type
::
Position3D
>
()
=
{
side
,
side
,
side
};
// 15
vertices
[
16
].
Attr
<
Type
::
Position3D
>
()
=
{
-
side
,
-
side
,
-
side
};
// 16 bottom side
vertices
[
17
].
Attr
<
Type
::
Position3D
>
()
=
{
side
,
-
side
,
-
side
};
// 17
vertices
[
18
].
Attr
<
Type
::
Position3D
>
()
=
{
-
side
,
-
side
,
side
};
// 18
vertices
[
19
].
Attr
<
Type
::
Position3D
>
()
=
{
side
,
-
side
,
side
};
// 19
vertices
[
20
].
Attr
<
Type
::
Position3D
>
()
=
{
-
side
,
side
,
-
side
};
// 20 top side
vertices
[
21
].
Attr
<
Type
::
Position3D
>
()
=
{
side
,
side
,
-
side
};
// 21
vertices
[
22
].
Attr
<
Type
::
Position3D
>
()
=
{
-
side
,
side
,
side
};
// 22
vertices
[
23
].
Attr
<
Type
::
Position3D
>
()
=
{
side
,
side
,
side
};
// 23
return
{
std
::
move
(
vertices
),{
0
,
2
,
1
,
2
,
3
,
1
,
4
,
5
,
7
,
4
,
7
,
6
,
8
,
10
,
9
,
10
,
11
,
9
,
12
,
13
,
15
,
12
,
15
,
14
,
16
,
17
,
18
,
18
,
17
,
19
,
20
,
23
,
21
,
20
,
22
,
23
}
};
}
static
IndexedTriangleList
MakeIndependentTextured
()
{
using
namespace
Dvtx
;
using
Type
=
Dvtx
::
VertexLayout
::
ElementType
;
auto
itl
=
MakeIndependent
(
std
::
move
(
VertexLayout
{}
.
Append
(
Type
::
Position3D
)
.
Append
(
Type
::
Normal
)
.
Append
(
Type
::
Texture2D
)
)
);
itl
.
vertices
[
0
].
Attr
<
Type
::
Texture2D
>
()
=
{
0.0
f
,
0.0
f
};
itl
.
vertices
[
1
].
Attr
<
Type
::
Texture2D
>
()
=
{
1.0
f
,
0.0
f
};
itl
.
vertices
[
2
].
Attr
<
Type
::
Texture2D
>
()
=
{
0.0
f
,
1.0
f
};
itl
.
vertices
[
3
].
Attr
<
Type
::
Texture2D
>
()
=
{
1.0
f
,
1.0
f
};
itl
.
vertices
[
4
].
Attr
<
Type
::
Texture2D
>
()
=
{
0.0
f
,
0.0
f
};
itl
.
vertices
[
5
].
Attr
<
Type
::
Texture2D
>
()
=
{
1.0
f
,
0.0
f
};
itl
.
vertices
[
6
].
Attr
<
Type
::
Texture2D
>
()
=
{
0.0
f
,
1.0
f
};
itl
.
vertices
[
7
].
Attr
<
Type
::
Texture2D
>
()
=
{
1.0
f
,
1.0
f
};
itl
.
vertices
[
8
].
Attr
<
Type
::
Texture2D
>
()
=
{
0.0
f
,
0.0
f
};
itl
.
vertices
[
9
].
Attr
<
Type
::
Texture2D
>
()
=
{
1.0
f
,
0.0
f
};
itl
.
vertices
[
10
].
Attr
<
Type
::
Texture2D
>
()
=
{
0.0
f
,
1.0
f
};
itl
.
vertices
[
11
].
Attr
<
Type
::
Texture2D
>
()
=
{
1.0
f
,
1.0
f
};
itl
.
vertices
[
12
].
Attr
<
Type
::
Texture2D
>
()
=
{
0.0
f
,
0.0
f
};
itl
.
vertices
[
13
].
Attr
<
Type
::
Texture2D
>
()
=
{
1.0
f
,
0.0
f
};
itl
.
vertices
[
14
].
Attr
<
Type
::
Texture2D
>
()
=
{
0.0
f
,
1.0
f
};
itl
.
vertices
[
15
].
Attr
<
Type
::
Texture2D
>
()
=
{
1.0
f
,
1.0
f
};
itl
.
vertices
[
16
].
Attr
<
Type
::
Texture2D
>
()
=
{
0.0
f
,
0.0
f
};
itl
.
vertices
[
17
].
Attr
<
Type
::
Texture2D
>
()
=
{
1.0
f
,
0.0
f
};
itl
.
vertices
[
18
].
Attr
<
Type
::
Texture2D
>
()
=
{
0.0
f
,
1.0
f
};
itl
.
vertices
[
19
].
Attr
<
Type
::
Texture2D
>
()
=
{
1.0
f
,
1.0
f
};
itl
.
vertices
[
20
].
Attr
<
Type
::
Texture2D
>
()
=
{
0.0
f
,
0.0
f
};
itl
.
vertices
[
21
].
Attr
<
Type
::
Texture2D
>
()
=
{
1.0
f
,
0.0
f
};
itl
.
vertices
[
22
].
Attr
<
Type
::
Texture2D
>
()
=
{
0.0
f
,
1.0
f
};
itl
.
vertices
[
23
].
Attr
<
Type
::
Texture2D
>
()
=
{
1.0
f
,
1.0
f
};
return
itl
;
}
};
\ No newline at end of file
hw3d/IndexedTriangleList.h
View file @
99e15f43
...
@@ -27,26 +27,26 @@ public:
...
@@ -27,26 +27,26 @@ public:
);
);
}
}
}
}
//// asserts face-independent vertices w/ normals cleared to zero
void
SetNormalsIndependentFlat
()
noxnd
//void SetNormalsIndependentFlat() noxnd
{
//{
using
namespace
DirectX
;
// using namespace DirectX;
using
Type
=
Dvtx
::
VertexLayout
::
ElementType
;
// for( size_t i = 0; i < indices.size(); i += 3 )
for
(
size_t
i
=
0
;
i
<
indices
.
size
();
i
+=
3
)
// {
{
// auto& v0 = vertices[indices[i]];
auto
v0
=
vertices
[
indices
[
i
]];
// auto& v1 = vertices[indices[i + 1]];
auto
v1
=
vertices
[
indices
[
i
+
1
]];
// auto& v2 = vertices[indices[i + 2]];
auto
v2
=
vertices
[
indices
[
i
+
2
]];
// const auto p0 = XMLoadFloat3( &v0.pos );
const
auto
p0
=
XMLoadFloat3
(
&
v0
.
Attr
<
Type
::
Position3D
>
()
);
// const auto p1 = XMLoadFloat3( &v1.pos );
const
auto
p1
=
XMLoadFloat3
(
&
v1
.
Attr
<
Type
::
Position3D
>
()
);
// const auto p2 = XMLoadFloat3( &v2.pos );
const
auto
p2
=
XMLoadFloat3
(
&
v2
.
Attr
<
Type
::
Position3D
>
()
);
const
auto
n
=
XMVector3Normalize
(
XMVector3Cross
(
(
p1
-
p0
),(
p2
-
p0
)
)
);
// const auto n = XMVector3Normalize( XMVector3Cross( (p1 - p0),(p2 - p0) ) );
XMStoreFloat3
(
&
v0
.
Attr
<
Type
::
Normal
>
(),
n
);
//
XMStoreFloat3
(
&
v1
.
Attr
<
Type
::
Normal
>
(),
n
);
// XMStoreFloat3( &v0.n,n );
XMStoreFloat3
(
&
v2
.
Attr
<
Type
::
Normal
>
(),
n
);
// XMStoreFloat3( &v1.n,n );
}
// XMStoreFloat3( &v2.n,n );
}
// }
//}
public:
public:
Dvtx
::
VertexBuffer
vertices
;
Dvtx
::
VertexBuffer
vertices
;
...
...
hw3d/Plane.h
View file @
99e15f43
...
@@ -16,8 +16,8 @@ public:
...
@@ -16,8 +16,8 @@ public:
assert
(
divisions_x
>=
1
);
assert
(
divisions_x
>=
1
);
assert
(
divisions_y
>=
1
);
assert
(
divisions_y
>=
1
);
constexpr
float
width
=
2
.0
f
;
constexpr
float
width
=
1
.0
f
;
constexpr
float
height
=
2
.0
f
;
constexpr
float
height
=
1
.0
f
;
const
int
nVertices_x
=
divisions_x
+
1
;
const
int
nVertices_x
=
divisions_x
+
1
;
const
int
nVertices_y
=
divisions_y
+
1
;
const
int
nVertices_y
=
divisions_y
+
1
;
Dvtx
::
VertexBuffer
vb
{
std
::
move
(
layout
)
};
Dvtx
::
VertexBuffer
vb
{
std
::
move
(
layout
)
};
...
...
hw3d/TestCube.cpp
0 → 100644
View file @
99e15f43
#include "TestCube.h"
#include "Cube.h"
#include "BindableCommon.h"
#include "TransformCbufDoubleboi.h"
#include "imgui/imgui.h"
TestCube
::
TestCube
(
Graphics
&
gfx
,
float
size
)
{
using
namespace
Bind
;
namespace
dx
=
DirectX
;
auto
model
=
Cube
::
MakeIndependentTextured
();
model
.
Transform
(
dx
::
XMMatrixScaling
(
size
,
size
,
size
)
);
model
.
SetNormalsIndependentFlat
();
const
auto
geometryTag
=
"$cube."
+
std
::
to_string
(
size
);
AddBind
(
VertexBuffer
::
Resolve
(
gfx
,
geometryTag
,
model
.
vertices
)
);
AddBind
(
IndexBuffer
::
Resolve
(
gfx
,
geometryTag
,
model
.
indices
)
);
AddBind
(
Texture
::
Resolve
(
gfx
,
"Images
\\
brickwall.jpg"
)
);
AddBind
(
Texture
::
Resolve
(
gfx
,
"Images
\\
brickwall_normal.jpg"
,
1u
)
);
auto
pvs
=
VertexShader
::
Resolve
(
gfx
,
"PhongVS.cso"
);
auto
pvsbc
=
pvs
->
GetBytecode
();
AddBind
(
std
::
move
(
pvs
)
);
AddBind
(
PixelShader
::
Resolve
(
gfx
,
"PhongPSNormalMap.cso"
)
);
AddBind
(
PixelConstantBuffer
<
PSMaterialConstant
>::
Resolve
(
gfx
,
pmc
,
1u
)
);
AddBind
(
InputLayout
::
Resolve
(
gfx
,
model
.
vertices
.
GetLayout
(),
pvsbc
)
);
AddBind
(
Topology
::
Resolve
(
gfx
,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST
)
);
AddBind
(
std
::
make_shared
<
TransformCbufDoubleboi
>
(
gfx
,
*
this
,
0u
,
2u
)
);
}
void
TestCube
::
SetPos
(
DirectX
::
XMFLOAT3
pos
)
noexcept
{
this
->
pos
=
pos
;
}
void
TestCube
::
SetRotation
(
float
roll
,
float
pitch
,
float
yaw
)
noexcept
{
this
->
roll
=
roll
;
this
->
pitch
=
pitch
;
this
->
yaw
=
yaw
;
}
DirectX
::
XMMATRIX
TestCube
::
GetTransformXM
()
const
noexcept
{
return
DirectX
::
XMMatrixRotationRollPitchYaw
(
roll
,
pitch
,
yaw
)
*
DirectX
::
XMMatrixTranslation
(
pos
.
x
,
pos
.
y
,
pos
.
z
);
}
void
TestCube
::
SpawnControlWindow
(
Graphics
&
gfx
)
noexcept
{
if
(
ImGui
::
Begin
(
"Cube"
)
)
{
ImGui
::
Text
(
"Position"
);
ImGui
::
SliderFloat
(
"X"
,
&
pos
.
x
,
-
80.0
f
,
80.0
f
,
"%.1f"
);
ImGui
::
SliderFloat
(
"Y"
,
&
pos
.
y
,
-
80.0
f
,
80.0
f
,
"%.1f"
);
ImGui
::
SliderFloat
(
"Z"
,
&
pos
.
z
,
-
80.0
f
,
80.0
f
,
"%.1f"
);
ImGui
::
Text
(
"Orientation"
);
ImGui
::
SliderAngle
(
"Roll"
,
&
roll
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Pitch"
,
&
pitch
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Yaw"
,
&
yaw
,
-
180.0
f
,
180.0
f
);
ImGui
::
Text
(
"Shading"
);
bool
changed0
=
ImGui
::
SliderFloat
(
"Spec. Int."
,
&
pmc
.
specularIntensity
,
0.0
f
,
1.0
f
);
bool
changed1
=
ImGui
::
SliderFloat
(
"Spec. Power"
,
&
pmc
.
specularPower
,
0.0
f
,
100.0
f
);
bool
checkState
=
pmc
.
normalMappingEnabled
==
TRUE
;
bool
changed2
=
ImGui
::
Checkbox
(
"Enable Normal Map"
,
&
checkState
);
pmc
.
normalMappingEnabled
=
checkState
?
TRUE
:
FALSE
;
if
(
changed0
||
changed1
||
changed2
)
{
QueryBindable
<
Bind
::
PixelConstantBuffer
<
PSMaterialConstant
>>
()
->
Update
(
gfx
,
pmc
);
}
}
ImGui
::
End
();
}
hw3d/TestCube.h
0 → 100644
View file @
99e15f43
#pragma once
#include "Drawable.h"
class
TestCube
:
public
Drawable
{
public:
TestCube
(
Graphics
&
gfx
,
float
size
);
void
SetPos
(
DirectX
::
XMFLOAT3
pos
)
noexcept
;
void
SetRotation
(
float
roll
,
float
pitch
,
float
yaw
)
noexcept
;
DirectX
::
XMMATRIX
GetTransformXM
()
const
noexcept
override
;
void
SpawnControlWindow
(
Graphics
&
gfx
)
noexcept
;
private:
struct
PSMaterialConstant
{
float
specularIntensity
=
0.1
f
;
float
specularPower
=
20.0
f
;
BOOL
normalMappingEnabled
=
TRUE
;
float
padding
[
1
];
}
pmc
;
DirectX
::
XMFLOAT3
pos
=
{
1.0
f
,
1.0
f
,
1.0
f
};
float
roll
=
0.0
f
;
float
pitch
=
0.0
f
;
float
yaw
=
0.0
f
;
};
\ No newline at end of file
hw3d/Vertex.cpp
View file @
99e15f43
...
@@ -146,10 +146,20 @@ namespace Dvtx
...
@@ -146,10 +146,20 @@ namespace Dvtx
// VertexBuffer
// VertexBuffer
VertexBuffer
::
VertexBuffer
(
VertexLayout
layout
)
noxnd
VertexBuffer
::
VertexBuffer
(
VertexLayout
layout
,
size_t
size
)
noxnd
:
:
layout
(
std
::
move
(
layout
)
)
layout
(
std
::
move
(
layout
)
)
{}
{
Resize
(
size
);
}
void
VertexBuffer
::
Resize
(
size_t
newSize
)
noxnd
{
const
auto
size
=
Size
();
if
(
size
<
newSize
)
{
buffer
.
resize
(
buffer
.
size
()
+
layout
.
Size
()
*
(
newSize
-
size
)
);
}
}
const
char
*
VertexBuffer
::
GetData
()
const
noxnd
const
char
*
VertexBuffer
::
GetData
()
const
noxnd
{
{
return
buffer
.
data
();
return
buffer
.
data
();
...
...
hw3d/Vertex.h
View file @
99e15f43
...
@@ -204,9 +204,10 @@ namespace Dvtx
...
@@ -204,9 +204,10 @@ namespace Dvtx
class
VertexBuffer
class
VertexBuffer
{
{
public:
public:
VertexBuffer
(
VertexLayout
layout
)
noxnd
;
VertexBuffer
(
VertexLayout
layout
,
size_t
size
=
0u
)
noxnd
;
const
char
*
GetData
()
const
noxnd
;
const
char
*
GetData
()
const
noxnd
;
const
VertexLayout
&
GetLayout
()
const
noexcept
;
const
VertexLayout
&
GetLayout
()
const
noexcept
;
void
Resize
(
size_t
newSize
)
noxnd
;
size_t
Size
()
const
noxnd
;
size_t
Size
()
const
noxnd
;
size_t
SizeBytes
()
const
noxnd
;
size_t
SizeBytes
()
const
noxnd
;
template
<
typename
...
Params
>
template
<
typename
...
Params
>
...
...
hw3d/hw3d.vcxproj
View file @
99e15f43
...
@@ -118,6 +118,7 @@
...
@@ -118,6 +118,7 @@
<ClCompile
Include=
"Sampler.cpp"
/>
<ClCompile
Include=
"Sampler.cpp"
/>
<ClCompile
Include=
"SolidSphere.cpp"
/>
<ClCompile
Include=
"SolidSphere.cpp"
/>
<ClCompile
Include=
"Surface.cpp"
/>
<ClCompile
Include=
"Surface.cpp"
/>
<ClCompile
Include=
"TestCube.cpp"
/>
<ClCompile
Include=
"TestPlane.cpp"
/>
<ClCompile
Include=
"TestPlane.cpp"
/>
<ClCompile
Include=
"Texture.cpp"
/>
<ClCompile
Include=
"Texture.cpp"
/>
<ClCompile
Include=
"Topology.cpp"
/>
<ClCompile
Include=
"Topology.cpp"
/>
...
@@ -143,6 +144,8 @@
...
@@ -143,6 +144,8 @@
<ClInclude
Include=
"Color.h"
/>
<ClInclude
Include=
"Color.h"
/>
<ClInclude
Include=
"ConditionalNoexcept.h"
/>
<ClInclude
Include=
"ConditionalNoexcept.h"
/>
<ClInclude
Include=
"ConstantBuffers.h"
/>
<ClInclude
Include=
"ConstantBuffers.h"
/>
<ClInclude
Include=
"Cube.h"
/>
<ClInclude
Include=
"TestCube.h"
/>
<ClInclude
Include=
"Drawable.h"
/>
<ClInclude
Include=
"Drawable.h"
/>
<ClInclude
Include=
"dxerr.h"
/>
<ClInclude
Include=
"dxerr.h"
/>
<ClInclude
Include=
"DxgiInfoManager.h"
/>
<ClInclude
Include=
"DxgiInfoManager.h"
/>
...
...
hw3d/hw3d.vcxproj.filters
View file @
99e15f43
...
@@ -156,6 +156,9 @@
...
@@ -156,6 +156,9 @@
<ClCompile
Include=
"TransformCbufDoubleboi.cpp"
>
<ClCompile
Include=
"TransformCbufDoubleboi.cpp"
>
<Filter>
Source Files\Bindable
</Filter>
<Filter>
Source Files\Bindable
</Filter>
</ClCompile>
</ClCompile>
<ClCompile
Include=
"TestCube.cpp"
>
<Filter>
Source Files\Drawable
</Filter>
</ClCompile>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ClInclude
Include=
"WindowsMessageMap.h"
>
<ClInclude
Include=
"WindowsMessageMap.h"
>
...
@@ -314,6 +317,12 @@
...
@@ -314,6 +317,12 @@
<ClInclude
Include=
"TransformCbufDoubleboi.h"
>
<ClInclude
Include=
"TransformCbufDoubleboi.h"
>
<Filter>
Header Files\Bindable
</Filter>
<Filter>
Header Files\Bindable
</Filter>
</ClInclude>
</ClInclude>
<ClInclude
Include=
"Cube.h"
>
<Filter>
Header Files\Geometry
</Filter>
</ClInclude>
<ClInclude
Include=
"TestCube.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