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
Branches
Branches containing commit
Tags
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 {
* @param[in] deltaTime The time that has passed since last update.
* @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.
* @param deltaTime The time that has passed since last update.
* @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.
...
...
@@ -92,7 +92,7 @@ namespace vkcv {
* @brief Changes the field of view of the camera with an @p 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
...
...
@@ -100,19 +100,13 @@ namespace vkcv {
* @param[in] xOffset The offset added to the yaw value.
* @param[in] yOffset The offset added to the pitch value.
*/
void
panView
(
double
xOffset
,
double
yOffset
);
/**
* @brief Sets @p camera as the new camera object.
* @param camera The new camera object.
*/
virtual
void
setCamera
(
Camera
&
camera
);
void
panView
(
double
xOffset
,
double
yOffset
,
Camera
&
camera
);
/**
* @brief Updates the camera object in respect to @p deltaTime.
* @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.
...
...
@@ -121,7 +115,7 @@ namespace vkcv {
* @param[in] action The key action.
* @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
...
...
@@ -129,7 +123,7 @@ namespace vkcv {
* @param[in] offsetX The offset in horizontal 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,
...
...
@@ -137,7 +131,7 @@ namespace vkcv {
* @param[in] x The horizontal 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
...
...
@@ -146,7 +140,7 @@ namespace vkcv {
* @param[in] action The button action
* @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 {
m_fov_nsteps
=
100
;
m_fov_min
=
10
;
m_fov_max
=
120
;
m_lastX
=
0.0
;
m_lastY
=
0.0
;
}
void
PilotCameraController
::
changeFov
(
double
offset
){
float
fov
=
m_
camera
->
getFov
();
void
PilotCameraController
::
changeFov
(
double
offset
,
Camera
&
camera
){
float
fov
=
camera
.
getFov
();
float
fov_range
=
m_fov_max
-
m_fov_min
;
float
fov_stepsize
=
glm
::
radians
(
fov_range
)
/
static_cast
<
float
>
(
m_fov_nsteps
);
fov
-=
(
float
)
offset
*
fov_stepsize
;
...
...
@@ -36,64 +33,59 @@ namespace vkcv {
if
(
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
float
yaw
=
m_
camera
->
getYaw
()
+
xOffset
;
float
yaw
=
camera
.
getYaw
()
+
xOffset
;
if
(
yaw
<
-
180.0
f
)
{
yaw
+=
360.0
f
;
}
else
if
(
yaw
>
180.0
f
)
{
yaw
-=
360.0
f
;
}
m_
camera
->
setYaw
(
yaw
);
camera
.
setYaw
(
yaw
);
// handle pitch rotation
float
pitch
=
m_
camera
->
getPitch
()
-
yOffset
;
float
pitch
=
camera
.
getPitch
()
-
yOffset
;
if
(
pitch
>
89.0
f
)
{
pitch
=
89.0
f
;
}
if
(
pitch
<
-
89.0
f
)
{
pitch
=
-
89.0
f
;
}
m_
camera
->
setPitch
(
pitch
);
camera
.
setPitch
(
pitch
);
}
glm
::
mat4
PilotCameraController
::
updateView
(
double
deltaTime
){
updatePosition
(
deltaTime
);
glm
::
vec3
position
=
m_
camera
->
getPosition
();
glm
::
vec3
front
=
m_
camera
->
getFront
();
glm
::
vec3
up
=
m_
camera
->
getUp
();
m_
camera
->
lookAt
(
position
,
position
+
front
,
up
);
return
m_
camera
->
getView
();
glm
::
mat4
PilotCameraController
::
updateView
(
double
deltaTime
,
Camera
&
camera
){
updatePosition
(
deltaTime
,
camera
);
glm
::
vec3
position
=
camera
.
getPosition
();
glm
::
vec3
front
=
camera
.
getFront
();
glm
::
vec3
up
=
camera
.
getUp
();
camera
.
lookAt
(
position
,
position
+
front
,
up
);
return
camera
.
getView
();
}
glm
::
vec3
PilotCameraController
::
updatePosition
(
double
deltaTime
){
glm
::
vec3
position
=
m_
camera
->
getPosition
();
glm
::
vec3
front
=
m_
camera
->
getFront
();
glm
::
vec3
up
=
m_
camera
->
getUp
();
glm
::
vec3
PilotCameraController
::
updatePosition
(
double
deltaTime
,
Camera
&
camera
){
glm
::
vec3
position
=
camera
.
getPosition
();
glm
::
vec3
front
=
camera
.
getFront
();
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_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_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_downward
)
*
static_cast
<
float
>
(
deltaTime
);
m_
camera
->
setPosition
(
position
);
camera
.
setPosition
(
position
);
return
position
;
}
void
PilotCameraController
::
setCamera
(
Camera
&
camera
)
{
m_camera
=
&
camera
;
m_camera
->
setYaw
(
180.0
f
);
}
void
PilotCameraController
::
updateCamera
(
double
deltaTime
)
{
updateView
(
deltaTime
);
void
PilotCameraController
::
updateCamera
(
double
deltaTime
,
Camera
&
camera
)
{
updateView
(
deltaTime
,
camera
);
}
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
)
{
case
GLFW_KEY_W
:
moveForward
(
action
);
...
...
@@ -118,17 +110,11 @@ namespace vkcv {
}
}
void
PilotCameraController
::
scrollCallback
(
double
offsetX
,
double
offsetY
)
{
changeFov
(
offsetY
);
void
PilotCameraController
::
scrollCallback
(
double
offsetX
,
double
offsetY
,
Camera
&
camera
)
{
changeFov
(
offsetY
,
camera
);
}
void
PilotCameraController
::
mouseMoveCallback
(
double
x
,
double
y
)
{
auto
xoffset
=
static_cast
<
float
>
(
x
-
m_lastX
);
auto
yoffset
=
static_cast
<
float
>
(
y
-
m_lastY
);
m_lastX
=
x
;
m_lastY
=
y
;
void
PilotCameraController
::
mouseMoveCallback
(
double
xoffset
,
double
yoffset
,
Camera
&
camera
)
{
if
(
!
m_rotationActive
){
return
;
}
...
...
@@ -137,16 +123,14 @@ namespace vkcv {
xoffset
*=
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
){
glfwSetInputMode
(
m_window
->
getWindow
(),
GLFW_CURSOR
,
GLFW_CURSOR_DISABLED
);
m_rotationActive
=
true
;
}
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
;
}
}
...
...
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