From 3e7bd21fadb22267067ba55065fca4f9eb097e89 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Tue, 13 May 2014 05:04:09 +0200 Subject: [PATCH] Demo stuff --- assets | 2 +- src/Components/BarrelSteering.h | 3 +- src/GameWorld.cpp | 78 +++++++++++++++++++++--------- src/Renderer.cpp | 26 +++++----- src/Systems/TankSteeringSystem.cpp | 8 ++- src/Systems/TankSteeringSystem.h | 1 + 6 files changed, 78 insertions(+), 40 deletions(-) diff --git a/assets b/assets index 15ac025..0a617d5 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 15ac02523ad374b4aaf60a16db89b1934de7f303 +Subproject commit 0a617d58c737a9ed947db0fc1a0f0f7b0f54b80f diff --git a/src/Components/BarrelSteering.h b/src/Components/BarrelSteering.h index 1cd71be..94f918c 100644 --- a/src/Components/BarrelSteering.h +++ b/src/Components/BarrelSteering.h @@ -9,11 +9,12 @@ namespace Components struct BarrelSteering : Component { BarrelSteering() - : TurnSpeed(1.f), Axis(glm::vec3(0,1,0)){ } + : TurnSpeed(1.f), ReloadTime(1.f), Axis(glm::vec3(0,1,0)){ } float TurnSpeed; glm::vec3 Axis; EntityID ShotTemplate; float ShotSpeed; + float ReloadTime; virtual BarrelSteering* Clone() const override { return new BarrelSteering(*this); } }; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 151ad43..8ba9083 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -13,8 +13,7 @@ void GameWorld::Initialize() BindKey(GLFW_KEY_A, "horizontal", -1.f); BindKey(GLFW_KEY_D, "horizontal", 1.f); BindGamepadAxis(Gamepad::Axis::LeftX, "horizontal", 1.f); - BindGamepadAxis(Gamepad::Axis::RightTrigger, "vertical", 1.f); - BindGamepadAxis(Gamepad::Axis::LeftTrigger, "vertical", -1.f); + BindGamepadAxis(Gamepad::Axis::LeftY, "vertical", 1.f); BindKey(GLFW_KEY_UP, "barrel_rotation", 1.f); BindKey(GLFW_KEY_DOWN, "barrel_rotation", -1.f); @@ -27,7 +26,7 @@ void GameWorld::Initialize() BindGamepadButton(Gamepad::Button::A, "handbrake", 1.f); BindKey(GLFW_KEY_Z, "shoot", 1.f); - + BindGamepadAxis(Gamepad::Axis::RightTrigger, "shoot", 1.f); //BindGamepadButton(Gamepad::Button::Up, "Gamepad::Button::Up", 1.f); //BindGamepadButton(Gamepad::Button::Down, "Gamepad::Button::Down", 1.f); //BindGamepadButton(Gamepad::Button::Left, "Gamepad::Button::Left", 1.f); @@ -106,7 +105,29 @@ void GameWorld::Initialize() CommitEntity(ground); } - + { + auto container = CreateEntity(); + auto transform = AddComponent(container, "Transform"); + transform->Position = glm::vec3(40.f, 20.f, 10.f); + transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); + auto model = AddComponent(container, "Model"); + model->ModelFile = "Models/Container/Container.OBJ"; + + auto physics = AddComponent(container, "Physics"); + physics->Mass = 4000; + physics->Static = false; + + { + auto groundshape = CreateEntity(container); + auto transformshape = AddComponent(groundshape, "Transform"); + auto meshShape = AddComponent(groundshape, "MeshShape"); + meshShape->ResourceName = "Models/Container/Container.OBJ"; + CommitEntity(groundshape); + } + + + CommitEntity(container); + } /*{ auto jeep = CreateEntity(); @@ -292,6 +313,7 @@ void GameWorld::Initialize() barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f); barrelSteering->TurnSpeed = glm::pi()/4.f; barrelSteering->ShotSpeed = 70.f; + barrelSteering->ReloadTime = 0.33f; { auto shot = CreateEntity(barrel); auto transform = AddComponent(shot, "Transform"); @@ -305,6 +327,10 @@ void GameWorld::Initialize() auto modelComponent = AddComponent(shot, "Model"); modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj"; + auto light = AddComponent(shot, "PointLight"); + light->Diffuse = glm::vec3(230.f / 255.f, 115.f / 255.f, 0.f / 255.f); + light->Specular = glm::vec3(1.f); + { auto shape = CreateEntity(shot); auto transform = AddComponent(shape, "Transform"); @@ -319,18 +345,33 @@ void GameWorld::Initialize() } CommitEntity(barrel); } + CommitEntity(tower); + + { + auto camera = CreateEntity(tower); + auto transform = AddComponent(camera, "Transform"); + transform->Position.z = 30.f; + transform->Position.y = 5.f; + //transform->Orientation = glm::quat(glm::vec3(-glm::pi() / 8.f, 0.f, 0.f)); + transform->Orientation = glm::angleAxis(glm::pi() / 100, glm::vec3(1, 0, 0)); + auto cameraComp = AddComponent(camera, "Camera"); + cameraComp->FarClip = 2000.f; + AddComponent(camera, "Input"); + auto freeSteering = AddComponent(camera, "FreeSteering"); + CommitEntity(camera); + } } { auto lightentity = CreateEntity(tank); auto transform = AddComponent(lightentity, "Transform"); - transform->Position = glm::vec3(0, 0, 0); + transform->Position = glm::vec3(0, 14, 0); auto light = AddComponent(lightentity, "PointLight"); - //light->Diffuse = glm::vec3(128.f/255.f, 172.f/255.f, 242.f/255.f); - //light->Specular = glm::vec3(1.f); - /*light->ConstantAttenuation = 0.3f; - light->LinearAttenuation = 0.003f; - light->QuadraticAttenuation = 0.002f;*/ + light->Diffuse = glm::vec3(60.f/255.f, 50.f/255.f, 242.f/255.f); + light->Specular = glm::vec3(0.7f); + light->ConstantAttenuation = 0.3f; + light->LinearAttenuation = 0.002f; + light->QuadraticAttenuation = 0.06f; } // auto wheelpair = CreateEntity(tank); @@ -340,7 +381,7 @@ void GameWorld::Initialize() //Create wheels float wheelOffset = 0.4f; float springLength = 0.3f; - float suspensionStrength = 25.f; + float suspensionStrength = 15.f; { auto wheel = CreateEntity(tank); @@ -538,6 +579,7 @@ void GameWorld::Initialize() //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); CommitEntity(entity); + SetProperty(tank, "Emitter1", emitterComponent); auto particleEntity = CreateEntity(entity); auto TEMP = AddComponent(particleEntity, "Transform"); @@ -622,6 +664,7 @@ void GameWorld::Initialize() //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); CommitEntity(entity); + SetProperty(tank, "Emitter2", emitterComponent); auto particleEntity = CreateEntity(entity); auto TEMP = AddComponent(particleEntity, "Transform"); @@ -634,19 +677,6 @@ void GameWorld::Initialize() } CommitEntity(tank); - { - auto camera = CreateEntity(tank); - auto transform = AddComponent(camera, "Transform"); - transform->Position.z = 30.f; - transform->Position.y = 5.f; - //transform->Orientation = glm::quat(glm::vec3(-glm::pi() / 8.f, 0.f, 0.f)); - transform->Orientation = glm::angleAxis(glm::pi() / 100, glm::vec3(1,0,0)); - auto cameraComp = AddComponent(camera, "Camera"); - cameraComp->FarClip = 2000.f; - AddComponent(camera, "Input"); - auto freeSteering = AddComponent(camera, "FreeSteering"); - CommitEntity(camera); - } } diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 3498e93..44a4162 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -791,12 +791,12 @@ void Renderer::DrawLightScene() glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "lp"), 1, glm::value_ptr(light.Position)); glUniform3f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "CameraPosition"), m_Camera->Position().x, m_Camera->Position().y, m_Camera->Position().z); glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "specularExponent"), light.SpecularExponent); -// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ConstantAttenuation"), light.ConstantAttenuation); -// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), light.LinearAttenuation); -// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), light.QuadraticAttenuation); - glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ConstantAttenuation"), CAtt); - glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), LAtt); - glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), QAtt); + glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ConstantAttenuation"), light.ConstantAttenuation); + glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), light.LinearAttenuation); + glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), light.QuadraticAttenuation); +// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ConstantAttenuation"), CAtt); +// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), LAtt); +// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), QAtt); glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size()); }; @@ -812,13 +812,13 @@ void Renderer::SetSphereModel( Model* _model ) glm::mat4 Renderer::CreateLightMatrix(Light &_light) { -// float c = _light.ConstantAttenuation; -// float l = _light.LinearAttenuation; -// float q = _light.QuadraticAttenuation; - float c = CAtt; - float l = LAtt; - float q = QAtt; - float cutOffRadius = abs(sqrt((-4*c*q) + pow(l, 2) + (1024*q) - l) / (2*q)); + float c = _light.ConstantAttenuation; + float l = _light.LinearAttenuation; + float q = _light.QuadraticAttenuation; +// float c = CAtt; +// float l = LAtt; +// float q = QAtt; + float cutOffRadius = abs(sqrt((-4*c*q) + pow(l, 2) + (1024*q) - l) / (2*q)) + 6; glm::mat4 model; model *= glm::translate(_light.Position); diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index 6ecbfb9..f1b85e2 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -32,6 +32,12 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit e.PositionY = m_TankInputController->PositionY; e.Handbrake = m_TankInputController->Handbrake; EventBroker->Publish(e); + + auto emitter1 = m_World->GetProperty>(entity, "Emitter1"); + auto emitter2 = m_World->GetProperty>(entity, "Emitter2"); + + emitter1->SpawnCount = (int)(m_TankInputController->PositionY < -0.1) * 2; + emitter2->SpawnCount = (int)(m_TankInputController->PositionY < -0.1) * 2; } auto towerSteeringComponent = m_World->GetComponent(entity, "TowerSteering"); @@ -50,7 +56,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * m_TowerInputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis); transformComponent->Orientation *= orientation; - if(m_TowerInputController->Shoot && m_TimeSinceLastShot[entity] > 1.0) + if (m_TowerInputController->Shoot && m_TimeSinceLastShot[entity] > barrelSteeringComponent->ReloadTime) { EntityID clone = m_World->CloneEntity(barrelSteeringComponent->ShotTemplate); auto templateAbsoluteTransform = m_World->GetSystem("TransformSystem")->AbsoluteTransform(barrelSteeringComponent->ShotTemplate); diff --git a/src/Systems/TankSteeringSystem.h b/src/Systems/TankSteeringSystem.h index d264325..1f66ffe 100644 --- a/src/Systems/TankSteeringSystem.h +++ b/src/Systems/TankSteeringSystem.h @@ -8,6 +8,7 @@ #include "Components/TowerSteering.h" #include "Components/BarrelSteering.h" #include "Components/Vehicle.h" +#include "Components/ParticleEmitter.h" #include "Systems/TransformSystem.h" #include "InputController.h"