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
305895dc
Commit
305895dc
authored
Jul 06, 2019
by
chili
Browse files
bad camera rotation free mouse look
parent
2a6d9115
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
305895dc
...
@@ -30,8 +30,14 @@ void App::DoFrame()
...
@@ -30,8 +30,14 @@ void App::DoFrame()
while
(
const
auto
e
=
wnd
.
kbd
.
ReadKey
()
)
while
(
const
auto
e
=
wnd
.
kbd
.
ReadKey
()
)
{
{
if
(
e
->
IsPress
()
&&
e
->
GetCode
()
==
VK_INSERT
)
if
(
!
e
->
IsPress
()
)
{
{
continue
;
}
switch
(
e
->
GetCode
()
)
{
case
VK_ESCAPE
:
if
(
wnd
.
CursorEnabled
()
)
if
(
wnd
.
CursorEnabled
()
)
{
{
wnd
.
DisableCursor
();
wnd
.
DisableCursor
();
...
@@ -42,6 +48,46 @@ void App::DoFrame()
...
@@ -42,6 +48,46 @@ void App::DoFrame()
wnd
.
EnableCursor
();
wnd
.
EnableCursor
();
wnd
.
mouse
.
DisableRaw
();
wnd
.
mouse
.
DisableRaw
();
}
}
break
;
case
VK_F1
:
showDemoWindow
=
true
;
break
;
}
}
if
(
!
wnd
.
CursorEnabled
()
)
{
if
(
wnd
.
kbd
.
KeyIsPressed
(
'W'
)
)
{
cam
.
Translate
(
{
0.0
f
,
0.0
f
,
dt
}
);
}
if
(
wnd
.
kbd
.
KeyIsPressed
(
'A'
)
)
{
cam
.
Translate
(
{
-
dt
,
0.0
f
,
0.0
f
}
);
}
if
(
wnd
.
kbd
.
KeyIsPressed
(
'S'
)
)
{
cam
.
Translate
(
{
0.0
f
,
0.0
f
,
-
dt
}
);
}
if
(
wnd
.
kbd
.
KeyIsPressed
(
'D'
)
)
{
cam
.
Translate
(
{
dt
,
0.0
f
,
0.0
f
}
);
}
if
(
wnd
.
kbd
.
KeyIsPressed
(
'R'
)
)
{
cam
.
Translate
(
{
0.0
f
,
dt
,
0.0
f
}
);
}
if
(
wnd
.
kbd
.
KeyIsPressed
(
'F'
)
)
{
cam
.
Translate
(
{
0.0
f
,
-
dt
,
0.0
f
}
);
}
}
while
(
const
auto
delta
=
wnd
.
mouse
.
ReadRawDelta
()
)
{
if
(
!
wnd
.
CursorEnabled
()
)
{
cam
.
Rotate
(
delta
->
x
,
delta
->
y
);
}
}
}
}
...
@@ -50,7 +96,6 @@ void App::DoFrame()
...
@@ -50,7 +96,6 @@ void App::DoFrame()
light
.
SpawnControlWindow
();
light
.
SpawnControlWindow
();
ShowImguiDemoWindow
();
ShowImguiDemoWindow
();
nano
.
ShowWindow
();
nano
.
ShowWindow
();
ShowRawInputWindow
();
// present
// present
wnd
.
Gfx
().
EndFrame
();
wnd
.
Gfx
().
EndFrame
();
...
@@ -58,26 +103,10 @@ void App::DoFrame()
...
@@ -58,26 +103,10 @@ void App::DoFrame()
void
App
::
ShowImguiDemoWindow
()
void
App
::
ShowImguiDemoWindow
()
{
{
static
bool
show_demo_window
=
true
;
if
(
showDemoWindow
)
if
(
show_demo_window
)
{
ImGui
::
ShowDemoWindow
(
&
show_demo_window
);
}
}
void
App
::
ShowRawInputWindow
()
{
while
(
const
auto
d
=
wnd
.
mouse
.
ReadRawDelta
()
)
{
x
+=
d
->
x
;
y
+=
d
->
y
;
}
if
(
ImGui
::
Begin
(
"Raw Input"
)
)
{
{
ImGui
::
Text
(
"Tally: (%d,%d)"
,
x
,
y
);
ImGui
::
ShowDemoWindow
(
&
showDemoWindow
);
ImGui
::
Text
(
"Cursor: %s"
,
wnd
.
CursorEnabled
()
?
"enabled"
:
"disabled"
);
}
}
ImGui
::
End
();
}
}
App
::~
App
()
App
::~
App
()
...
...
hw3d/App.h
View file @
305895dc
...
@@ -17,9 +17,8 @@ public:
...
@@ -17,9 +17,8 @@ public:
private:
private:
void
DoFrame
();
void
DoFrame
();
void
ShowImguiDemoWindow
();
void
ShowImguiDemoWindow
();
void
ShowRawInputWindow
();
private:
private:
int
x
=
0
,
y
=
0
;
bool
showDemoWindow
=
false
;
ImguiManager
imgui
;
ImguiManager
imgui
;
Window
wnd
;
Window
wnd
;
ChiliTimer
timer
;
ChiliTimer
timer
;
...
...
hw3d/Camera.cpp
View file @
305895dc
#include "Camera.h"
#include "Camera.h"
#include "imgui/imgui.h"
#include "imgui/imgui.h"
#include "ChiliMath.h"
namespace
dx
=
DirectX
;
namespace
dx
=
DirectX
;
Camera
::
Camera
()
noexcept
{
Reset
();
}
DirectX
::
XMMATRIX
Camera
::
GetMatrix
()
const
noexcept
DirectX
::
XMMATRIX
Camera
::
GetMatrix
()
const
noexcept
{
{
const
auto
pos
=
dx
::
XMVector3Transform
(
return
dx
::
XMMatrixTranslation
(
-
pos
.
x
,
-
pos
.
y
,
-
pos
.
z
)
*
dx
::
XMVectorSet
(
0.0
f
,
0.0
f
,
-
r
,
0.0
f
),
dx
::
XMMatrixRotationRollPitchYaw
(
-
pitch
,
-
yaw
,
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
void
Camera
::
SpawnControlWindow
()
noexcept
...
@@ -22,12 +20,11 @@ void Camera::SpawnControlWindow() noexcept
...
@@ -22,12 +20,11 @@ void Camera::SpawnControlWindow() noexcept
if
(
ImGui
::
Begin
(
"Camera"
)
)
if
(
ImGui
::
Begin
(
"Camera"
)
)
{
{
ImGui
::
Text
(
"Position"
);
ImGui
::
Text
(
"Position"
);
ImGui
::
SliderFloat
(
"
R
"
,
&
r
,
0.
2
f
,
80.0
f
,
"%.1f"
);
ImGui
::
SliderFloat
(
"
X
"
,
&
pos
.
x
,
-
8
0.
0
f
,
80.0
f
,
"%.1f"
);
ImGui
::
Slider
Angle
(
"Theta"
,
&
theta
,
-
1
80.0
f
,
1
80.0
f
);
ImGui
::
Slider
Float
(
"Y"
,
&
pos
.
y
,
-
80.0
f
,
80.0
f
,
"%.1f"
);
ImGui
::
Slider
Angle
(
"Phi"
,
&
phi
,
-
8
9
.0
f
,
8
9
.0
f
);
ImGui
::
Slider
Float
(
"Z"
,
&
pos
.
z
,
-
8
0
.0
f
,
8
0
.0
f
,
"%.1f"
);
ImGui
::
Text
(
"Orientation"
);
ImGui
::
Text
(
"Orientation"
);
ImGui
::
SliderAngle
(
"Roll"
,
&
roll
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Pitch"
,
&
pitch
,
-
90.0
f
,
90.0
f
);
ImGui
::
SliderAngle
(
"Pitch"
,
&
pitch
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Yaw"
,
&
yaw
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Yaw"
,
&
yaw
,
-
180.0
f
,
180.0
f
);
if
(
ImGui
::
Button
(
"Reset"
)
)
if
(
ImGui
::
Button
(
"Reset"
)
)
{
{
...
@@ -39,10 +36,27 @@ void Camera::SpawnControlWindow() noexcept
...
@@ -39,10 +36,27 @@ void Camera::SpawnControlWindow() noexcept
void
Camera
::
Reset
()
noexcept
void
Camera
::
Reset
()
noexcept
{
{
r
=
20.0
f
;
pos
=
{
0.0
f
,
7.5
f
,
-
18.0
f
};
theta
=
0.0
f
;
phi
=
0.0
f
;
pitch
=
0.0
f
;
pitch
=
0.0
f
;
yaw
=
0.0
f
;
yaw
=
0.0
f
;
roll
=
0.0
f
;
}
void
Camera
::
Rotate
(
float
dx
,
float
dy
)
noexcept
{
yaw
=
wrap_angle
(
yaw
+
dx
*
rotationSpeed
);
pitch
=
std
::
clamp
(
pitch
+
dy
*
rotationSpeed
,
-
PI
/
2.0
f
,
PI
/
2.0
f
);
}
void
Camera
::
Translate
(
DirectX
::
XMFLOAT3
translation
)
noexcept
{
dx
::
XMStoreFloat3
(
&
translation
,
dx
::
XMVector3Transform
(
dx
::
XMLoadFloat3
(
&
translation
),
dx
::
XMMatrixRotationRollPitchYaw
(
pitch
,
yaw
,
0.0
f
)
*
dx
::
XMMatrixScaling
(
travelSpeed
,
travelSpeed
,
travelSpeed
)
)
);
pos
=
{
pos
.
x
+
translation
.
x
,
pos
.
y
+
translation
.
y
,
pos
.
z
+
translation
.
z
};
}
}
hw3d/Camera.h
View file @
305895dc
...
@@ -4,14 +4,16 @@
...
@@ -4,14 +4,16 @@
class
Camera
class
Camera
{
{
public:
public:
Camera
()
noexcept
;
DirectX
::
XMMATRIX
GetMatrix
()
const
noexcept
;
DirectX
::
XMMATRIX
GetMatrix
()
const
noexcept
;
void
SpawnControlWindow
()
noexcept
;
void
SpawnControlWindow
()
noexcept
;
void
Reset
()
noexcept
;
void
Reset
()
noexcept
;
void
Rotate
(
float
dx
,
float
dy
)
noexcept
;
void
Translate
(
DirectX
::
XMFLOAT3
translation
)
noexcept
;
private:
private:
float
r
=
20.0
f
;
DirectX
::
XMFLOAT3
pos
;
float
theta
=
0.0
f
;
float
pitch
;
float
phi
=
0.0
f
;
float
yaw
;
float
pitch
=
0.0
f
;
static
constexpr
float
travelSpeed
=
12.0
f
;
float
yaw
=
0.0
f
;
static
constexpr
float
rotationSpeed
=
0.004
f
;
float
roll
=
0.0
f
;
};
};
\ No newline at end of file
hw3d/Models/nano.gltf
View file @
305895dc
This diff is collapsed.
Click to expand it.
hw3d/PointLight.cpp
View file @
305895dc
...
@@ -39,7 +39,7 @@ void PointLight::SpawnControlWindow() noexcept
...
@@ -39,7 +39,7 @@ void PointLight::SpawnControlWindow() noexcept
void
PointLight
::
Reset
()
noexcept
void
PointLight
::
Reset
()
noexcept
{
{
cbData
=
{
cbData
=
{
{
0.0
f
,
0.0
f
,
0.0
f
},
{
1.5
f
,
14.0
f
,
-
4.5
f
},
{
0.05
f
,
0.05
f
,
0.05
f
},
{
0.05
f
,
0.05
f
,
0.05
f
},
{
1.0
f
,
1.0
f
,
1.0
f
},
{
1.0
f
,
1.0
f
,
1.0
f
},
1.0
f
,
1.0
f
,
...
...
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