Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VkCV Framework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor 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
Vulkan2021
VkCV Framework
Commits
0f9d1e87
Verified
Commit
0f9d1e87
authored
3 years ago
by
Josch Morgenstern
Browse files
Options
Downloads
Patches
Plain Diff
[
#42
] remove window and camera from PilotCameraController
parent
0e7d48c8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!35
Resolve "Kamera - Trackballkamera"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/camera/include/vkcv/camera/PilotCameraController.hpp
+9
-15
9 additions, 15 deletions
modules/camera/include/vkcv/camera/PilotCameraController.hpp
modules/camera/src/vkcv/camera/PilotCameraController.cpp
+28
-44
28 additions, 44 deletions
modules/camera/src/vkcv/camera/PilotCameraController.cpp
with
37 additions
and
59 deletions
modules/camera/include/vkcv/camera/PilotCameraController.hpp
+
9
−
15
View file @
0f9d1e87
...
@@ -31,14 +31,14 @@ namespace vkcv {
...
@@ -31,14 +31,14 @@ namespace vkcv {
* @param[in] deltaTime The time that has passed since last update.
* @param[in] deltaTime The time that has passed since last update.
* @return The updated camera position.
* @return The updated camera position.
*/
*/
glm
::
vec3
updatePosition
(
double
deltaTime
);
glm
::
vec3
updatePosition
(
double
deltaTime
,
Camera
&
camera
);
/**
/**
* @brief Updates the view matrix of the camera with respect to @p deltaTime.
* @brief Updates the view matrix of the camera with respect to @p deltaTime.
* @param deltaTime The time that has passed since last update.
* @param deltaTime The time that has passed since last update.
* @return The updated view matrix of the camera.
* @return The updated view matrix of the camera.
*/
*/
glm
::
mat4
updateView
(
double
deltaTime
);
glm
::
mat4
updateView
(
double
deltaTime
,
Camera
&
camera
);
/**
/**
* @brief Indicates forward movement of the camera depending on the performed @p action.
* @brief Indicates forward movement of the camera depending on the performed @p action.
...
@@ -92,7 +92,7 @@ namespace vkcv {
...
@@ -92,7 +92,7 @@ namespace vkcv {
* @brief Changes the field of view of the camera with an @p offset in degrees.
* @brief Changes the field of view of the camera with an @p offset in degrees.
* @param[in] offset The offset in degrees.
* @param[in] offset The offset in degrees.
*/
*/
void
changeFov
(
double
offset
);
void
changeFov
(
double
offset
,
Camera
&
camera
);
/**
/**
* @brief Pans the view of the camera according to the pitch and yaw values and additional offsets @p xOffset
* @brief Pans the view of the camera according to the pitch and yaw values and additional offsets @p xOffset
...
@@ -100,19 +100,13 @@ namespace vkcv {
...
@@ -100,19 +100,13 @@ namespace vkcv {
* @param[in] xOffset The offset added to the yaw value.
* @param[in] xOffset The offset added to the yaw value.
* @param[in] yOffset The offset added to the pitch value.
* @param[in] yOffset The offset added to the pitch value.
*/
*/
void
panView
(
double
xOffset
,
double
yOffset
);
void
panView
(
double
xOffset
,
double
yOffset
,
Camera
&
camera
);
/**
* @brief Sets @p camera as the new camera object.
* @param camera The new camera object.
*/
virtual
void
setCamera
(
Camera
&
camera
);
/**
/**
* @brief Updates the camera object in respect to @p deltaTime.
* @brief Updates the camera object in respect to @p deltaTime.
* @param deltaTime The time that has passed since last update.
* @param deltaTime The time that has passed since last update.
*/
*/
void
updateCamera
(
double
deltaTime
);
void
updateCamera
(
double
deltaTime
,
Camera
&
camera
);
/**
/**
* @brief A callback function for key events. Currently, 3D camera movement via W, A, S, D, E, Q are supported.
* @brief A callback function for key events. Currently, 3D camera movement via W, A, S, D, E, Q are supported.
...
@@ -121,7 +115,7 @@ namespace vkcv {
...
@@ -121,7 +115,7 @@ namespace vkcv {
* @param[in] action The key action.
* @param[in] action The key action.
* @param[in] mods The modifier bits.
* @param[in] mods The modifier bits.
*/
*/
void
keyCallback
(
int
key
,
int
scancode
,
int
action
,
int
mods
);
void
keyCallback
(
int
key
,
int
scancode
,
int
action
,
int
mods
,
Camera
&
camera
);
/**
/**
* @brief A callback function for mouse scrolling events. Currently, this leads to changes in the field of view
* @brief A callback function for mouse scrolling events. Currently, this leads to changes in the field of view
...
@@ -129,7 +123,7 @@ namespace vkcv {
...
@@ -129,7 +123,7 @@ namespace vkcv {
* @param[in] offsetX The offset in horizontal direction.
* @param[in] offsetX The offset in horizontal direction.
* @param[in] offsetY The offset in vertical direction.
* @param[in] offsetY The offset in vertical direction.
*/
*/
void
scrollCallback
(
double
offsetX
,
double
offsetY
);
void
scrollCallback
(
double
offsetX
,
double
offsetY
,
Camera
&
camera
);
/**
/**
* @brief A callback function for mouse movement events. Currently, this leads to panning the view of the camera,
* @brief A callback function for mouse movement events. Currently, this leads to panning the view of the camera,
...
@@ -137,7 +131,7 @@ namespace vkcv {
...
@@ -137,7 +131,7 @@ namespace vkcv {
* @param[in] x The horizontal mouse position
* @param[in] x The horizontal mouse position
* @param[in] y The vertical mouse position
* @param[in] y The vertical mouse position
*/
*/
void
mouseMoveCallback
(
double
x
,
double
y
);
void
mouseMoveCallback
(
double
x
,
double
y
,
Camera
&
camera
);
/**
/**
* @brief A callback function for mouse button events. Currently, the right mouse button enables panning the
* @brief A callback function for mouse button events. Currently, the right mouse button enables panning the
...
@@ -146,7 +140,7 @@ namespace vkcv {
...
@@ -146,7 +140,7 @@ namespace vkcv {
* @param[in] action The button action
* @param[in] action The button action
* @param[in] mods The modifier bits
* @param[in] mods The modifier bits
*/
*/
void
mouseButtonCallback
(
int
button
,
int
action
,
int
mods
);
void
mouseButtonCallback
(
int
button
,
int
action
,
int
mods
,
Camera
&
camera
);
};
};
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
modules/camera/src/vkcv/camera/PilotCameraController.cpp
+
28
−
44
View file @
0f9d1e87
...
@@ -20,13 +20,10 @@ namespace vkcv {
...
@@ -20,13 +20,10 @@ namespace vkcv {
m_fov_nsteps
=
100
;
m_fov_nsteps
=
100
;
m_fov_min
=
10
;
m_fov_min
=
10
;
m_fov_max
=
120
;
m_fov_max
=
120
;
m_lastX
=
0.0
;
m_lastY
=
0.0
;
}
}
void
PilotCameraController
::
changeFov
(
double
offset
){
void
PilotCameraController
::
changeFov
(
double
offset
,
Camera
&
camera
){
float
fov
=
m_
camera
->
getFov
();
float
fov
=
camera
.
getFov
();
float
fov_range
=
m_fov_max
-
m_fov_min
;
float
fov_range
=
m_fov_max
-
m_fov_min
;
float
fov_stepsize
=
glm
::
radians
(
fov_range
)
/
static_cast
<
float
>
(
m_fov_nsteps
);
float
fov_stepsize
=
glm
::
radians
(
fov_range
)
/
static_cast
<
float
>
(
m_fov_nsteps
);
fov
-=
(
float
)
offset
*
fov_stepsize
;
fov
-=
(
float
)
offset
*
fov_stepsize
;
...
@@ -36,64 +33,59 @@ namespace vkcv {
...
@@ -36,64 +33,59 @@ namespace vkcv {
if
(
fov
>
glm
::
radians
(
m_fov_max
))
{
if
(
fov
>
glm
::
radians
(
m_fov_max
))
{
fov
=
glm
::
radians
(
m_fov_max
);
fov
=
glm
::
radians
(
m_fov_max
);
}
}
m_
camera
->
setFov
(
fov
);
camera
.
setFov
(
fov
);
}
}
void
PilotCameraController
::
panView
(
double
xOffset
,
double
yOffset
)
{
void
PilotCameraController
::
panView
(
double
xOffset
,
double
yOffset
,
Camera
&
camera
)
{
// handle yaw rotation
// handle yaw rotation
float
yaw
=
m_
camera
->
getYaw
()
+
xOffset
;
float
yaw
=
camera
.
getYaw
()
+
xOffset
;
if
(
yaw
<
-
180.0
f
)
{
if
(
yaw
<
-
180.0
f
)
{
yaw
+=
360.0
f
;
yaw
+=
360.0
f
;
}
}
else
if
(
yaw
>
180.0
f
)
{
else
if
(
yaw
>
180.0
f
)
{
yaw
-=
360.0
f
;
yaw
-=
360.0
f
;
}
}
m_
camera
->
setYaw
(
yaw
);
camera
.
setYaw
(
yaw
);
// handle pitch rotation
// handle pitch rotation
float
pitch
=
m_
camera
->
getPitch
()
-
yOffset
;
float
pitch
=
camera
.
getPitch
()
-
yOffset
;
if
(
pitch
>
89.0
f
)
{
if
(
pitch
>
89.0
f
)
{
pitch
=
89.0
f
;
pitch
=
89.0
f
;
}
}
if
(
pitch
<
-
89.0
f
)
{
if
(
pitch
<
-
89.0
f
)
{
pitch
=
-
89.0
f
;
pitch
=
-
89.0
f
;
}
}
m_
camera
->
setPitch
(
pitch
);
camera
.
setPitch
(
pitch
);
}
}
glm
::
mat4
PilotCameraController
::
updateView
(
double
deltaTime
){
glm
::
mat4
PilotCameraController
::
updateView
(
double
deltaTime
,
Camera
&
camera
){
updatePosition
(
deltaTime
);
updatePosition
(
deltaTime
,
camera
);
glm
::
vec3
position
=
m_
camera
->
getPosition
();
glm
::
vec3
position
=
camera
.
getPosition
();
glm
::
vec3
front
=
m_
camera
->
getFront
();
glm
::
vec3
front
=
camera
.
getFront
();
glm
::
vec3
up
=
m_
camera
->
getUp
();
glm
::
vec3
up
=
camera
.
getUp
();
m_
camera
->
lookAt
(
position
,
position
+
front
,
up
);
camera
.
lookAt
(
position
,
position
+
front
,
up
);
return
m_
camera
->
getView
();
return
camera
.
getView
();
}
}
glm
::
vec3
PilotCameraController
::
updatePosition
(
double
deltaTime
){
glm
::
vec3
PilotCameraController
::
updatePosition
(
double
deltaTime
,
Camera
&
camera
){
glm
::
vec3
position
=
m_
camera
->
getPosition
();
glm
::
vec3
position
=
camera
.
getPosition
();
glm
::
vec3
front
=
m_
camera
->
getFront
();
glm
::
vec3
front
=
camera
.
getFront
();
glm
::
vec3
up
=
m_
camera
->
getUp
();
glm
::
vec3
up
=
camera
.
getUp
();
position
+=
(
m_cameraSpeed
*
front
*
static_cast
<
float
>
(
m_forward
)
*
static_cast
<
float
>
(
deltaTime
));
position
+=
(
m_cameraSpeed
*
front
*
static_cast
<
float
>
(
m_forward
)
*
static_cast
<
float
>
(
deltaTime
));
position
-=
(
m_cameraSpeed
*
front
*
static_cast
<
float
>
(
m_backward
)
*
static_cast
<
float
>
(
deltaTime
));
position
-=
(
m_cameraSpeed
*
front
*
static_cast
<
float
>
(
m_backward
)
*
static_cast
<
float
>
(
deltaTime
));
position
+=
(
glm
::
normalize
(
glm
::
cross
(
front
,
up
))
*
m_cameraSpeed
*
static_cast
<
float
>
(
m_left
)
*
static_cast
<
float
>
(
deltaTime
));
position
+=
(
glm
::
normalize
(
glm
::
cross
(
front
,
up
))
*
m_cameraSpeed
*
static_cast
<
float
>
(
m_left
)
*
static_cast
<
float
>
(
deltaTime
));
position
-=
(
glm
::
normalize
(
glm
::
cross
(
front
,
up
))
*
m_cameraSpeed
*
static_cast
<
float
>
(
m_right
)
*
static_cast
<
float
>
(
deltaTime
));
position
-=
(
glm
::
normalize
(
glm
::
cross
(
front
,
up
))
*
m_cameraSpeed
*
static_cast
<
float
>
(
m_right
)
*
static_cast
<
float
>
(
deltaTime
));
position
-=
up
*
m_cameraSpeed
*
static_cast
<
float
>
(
m_upward
)
*
static_cast
<
float
>
(
deltaTime
);
position
-=
up
*
m_cameraSpeed
*
static_cast
<
float
>
(
m_upward
)
*
static_cast
<
float
>
(
deltaTime
);
position
+=
up
*
m_cameraSpeed
*
static_cast
<
float
>
(
m_downward
)
*
static_cast
<
float
>
(
deltaTime
);
position
+=
up
*
m_cameraSpeed
*
static_cast
<
float
>
(
m_downward
)
*
static_cast
<
float
>
(
deltaTime
);
m_
camera
->
setPosition
(
position
);
camera
.
setPosition
(
position
);
return
position
;
return
position
;
}
}
void
PilotCameraController
::
setCamera
(
Camera
&
camera
)
{
void
PilotCameraController
::
updateCamera
(
double
deltaTime
,
Camera
&
camera
)
{
m_camera
=
&
camera
;
updateView
(
deltaTime
,
camera
);
m_camera
->
setYaw
(
180.0
f
);
}
void
PilotCameraController
::
updateCamera
(
double
deltaTime
)
{
updateView
(
deltaTime
);
}
}
void
PilotCameraController
::
keyCallback
(
int
key
,
int
scancode
,
int
action
,
int
mods
)
{
void
PilotCameraController
::
keyCallback
(
int
key
,
int
scancode
,
int
action
,
int
mods
,
Camera
&
camera
)
{
switch
(
key
)
{
switch
(
key
)
{
case
GLFW_KEY_W
:
case
GLFW_KEY_W
:
moveForward
(
action
);
moveForward
(
action
);
...
@@ -118,17 +110,11 @@ namespace vkcv {
...
@@ -118,17 +110,11 @@ namespace vkcv {
}
}
}
}
void
PilotCameraController
::
scrollCallback
(
double
offsetX
,
double
offsetY
)
{
void
PilotCameraController
::
scrollCallback
(
double
offsetX
,
double
offsetY
,
Camera
&
camera
)
{
changeFov
(
offsetY
);
changeFov
(
offsetY
,
camera
);
}
}
void
PilotCameraController
::
mouseMoveCallback
(
double
x
,
double
y
)
{
void
PilotCameraController
::
mouseMoveCallback
(
double
xoffset
,
double
yoffset
,
Camera
&
camera
)
{
auto
xoffset
=
static_cast
<
float
>
(
x
-
m_lastX
);
auto
yoffset
=
static_cast
<
float
>
(
y
-
m_lastY
);
m_lastX
=
x
;
m_lastY
=
y
;
if
(
!
m_rotationActive
){
if
(
!
m_rotationActive
){
return
;
return
;
}
}
...
@@ -137,16 +123,14 @@ namespace vkcv {
...
@@ -137,16 +123,14 @@ namespace vkcv {
xoffset
*=
sensitivity
;
xoffset
*=
sensitivity
;
yoffset
*=
sensitivity
;
yoffset
*=
sensitivity
;
panView
(
xoffset
,
yoffset
);
panView
(
xoffset
,
yoffset
,
camera
);
}
}
void
PilotCameraController
::
mouseButtonCallback
(
int
button
,
int
action
,
int
mods
)
{
void
PilotCameraController
::
mouseButtonCallback
(
int
button
,
int
action
,
int
mods
,
Camera
&
camera
)
{
if
(
button
==
GLFW_MOUSE_BUTTON_2
&&
m_rotationActive
==
false
&&
action
==
GLFW_PRESS
){
if
(
button
==
GLFW_MOUSE_BUTTON_2
&&
m_rotationActive
==
false
&&
action
==
GLFW_PRESS
){
glfwSetInputMode
(
m_window
->
getWindow
(),
GLFW_CURSOR
,
GLFW_CURSOR_DISABLED
);
m_rotationActive
=
true
;
m_rotationActive
=
true
;
}
}
else
if
(
button
==
GLFW_MOUSE_BUTTON_2
&&
m_rotationActive
==
true
&&
action
==
GLFW_RELEASE
){
else
if
(
button
==
GLFW_MOUSE_BUTTON_2
&&
m_rotationActive
==
true
&&
action
==
GLFW_RELEASE
){
glfwSetInputMode
(
m_window
->
getWindow
(),
GLFW_CURSOR
,
GLFW_CURSOR_NORMAL
);
m_rotationActive
=
false
;
m_rotationActive
=
false
;
}
}
}
}
...
...
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