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
f298a1ac
Commit
f298a1ac
authored
Aug 04, 2019
by
chili
Browse files
basic plane, doesn't work ;(
parent
2526ae6c
Changes
9
Show whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
f298a1ac
...
...
@@ -14,8 +14,10 @@ GDIPlusManager gdipm;
App
::
App
()
:
wnd
(
1280
,
720
,
"The Donkey Fart Box"
),
light
(
wnd
.
Gfx
()
)
light
(
wnd
.
Gfx
()
),
plane
(
wnd
.
Gfx
(),
3.0
f
)
{
plane
.
SetPos
(
{
1.0
f
,
17.0
f
,
-
1.0
f
}
);
wnd
.
Gfx
().
SetProjection
(
dx
::
XMMatrixPerspectiveLH
(
1.0
f
,
9.0
f
/
16.0
f
,
0.5
f
,
40.0
f
)
);
}
...
...
@@ -29,6 +31,7 @@ void App::DoFrame()
nano
.
Draw
(
wnd
.
Gfx
()
);
nano2
.
Draw
(
wnd
.
Gfx
()
);
light
.
Draw
(
wnd
.
Gfx
()
);
plane
.
Draw
(
wnd
.
Gfx
()
);
while
(
const
auto
e
=
wnd
.
kbd
.
ReadKey
()
)
{
...
...
hw3d/App.h
View file @
f298a1ac
...
...
@@ -4,6 +4,7 @@
#include "ImguiManager.h"
#include "Camera.h"
#include "PointLight.h"
#include "TestPlane.h"
#include "Mesh.h"
#include <set>
...
...
@@ -27,4 +28,5 @@ private:
PointLight
light
;
Model
nano
{
wnd
.
Gfx
(),
"Models
\\
nano_textured
\\
nanosuit.obj"
};
Model
nano2
{
wnd
.
Gfx
(),
"Models
\\
nano_textured
\\
nanosuit.obj"
};
TestPlane
plane
;
};
\ No newline at end of file
hw3d/Images/brickwall.jpg
0 → 100644
View file @
f298a1ac
194 KB
hw3d/Images/brickwall_normal.jpg
0 → 100644
View file @
f298a1ac
559 KB
hw3d/Plane.h
0 → 100644
View file @
f298a1ac
#pragma once
#include <optional>
#include "Vertex.h"
#include "IndexedTriangleList.h"
#include <DirectXMath.h>
#include "ChiliMath.h"
#include <array>
class
Plane
{
public:
static
IndexedTriangleList
MakeTesselatedTextured
(
Dvtx
::
VertexLayout
layout
,
int
divisions_x
,
int
divisions_y
)
{
namespace
dx
=
DirectX
;
assert
(
divisions_x
>=
1
);
assert
(
divisions_y
>=
1
);
constexpr
float
width
=
2.0
f
;
constexpr
float
height
=
2.0
f
;
const
int
nVertices_x
=
divisions_x
+
1
;
const
int
nVertices_y
=
divisions_y
+
1
;
Dvtx
::
VertexBuffer
vb
{
std
::
move
(
layout
)
};
{
const
float
side_x
=
width
/
2.0
f
;
const
float
side_y
=
height
/
2.0
f
;
const
float
divisionSize_x
=
width
/
float
(
divisions_x
);
const
float
divisionSize_y
=
height
/
float
(
divisions_y
);
const
float
divisionSize_x_tc
=
1.0
f
/
float
(
divisions_x
);
const
float
divisionSize_y_tc
=
1.0
f
/
float
(
divisions_y
);
for
(
int
y
=
0
,
i
=
0
;
y
<
nVertices_y
;
y
++
)
{
const
float
y_pos
=
float
(
y
)
*
divisionSize_y
-
1.0
f
;
const
float
y_pos_tc
=
1.0
f
-
float
(
y
)
*
divisionSize_y_tc
;
for
(
int
x
=
0
;
x
<
nVertices_x
;
x
++
,
i
++
)
{
const
float
x_pos
=
float
(
x
)
*
divisionSize_x
-
1.0
f
;
const
float
x_pos_tc
=
float
(
x
)
*
divisionSize_x_tc
;
vb
.
EmplaceBack
(
dx
::
XMFLOAT3
{
x_pos
,
y_pos
,
0.0
f
},
dx
::
XMFLOAT3
{
0.0
f
,
0.0
f
,
1.0
f
},
dx
::
XMFLOAT2
{
x_pos_tc
,
y_pos_tc
}
);
}
}
}
std
::
vector
<
unsigned
short
>
indices
;
indices
.
reserve
(
sq
(
divisions_x
*
divisions_y
)
*
6
);
{
const
auto
vxy2i
=
[
nVertices_x
](
size_t
x
,
size_t
y
)
{
return
(
unsigned
short
)(
y
*
nVertices_x
+
x
);
};
for
(
size_t
y
=
0
;
y
<
divisions_y
;
y
++
)
{
for
(
size_t
x
=
0
;
x
<
divisions_x
;
x
++
)
{
const
std
::
array
<
unsigned
short
,
4
>
indexArray
=
{
vxy2i
(
x
,
y
),
vxy2i
(
x
+
1
,
y
),
vxy2i
(
x
,
y
+
1
),
vxy2i
(
x
+
1
,
y
+
1
)
};
indices
.
push_back
(
indexArray
[
0
]
);
indices
.
push_back
(
indexArray
[
2
]
);
indices
.
push_back
(
indexArray
[
1
]
);
indices
.
push_back
(
indexArray
[
1
]
);
indices
.
push_back
(
indexArray
[
2
]
);
indices
.
push_back
(
indexArray
[
3
]
);
}
}
}
return
{
std
::
move
(
vb
),
std
::
move
(
indices
)
};
}
static
IndexedTriangleList
Make
()
{
using
Dvtx
::
VertexLayout
;
VertexLayout
vl
;
vl
.
Append
(
VertexLayout
::
Position3D
);
vl
.
Append
(
VertexLayout
::
Normal
);
vl
.
Append
(
VertexLayout
::
Texture2D
);
return
MakeTesselatedTextured
(
std
::
move
(
vl
),
1
,
1
);
}
};
hw3d/TestPlane.cpp
0 → 100644
View file @
f298a1ac
#include "TestPlane.h"
#include "Plane.h"
#include "BindableCommon.h"
TestPlane
::
TestPlane
(
Graphics
&
gfx
,
float
size
)
{
using
namespace
Bind
;
namespace
dx
=
DirectX
;
auto
model
=
Plane
::
Make
();
model
.
Transform
(
dx
::
XMMatrixScaling
(
size
,
size
,
1.0
f
)
);
const
auto
geometryTag
=
"$plane."
+
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"
)
);
auto
pvs
=
VertexShader
::
Resolve
(
gfx
,
"PhongVS.cso"
);
auto
pvsbc
=
pvs
->
GetBytecode
();
AddBind
(
std
::
move
(
pvs
)
);
AddBind
(
PixelShader
::
Resolve
(
gfx
,
"PhongPS.cso"
)
);
struct
PSMaterialConstant
{
float
specularIntensity
=
0.8
f
;
float
specularPower
=
45.0
f
;
float
padding
[
2
];
}
pmc
;
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
<
TransformCbuf
>
(
gfx
,
*
this
)
);
}
void
TestPlane
::
SetPos
(
DirectX
::
XMFLOAT3
pos
)
noexcept
{
this
->
pos
=
pos
;
}
void
TestPlane
::
SetRotation
(
float
roll
,
float
pitch
,
float
yaw
)
noexcept
{
this
->
roll
=
roll
;
this
->
pitch
=
pitch
;
this
->
yaw
=
yaw
;
}
DirectX
::
XMMATRIX
TestPlane
::
GetTransformXM
()
const
noexcept
{
return
DirectX
::
XMMatrixRotationRollPitchYaw
(
roll
,
pitch
,
yaw
)
*
DirectX
::
XMMatrixTranslation
(
pos
.
x
,
pos
.
y
,
pos
.
z
);
}
hw3d/TestPlane.h
0 → 100644
View file @
f298a1ac
#pragma once
#include "Drawable.h"
class
TestPlane
:
public
Drawable
{
public:
TestPlane
(
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
;
private:
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/hw3d.vcxproj
View file @
f298a1ac
...
...
@@ -118,6 +118,7 @@
<ClCompile
Include=
"Sampler.cpp"
/>
<ClCompile
Include=
"SolidSphere.cpp"
/>
<ClCompile
Include=
"Surface.cpp"
/>
<ClCompile
Include=
"TestPlane.cpp"
/>
<ClCompile
Include=
"Texture.cpp"
/>
<ClCompile
Include=
"Topology.cpp"
/>
<ClCompile
Include=
"TransformCbuf.cpp"
/>
...
...
@@ -161,6 +162,7 @@
<ClInclude
Include=
"InputLayout.h"
/>
<ClInclude
Include=
"Keyboard.h"
/>
<ClInclude
Include=
"Mesh.h"
/>
<ClInclude
Include=
"Plane.h"
/>
<ClInclude
Include=
"PointLight.h"
/>
<ClInclude
Include=
"Mouse.h"
/>
<ClInclude
Include=
"PixelShader.h"
/>
...
...
@@ -169,6 +171,7 @@
<ClInclude
Include=
"SolidSphere.h"
/>
<ClInclude
Include=
"Sphere.h"
/>
<ClInclude
Include=
"Surface.h"
/>
<ClInclude
Include=
"TestPlane.h"
/>
<ClInclude
Include=
"Texture.h"
/>
<ClInclude
Include=
"Topology.h"
/>
<ClInclude
Include=
"TransformCbuf.h"
/>
...
...
hw3d/hw3d.vcxproj.filters
View file @
f298a1ac
...
...
@@ -150,6 +150,9 @@
<ClCompile
Include=
"Mesh.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
<ClCompile
Include=
"TestPlane.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"WindowsMessageMap.h"
>
...
...
@@ -299,6 +302,12 @@
<ClInclude
Include=
"BindableCodex.h"
>
<Filter>
Header Files\Bindable
</Filter>
</ClInclude>
<ClInclude
Include=
"Plane.h"
>
<Filter>
Header Files\Geometry
</Filter>
</ClInclude>
<ClInclude
Include=
"TestPlane.h"
>
<Filter>
Header Files\Drawable
</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<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