Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Johannes Braun
glare
Commits
f89bb3e8
Commit
f89bb3e8
authored
Aug 17, 2017
by
Johannes Braun
Browse files
Optimizations and c++17!
parent
e5b5f698
Changes
36
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
f89bb3e8
...
...
@@ -7,7 +7,11 @@ include(${CMAKE_MODULE_PATH}/setup/directory_macros.cmake)
include
(
${
CMAKE_MODULE_PATH
}
/setup/external_libraries.cmake
)
include
(
${
CMAKE_MODULE_PATH
}
/setup/macros.cmake
)
set
(
CMAKE_CXX_STANDARD 14
)
set
(
CMAKE_CXX_STANDARD 17
)
if
(
MSVC
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
/std:c++17"
)
endif
()
if
(
SYS_WINDOWS
)
add_definitions
(
"-DLOG_PLATFORM_WINDOWS"
)
...
...
CppProperties.json
0 → 100644
View file @
f89bb3e8
{
"configurations"
:
[
{
"inheritEnvironments"
:
[
"msvc_x86"
],
"name"
:
"x86-Debug"
,
"includePath"
:
[
"${env.INCLUDE}"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
libraries
\\
raytrace
\\
data"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
libraries
\\
imgui"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
libraries
\\
raytrace
\\
data
\\
collector_units"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
executables
\\
pathtracing"
],
"defines"
:
[
"WIN32"
,
"_DEBUG"
,
"UNICODE"
,
"_UNICODE"
],
"intelliSenseMode"
:
"msvc-x86"
},
{
"inheritEnvironments"
:
[
"msvc_x86"
],
"name"
:
"x86-Release"
,
"includePath"
:
[
"${env.INCLUDE}"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
libraries
\\
raytrace
\\
data"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
libraries
\\
imgui"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
libraries
\\
raytrace
\\
data
\\
collector_units"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
executables
\\
pathtracing"
],
"defines"
:
[
"WIN32"
,
"NDEBUG"
,
"UNICODE"
,
"_UNICODE"
],
"intelliSenseMode"
:
"msvc-x86"
},
{
"inheritEnvironments"
:
[
"msvc_x64"
],
"name"
:
"x64-Debug"
,
"includePath"
:
[
"${env.INCLUDE}"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
libraries
\\
raytrace
\\
data"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
libraries
\\
imgui"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
libraries
\\
raytrace
\\
data
\\
collector_units"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
executables
\\
pathtracing"
],
"defines"
:
[
"WIN32"
,
"_DEBUG"
,
"UNICODE"
,
"_UNICODE"
],
"intelliSenseMode"
:
"msvc-x64"
},
{
"inheritEnvironments"
:
[
"msvc_x64"
],
"name"
:
"x64-Release"
,
"includePath"
:
[
"${env.INCLUDE}"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
libraries
\\
raytrace
\\
data"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
libraries
\\
imgui"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
libraries
\\
raytrace
\\
data
\\
collector_units"
,
"c:
\\
Users
\\
johannesbraun
\\
Desktop
\\
glare
\\
src
\\
executables
\\
pathtracing"
],
"defines"
:
[
"WIN32"
,
"NDEBUG"
,
"UNICODE"
,
"_UNICODE"
],
"intelliSenseMode"
:
"msvc-x64"
}
]
}
\ No newline at end of file
assets/preferences/default.xml
View file @
f89bb3e8
<settings
version=
"2.0"
>
<group
name=
"config"
>
<item
name=
"window_title"
value=
"GLARE - An OpenGL and Raytracing
Framework
"
/>
<item
name=
"window_title"
value=
"GLARE - An OpenGL and Raytracing
Engine
"
/>
<item
name=
"window_size_x"
value=
"1440"
/>
<item
name=
"window_size_y"
value=
"900"
/>
<item
name=
"vsync"
value=
"0"
/>
<item
name=
"msaa"
value=
"
4
"
/>
<item
name=
"msaa"
value=
"
1
"
/>
</group>
<item
name=
"splash_screen"
value=
"/preferences/splash_01.xml"
/>
...
...
src/executables/game/main.cpp
View file @
f89bb3e8
...
...
@@ -9,6 +9,7 @@
#include
<components/PlayerController.h>
#include
<components/FramerateCounter.h>
#include
<core/time.h>
#include
"src/map.h"
using
namespace
glare
;
...
...
@@ -58,11 +59,11 @@ int main(int argc, char* argv[])
core
::
state
::
graph_root
->
attach
(
lighting_node
);
// Start it up!
glare
::
core
::
state
::
mainLoop
([
&
](
double
delta
)
glare
::
core
::
state
::
mainLoop
([
&
]()
{
// Rotate the sun on keypress
if
(
controls
::
keyState
(
controls
::
Key
::
eF
)
==
controls
::
ButtonAction
::
ePress
)
{
sun_node
->
transform
.
rotate
({
glm
::
radians
(
80.
f
)
*
delta
,
0
,
0
});
sun_node
->
transform
.
rotate
({
glm
::
radians
(
80.
f
)
*
glare
::
core
::
Time
::
deltaTime
()
,
0
,
0
});
}
// Set the light position to the player camera position
...
...
src/executables/hdr_viewer/main.cpp
View file @
f89bb3e8
...
...
@@ -42,7 +42,7 @@ int main(int argc, char* argv[])
core
::
Program
heatmap_generator
(
files
::
shader
(
"/heatmap/heatmap.comp"
));
core
::
state
::
mainLoop
([
&
texture_renderer
,
&
image
,
&
heatmap_other_image
,
&
heatmap
,
&
heatmap_generator
](
double
)
core
::
state
::
mainLoop
([
&
texture_renderer
,
&
image
,
&
heatmap_other_image
,
&
heatmap
,
&
heatmap_generator
]()
{
static
int
current_tab
=
0
;
...
...
src/executables/just_testing/main.cpp
View file @
f89bb3e8
#include
<core/base/program.h>
#include
<core/rendering/texture_renderer.h>
#include
<core/state.h>
#include
<core/res/resources.h>
#include
<any>
#include
<vector>
#include
<util/files.h>
#include
<util/images.h>
#include
<iostream>
std
::
vector
<
std
::
any
>
anystuff
;
using
namespace
glare
;
int
main
(
int
argc
,
char
*
argv
[])
void
[[
deprecated
]]
bla
()
{
core
::
state
::
initialize
(
files
::
asset
(
"/preferences/default.xml"
));
auto
texture_renderer
=
core
::
DefaultTextureRenderers
::
makeSimpleRenderer
();
while
(
true
)
{
std
::
cout
<<
"Put in your first HDR image and press enter: "
;
std
::
string
link_to_first_hdr
;
std
::
cin
>>
link_to_first_hdr
;
if
(
link_to_first_hdr
==
""
)
break
;
std
::
cout
<<
"Put in your second HDR image and press enter: "
;
std
::
string
link_to_second_hdr
;
std
::
cin
>>
link_to_second_hdr
;
auto
first
=
core
::
Resources
::
getInstance
().
getTextureHDR
(
link_to_first_hdr
);
auto
second
=
core
::
Resources
::
getInstance
().
getTextureHDR
(
link_to_second_hdr
);
assert
(
first
->
getSize
()
==
second
->
getSize
());
auto
result
=
std
::
make_shared
<
core
::
TextureRGBA_32F
>
(
first
->
getSize
().
x
,
first
->
getSize
().
y
);
}
core
::
Program
heatmap_generator
(
files
::
shader
(
"/heatmap/heatmap.comp"
));
heatmap_generator
.
use
();
heatmap_generator
.
uniform
(
"u_first_image"
,
first
->
makeImageResident
(
gl
::
Access
::
eReadOnly
));
heatmap_generator
.
uniform
(
"u_second_image"
,
second
->
makeImageResident
(
gl
::
Access
::
eReadOnly
));
heatmap_generator
.
uniform
(
"u_result_heatmap"
,
result
->
makeImageResident
(
gl
::
Access
::
eWriteOnly
));
heatmap_generator
.
dispatch2d
(
first
->
getSize
().
x
,
24
,
first
->
getSize
().
y
,
24
);
auto
out_name
=
fs
::
path
(
link_to_first_hdr
).
filename
().
string
()
+
"++++"
+
fs
::
path
(
link_to_second_hdr
).
filename
().
string
()
+
".png"
;
core
::
textures
::
saveTexture
(
files
::
asset
(
"/screenshots/"
)
/
out_name
,
*
result
);
int
main
()
{
anystuff
.
push_back
(
std
::
make_any
<
int
>
(
10
));
bla
();
core
::
state
::
mainLoop
([
&
texture_renderer
,
&
result
](
double
)
{
texture_renderer
->
draw
(
*
result
);
});
}
system
(
"pause"
)
;
bool
b
=
true
;
}
\ No newline at end of file
src/executables/minimal_gui/main.cpp
View file @
f89bb3e8
...
...
@@ -23,7 +23,7 @@ int main(int argc, char* argv[])
core
::
state
::
camera
->
owner
()
->
makeComponent
<
component
::
PlayerController
>
();
// Render the scene with the pathtracer
core
::
state
::
mainLoop
([](
double
delta
)
{
core
::
state
::
mainLoop
([]()
{
gui
();
});
}
...
...
src/executables/minimal_opengl/main.cpp
View file @
f89bb3e8
...
...
@@ -24,5 +24,5 @@ int main(int argc, char* argv[])
core
::
state
::
camera
->
owner
()
->
makeComponent
<
component
::
PlayerController
>
();
// Render the scene with the pathtracer
core
::
state
::
mainLoop
([](
double
delta
)
{
core
::
state
::
draw
(
core
::
state
::
DrawMode
::
eGBuffer
);
});
core
::
state
::
mainLoop
([]()
{
core
::
state
::
draw
(
core
::
state
::
DrawMode
::
eGBuffer
);
});
}
\ No newline at end of file
src/executables/minimal_pathtracer/main.cpp
View file @
f89bb3e8
...
...
@@ -25,5 +25,5 @@ int main(int argc, char* argv[])
const
auto
pathtracer
=
std
::
make_unique
<
raytrace
::
Pathtracer
>
(
core
::
state
::
graph_root
);
// Render the scene with the pathtracer
core
::
state
::
mainLoop
([
&
pathtracer
](
double
delta
)
{
pathtracer
->
draw
();
});
core
::
state
::
mainLoop
([
&
pathtracer
]()
{
pathtracer
->
draw
();
});
}
\ No newline at end of file
src/executables/pathtracing/main.cpp
View file @
f89bb3e8
...
...
@@ -74,7 +74,7 @@ int main(int argc, char* argv[])
// For debug purposes, add a frame rate counter to the root node, which will never be deleted/removed on runtime if not explicitly told so.
core
::
state
::
graph_root
->
makeComponent
<
component
::
FramerateCounter
>
();
core
::
state
::
mainLoop
([
&
](
double
delta
)
core
::
state
::
mainLoop
([
&
]()
{
switch
(
render_mode
)
{
...
...
@@ -111,6 +111,7 @@ void keyPress(controls::Key key, controls::KeyMods mods)
void
loadScene
(
const
fs
::
path
&
path
,
float
scale
)
{
// Ain't no need for the last scene anymore.
bool
had_player_controller
=
core
::
state
::
graph_root
->
find
<
component
::
PlayerController
>
()
!=
nullptr
;
core
::
state
::
graph_root
->
clearChildren
();
//Initialize some scene graph from an obj file
...
...
@@ -138,8 +139,9 @@ void loadScene(const fs::path& path, float scale)
core
::
state
::
graph_root
->
attach
(
cam_node
);
}
//Attach a PlayerController to the current main camera, so we can fly around in the scene.
cam_node
->
makeComponent
<
component
::
PlayerController
>
();
if
(
!
had_player_controller
)
cam_node
->
makeComponent
<
component
::
PlayerController
>
();
// Reload Pathtracer if used.
if
(
pathtracer
&&
pathtracer
->
collector
())
...
...
src/libraries/components/FramerateCounter.cpp
View file @
f89bb3e8
...
...
@@ -4,33 +4,30 @@
#include
<util/log.h>
#include
<imgui/imgui_glfw.h>
namespace
glare
namespace
glare
::
component
{
namespace
component
void
FramerateCounter
::
update
()
{
void
FramerateCounter
::
update
()
{
frame
++
;
time
+=
core
::
Time
::
deltaTime
();
frame
++
;
time
+=
core
::
Time
::
deltaTime
();
if
(
time
>=
1
)
{
fps
=
static_cast
<
float
>
(
frame
);
frametime
=
static_cast
<
float
>
(
1000
*
time
/
frame
);
Log_Debug
<<
std
::
to_string
(
frame
)
<<
" FPS | "
<<
std
::
to_string
(
1000
*
time
/
frame
)
<<
"ms/Frame"
;
time
=
0
;
frame
=
0
;
}
if
(
time
>=
1
)
{
fps
=
static_cast
<
float
>
(
frame
);
frametime
=
static_cast
<
float
>
(
1000
*
time
/
frame
);
Log_Debug
<<
std
::
to_string
(
frame
)
<<
" FPS | "
<<
std
::
to_string
(
1000
*
time
/
frame
)
<<
"ms/Frame"
;
time
=
0
;
frame
=
0
;
}
#if _DEBUG
const
std
::
string
build_type
=
"Debug build | "
;
const
std
::
string
build_type
=
"Debug build | "
;
#elif NDEBUG
const
std
::
string
build_type
=
"Release build | "
;
const
std
::
string
build_type
=
"Release build | "
;
#endif
ImGui
::
Begin
(
"Debug"
);
ImGui
::
Text
((
build_type
+
std
::
to_string
(
fps
)
+
"fps | "
+
std
::
to_string
(
frametime
)
+
"ms/Frame"
).
c_str
());
ImGui
::
End
();
}
ImGui
::
Begin
(
"Debug"
);
ImGui
::
Text
((
build_type
+
std
::
to_string
(
fps
)
+
"fps | "
+
std
::
to_string
(
frametime
)
+
"ms/Frame"
).
c_str
());
ImGui
::
End
();
}
}
\ No newline at end of file
src/libraries/components/FramerateCounter.h
View file @
f89bb3e8
...
...
@@ -3,22 +3,19 @@
#include
<core/graph/component.h>
namespace
glare
namespace
glare
::
component
{
namespace
c
omponent
class
FramerateCounter
:
public
core
::
GraphNodeC
omponent
{
class
FramerateCounter
:
public
core
::
GraphNodeComponent
{
public:
void
update
()
override
;
public:
void
update
()
override
;
private:
float
fps
=
0
;
float
frametime
=
0
;
double
time
=
0
;
int
frame
=
0
;
};
}
private:
float
fps
=
0
;
float
frametime
=
0
;
double
time
=
0
;
int
frame
=
0
;
};
}
#endif //__FRAMERATECOUNTER_H
src/libraries/components/PlayerController.cpp
View file @
f89bb3e8
...
...
@@ -6,112 +6,120 @@
#include
<imgui/imgui_glfw.h>
#include
<core/message_tags.h>
namespace
glare
namespace
glare
::
component
{
namespace
component
size_t
PlayerController
::
s_current_id
=
0
;
PlayerController
::
PlayerController
()
:
m_id
(
s_current_id
++
)
{
size_t
PlayerController
::
s_current_id
=
0
;
core
::
Callbacks
::
addKeyActionCallback
(
"player_controller"
+
std
::
to_string
(
m_id
),
std
::
bind
(
&
PlayerController
::
onKeyAction
,
this
,
std
::
placeholders
::
_1
,
std
::
placeholders
::
_2
,
std
::
placeholders
::
_3
));
core
::
Callbacks
::
addMouseButtonCallback
(
"player_controller"
+
std
::
to_string
(
m_id
),
std
::
bind
(
&
PlayerController
::
onMouseButtonAction
,
this
,
std
::
placeholders
::
_1
,
std
::
placeholders
::
_2
,
std
::
placeholders
::
_3
));
PlayerController
::
PlayerController
()
:
m_id
(
s_current_id
++
)
{
core
::
Callbacks
::
addKeyActionCallback
(
"player_controller"
+
std
::
to_string
(
m_id
),
std
::
bind
(
&
PlayerController
::
onKeyAction
,
this
,
std
::
placeholders
::
_1
,
std
::
placeholders
::
_2
,
std
::
placeholders
::
_3
));
core
::
Callbacks
::
addMouseButtonCallback
(
"player_controller"
+
std
::
to_string
(
m_id
),
std
::
bind
(
&
PlayerController
::
onMouseButtonAction
,
this
,
std
::
placeholders
::
_1
,
std
::
placeholders
::
_2
,
std
::
placeholders
::
_3
));
registerForMessage
(
tags
::
camera
);
}
registerForMessage
(
tags
::
camera
);
PlayerController
::~
PlayerController
()
{
try
{
core
::
Callbacks
::
removeKeyActionCallback
(
"player_controller"
+
std
::
to_string
(
m_id
));
core
::
Callbacks
::
removeMouseButtonCallback
(
"player_controller"
+
std
::
to_string
(
m_id
));
unregisterForMessage
(
tags
::
camera
);
}
PlayerController
::~
PlayerController
()
catch
(...)
{
try
{
core
::
Callbacks
::
removeKeyActionCallback
(
"player_controller"
+
std
::
to_string
(
m_id
));
core
::
Callbacks
::
removeMouseButtonCallback
(
"player_controller"
+
std
::
to_string
(
m_id
));
unregisterForMessage
(
tags
::
camera
);
}
catch
(...)
{
}
}
}
void
PlayerController
::
handle
(
messaging
::
message_t
&
message
)
bool
PlayerController
::
isPossessed
()
const
{
return
core
::
state
::
camera
->
owner
()
==
owner
();
}
void
PlayerController
::
handle
(
messaging
::
message_t
&
message
)
{
switch
(
message
.
name
)
{
switch
(
message
.
name
)
{
case
tags
::
camera
:
case
tags
::
camera
:
{
if
(
owner
()
!=
core
::
state
::
camera
->
owner
())
{
if
(
owner
()
!=
core
::
state
::
camera
->
owner
())
{
core
::
state
::
camera
->
owner
()
->
addComponent
(
detachAs
<
PlayerController
>
());
}
}
break
;
core
::
state
::
camera
->
owner
()
->
addComponent
(
detachAs
<
PlayerController
>
());
}
}
break
;
}
}
void
PlayerController
::
onKeyAction
(
controls
::
Key
key
,
controls
::
ButtonAction
action
,
controls
::
KeyMods
mods
)
void
PlayerController
::
onKeyAction
(
controls
::
Key
key
,
controls
::
ButtonAction
action
,
controls
::
KeyMods
mods
)
{
if
(
isPossessed
()
&&
action
==
controls
::
ButtonAction
::
ePress
)
{
if
(
action
==
controls
::
ButtonAction
::
ePress
)
switch
(
key
)
{
switch
(
key
)
{
case
controls
::
Key
::
eEscape
:
core
::
state
::
window
->
close
();
return
;
}
case
controls
::
Key
::
eEscape
:
core
::
state
::
window
->
close
();
return
;
}
}
}
void
PlayerController
::
onMouseButtonAction
(
controls
::
MouseButton
button
,
controls
::
ButtonAction
action
,
controls
::
KeyMods
mods
)
void
PlayerController
::
onMouseButtonAction
(
controls
::
MouseButton
button
,
controls
::
ButtonAction
action
,
controls
::
KeyMods
mods
)
{
if
(
isPossessed
()
&&
action
==
controls
::
ButtonAction
::
ePress
)
{
if
(
action
==
controls
::
ButtonAction
::
ePress
)
switch
(
button
)
{
switch
(
button
)
{
case
controls
::
MouseButton
::
eRight
:
controls
::
setCursorGrabbed
(
!
controls
::
isCursorGrabbed
());
return
;
}
case
controls
::
MouseButton
::
eRight
:
controls
::
setCursorGrabbed
(
!
controls
::
isCursorGrabbed
());
return
;
}
}
}
void
PlayerController
::
gui
()
void
PlayerController
::
gui
()
{
if
(
isPossessed
())
{
if
(
ImGui
::
Begin
(
"Player Controller"
,
nullptr
,
ImGuiWindowFlags_AlwaysAutoResize
))
if
(
ImGui
::
ComponentHeader
(
"Player Controller"
,
owner
()
->
name
().
c_str
(),
GraphNodeComponent
::
id
()
))
{
ImGui
::
DragFloat
(
"Movement Speed"
,
&
m_speed
,
0.5
f
);
ImGui
::
DragFloat
(
"Rotation Speed"
,
&
m_rotation_speed
,
0.01
f
);
ImGui
::
DragFloat
(
"Shift Multiplier"
,
&
m_boost
,
0.5
f
);
}
ImGui
::
End
();
}
}
void
PlayerController
::
update
()
{
auto
&&
transform
=
owner
()
->
transform
;
float
forward
=
static_cast
<
float
>
((
controls
::
keyState
(
controls
::
Key
::
eW
)
==
controls
::
ButtonAction
::
ePress
)
-
(
controls
::
keyState
(
controls
::
Key
::
eS
)
==
controls
::
ButtonAction
::
ePress
));
float
right
=
static_cast
<
float
>
((
controls
::
keyState
(
controls
::
Key
::
eD
)
==
controls
::
ButtonAction
::
ePress
)
-
(
controls
::
keyState
(
controls
::
Key
::
eA
)
==
controls
::
ButtonAction
::
ePress
));
float
up
=
static_cast
<
float
>
((
controls
::
keyState
(
controls
::
Key
::
eE
)
==
controls
::
ButtonAction
::
ePress
)
-
(
controls
::
keyState
(
controls
::
Key
::
eQ
)
==
controls
::
ButtonAction
::
ePress
));
if
(
controls
::
keyState
(
controls
::
Key
::
eLeftShift
)
==
controls
::
ButtonAction
::
ePress
)
{
forward
*=
m_boost
;
right
*=
m_boost
;
up
*=
m_boost
;
}
void
PlayerController
::
update
()
{
if
(
!
isPossessed
())
return
;
transform
.
position
+=
owner
()
->
worldTransform
().
forward
()
*
forward
*
m_speed
*
core
::
Time
::
deltaTime
()
+
owner
()
->
worldTransform
().
right
()
*
right
*
m_speed
*
core
::
Time
::
deltaTime
()
+
owner
()
->
worldTransform
().
up
()
*
up
*
m_speed
*
core
::
Time
::
deltaTime
();
auto
&&
transform
=
owner
()
->
transform
;
const
glm
::
vec2
delta
=
last_position
-
controls
::
getCursorPosition
();
last_position
=
controls
::
getCursorPosition
();
float
forward
=
static_cast
<
float
>
((
controls
::
keyState
(
controls
::
Key
::
eW
)
==
controls
::
ButtonAction
::
ePress
)
-
(
controls
::
keyState
(
controls
::
Key
::
eS
)
==
controls
::
ButtonAction
::
ePress
));
float
right
=
static_cast
<
float
>
((
controls
::
keyState
(
controls
::
Key
::
eD
)
==
controls
::
ButtonAction
::
ePress
)
-
(
controls
::
keyState
(
controls
::
Key
::
eA
)
==
controls
::
ButtonAction
::
ePress
));
float
up
=
static_cast
<
float
>
((
controls
::
keyState
(
controls
::
Key
::
eE
)
==
controls
::
ButtonAction
::
ePress
)
-
(
controls
::
keyState
(
controls
::
Key
::
eQ
)
==
controls
::
ButtonAction
::
ePress
));
if
(
controls
::
isCursorGrabbed
())
{
transform
.
rotation
=
glm
::
quat
(
glm
::
vec3
(
0.
f
,
glm
::
radians
(
delta
.
x
/
10
)
*
m_rotation_speed
,
0.
f
))
*
owner
()
->
transform
.
rotation
;
transform
.
rotation
*=
glm
::
quat
(
glm
::
vec3
(
glm
::
radians
(
delta
.
y
/
10
)
*
m_rotation_speed
,
0.
f
,
0.
f
));
}
if
(
controls
::
keyState
(
controls
::
Key
::
eLeftShift
)
==
controls
::
ButtonAction
::
ePress
)
{
forward
*=
m_boost
;
right
*=
m_boost
;
up
*=
m_boost
;
}
transform
.
position
+=
owner
()
->
worldTransform
().
forward
()
*
forward
*
m_speed
*
core
::
Time
::
deltaTime
()
+
owner
()
->
worldTransform
().
right
()
*
right
*
m_speed
*
core
::
Time
::
deltaTime
()
+
owner
()
->
worldTransform
().
up
()
*
up
*
m_speed
*
core
::
Time
::
deltaTime
();
const
glm
::
vec2
delta
=
last_position
-
controls
::
getCursorPosition
();
last_position
=
controls
::
getCursorPosition
();
if
(
controls
::
isCursorGrabbed
())
{
transform
.
rotation
=
glm
::
quat
(
glm
::
vec3
(
0.
f
,
glm
::
radians
(
delta
.
x
/
10
)
*
m_rotation_speed
,
0.
f
))
*
owner
()
->
transform
.
rotation
;
transform
.
rotation
*=
glm
::
quat
(
glm
::
vec3
(
glm
::
radians
(
delta
.
y
/
10
)
*
m_rotation_speed
,
0.
f
,
0.
f
));
}
}
}
src/libraries/components/PlayerController.h
View file @
f89bb3e8
...
...
@@ -6,36 +6,35 @@
#include
<core/graph/component.h>
#include
<core/control.h>
namespace
glare
namespace
glare
::
component
{
namespace
component
class
PlayerController
:
public
core
::
GraphNodeComponent
,
public
messaging
::
Receiver
{
class
PlayerController
:
public
core
::
GraphNodeComponent
,
public
messaging
::
Receiver
{
public:
PlayerController
();
~
PlayerController
();
public:
PlayerController
();
~
PlayerController
();
void
handle
(
messaging
::
message_t
&
message
)
override
;
void
handle
(
messaging
::
message_t
&
message
)
override
;
void
onKeyAction
(
controls
::
Key
key
,
controls
::
ButtonAction
action
,
controls
::
KeyMods
mods
);
void
onMouseButtonAction
(
controls
::
MouseButton
button
,
controls
::
ButtonAction
action
,
controls
::
KeyMods
mods
);
void
onKeyAction
(
controls
::
Key
key
,
controls
::
ButtonAction
action
,
controls
::
KeyMods
mods
);
void
onMouseButtonAction
(
controls
::
MouseButton
button
,
controls
::
ButtonAction
action
,
controls
::
KeyMods
mods
);
void
update
()
override
;
void
update
()
override
;
void
gui
()
override
;
void
gui
()
override
;
private:
static
size_t
s_current_id
;
size_t
m_id
;
bool
isPossessed
()
const
;
glm
::
vec2
last_position
;
float
m_speed
=
10.
f
;
float
m_rotation_speed
=
1.
f
;
float
m_boost
=
8.
f
;
<