Commit edf93dbf authored by Michael Ochmann's avatar Michael Ochmann
Browse files

cleaned license file

parents 5c47f941 4906dc48
This diff is collapsed.
......@@ -8,6 +8,7 @@ lib/sdl2_mixer/i686-w64-mingw32/include/SDL2
lib/sdl2_mixer/x86_64-w64-mingw32/include/SDL2
include/core
include/
glm/
lib/
lib/glm/glm/glm.hpp
tools/mesh_converter/lib/assimp/code
......@@ -101,3 +102,8 @@ lib/glm/test/external/gli/gtx
lib/glm/glm/detail
lib/gli/external/glm-0.9.5.1/glm/gtc
include/game_state_machine
src/physics/movement
include/physics/movement
include/physics/collision
include/physics
src/physics
# FSI-Lizenz
Copyright © 2015 Benjamin Albsmeier, Thomas Eppers, Johannes Kirchner, Michael Ochmann
Copyright © 2015 Benjamin Albsmeier, Jeremias Boos, Thomas Eppers, Johannes Kirchner, Michael Ochmann
Hiermit wird unentgeltlich jeder Person, die eine Kopie der Software und der zugehörigen Dokumentationen
(die "Software") erhält, die Erlaubnis erteilt, sie uneingeschränkt zu benutzen, inklusive und ohne Ausnahme dem Recht,
......
......@@ -9,8 +9,9 @@ out vec2 texcoord_;
uniform mat4 projection;
uniform mat4 view;
uniform mat4 model;
void main() {
gl_Position = projection * view * vec4(_position, 1.f);
gl_Position = projection * view * model * vec4(_position, 1.f);
texcoord_ = _texcoord;
}
......@@ -10,6 +10,7 @@ namespace gdw {
class graphics_system;
class rendering_system;
class game_state_machine;
class physics_system;
}
namespace gdw {
......@@ -22,6 +23,7 @@ namespace gdw {
std::unique_ptr<gdw::graphics_system> graphics_system_;
std::unique_ptr<gdw::rendering_system> rendering_system_;
std::unique_ptr<gdw::game_state_machine> game_state_machine_;
std::unique_ptr<gdw::physics_system> physics_system_;
// needs to be the last one that will be destroyed
gdw::entity_manager entity_manager_;
......@@ -70,6 +72,10 @@ namespace gdw {
gdw::game_state_machine& game_state_machine() noexcept {
return *game_state_machine_;
}
gdw::physics_system& physics_system() noexcept {
return *physics_system_;
}
};
}
......
......@@ -5,6 +5,9 @@
namespace gdw {
class entity;
class movement_component;
class play_state : public game_state {
public:
play_state(engine& engine);
......@@ -13,6 +16,9 @@ public:
void update(float dt);
void on_enter();
void on_exit();
private:
entity* wcube_;
movement_component* wcube_move_;
};
} //Namespace gdw
......
#ifndef __MOVEMENT_COMPONENT__
#define __MOVEMENT_COMPONENT__
#include <ecs/component.hpp>
#include <util/id.hpp>
#include <glm/glm.hpp>
#include <vector>
namespace gdw {
class engine;
class entity;
class movement_component : public component {
public:
movement_component(engine& engine, entity& owner);
~movement_component();
void update(float dt);
void set_mass(float mass){mass_ = mass;}
void set_damping(float damping){damping_ = damping;}
float mass() {return mass_;}
float damping() {return damping_;}
void set_current_velocity(glm::vec3 velocity) {current_velocity_ = velocity;}
glm::vec3 current_velocity() {return current_velocity_;}
void add_force(glm::vec3 force) {forces_.push_back(force);}
void set_constant_force(glm::vec3 constant_force) {constant_force_ = constant_force;}
glm::vec3 constant_force() {return constant_force_;}
static unsigned long long type_id() {
return gdw::type_id<gdw::movement_component>();
}
private:
float mass_;
float damping_;
glm::vec3 current_velocity_;
glm::vec3 constant_force_;
std::vector<glm::vec3> forces_;
};
} //Namespace gdw
#endif
#ifndef __PHYSICS_SYSTEM__
#define __PHYSICS_SYSTEM__
#include <vector>
namespace gdw {
class engine;
class movement_component;
class physics_system {
public:
physics_system(engine& engine);
~physics_system();
void update(float dt);
private:
void register_movement_component(movement_component* comp);
void unregister_movement_component(movement_component* comp);
private:
friend class movement_component;
engine &engine_;
std::vector<movement_component*> movement_components_;
};
} //Namespace gdw
#endif
#include <chrono>
#include <SDL.h>
#include <asset/asset.hpp>
......@@ -15,6 +13,7 @@
#include <util/logger.hpp>
#include <util/make_unique.hpp>
#include <game_state_machine/game_state_machine.h>
#include <physics/physics_system.h>
namespace gdw {
engine::engine()
......@@ -26,13 +25,12 @@ namespace gdw {
SDL_ClearError();
throw std::runtime_error("could not initialize SDL" + sdl_error);
}
physics_system_ = make_unique<gdw::physics_system>(*this);
audio_ = make_unique<gdw::audio>(*this);
graphics_system_ = make_unique<gdw::graphics_system>(*this);
rendering_system_ = make_unique<gdw::rendering_system>(*this);
game_state_machine_ = make_unique<gdw::game_state_machine>(*this);
auto& wcube = entity_manager_.emplace_back(glm::vec3(0.f), glm::angleAxis(0.f, glm::vec3(0.f)));
wcube.emplace_back<staticmesh_component>("mesh/cube.msh");
}
engine::~engine() noexcept {
......@@ -40,7 +38,9 @@ namespace gdw {
}
void engine::update(float delta_time) {
physics_system_->update(delta_time);
game_state_machine_->update(delta_time);
graphics_system_->begin();
rendering_system_->update(delta_time);
graphics_system_->end(delta_time);
......@@ -48,9 +48,8 @@ namespace gdw {
void engine::run() {
auto event = SDL_Event();
auto duration = std::chrono::high_resolution_clock::now().time_since_epoch();
auto last_time = 0.f;
auto current_time = std::chrono::duration_cast<std::chrono::duration<float>>(duration).count();
auto current_time = static_cast<float>(SDL_GetTicks()) / 1000.f;
auto delta_time = 0.f;
while (!quit_) {
......@@ -59,9 +58,8 @@ namespace gdw {
quit_ = true;
}
}
duration = std::chrono::high_resolution_clock::now().time_since_epoch();
last_time = current_time;
current_time = std::chrono::duration_cast<std::chrono::duration<float>>(duration).count();
current_time = static_cast<float>(SDL_GetTicks()) / 1000.f;
delta_time = current_time - last_time;
update(delta_time);
......
......@@ -13,6 +13,7 @@ game_state_machine::game_state_machine(engine& engine):engine_(engine), current_
//default state
current_state_ = game_states_[type_id<play_state>()].get();
current_state_->on_enter();
}
game_state_machine::~game_state_machine() {
......
......@@ -7,6 +7,8 @@
#include <ecs/entity.hpp>
#include <game_state_machine/game_state_machine.h>
#include <game_state_machine/menu_state.h>
#include <rendering/staticmesh_component.hpp>
#include <physics/movement/movement_component.h>
namespace gdw {
......@@ -17,9 +19,22 @@ play_state::play_state(engine &engine):game_state(engine) {
play_state::~play_state() {}
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) {}
void play_state::update(float dt) {
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() {
......
#include <physics/movement/movement_component.h>
#include <core/engine.hpp>
#include <physics/physics_system.h>
#include <ecs/entity.hpp>
#include <iostream>
namespace gdw {
movement_component::movement_component(engine& engine, entity& owner):
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);
}
movement_component::~movement_component() {
//unregister
engine_.physics_system().unregister_movement_component(this);
}
void movement_component::update(float dt) {
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();
}
}
#include <physics/physics_system.h>
#include <core/engine.hpp>
#include <util/component_helper.hpp>
#include <physics/movement/movement_component.h>
#include <iostream>
namespace gdw {
physics_system::physics_system(engine& engine):engine_(engine) {
}
physics_system::~physics_system() {
}
void physics_system::update(float dt) {
for(auto &move : movement_components_)
move->update(dt);
}
void physics_system::register_movement_component(movement_component* comp) {
movement_components_.emplace_back(comp);
}
void physics_system::unregister_movement_component(movement_component* comp) {
remove_component(movement_components_, comp);
}
} //namespace gdw
Supports Markdown
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