Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
GameDevWeek
Sommersemester 2015
Cpp
Deth Buff Arr
Commits
2a850986
Commit
2a850986
authored
Sep 26, 2015
by
Michael Ochmann
Browse files
Merge branch 'develop' into feature/sound
parents
ea2d5dc1
8354dafb
Changes
7
Hide whitespace changes
Inline
Side-by-side
include/gameplay/game_input_manager.h
View file @
2a850986
#ifndef __GAME_INPUT_MANAGER__
#define __GAME_INPUT_MANAGER__
#include <glm/glm.hpp>
namespace
gdw
{
class
engine
;
...
...
@@ -12,6 +14,7 @@ public:
static
const
float
maximum_movement_distance
;
void
update
(
float
dt
);
glm
::
vec3
get_world_mouse_pos
();
private:
void
handle_key_input
(
float
dt
);
void
handle_mouse_input
(
float
dt
);
...
...
include/gameplay/level_manager.h
View file @
2a850986
...
...
@@ -36,6 +36,8 @@ public:
void
destroy_all_victims
();
void
destroy_all_asteroids
();
maploader
&
get_maploader
()
{
return
maploader_
;}
private:
engine
&
engine_
;
std
::
vector
<
unsigned
long
long
>
victims_
;
...
...
include/mapgen/mapgen.hpp
View file @
2a850986
...
...
@@ -76,6 +76,8 @@ namespace gdw{
float
realAstroidDistance
=
0.0
f
;
float
minAstroidRadius
=
0.0
f
;
float
maxAstroidRadius
=
0.0
f
;
float
maxAstroidRotationSpeed
=
0.2
f
;
float
maxAstroidMotionSpeed
=
0.2
f
;
std
::
vector
<
astroid
>
astroids
;
};
...
...
@@ -107,6 +109,8 @@ namespace gdw{
float
minAstroidRadius
=
1.0
f
;
float
maxAstroidRadius
=
1.0
f
;
float
astroidDistance
=
2.0
f
;
float
maxAstroidRotationSpeed
=
0.2
f
;
float
maxAstroidMotionSpeed
=
0.2
f
;
bool
debug
=
false
;
};
...
...
src/gameplay/game_input_manager.cpp
View file @
2a850986
...
...
@@ -36,6 +36,35 @@ namespace gdw {
handle_mouse_input
(
dt
);
}
glm
::
vec3
game_input_manager
::
get_world_mouse_pos
()
{
auto
&
input
=
engine_
.
input
();
auto
&
level_manager
=
engine_
.
game_play_system
().
level_manager
();
float
x
=
(
input
.
mousePos
().
x
/
engine_
.
graphics_system
().
width
())
*
2.0
f
-
1
;
float
y
=
(
input
.
mousePos
().
y
/
engine_
.
graphics_system
().
height
())
*
2.0
f
-
1
;
auto
cam
=
level_manager
.
camera
()
->
component
<
camera_component
>
();
auto
camera
=
level_manager
.
camera
();
auto
mouse_pos
=
glm
::
vec2
(
x
,
-
y
);
auto
inv_proj_view
=
glm
::
inverse
(
cam
->
projection_view
());
auto
world_pos_near
=
inv_proj_view
*
glm
::
vec4
(
mouse_pos
,
0.1
f
,
1.
f
);
auto
world_pos_far
=
inv_proj_view
*
glm
::
vec4
(
mouse_pos
,
0.9
f
,
1.
f
);
world_pos_near
/=
world_pos_near
.
w
;
world_pos_far
/=
world_pos_far
.
w
;
auto
ray_dir
=
world_pos_far
-
world_pos_near
;
auto
final_pos
=
world_pos_near
+
ray_dir
;
auto
&
entity_manager
=
engine_
.
entity_manager
();
auto
plane_normal
=
glm
::
vec3
(
0
,
1
,
0
);
//Hardcoded ground plane
//HNF
float
d
=
glm
::
dot
(
glm
::
vec3
(
0
,
3
,
15
)
-
glm
::
vec3
(
world_pos_near
),
plane_normal
)
/
glm
::
dot
(
glm
::
vec3
(
glm
::
normalize
(
-
ray_dir
)),
plane_normal
);
return
camera
->
position
()
-
glm
::
vec3
((
glm
::
normalize
(
ray_dir
))
*
d
);
}
void
game_input_manager
::
handle_key_input
(
float
dt
)
{
auto
&
level_manager
=
engine_
.
game_play_system
().
level_manager
();
auto
player
=
level_manager
.
player
();
...
...
@@ -75,30 +104,7 @@ namespace gdw {
// SET ITEM WITH SPACE KEY
if
(
input
.
isKeyDown
(
SDLK_SPACE
))
{
float
x
=
(
input
.
mousePos
().
x
/
engine_
.
graphics_system
().
width
())
*
2.0
f
-
1
;
float
y
=
(
input
.
mousePos
().
y
/
engine_
.
graphics_system
().
height
())
*
2.0
f
-
1
;
auto
cam
=
level_manager
.
camera
()
->
component
<
camera_component
>
();
auto
camera
=
level_manager
.
camera
();
auto
mouse_pos
=
glm
::
vec2
(
x
,
-
y
);
auto
inv_proj_view
=
glm
::
inverse
(
cam
->
projection_view
());
auto
world_pos_near
=
inv_proj_view
*
glm
::
vec4
(
mouse_pos
,
0.1
f
,
1.
f
);
auto
world_pos_far
=
inv_proj_view
*
glm
::
vec4
(
mouse_pos
,
0.9
f
,
1.
f
);
world_pos_near
/=
world_pos_near
.
w
;
world_pos_far
/=
world_pos_far
.
w
;
auto
ray_dir
=
world_pos_far
-
world_pos_near
;
auto
final_pos
=
world_pos_near
+
ray_dir
;
auto
&
entity_manager
=
engine_
.
entity_manager
();
auto
plane_normal
=
glm
::
vec3
(
0
,
1
,
0
);
//Hardcoded ground plane
//HNF
float
d
=
glm
::
dot
(
glm
::
vec3
(
0
,
3
,
15
)
-
glm
::
vec3
(
world_pos_near
),
plane_normal
)
/
glm
::
dot
(
glm
::
vec3
(
glm
::
normalize
(
-
ray_dir
)),
plane_normal
);
auto
intersection_point
=
camera
->
position
()
-
glm
::
vec3
((
glm
::
normalize
(
ray_dir
))
*
d
);
engine_
.
game_play_system
().
player_item_manager
().
place_item
(
intersection_point
);
engine_
.
game_play_system
().
player_item_manager
().
place_item
(
get_world_mouse_pos
());
}
}
...
...
@@ -123,7 +129,6 @@ namespace gdw {
if
(
input
.
isMouseButtonReleased
(
SDL_BUTTON_LEFT
))
{
engine_
.
audioEventHandler
().
trigger
(
AudioEventHandler
::
TRAKTORBEAM_REVERSE_DEACTIVATED
);
}
if
(
input
.
isMouseButtonPressed
(
SDL_BUTTON_RIGHT
))
{
engine_
.
audioEventHandler
().
trigger
(
AudioEventHandler
::
TRAKTORBEAM_ACTIVATED
);
}
...
...
@@ -131,32 +136,9 @@ namespace gdw {
engine_
.
audioEventHandler
().
trigger
(
AudioEventHandler
::
TRAKTORBEAM_REVERSE_DEACTIVATED
);
}
//LEFT && RIGHT CLICK
if
(
input
.
isMouseButtonDown
(
SDL_BUTTON_LEFT
)
||
input
.
isMouseButtonDown
(
SDL_BUTTON_RIGHT
))
{
float
x
=
(
input
.
mousePos
().
x
/
engine_
.
graphics_system
().
width
())
*
2.0
f
-
1
;
float
y
=
(
input
.
mousePos
().
y
/
engine_
.
graphics_system
().
height
())
*
2.0
f
-
1
;
auto
cam
=
level_manager
.
camera
()
->
component
<
camera_component
>
();
auto
camera
=
level_manager
.
camera
();
auto
mouse_pos
=
glm
::
vec2
(
x
,
-
y
);
auto
inv_proj_view
=
glm
::
inverse
(
cam
->
projection_view
());
auto
world_pos_near
=
inv_proj_view
*
glm
::
vec4
(
mouse_pos
,
0.1
f
,
1.
f
);
auto
world_pos_far
=
inv_proj_view
*
glm
::
vec4
(
mouse_pos
,
0.9
f
,
1.
f
);
world_pos_near
/=
world_pos_near
.
w
;
world_pos_far
/=
world_pos_far
.
w
;
auto
ray_dir
=
world_pos_far
-
world_pos_near
;
auto
final_pos
=
world_pos_near
+
ray_dir
;
auto
&
entity_manager
=
engine_
.
entity_manager
();
auto
plane_normal
=
glm
::
vec3
(
0
,
1
,
0
);
//Hardcoded ground plane
//HNF
float
d
=
glm
::
dot
(
glm
::
vec3
(
0
,
3
,
15
)
-
glm
::
vec3
(
world_pos_near
),
plane_normal
)
/
glm
::
dot
(
glm
::
vec3
(
glm
::
normalize
(
-
ray_dir
)),
plane_normal
);
auto
intersection_point
=
camera
->
position
()
-
glm
::
vec3
((
glm
::
normalize
(
ray_dir
))
*
d
);
auto
intersection_point
=
get_world_mouse_pos
();
auto
cannon
=
level_manager
.
cannon
();
auto
cannon_pos
=
glm
::
vec3
(
cannon
->
position
().
x
,
3.
f
,
cannon
->
position
().
z
);
...
...
@@ -185,7 +167,7 @@ namespace gdw {
ray_unnormalized
=
r
.
destination
-
r
.
source
;
}
auto
ray_length_
=
glm
::
length
(
ray_unnormalized
)
;
auto
ray_length_
=
40.
f
;
auto
collider
=
engine_
.
physics_system
().
checkCollisions
<
gdw
::
shape_type
::
ray
>
(
&
r
);
for
(
auto
&
coll
:
collider
)
{
...
...
src/mapgen/mapgen.cpp
View file @
2a850986
...
...
@@ -33,6 +33,8 @@ namespace gdw{
m
->
astroidDistance
=
c
.
astroidDistance
>=
1
?
c
.
astroidDistance
:
2.0
f
;
m
->
realAstroidDistance
=
m
->
astroidDistance
*
m
->
maxAstroidRadius
*
1.4
f
;
m
->
maxAstroidRotationSpeed
=
c
.
maxAstroidRotationSpeed
>=
0
?
c
.
maxAstroidRotationSpeed
<=
6.28318530718
f
?
c
.
maxAstroidRotationSpeed
:
6.28318530718
f
:
.0
f
;
m
->
maxAstroidMotionSpeed
=
c
.
maxAstroidMotionSpeed
>=
0
?
c
.
maxAstroidMotionSpeed
:
.0
f
;
m
->
minBoundX
=
m
->
startX
-
m
->
realAstroidDistance
;
m
->
minBoundY
=
m
->
startY
-
m
->
realAstroidDistance
;
...
...
@@ -47,8 +49,9 @@ namespace gdw{
std
::
uniform_int_distribution
<>
astroidTypes
(
0
,
m
->
astroidTypes
-
1
);
std
::
uniform_real_distribution
<>
astroidRadius
(
m
->
minAstroidRadius
,
m
->
maxAstroidRadius
);
std
::
uniform_real_distribution
<>
astroidPosShift
(
-
(
m
->
realAstroidDistance
*
0.25
f
),
m
->
realAstroidDistance
*
0.25
f
);
std
::
uniform_real_distribution
<>
astroidRotation
(
0
,
6.28318530718
f
);
std
::
uniform_real_distribution
<>
astroidMotionSpeed
(
0.
f
,
10.
f
);
std
::
uniform_real_distribution
<>
astroidRotation
(
0
,
6.28318530718
f
);
//0 - 2*PI
std
::
uniform_real_distribution
<>
astroidRotationSpeed
(
-
m
->
maxAstroidRotationSpeed
,
m
->
maxAstroidRotationSpeed
);
std
::
uniform_real_distribution
<>
astroidMotionSpeed
(
-
m
->
maxAstroidMotionSpeed
,
m
->
maxAstroidMotionSpeed
);
if
(
debug
)
log
<<
"============================================================"
<<
std
::
endl
<<
"mapgen debug out:"
<<
std
::
endl
...
...
@@ -80,7 +83,7 @@ namespace gdw{
a
.
rotationY
=
astroidRotation
(
generator
);
a
.
rotationZ
=
astroidRotation
(
generator
);
a
.
motionSpeed
=
astroidMotionSpeed
(
generator
);
a
.
rotationSpeed
=
astroid
Mo
tionSpeed
(
generator
);
a
.
rotationSpeed
=
astroid
Rota
tionSpeed
(
generator
);
m
->
astroids
.
push_back
(
a
);
if
(
debug
)
log
<<
"o"
;
}
else
{
...
...
src/mapgen/maploader.cpp
View file @
2a850986
...
...
@@ -610,23 +610,28 @@ namespace gdw {
continue
;
}
//enty->position(glm::vec3(ag->npos[0], ag->npos[1], ag->npos[2]));
auto
desired_pos
=
glm
::
vec3
(
ag
->
npos
[
0
],
ag
->
npos
[
1
],
ag
->
npos
[
2
]);
auto
current_pos
=
enty
->
position
();
auto
agent_velocity
=
glm
::
vec3
(
ag
->
vel
[
0
],
ag
->
vel
[
1
],
ag
->
vel
[
2
]);
auto
move
=
enty
->
component
<
movement_component
>
();
if
(
!
move
)
continue
;
auto
target_pos
=
desired_pos
-
current_pos
;
auto
force
=
glm
::
normalize
(
target_pos
)
*
glm
::
length
(
target_pos
);
constexpr
float
max_speed
=
10.
f
;
force
=
(
glm
::
length
(
force
)
<
max_speed
)
?
force
:
glm
::
normalize
(
force
)
*
max_speed
;
//move->add_force(force);
move
->
add_force
(
agent_velocity
);
ag
->
npos
[
0
]
=
current_pos
.
x
;
ag
->
npos
[
1
]
=
current_pos
.
y
;
ag
->
npos
[
2
]
=
current_pos
.
z
;
///CALCULATE POS
//auto desired_pos = glm::vec3(ag->npos[0], ag->npos[1], ag->npos[2]);
// auto current_pos = enty->position();
// auto target_pos = desired_pos - current_pos;
// auto force = glm::normalize(target_pos)*glm::length(target_pos);
// constexpr float max_speed = 10.f;
// force = (glm::length(force) < max_speed)?force : glm::normalize(force)*max_speed;
//move->add_force(force);
///SET POS HARD
//enty->position(glm::vec3(ag->npos[0], ag->npos[1], ag->npos[2]));
}
}
}
...
...
src/physics/movement/movement_component.cpp
View file @
2a850986
...
...
@@ -2,6 +2,9 @@
#include <core/engine.hpp>
#include <physics/physics_system.h>
#include <ecs/entity.hpp>
#include <gameplay/game_play_system.h>
#include <mapgen/maploader.hpp>
#include <gameplay/level_manager.h>
#include <iostream>
namespace
gdw
{
...
...
@@ -29,7 +32,7 @@ namespace gdw {
forces_
.
clear
();
//Update Navigation Position
engine_
.
game_play_system
().
level_manager
().
get_maploader
().
set_agent_pos
(
owner_
.
id
(),
owner_
.
position
());
//Angular kinematik
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment