Merge branch 'master' into havok

Conflicts:
	assets
	src/GameWorld.cpp
	vs11/Returngeance/Returngeance.vcxproj.filters
This commit is contained in:
2014-05-17 21:23:46 +02:00
40 changed files with 1394 additions and 883 deletions
+14 -5
View File
@@ -9,13 +9,22 @@ namespace Components
struct PointLight : Component
{
float Intensity;
float MaxRange;
PointLight()
: Specular(1.0f, 1.0f, 1.0f)
, Diffuse(1.0f, 1.0f, 1.0f)
, specularExponent(50.0f)
, ConstantAttenuation(1.0f)
, LinearAttenuation(0.f)
, QuadraticAttenuation(3.f)
{ }
float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation;
Color color;
glm::vec3 Specular;
glm::vec3 Diffuse;
float constantAttenuation, linearAttenuation, quadraticAttenuation;
float spotExponent;
Color color;
float specularExponent;
float Scale;
virtual PointLight* Clone() const override { return new PointLight(*this); }
};
+1
View File
@@ -10,6 +10,7 @@ struct BindMouseButton : Event
{
int Button;
std::string Command;
float Value;
};
}
+14
View File
@@ -0,0 +1,14 @@
#ifndef Events_LockMouse_h__
#define Events_LockMouse_h__
#include "EventBroker.h"
namespace Events
{
struct LockMouse : Event { };
struct UnlockMouse : Event { };
}
#endif // Events_LockMouse_h__
+22 -2
View File
@@ -10,12 +10,18 @@ template <typename T>
class Factory
{
public:
void Register(std::string name, std::function<T(void)> factoryFunction)
/*void Register(std::string name, std::function<T(void)> factoryFunction)
{
m_FactoryFunctions[name] = factoryFunction;
}*/
template <typename T2>
void Register(std::function<T(void)> factoryFunction)
{
m_FactoryFunctions[typeid(T2).name()] = factoryFunction;
}
T Create(std::string name)
/*T Create(std::string name)
{
auto it = m_FactoryFunctions.find(name);
if (it != m_FactoryFunctions.end())
@@ -26,6 +32,20 @@ public:
{
return nullptr;
}
}*/
template <typename T2>
T Create()
{
auto it = m_FactoryFunctions.find(typeid(T2).name());
if (it != m_FactoryFunctions.end())
{
return it->second();
}
else
{
return nullptr;
}
}
private:
+196 -216
View File
@@ -13,20 +13,20 @@ 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);
BindKey(GLFW_KEY_LEFT, "tower_rotation", -1.f);
BindKey(GLFW_KEY_RIGHT, "tower_rotation", 1.f);
BindGamepadAxis(Gamepad::Axis::RightX, "tower_rotation", 1.f);
BindGamepadAxis(Gamepad::Axis::RightY, "barrel_rotation", 1.f);
BindKey(GLFW_KEY_SPACE, "handbrake", 1.f);
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);
@@ -42,62 +42,40 @@ void GameWorld::Initialize()
//BindGamepadButton(Gamepad::Button::B, "Gamepad::Button::B", 1.f);
//BindGamepadButton(Gamepad::Button::X, "Gamepad::Button::X", 1.f);
//BindGamepadButton(Gamepad::Button::Y, "Gamepad::Button::Y", 1.f);
//
// BindKey(GLFW_KEY_UP, "vertical", -1.f);
// BindKey(GLFW_KEY_DOWN, "vertical", 1.f);
// BindKey(GLFW_KEY_LEFT, "horizontal", -1.f);
// BindKey(GLFW_KEY_RIGHT, "horizontal", 1.f);
/*
BindKey(GLFW_KEY_Q, "+tower_right");
BindKey(GLFW_KEY_E, "+tower_left");
BindKey(GLFW_KEY_Q, "+up");
BindKey(GLFW_KEY_LEFT_CONTROL, "+down");
BindKey(GLFW_KEY_LEFT_ALT, "+slow");
BindKey(GLFW_KEY_LEFT_SHIFT, "+fast");
BindMouseButton(GLFW_MOUSE_BUTTON_1, "+attack");
BindMouseButton(GLFW_MOUSE_BUTTON_2, "+attack2");
BindMouseButton(GLFW_MOUSE_BUTTON_3, "+attack3");
BindKey(GLFW_KEY_UP, "+cam_forward");
BindKey(GLFW_KEY_DOWN, "+cam_backward");
BindKey(GLFW_KEY_LEFT, "+cam_left");
BindKey(GLFW_KEY_RIGHT, "+cam_right");*/
RegisterComponents();
{
auto camera = CreateEntity();
auto transform = AddComponent<Components::Transform>(camera, "Transform");
transform->Position.z = 20.f;
transform->Position.y = 20.f;
//transform->Orientation = glm::quat(glm::vec3(glm::pi<float>() / 8.f, 0.f, 0.f));
auto cameraComp = AddComponent<Components::Camera>(camera, "Camera");
cameraComp->FarClip = 2000.f;
auto freeSteering = AddComponent<Components::FreeSteering>(camera, "FreeSteering");
CommitEntity(camera);
}
//{
// auto camera = CreateEntity();
// auto transform = AddComponent<Components::Transform>(camera);
// transform->Position.z = 20.f;
// transform->Position.y = 20.f;
// //transform->Orientation = glm::quat(glm::vec3(glm::pi<float>() / 8.f, 0.f, 0.f));
// auto cameraComp = AddComponent<Components::Camera>(camera);
// cameraComp->FarClip = 2000.f;
// auto freeSteering = AddComponent<Components::FreeSteering>(camera);
// CommitEntity(camera);
//}
{
auto ground = CreateEntity();
auto transform = AddComponent<Components::Transform>(ground, "Transform");
auto transform = AddComponent<Components::Transform>(ground);
transform->Position = glm::vec3(0, 0, 0);
//transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f);
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
auto model = AddComponent<Components::Model>(ground, "Model");
auto model = AddComponent<Components::Model>(ground);
//model->ModelFile = "Models/TestScene/testScene.obj";
model->ModelFile = "Models/Placeholders/Terrain/Terrain2.obj";
auto physics = AddComponent<Components::Physics>(ground, "Physics");
auto physics = AddComponent<Components::Physics>(ground);
physics->Mass = 10;
physics->Static = true;
auto groundshape = CreateEntity(ground);
auto transformshape = AddComponent<Components::Transform>(groundshape, "Transform");
auto meshShape = AddComponent<Components::MeshShape>(groundshape, "MeshShape");
auto transformshape = AddComponent<Components::Transform>(groundshape);
auto meshShape = AddComponent<Components::MeshShape>(groundshape);
meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain2.obj";
//meshShape->ResourceName = "Models/TestScene/testScene.obj";
@@ -110,23 +88,23 @@ void GameWorld::Initialize()
/*{
auto jeep = CreateEntity();
auto transform = AddComponent<Components::Transform>(jeep, "Transform");
auto transform = AddComponent<Components::Transform>(jeep);
transform->Position = glm::vec3(0, 5, 0);
transform->Orientation = glm::angleAxis(glm::pi<float>()/2, glm::vec3(0, 1, 0));
auto physics = AddComponent<Components::Physics>(jeep, "Physics");
auto physics = AddComponent<Components::Physics>(jeep);
physics->Mass = 1800;
physics->Static = false;
auto vehicle = AddComponent<Components::Vehicle>(jeep, "Vehicle");
AddComponent<Components::Input>(jeep, "Input");
auto vehicle = AddComponent<Components::Vehicle>(jeep);
AddComponent<Components::Input>(jeep);
{
auto shape = CreateEntity(jeep);
auto transform = AddComponent<Components::Transform>(shape, "Transform");
auto meshShape = AddComponent<Components::MeshShape>(shape, "MeshShape");
auto transform = AddComponent<Components::Transform>(shape);
auto meshShape = AddComponent<Components::MeshShape>(shape);
meshShape->ResourceName = "Models/Jeep/Chassi/ChassiCollision.obj";
CommitEntity(shape);
// auto box = AddComponent<Components::Box>(jeep, "Box");
// auto box = AddComponent<Components::Box>(jeep);
// box->Width = 1.487f;
// box->Height = 0.727f;
// box->Depth = 2.594f;
@@ -135,17 +113,17 @@ void GameWorld::Initialize()
{
auto chassis = CreateEntity(jeep);
auto transform = AddComponent<Components::Transform>(chassis, "Transform");
auto transform = AddComponent<Components::Transform>(chassis);
transform->Position = glm::vec3(0, 0, 0); // 0.6577f
auto model = AddComponent<Components::Model>(chassis, "Model");
auto model = AddComponent<Components::Model>(chassis);
model->ModelFile = "Models/Jeep/Chassi/chassi.obj";
}
{
auto lightentity = CreateEntity(jeep);
auto transform = AddComponent<Components::Transform>(lightentity, "Transform");
auto transform = AddComponent<Components::Transform>(lightentity);
transform->Position = glm::vec3(0, 15, 0);
auto light = AddComponent<Components::PointLight>(lightentity, "PointLight");
auto light = AddComponent<Components::PointLight>(lightentity);
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;
@@ -160,12 +138,12 @@ void GameWorld::Initialize()
float suspensionStrength = 35.f;
{
auto wheel = CreateEntity(jeep);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.9f, 0.5546f - wheelOffset, -0.9242f);
transform->Scale = glm::vec3(1.0f);
auto model = AddComponent<Components::Model>(wheel, "Model");
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 50;
@@ -179,13 +157,13 @@ void GameWorld::Initialize()
{
auto wheel = CreateEntity(jeep);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.9f, 0.5546f - wheelOffset, -0.9242f);
transform->Scale = glm::vec3(1.0f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
auto model = AddComponent<Components::Model>(wheel, "Model");
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 50;
@@ -199,11 +177,11 @@ void GameWorld::Initialize()
{
auto wheel = CreateEntity(jeep);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(0.2726f, 0.2805f - wheelOffset, 1.9307f);
auto model = AddComponent<Components::Model>(wheel, "Model");
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 50;
@@ -217,12 +195,12 @@ void GameWorld::Initialize()
{
auto wheel = CreateEntity(jeep);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-0.2726f, 0.2805f - wheelOffset, 1.9307f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
auto model = AddComponent<Components::Model>(wheel, "Model");
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 50;
@@ -240,26 +218,26 @@ void GameWorld::Initialize()
{
auto tank = CreateEntity();
auto transform = AddComponent<Components::Transform>(tank, "Transform");
auto transform = AddComponent<Components::Transform>(tank);
transform->Position = glm::vec3(0, 5, 0);
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
auto physics = AddComponent<Components::Physics>(tank, "Physics");
auto physics = AddComponent<Components::Physics>(tank);
physics->Mass = 45000;
physics->Static = false;
auto vehicle = AddComponent<Components::Vehicle>(tank, "Vehicle");
auto vehicle = AddComponent<Components::Vehicle>(tank);
vehicle->MaxTorque = 5200.f;
vehicle->MaxSteeringAngle = 90.f;
AddComponent<Components::TankSteering>(tank, "TankSteering");
AddComponent<Components::Input>(tank, "Input");
AddComponent<Components::TankSteering>(tank);
AddComponent<Components::Input>(tank);
{
auto shape = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(shape, "Transform");
auto meshShape = AddComponent<Components::MeshShape>(shape, "MeshShape");
auto transform = AddComponent<Components::Transform>(shape);
auto meshShape = AddComponent<Components::MeshShape>(shape);
meshShape->ResourceName = "Models/Tank/Fix/ChassiCollision.obj";
CommitEntity(shape);
// auto box = AddComponent<Components::Box>(jeep, "Box");
// auto box = AddComponent<Components::Box>(jeep);
// box->Width = 1.487f;
// box->Height = 0.727f;
// box->Depth = 2.594f;
@@ -268,48 +246,48 @@ void GameWorld::Initialize()
{
auto chassis = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(chassis, "Transform");
auto transform = AddComponent<Components::Transform>(chassis);
transform->Position = glm::vec3(0, 0, 0);
auto model = AddComponent<Components::Model>(chassis, "Model");
auto model = AddComponent<Components::Model>(chassis);
model->ModelFile = "Models/Tank/Fix/Chassi.obj";
}
{
auto tower = CreateEntity(tank);
SetProperty(tower, "Name", "tower");
auto transform = AddComponent<Components::Transform>(tower, "Transform");
auto transform = AddComponent<Components::Transform>(tower);
transform->Position = glm::vec3(0.f, 1.2f, 1.8f);
auto model = AddComponent<Components::Model>(tower, "Model");
auto model = AddComponent<Components::Model>(tower);
model->ModelFile = "Models/Tank/Fix/Top.obj";
auto towerSteering = AddComponent<Components::TowerSteering>(tower, "TowerSteering");
auto towerSteering = AddComponent<Components::TowerSteering>(tower);
towerSteering->Axis = glm::vec3(0.f, 1.f, 0.f);
towerSteering->TurnSpeed = glm::pi<float>()/4.f;
{
auto barrel = CreateEntity(tower);
auto transform = AddComponent<Components::Transform>(barrel, "Transform");
auto transform = AddComponent<Components::Transform>(barrel);
transform->Position = glm::vec3(-0.018f, -0.2, -1.3f);
auto model = AddComponent<Components::Model>(barrel, "Model");
auto model = AddComponent<Components::Model>(barrel);
model->ModelFile = "Models/Tank/Fix/Barrel.obj";
auto barrelSteering = AddComponent<Components::BarrelSteering>(barrel, "BarrelSteering");
auto barrelSteering = AddComponent<Components::BarrelSteering>(barrel);
barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f);
barrelSteering->TurnSpeed = glm::pi<float>()/4.f;
barrelSteering->ShotSpeed = 70.f;
{
auto shot = CreateEntity(barrel);
auto transform = AddComponent<Components::Transform>(shot, "Transform");
auto transform = AddComponent<Components::Transform>(shot);
transform->Position = glm::vec3(0.35f, 0.f, -2.f);
transform->Orientation = glm::angleAxis(-glm::pi<float>()/2.f, glm::vec3(1, 0, 0));
transform->Scale = glm::vec3(3.f);
AddComponent(shot, "Template");
auto physics = AddComponent<Components::Physics>(shot, "Physics");
AddComponent<Components::Template>(shot);
auto physics = AddComponent<Components::Physics>(shot);
physics->Mass = 10.f;
physics->Static = false;
auto modelComponent = AddComponent<Components::Model>(shot, "Model");
auto modelComponent = AddComponent<Components::Model>(shot);
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
{
auto shape = CreateEntity(shot);
auto transform = AddComponent<Components::Transform>(shape, "Transform");
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
auto transform = AddComponent<Components::Transform>(shape);
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.5f;
boxShape->Height = 0.5f;
boxShape->Depth = 0.5f;
@@ -320,18 +298,32 @@ void GameWorld::Initialize()
}
CommitEntity(barrel);
}
{
auto camera = CreateEntity(tower);
auto transform = AddComponent<Components::Transform>(camera);
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);
cameraComp->FarClip = 2000.f;
AddComponent<Components::Input>(camera);
//auto freeSteering = AddComponent<Components::FreeSteering>(camera);
CommitEntity(camera);
}
}
{
auto lightentity = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(lightentity, "Transform");
transform->Position = glm::vec3(0, 15, 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;
auto transform = AddComponent<Components::Transform>(lightentity);
transform->Position = glm::vec3(0, 0, 0);
auto light = AddComponent<Components::PointLight>(lightentity);
//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;*/
}
// auto wheelpair = CreateEntity(tank);
@@ -345,12 +337,12 @@ void GameWorld::Initialize()
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -2.6f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel, "Model");
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
@@ -363,9 +355,9 @@ void GameWorld::Initialize()
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
@@ -375,12 +367,12 @@ void GameWorld::Initialize()
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -0.83f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel, "Model");
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
@@ -393,9 +385,9 @@ void GameWorld::Initialize()
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
@@ -406,12 +398,12 @@ void GameWorld::Initialize()
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -2.6f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel, "Model");
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
@@ -424,9 +416,9 @@ void GameWorld::Initialize()
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
@@ -436,12 +428,12 @@ void GameWorld::Initialize()
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -0.83f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel, "Model");
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
@@ -454,9 +446,9 @@ void GameWorld::Initialize()
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
@@ -469,11 +461,11 @@ void GameWorld::Initialize()
//Back
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 1.f);
auto model = AddComponent<Components::Model>(wheel, "Model");
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
@@ -486,9 +478,9 @@ void GameWorld::Initialize()
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
@@ -498,11 +490,11 @@ void GameWorld::Initialize()
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 2.95f);
auto model = AddComponent<Components::Model>(wheel, "Model");
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
@@ -515,9 +507,9 @@ void GameWorld::Initialize()
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
@@ -525,12 +517,12 @@ void GameWorld::Initialize()
}
CommitEntity(wheel);
/*auto entity = CreateEntity(tank);
auto transformComponent = AddComponent<Components::Transform>(entity, "Transform");
auto entity = CreateEntity(tank);
auto transformComponent = AddComponent<Components::Transform>(entity);
transformComponent->Position = glm::vec3(2,-1.7,2.0);
transformComponent->Scale = glm::vec3(3,3,3);
transformComponent->Orientation = glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0));
auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity, "ParticleEmitter");
auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity);
emitterComponent->SpawnCount = 2;
emitterComponent->SpawnFrequency = 0.005;
emitterComponent->SpreadAngle = glm::pi<float>();
@@ -541,23 +533,23 @@ void GameWorld::Initialize()
CommitEntity(entity);
auto particleEntity = CreateEntity(entity);
auto TEMP = AddComponent<Components::Transform>(particleEntity, "Transform");
auto TEMP = AddComponent<Components::Transform>(particleEntity);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity, "Sprite");
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
emitterComponent->ParticleTemplate = particleEntity;
CommitEntity(particleEntity);*/
CommitEntity(particleEntity);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 1.f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel, "Model");
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
@@ -570,9 +562,9 @@ void GameWorld::Initialize()
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
@@ -582,11 +574,11 @@ void GameWorld::Initialize()
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 2.95f);
auto model = AddComponent<Components::Model>(wheel, "Model");
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
@@ -599,9 +591,9 @@ void GameWorld::Initialize()
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
@@ -609,45 +601,32 @@ void GameWorld::Initialize()
}
CommitEntity(wheel);
//auto entity = CreateEntity(tank);
//auto transformComponent = AddComponent<Components::Transform>(entity, "Transform");
//transformComponent->Position = glm::vec3(-2,-1.7,2.0);
//transformComponent->Scale = glm::vec3(3,3,3);
//transformComponent->Orientation = glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0));
//auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity, "ParticleEmitter");
//emitterComponent->SpawnCount = 2;
//emitterComponent->SpawnFrequency = 0.005;
//emitterComponent->SpreadAngle = glm::pi<float>();
//emitterComponent->UseGoalVelocity = false;
//emitterComponent->LifeTime = 0.5;
////emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
//emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
//CommitEntity(entity);
auto entity = CreateEntity(tank);
auto transformComponent = AddComponent<Components::Transform>(entity);
transformComponent->Position = glm::vec3(-2,-1.7,2.0);
transformComponent->Scale = glm::vec3(3,3,3);
transformComponent->Orientation = glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0));
auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity);
emitterComponent->SpawnCount = 2;
emitterComponent->SpawnFrequency = 0.005;
emitterComponent->SpreadAngle = glm::pi<float>();
emitterComponent->UseGoalVelocity = false;
emitterComponent->LifeTime = 0.5;
//emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
CommitEntity(entity);
//auto particleEntity = CreateEntity(entity);
//auto TEMP = AddComponent<Components::Transform>(particleEntity, "Transform");
//TEMP->Scale = glm::vec3(0);
//auto spriteComponent = AddComponent<Components::Sprite>(particleEntity, "Sprite");
//spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
//emitterComponent->ParticleTemplate = particleEntity;
auto particleEntity = CreateEntity(entity);
auto TEMP = AddComponent<Components::Transform>(particleEntity);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
emitterComponent->ParticleTemplate = particleEntity;
//CommitEntity(particleEntity);
CommitEntity(particleEntity);
}
CommitEntity(tank);
{
auto camera = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(camera, "Transform");
transform->Position.z = 20.f;
transform->Position.y = 7.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);
}
}
@@ -656,7 +635,7 @@ void GameWorld::Initialize()
for(int i = 0; i < 10; i++)
{
auto entity = CreateEntity();
auto transform = AddComponent<Components::Transform>(entity, "Transform");
auto transform = AddComponent<Components::Transform>(entity);
transform->Position = glm::vec3(30 + i*0.1f, 0 + i*0.1f, 10 + i*0.1f);
transform->Scale = glm::vec3(0);
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
@@ -664,13 +643,13 @@ void GameWorld::Initialize()
std::stringstream ss;
ss << "Models/Placeholders/ShatterTest/" << i+1 << ".obj";
auto model = AddComponent<Components::Model>(entity, "Model");
auto model = AddComponent<Components::Model>(entity);
model->ModelFile = ss.str();
auto physics = AddComponent<Components::Physics>(entity, "Physics");
auto physics = AddComponent<Components::Physics>(entity);
physics->Mass = 100;
physics->Static = true;
auto meshShape = AddComponent<Components::MeshShape>(entity, "MeshShape");
auto meshShape = AddComponent<Components::MeshShape>(entity);
meshShape->ResourceName = ss.str();
CommitEntity(entity);
@@ -683,22 +662,22 @@ void GameWorld::Initialize()
for (int x = -5; x < 5; x++)
{
auto brick = CreateEntity();
auto transform = AddComponent<Components::Transform>(brick, "Transform");
auto transform = AddComponent<Components::Transform>(brick);
transform->Position = glm::vec3(x + 0.01f, y * 0.3f + 0.01f, -20);
transform->Position.x += (y % 2)*0.5f;
transform->Scale = glm::vec3(1, 0.3f, 0.4f);
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
auto model = AddComponent<Components::Model>(brick, "Model");
auto model = AddComponent<Components::Model>(brick);
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
auto physics = AddComponent<Components::Physics>(brick, "Physics");
auto physics = AddComponent<Components::Physics>(brick);
physics->Mass = 3;
auto shape = CreateEntity(brick);
auto transformshape = AddComponent<Components::Transform>(shape, "Transform");
auto box = AddComponent<Components::BoxShape>(shape, "BoxShape");
auto transformshape = AddComponent<Components::Transform>(shape);
auto box = AddComponent<Components::BoxShape>(shape);
box->Width = 0.5f;
box->Height = 0.15f;
box->Depth = 0.3f;
@@ -712,16 +691,16 @@ void GameWorld::Initialize()
for (int y = 0; y < 5; y++)
{
auto cube = CreateEntity();
auto transform = AddComponent<Components::Transform>(cube, "Transform");
auto transform = AddComponent<Components::Transform>(cube);
transform->Position = glm::vec3(3 * x + 0.1f + -20.f, 3 * y + 0.1f + 1.f, 0);
transform->Scale = glm::vec3(3);
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
auto model = AddComponent<Components::Model>(cube, "Model");
auto model = AddComponent<Components::Model>(cube);
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
auto physics = AddComponent<Components::Physics>(cube, "Physics");
auto physics = AddComponent<Components::Physics>(cube);
physics->Mass = 100;
auto box = AddComponent<Components::BoxShape>(cube, "BoxShape");
auto box = AddComponent<Components::BoxShape>(cube);
box->Width = 1.5f;
box->Height = 1.5f;
box->Depth = 1.5f;
@@ -733,7 +712,7 @@ void GameWorld::Initialize()
/*{
auto entity = CreateEntity();
AddComponent(entity, "Transform");
auto emitter = AddComponent<Components::SoundEmitter>(entity, "SoundEmitter");
auto emitter = AddComponent<Components::SoundEmitter>(entity);
emitter->Path = "Sounds/korvring.wav";
emitter->Loop = true;
GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(emitter);
@@ -749,40 +728,40 @@ void GameWorld::Update(double dt)
void GameWorld::RegisterComponents()
{
m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); });
m_ComponentFactory.Register("Template", []() { return new Components::Template(); });
m_ComponentFactory.Register<Components::Transform>([]() { return new Components::Transform(); });
m_ComponentFactory.Register<Components::Template>([]() { return new Components::Template(); });
}
void GameWorld::RegisterSystems()
{
m_SystemFactory.Register("TransformSystem", [this]() { return new Systems::TransformSystem(this, m_EventBroker); });
//m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); });
m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_EventBroker); });
m_SystemFactory.Register("DebugSystem", [this]() { return new Systems::DebugSystem(this, m_EventBroker); });
//m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); });
m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this, m_EventBroker); });
//m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); });
m_SystemFactory.Register("FreeSteeringSystem", [this]() { return new Systems::FreeSteeringSystem(this, m_EventBroker); });
m_SystemFactory.Register("TankSteeringSystem", [this]() { return new Systems::TankSteeringSystem(this, m_EventBroker); });
m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this, m_EventBroker); });
m_SystemFactory.Register("PhysicsSystem", [this]() { return new Systems::PhysicsSystem(this, m_EventBroker); });
m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_EventBroker, m_Renderer); });
m_SystemFactory.Register<Systems::TransformSystem>([this]() { return new Systems::TransformSystem(this, m_EventBroker); });
//m_SystemFactory.Register<Systems::LevelGenerationSystem>([this]() { return new Systems::LevelGenerationSystem(this); });
m_SystemFactory.Register<Systems::InputSystem>([this]() { return new Systems::InputSystem(this, m_EventBroker); });
m_SystemFactory.Register<Systems::DebugSystem>([this]() { return new Systems::DebugSystem(this, m_EventBroker); });
//m_SystemFactory.Register<Systems::CollisionSystem>([this]() { return new Systems::CollisionSystem(this); });
m_SystemFactory.Register<Systems::ParticleSystem>([this]() { return new Systems::ParticleSystem(this, m_EventBroker); });
//m_SystemFactory.Register<Systems::PlayerSystem>([this]() { return new Systems::PlayerSystem(this); });
m_SystemFactory.Register<Systems::FreeSteeringSystem>([this]() { return new Systems::FreeSteeringSystem(this, m_EventBroker); });
m_SystemFactory.Register<Systems::TankSteeringSystem>([this]() { return new Systems::TankSteeringSystem(this, m_EventBroker); });
m_SystemFactory.Register<Systems::SoundSystem>([this]() { return new Systems::SoundSystem(this, m_EventBroker); });
m_SystemFactory.Register<Systems::PhysicsSystem>([this]() { return new Systems::PhysicsSystem(this, m_EventBroker); });
m_SystemFactory.Register<Systems::RenderSystem>([this]() { return new Systems::RenderSystem(this, m_EventBroker, m_Renderer); });
}
void GameWorld::AddSystems()
{
AddSystem("TransformSystem");
//AddSystem("LevelGenerationSystem");
AddSystem("InputSystem");
AddSystem("DebugSystem");
//AddSystem("CollisionSystem");
AddSystem("ParticleSystem");
//AddSystem("PlayerSystem");
AddSystem("FreeSteeringSystem");
AddSystem("TankSteeringSystem");
AddSystem("SoundSystem");
AddSystem("PhysicsSystem");
AddSystem("RenderSystem");
AddSystem<Systems::TransformSystem>();
//AddSystem<Systems::LevelGenerationSystem>();
AddSystem<Systems::InputSystem>();
AddSystem<Systems::DebugSystem>();
//AddSystem<Systems::CollisionSystem>();
AddSystem<Systems::ParticleSystem>();
//AddSystem<Systems::PlayerSystem>();
AddSystem<Systems::FreeSteeringSystem>();
AddSystem<Systems::TankSteeringSystem>();
AddSystem<Systems::SoundSystem>();
AddSystem<Systems::PhysicsSystem>();
AddSystem<Systems::RenderSystem>();
}
void GameWorld::BindKey(int keyCode, std::string command, float value)
@@ -794,11 +773,12 @@ void GameWorld::BindKey(int keyCode, std::string command, float value)
m_EventBroker->Publish(e);
}
void GameWorld::BindMouseButton(int button, std::string command)
void GameWorld::BindMouseButton(int button, std::string command, float value)
{
Events::BindMouseButton e;
e.Button = button;
e.Command = command;
e.Value = value;
m_EventBroker->Publish(e);
}
+1 -1
View File
@@ -57,7 +57,7 @@ private:
std::shared_ptr<Renderer> m_Renderer;
void BindKey(int keyCode, std::string command, float value);
void BindMouseButton(int button, std::string command);
void BindMouseButton(int button, std::string command, float value);
void BindGamepadAxis(Gamepad::Axis axis, std::string command, float value);
void BindGamepadButton(Gamepad::Button button, std::string command, float value);
};
+27 -8
View File
@@ -5,6 +5,9 @@ void InputManager::Initialize()
{
m_LastGamepadAxisState = std::array<GamepadAxisState, XUSER_MAX_COUNT>();
m_LastGamepadButtonState = std::array<GamepadButtonState, XUSER_MAX_COUNT>();
EVENT_SUBSCRIBE_MEMBER(m_ELockMouse, &InputManager::OnLockMouse);
EVENT_SUBSCRIBE_MEMBER(m_EUnlockMouse, &InputManager::OnUnlockMouse);
}
void InputManager::Update(double dt)
@@ -20,13 +23,13 @@ void InputManager::Update(double dt)
{
Events::KeyDown e;
e.KeyCode = i;
m_EventBroker->Publish(e);
EventBroker->Publish(e);
}
else
{
Events::KeyUp e;
e.KeyCode = i;
m_EventBroker->Publish(e);
EventBroker->Publish(e);
}
}
}
@@ -42,13 +45,13 @@ void InputManager::Update(double dt)
{
Events::MousePress e;
e.Button = i;
m_EventBroker->Publish(e);
EventBroker->Publish(e);
}
else
{
Events::MouseRelease e;
e.Button = i;
m_EventBroker->Publish(e);
EventBroker->Publish(e);
}
}
}
@@ -65,7 +68,7 @@ void InputManager::Update(double dt)
e.Y = m_CurrentMouseY;
e.DeltaX = m_CurrentMouseDeltaX;
e.DeltaY = m_CurrentMouseDeltaY;
m_EventBroker->Publish(e);
EventBroker->Publish(e);
}
// // Lock mouse while holding LMB
@@ -156,7 +159,7 @@ void InputManager::PublishGamepadAxisIfChanged(int gamepadID, Gamepad::Axis axis
e.GamepadID = gamepadID;
e.Axis = axis;
e.Value = currentValue;
m_EventBroker->Publish(e);
EventBroker->Publish(e);
}
}
@@ -171,14 +174,30 @@ void InputManager::PublishGamepadButtonIfChanged(int gamepadID, Gamepad::Button
Events::GamepadButtonDown e;
e.GamepadID = gamepadID;
e.Button = button;
m_EventBroker->Publish(e);
EventBroker->Publish(e);
}
else
{
Events::GamepadButtonUp e;
e.GamepadID = gamepadID;
e.Button = button;
m_EventBroker->Publish(e);
EventBroker->Publish(e);
}
}
}
bool InputManager::OnLockMouse(const Events::LockMouse &event)
{
m_MouseLocked = true;
glfwSetInputMode(m_GLFWWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
return true;
}
bool InputManager::OnUnlockMouse(const Events::UnlockMouse &event)
{
m_MouseLocked = false;
glfwSetInputMode(m_GLFWWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
return true;
}
+13 -5
View File
@@ -11,22 +11,24 @@
#include "Events/MousePress.h"
#include "Events/MouseRelease.h"
#include "Events/MouseMove.h"
#include "Events/LockMouse.h"
#include "Events/GamepadAxis.h"
#include "Events/GamepadButton.h"
class InputManager
{
public:
InputManager(GLFWwindow* window, std::shared_ptr<EventBroker> eventBroker)
InputManager(GLFWwindow* window, std::shared_ptr<::EventBroker> eventBroker)
: m_GLFWWindow(window)
, m_EventBroker(eventBroker)
, EventBroker(eventBroker)
, m_CurrentKeyState()
, m_LastKeyState()
, m_CurrentMouseState()
, m_LastMouseState()
, m_CurrentMouseX(0), m_CurrentMouseY(0)
, m_LastMouseX(0), m_LastMouseY(0)
, m_CurrentMouseDeltaX(0), m_CurrentMouseDeltaY(0)
, m_CurrentMouseDeltaX(0), m_CurrentMouseDeltaY(0)
, m_MouseLocked(false)
{ Initialize(); }
void Initialize();
@@ -35,8 +37,13 @@ public:
private:
GLFWwindow* m_GLFWWindow;
std::shared_ptr<EventBroker> m_EventBroker;
std::shared_ptr<::EventBroker> EventBroker;
EventRelay<Events::LockMouse> m_ELockMouse;
bool OnLockMouse(const Events::LockMouse &event);
EventRelay<Events::UnlockMouse> m_EUnlockMouse;
bool OnUnlockMouse(const Events::UnlockMouse &event);
std::array<int, GLFW_KEY_LAST+1> m_CurrentKeyState;
std::array<int, GLFW_KEY_LAST+1> m_LastKeyState;
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_CurrentMouseState;
@@ -51,6 +58,7 @@ private:
double m_CurrentMouseX, m_CurrentMouseY;
double m_LastMouseX, m_LastMouseY;
double m_CurrentMouseDeltaX, m_CurrentMouseDeltaY;
bool m_MouseLocked;
void PublishGamepadAxisIfChanged(int gamepadID, Gamepad::Axis axis);
void PublishGamepadButtonIfChanged(int gamepadID, Gamepad::Button button);
+3 -3
View File
@@ -7,13 +7,13 @@
void VehicleSetup::buildVehicle(World *world, const hkpWorld* physicsWorld, hkpVehicleInstance& vehicle, EntityID vehicleEntity, std::vector<EntityID> wheelEntities)
{
auto vehicleComponent = world->GetComponent<Components::Vehicle>(vehicleEntity, "Vehicle");
auto vehicleComponent = world->GetComponent<Components::Vehicle>(vehicleEntity);
WheelData wheelData;
for (int i = 0; i < wheelEntities.size(); i++)
{
wheelData.WheelComponent = world->GetComponent<Components::Wheel>(wheelEntities[i], "Wheel");
wheelData.TransformComponent = world->GetComponent<Components::Transform>(wheelEntities[i], "Transform");
wheelData.WheelComponent = world->GetComponent<Components::Wheel>(wheelEntities[i]);
wheelData.TransformComponent = world->GetComponent<Components::Transform>(wheelEntities[i]);
m_Wheels.push_back(wheelData);
}
+446 -211
View File
@@ -13,12 +13,15 @@ Renderer::Renderer()
m_DrawWireframe = false;
m_DrawBounds = false;
#endif
m_ShadowMapRes = 2048;
Gamma = 2.2f;
CAtt = 1.0f;
LAtt = 0.0f;
QAtt = 3.0f;
m_ShadowMapRes = 2048*8;
m_SunPosition = glm::vec3(0, 3.5f, 10);
m_SunTarget = glm::vec3(0, 0, 0);
m_SunProjection = glm::ortho<float>(-100, 100, -100, 100, -100, 100);
Lights = 0;
m_SunProjection = glm::ortho<float>(-200.f, 200.f, -200.f, 200.f, -100, 200);
/* Lights = 0;*/
}
void Renderer::Initialize()
@@ -76,7 +79,7 @@ void Renderer::Initialize()
void Renderer::LoadContent()
{
auto standardVS = std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex.glsl"));
/*auto standardVS = std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex.glsl"));
auto standardFS = std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment.glsl"));
m_ShaderProgram.AddShader(standardVS);
@@ -89,12 +92,7 @@ void Renderer::LoadContent()
m_ShaderProgramNormals.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Normals.frag.glsl")));
m_ShaderProgramNormals.Compile();
m_ShaderProgramNormals.Link();
m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ShadowMap.vert.glsl")));
m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ShadowMap.frag.glsl")));
m_ShaderProgramShadows.Compile();
m_ShaderProgramShadows.Link();
m_ShaderProgramShadowsDrawDepth.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/VisualizeDepth.vert.glsl")));
m_ShaderProgramShadowsDrawDepth.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/VisualizeDepth.frag.glsl")));
m_ShaderProgramShadowsDrawDepth.Compile();
@@ -108,13 +106,124 @@ void Renderer::LoadContent()
m_ShaderProgramSkybox.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Skybox.vert.glsl")));
m_ShaderProgramSkybox.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Skybox.frag.glsl")));
m_ShaderProgramSkybox.Compile();
m_ShaderProgramSkybox.Link();
m_ShaderProgramSkybox.Link();*/
m_Skybox = std::make_shared<Skybox>("Textures/Skybox/Sunset", "jpg");
m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ShadowMap.vert.glsl")));
m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ShadowMap.frag.glsl")));
m_ShaderProgramShadows.Compile();
m_ShaderProgramShadows.Link();
m_DebugAABB = CreateAABB();
m_FirstPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex.glsl")));
m_FirstPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment.glsl")));
m_FirstPassProgram.Compile();
glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 0, "frag_Diffuse");
glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 1, "frag_Position");
glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 2, "frag_Normal");
m_FirstPassProgram.Link();
m_SecondPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex2.glsl")));
m_SecondPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment2.glsl")));
m_SecondPassProgram.Compile();
m_SecondPassProgram.Link();
m_SecondPassProgram_Debug.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex2.glsl")));
m_SecondPassProgram_Debug.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment2-Debug.glsl")));
m_SecondPassProgram_Debug.Compile();
m_SecondPassProgram_Debug.Link();
m_FinalPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/FinalPass.vert.glsl")));
m_FinalPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FinalPass.frag.glsl")));
m_FinalPassProgram.Compile();
m_FinalPassProgram.Link();
m_ScreenQuad = CreateQuad();
CreateShadowMap(m_ShadowMapRes);
FrameBufferTextures();
}
void Renderer::Draw(double dt)
{
if(glfwGetKey(m_Window, GLFW_KEY_F1))
{
m_QuadView = false;
}
if(glfwGetKey(m_Window, GLFW_KEY_F2))
{
m_QuadView = true;
}
if(glfwGetKey(m_Window, GLFW_KEY_KP_1))
{
Gamma -= 0.3f * dt;
LOG_INFO("Gamma_UP: %f", Gamma);
}
if(glfwGetKey(m_Window, GLFW_KEY_KP_4))
{
Gamma += 0.3f * dt;
LOG_INFO("Gamma_DOWN: %f", Gamma);
}
if(glfwGetKey(m_Window, GLFW_KEY_1))
{
if(glfwGetKey(m_Window, GLFW_KEY_KP_ADD))
{
CAtt += 0.5f * dt;
LOG_INFO("Const: %f", CAtt);
}
if(glfwGetKey(m_Window, GLFW_KEY_KP_SUBTRACT))
{
CAtt -= 0.5f * dt;
LOG_INFO("Const: %f", CAtt);
}
}
if(glfwGetKey(m_Window, GLFW_KEY_2))
{
if(glfwGetKey(m_Window, GLFW_KEY_KP_ADD))
{
LAtt += 0.5f * dt;
LOG_INFO("Linear: %f", LAtt);
}
if(glfwGetKey(m_Window, GLFW_KEY_KP_SUBTRACT))
{
LAtt -= 0.5f * dt;
LOG_INFO("Linear: %f", LAtt);
}
}
if(glfwGetKey(m_Window, GLFW_KEY_3))
{
if(glfwGetKey(m_Window, GLFW_KEY_KP_ADD))
{
QAtt += 0.5f * dt;
LOG_INFO("Quadratic: %f", QAtt);
}
if(glfwGetKey(m_Window, GLFW_KEY_KP_SUBTRACT))
{
QAtt -= 0.5f * dt;
LOG_INFO("Quadratic: %f", QAtt);
}
}
glDisable(GL_BLEND);
DrawFBO();
ClearStuff();
glfwSwapBuffers(m_Window);
}
#pragma region TempRegion
void Renderer::DrawSkybox()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, m_Width, m_Height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_ShaderProgramSkybox.Bind();
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * glm::toMat4(glm::inverse(m_Camera->Orientation()));
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(cameraMatrix));
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
m_Skybox->Draw();
}
void Renderer::CreateShadowMap(int resolution)
@@ -137,194 +246,35 @@ void Renderer::CreateShadowMap(int resolution)
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_ShadowDepthTexture, 0);
glDrawBuffer(GL_NONE);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
LOG_ERROR("Framebuffer incomplete!");
return;
}
}
void Renderer::Draw(double dt)
{
glDisable(GL_BLEND);
DrawSkybox();
DrawShadowMap();
DrawScene();
#ifdef DEBUG
// Draw bounding boxes
if (m_DrawBounds)
{
glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
m_ShaderProgramDebugAABB.Bind();
for (auto tuple : AABBsToRender)
{
glm::mat4 modelMatrix;
bool colliding;
std::tie(modelMatrix, colliding) = tuple;
// Model matrix
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
glm::mat4 MVP = cameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
// Color
glm::vec4 color(1.f, 1.f, 1.f, 0.f);
if (colliding)
color = glm::vec4(1.f, 0.f, 0.f, 0.f);
glUniform4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "Color"), 1, glm::value_ptr(color));
glBindVertexArray(m_DebugAABB);
glDrawArrays(GL_LINES, 0, 24);
}
}
DrawDebugShadowMap();
#endif
ClearStuff();
glfwSwapBuffers(m_Window);
}
void Renderer::DrawSkybox()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, m_Width, m_Height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_ShaderProgramSkybox.Bind();
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * glm::toMat4(glm::inverse(m_Camera->Orientation()));
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(cameraMatrix));
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
m_Skybox->Draw();
}
void Renderer::DrawScene()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, m_Width, m_Height);
glClear(GL_DEPTH_BUFFER_BIT);
//glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
#ifdef DEBUG
glDisable(GL_CULL_FACE);
glPolygonMode(GL_BACK, GL_LINE);
#endif
// Draw models
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate(-m_Camera->Position() * glm::vec3(1, 0, 0));
glm::mat4 depthCamera = m_SunProjection * depthViewMatrix;
glm::mat4 biasMatrix(
0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.5, 0.5, 0.5, 1.0
);
m_ShaderProgram.Bind();
glUniform1i(glGetUniformLocation(m_ShaderProgram.GetHandle(), "numberOfLights"), Lights);
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), Lights, Light_position.data());
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), Lights, Light_specular.data());
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "diffuse"), Lights, Light_diffuse.data());
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), Lights, Light_constantAttenuation.data());
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), Lights, Light_linearAttenuation.data());
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), Lights, Light_quadraticAttenuation.data());
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), Lights, Light_spotExponent.data());
if (m_DrawWireframe)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
//DrawModels(m_ShaderProgram);
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
glm::mat4 depthCameraMatrix = biasMatrix * depthCamera;
glm::mat4 MVP;
glm::mat4 depthMVP;
for (auto tuple : ModelsToRender)
{
Model* model;
glm::mat4 modelMatrix;
bool visible;
std::tie(model, modelMatrix, visible, std::ignore) = tuple;
if (!visible)
continue;
MVP = cameraMatrix * modelMatrix;
depthMVP = depthCameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glBindVertexArray(model->VAO);
for (auto texGroup : model->TextureGroups)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, *texGroup.Texture);
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
}
}
for (auto tuple : TexturesToRender)
{
Texture* texture;
glm::mat4 modelMatrix;
glm::mat4 billboardMatrix;
std::tie(texture, modelMatrix, billboardMatrix) = tuple;
//MVP = cameraMatrix * glm::inverse(glm::toMat4(m_Camera->Orientation()) * modelMatrix );
MVP = cameraMatrix * modelMatrix * billboardMatrix;
depthMVP = depthCameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, *texture);
glBindVertexArray(m_ScreenQuad);
glDrawArrays(GL_TRIANGLES, 0, 6);
}
#ifdef DEBUG
// Debug draw model normals
if (m_DrawNormals)
{
m_ShaderProgramNormals.Bind();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
DrawModels(m_ShaderProgramNormals);
}
#endif
}
void Renderer::DrawShadowMap()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glEnable(GL_DEPTH_TEST);//Tests where objects are and display them correctly
glEnable(GL_CULL_FACE); //removes triangles on the wrong side of the object
glCullFace(GL_BACK); //Make it so that only the back faces are rendered
//Binds the FBO and sets the veiwport, witch in effect is how large the shadowmap is and what resolution it has.
glBindFramebuffer(GL_FRAMEBUFFER, m_ShadowFrameBuffer);
glViewport(0, 0, m_ShadowMapRes, m_ShadowMapRes);
glClear(GL_DEPTH_BUFFER_BIT);
//glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate(-m_Camera->Position() * glm::vec3(1, 0, 0));
// glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0));
//Creates the "camera" for the shadowmap from the direction of the sun.
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0));
glm::mat4 depthCamera = m_SunProjection * depthViewMatrix;
//glm::mat4 cameraMatrix = depthProjectionMatrix * m_Camera->ViewMatrix();
glm::mat4 MVP;
m_ShaderProgramShadows.Bind();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //Draws filled polygons
//For each model, render them to the shadowmap
for (auto tuple : ModelsToRender)
{
Model* model;
@@ -425,26 +375,22 @@ void Renderer::AddPointLightToDraw(
glm::vec3 _position,
glm::vec3 _specular,
glm::vec3 _diffuse,
float _constantAttenuation,
float _linearAttenuation,
float _quadraticAttenuation,
float _spotExponent
float _specularExponent,
float _ConstantAttenuation,
float _LinearAttenuation,
float _QuadraticAttenuation
)
{
Light_position.push_back(_position.x);
Light_position.push_back(_position.y);
Light_position.push_back(_position.z);
Light_specular.push_back(_specular.x);
Light_specular.push_back(_specular.y);
Light_specular.push_back(_specular.z);
Light_diffuse.push_back(_diffuse.x);
Light_diffuse.push_back(_diffuse.y);
Light_diffuse.push_back(_diffuse.z);
Light_constantAttenuation.push_back(_constantAttenuation);
Light_linearAttenuation.push_back(_linearAttenuation);
Light_quadraticAttenuation.push_back(_quadraticAttenuation);
Light_spotExponent.push_back(_spotExponent);
Lights = Light_constantAttenuation.size();
Light light;
light.Position = _position;
light.Diffuse = _diffuse;
light.Specular = _specular;
light.SpecularExponent = _specularExponent;
light.ConstantAttenuation = _ConstantAttenuation;
light.LinearAttenuation = _LinearAttenuation;
light.QuadraticAttenuation = _QuadraticAttenuation;
light.SphereModelMatrix = CreateLightMatrix(light);
Lights.push_back(light);
}
void Renderer::AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding)
@@ -577,17 +523,306 @@ GLuint Renderer::CreateSkybox()
return vao;
}
void Renderer::ClearStuff()
{
AABBsToRender.clear();
ModelsToRender.clear();
TexturesToRender.clear();
Light_position.clear();
Light_specular.clear();
Light_diffuse.clear();
Light_constantAttenuation.clear();
Light_linearAttenuation.clear();
Light_quadraticAttenuation.clear();
Light_spotExponent.clear();
Lights = 0;
}
Lights.clear();
}
#pragma endregion
void Renderer::FrameBufferTextures()
{
m_fbBasePass = 0;
m_fDepthBuffer = 0;
glGenFramebuffers(1, &m_fbBasePass);
glGenRenderbuffers(1, &m_fDepthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, m_fDepthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Width, m_Height);
//Generate and bind diffuse texture
glGenTextures(1, &m_fDiffuseTexture);
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//Generate and bind position texture
glGenTextures(1, &m_fPositionTexture);
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//Generate and bind normal texture
glGenTextures(1, &m_fNormalsTexture);
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
/*glGenTextures(1, &m_fShadowTexture);
glBindTexture(GL_TEXTURE_2D, m_fShadowTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);*/
//Bind fb
glBindFramebuffer(GL_FRAMEBUFFER, m_fbBasePass);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_fDepthBuffer);
//Attach textures to the FB
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fDiffuseTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, m_fPositionTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, m_fNormalsTexture, 0);
//glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, m_fShadowTexture, 0);
GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(fbStatus != GL_FRAMEBUFFER_COMPLETE)
{
LOG_ERROR("DeferredLighting:Init: m_fbBasePass incomplete: 0x%x\n", fbStatus);
//exit(1);
}
m_fbLightingPass = 0;
glGenFramebuffers(1, &m_fbLightingPass);
glGenTextures(1, &m_fLightingTexture);
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbLightingPass);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fLightingTexture, 0);
fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(fbStatus != GL_FRAMEBUFFER_COMPLETE)
{
LOG_ERROR("DeferredLighting:Init: m_fbLightingPass incomplete: 0x%x\n", fbStatus);
//exit(1);
}
}
void Renderer::DrawFBO()
{
DrawShadowMap();
/*
Base pass
*/
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass);
// Clear G-buffer
GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
glDrawBuffers(3, windowBuffClear);
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Execute the first render stage which will fill out the internal buffers with data(??)
m_FirstPassProgram.Bind();
GLenum windowBuffOpaque[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
glDrawBuffers(3, windowBuffOpaque);
glCullFace(GL_BACK);
glViewport(0, 0, m_Width, m_Height);
DrawFBOScene();
/*
Lighting pass
*/
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbLightingPass);
GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, lightingPassAttachments);
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
m_SecondPassProgram.Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
glCullFace(GL_FRONT);
DrawLightScene();
/*
Final pass
*/
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_FinalPassProgram.Bind();
// Ambient light
glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.1f, 0.1f, 0.1f)));
glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glCullFace(GL_BACK);
glBindVertexArray(m_ScreenQuad);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 6);
}
void Renderer::DrawFBOScene()
{
// glEnable(GL_DEPTH_TEST);//Tests where objects are and display them correctly
// glEnable(GL_CULL_FACE); //removes triangles on the wrong side of the object
// glCullFace(GL_BACK); //Make it so that only the back faces are rendered
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //Draws filled polygons
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
glm::mat4 MVP;
glm::mat4 biasMatrix(
0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.5, 0.5, 0.5, 1.0
);
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0));
glm::mat4 depthCamera = m_SunProjection * depthViewMatrix;
glm::mat4 depthCameraMatrix = biasMatrix * depthCamera;
glm::mat4 depthMVP;
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
for (auto tuple : ModelsToRender)
{
Model* model;
glm::mat4 modelMatrix;
bool visible;
std::tie(model, modelMatrix, visible, std::ignore) = tuple;
if (!visible)
continue;
MVP = cameraMatrix * modelMatrix;
depthMVP = depthCameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
glBindVertexArray(model->VAO);
for (auto texGroup : model->TextureGroups)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, *texGroup.Texture);
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
}
}
for (auto tuple : TexturesToRender)
{
Texture* texture;
glm::mat4 modelMatrix;
glm::mat4 billboardMatrix;
std::tie(texture, modelMatrix, billboardMatrix) = tuple;
//MVP = cameraMatrix * glm::inverse(glm::toMat4(m_Camera->Orientation()) * modelMatrix );
MVP = cameraMatrix * modelMatrix * billboardMatrix;
depthMVP = depthCameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, *texture);
glBindVertexArray(m_ScreenQuad);
glDrawArrays(GL_TRIANGLES, 0, 6);
}
}
void Renderer::DrawLightScene()
{
glEnable(GL_BLEND);
glBlendEquation (GL_FUNC_ADD);
glBlendFunc(GL_ONE,GL_ONE);
glDisable (GL_DEPTH_TEST);
glDepthMask (GL_FALSE);
glBindVertexArray(m_sphereModel->VAO);
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
glm::mat4 MVP;
for (auto &light : Lights)
{
MVP = cameraMatrix * light.SphereModelMatrix;
glUniform2fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ViewportSize"), 1,glm::value_ptr(glm::vec2(m_Width, m_Height)));
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(light.SphereModelMatrix));
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ls"), 1, glm::value_ptr(light.Specular));
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ld"), 1, glm::value_ptr(light.Diffuse));
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);
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
};
glEnable (GL_DEPTH_TEST);
glDepthMask (GL_TRUE);
glDisable (GL_BLEND);
}
void Renderer::SetSphereModel( Model* _model )
{
m_sphereModel = _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));
glm::mat4 model;
model *= glm::translate(_light.Position);
model *= glm::scale(glm::vec3(cutOffRadius));
return model;
}
+53 -13
View File
@@ -12,6 +12,7 @@
#include "Model.h"
#include "Components/PointLight.h"
#include "Skybox.h"
#include "ResourceManager.h"
class Renderer
{
@@ -26,14 +27,6 @@ public:
std::list<std::tuple<Model*, glm::mat4, bool, bool>> ModelsToRender;
std::list<std::tuple<Texture*, glm::mat4, glm::mat4>> TexturesToRender;
int Lights;
std::vector<float> Light_position;
std::vector<float> Light_specular;
std::vector<float> Light_diffuse;
std::vector<float> Light_constantAttenuation;
std::vector<float> Light_linearAttenuation;
std::vector<float> Light_quadraticAttenuation;
std::vector<float> Light_spotExponent;
std::list<std::tuple<glm::mat4, bool>> AABBsToRender;
Renderer();
@@ -49,10 +42,10 @@ public:
glm::vec3 _position,
glm::vec3 _specular,
glm::vec3 _diffuse,
float _constantAttenuation,
float _linearAttenuation,
float _quadraticAttenuation,
float _spotExponent
float _specularExponent,
float _ConstantAttenuation,
float _LinearAttenuation,
float _QuadraticAttenuation
);
void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding);
@@ -69,8 +62,25 @@ public:
void DrawBounds(bool val) { m_DrawBounds = val; }
void DrawSkybox();
void SetSphereModel(Model* _model);
private:
int m_Width, m_Height;
struct Light
{
glm::vec3 Position;
glm::vec3 Specular;
glm::vec3 Diffuse;
float SpecularExponent;
glm::mat4 SphereModelMatrix;
float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation;
};
float Gamma;
std::list<Light> Lights;
GLFWwindow* m_Window;
GLint m_glVersion[2];
GLchar* m_glVendor;
@@ -78,6 +88,7 @@ private:
bool m_DrawNormals;
bool m_DrawWireframe;
bool m_DrawBounds;
float CAtt, LAtt, QAtt;
std::shared_ptr<Skybox> m_Skybox;
@@ -87,24 +98,53 @@ private:
glm::mat4 m_SunProjection;
GLuint m_DebugAABB;
GLuint m_ScreenQuad;
GLuint m_ShadowFrameBuffer;
GLuint m_ShadowDepthTexture;
GLuint m_fbBasePass;
GLuint m_fDiffuseTexture;
GLuint m_fPositionTexture;
GLuint m_fNormalsTexture;
GLuint m_fBlendTexture;
GLuint m_fbLightingPass;
GLuint m_fLightingTexture;
GLuint m_fShadowTexture;
GLuint m_fDepthBuffer;
GLenum draw_bufs[2];
GLuint m_ScreenQuad;
Model* m_sphereModel;
bool m_QuadView;
std::shared_ptr<Camera> m_Camera;
ShaderProgram m_ShaderProgram;
ShaderProgram m_FirstPassProgram;
ShaderProgram m_SecondPassProgram;
ShaderProgram m_SecondPassProgram_Debug;
ShaderProgram m_FinalPassProgram;
ShaderProgram m_ShaderProgramNormals;
ShaderProgram m_ShaderProgramShadows;
ShaderProgram m_ShaderProgramShadowsDrawDepth;
ShaderProgram m_ShaderProgramDebugAABB;
ShaderProgram m_ShaderProgramSkybox;
void ClearStuff();
void DrawScene();
void DrawModels(ShaderProgram &shader);
void DrawShadowMap();
void CreateShadowMap(int resolution);
void FrameBufferTextures();
void DrawFBO();
void DrawFBOScene();
void DrawLightScene();
void BindFragDataLocation();
glm::mat4 CreateLightMatrix(Light &_light);
GLuint CreateQuad();
void DrawDebugShadowMap();
GLuint CreateAABB();
+6 -1
View File
@@ -103,6 +103,11 @@ void ShaderProgram::AddShader(std::shared_ptr<Shader> shader)
void ShaderProgram::Compile()
{
if (m_ShaderProgramHandle == 0)
{
m_ShaderProgramHandle = glCreateProgram();
}
for (auto &shader : m_Shaders)
{
if (!shader->IsCompiled())
@@ -121,7 +126,7 @@ GLuint ShaderProgram::Link()
}
LOG_INFO("Linking shader program");
m_ShaderProgramHandle = glCreateProgram();
for (auto &shader : m_Shaders)
{
glAttachShader(m_ShaderProgramHandle, shader->GetHandle());
+1 -1
View File
@@ -61,7 +61,7 @@ class ShaderProgram
{
public:
ShaderProgram()
: m_ShaderProgramHandle(0) { }
: m_ShaderProgramHandle(0) { }
~ShaderProgram();
void AddShader(std::shared_ptr<Shader> shader);
+29
View File
@@ -0,0 +1,29 @@
#version 430
uniform vec3 La;
uniform float Gamma;
layout (binding=0) uniform sampler2D DiffuseTexture;
layout (binding=1) uniform sampler2D LightingTexture;
layout (binding=2) uniform sampler2D ShadowTexture;
in VertexData
{
vec3 Position;
vec2 TextureCoord;
} Input;
out vec4 FragmentColor;
void main()
{
vec4 DiffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord);
vec4 ShadowTexel = texture(ShadowTexture, Input.TextureCoord);
vec4 _FragmentColor = DiffuseTexel * vec4(La, 1.0) + LightingTexel;
FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
//FragmentColor = ShadowTexel;
}
+16
View File
@@ -0,0 +1,16 @@
#version 430
layout(location = 0) in vec3 Position;
out VertexData
{
vec3 Position;
vec2 TextureCoord;
} Output;
void main()
{
gl_Position = vec4(Position, 1.0);
Output.Position = Position;
Output.TextureCoord = (vec2(Position) + 1) / 2;
}
+26 -96
View File
@@ -1,113 +1,43 @@
#version 430
uniform mat4 model;
uniform mat4 view;
layout(binding=0) uniform sampler2D texture0;
layout(binding=1) uniform sampler2D shadowMap;
const int maxNumberOfLights = 82;
uniform int numberOfLights;
uniform vec3 position[maxNumberOfLights];
uniform vec3 specular[maxNumberOfLights];
uniform vec3 diffuse[maxNumberOfLights];
uniform float constantAttenuation[maxNumberOfLights];
uniform float linearAttenuation[maxNumberOfLights];
uniform float quadraticAttenuation[maxNumberOfLights];
uniform float spotExponent[maxNumberOfLights];
layout (binding=0) uniform sampler2D DiffuseTexture;
layout (binding=1) uniform sampler2D ShadowTexture;
in VertexData
{
vec3 Position;
vec3 Normal;
vec2 TextureCoord;
vec3 ShadowCoord;
vec4 ShadowCoord;
} Input;
vec3 scene_ambient = vec3(0.5, 0.5, 0.5);
out vec4 frag_Diffuse;
out vec4 frag_Position;
out vec4 frag_Normal;
out vec4 fragmentColor;
float Shadow(vec4 ShadowCoord)
{
//float cosTheta = clamp(dot(Input.Normal, 1.0), 0.0, 1.0);
float bias = 0.0005; // cosTheta is dot( n,l ), clamped between 0 and 1
bias = clamp(bias, 0.0, 0.01);
if( texture(ShadowTexture, Input.ShadowCoord.xy).z < ShadowCoord.z - bias)
{
return 0.3;
}
else
{
return 1.0;
}
}
void main()
{
// Diffuse Texture
frag_Diffuse = texture(DiffuseTexture, Input.TextureCoord) * Shadow(Input.ShadowCoord);
// Texture
vec4 texel = texture2D(texture0, Input.TextureCoord);
//vec4 texel = (blend.x * texel0) + (blend.y * texel1) + (blend.z * texel2);
// G-buffer Position
frag_Position = vec4(Input.Position.xyz, 1.0);
//
// Phong shading
//
// Ambient light
vec3 La = scene_ambient; // Ambient light
vec3 Ks = vec3(0.3, 0.3, 0.3); // Specular reflectance
vec3 Kd = vec3(1.0, 1.0, 1.0); // Diffuse reflectance
vec3 Ka = vec3(1.0, 1.0, 1.0); // Ambient reflectance
vec3 Is;
vec3 Id;
// Shadows
//float cosTheta = clamp(dot(Input.Normal, vec3(0, 1, 0)), 0.0, 1.0);
//float bias = 0.001 * tan(acos(cosTheta)); // cosTheta is dot( n,l ), clamped between 0 and 1
//bias = clamp(bias, 0.0, 0.01);
float visibility = 1.0;
/*if (Input.ShadowCoord.x >= 0.0 && Input.ShadowCoord.x <= 1.0 && Input.ShadowCoord.y >= 0.0 && Input.ShadowCoord.y <= 1.0)
{
float bias = 0.00005;
vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy);
if (shadowMapValue.z < clamp(Input.ShadowCoord.z - bias, 0, 1))
{
visibility = 0.3;
}
}*/
vec3 totalLighting = La * Ka * visibility;
float attenuation;
for(int i = 0; i < numberOfLights && i < maxNumberOfLights; i++)
{
// Light
//vec3 lightPosition = vec3(0, 0, 2);
vec3 Ls = specular[i]; // Specular light
vec3 Ld = diffuse[i]; // Diffuse light
vec3 lightPosView = vec3(view * vec4(position[i], 1.0));
vec3 surfacePosition = vec3(model * vec4(Input.Position, 1.0));
vec3 surfacePosView = vec3(view * vec4(surfacePosition, 1.0));
vec3 surfaceToLight = normalize(lightPosView - surfacePosView);
mat3 normalMatrix = transpose(inverse(mat3(view * model)));
vec3 surfaceNormal = normalize(normalMatrix * Input.Normal);
float dist = length(position[i] - surfacePosition);
attenuation = 1.0 / (constantAttenuation[i]
+ linearAttenuation[i] * dist
+ quadraticAttenuation[i] * pow(dist, 2.0));
//attenuation = attenuation * pow(clampedCosine, spotExponent[i]);
// Diffuse light
float dotProd = dot(surfaceToLight, surfaceNormal);
dotProd = max(dotProd, 0.0);
Id = Ld * Kd * abs(dotProd) * attenuation;
// Specular light
vec3 reflection = reflect(-surfaceToLight, surfaceNormal);
float dotSpecular = dot(reflection, normalize(-surfacePosView));
dotSpecular = max(dotSpecular, 0.0);
float specularFactor = pow(dotSpecular, 30.0); // Specular factor
Is = attenuation * Ls * Ks * specularFactor;
totalLighting = totalLighting + Id + Is;
}
fragmentColor = vec4(totalLighting, 1.0) * texel;
//fragmentColor = vec4(Id, 1.0) * texel;
//fragmentColor = texel;
// G-buffer Normal
frag_Normal = vec4(Input.Normal, 0.0);
}
+38
View File
@@ -0,0 +1,38 @@
#version 430
layout (binding=0) uniform sampler2D DiffuseTexture;
layout (binding=1) uniform sampler2D PositionTexture;
layout (binding=2) uniform sampler2D NormalTexture;
in VertexData
{
vec3 Position;
vec3 Normal;
vec2 TextureCoord;
} Input;
out vec4 FragColor;
void DrawQuadrant(vec4 texel, vec2 quadrant)
{
if (-quadrant.x * Input.Position.x < 0 && -quadrant.y * Input.Position.y < 0)
{
FragColor = texel;
}
}
void main()
{
vec4 DiffuseTexel = texture2D(DiffuseTexture, Input.TextureCoord);
vec4 PositionTexel = texture2D(PositionTexture, Input.TextureCoord);
vec4 NormalTexel = texture2D(NormalTexture, Input.TextureCoord);
//FragColor = texture2D(DiffuseTexture, Input.TextureCoord * 2 + vec2(0, -1));
DrawQuadrant(texture2D(DiffuseTexture, Input.TextureCoord * 2), vec2(-1, 1));
DrawQuadrant(texture2D(PositionTexture, Input.TextureCoord * 2), vec2(1, 1));
DrawQuadrant(texture2D(NormalTexture, Input.TextureCoord * 2), vec2(-1, -1));
vec4 AllTexel = texture2D(DiffuseTexture, Input.TextureCoord*2)*texture2D(PositionTexture, Input.TextureCoord*2)*texture2D(NormalTexture, Input.TextureCoord*2);
DrawQuadrant(AllTexel, vec2(1, -1));
}
+84
View File
@@ -0,0 +1,84 @@
#version 430
layout (binding=0) uniform sampler2D PositionTexture;
layout (binding=1) uniform sampler2D NormalsTexture;
uniform vec2 ViewportSize;
uniform mat4 MVP;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform vec3 la;
uniform vec3 ls;
uniform vec3 ld;
uniform vec3 lp;
uniform float specularExponent;
uniform vec3 CameraPosition;
uniform float ConstantAttenuation;
uniform float LinearAttenuation;
uniform float QuadraticAttenuation;
const vec3 ks = vec3(1.0, 1.0, 1.0);
const vec3 kd = vec3(1.0, 1.0, 1.0);
const vec3 ka = vec3(1.0, 1.0, 1.0);
const float kshine = 1.0;
in VertexData
{
vec3 Position;
vec2 TextureCoord;
} Input;
out vec4 FragColor;
vec4 phong(vec3 position, vec3 normal)
{
// Diffuse
vec3 lightPos = vec3(V * vec4(lp, 1.0));
vec3 distanceToLight = lightPos - position;
vec3 directionToLight = normalize(distanceToLight);
float dotProd = dot(directionToLight, normal);
dotProd = max(dotProd, 0.0);
vec3 Id = kd * ld * dotProd;
// Specular
//vec3 reflection = reflect(-directionToLight, normal);
vec3 surfaceToViewer = normalize(-position);
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
float dotSpecular = max(dot(halfWay, normal), 0.0);
float specularFactor = pow(dotSpecular, specularExponent * 2.0);
vec3 Is = ks * ls * specularFactor;
//Attenuation
float dist = distance(lightPos, position);
//float attenuation = -log(min(1.0, dist / LightRadius));
float attenuation = 1.0 / (ConstantAttenuation + (LinearAttenuation * dist) + (QuadraticAttenuation * dist * dist));
//float attenuation = 1.0 / (1.0 - 0.0001 * pow(dist, 2));
//float attenuation = clamp(0.0, 1.0, 1.0 / (0.001 + (0.001 * dist) + (0.001 * dist * dist)));
//float attenuation = 1.0 / dot(directionToLight, directionToLight);
//float att_s = 5;
//float attenuation = pow(dist, 2) / pow(5.0, 2);
//attenuation = 1.0 / (1.0 + attenuation * att_s);
//att_s = 1.0 / (1.0 + att_s);
//attenuation = attenuation / (1.0 - att_s);
//float radius = 5.0;
//float alpha = dist / radius;
//float dampingFactor = 1.0 - pow(alpha, 3);
return vec4((Id + Is) * attenuation, 1.0);
}
void main()
{
vec2 TextureCoord = gl_FragCoord.xy / ViewportSize;
vec4 PositionTexel = texture(PositionTexture, TextureCoord);
vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
FragColor = phong(vec3(PositionTexel), vec3(NormalTexel));
}
+10 -7
View File
@@ -1,26 +1,29 @@
#version 430
uniform mat4 MVP;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform mat4 DepthMVP;
layout(location = 0) in vec3 Position;
layout(location = 1) in vec3 Normal;
layout(location = 2) in vec2 TextureCoord;
layout (location = 0) in vec3 Position;
layout (location = 1) in vec3 Normal;
layout (location = 2) in vec2 TextureCoord;
out VertexData
{
vec3 Position;
vec3 Normal;
vec2 TextureCoord;
vec3 ShadowCoord;
vec4 ShadowCoord;
} Output;
void main()
{
gl_Position = MVP * vec4(Position, 1.0);
Output.Position = Position;
Output.Normal = Normal;
Output.Position = vec3(V * M * vec4(Position, 1.0));
Output.Normal = normalize(vec3(inverse(transpose(V * M)) * vec4(Normal, 0.0)));
Output.TextureCoord = TextureCoord;
Output.ShadowCoord = vec3(DepthMVP * vec4(Position, 1.0));
Output.ShadowCoord = DepthMVP * vec4(Position, 1.0);
}
+22
View File
@@ -0,0 +1,22 @@
#version 430
uniform mat4 MVP;
layout (location = 0) in vec3 Position;
layout (location = 2) in vec2 TextureCoord;
uniform mat4 depthBiasMVP;
out VertexData
{
vec3 Position;
vec2 TextureCoord;
} Output;
void main()
{
gl_Position = MVP * vec4(Position, 1.0);
Output.Position = Position;
Output.TextureCoord = (vec2(Position) + 1.0) / 2.0;
}
-20
View File
@@ -1,20 +0,0 @@
#version 430
in vec2 TexCoord0;
in vec3 Normal0;
in vec3 WorldPos0;
layout (location = 0) out vec3 WorldPosOut;
layout (location = 1) out vec3 DiffuseOut;
layout (location = 2) out vec3 NormalOut;
layout (location = 3) out vec3 TexCoordOut;
uniform sampler2D gColorMap;
void main()
{
WorldPosOut = WorldPos0;
DiffuseOut = texture(gColorMap, TexCoord0).xyz;
NormalOut = normalize(Normal0);
TexCoordOut = vec3(TexCoord0, 0.0);
}
-20
View File
@@ -1,20 +0,0 @@
#version 430
layout (location = 0) in vec3 Position;
layout (location = 1) in vec2 TexCoord;
layout (location = 2) in vec3 Normal;
uniform mat4 gWVP;
uniform mat4 gWorld;
out vec2 TexCoord0;
out vec3 Normal0;
out vec3 WorldPos0;
void main()
{
gl_Position = gWVP * vec4(Position, 1.0);
TexCoord0 = TexCoord;
Normal0 = (gWorld * vec4(Normal, 0.0)).xyz;
WorldPos0 = (gWorld * vec4(Position, 1.0)).xyz;
}
+58 -72
View File
@@ -4,7 +4,7 @@
void Systems::FreeSteeringSystem::RegisterComponents(ComponentFactory* cf)
{
cf->Register("FreeSteering", []() { return new Components::FreeSteering(); });
cf->Register<Components::FreeSteering>([]() { return new Components::FreeSteering(); });
}
void Systems::FreeSteeringSystem::Initialize()
@@ -19,100 +19,90 @@ void Systems::FreeSteeringSystem::Update(double dt)
void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto steering = m_World->GetComponent<Components::FreeSteering>(entity, "FreeSteering");
auto steering = m_World->GetComponent<Components::FreeSteering>(entity);
if (steering)
{
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto transform = m_World->GetComponent<Components::Transform>(entity);
glm::vec3 cameraRight = glm::vec3(m_InputController->Orientation * glm::vec4(1, 0, 0, 0));
glm::vec3 cameraForward = glm::vec3(m_InputController->Orientation * glm::vec4(0, 0, -1, 0));
glm::vec3 cameraRight = glm::vec3(transform->Orientation * glm::vec4(1, 0, 0, 0));
glm::vec3 cameraForward = glm::vec3(transform->Orientation * glm::vec4(0, 0, -1, 0));
glm::vec3 movement;
movement += cameraRight * m_InputController->Movement.x;
movement.y += m_InputController->Movement.y;
movement += cameraForward * -m_InputController->Movement.z;
transform->Position += movement * steering->Speed * m_InputController->SpeedMultiplier * (float)dt;
transform->Orientation = m_InputController->Orientation;
float speedMultiplier = 1.f;
if (m_InputController->SpeedMultiplier > 0)
speedMultiplier *= 4;
else if (m_InputController->SpeedMultiplier < 0)
speedMultiplier /= 4;
transform->Position += movement * steering->Speed * speedMultiplier * (float)dt;
glm::quat mouseOrientationPitch = glm::quat(m_InputController->MouseOrientation * glm::vec3(1, 0, 0));
glm::quat mouseOrientationYaw = glm::quat(m_InputController->MouseOrientation * glm::vec3(0, 1, 0));
glm::vec3 controllerOrientationEuler = m_InputController->ControllerOrientation * (float)dt;
glm::quat controllerOrientationPitch = glm::quat(controllerOrientationEuler * glm::vec3(1, 0, 0));
glm::quat controllerOrientationYaw = glm::quat(controllerOrientationEuler * glm::vec3(0, 1, 0));
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
//---------------------------------------------------------------------
transform->Orientation = (mouseOrientationYaw * controllerOrientationYaw)
* transform->Orientation
* (mouseOrientationPitch * controllerOrientationPitch);
//---------------------------------------------------------------------
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
}
m_InputController->MouseOrientation = glm::vec3(0);
}
bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const Events::InputCommand &event)
{
// Movement
if (event.Command == "+cam_forward")
if (event.Command == "vertical")
{
Movement.z += -1.f;
Movement.z = -event.Value;
}
else if (event.Command == "-cam_forward")
else if (event.Command == "horizontal")
{
Movement.z -= -1.f;
Movement.x = event.Value;
}
else if (event.Command == "+cam_backward")
else if (event.Command == "normal")
{
Movement.z += 1.f;
}
else if (event.Command == "-cam_backward")
{
Movement.z -= 1.f;
}
else if (event.Command == "+cam_right")
{
Movement.x -= 1.f;
}
else if (event.Command == "-cam_right")
{
Movement.x += 1.f;
}
else if (event.Command == "+cam_left")
{
Movement.x -= -1.f;
}
else if (event.Command == "-cam_left")
{
Movement.x += -1.f;
}
else if (event.Command == "+up")
{
Movement.y += 1.f;
}
else if (event.Command == "-up")
{
Movement.y -= 1.f;
}
else if (event.Command == "+down")
{
Movement.y += -1.f;
}
else if (event.Command == "-down")
{
Movement.y -= -1.f;
Movement.y = event.Value;
}
// Speed
else if (event.Command == "+fast")
else if (event.Command == "speed")
{
SpeedMultiplier *= 4.f;
}
else if (event.Command == "-fast")
{
SpeedMultiplier /= 4.f;
}
else if (event.Command == "+slow")
{
SpeedMultiplier /= 4.f;
}
else if (event.Command == "-slow")
{
SpeedMultiplier *= 4.f;
SpeedMultiplier = event.Value;
}
// Mouse click
else if (event.Command == "+attack")
else if (event.Command == "attack")
{
OrientationActive = true;
OrientationActive = event.Value > 0;
if (OrientationActive)
{
Events::LockMouse e;
EventBroker->Publish(e);
}
else
{
Events::UnlockMouse e;
EventBroker->Publish(e);
}
}
else if (event.Command == "-attack")
else if (event.Command == "vertical2")
{
OrientationActive = false;
ControllerOrientation.x = event.Value;
}
else if (event.Command == "horizontal2")
{
ControllerOrientation.y = -event.Value;
}
return true;
@@ -122,11 +112,7 @@ bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnMouseMove(const
{
if (OrientationActive)
{
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
//---------------------------------------------------------------------
Orientation = glm::angleAxis<float>(event.DeltaX / 300.f, glm::vec3(0, -1, 0)) * Orientation * glm::angleAxis<float>(event.DeltaY / 300.f, glm::vec3(-1, 0, 0));
//---------------------------------------------------------------------
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
MouseOrientation = -glm::vec3(event.DeltaY / 300.f, event.DeltaX / 300.f, 0.f);
}
return true;
+4 -2
View File
@@ -4,6 +4,7 @@
#include "Components/Transform.h"
#include "Components/FreeSteering.h"
#include "InputController.h"
#include "Events/LockMouse.h"
namespace Systems
{
@@ -31,11 +32,12 @@ class FreeSteeringSystem::FreeSteeringInputController : InputController
public:
FreeSteeringInputController(std::shared_ptr<::EventBroker> eventBroker)
: InputController(eventBroker)
, SpeedMultiplier(1.f)
, SpeedMultiplier(0.f)
, OrientationActive(false) { }
glm::vec3 Movement;
glm::quat Orientation;
glm::vec3 MouseOrientation;
glm::vec3 ControllerOrientation;
float SpeedMultiplier;
bool OrientationActive;
+65 -15
View File
@@ -4,7 +4,7 @@
void Systems::InputSystem::RegisterComponents(ComponentFactory* cf)
{
cf->Register("Input", []() { return new Components::Input(); });
cf->Register<Components::Input>([]() { return new Components::Input(); });
}
void Systems::InputSystem::Initialize()
@@ -52,8 +52,8 @@ bool Systems::InputSystem::OnKeyDown(const Events::KeyDown &event)
std::string command;
float value;
std::tie(command, value) = bindingIt->second;
m_CommandValues[command] += value;
PublishCommand(0, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
m_CommandKeyboardValues[command][event.KeyCode] = value;
PublishCommand(0, command, GetCommandTotalValue(command));
}
return true;
@@ -67,8 +67,8 @@ bool Systems::InputSystem::OnKeyUp(const Events::KeyUp &event)
std::string command;
float value;
std::tie(command, value) = bindingIt->second;
m_CommandValues[command] -= value;
PublishCommand(0, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
m_CommandKeyboardValues[command][event.KeyCode] = 0;
PublishCommand(0, command, GetCommandTotalValue(command));;
}
return true;
@@ -79,7 +79,11 @@ bool Systems::InputSystem::OnMousePress(const Events::MousePress &event)
auto bindingIt = m_MouseButtonBindings.find(event.Button);
if (bindingIt != m_MouseButtonBindings.end())
{
PublishCommand(0, bindingIt->second, 1.f);
std::string command;
float value;
std::tie(command, value) = bindingIt->second;
m_CommandMouseButtonValues[command][event.Button] = value;
PublishCommand(0, command, GetCommandTotalValue(command));
}
return true;
@@ -90,7 +94,11 @@ bool Systems::InputSystem::OnMouseRelease(const Events::MouseRelease &event)
auto bindingIt = m_MouseButtonBindings.find(event.Button);
if (bindingIt != m_MouseButtonBindings.end())
{
PublishCommand(0, bindingIt->second, 1.f);
std::string command;
float value;
std::tie(command, value) = bindingIt->second;
m_CommandMouseButtonValues[command][event.Button] = 0;
PublishCommand(0, command, GetCommandTotalValue(command));
}
return true;
@@ -104,7 +112,8 @@ bool Systems::InputSystem::OnGamepadAxis(const Events::GamepadAxis &event)
std::string command;
float value;
std::tie(command, value) = bindingIt->second;
PublishCommand(event.GamepadID + 1, command, event.Value * value);
m_CommandGamepadAxisValues[command][event.Axis] = event.Value * value;
PublishCommand(event.GamepadID + 1, command, GetCommandTotalValue(command));
}
return true;
@@ -118,8 +127,8 @@ bool Systems::InputSystem::OnGamepadButtonDown(const Events::GamepadButtonDown &
std::string command;
float value;
std::tie(command, value) = bindingIt->second;
m_CommandValues[command] += value;
PublishCommand(event.GamepadID + 1, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
m_CommandGamepadButtonValues[command][event.Button] = value;
PublishCommand(event.GamepadID + 1, command, GetCommandTotalValue(command));
}
return true;
@@ -133,8 +142,8 @@ bool Systems::InputSystem::OnGamepadButtonUp(const Events::GamepadButtonUp &even
std::string command;
float value;
std::tie(command, value) = bindingIt->second;
m_CommandValues[command] -= value;
PublishCommand(event.GamepadID + 1, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
m_CommandGamepadButtonValues[command][event.Button] = 0;
PublishCommand(event.GamepadID + 1, command, GetCommandTotalValue(command));
}
return true;
@@ -164,7 +173,7 @@ bool Systems::InputSystem::OnBindMouseButton(const Events::BindMouseButton &even
}
else
{
m_MouseButtonBindings[event.Button] = event.Command;
m_MouseButtonBindings[event.Button] = std::make_tuple(event.Command, event.Value);
LOG_DEBUG("Input: Bound mouse button %i to %s", event.Button, event.Command.c_str());
}
@@ -201,6 +210,49 @@ bool Systems::InputSystem::OnBindGamepadButton(const Events::BindGamepadButton &
return true;
}
float Systems::InputSystem::GetCommandTotalValue(std::string command)
{
float value = 0.f;
auto keyboardIt = m_CommandKeyboardValues.find(command);
if (keyboardIt != m_CommandKeyboardValues.end())
{
for (auto &key : keyboardIt->second)
{
value += key.second;
}
}
auto mouseButtonIt = m_CommandMouseButtonValues.find(command);
if (mouseButtonIt != m_CommandMouseButtonValues.end())
{
for (auto &button : mouseButtonIt->second)
{
value += button.second;
}
}
auto gamepadAxisIt = m_CommandGamepadAxisValues.find(command);
if (gamepadAxisIt != m_CommandGamepadAxisValues.end())
{
for (auto &axis : gamepadAxisIt->second)
{
value += axis.second;
}
}
auto gamepadButtonIt = m_CommandGamepadButtonValues.find(command);
if (gamepadButtonIt != m_CommandGamepadButtonValues.end())
{
for (auto &button : gamepadButtonIt->second)
{
value += button.second;
}
}
return std::max(-1.f, std::min(value, 1.f));
}
void Systems::InputSystem::PublishCommand(int playerID, std::string command, float value)
{
Events::InputCommand e;
@@ -211,5 +263,3 @@ void Systems::InputSystem::PublishCommand(int playerID, std::string command, flo
LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, playerID);
}
+6 -2
View File
@@ -34,10 +34,13 @@ public:
void Update(double dt) override;
private:
std::unordered_map<std::string, float> m_CommandValues; // command string -> command current value
std::unordered_map<std::string, std::unordered_map<int, float>> m_CommandKeyboardValues; // command string -> keyboard key value for command
std::unordered_map<std::string, std::unordered_map<int, float>> m_CommandMouseButtonValues; // command string -> mouse button value for command
std::unordered_map<std::string, std::unordered_map<Gamepad::Axis, float>> m_CommandGamepadAxisValues; // command string -> gamepad axis value for command
std::unordered_map<std::string, std::unordered_map<Gamepad::Button, float>> m_CommandGamepadButtonValues; // command string -> gamepad button value for command
// Input binding tables
std::unordered_map<int, std::tuple<std::string, float>> m_KeyBindings; // GLFW_KEY... -> command string & value
std::unordered_map<int, std::string> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string
std::unordered_map<int, std::tuple<std::string, float>> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string
std::unordered_map<Gamepad::Axis, std::tuple<std::string, float>> m_GamepadAxisBindings; // Gamepad::Axis -> command string & value
std::unordered_map<Gamepad::Button, std::tuple<std::string, float>> m_GamepadButtonBindings; // Gamepad::Button -> command string
@@ -66,6 +69,7 @@ private:
EventRelay<Events::BindGamepadButton> m_EBindGamepadButton;
bool OnBindGamepadButton(const Events::BindGamepadButton &event);
float GetCommandTotalValue(std::string command);
void PublishCommand(int playerID, std::string command, float value);
};
+12 -12
View File
@@ -6,7 +6,7 @@
void Systems::ParticleSystem::Initialize()
{
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>("TransformSystem");
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
}
void Systems::ParticleSystem::Update(double dt)
@@ -16,15 +16,15 @@ void Systems::ParticleSystem::Update(double dt)
void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if(!transformComponent)
return;
auto emitterComponent = m_World->GetComponent<Components::ParticleEmitter>(entity, "ParticleEmitter");
auto emitterComponent = m_World->GetComponent<Components::ParticleEmitter>(entity);
if(emitterComponent)
{
emitterComponent->TimeSinceLastSpawn += dt;
auto emitterTransformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto emitterTransformComponent = m_World->GetComponent<Components::Transform>(entity);
if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency)
{
SpawnParticles(entity);
@@ -35,8 +35,8 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
for(it = m_ParticleEmitter[entity].begin(); it != m_ParticleEmitter[entity].end();)
{
EntityID particleID = (it)->ParticleID;
auto transformComponent = m_World->GetComponent<Components::Transform>(particleID, "Transform");
auto particleComponent = m_World->GetComponent<Components::Particle>(particleID, "Particle");
auto transformComponent = m_World->GetComponent<Components::Transform>(particleID);
auto particleComponent = m_World->GetComponent<Components::Particle>(particleID);
double timeLived = glfwGetTime() - it->SpawnTime;
if(timeLived > particleComponent->LifeTime)
@@ -94,15 +94,15 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
void Systems::ParticleSystem::RegisterComponents(ComponentFactory* cf)
{
cf->Register("ParticleEmitter", []() { return new Components::ParticleEmitter(); });
cf->Register("Particle", []() { return new Components::Particle(); });
cf->Register<Components::ParticleEmitter>([]() { return new Components::ParticleEmitter(); });
cf->Register<Components::Particle>([]() { return new Components::Particle(); });
}
void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
{
auto emitterComponent = m_World->GetComponent<Components::ParticleEmitter>(emitterID, "ParticleEmitter");
auto emitterTransform = m_World->GetComponent<Components::Transform>(emitterID, "Transform");
auto emitterComponent = m_World->GetComponent<Components::ParticleEmitter>(emitterID);
auto emitterTransform = m_World->GetComponent<Components::Transform>(emitterID);
glm::vec3 emitterPos = m_TransformSystem->AbsolutePosition(emitterID);
glm::quat emitterOrientation = emitterTransform->Orientation;
@@ -113,7 +113,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
{
auto ent = m_World->CloneEntity(emitterComponent->ParticleTemplate);
auto particleTransform = m_World->GetComponent<Components::Transform>(ent, "Transform");
auto particleTransform = m_World->GetComponent<Components::Transform>(ent);
particleTransform->Position = emitterPos;
particleTransform->Orientation = emitterOrientation;
@@ -124,7 +124,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
glm::normalize(glm::angleAxis(RandomizeAngle(spreadAngle), glm::vec3(0, 1, 0))) *
glm::normalize(glm::angleAxis(RandomizeAngle(spreadAngle), glm::vec3(0, 0, 1)));
auto particle = m_World->AddComponent<Components::Particle>(ent, "Particle");
auto particle = m_World->AddComponent<Components::Particle>(ent);
particle->LifeTime = emitterComponent->LifeTime;
particle->ScaleSpectrum = emitterComponent->ScaleSpectrum;
particle->VelocitySpectrum.push_back(particleTransform->Velocity);
+24 -24
View File
@@ -112,14 +112,14 @@ void Systems::PhysicsSystem::Initialize()
void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
{
cf->Register("Physics", []() { return new Components::Physics(); });
cf->Register("BoxShape", []() { return new Components::BoxShape(); });
cf->Register("SphereShape", []() { return new Components::SphereShape(); });
cf->Register("Vehicle", []() { return new Components::Vehicle(); });
cf->Register("Wheel", []() { return new Components::Wheel(); });
cf->Register("MeshShape", []() { return new Components::MeshShape(); });
cf->Register("HingeConstraint", []() { return new Components::HingeConstraint(); });
cf->Register("WheelPair", []() { return new Components::WheelPair(); });
cf->Register<Components::Physics>([]() { return new Components::Physics(); });
cf->Register<Components::BoxShape>([]() { return new Components::BoxShape(); });
cf->Register<Components::SphereShape>([]() { return new Components::SphereShape(); });
cf->Register<Components::Vehicle>([]() { return new Components::Vehicle(); });
cf->Register<Components::Wheel>([]() { return new Components::Wheel(); });
cf->Register<Components::MeshShape>([]() { return new Components::MeshShape(); });
cf->Register<Components::HingeConstraint>([]() { return new Components::HingeConstraint(); });
cf->Register<Components::WheelPair>([]() { return new Components::WheelPair(); });
}
void Systems::PhysicsSystem::Update(double dt)
@@ -132,7 +132,7 @@ void Systems::PhysicsSystem::Update(double dt)
if (m_RigidBodies.find(entity) == m_RigidBodies.end())
continue;
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (!transformComponent)
continue;
@@ -143,7 +143,7 @@ void Systems::PhysicsSystem::Update(double dt)
if (parent)
{
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
position = ConvertPosition(absoluteTransform.Position);
rotation = ConvertRotation(absoluteTransform.Orientation);
}
@@ -184,11 +184,11 @@ void Systems::PhysicsSystem::Update(double dt)
void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (!transformComponent)
return;
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity, "Wheel");
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity);
if (wheelComponent)
{
EntityID car = m_World->GetEntityParent(entity);
@@ -212,7 +212,7 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
}
else if(m_RigidBodies.find(entity) != m_RigidBodies.end())
{
auto transformComponentParent = m_World->GetComponent<Components::Transform>(parent, "Transform");
auto transformComponentParent = m_World->GetComponent<Components::Transform>(parent);
transformComponent->Position = ConvertPosition(m_RigidBodies[entity]->getPosition());
transformComponent->Orientation = ConvertRotation(m_RigidBodies[entity]->getRotation());
@@ -231,11 +231,11 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
{
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (!transformComponent)
return;
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity, "Wheel");
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity);
if (wheelComponent)
{
wheelComponent->ID = m_Wheels.size();
@@ -245,9 +245,9 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
EntityID entityParent = m_World->GetEntityBaseParent(entity);
auto sphereComponent = m_World->GetComponent<Components::SphereShape>(entity, "SphereShape");
auto boxComponent = m_World->GetComponent<Components::BoxShape>(entity, "BoxShape");
auto meshShapeComponent = m_World->GetComponent<Components::MeshShape >(entity, "MeshShape");
auto sphereComponent = m_World->GetComponent<Components::SphereShape>(entity);
auto boxComponent = m_World->GetComponent<Components::BoxShape>(entity);
auto meshShapeComponent = m_World->GetComponent<Components::MeshShape >(entity);
if(entityParent == entity && (sphereComponent || boxComponent || meshShapeComponent))
{
@@ -255,7 +255,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
return;
}
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity, "Physics");
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
if (physicsComponent)
{
hkpShape* shape;
@@ -296,7 +296,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
{
rigidBodyInfo.m_shape = shape;
rigidBodyInfo.m_motionType = hkpMotion::MOTION_DYNAMIC;
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
hkVector4 position = ConvertPosition(absoluteTransform.Position);
hkQuaternion rotation = ConvertRotation(absoluteTransform.Orientation);
rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3));
@@ -309,7 +309,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
// Create RigidBody
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
auto vehicleComponent = m_World->GetComponent<Components::Vehicle >(entity, "Vehicle");
auto vehicleComponent = m_World->GetComponent<Components::Vehicle >(entity);
if (vehicleComponent && m_Vehicles.find(entity) == m_Vehicles.end())
{
for (int i = 0; i < m_Wheels.size(); i++)
@@ -365,7 +365,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
for (auto &shapeData : m_Shapes[entity])
{
auto childTransformComponent = m_World->GetComponent<Components::Transform>(shapeData.Entity, "Transform");
auto childTransformComponent = m_World->GetComponent<Components::Transform>(shapeData.Entity);
hkVector4 position = ConvertPosition(childTransformComponent->Position);
hkQuaternion rotation = ConvertRotation(childTransformComponent->Orientation);
@@ -386,7 +386,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
{
rigidBodyInfo.m_shape = shape;
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
hkVector4 position = ConvertPosition(absoluteTransform.Position);
hkQuaternion rotation = ConvertRotation(absoluteTransform.Orientation);
rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3));
@@ -576,7 +576,7 @@ const hkVector4& Systems::PhysicsSystem::ConvertScale(glm::vec3 glmScale)
bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
{
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity, "Vehicle");
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity);
if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
{
m_PhysicsWorld->markForWrite();
+19 -16
View File
@@ -12,12 +12,12 @@ void Systems::RenderSystem::OnComponentCreated(std::string type, std::shared_ptr
void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (transformComponent == nullptr)
return;
// Draw models
auto modelComponent = m_World->GetComponent<Components::Model>(entity, "Model");
auto modelComponent = m_World->GetComponent<Components::Model>(entity);
if (modelComponent != nullptr)
{
auto model = m_World->GetResourceManager()->Load<Model>("Model", modelComponent->ModelFile);
@@ -31,7 +31,7 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
}
}
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity, "PointLight");
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
if (pointLightComponent != nullptr)
{
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
@@ -39,13 +39,14 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
position,
pointLightComponent->Specular,
pointLightComponent->Diffuse,
pointLightComponent->constantAttenuation,
pointLightComponent->linearAttenuation,
pointLightComponent->quadraticAttenuation,
pointLightComponent->spotExponent);
pointLightComponent->specularExponent,
pointLightComponent->ConstantAttenuation,
pointLightComponent->LinearAttenuation,
pointLightComponent->QuadraticAttenuation
);
}
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity, "Camera");
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity);
if (cameraComponent != nullptr)
{
m_Renderer->GetCamera()->Position(m_TransformSystem->AbsolutePosition(entity));
@@ -56,13 +57,13 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
m_Renderer->GetCamera()->FarClip(cameraComponent->FarClip);
}
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity, "Sprite");
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
if(spriteComponent != nullptr)
{
//TEMP
Texture* texture = m_World->GetResourceManager()->Load<Texture>("Texture", spriteComponent->SpriteFile);
//glBindTexture(GL_TEXTURE_2D, texture);
auto transform = m_World->GetComponent<Components::Transform>(spriteComponent->Entity, "Transform");
auto transform = m_World->GetComponent<Components::Transform>(spriteComponent->Entity);
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(transform->Orientation).z, glm::vec3(0, 0, -1));
m_Renderer->AddTextureToDraw(texture, transform->Position, orientation2D, transform->Scale);
}
@@ -70,16 +71,18 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
void Systems::RenderSystem::Initialize()
{
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>("TransformSystem");
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
m_Renderer->SetSphereModel(m_World->GetResourceManager()->Load<Model>("Model", "Models/Placeholders/PhysicsTest/Sphere.obj"));
}
void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
{
cf->Register("Camera", []() { return new Components::Camera(); });
cf->Register("Model", []() { return new Components::Model(); });
cf->Register("Sprite", []() { return new Components::Sprite(); });
cf->Register("PointLight", []() { return new Components::PointLight(); });
cf->Register("DirectionalLight", []() { return new Components::DirectionalLight(); });
cf->Register<Components::Camera>([]() { return new Components::Camera(); });
cf->Register<Components::Model>([]() { return new Components::Model(); });
cf->Register<Components::Sprite>([]() { return new Components::Sprite(); });
cf->Register<Components::PointLight>([]() { return new Components::PointLight(); });
cf->Register<Components::DirectionalLight>([]() { return new Components::DirectionalLight(); });
}
void Systems::RenderSystem::RegisterResourceTypes(ResourceManager* rm)
+3 -3
View File
@@ -29,7 +29,7 @@ void Systems::SoundSystem::Initialize()
void Systems::SoundSystem::RegisterComponents(ComponentFactory* cf)
{
cf->Register("SoundEmitter", []() { return new Components::SoundEmitter(); });
cf->Register<Components::SoundEmitter>([]() { return new Components::SoundEmitter(); });
}
void Systems::SoundSystem::RegisterResourceTypes(ResourceManager* rm)
@@ -44,7 +44,7 @@ void Systems::SoundSystem::Update(double dt)
void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (transformComponent == nullptr)
return;
@@ -68,7 +68,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
alListenerfv(AL_ORIENTATION, listenerOri);
}
auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity, "SoundEmitter");
auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity);
if(soundEmitter != nullptr)
{
ALuint source = m_Sources[soundEmitter];
+11 -11
View File
@@ -4,9 +4,9 @@
void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf )
{
cf->Register("TankSteering", []() { return new Components::TankSteering(); });
cf->Register("TowerSteering", []() { return new Components::TowerSteering(); });
cf->Register("BarrelSteering", []() { return new Components::BarrelSteering(); });
cf->Register<Components::TankSteering>([]() { return new Components::TankSteering(); });
cf->Register<Components::TowerSteering>([]() { return new Components::TowerSteering(); });
cf->Register<Components::BarrelSteering>([]() { return new Components::BarrelSteering(); });
}
void Systems::TankSteeringSystem::Initialize()
@@ -23,7 +23,7 @@ void Systems::TankSteeringSystem::Update(double dt)
void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto tankSteeringComponent = m_World->GetComponent<Components::TankSteering>(entity, "TankSteering");
auto tankSteeringComponent = m_World->GetComponent<Components::TankSteering>(entity);
if(tankSteeringComponent)
{
Events::TankSteer e;
@@ -34,27 +34,27 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
EventBroker->Publish(e);
}
auto towerSteeringComponent = m_World->GetComponent<Components::TowerSteering>(entity, "TowerSteering");
auto towerSteeringComponent = m_World->GetComponent<Components::TowerSteering>(entity);
if(towerSteeringComponent)
{
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
glm::quat orientation = glm::angleAxis(towerSteeringComponent->TurnSpeed * m_TowerInputController->TowerDirection * (float)dt, towerSteeringComponent->Axis);
transformComponent->Orientation *= orientation;
}
auto barrelSteeringComponent = m_World->GetComponent<Components::BarrelSteering>(entity, "BarrelSteering");
auto barrelSteeringComponent = m_World->GetComponent<Components::BarrelSteering>(entity);
if(barrelSteeringComponent)
{
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
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)
{
EntityID clone = m_World->CloneEntity(barrelSteeringComponent->ShotTemplate);
auto templateAbsoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(barrelSteeringComponent->ShotTemplate);
auto cloneTransform = m_World->GetComponent<Components::Transform>(clone, "Transform");
auto templateAbsoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(barrelSteeringComponent->ShotTemplate);
auto cloneTransform = m_World->GetComponent<Components::Transform>(clone);
cloneTransform->Position = templateAbsoluteTransform.Position;
cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation;
Events::SetVelocity e;
+8 -8
View File
@@ -7,8 +7,8 @@
// if (parent == 0)
// return;
//
// auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
// auto parentTransform = m_World->GetComponent<Components::Transform>(parent, "Transform");
// auto transform = m_World->GetComponent<Components::Transform>(entity);
// auto parentTransform = m_World->GetComponent<Components::Transform>(parent);
//
// transform->Position = parentTransform->Position + transform->RelativePosition;
//}
@@ -20,10 +20,10 @@ glm::vec3 Systems::TransformSystem::AbsolutePosition(EntityID entity)
do
{
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto transform = m_World->GetComponent<Components::Transform>(entity);
//absPosition += transform->Position;
entity = m_World->GetEntityParent(entity);
auto transform2 = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto transform2 = m_World->GetComponent<Components::Transform>(entity);
if (entity == 0)
absPosition += transform->Position;
else
@@ -39,7 +39,7 @@ glm::quat Systems::TransformSystem::AbsoluteOrientation(EntityID entity)
do
{
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto transform = m_World->GetComponent<Components::Transform>(entity);
absOrientation = transform->Orientation * absOrientation;
entity = m_World->GetEntityParent(entity);
} while (entity != 0);
@@ -53,7 +53,7 @@ glm::vec3 Systems::TransformSystem::AbsoluteScale(EntityID entity)
do
{
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto transform = m_World->GetComponent<Components::Transform>(entity);
absScale *= transform->Scale;
entity = m_World->GetEntityParent(entity);
} while (entity != 0);
@@ -69,9 +69,9 @@ Components::Transform Systems::TransformSystem::AbsoluteTransform(EntityID entit
do
{
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto transform = m_World->GetComponent<Components::Transform>(entity);
entity = m_World->GetEntityParent(entity);
auto transform2 = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto transform2 = m_World->GetComponent<Components::Transform>(entity);
// Position
if (entity == 0)
+28
View File
@@ -0,0 +1,28 @@
#ifndef UTIL_H
#define UTIL_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define ZERO_MEM(a) memset(a, 0, sizeof(a))
#define ARRAY_SIZE_IN_ELEMENTS(a) (sizeof(a)/sizeof(a[0]))
#define INVALID_OGL_VALUE 0xFFFFFFFF
#define SAFE_DELETE(p) if (p) { delete p; p = NULL; }
#define GLExitIfError() \
{ \
GLenum Error = glGetError(); \
\
if (Error != GL_NO_ERROR) { \
printf("OpenGL error in %s:%d: 0x%x\n", __FILE__, __LINE__, Error); \
exit(0); \
} \
}
#define GLCheckError() (glGetError() == GL_NO_ERROR)
#endif /* UTIL_H */
+1 -11
View File
@@ -132,11 +132,6 @@ void World::Initialize()
}
}
std::shared_ptr<Component> World::AddComponent(EntityID entity, std::string componentType)
{
return AddComponent<Component>(entity, componentType);
}
void World::CommitEntity(EntityID entity)
{
for (auto pair : m_Systems)
@@ -158,11 +153,6 @@ void World::AddComponent(EntityID entity, std::string componentType, std::shared
}
}
void World::AddSystem(std::string systemType)
{
m_Systems[systemType] = std::shared_ptr<System>(m_SystemFactory.Create(systemType));
}
EntityID World::CloneEntity(EntityID entity, EntityID parent /* = 0 */)
{
int clone = CreateEntity(parent);
@@ -170,7 +160,7 @@ EntityID World::CloneEntity(EntityID entity, EntityID parent /* = 0 */)
for (auto pair : m_EntityComponents[entity])
{
auto type = pair.first;
if (type == "Template")
if (type == typeid(Components::Template).name())
continue;
auto component = std::shared_ptr<Component>(pair.second->Clone());
if (component != nullptr)
+21 -19
View File
@@ -13,6 +13,7 @@
#include "Factory.h"
#include "Entity.h"
#include "Component.h"
#include "Components/Template.h"
#include "System.h"
#include "EventBroker.h"
#include "ResourceManager.h"
@@ -31,10 +32,14 @@ public:
virtual void AddSystems() = 0;
virtual void RegisterComponents() = 0;
template <typename T>
void AddSystem()
{
m_Systems[typeid(T).name()] = std::shared_ptr<System>(m_SystemFactory.Create<T>());
}
void AddSystem(std::string systemType);
template <class T>
std::shared_ptr<T> GetSystem(std::string systemType);
template <typename T>
std::shared_ptr<T> GetSystem();
EntityID CreateEntity(EntityID parent = 0);
EntityID CloneEntity(EntityID entity, EntityID parent = 0);
@@ -69,10 +74,9 @@ public:
}
template <class T>
std::shared_ptr<T> AddComponent(EntityID entity, std::string componentType);
std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType);
std::shared_ptr<T> AddComponent(EntityID entity);
template <class T>
T* GetComponent(EntityID entity, std::string componentType);
T* GetComponent(EntityID entity);
// Triggers commit events in systems
void CommitEntity(EntityID entity);
@@ -117,11 +121,13 @@ protected:
};
template <class T>
std::shared_ptr<T> World::GetSystem(std::string systemType)
std::shared_ptr<T> World::GetSystem()
{
const char* systemType = typeid(T).name();
if (m_Systems.find(systemType) == m_Systems.end())
{
LOG_WARNING("Tried to get pointer to unregistered system \"%s\"!", systemType.c_str());
LOG_WARNING("Tried to get pointer to unregistered system \"%s\"!", systemType);
return nullptr;
}
@@ -129,12 +135,14 @@ std::shared_ptr<T> World::GetSystem(std::string systemType)
}
template <class T>
std::shared_ptr<T> World::AddComponent(EntityID entity, std::string componentType)
std::shared_ptr<T> World::AddComponent(EntityID entity)
{
std::shared_ptr<T> component = std::shared_ptr<T>(static_cast<T*>(m_ComponentFactory.Create(componentType)));
const char* componentType = typeid(T).name();
std::shared_ptr<T> component = std::shared_ptr<T>(static_cast<T*>(m_ComponentFactory.Create<T>()));
if (component == nullptr)
{
LOG_ERROR("Failed to attach invalid component \"%s\" to entity #%i", componentType.c_str(), entity);
LOG_ERROR("Failed to attach invalid component \"%s\" to entity #%i", componentType, entity);
return nullptr;
}
@@ -145,17 +153,11 @@ std::shared_ptr<T> World::AddComponent(EntityID entity, std::string componentTyp
template <class T>
T* World::GetComponent(EntityID entity, std::string componentType)
T* World::GetComponent(EntityID entity)
{
/*auto it0 = m_EntityComponents.find(entity);
if (it0 == m_EntityComponents.end())
return nullptr;*/
auto components = m_EntityComponents[entity];
auto it = components.find(componentType);
auto it = components.find(typeid(T).name());
if (it != components.end())
{
return static_cast<T*>(it->second.get());
-40
View File
@@ -1,40 +0,0 @@
#include "PrecompiledHeader.h"
#include "gBuffer.h"
bool GBuffer::Init(unsigned int WindowWidth, unsigned int WindowHeight)
{
// Create the FBO
glGenFramebuffers(1, &m_fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo);
// Create the gbuffer textures
glGenTextures(ARRAY_SIZE_IN_ELEMENTS(m_textures), m_textures);
glGenTextures(1, &m_depthTexture);
for (unsigned int i = 0 ; i < ARRAY_SIZE_IN_ELEMENTS(m_textures) ; i++) {
glBindTexture(GL_TEXTURE_2D, m_textures[i]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, WindowWidth, WindowHeight, 0, GL_RGB, GL_FLOAT, NULL);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, m_textures[i], 0);
}
// depth
glBindTexture(GL_TEXTURE_2D, m_depthTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, WindowWidth, WindowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
NULL);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthTexture, 0);
GLenum DrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(ARRAY_SIZE_IN_ELEMENTS(DrawBuffers), DrawBuffers);
GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (Status != GL_FRAMEBUFFER_COMPLETE) {
printf("FB error, status: 0x%x\n", Status);
return false;
}
// restore default FBO
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
return true;
}
-35
View File
@@ -1,35 +0,0 @@
#ifndef gBuffer_h__
#define gBuffer_h__
#include <stdio.h>
class GBuffer
{
public:
enum GBUFFER_TEXTURE_TYPE {
GBUFFER_TEXTURE_TYPE_POSITION,
GBUFFER_TEXTURE_TYPE_DIFFUSE,
GBUFFER_TEXTURE_TYPE_NORMAL,
GBUFFER_TEXTURE_TYPE_TEXCOORD,
GBUFFER_NUM_TEXTURES
};
GBuffer();
~GBuffer();
bool Init(unsigned int WindowWidth, unsigned int WindowHeight);
void BindForWriting();
void BindForReading();
private:
GLuint m_fbo;
GLuint m_textures[GBUFFER_NUM_TEXTURES];
GLuint m_depthTexture;
};
#endif //gBuffer_h__