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
18dd6edb
Commit
18dd6edb
authored
Mar 03, 2019
by
chili
Browse files
camera with control window
parent
13abbb1e
Changes
7
Show whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
18dd6edb
...
@@ -77,13 +77,13 @@ App::App()
...
@@ -77,13 +77,13 @@ App::App()
std
::
generate_n
(
std
::
back_inserter
(
drawables
),
nDrawables
,
Factory
{
wnd
.
Gfx
()
}
);
std
::
generate_n
(
std
::
back_inserter
(
drawables
),
nDrawables
,
Factory
{
wnd
.
Gfx
()
}
);
wnd
.
Gfx
().
SetProjection
(
dx
::
XMMatrixPerspectiveLH
(
1.0
f
,
3.0
f
/
4.0
f
,
0.5
f
,
40.0
f
)
);
wnd
.
Gfx
().
SetProjection
(
dx
::
XMMatrixPerspectiveLH
(
1.0
f
,
3.0
f
/
4.0
f
,
0.5
f
,
40.0
f
)
);
wnd
.
Gfx
().
SetCamera
(
dx
::
XMMatrixTranslation
(
0.0
f
,
0.0
f
,
20.0
f
)
);
}
}
void
App
::
DoFrame
()
void
App
::
DoFrame
()
{
{
const
auto
dt
=
timer
.
Mark
()
*
speed_factor
;
const
auto
dt
=
timer
.
Mark
()
*
speed_factor
;
wnd
.
Gfx
().
BeginFrame
(
0.07
f
,
0.0
f
,
0.12
f
);
wnd
.
Gfx
().
BeginFrame
(
0.07
f
,
0.0
f
,
0.12
f
);
wnd
.
Gfx
().
SetCamera
(
cam
.
GetMatrix
()
);
for
(
auto
&
d
:
drawables
)
for
(
auto
&
d
:
drawables
)
{
{
...
@@ -96,9 +96,11 @@ void App::DoFrame()
...
@@ -96,9 +96,11 @@ void App::DoFrame()
{
{
ImGui
::
SliderFloat
(
"Speed Factor"
,
&
speed_factor
,
0.0
f
,
4.0
f
);
ImGui
::
SliderFloat
(
"Speed Factor"
,
&
speed_factor
,
0.0
f
,
4.0
f
);
ImGui
::
Text
(
"%.3f ms/frame (%.1f FPS)"
,
1000.0
f
/
ImGui
::
GetIO
().
Framerate
,
ImGui
::
GetIO
().
Framerate
);
ImGui
::
Text
(
"%.3f ms/frame (%.1f FPS)"
,
1000.0
f
/
ImGui
::
GetIO
().
Framerate
,
ImGui
::
GetIO
().
Framerate
);
ImGui
::
Text
(
"Status: %s"
,
wnd
.
kbd
.
KeyIsPressed
(
VK_SPACE
)
?
"PAUSED"
:
"RUNNING"
);
ImGui
::
Text
(
"Status: %s"
,
wnd
.
kbd
.
KeyIsPressed
(
VK_SPACE
)
?
"PAUSED"
:
"RUNNING
(hold spacebar to pause)
"
);
}
}
ImGui
::
End
();
ImGui
::
End
();
// imgui window to control camera
cam
.
SpawnControlWindow
();
// present
// present
wnd
.
Gfx
().
EndFrame
();
wnd
.
Gfx
().
EndFrame
();
...
...
hw3d/App.h
View file @
18dd6edb
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#include "Window.h"
#include "Window.h"
#include "ChiliTimer.h"
#include "ChiliTimer.h"
#include "ImguiManager.h"
#include "ImguiManager.h"
#include "Camera.h"
class
App
class
App
{
{
...
@@ -18,5 +19,6 @@ private:
...
@@ -18,5 +19,6 @@ private:
ChiliTimer
timer
;
ChiliTimer
timer
;
std
::
vector
<
std
::
unique_ptr
<
class
Drawable
>>
drawables
;
std
::
vector
<
std
::
unique_ptr
<
class
Drawable
>>
drawables
;
float
speed_factor
=
1.0
f
;
float
speed_factor
=
1.0
f
;
Camera
cam
;
static
constexpr
size_t
nDrawables
=
180
;
static
constexpr
size_t
nDrawables
=
180
;
};
};
\ No newline at end of file
hw3d/Camera.cpp
0 → 100644
View file @
18dd6edb
#include "Camera.h"
#include "imgui/imgui.h"
namespace
dx
=
DirectX
;
DirectX
::
XMMATRIX
Camera
::
GetMatrix
()
const
noexcept
{
const
auto
pos
=
dx
::
XMVector3Transform
(
dx
::
XMVectorSet
(
0.0
f
,
0.0
f
,
-
r
,
0.0
f
),
dx
::
XMMatrixRotationRollPitchYaw
(
phi
,
-
theta
,
0.0
f
)
);
return
dx
::
XMMatrixLookAtLH
(
pos
,
dx
::
XMVectorZero
(),
dx
::
XMVectorSet
(
0.0
f
,
1.0
f
,
0.0
f
,
0.0
f
)
)
*
dx
::
XMMatrixRotationRollPitchYaw
(
pitch
,
-
yaw
,
roll
);
}
void
Camera
::
SpawnControlWindow
()
noexcept
{
if
(
ImGui
::
Begin
(
"Camera"
)
)
{
ImGui
::
Text
(
"Position"
);
ImGui
::
SliderFloat
(
"R"
,
&
r
,
0.0
f
,
80.0
f
,
"%.1f"
);
ImGui
::
SliderAngle
(
"Theta"
,
&
theta
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Phi"
,
&
phi
,
-
89.0
f
,
89.0
f
);
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
);
if
(
ImGui
::
Button
(
"Reset"
)
)
{
Reset
();
}
}
ImGui
::
End
();
}
void
Camera
::
Reset
()
noexcept
{
r
=
20.0
f
;
theta
=
0.0
f
;
phi
=
0.0
f
;
pitch
=
0.0
f
;
yaw
=
0.0
f
;
roll
=
0.0
f
;
}
hw3d/Camera.h
0 → 100644
View file @
18dd6edb
#pragma once
#include "Graphics.h"
class
Camera
{
public:
DirectX
::
XMMATRIX
GetMatrix
()
const
noexcept
;
void
SpawnControlWindow
()
noexcept
;
void
Reset
()
noexcept
;
private:
float
r
=
20.0
f
;
float
theta
=
0.0
f
;
float
phi
=
0.0
f
;
float
pitch
=
0.0
f
;
float
yaw
=
0.0
f
;
float
roll
=
0.0
f
;
};
\ No newline at end of file
hw3d/SkinnedBox.h
View file @
18dd6edb
#pragma once
#pragma once
#pragma once
#include "DrawableBase.h"
#include "DrawableBase.h"
...
...
hw3d/hw3d.vcxproj
View file @
18dd6edb
...
@@ -150,6 +150,7 @@
...
@@ -150,6 +150,7 @@
<ClCompile
Include=
"App.cpp"
/>
<ClCompile
Include=
"App.cpp"
/>
<ClCompile
Include=
"Bindable.cpp"
/>
<ClCompile
Include=
"Bindable.cpp"
/>
<ClCompile
Include=
"Box.cpp"
/>
<ClCompile
Include=
"Box.cpp"
/>
<ClCompile
Include=
"Camera.cpp"
/>
<ClCompile
Include=
"ChiliException.cpp"
/>
<ClCompile
Include=
"ChiliException.cpp"
/>
<ClCompile
Include=
"ChiliTimer.cpp"
/>
<ClCompile
Include=
"ChiliTimer.cpp"
/>
<ClCompile
Include=
"Drawable.cpp"
/>
<ClCompile
Include=
"Drawable.cpp"
/>
...
@@ -189,6 +190,7 @@
...
@@ -189,6 +190,7 @@
<ClInclude
Include=
"Bindable.h"
/>
<ClInclude
Include=
"Bindable.h"
/>
<ClInclude
Include=
"BindableBase.h"
/>
<ClInclude
Include=
"BindableBase.h"
/>
<ClInclude
Include=
"Box.h"
/>
<ClInclude
Include=
"Box.h"
/>
<ClInclude
Include=
"Camera.h"
/>
<ClInclude
Include=
"ChiliException.h"
/>
<ClInclude
Include=
"ChiliException.h"
/>
<ClInclude
Include=
"ChiliMath.h"
/>
<ClInclude
Include=
"ChiliMath.h"
/>
<ClInclude
Include=
"ChiliTimer.h"
/>
<ClInclude
Include=
"ChiliTimer.h"
/>
...
...
hw3d/hw3d.vcxproj.filters
View file @
18dd6edb
...
@@ -150,6 +150,9 @@
...
@@ -150,6 +150,9 @@
<ClCompile
Include=
"ImguiManager.cpp"
>
<ClCompile
Include=
"ImguiManager.cpp"
>
<Filter>
Source Files
</Filter>
<Filter>
Source Files
</Filter>
</ClCompile>
</ClCompile>
<ClCompile
Include=
"Camera.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ClInclude
Include=
"WindowsMessageMap.h"
>
<ClInclude
Include=
"WindowsMessageMap.h"
>
...
@@ -305,6 +308,9 @@
...
@@ -305,6 +308,9 @@
<ClInclude
Include=
"ImguiManager.h"
>
<ClInclude
Include=
"ImguiManager.h"
>
<Filter>
Header Files
</Filter>
<Filter>
Header Files
</Filter>
</ClInclude>
</ClInclude>
<ClInclude
Include=
"Camera.h"
>
<Filter>
Header Files
</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