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
99e230c6
Commit
99e230c6
authored
Jul 06, 2019
by
chili
Browse files
can refactor recursive tree show to only need 1 ref now
parent
dac6fa8a
Changes
2
Hide whitespace changes
Inline
Side-by-side
hw3d/Mesh.cpp
View file @
99e230c6
...
...
@@ -98,11 +98,13 @@ void Node::AddChild( std::unique_ptr<Node> pChild ) noxnd
childPtrs
.
push_back
(
std
::
move
(
pChild
)
);
}
void
Node
::
ShowTree
(
std
::
optional
<
int
>&
selectedIndex
,
Node
*&
pSelectedNode
)
const
noexcept
void
Node
::
ShowTree
(
Node
*&
pSelectedNode
)
const
noexcept
{
// if there is no selected node, set selectedId to an impossible value
const
int
selectedId
=
(
pSelectedNode
==
nullptr
)
?
-
1
:
pSelectedNode
->
GetId
();
// build up flags for current node
const
auto
node_flags
=
ImGuiTreeNodeFlags_OpenOnArrow
|
((
GetId
()
==
selectedI
ndex
.
value_or
(
-
1
)
)
?
ImGuiTreeNodeFlags_Selected
:
0
)
|
((
GetId
()
==
selectedI
d
)
?
ImGuiTreeNodeFlags_Selected
:
0
)
|
((
childPtrs
.
size
()
==
0
)
?
ImGuiTreeNodeFlags_Leaf
:
0
);
// render this node
const
auto
expanded
=
ImGui
::
TreeNodeEx
(
...
...
@@ -111,7 +113,6 @@ void Node::ShowTree( std::optional<int>& selectedIndex,Node*& pSelectedNode ) co
// processing for selecting node
if
(
ImGui
::
IsItemClicked
()
)
{
selectedIndex
=
GetId
();
pSelectedNode
=
const_cast
<
Node
*>
(
this
);
}
// recursive rendering of open node's children
...
...
@@ -119,7 +120,7 @@ void Node::ShowTree( std::optional<int>& selectedIndex,Node*& pSelectedNode ) co
{
for
(
const
auto
&
pChild
:
childPtrs
)
{
pChild
->
ShowTree
(
selectedIndex
,
pSelectedNode
);
pChild
->
ShowTree
(
pSelectedNode
);
}
ImGui
::
TreePop
();
}
...
...
@@ -149,12 +150,12 @@ public:
if
(
ImGui
::
Begin
(
windowName
)
)
{
ImGui
::
Columns
(
2
,
nullptr
,
true
);
root
.
ShowTree
(
selectedIndex
,
pSelectedNode
);
root
.
ShowTree
(
pSelectedNode
);
ImGui
::
NextColumn
();
if
(
pSelectedNode
!=
nullptr
)
{
auto
&
transform
=
transforms
[
*
s
elected
Index
];
auto
&
transform
=
transforms
[
pS
elected
Node
->
GetId
()
];
ImGui
::
Text
(
"Orientation"
);
ImGui
::
SliderAngle
(
"Roll"
,
&
transform
.
roll
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Pitch"
,
&
transform
.
pitch
,
-
180.0
f
,
180.0
f
);
...
...
@@ -169,7 +170,8 @@ public:
}
dx
::
XMMATRIX
GetTransform
()
const
noexcept
{
const
auto
&
transform
=
transforms
.
at
(
*
selectedIndex
);
assert
(
pSelectedNode
!=
nullptr
);
const
auto
&
transform
=
transforms
.
at
(
pSelectedNode
->
GetId
()
);
return
dx
::
XMMatrixRotationRollPitchYaw
(
transform
.
roll
,
transform
.
pitch
,
transform
.
yaw
)
*
dx
::
XMMatrixTranslation
(
transform
.
x
,
transform
.
y
,
transform
.
z
);
...
...
@@ -179,7 +181,6 @@ public:
return
pSelectedNode
;
}
private:
std
::
optional
<
int
>
selectedIndex
;
Node
*
pSelectedNode
;
struct
TransformParameters
{
...
...
hw3d/Mesh.h
View file @
99e230c6
...
...
@@ -41,7 +41,7 @@ public:
int
GetId
()
const
noexcept
;
private:
void
AddChild
(
std
::
unique_ptr
<
Node
>
pChild
)
noxnd
;
void
ShowTree
(
std
::
optional
<
int
>&
selectedIndex
,
Node
*&
pSelectedNode
)
const
noexcept
;
void
ShowTree
(
Node
*&
pSelectedNode
)
const
noexcept
;
private:
std
::
string
name
;
int
id
;
...
...
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