Commit 7b756e8d authored by Elias Broschin's avatar Elias Broschin
Browse files

movement done

parent 58402faa
......@@ -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_;
......
......@@ -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() {
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment