Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn

Conflicts:
	Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters
	Escape-the-Dawn/GameWorld.cpp
This commit is contained in:
Adam
2014-03-14 01:53:22 +01:00
37 changed files with 529 additions and 244 deletions
+2 -2
View File
@@ -85,8 +85,8 @@ void Systems::CollisionSystem::Intersects(EntityID aEntity, EntityID bEntity)
if (aMin.x <= bMax.x && bMin.x <= aMax.x) {
if (aMin.y <= bMax.y && bMin.y <= aMax.y) {
if (aMin.z <= bMax.z && bMin.z <= aMax.z) {
aCollisionComponent->CollidingEntities.push_back(aEntity);
bCollisionComponent->CollidingEntities.push_back(bEntity);
aCollisionComponent->CollidingEntities.push_back(bEntity);
bCollisionComponent->CollidingEntities.push_back(aEntity);
return;
}
}
@@ -8,6 +8,7 @@ Systems::LevelGenerationSystem::LevelGenerationSystem( World* world )
velocity = 0;
startx = 0;
startyz = glm::vec2(0, -1000);
spawnFrequency = 0.1f;
}
void Systems::LevelGenerationSystem::SpawnObstacle()
@@ -17,18 +18,17 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
EntityID ent;
ent = m_World->CreateEntity();
obstacles.push_back(ent);
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
transform = m_World->AddComponent<Components::Transform>(ent, "Transform");
bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
model = m_World->AddComponent<Components::Model>(ent, "Model");
auto transform = m_World->AddComponent<Components::Transform>(ent, "Transform");
auto bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
auto collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
auto model = m_World->AddComponent<Components::Model>(ent, "Model");
auto sound = m_World->AddComponent<Components::SoundEmitter>(ent, "SoundEmitter");
positionRandom = -500 + startx + (rand() % 1000);
transform->Position = glm::vec3(positionRandom, startyz);
//transform->Velocity = glm::vec3(0.f, 10.f, 100.f);
transform->Velocity = glm::vec3(0.f, 10.f, 0);
sound->Loop = true;
sound->Gain = 1.f;
@@ -37,7 +37,8 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
if(typeRandom >= 0 && typeRandom < 2) // Mountain stuff :D
{
float scale = (float)(rand() % 1000) / 250;
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
float scale = 1.0f + (float)(rand() % 1000) / 250;
transform->Scale = glm::vec3(scale);
bounds->VolumeVector = glm::vec3(9, 12, 7);
bounds->Origin = glm::vec3(1,11,-1);
@@ -45,7 +46,8 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
}
else if(typeRandom >= 2 && typeRandom < 5) // Single Mountain :D
{
float scale = (float)(rand() % 1000) / 200;
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
float scale = 1.0f + (float)(rand() % 1000) / 200;
transform->Scale = glm::vec3(scale);
bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f);
bounds->Origin = glm::vec3(0,7.5f,0);
@@ -53,7 +55,8 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
}
else if(typeRandom >= 5 && typeRandom < 8)
{
float scale = (float)(rand() % 1000) / 100;
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
float scale = 1.f + (float)(rand() % 1000) / 100;
transform->Scale = glm::vec3(scale);
bounds->VolumeVector = glm::vec3(1, 1, 1);
bounds->Origin = glm::vec3(0,1,0);
@@ -61,20 +64,20 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
}
if(typeRandom >= 8 && typeRandom < 10)
{
float scale = (float)(rand() % 1000) / 100;
m_World->SetProperty(ent, "Name", std::string("PowerUp"));
bounds->VolumeVector = glm::vec3(4, 4, 4);
bounds->Origin = glm::vec3(0,4,0);
powerUp = m_World->AddComponent<Components::PowerUp>(ent, "PowerUp");
powerUp->Speed = 10.f;
auto powerUp = m_World->AddComponent<Components::PowerUp>(ent, "PowerUp");
powerUp->Speed = 200.f;
model->ModelFile = "Models/powerup.obj";
}
// Put it below ground level
//transform->Position.y -= bounds->VolumeVector.y * 2.f;
transform->Position.y -= bounds->VolumeVector.y * 2.f;
}
@@ -82,47 +85,47 @@ void Systems::LevelGenerationSystem::Update( double dt )
{
elapsedtime += dt;
spawnFrequency = 10/velocity;
if(elapsedtime > 0.1){
if(elapsedtime > spawnFrequency){
SpawnObstacle();
elapsedtime = 0;
}
std::list<EntityID> removethis;
for(auto ent : obstacles)
{
auto transform = m_World->GetComponent<Components::Transform>(ent, "Transform");
transform->Velocity.z = velocity;
transform->Position += transform->Velocity * (float)dt;
// Stop raising obstacles when they reach ground level
if (transform->Velocity.y > 0 && transform->Position.y >= 0) {
transform->Position.y = 0;
transform->Velocity.y = 0;
}
if(transform->Position.z > 800)
{
removethis.push_back(ent);
}
}
for(auto ent : removethis)
{
m_World->RemoveEntity(ent);
obstacles.remove(ent);
}
removethis.clear();
}
void Systems::LevelGenerationSystem::UpdateEntity( double dt, EntityID entity, EntityID parent )
{
if( m_World->GetProperty<std::string>(entity, "Name") == "Obstacle" || m_World->GetProperty<std::string>(entity, "Name") == "PowerUp")
{
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
transform->Velocity.z = velocity;
transform->Position += transform->Velocity * (float)dt;
// Stop raising obstacles when they reach ground level
if (transform->Velocity.y > 0 && transform->Position.y >= 0)
{
transform->Position.y = 0;
transform->Velocity.y = 0;
}
auto model = m_World->GetComponent<Components::Model>(entity, "Model");
if (transform->Position.z > 10 && model->Visible)
{
model->Visible = false;
}
if(transform->Position.z > 800) {
m_World->RemoveEntity(entity);
}
}
if( m_World->GetProperty<std::string>(entity, "Name") == "Player")
{
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
startyz = glm::vec2(0, transformComponent->Position.z - 1000);
startx = transformComponent->Position.x;
velocity = transformComponent->Velocity.z;
@@ -31,18 +31,9 @@ namespace Systems
int positionRandom;
glm::vec2 startyz;
float startx;
double elapsedtime;
std::list<EntityID> obstacles;
float velocity;
std::shared_ptr<Components::Transform> transform;
std::shared_ptr<Components::Bounds> bounds;
std::shared_ptr<Components::Collision> collision;
std::shared_ptr<Components::Model> model;
std::shared_ptr<Components::PointLight> pointLight;
std::shared_ptr<Components::PowerUp> powerUp;
float spawnFrequency;
};
}
+108 -46
View File
@@ -10,11 +10,14 @@ Systems::PlayerSystem::PlayerSystem( World* world ) : System(world)
m_CameraOrientation = glm::angleAxis<float>(glm::radians(15.0f),glm::vec3(1,0,0));
freecamEnabled = false;
m_poweruptimeleft = 0;
m_basespeed = 100.f;
m_maxspeed = 100.f;
}
void Systems::PlayerSystem::Update(double dt)
{
m_poweruptimeleft -= (float)dt;
}
void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
@@ -26,48 +29,74 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
if (input == nullptr)
return;
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
auto name = m_World->GetProperty<std::string>(entity, "Name");
if (name == "Camera" && freecamEnabled) {
glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation);
glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation);
float speed = m_PlayerSpeed;
if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) {
speed *= 4.0f;
}
if(input->KeyState[GLFW_KEY_LEFT_ALT]) {
speed /= 4.0f;
}
if(input->KeyState[GLFW_KEY_A]) {
transform->Position -= Camera_Right * (float)dt * speed;
}
else if(input->KeyState[GLFW_KEY_D]) {
transform->Position += Camera_Right * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_W]) {
transform->Position -= Camera_Forward * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_S]) {
transform->Position += Camera_Forward * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_SPACE]) {
transform->Position += glm::vec3(0, 1, 0) * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_LEFT_CONTROL]) {
transform->Position -= glm::vec3(0, 1, 0) * (float)dt * speed;
}
if (input->MouseState[GLFW_MOUSE_BUTTON_LEFT]) {
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
//---------------------------------------------------------------------
transform->Orientation = glm::angleAxis<float>(input->dY/300.f,glm::vec3(1,0,0)) * transform->Orientation;
transform->Orientation = transform->Orientation * glm::angleAxis<float>(input->dX/300.f,glm::vec3(0,1,0));
//---------------------------------------------------------------------
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
if(collision != nullptr)
{
for(auto ent : collision->CollidingEntities)
{
if(m_World->GetProperty<std::string>(ent, "Name") == "Obstacle")
{
m_World->RemoveEntity(entity);
}
}
}
if (name == "Camera") {
if(input->KeyState[GLFW_KEY_F4] && !input->LastKeyState[GLFW_KEY_F4]) {
if(freecamEnabled)
freecamEnabled = false;
else
freecamEnabled = true;
}
if(freecamEnabled)
{
glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation);
glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation);
float speed = m_PlayerSpeed;
if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) {
speed *= 4.0f;
}
if(input->KeyState[GLFW_KEY_LEFT_ALT]) {
speed /= 4.0f;
}
if(input->KeyState[GLFW_KEY_A]) {
transform->Position -= Camera_Right * (float)dt * speed;
}
else if(input->KeyState[GLFW_KEY_D]) {
transform->Position += Camera_Right * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_W]) {
transform->Position -= Camera_Forward * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_S]) {
transform->Position += Camera_Forward * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_SPACE]) {
transform->Position += glm::vec3(0, 1, 0) * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_LEFT_CONTROL]) {
transform->Position -= glm::vec3(0, 1, 0) * (float)dt * speed;
}
if (input->MouseState[GLFW_MOUSE_BUTTON_LEFT]) {
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
//---------------------------------------------------------------------
transform->Orientation = glm::angleAxis<float>(input->dY/300.f,glm::vec3(1,0,0)) * transform->Orientation;
transform->Orientation = transform->Orientation * glm::angleAxis<float>(input->dX/300.f,glm::vec3(0,1,0));
//---------------------------------------------------------------------
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
}
}
}
if (name == "Player")
{
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
@@ -79,7 +108,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
glm::vec3 Ship_Forward = glm::vec3(glm::vec4(0, 0, 1, 0));
float TurnSpeed = 1.0f;
glm::vec3 Euler = glm::eulerAngles(transform->Orientation);
glm::vec3 Euler = glm::degrees(glm::eulerAngles(transform->Orientation));
if(input->KeyState[GLFW_KEY_LEFT]) {
transform->Position -= Ship_Right * (float)dt * (m_PlayerSpeed + Euler.z);
@@ -115,6 +144,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
}
else
{
transform->Position -= Ship_Right * (float)dt * Euler.z;
if(Euler.z < 1.5f && Euler.z > -1.5f)
transform->Orientation = glm::angleAxis<float>(0,glm::vec3(0,0,1));
else if(Euler.z < 0.f)
@@ -130,23 +160,55 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
}
if(input->KeyState[GLFW_KEY_F4] && !input->LastKeyState[GLFW_KEY_F4]) {
if(freecamEnabled)
freecamEnabled = false;
else
freecamEnabled = true;
//powerup
auto cameraEntity = m_World->GetProperty<EntityID>(entity, "Camera");
auto cameracamera = m_World->GetComponent<Components::Camera>(cameraEntity, "Camera");
cameracamera->FOV = glm::radians(20.f + transform->Velocity.z/3 );
auto collisionComponent = m_World->GetComponent<Components::Collision>(entity, "Collision");
for(auto ent : collisionComponent->CollidingEntities)
{
std::string name = m_World->GetProperty<std::string>(ent, "Name");
if(name == "PowerUp")
{
auto powerupComp = m_World->GetComponent<Components::PowerUp>(ent, "PowerUp");
m_maxspeed = powerupComp->Speed;
m_poweruptimeleft = 5.f;
m_World->RemoveEntity(ent);
}
}
if(m_poweruptimeleft <= 0)
{
m_maxspeed = m_basespeed;
}
if(transform->Velocity.z < m_maxspeed)
{
transform->Velocity.z += 100.f*dt;
if(transform->Velocity.z >= m_maxspeed)
transform->Velocity.z = m_maxspeed;
}
else if(transform->Velocity.z > m_maxspeed)
{
transform->Velocity.z -= 50.f*dt;
if(transform->Velocity.z <= m_maxspeed)
transform->Velocity.z = m_maxspeed;
}
// Update camera
if(! freecamEnabled)
{
auto cameraEntity = m_World->GetProperty<EntityID>(entity, "Camera");
auto cameraTransform = m_World->GetComponent<Components::Transform>(cameraEntity, "Transform");
if (cameraTransform) {
cameraTransform->Position = transform->Position + m_CameraOffset;
cameraTransform->Orientation = m_CameraOrientation;
}
}
}
}
+7
View File
@@ -9,6 +9,8 @@
#include "Components/Collision.h"
#include "Components/Camera.h"
#include "Components/Bounds.h"
#include "Components/PowerUp.h"
#include "logging.h"
@@ -32,6 +34,11 @@ namespace Systems
glm::quat m_CameraOrientation;
bool freecamEnabled;
float m_basespeed;
float m_maxspeed;
float m_poweruptimeleft;
};
}
+13 -3
View File
@@ -25,7 +25,9 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
}
auto model = m_CachedModels[modelComponent->ModelFile];
m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation, transformComponent->Scale);
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity);
m_Renderer->AddModelToDraw(model, position, orientation, transformComponent->Scale, modelComponent->Visible);
}
// Debug draw bounds
@@ -33,7 +35,7 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
if (bounds != nullptr) {
glm::vec3 origin = transformComponent->Position + (transformComponent->Scale * bounds->Origin);
glm::vec3 origin = m_TransformSystem->AbsolutePosition(entity) + (transformComponent->Scale * bounds->Origin);
glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector;
m_Renderer->AddAABBToDraw(origin, volumeVector, (collision != nullptr && collision->CollidingEntities.size() > 0));
}
@@ -42,8 +44,9 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity, "PointLight");
if (pointLightComponent != nullptr)
{
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
m_Renderer->AddPointLightToDraw(
transformComponent->Position,
position,
pointLightComponent->Specular,
pointLightComponent->Diffuse,
pointLightComponent->constantAttenuation,
@@ -51,6 +54,7 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
pointLightComponent->quadraticAttenuation,
pointLightComponent->spotExponent);
}
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity, "Camera");
if (cameraComponent != nullptr)
{
@@ -63,6 +67,12 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
}
}
void Systems::RenderSystem::Initialize()
{
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>("TransformSystem");
}
+4 -1
View File
@@ -4,6 +4,7 @@
#include <unordered_map>
#include "System.h"
#include "Systems/TransformSystem.h"
#include "Model.h"
#include "Texture.h"
#include "Components/Model.h"
@@ -22,6 +23,8 @@ namespace Systems
RenderSystem(World* world, std::shared_ptr<Renderer> renderer)
: System(world), m_Renderer(renderer){ }
void Initialize() override;
std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels;
void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) override;
@@ -29,7 +32,7 @@ namespace Systems
private:
std::shared_ptr<Renderer> m_Renderer;
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
};
-1
View File
@@ -7,7 +7,6 @@
#include <AL/al.h>
#include <AL/alc.h>
#include <vector>
#include <glm/gtx/quaternion.hpp>
namespace Systems
{
@@ -0,0 +1,47 @@
#include "TransformSystem.h"
#include "World.h"
//void Systems::TransformSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
//{
// if (parent == 0)
// return;
//
// auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
// auto parentTransform = m_World->GetComponent<Components::Transform>(parent, "Transform");
//
// transform->Position = parentTransform->Position + transform->RelativePosition;
//}
glm::vec3 Systems::TransformSystem::AbsolutePosition(EntityID entity)
{
glm::vec3 absPosition;
glm::quat accumulativeOrientation;
do
{
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
//absPosition += transform->Position;
entity = m_World->GetEntityParent(entity);
auto transform2 = m_World->GetComponent<Components::Transform>(entity, "Transform");
if (entity != 0)
absPosition += transform2->Orientation * transform->Position;
else
absPosition += transform->Position;
} while (entity != 0);
return absPosition * accumulativeOrientation;
}
glm::quat Systems::TransformSystem::AbsoluteOrientation(EntityID entity)
{
glm::quat absOrientation;
do
{
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
absOrientation *= transform->Orientation;
entity = m_World->GetEntityParent(entity);
} while (entity != 0);
return absOrientation;
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef TransformSystem_h__
#define TransformSystem_h__
#include "System.h"
#include "Components/Transform.h"
namespace Systems
{
class TransformSystem : public System
{
public:
TransformSystem(World* world)
: System(world) { }
//void Update(double dt) override;
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
glm::vec3 AbsolutePosition(EntityID entity);
glm::quat AbsoluteOrientation(EntityID entity);
};
}
#endif // TransformSystem_h__