Demo stuff

This commit is contained in:
2014-05-13 05:04:09 +02:00
parent bafa8d0a5d
commit 3e7bd21fad
6 changed files with 78 additions and 40 deletions
+1 -1
Submodule assets updated: 15ac02523a...0a617d58c7
+2 -1
View File
@@ -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); }
};
+54 -24
View File
@@ -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<Components::Transform>(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<Components::Model>(container, "Model");
model->ModelFile = "Models/Container/Container.OBJ";
auto physics = AddComponent<Components::Physics>(container, "Physics");
physics->Mass = 4000;
physics->Static = false;
{
auto groundshape = CreateEntity(container);
auto transformshape = AddComponent<Components::Transform>(groundshape, "Transform");
auto meshShape = AddComponent<Components::MeshShape>(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<float>()/4.f;
barrelSteering->ShotSpeed = 70.f;
barrelSteering->ReloadTime = 0.33f;
{
auto shot = CreateEntity(barrel);
auto transform = AddComponent<Components::Transform>(shot, "Transform");
@@ -305,6 +327,10 @@ void GameWorld::Initialize()
auto modelComponent = AddComponent<Components::Model>(shot, "Model");
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
auto light = AddComponent<Components::PointLight>(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<Components::Transform>(shape, "Transform");
@@ -319,18 +345,33 @@ void GameWorld::Initialize()
}
CommitEntity(barrel);
}
CommitEntity(tower);
{
auto camera = CreateEntity(tower);
auto transform = AddComponent<Components::Transform>(camera, "Transform");
transform->Position.z = 30.f;
transform->Position.y = 5.f;
//transform->Orientation = glm::quat(glm::vec3(-glm::pi<float>() / 8.f, 0.f, 0.f));
transform->Orientation = glm::angleAxis(glm::pi<float>() / 100, glm::vec3(1, 0, 0));
auto cameraComp = AddComponent<Components::Camera>(camera, "Camera");
cameraComp->FarClip = 2000.f;
AddComponent(camera, "Input");
auto freeSteering = AddComponent<Components::FreeSteering>(camera, "FreeSteering");
CommitEntity(camera);
}
}
{
auto lightentity = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(lightentity, "Transform");
transform->Position = glm::vec3(0, 0, 0);
transform->Position = glm::vec3(0, 14, 0);
auto light = AddComponent<Components::PointLight>(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<float>() / 100);
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
CommitEntity(entity);
SetProperty(tank, "Emitter1", emitterComponent);
auto particleEntity = CreateEntity(entity);
auto TEMP = AddComponent<Components::Transform>(particleEntity, "Transform");
@@ -622,6 +664,7 @@ void GameWorld::Initialize()
//emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
CommitEntity(entity);
SetProperty(tank, "Emitter2", emitterComponent);
auto particleEntity = CreateEntity(entity);
auto TEMP = AddComponent<Components::Transform>(particleEntity, "Transform");
@@ -634,19 +677,6 @@ void GameWorld::Initialize()
}
CommitEntity(tank);
{
auto camera = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(camera, "Transform");
transform->Position.z = 30.f;
transform->Position.y = 5.f;
//transform->Orientation = glm::quat(glm::vec3(-glm::pi<float>() / 8.f, 0.f, 0.f));
transform->Orientation = glm::angleAxis(glm::pi<float>() / 100, glm::vec3(1,0,0));
auto cameraComp = AddComponent<Components::Camera>(camera, "Camera");
cameraComp->FarClip = 2000.f;
AddComponent(camera, "Input");
auto freeSteering = AddComponent<Components::FreeSteering>(camera, "FreeSteering");
CommitEntity(camera);
}
}
+13 -13
View File
@@ -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);
+7 -1
View File
@@ -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<std::shared_ptr<Components::ParticleEmitter>>(entity, "Emitter1");
auto emitter2 = m_World->GetProperty<std::shared_ptr<Components::ParticleEmitter>>(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<Components::TowerSteering>(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<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(barrelSteeringComponent->ShotTemplate);
+1
View File
@@ -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"