Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RBComb Sample Visualizer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Pascal Engeler
RBComb Sample Visualizer
Commits
4808969a
Commit
4808969a
authored
1 year ago
by
Pascal Engeler
Browse files
Options
Downloads
Patches
Plain Diff
Added input polling
parent
4982c82d
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
gui/include/input_state.hpp
+33
-0
33 additions, 0 deletions
gui/include/input_state.hpp
gui/src/input_state.cpp
+135
-0
135 additions, 0 deletions
gui/src/input_state.cpp
gui/src/main.cpp
+16
-4
16 additions, 4 deletions
gui/src/main.cpp
with
184 additions
and
4 deletions
gui/include/input_state.hpp
0 → 100644
+
33
−
0
View file @
4808969a
#pragma once
#include
<SDL.h>
class
InputState
{
public:
static
void
update
(
const
unsigned
width
,
const
unsigned
height
);
//state of mouse buttons
static
bool
mwheel_pressed
;
static
bool
lmb_pressed
;
static
bool
lmb_click
;
static
bool
rmb_pressed
;
//state of tracked keyboard buttons
static
bool
esc_click
;
//esc is down
//mouse position
static
float
mpos_x
;
static
float
mpos_y
;
static
unsigned
umpos_x
;
static
unsigned
umpos_y
;
//relative mouse motion
static
float
mmot_x
;
static
float
mmot_y
;
//relative mouse wheel motion
static
float
mwheelmot_y
;
//quit event
static
bool
should_quit
;
};
This diff is collapsed.
Click to expand it.
gui/src/input_state.cpp
0 → 100644
+
135
−
0
View file @
4808969a
#include
<input_state.hpp>
#include
<iostream>
#include
<imgui_bundle.hpp>
bool
InputState
::
mwheel_pressed
=
false
;
bool
InputState
::
lmb_pressed
=
false
;
bool
InputState
::
lmb_click
=
false
;
bool
InputState
::
rmb_pressed
=
false
;
bool
InputState
::
esc_click
=
false
;
float
InputState
::
mpos_x
=
0.
f
;
float
InputState
::
mpos_y
=
0.
f
;
unsigned
InputState
::
umpos_x
=
0
;
unsigned
InputState
::
umpos_y
=
0
;
float
InputState
::
mmot_x
=
0.
f
;
float
InputState
::
mmot_y
=
0.
f
;
float
InputState
::
mwheelmot_y
=
0.
f
;
bool
InputState
::
should_quit
=
false
;
void
InputState
::
update
(
const
unsigned
width
,
const
unsigned
height
)
{
//reset relative data
mmot_x
=
0.
f
;
mmot_y
=
0.
f
;
mwheelmot_y
=
0.
f
;
lmb_click
=
false
;
esc_click
=
false
;
SDL_Event
event
;
while
(
SDL_PollEvent
(
&
event
))
{
/*Hand event off to ImGui*/
ImGui_ImplSDL2_ProcessEvent
(
&
event
);
if
(
ImGui
::
GetIO
().
WantCaptureMouse
)
{
continue
;
}
switch
(
event
.
type
)
{
case
SDL_QUIT
:
should_quit
=
true
;
break
;
case
SDL_MOUSEMOTION
:
mpos_x
=
event
.
motion
.
x
/
static_cast
<
float
>
(
width
);
mpos_y
=
1.
-
event
.
motion
.
y
/
static_cast
<
float
>
(
height
);
umpos_x
=
event
.
motion
.
x
;
umpos_y
=
event
.
motion
.
y
;
mmot_x
=
event
.
motion
.
xrel
/
static_cast
<
float
>
(
width
);
mmot_y
=
-
event
.
motion
.
yrel
/
static_cast
<
float
>
(
height
);
#ifndef NDEBUG
std
::
cout
<<
"Mouse Motion: "
<<
"("
<<
event
.
motion
.
x
<<
", "
<<
event
.
motion
.
y
<<
"), "
<<
"("
<<
event
.
motion
.
xrel
<<
", "
<<
event
.
motion
.
yrel
<<
"), "
<<
event
.
motion
.
state
<<
std
::
endl
;
#endif
break
;
case
SDL_MOUSEBUTTONDOWN
:
switch
(
event
.
button
.
button
)
{
case
SDL_BUTTON_LEFT
:
#ifndef NDEBUG
std
::
cout
<<
"LMB Pressed"
<<
std
::
endl
<<
std
::
flush
;
#endif
lmb_pressed
=
true
;
lmb_click
=
true
;
break
;
case
SDL_BUTTON_RIGHT
:
#ifndef NDEBUG
std
::
cout
<<
"RMB Pressed"
<<
std
::
endl
<<
std
::
flush
;
#endif
rmb_pressed
=
true
;
break
;
case
SDL_BUTTON_MIDDLE
:
#ifndef NDEBUG
std
::
cout
<<
"MWHEEL Pressed"
<<
std
::
endl
<<
std
::
flush
;
#endif
mwheel_pressed
=
true
;
break
;
default:
break
;
}
#ifndef NDEBUG
std
::
cout
<<
"Mousebutton Down: "
<<
"("
<<
event
.
button
.
x
<<
", "
<<
event
.
button
.
y
<<
"), "
<<
event
.
button
.
state
<<
", "
<<
event
.
button
.
which
<<
std
::
endl
;
#endif
break
;
case
SDL_MOUSEBUTTONUP
:
switch
(
event
.
button
.
button
)
{
case
SDL_BUTTON_LEFT
:
#ifndef NDEBUG
std
::
cout
<<
"LMB Released"
<<
std
::
endl
<<
std
::
flush
;
#endif
lmb_pressed
=
false
;
break
;
case
SDL_BUTTON_RIGHT
:
#ifndef NDEBUG
std
::
cout
<<
"RMB Released"
<<
std
::
endl
<<
std
::
flush
;
#endif
rmb_pressed
=
false
;
break
;
case
SDL_BUTTON_MIDDLE
:
#ifndef NDEBUG
std
::
cout
<<
"MWHEEL Released"
<<
std
::
endl
<<
std
::
flush
;
#endif
mwheel_pressed
=
false
;
break
;
default:
break
;
}
#ifndef NDEBUG
std
::
cout
<<
"Mousebutton Up: "
<<
"("
<<
event
.
button
.
x
<<
", "
<<
event
.
button
.
y
<<
"), "
<<
event
.
button
.
state
<<
", "
<<
event
.
button
.
which
<<
std
::
endl
;
#endif
break
;
case
SDL_MOUSEWHEEL
:
#ifndef NDEBUG
std
::
cout
<<
"Mousewheel Scrolled: "
<<
event
.
wheel
.
y
<<
std
::
endl
;
#endif
mwheelmot_y
=
static_cast
<
float
>
(
event
.
wheel
.
y
);
break
;
case
SDL_KEYDOWN
:
#ifndef NDEBUG
std
::
cout
<<
"Keypress: "
<<
static_cast
<
int
>
(
event
.
key
.
keysym
.
sym
)
<<
std
::
endl
;
#endif
if
(
event
.
key
.
keysym
.
sym
==
SDLK_ESCAPE
)
{
if
(
event
.
key
.
type
==
SDL_KEYDOWN
)
{
esc_click
=
true
;
}
}
break
;
default
:
break
;
}
}
}
This diff is collapsed.
Click to expand it.
gui/src/main.cpp
+
16
−
4
View file @
4808969a
...
...
@@ -4,6 +4,7 @@
#include
<camera_arcball.hpp>
#include
<layer.hpp>
#include
<imgui_bundle.hpp>
#include
<input_state.hpp>
#include
<screendefs.hpp>
...
...
@@ -25,7 +26,7 @@ int main(int argc, char** argv) {
glm
::
vec3
lookAt
(
0.
,
0.
,
0.
);
glm
::
vec3
eye
(
0.
,
-
0.5
,
5
0.
);
glm
::
vec3
eye
(
0.
,
-
0.5
,
9
0.
);
glm
::
vec3
upVector
(
0.
,
0.
,
1.
);
Camera
camera
(
eye
,
lookAt
,
upVector
);
...
...
@@ -47,23 +48,34 @@ int main(int argc, char** argv) {
size_t
count
=
0
;
auto
start
=
std
::
chrono
::
high_resolution_clock
::
now
();
while
(
true
)
{
while
(
!
InputState
::
should_quit
)
{
++
count
;
//number of frames processed
InputState
::
update
(
WIDTH
,
HEIGHT
);
if
(
InputState
::
rmb_pressed
)
{
//panning
}
else
if
(
InputState
::
esc_click
)
{
//reset view and selection
}
else
if
(
InputState
::
lmb_click
)
{
//select object
}
/*New Gui Frame*/
ImGui_ImplOpenGL3_NewFrame
();
ImGui_ImplSDL2_NewFrame
(
infra
.
window
());
ImGui
::
NewFrame
();
glClearColor
(
0.2
f
,
0.3
f
,
0.3
f
,
1.0
f
);
glClearColor
(
78.
/
255
,
97.
/
255.
,
117.
/
255.
,
1.0
f
);
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
/*Update projection, view, model*/
/*Draw here*/
int
drawing_mode
=
1
;
int
drawing_mode
=
0
;
int
index_selected
=
-
1
;
bottom_metal
.
draw
(
projection
,
view
,
model
,
drawing_mode
,
index_selected
);
...
...
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