Commit 8139f29e authored by Michael Ochmann's avatar Michael Ochmann
Browse files

Merge branch 'develop' of gitlab.fsi.hochschule-trier.de:GameDevWeek/gdw_ss15_cpp into develop

parents e5524569 012056a8
......@@ -157,4 +157,7 @@ This project contains external artwork licensed under various Creative Commons L
* **Wood** by **21ev**@deviantart, [CC BY-SA 3.0](http://creativecommons.org/licenses/by-sa/3.0/legalcode)
[Source](http://21ev.deviantart.com/art/wooden-texture-335286532)
* **Picture of the Moon** by **NASA**, [CC BY-NC 2.0](https://creativecommons.org/licenses/by-nc/2.0/)
[Source](https://selz.com/de/item/54a86fa6b79872193c1d63b3)
\ No newline at end of file
[Source](https://selz.com/de/item/54a86fa6b79872193c1d63b3)
* **Reststop** by **DUAEL DESIGNS LLC & ROBERT STEIN III '10**,
[CC-BY-3.0-US](http://creativecommons.org/licenses/by/3.0/us/)
[Source](http://freebitmaps.blogspot.de/2010/10/srgb-planet-reststop.html)
No preview for this file type
#version 330
in vec3 color_;
out vec4 frag_color;
void main() {
frag_color = vec4(color_, 1.f);
}
#version 330
in vec3 _point;
in vec3 _position;
in float _size;
in vec3 _color;
out vec3 color_;
uniform mat4 projection;
uniform mat4 view;
void main() {
gl_Position = projection * view * vec4(_point + _position, 1.f);
gl_PointSize = _size;
color_ = _color;
}
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -16,7 +16,7 @@ public:
void update(float dt);
glm::vec3 get_world_mouse_pos();
void render_ray(ray* r, float length, float radius, glm::vec3 color);
void render_ray(ray* r, const glm::vec3& offset, float length, float radius, bool invert, glm::vec3 color);
void process_beam_collision(ray& r, glm::vec3 &ray_unnormalized, float &beam_velocity, float &ray_length_, bool &asteroid_hit, int &portal_type, float &remaining_ray_length);
private:
void handle_key_input(float dt);
......
......@@ -72,6 +72,9 @@ private:
maploader maploader_;
float map_load_timer_;
float plane_offset_y_;
glm::vec4 cannon_socket_offset_;
glm::vec4 cannon_offset_;
bool is_level_build_;
};
......
......@@ -17,77 +17,77 @@
#include <glm/glm.hpp>
namespace gdw {
class engine;
class entity;
class engine;
class entity;
class maploader{
enum SamplePolyAreas
{
SAMPLE_POLYAREA_GROUND,
SAMPLE_POLYAREA_WATER,
SAMPLE_POLYAREA_ROAD,
SAMPLE_POLYAREA_DOOR,
SAMPLE_POLYAREA_GRASS,
SAMPLE_POLYAREA_JUMP,
};
enum SamplePolyFlags
{
SAMPLE_POLYFLAGS_WALK = 0x01, // Ability to walk (ground, grass, road)
SAMPLE_POLYFLAGS_SWIM = 0x02, // Ability to swim (water).
SAMPLE_POLYFLAGS_DOOR = 0x04, // Ability to move through doors.
SAMPLE_POLYFLAGS_JUMP = 0x08, // Ability to jump.
SAMPLE_POLYFLAGS_DISABLED = 0x10, // Disabled polygon
SAMPLE_POLYFLAGS_ALL = 0xffff // All abilities.
};
class maploader{
enum SamplePolyAreas
{
SAMPLE_POLYAREA_GROUND,
SAMPLE_POLYAREA_WATER,
SAMPLE_POLYAREA_ROAD,
SAMPLE_POLYAREA_DOOR,
SAMPLE_POLYAREA_GRASS,
SAMPLE_POLYAREA_JUMP,
};
enum SamplePolyFlags
{
SAMPLE_POLYFLAGS_WALK = 0x01, // Ability to walk (ground, grass, road)
SAMPLE_POLYFLAGS_SWIM = 0x02, // Ability to swim (water).
SAMPLE_POLYFLAGS_DOOR = 0x04, // Ability to move through doors.
SAMPLE_POLYFLAGS_JUMP = 0x08, // Ability to jump.
SAMPLE_POLYFLAGS_DISABLED = 0x10, // Disabled polygon
SAMPLE_POLYFLAGS_ALL = 0xffff // All abilities.
};
private:
engine &engine_;
unsigned char* triareas_;
rcHeightfield* solid_;
rcCompactHeightfield* chf_;
rcContourSet* cset_;
rcPolyMesh* pmesh_;
rcConfig cfg_;
rcPolyMeshDetail* dmesh_;
dtNavMesh* navMesh_;
dtNavMeshQuery* navQuery_;
dtCrowd* crowd_;
BuildContext ctx_;
float m_targetPos[3];
dtPolyRef m_targetRef;
std::unordered_map<int,unsigned long long> entityAgent;
private:
engine &engine_;
unsigned char* triareas_;
rcHeightfield* solid_;
rcCompactHeightfield* chf_;
rcContourSet* cset_;
rcPolyMesh* pmesh_;
rcConfig cfg_;
rcPolyMeshDetail* dmesh_;
dtNavMesh* navMesh_;
dtNavMeshQuery* navQuery_;
dtCrowd* crowd_;
BuildContext ctx_;
float m_targetPos[3];
dtPolyRef m_targetRef;
std::unordered_map<int,unsigned long long> entityAgent;
static constexpr float agent_size_ = 2.25f;
public:
maploader(engine &engine);
virtual ~maploader();
public:
maploader(engine &engine);
virtual ~maploader();
std::unique_ptr<map> load(const std::vector<std::string>& meshnames,
const float& modelscale,
const int& mapWidth,const int& mapHeight,const int& mapDeep,
const int& startX,const int& startY,const int& startZ,
const int& seed = 27389,const int& scatter= 17,
const float& minAstroidRadius = 1,const float& maxAstroidRadius = 1, bool debug = false);
std::unique_ptr<map> load(const std::vector<std::string>& meshnames,
const float& modelscale,
const int& mapWidth,const int& mapHeight,const int& mapDeep,
const int& startX,const int& startY,const int& startZ,
const int& seed = 27389,const int& scatter= 17,
const float& minAstroidRadius = 1,const float& maxAstroidRadius = 1, bool debug = false);
int add_agent(const float *p, unsigned long long int entityID);
void set_move_target(const float *p, bool adjust);
void set_move_target(const float *p, bool adjust);
void update(const float dt);
void render();
void update(const float dt);
void render();
void removeAgent(int idx);
void removeAgent(int idx);
void set_agent_pos(int idx, const glm::vec3 &pos);
void set_agent_pos(int idx, const glm::vec3 &pos);
void set_agent_pos(unsigned long long int entityID, const glm::vec3 &pos);
private:
private:
void cleanup();
void cleanup();
void generate_cylinder(float size,
float x, float y,float z,std::vector<int>& in,
std::vector<float>& v,
int segments = 8);
void generate_cylinder(float size,
float x, float y,float z,std::vector<int>& in,
std::vector<float>& v,
int segments = 8);
};
}
#endif //GDW_SS15_CPP_MAPLOADER_HPP
......@@ -14,38 +14,38 @@ class entity;
class movement_component : public component {
public:
movement_component(engine& engine, entity& owner);
~movement_component();
movement_component(engine& engine, entity& owner);
~movement_component();
void update(float dt);
void update(float dt);
void set_mass(float mass){mass_ = mass;}
void set_damping(float damping){damping_ = damping;}
void set_mass(float mass){mass_ = mass;}
void set_damping(float damping){damping_ = damping;}
float mass() {return mass_;}
float damping() {return 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 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 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_;}
void set_constant_force(glm::vec3 constant_force) {constant_force_ = constant_force;}
glm::vec3 constant_force() {return constant_force_;}
void add_angular_force(glm::vec3 force){angular_forces_.push_back(force);}
static unsigned long long type_id() {
return gdw::type_id<gdw::movement_component>();
}
static unsigned long long type_id() {
return gdw::type_id<gdw::movement_component>();
}
private:
float mass_;
float damping_;
float mass_;
float damping_;
glm::vec3 current_velocity_;
glm::vec3 constant_force_;
std::vector<glm::vec3> forces_;
glm::vec3 current_velocity_;
glm::vec3 constant_force_;
std::vector<glm::vec3> forces_;
std::vector<glm::vec3> angular_forces_;
glm::vec3 angular_velocity_;
......
......@@ -16,35 +16,39 @@ class ray;
class physics_system {
public:
physics_system(engine& engine);
~physics_system();
physics_system(engine& engine);
~physics_system();
void update(float dt);
void narrow_phase();
void update(float dt);
void narrow_phase();
template <shape_type A, shape_type B>
bool checkCollisions(const collision_shape* s1, const collision_shape* s2);
template <shape_type A, shape_type B>
bool checkCollisions(const collision_shape* s1, const collision_shape* s2);
template <shape_type A>
std::vector<unsigned long long> checkCollisions(const collision_shape* s1);
gdw::collision_data_manager& collision_data_manager() noexcept {
return collision_data_manager_;
}
gdw::collision_data_manager& collision_data_manager() noexcept {
return collision_data_manager_;
}
auto& collision_components() {
return collision_components_;
}
private:
void register_movement_component(movement_component* comp);
void unregister_movement_component(movement_component* comp);
void register_movement_component(movement_component* comp);
void unregister_movement_component(movement_component* comp);
void register_collision_component(collision_component* comp);
void unregister_collision_component(collision_component* comp);
void register_collision_component(collision_component* comp);
void unregister_collision_component(collision_component* comp);
private:
friend class movement_component;
friend class collision_component;
engine &engine_;
std::vector<movement_component*> movement_components_;
std::vector<collision_component*> collision_components_;
gdw::collision_data_manager collision_data_manager_;
friend class movement_component;
friend class collision_component;
engine &engine_;
std::vector<movement_component*> movement_components_;
std::vector<collision_component*> collision_components_;
gdw::collision_data_manager collision_data_manager_;
};
} //Namespace gdw
......
......@@ -80,6 +80,13 @@ namespace gdw {
vertex_array simple_render_vao_;
int simple_render_element_size_;
vertex_layout starfield_vertex_layout_;
program starfield_program_;
vertex_buffer starfield_point_;
vertex_buffer starfield_vbo_;
vertex_array starfield_vao_;
unsigned int starfield_size_ = 0;
std::unordered_map<unsigned long long, camera_component*> camera_components_;
std::vector<directional_light_component*> directional_light_components_;
std::vector<light_component*> light_components_;
......@@ -144,6 +151,8 @@ namespace gdw {
void render_non_opauqe_geometry(float delta_time, camera_component& camera);
void render_navMesh(camera_component &camera);
void render_final_image();
void generate_starfield();
void render_starfield(camera_component& camera);
void register_component(camera_component* component);
......
#ifndef __GDW_STAR_VERTEX_HPP__
#define __GDW_STAR_VERTEX_HPP__
#include <glm/glm.hpp>
namespace gdw {
struct star_vertex {
glm::vec3 position;
float size;
glm::vec3 color;
};
}
#endif
dome_diffuse.dds : 17
piratenschiff_material.dds : 4
Meteor_LOW_Normals.dds : 10
victim_diffuse.dds : 15
cannon.dds : 11
piratenschiff_diffuse.dds : 5
Meteor_normal_2.dds : 21
beam.dds : 12
piratenschiff_normal.dds : 6
Meteor_normal_2.dds : 21
Meteor_LOW_Normals.dds : 10
cannon.dds : 11
victim_diffuse.dds : 15
greyscale_normal.dds : 2
black.dds : 7
victim2_diffuse.dds : 16
planet_textur.dds : 19
deathstar.dds : 20
dome_material.dds : 18
beam_stripes.dds : 13
weighted_companion_cube_export_material.dds : 3
black.dds.001.dds : 8
deathstar.dds : 20
dome_material.dds : 18
greyscale_normal.dds.001.dds : 14
black.dds.001.dds : 8
planet_textur.dds : 19
victim2_diffuse.dds : 16
weighted_companion_cube_export.dds : 1
Texture_Meteor.dds : 9
next_id : 24
deathstar_material.dds : 23
coin.dds : 22
deathstar_material.dds : 23
......@@ -9,14 +9,14 @@
namespace gdw {
game_state_machine::game_state_machine(engine& engine):engine_(engine), current_state_(nullptr) {
game_states_[type_id<play_state>()] = make_unique<play_state>(engine);
game_states_[type_id<menu_state>()] = make_unique<menu_state>(engine);
game_states_[type_id<credits_state>()] = make_unique<credits_state>(engine);
game_states_[type_id<play_state>()] = make_unique<play_state>(engine);
//game_states_[type_id<menu_state>()] = make_unique<menu_state>(engine);
//game_states_[type_id<credits_state>()] = make_unique<credits_state>(engine);
//default state
//current_state_ = game_states_[type_id<play_state>()].get();
current_state_ = game_states_[type_id<menu_state>()].get();
current_state_->on_enter();
//default state
//current_state_ = game_states_[type_id<play_state>()].get();
current_state_ = game_states_[type_id<play_state>()].get();
current_state_->on_enter();
}
game_state_machine::~game_state_machine() {
......@@ -24,8 +24,8 @@ game_state_machine::~game_state_machine() {
}
void game_state_machine::update(float dt) {
if(current_state_)
current_state_->update(dt);
if(current_state_)
current_state_->update(dt);
}
} //namespace gdw
#include <glm/gtx/string_cast.hpp>
#include <gameplay/game_input_manager.h>
#include <core/engine.hpp>
#include <SDL.h>
......@@ -60,7 +62,7 @@ namespace gdw {
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);
float d = glm::dot(glm::vec3(0.f, 0.f, 0.f) - 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);
}
......@@ -145,24 +147,13 @@ namespace gdw {
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);
ray r(cannon_pos, intersection_point);
//SPAWN LASER
auto v1 = glm::vec3(0,0,-1);
auto v2 = glm::normalize(r.destination-r.source);
auto angle = std::acos(glm::dot(v1, v2) / glm::length(v1) * glm::length(v2));
auto cross = glm::cross(v1, v2);
if(glm::length(cross) < 0.01f) return;
auto axis = glm::normalize(cross);
auto s = sin(angle/2.f);
auto qx = axis.x *s;
auto qy = axis.y *s;
auto qz = axis.z *s;
auto qw = cos(angle/2.f);
auto rot = glm::angleAxis(glm::radians(180.f), glm::vec3(0,1,0));
rot *= glm::quat(qw,qx,qy,qz);
if (!cannon) {
return;
}
auto cannon_pos = cannon->position();
auto cannon_rotation = glm::toMat4(cannon->rotation());
auto offset = glm::vec3(cannon_rotation * glm::vec4(0.f, 0.57352f, 1.3088f, 1.f));
ray r(cannon_pos + offset, intersection_point);
auto ray_unnormalized = glm::vec3(1.f);
if (input.isDown(inputMapping::beam_normal)) {
......@@ -183,10 +174,10 @@ namespace gdw {
if (input.isDown(inputMapping::beam_normal)) {
auto ray_length = (std::abs(ray_length_ - 0.f) < 0.001f)? glm::length(ray_unnormalized): ray_length_;
render_ray(&r, ray_length, std::max((beam_velocity/10.f)/2.f, 1.f), glm::vec3(0,0,1));
render_ray(&r, offset, ray_length, 0.18f, false, glm::vec3(0.5f, 0.6f, 0.9f));
} else {
auto ray_length = (std::abs(ray_length_ - 0.f) < 0.001f)? glm::length(ray_unnormalized): ray_length_;
render_ray(&r, ray_length, std::max((beam_velocity/10.f)/2.f, 1.f), glm::vec3(1,0,0));
render_ray(&r, offset, ray_length, 0.18f, true, glm::vec3(0.8f, 0.4f, 0.f));
}
// do {
switch(portal_type) {
......@@ -198,9 +189,9 @@ namespace gdw {
ray_length_ = remaining_length;
process_beam_collision(r2, ray_unnormalized, beam_velocity, ray_length_, asteroid_hit, portal_type, remaining_length);
if (input.isDown(inputMapping::beam_normal)) {
render_ray(&r2, remaining_length, std::max((beam_velocity/10.f)/2.f, 1.f), glm::vec3(0,0,1));
render_ray(&r2, offset, remaining_length, 0.18f, false, glm::vec3(0,0,1));
} else {
render_ray(&r2, remaining_length, std::max((beam_velocity/10.f)/2.f, 1.f), glm::vec3(1,0,0));
render_ray(&r2, offset, remaining_length, 0.18f, true, glm::vec3(1,0,0));
}
}
break;
......@@ -213,9 +204,9 @@ namespace gdw {
ray_length_ = remaining_length;
process_beam_collision(r2, ray_unnormalized, beam_velocity, ray_length_, asteroid_hit, portal_type, remaining_length);
if (input.isDown(inputMapping::beam_normal)) {
render_ray(&r2, remaining_length, std::max((beam_velocity/10.f)/2.f, 1.f), glm::vec3(0,0,1));
render_ray(&r2, offset, remaining_length, 0.18f, false, glm::vec3(0,0,1));
} else {
render_ray(&r2, remaining_length, std::max((beam_velocity/10.f)/2.f, 1.f), glm::vec3(1,0,0));
render_ray(&r2, offset, remaining_length, 0.18f, true, glm::vec3(1,0,0));
}
}
break;
......@@ -239,6 +230,16 @@ namespace gdw {
break;
}
}
auto cannon = level_manager.cannon();
if (cannon) {
const static auto cannon_dir = glm::vec3(0.f, 0.f, 1.f);
auto ray_dir = get_world_mouse_pos() - cannon->position();
auto alpha = glm::atan(ray_dir.x, ray_dir.z);
auto beta = glm::atan(cannon_dir.x, cannon_dir.z);
auto cannon_rotation = glm::angleAxis(alpha + beta, glm::vec3(0.f, 1.f, 0.f));
cannon->rotation(cannon_rotation);
}
}
void game_input_manager::process_beam_collision(ray& r, glm::vec3 &ray_unnormalized, float &beam_velocity, float &ray_length_, bool &asteroid_hit, int &portal_type, float &remaining_ray_length) {
......@@ -262,7 +263,6 @@ namespace gdw {
//BEAM X ASTEROIDS
for(auto &coll : collider) {
auto c = engine_.entity_manager().resolve(coll);
auto type_comp = c->component<object_type_component>();
if(type_comp) {
if(type_comp->get_object_type() == "ASTEROID") {
......@@ -315,27 +315,20 @@ namespace gdw {
auto distance = glm::length(r.source - c->position());
if(glm::length(r.source - c->position()) < ray_length_) {
move->add_force((attract_dir * beam_velocity) / std::max(distance/20.f, 2.f));
ray_length_ = std::min(ray_length_, glm::length(c->position() - r.source));
}
}
}
}
void game_input_manager::render_ray(ray* r, float length, float radius, glm::vec3 color) {
auto v1 = glm::vec3(0,0,-1);
auto v2 = glm::normalize(r->destination-r->source);
auto angle = std::acos(glm::dot(v1, v2) / glm::length(v1) * glm::length(v2));
auto cross = glm::cross(v1, v2);
if(glm::length(cross) < 0.01f) return;
auto axis = glm::normalize(cross);
auto s = sin(angle/2.f);
auto qx = axis.x * s;
auto qy = axis.y * s;
auto qz = axis.z * s;
auto qw = cos(angle/2.f);
auto rot = glm::angleAxis(glm::radians(180.f), glm::vec3(0,1,0));
rot *= glm::quat(qw,qx,qy,qz);
engine_.rendering_system().render_trakor_beam(r->source, rot, length, radius, false, color);
void game_input_manager::render_ray(ray* r, const glm::vec3& offset, float length, float radius, bool invert, glm::vec3 color) {
const static auto cannon_dir = glm::vec3(0.f, 0.f, 1.f);
auto ray_dir = glm::normalize(r->destination - (r->source - offset));
auto alpha = glm::atan(ray_dir.x, ray_dir.z);
auto beta = glm::atan(cannon_dir.x, cannon_dir.z);
auto cannon_rotation = glm::angleAxis(alpha + beta, glm::vec3(0.f, 1.f, 0.f));
engine_.rendering_system().render_trakor_beam(r->source, cannon_rotation, length, radius, invert, color);
}
} //Namespace gdw
......@@ -34,7 +34,7 @@ namespace gdw {
auto &placed_item_coll = placed_item.emplace_back<collision_component>(new sphere(glm::vec3(0.f),7.f));
placed_item.emplace_back<object_type_component>("MAGNET_FIELD");
placed_item_coll.set_trigger([this](unsigned long long self_id, unsigned long long coll_id) {
auto collider = engine_.entity_manager().resolve(coll_id);