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
143981dc
Commit
143981dc
authored
Jun 21, 2019
by
chili
Browse files
model window in own class (pImpl)
parent
97013ac9
Changes
2
Hide whitespace changes
Inline
Side-by-side
hw3d/Mesh.cpp
View file @
143981dc
#include "Mesh.h"
#include "imgui/imgui.h"
namespace
dx
=
DirectX
;
// Mesh
Mesh
::
Mesh
(
Graphics
&
gfx
,
std
::
vector
<
std
::
unique_ptr
<
Bind
::
Bindable
>>
bindPtrs
)
{
...
...
@@ -63,14 +65,14 @@ void Node::AddChild( std::unique_ptr<Node> pChild ) noxnd
childPtrs
.
push_back
(
std
::
move
(
pChild
)
);
}
void
Node
::
Render
Tree
()
const
noexcept
void
Node
::
Show
Tree
()
const
noexcept
{
// if tree node expanded, recursively render all children
if
(
ImGui
::
TreeNode
(
name
.
c_str
()
)
)
{
for
(
const
auto
&
pChild
:
childPtrs
)
{
pChild
->
Render
Tree
();
pChild
->
Show
Tree
();
}
ImGui
::
TreePop
();
}
...
...
@@ -78,7 +80,50 @@ void Node::RenderTree() const noexcept
// Model
class
ModelWindow
// pImpl idiom, only defined in this .cpp
{
public:
void
Show
(
const
char
*
windowName
,
const
Node
&
root
)
noexcept
{
// window name defaults to "Model"
windowName
=
windowName
?
windowName
:
"Model"
;
if
(
ImGui
::
Begin
(
windowName
)
)
{
ImGui
::
Columns
(
2
,
nullptr
,
true
);
root
.
ShowTree
();
ImGui
::
NextColumn
();
ImGui
::
Text
(
"Orientation"
);
ImGui
::
SliderAngle
(
"Roll"
,
&
pos
.
roll
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Pitch"
,
&
pos
.
pitch
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Yaw"
,
&
pos
.
yaw
,
-
180.0
f
,
180.0
f
);
ImGui
::
Text
(
"Position"
);
ImGui
::
SliderFloat
(
"X"
,
&
pos
.
x
,
-
20.0
f
,
20.0
f
);
ImGui
::
SliderFloat
(
"Y"
,
&
pos
.
y
,
-
20.0
f
,
20.0
f
);
ImGui
::
SliderFloat
(
"Z"
,
&
pos
.
z
,
-
20.0
f
,
20.0
f
);
}
ImGui
::
End
();
}
dx
::
XMMATRIX
GetTransform
()
const
noexcept
{
return
dx
::
XMMatrixRotationRollPitchYaw
(
pos
.
roll
,
pos
.
pitch
,
pos
.
yaw
)
*
dx
::
XMMatrixTranslation
(
pos
.
x
,
pos
.
y
,
pos
.
z
);
}
private:
struct
{
float
roll
=
0.0
f
;
float
pitch
=
0.0
f
;
float
yaw
=
0.0
f
;
float
x
=
0.0
f
;
float
y
=
0.0
f
;
float
z
=
0.0
f
;
}
pos
;
};
Model
::
Model
(
Graphics
&
gfx
,
const
std
::
string
fileName
)
:
pWindow
(
std
::
make_unique
<
ModelWindow
>
()
)
{
Assimp
::
Importer
imp
;
const
auto
pScene
=
imp
.
ReadFile
(
fileName
.
c_str
(),
...
...
@@ -96,32 +141,17 @@ Model::Model( Graphics& gfx,const std::string fileName )
void
Model
::
Draw
(
Graphics
&
gfx
)
const
noxnd
{
const
auto
transform
=
DirectX
::
XMMatrixRotationRollPitchYaw
(
pos
.
roll
,
pos
.
pitch
,
pos
.
yaw
)
*
DirectX
::
XMMatrixTranslation
(
pos
.
x
,
pos
.
y
,
pos
.
z
);
pRoot
->
Draw
(
gfx
,
transform
);
pRoot
->
Draw
(
gfx
,
pWindow
->
GetTransform
()
);
}
void
Model
::
ShowWindow
(
const
char
*
windowName
)
noexcept
{
windowName
=
windowName
?
windowName
:
"Model"
;
if
(
ImGui
::
Begin
(
windowName
)
)
{
ImGui
::
Columns
(
2
,
nullptr
,
true
);
pRoot
->
RenderTree
();
ImGui
::
NextColumn
();
ImGui
::
Text
(
"Orientation"
);
ImGui
::
SliderAngle
(
"Roll"
,
&
pos
.
roll
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Pitch"
,
&
pos
.
pitch
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Yaw"
,
&
pos
.
yaw
,
-
180.0
f
,
180.0
f
);
ImGui
::
Text
(
"Position"
);
ImGui
::
SliderFloat
(
"X"
,
&
pos
.
x
,
-
20.0
f
,
20.0
f
);
ImGui
::
SliderFloat
(
"Y"
,
&
pos
.
y
,
-
20.0
f
,
20.0
f
);
ImGui
::
SliderFloat
(
"Z"
,
&
pos
.
z
,
-
20.0
f
,
20.0
f
);
}
ImGui
::
End
();
pWindow
->
Show
(
windowName
,
*
pRoot
);
}
Model
::~
Model
()
noexcept
{}
std
::
unique_ptr
<
Mesh
>
Model
::
ParseMesh
(
Graphics
&
gfx
,
const
aiMesh
&
mesh
)
{
namespace
dx
=
DirectX
;
...
...
hw3d/Mesh.h
View file @
143981dc
...
...
@@ -23,7 +23,7 @@ class Node
public:
Node
(
const
std
::
string
&
name
,
std
::
vector
<
Mesh
*>
meshPtrs
,
const
DirectX
::
XMMATRIX
&
transform
)
noxnd
;
void
Draw
(
Graphics
&
gfx
,
DirectX
::
FXMMATRIX
accumulatedTransform
)
const
noxnd
;
void
Render
Tree
()
const
noexcept
;
void
Show
Tree
()
const
noexcept
;
private:
void
AddChild
(
std
::
unique_ptr
<
Node
>
pChild
)
noxnd
;
private:
...
...
@@ -39,19 +39,12 @@ public:
Model
(
Graphics
&
gfx
,
const
std
::
string
fileName
);
void
Draw
(
Graphics
&
gfx
)
const
noxnd
;
void
ShowWindow
(
const
char
*
windowName
=
nullptr
)
noexcept
;
~
Model
()
noexcept
;
private:
static
std
::
unique_ptr
<
Mesh
>
ParseMesh
(
Graphics
&
gfx
,
const
aiMesh
&
mesh
);
std
::
unique_ptr
<
Node
>
ParseNode
(
const
aiNode
&
node
)
noexcept
;
private:
std
::
unique_ptr
<
Node
>
pRoot
;
std
::
vector
<
std
::
unique_ptr
<
Mesh
>>
meshPtrs
;
struct
{
float
roll
=
0.0
f
;
float
pitch
=
0.0
f
;
float
yaw
=
0.0
f
;
float
x
=
0.0
f
;
float
y
=
0.0
f
;
float
z
=
0.0
f
;
}
pos
;
std
::
unique_ptr
<
class
ModelWindow
>
pWindow
;
};
\ No newline at end of file
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