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
cdb56818
Commit
cdb56818
authored
Jul 06, 2019
by
chili
Browse files
better camera rotation with lookAt + rotation of view direction
parent
305895dc
Changes
1
Hide whitespace changes
Inline
Side-by-side
hw3d/Camera.cpp
View file @
cdb56818
...
...
@@ -11,8 +11,19 @@ Camera::Camera() noexcept
DirectX
::
XMMATRIX
Camera
::
GetMatrix
()
const
noexcept
{
return
dx
::
XMMatrixTranslation
(
-
pos
.
x
,
-
pos
.
y
,
-
pos
.
z
)
*
dx
::
XMMatrixRotationRollPitchYaw
(
-
pitch
,
-
yaw
,
0.0
f
);
using
namespace
dx
;
const
dx
::
XMVECTOR
forwardBaseVector
=
XMVectorSet
(
0.0
f
,
0.0
f
,
1.0
f
,
0.0
f
);
// apply the camera rotations to a base vector
const
auto
lookVector
=
XMVector3Transform
(
forwardBaseVector
,
XMMatrixRotationRollPitchYaw
(
pitch
,
yaw
,
0.0
f
)
);
// generate camera transform (applied to all objects to arrange them relative
// to camera position/orientation in world) from cam position and direction
// camera "top" always faces towards +Y (cannot do a barrel roll)
const
auto
camPosition
=
XMLoadFloat3
(
&
pos
);
const
auto
camTarget
=
camPosition
+
lookVector
;
return
XMMatrixLookAtLH
(
camPosition
,
camTarget
,
XMVectorSet
(
0.0
f
,
1.0
f
,
0.0
f
,
0.0
f
)
);
}
void
Camera
::
SpawnControlWindow
()
noexcept
...
...
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