Skip to content
GitLab
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
7b756e8d
Commit
7b756e8d
authored
Sep 21, 2015
by
Elias Broschin
Browse files
movement done
parent
58402faa
Changes
3
Hide whitespace changes
Inline
Side-by-side
include/physics/movement/movement_component.h
View file @
7b756e8d
...
...
@@ -19,11 +19,9 @@ public:
void
update
(
float
dt
);
void
set_mass
(
float
mass
){
mass_
=
mass
;}
void
set_spring
(
float
spring
){
spring_
=
spring
;}
void
set_damping
(
float
damping
){
damping_
=
damping
;}
float
mass
()
{
return
mass_
;}
float
spring
()
{
return
spring_
;}
float
damping
()
{
return
damping_
;}
void
set_current_velocity
(
glm
::
vec3
velocity
)
{
current_velocity_
=
velocity
;}
...
...
@@ -40,7 +38,6 @@ public:
private:
float
mass_
;
float
spring_
;
float
damping_
;
glm
::
vec3
current_velocity_
;
...
...
src/game_state_machine/play_state.cpp
View file @
7b756e8d
...
...
@@ -22,10 +22,18 @@ void play_state::on_enter() {
wcube_
=
&
engine_
.
entity_manager
().
emplace_back
(
glm
::
vec3
(
0.
f
),
glm
::
angleAxis
(
0.
f
,
glm
::
vec3
(
0.
f
)));
wcube_
->
emplace_back
<
staticmesh_component
>
(
"mesh/cube.msh"
);
wcube_move_
=
&
wcube_
->
emplace_back
<
movement_component
>
();
// wcube_move_->set_damping(0.001f);
// wcube_move_->set_mass(0.01f);
}
void
play_state
::
update
(
float
dt
)
{
wcube_move_
->
add_force
(
glm
::
vec3
(
100
,
0
,
0
));
static
float
t
=
0.
f
;
static
float
neg
=
1.
f
;
t
+=
dt
*
neg
;
if
(
t
>
2.
f
||
t
<
-
2.
f
)
{
neg
*=
-
1.
f
;
}
wcube_move_
->
add_force
(
glm
::
vec3
((
2.
f
*
neg
),
-
(
1.
f
*
neg
),
0
));
}
void
play_state
::
on_exit
()
{
...
...
src/physics/movement/movement_component.cpp
View file @
7b756e8d
...
...
@@ -6,7 +6,7 @@
namespace
gdw
{
movement_component
::
movement_component
(
engine
&
engine
,
entity
&
owner
)
:
component
(
engine
,
owner
),
mass_
(
1.
f
),
spring_
(
1.
f
),
damping_
(
1.
f
),
constant_force_
(
glm
::
vec3
(
0.
f
)),
component
(
engine
,
owner
),
mass_
(
1.
f
),
damping_
(
1.
f
),
constant_force_
(
glm
::
vec3
(
0.
f
)),
current_velocity_
(
glm
::
vec3
(
0.
f
))
{
//Register
engine
.
physics_system
().
register_movement_component
(
this
);
...
...
@@ -22,7 +22,7 @@ namespace gdw {
for
(
auto
&
force
:
forces_
)
{
accel
+=
force
;}
//hack
accel
+=
glm
::
vec3
(
0.
f
)
*
(
spring_
/
mass_
);
//
accel += glm::vec3(0.f) * (spring_/mass_);
accel
-=
current_velocity_
*
(
damping_
/
mass_
);
current_velocity_
+=
accel
*
dt
;
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment