Commit 4687d770 authored by Elias Broschin's avatar Elias Broschin
Browse files

angular movement done

parent 975e02be
......@@ -5,6 +5,7 @@
#include <util/id.hpp>
#include <glm/glm.hpp>
#include <vector>
#include <glm/gtx/quaternion.hpp>
namespace gdw {
......@@ -32,6 +33,8 @@ public:
void set_constant_force(glm::vec3 constant_force) {constant_force_ = constant_force;}
glm::vec3 constant_force() {return constant_force_;}
void set_angular_speed(float wx, float wy, float wz){angular_speed_ = glm::quat(0.f, wx, wy, wz);}
static unsigned long long type_id() {
return gdw::type_id<gdw::movement_component>();
}
......@@ -43,6 +46,8 @@ private:
glm::vec3 current_velocity_;
glm::vec3 constant_force_;
std::vector<glm::vec3> forces_;
glm::quat angular_speed_;
};
} //Namespace gdw
......
recastnavigation @ 1dd5cf18
Subproject commit 1dd5cf1883d61e723fef3d4957cf758c50e7a52b
......@@ -41,7 +41,7 @@ namespace gdw {
}
void engine::update(float delta_time) {
physics_system_->update(delta_time);
physics_system_->update(1.f/60.f); //Update fix 60 Hz
game_state_machine_->update(delta_time);
graphics_system_->begin();
......
......@@ -4,6 +4,7 @@
#include <core/window.hpp>
#include <util/config.hpp>
#include <util/config_manager.hpp>
#include <iostream>
namespace gdw {
window::window(engine& engine)
......
......@@ -29,13 +29,13 @@ 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");
auto &wcube_col_ = wcube_->emplace_back<collision_component>(new sphere(glm::vec3(0.f), 1.2f));
wcube_col_.set_trigger([](){std::cout << "trigger 1" << std::endl;});
//wcube_col_.set_trigger([](){std::cout << "trigger 1" << std::endl;});
wcube_move_ = &wcube_->emplace_back<movement_component>();
wcube2_ = &engine_.entity_manager().emplace_back(glm::vec3(0.f), glm::angleAxis(0.f, glm::vec3(0.f)));
wcube2_->emplace_back<staticmesh_component>("mesh/cube.msh");
auto &wcube_col2_ = wcube2_->emplace_back<collision_component>(new sphere(glm::vec3(0.f), 1.2f));
wcube_col2_.set_trigger([](){std::cout << "trigger 2" << std::endl;});
//wcube_col2_.set_trigger([](){std::cout << "trigger 2" << std::endl;});
wcube2_move_ = &wcube2_->emplace_back<movement_component>();
// wcube_move_->set_damping(0.001f);
......@@ -53,10 +53,8 @@ void play_state::update(float dt) {
wcube2_move_->add_force(glm::vec3(-(2.f*neg),(1.f*neg),0));
if(engine_.input().isMouseButtonPressed(1)) {
auto pos = engine_.input().mousePos();
std::cout << pos.x << "/" << pos.y << std::endl;
}
wcube_move_->set_angular_speed(3.f,5.f,1.f);
wcube2_move_->set_angular_speed(-3.f,-5.f,-1.f);
}
void play_state::on_exit() {
......
......@@ -8,7 +8,7 @@
namespace gdw{
collision_component::collision_component(engine& engine, entity& owner, gdw::collision_shape* col_shape):
component(engine,owner) {
component(engine,owner), trigger_([](){}) {
engine_.physics_system().register_collision_component(this);
collision_shape_ = std::move(std::unique_ptr<gdw::collision_shape>(col_shape));
collision_shape_->set_owner(&owner);
......
......@@ -18,16 +18,22 @@ namespace gdw {
}
void movement_component::update(float dt) {
//Position kinematik
glm::vec3 accel(constant_force_);
for(auto &force : forces_) {accel += force;}
//hack
//accel += glm::vec3(0.f) * (spring_/mass_);
accel -= current_velocity_ * (damping_/mass_);
current_velocity_ += accel * dt;
owner_.position(owner_.position() + current_velocity_ * dt);
forces_.clear();
//Angular kinematik
glm::quat w(angular_speed_);
glm::quat q(owner_.rotation());
glm::quat dq(0.5f *(w*q));
owner_.rotation(q + dt*(dq));
owner_.rotation(glm::normalize(owner_.rotation()));
}
}
......@@ -4,6 +4,7 @@
#include <core/engine.hpp>
#include <util/config.hpp>
#include <iostream>
namespace gdw {
config::config(engine& engine, const std::string& name, const std::string& data)
......
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