Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Game Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Game Development
Game Library
Commits
5792db23
Commit
5792db23
authored
3 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
use NDC for mouse axis
parent
6cc0b228
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
demo/main.cpp
+5
-5
5 additions, 5 deletions
demo/main.cpp
fggl/gfx/window.cpp
+9
-3
9 additions, 3 deletions
fggl/gfx/window.cpp
with
14 additions
and
8 deletions
demo/main.cpp
+
5
−
5
View file @
5792db23
...
...
@@ -55,7 +55,7 @@ camera_type cam_mode = cam_free;
using
namespace
fggl
::
input
;
using
InputManager
=
std
::
shared_ptr
<
fggl
::
input
::
Input
>
;
void
process_arcball
(
fggl
::
gfx
::
Window
&
window
,
fggl
::
ecs
::
ECS
&
ecs
,
InputManager
input
,
fggl
::
ecs
::
entity_t
cam
)
{
void
process_arcball
(
fggl
::
ecs
::
ECS
&
ecs
,
InputManager
input
,
fggl
::
ecs
::
entity_t
cam
)
{
// see https://asliceofrendering.com/camera/2019/11/30/ArcballCamera/
auto
camTransform
=
ecs
.
getComponent
<
fggl
::
math
::
Transform
>
(
cam
);
auto
camComp
=
ecs
.
getComponent
<
fggl
::
gfx
::
Camera
>
(
cam
);
...
...
@@ -67,8 +67,8 @@ void process_arcball(fggl::gfx::Window& window, fggl::ecs::ECS& ecs, InputManage
glm
::
vec3
viewDir
=
-
glm
::
transpose
(
view
)[
2
];
glm
::
vec3
rightDir
=
glm
::
transpose
(
view
)[
0
];
float
deltaAngleX
=
(
2
*
M_PI
/
window
.
width
()
);
float
deltaAngleY
=
(
M_PI
/
window
.
height
()
);
float
deltaAngleX
=
(
2
*
M_PI
);
float
deltaAngleY
=
(
M_PI
);
float
xAngle
=
(
-
mouse
.
axisDelta
(
fggl
::
input
::
MouseAxis
::
X
)
)
*
deltaAngleX
;
float
yAngle
=
(
-
mouse
.
axisDelta
(
fggl
::
input
::
MouseAxis
::
Y
)
)
*
deltaAngleY
;
...
...
@@ -170,14 +170,14 @@ void process_camera(fggl::gfx::Window& window, fggl::ecs::ECS& ecs, InputManager
// scroll wheel
glm
::
vec3
motion
(
0.0
f
);
float
delta
=
input
->
mouse
.
axis
Delta
(
fggl
::
input
::
MouseAxis
::
SCROLL_Y
);
float
delta
=
input
->
mouse
.
axis
(
fggl
::
input
::
MouseAxis
::
SCROLL_Y
);
if
(
(
glm
::
length
(
dir
)
<
25.0
f
&&
delta
<
0.0
f
)
||
(
glm
::
length
(
dir
)
>
2.5
f
&&
delta
>
0.0
f
)
)
motion
-=
(
forward
*
delta
);
camTransform
->
origin
(
camTransform
->
origin
()
+
motion
);
if
(
cam_mode
==
cam_arcball
||
input
->
mouse
.
button
(
fggl
::
input
::
MouseButton
::
MIDDLE
)
)
{
process_arcball
(
window
,
ecs
,
input
,
cam
);
process_arcball
(
ecs
,
input
,
cam
);
}
else
if
(
cam_mode
==
cam_free
)
{
process_freecam
(
ecs
,
input
,
cam
);
}
...
...
This diff is collapsed.
Click to expand it.
fggl/gfx/window.cpp
+
9
−
3
View file @
5792db23
#include
"window.hpp"
#include
"window_input.hpp"
...
...
@@ -6,8 +5,6 @@
#include
<string>
#include
<stdexcept>
#include
<GLFW/glfw3.h>
using
namespace
fggl
::
gfx
;
static
void
glfw_error
(
int
code
,
const
char
*
description
)
{
...
...
@@ -24,6 +21,15 @@ static void framebuffer_resize(GLFWwindow* window, int width, int height) {
static
void
fggl_input_cursor
(
GLFWwindow
*
window
,
double
x
,
double
y
)
{
auto
&
input
=
GlfwInputManager
::
instance
();
auto
fgglWin
=
(
Window
*
)
glfwGetWindowUserPointer
(
window
);
#ifndef FGGL_INPUT_SCREEN_COORDS
// convert to nice ranges...
x
=
(
x
/
fgglWin
->
width
()
*
2
)
-
1.0
;
// [-1, 1]
y
=
(
y
/
fgglWin
->
height
()
*
2
)
-
1.0
;
// [-1, 1]
#endif
// inform the input system
input
.
onMouseMove
(
x
,
y
);
}
...
...
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