Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Jupiteapot
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
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
Adam Štěpánek
Jupiteapot
Commits
bda71f63
There was an error fetching the commit references. Please try again later.
Commit
bda71f63
authored
5 years ago
by
Adam Štěpánek
Browse files
Options
Downloads
Patches
Plain Diff
Fix naming conventions in RotateCamera
parent
cec0e556
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
framework/include/rotate_camera.hpp
+16
-14
16 additions, 14 deletions
framework/include/rotate_camera.hpp
framework/src/rotate_camera.cpp
+34
-39
34 additions, 39 deletions
framework/src/rotate_camera.cpp
src/application.cpp
+6
-6
6 additions, 6 deletions
src/application.cpp
with
56 additions
and
59 deletions
framework/include/rotate_camera.hpp
+
16
−
14
View file @
bda71f63
...
...
@@ -13,52 +13,54 @@ class RotateCamera
private:
/// Constants that defines the behaviour of the camera
/// - Minimum elevation in radians
static
const
float
min
_e
levation
;
static
const
float
min
E
levation
;
/// - Maximum elevation in radians
static
const
float
max
_e
levation
;
static
const
float
max
E
levation
;
/// - Minimum distance from the point of interest
static
const
float
min
_d
istance
;
static
const
float
min
D
istance
;
/// - Sensitivity of the mouse when changing elevation or direction angles
static
const
float
angle
_s
ensitivity
;
static
const
float
angle
S
ensitivity
;
/// - Sensitivity of the mouse when changing zoom
static
const
float
zoom
_s
ensitivity
;
static
const
float
zoom
S
ensitivity
;
/// angle_direction is an angle in which determines into which direction in xz plane I look.
/// - 0 degrees .. I look in -z direction
/// - 90 degrees .. I look in -x direction
/// - 180 degrees .. I look in +z direction
/// - 270 degrees .. I look in +x direction
float
angle
_d
irection
;
float
angle
D
irection
;
/// angle_direction is an angle in which determines from which "height" I look.
/// - positive elevation .. I look from above the xz plane
/// - negative elevation .. I look from below the xz plane
float
angle
_e
levation
;
float
angle
E
levation
;
/// Distance from (0,0,0), the point at which I look
float
distance
;
/// Final position of the eye in world space coordinates, for LookAt or shaders
glm
::
vec3
eye
_p
osition
;
glm
::
vec3
eye
P
osition
;
/// Last X and Y coordinates of the mouse cursor
int
last
_x
,
last
_y
;
int
last
X
,
last
Y
;
/// True or false if moused buttons are pressed and the user rotates/zooms the camera
bool
is
_r
otating
,
is
_z
ooming
;
bool
is
R
otating
,
is
Z
ooming
;
/// Recomputes 'eye_position' from 'angle_direction', 'angle_elevation', and 'distance'
void
update
_eye_p
os
();
void
update
EyeP
os
();
public:
RotateCamera
();
/// Call when the user presses or releases a mouse button (see glfwSetMouseButtonCallback)
void
on
_m
ouse
_b
utton
(
int
button
,
int
action
,
int
mods
);
void
on
M
ouse
B
utton
(
int
button
,
int
action
,
int
mods
);
/// Call when the user moves with the mouse cursor (see glfwSetCursorPosCallback)
void
on
_m
ouse
_m
ove
(
double
x
,
double
y
);
void
on
M
ouse
M
ove
(
double
x
,
double
y
);
/// Returns the position of the eye in world space coordinates
glm
::
vec3
get_eye_position
()
const
;
glm
::
vec3
getEyePosition
()
const
{
return
eyePosition
;
}
};
This diff is collapsed.
Click to expand it.
framework/src/rotate_camera.cpp
+
34
−
39
View file @
bda71f63
...
...
@@ -2,74 +2,69 @@
#include
<GLFW/glfw3.h>
const
float
RotateCamera
::
min
_e
levation
=
-
1.5
f
;
const
float
RotateCamera
::
max
_e
levation
=
1.5
f
;
const
float
RotateCamera
::
min
_d
istance
=
1.0
f
;
const
float
RotateCamera
::
angle
_s
ensitivity
=
0.008
f
;
const
float
RotateCamera
::
zoom
_s
ensitivity
=
0.003
f
;
const
float
RotateCamera
::
min
E
levation
=
-
1.5
f
;
const
float
RotateCamera
::
max
E
levation
=
1.5
f
;
const
float
RotateCamera
::
min
D
istance
=
1.0
f
;
const
float
RotateCamera
::
angle
S
ensitivity
=
0.008
f
;
const
float
RotateCamera
::
zoom
S
ensitivity
=
0.003
f
;
RotateCamera
::
RotateCamera
()
:
angle
_d
irection
(
0.0
f
),
angle
_e
levation
(
0.785398163
f
),
distance
(
15.0
f
),
last
_x
(
0
),
last
_y
(
0
),
is
_r
otating
(
false
),
is
_z
ooming
(
false
)
:
angle
D
irection
(
0.0
f
),
angle
E
levation
(
0.785398163
f
),
distance
(
15.0
f
),
last
X
(
0
),
last
Y
(
0
),
is
R
otating
(
false
),
is
Z
ooming
(
false
)
{
update
_eye_p
os
();
update
EyeP
os
();
}
void
RotateCamera
::
update
_eye_p
os
()
void
RotateCamera
::
update
EyeP
os
()
{
eye
_p
osition
.
x
=
distance
*
cosf
(
angle
_e
levation
)
*
-
sinf
(
angle
_d
irection
);
eye
_p
osition
.
y
=
distance
*
sinf
(
angle
_e
levation
);
eye
_p
osition
.
z
=
distance
*
cosf
(
angle
_e
levation
)
*
cosf
(
angle
_d
irection
);
eye
P
osition
.
x
=
distance
*
cosf
(
angle
E
levation
)
*
-
sinf
(
angle
D
irection
);
eye
P
osition
.
y
=
distance
*
sinf
(
angle
E
levation
);
eye
P
osition
.
z
=
distance
*
cosf
(
angle
E
levation
)
*
cosf
(
angle
D
irection
);
}
void
RotateCamera
::
on
_m
ouse
_b
utton
(
int
button
,
int
action
,
int
mods
)
void
RotateCamera
::
on
M
ouse
B
utton
(
int
button
,
int
action
,
int
mods
)
{
// Left mouse button affects the angles
if
(
button
==
GLFW_MOUSE_BUTTON_LEFT
)
{
if
(
action
==
GLFW_PRESS
)
{
is
_r
otating
=
true
;
is
R
otating
=
true
;
}
else
{
is
_r
otating
=
false
;
is
R
otating
=
false
;
}
}
// Right mouse button affects the zoom
if
(
button
==
GLFW_MOUSE_BUTTON_RIGHT
)
{
if
(
action
==
GLFW_PRESS
)
{
is
_z
ooming
=
true
;
is
Z
ooming
=
true
;
}
else
{
is
_z
ooming
=
false
;
is
Z
ooming
=
false
;
}
}
}
void
RotateCamera
::
on
_m
ouse
_m
ove
(
double
x
,
double
y
)
void
RotateCamera
::
on
M
ouse
M
ove
(
double
x
,
double
y
)
{
float
dx
=
float
(
x
-
last
_x
);
float
dy
=
float
(
y
-
last
_y
);
last
_x
=
static_cast
<
int
>
(
x
);
last
_y
=
static_cast
<
int
>
(
y
);
float
dx
=
float
(
x
-
last
X
);
float
dy
=
float
(
y
-
last
Y
);
last
X
=
static_cast
<
int
>
(
x
);
last
Y
=
static_cast
<
int
>
(
y
);
if
(
is
_r
otating
)
{
angle
_d
irection
+=
dx
*
angle
_s
ensitivity
;
angle
_e
levation
+=
dy
*
angle
_s
ensitivity
;
if
(
is
R
otating
)
{
angle
D
irection
+=
dx
*
angle
S
ensitivity
;
angle
E
levation
+=
dy
*
angle
S
ensitivity
;
// Clamp the results
if
(
angle
_e
levation
>
max
_e
levation
)
angle
_e
levation
=
max
_e
levation
;
if
(
angle
_e
levation
<
min
_e
levation
)
angle
_e
levation
=
min
_e
levation
;
if
(
angle
E
levation
>
max
E
levation
)
angle
E
levation
=
max
E
levation
;
if
(
angle
E
levation
<
min
E
levation
)
angle
E
levation
=
min
E
levation
;
}
if
(
is
_z
ooming
)
{
distance
*=
(
1.0
f
+
dy
*
zoom
_s
ensitivity
);
if
(
is
Z
ooming
)
{
distance
*=
(
1.0
f
+
dy
*
zoom
S
ensitivity
);
// Clamp the results
if
(
distance
<
min
_d
istance
)
distance
=
min
_d
istance
;
if
(
distance
<
min
D
istance
)
distance
=
min
D
istance
;
}
update_eye_pos
();
}
glm
::
vec3
RotateCamera
::
get_eye_position
()
const
{
return
eye_position
;
updateEyePos
();
}
This diff is collapsed.
Click to expand it.
src/application.cpp
+
6
−
6
View file @
bda71f63
...
...
@@ -4,9 +4,9 @@ Application::Application(size_t initialWidth, size_t initialHeight) {
this
->
width
=
initialWidth
;
this
->
height
=
initialHeight
;
cameraUbo
.
position
=
glm
::
vec4
(
camera
.
get
_eye_p
osition
(),
1.0
f
);
cameraUbo
.
position
=
glm
::
vec4
(
camera
.
get
EyeP
osition
(),
1.0
f
);
cameraUbo
.
projection
=
glm
::
perspective
(
glm
::
radians
(
45.0
f
),
float
(
width
)
/
float
(
height
),
0.01
f
,
1000.0
f
);
cameraUbo
.
view
=
glm
::
lookAt
(
camera
.
get
_eye_p
osition
(),
glm
::
vec3
(
0.0
f
,
0.0
f
,
0.0
f
),
glm
::
vec3
(
0.0
f
,
1.0
f
,
0.0
f
));
cameraUbo
.
view
=
glm
::
lookAt
(
camera
.
get
EyeP
osition
(),
glm
::
vec3
(
0.0
f
,
0.0
f
,
0.0
f
),
glm
::
vec3
(
0.0
f
,
1.0
f
,
0.0
f
));
LightUBO
directionalLight
;
directionalLight
.
position
=
glm
::
vec4
(
1.0
f
,
1.0
f
,
1.0
f
,
0.0
f
);
...
...
@@ -92,9 +92,9 @@ void Application::render() {
// Camera
glm
::
vec3
cameraPosition
;
if
(
followedProbe
)
{
cameraPosition
=
glm
::
vec3
(
*
followedProbe
*
glm
::
vec4
(
camera
.
get
_eye_p
osition
(),
1.0
f
));
cameraPosition
=
glm
::
vec3
(
*
followedProbe
*
glm
::
vec4
(
camera
.
get
EyeP
osition
(),
1.0
f
));
}
else
{
cameraPosition
=
camera
.
get
_eye_p
osition
();
cameraPosition
=
camera
.
get
EyeP
osition
();
}
cameraUbo
.
position
=
glm
::
vec4
(
cameraPosition
,
1.0
f
);
cameraUbo
.
view
=
glm
::
lookAt
(
cameraPosition
,
glm
::
vec3
(
0.0
f
,
0.0
f
,
0.0
f
),
glm
::
vec3
(
0.0
f
,
1.0
f
,
0.0
f
));
...
...
@@ -197,10 +197,10 @@ void Application::onResize(GLFWwindow *window, int width, int height) {
//glNamedFramebufferTexture(postprocessFramebuffer, GL_DEPTH_ATTACHMENT, postprocessFramebufferDepth, 0);
}
void
Application
::
onMouseMove
(
GLFWwindow
*
window
,
double
x
,
double
y
)
{
camera
.
on
_m
ouse
_m
ove
(
x
,
y
);
camera
.
on
M
ouse
M
ove
(
x
,
y
);
}
void
Application
::
onMousePressed
(
GLFWwindow
*
window
,
int
button
,
int
action
,
int
mods
)
{
camera
.
on
_m
ouse
_b
utton
(
button
,
action
,
mods
);
camera
.
on
M
ouse
B
utton
(
button
,
action
,
mods
);
}
void
Application
::
onKeyPressed
(
GLFWwindow
*
window
,
int
key
,
int
scancode
,
int
action
,
int
mods
)
{
switch
(
key
)
{
...
...
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