Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
glow-extras
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jonathan Kunstwald
glow-extras
Commits
6a3d6bd6
Commit
6a3d6bd6
authored
7 years ago
by
Philip Trettner
Browse files
Options
Downloads
Patches
Plain Diff
Fixed FPSStyleLookaround - modernized to altitude-azimuth
parent
7f1e422a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
camera/glow-extras/camera/GenericCamera.cc
+18
-38
18 additions, 38 deletions
camera/glow-extras/camera/GenericCamera.cc
with
18 additions
and
38 deletions
camera/glow-extras/camera/GenericCamera.cc
+
18
−
38
View file @
6a3d6bd6
...
...
@@ -4,11 +4,7 @@
#include
<cassert>
#include
<glm/gtc/matrix_transform.hpp>
#include
<glm/gtc/quaternion.hpp>
#include
<glm/gtx/euler_angles.hpp>
#include
<glm/glm.hpp>
#include
<glm/gtx/string_cast.hpp>
#include
<glm/ext.hpp>
#ifdef GLOW_DEBUG
namespace
...
...
@@ -74,44 +70,28 @@ GenericCamera::GenericCamera(const std::string &_state)
void
GenericCamera
::
FPSstyleLookAround
(
float
_deltaX
,
float
_deltaY
)
{
float
yaw
=
0.0
f
;
float
pitch
=
0.0
f
;
glm
::
mat3
R
=
getRotationMatrix3
();
// get roll / pitch / yaw from the current rotation matrix:
float
yaw1
=
asin
(
-
R
[
2
][
0
]);
float
yaw2
=
glm
::
pi
<
float
>
()
-
asin
(
-
R
[
2
][
0
]);
auto
fwd
=
getForwardDirection
();
float
pitch1
=
(
cos
(
yaw1
)
>
0
)
?
atan2
(
R
[
2
][
1
],
R
[
2
][
2
])
:
atan2
(
-
R
[
2
][
1
],
-
R
[
2
][
2
]
);
float
pitch2
=
(
cos
(
yaw2
)
>
0
)
?
atan2
(
R
[
2
][
1
],
R
[
2
][
2
])
:
atan2
(
-
R
[
2
][
1
],
-
R
[
2
][
2
]
);
auto
altitude
=
glm
::
atan
(
fwd
.
y
,
length
(
glm
::
vec2
(
fwd
.
x
,
fwd
.
z
))
);
auto
azimuth
=
glm
::
atan
(
fwd
.
z
,
fwd
.
x
);
float
roll1
=
(
cos
(
yaw1
)
>
0
)
?
atan2
(
R
[
1
][
0
],
R
[
0
][
0
])
:
atan2
(
-
R
[
1
][
0
],
-
R
[
0
][
0
]);
float
roll2
=
(
cos
(
yaw2
)
>
0
)
?
atan2
(
R
[
1
][
0
],
R
[
0
][
0
])
:
atan2
(
-
R
[
1
][
0
],
-
R
[
0
][
0
]);
// we assume no roll at all, in that case one of the roll variants will be 0.0
// if not, use the smaller one -> minimize the camera "jump" as this will destroy
// information
if
(
std
::
abs
(
roll1
)
<=
std
::
abs
(
roll2
))
{
yaw
=
-
yaw1
;
pitch
=
-
pitch1
;
}
else
{
yaw
=
-
yaw2
;
pitch
=
-
pitch2
;
}
azimuth
+=
_deltaX
;
altitude
=
glm
::
clamp
(
altitude
-
_deltaY
,
-
0.499
f
*
glm
::
pi
<
float
>
(),
0.499
f
*
glm
::
pi
<
float
>
());
// add rotation diffs given:
yaw
=
yaw
+
_deltaX
;
pitch
=
glm
::
clamp
(
pitch
+
_deltaY
,
-
0.5
f
*
glm
::
pi
<
float
>
(),
0.5
f
*
glm
::
pi
<
float
>
());
auto
caz
=
glm
::
cos
(
azimuth
);
auto
saz
=
glm
::
sin
(
azimuth
);
auto
cal
=
glm
::
cos
(
altitude
);
auto
sal
=
glm
::
sin
(
altitude
);
// create rotation matices, seperated so we have full control over the order:
glm
::
mat4
newRotY
=
glm
::
yawPitchRoll
(
yaw
,
0.0
f
,
0.0
f
);
glm
::
mat4
newRotX
=
glm
::
yawPitchRoll
(
0.0
f
,
pitch
,
0.0
f
);
fwd
=
glm
::
vec3
(
//
cal
*
caz
,
//
sal
,
//
cal
*
saz
//
);
auto
right
=
normalize
(
cross
(
fwd
,
glm
::
vec3
(
0
,
1
,
0
)));
auto
up
=
cross
(
right
,
fwd
);
// multiplication order is important to prevent roll:
setRotationMatrix
(
newRotX
*
newRotY
);
setRotationMatrix
(
transpose
(
glm
::
mat3
(
right
,
up
,
-
fwd
)));
}
void
GenericCamera
::
rotateAroundTaget_GlobalAxes
(
float
_x
,
float
_y
,
float
_z
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment