Merge remote-tracking branch 'origin/master' into FMOD

Conflicts:
	src/GameWorld.cpp
	src/Systems/SoundSystem.h
	vs11/Returngeance/Returngeance.vcxproj.filters
This commit is contained in:
Stiffly
2014-05-25 01:42:26 +02:00
58 changed files with 1860 additions and 533 deletions
+1 -1
Submodule assets updated: 8514fb17f3...6cc38589ed
+1 -1
View File
@@ -2,6 +2,7 @@
#define Components_Camera_h__ #define Components_Camera_h__
#include "Component.h" #include "Component.h"
#include "Entity.h"
namespace Components namespace Components
{ {
@@ -13,7 +14,6 @@ struct Camera : Component
, NearClip(0.1f) , NearClip(0.1f)
, FarClip(100.f) { } , FarClip(100.f) { }
std::string Viewport;
float FOV; float FOV;
float NearClip; float NearClip;
float FarClip; float FarClip;
+21
View File
@@ -0,0 +1,21 @@
#ifndef Components_Health_h__
#define Components_Health_h__
#include "Component.h"
namespace Components
{
struct Health : Component
{
Health()
: health(1.0f){ }
float health;
virtual Health* Clone() const override { return new Health(*this); }
};
}
#endif // Components_Health_h__
+16
View File
@@ -0,0 +1,16 @@
#ifndef HelicopterSteering_h__
#define HelicopterSteering_h__
#include "Component.h"
namespace Components
{
struct HelicopterSteering : Component
{
HelicopterSteering* Clone() const override { return new HelicopterSteering(*this); }
};
}
#endif // HelicopterSteering_h__
+8 -10
View File
@@ -1,10 +1,6 @@
#ifndef Components_Input_h__ #ifndef Components_Input_h__
#define Components_Input_h__ #define Components_Input_h__
#include <array>
#include <GLFW/glfw3.h>
#include "Component.h" #include "Component.h"
namespace Components namespace Components
@@ -12,12 +8,14 @@ namespace Components
struct Input : Component struct Input : Component
{ {
std::array<int, GLFW_KEY_LAST+1> KeyState; /*Input()
std::array<int, GLFW_KEY_LAST+1> LastKeyState; : Keyboard(false)
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> MouseState; , Mouse(false)
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> LastMouseState; , GamepadID(0) { }
float dX, dY;
float WheelDelta; bool Keyboard;
bool Mouse;
int GamepadID;*/
virtual Input* Clone() const override { return new Input(*this); } virtual Input* Clone() const override { return new Input(*this); }
}; };
+21
View File
@@ -0,0 +1,21 @@
#ifndef Player_h__
#define Player_h__
#include "Component.h"
namespace Components
{
struct Player : Component
{
Player()
: ID(0) { }
int ID;
virtual Player* Clone() const override { return new Player(*this); }
};
}
#endif // Player_h__
+3
View File
@@ -7,6 +7,9 @@ namespace Components
{ {
struct TankSteering : Component struct TankSteering : Component
{ {
EntityID Player;
EntityID Turret;
EntityID Barrel;
TankSteering* Clone() const override { return new TankSteering(*this); } TankSteering* Clone() const override { return new TankSteering(*this); }
}; };
} }
-1
View File
@@ -10,7 +10,6 @@ struct TowerSteering : Component
{ {
TowerSteering() TowerSteering()
: TurnSpeed(1.f), Axis(glm::vec3(0,1,0)){ } : TurnSpeed(1.f), Axis(glm::vec3(0,1,0)){ }
float TurnSpeed; float TurnSpeed;
glm::vec3 Axis; glm::vec3 Axis;
virtual TowerSteering* Clone() const override { return new TowerSteering(*this); } virtual TowerSteering* Clone() const override { return new TowerSteering(*this); }
+29
View File
@@ -0,0 +1,29 @@
#ifndef Components_Viewport_h__
#define Components_Viewport_h__
#include "Component.h"
namespace Components
{
struct Viewport : Component
{
Viewport()
: Left(0.f)
, Top(0.f)
, Right(1.f)
, Bottom(1.f)
, Camera(0) { }
float Left;
float Top;
float Right;
float Bottom;
EntityID Camera;
virtual Viewport* Clone() const override { return new Viewport(*this); }
};
}
#endif // Components_Viewport_h__
+1 -1
View File
@@ -14,7 +14,7 @@ struct Wheel : Component
Wheel() Wheel()
: AxleID(0), Radius(0), Width(0), Mass(0), Steering(false), DownDirection(glm::vec3(0, -1, 0)), Friction(1.5f), SlipAngle(0.0f), : AxleID(0), Radius(0), Width(0), Mass(0), Steering(false), DownDirection(glm::vec3(0, -1, 0)), Friction(1.5f), SlipAngle(0.0f),
MaxBreakingTorque(1500.0f), ConnectedToHandbrake(false), SuspensionStrength(50.0f), TorqueRatio(0.25f) { } MaxBreakingTorque(50000.f), ConnectedToHandbrake(false), SuspensionStrength(50.0f), TorqueRatio(0.25f) { }
// The Hardpoint MUST be positioned INSIDE the chassis. // The Hardpoint MUST be positioned INSIDE the chassis.
glm::vec3 Hardpoint; glm::vec3 Hardpoint;
+1
View File
@@ -38,6 +38,7 @@ public:
m_InputManager->Update(dt); m_InputManager->Update(dt);
m_World->Update(dt); m_World->Update(dt);
m_Renderer->Draw(dt); m_Renderer->Draw(dt);
m_EventBroker->Clear();
glfwPollEvents(); glfwPollEvents();
} }
+42 -3
View File
@@ -1,5 +1,6 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include "EventBroker.h" #include "EventBroker.h"
#include "Events/BindKey.h"
BaseEventRelay::~BaseEventRelay() BaseEventRelay::~BaseEventRelay()
{ {
@@ -11,12 +12,18 @@ BaseEventRelay::~BaseEventRelay()
void EventBroker::Unsubscribe(BaseEventRelay &relay) // ? void EventBroker::Unsubscribe(BaseEventRelay &relay) // ?
{ {
auto itpair = m_Subscribers.equal_range(relay.m_TypeName); auto contextIt = m_ContextRelays.find(relay.m_ContextTypeName);
if (contextIt == m_ContextRelays.end())
return;
auto eventRelays = contextIt->second;
auto itpair = eventRelays.equal_range(relay.m_EventTypeName);
for (auto it = itpair.first; it != itpair.second; ++it) for (auto it = itpair.first; it != itpair.second; ++it)
{ {
if (it->second == &relay) if (it->second == &relay)
{ {
m_Subscribers.erase(it); eventRelays.erase(it);
break; break;
} }
} }
@@ -25,5 +32,37 @@ void EventBroker::Unsubscribe(BaseEventRelay &relay) // ?
void EventBroker::Subscribe(BaseEventRelay &relay) void EventBroker::Subscribe(BaseEventRelay &relay)
{ {
relay.m_Broker = this; relay.m_Broker = this;
m_Subscribers.insert(std::make_pair(relay.m_TypeName, &relay)); m_ContextRelays[relay.m_ContextTypeName].insert(std::make_pair(relay.m_EventTypeName, &relay));
}
int EventBroker::Process(std::string contextTypeName)
{
auto it = m_ContextRelays.find(contextTypeName);
if (it == m_ContextRelays.end())
return 0;
EventRelays_t &relays = it->second;
int eventsProcessed = 0;
for (auto &pair : *m_EventQueueRead)
{
std::string &eventTypeName = pair.first;
std::shared_ptr<Event> event = pair.second;
auto itpair = relays.equal_range(eventTypeName);
for (auto it2 = itpair.first; it2 != itpair.second; ++it2)
{
auto relay = it2->second;
relay->Receive(event);
eventsProcessed++;
}
}
return eventsProcessed;
}
void EventBroker::Clear()
{
std::swap(m_EventQueueRead, m_EventQueueWrite);
m_EventQueueWrite->clear();
} }
+69 -16
View File
@@ -3,6 +3,7 @@
#include <typeinfo> #include <typeinfo>
#include <functional> #include <functional>
#include <map>
#include <unordered_map> #include <unordered_map>
#include <list> #include <list>
@@ -23,19 +24,22 @@ class BaseEventRelay
friend class EventBroker; friend class EventBroker;
protected: protected:
BaseEventRelay(std::string typeName) BaseEventRelay(std::string contextTypeName, std::string eventTypeName)
: m_TypeName(typeName), m_Broker(nullptr) { } : m_ContextTypeName(contextTypeName)
, m_EventTypeName(eventTypeName)
, m_Broker(nullptr) { }
~BaseEventRelay(); ~BaseEventRelay();
public: public:
virtual bool Receive(const Event &event) = 0; virtual bool Receive(const std::shared_ptr<Event> event) = 0;
protected: protected:
std::string m_TypeName; std::string m_ContextTypeName;
std::string m_EventTypeName;
EventBroker* m_Broker; EventBroker* m_Broker;
}; };
template <typename EventType> template <typename ContextType, typename EventType>
class EventRelay : public BaseEventRelay class EventRelay : public BaseEventRelay
{ {
public: public:
@@ -43,24 +47,24 @@ public:
EventRelay() EventRelay()
: m_Callback(nullptr) : m_Callback(nullptr)
, BaseEventRelay(typeid(EventType).name()) { } , BaseEventRelay(typeid(ContextType).name(), typeid(EventType).name()) { }
EventRelay(CallbackType callback) EventRelay(CallbackType callback)
: m_Callback(callback) : m_Callback(callback)
, BaseEventRelay(typeid(EventType).name()) { } , BaseEventRelay(typeid(ContextType).name(), typeid(EventType).name()) { }
protected: protected:
bool Receive(const Event &event) override; bool Receive(const std::shared_ptr<Event> event) override;
private: private:
CallbackType m_Callback; CallbackType m_Callback;
}; };
template <typename EventType> template <typename ContextType, typename EventType>
bool EventRelay<EventType>::Receive(const Event &event) bool EventRelay<ContextType, EventType>::Receive(const std::shared_ptr<Event> event)
{ {
if (m_Callback != nullptr) if (m_Callback != nullptr)
{ {
return m_Callback(static_cast<const EventType&>(event)); return m_Callback(*static_cast<const EventType*>(event.get()));
} }
else else
{ {
@@ -70,26 +74,75 @@ bool EventRelay<EventType>::Receive(const Event &event)
class EventBroker class EventBroker
{ {
template <typename EventType> friend class EventRelay; template <typename ContextType, typename EventType> friend class EventRelay;
public: public:
EventBroker()
{
m_EventQueueRead = std::make_shared<EventQueue_t>();
m_EventQueueWrite = std::make_shared<EventQueue_t>();
}
void Subscribe(BaseEventRelay &relay);
template <typename EventType> template <typename EventType>
void Publish(const EventType &event); void Publish(const EventType &event);
void Subscribe(BaseEventRelay &relay); // Process all events no matter the context.
/*void Process()
{
}*/
/*
Process all events in a given context.
Returns: Number of events processed
*/
template <typename ContextType>
int Process();
int Process(std::string contextTypeName);
void Clear();
void Unsubscribe(BaseEventRelay &relay); void Unsubscribe(BaseEventRelay &relay);
template <typename ContextType>
void UnsubscribeAll();
private: private:
std::unordered_multimap<std::string, BaseEventRelay*> m_Subscribers; typedef std::string ContextTypeName_t; // typeid(ContextType).name()
}; typedef std::string EventTypeName_t; // typeid(EventType).name()
typedef std::unordered_multimap<EventTypeName_t, BaseEventRelay*> EventRelays_t;
typedef std::unordered_map<ContextTypeName_t, EventRelays_t> ContextRelays_t;
ContextRelays_t m_ContextRelays;
typedef std::list<std::pair<EventTypeName_t, std::shared_ptr<Event>>> EventQueue_t;
std::shared_ptr<EventQueue_t> m_EventQueueRead;
std::shared_ptr<EventQueue_t> m_EventQueueWrite;
};
template <typename EventType> template <typename EventType>
void EventBroker::Publish(const EventType &event) void EventBroker::Publish(const EventType &event)
{ {
auto itpair = m_Subscribers.equal_range(typeid(EventType).name()); /*auto itpair = m_Subscribers.equal_range(typeid(EventType).name());
for (auto it = itpair.first; it != itpair.second; ++it) for (auto it = itpair.first; it != itpair.second; ++it)
{ {
it->second->Receive(event); it->second->Receive(event);
}*/
m_EventQueueWrite->push_back(std::make_pair(typeid(EventType).name(), std::shared_ptr<EventType>(new EventType(event))));
}
template <typename ContextType>
int EventBroker::Process()
{
const std::string contextTypeName = typeid(ContextType).name();
return Process(contextTypeName);
}
template <typename ContextType>
void EventBroker::UnsubscribeAll()
{
const std::string contextTypeName = typeid(ContextType).name();
auto contextIt = m_ContextRelays.find(contextTypeName);
if (contextIt != m_ContextRelays.end())
{
m_ContextRelays.erase(contextIt);
} }
} }
+18
View File
@@ -0,0 +1,18 @@
#ifndef Events_ApplyForce_h__
#define Events_ApplyForce_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct ApplyForce : Event
{
EntityID Entity;
double DeltaTime;
glm::vec3 Force;
};
}
#endif // Events_ApplyForce_h__
+18
View File
@@ -0,0 +1,18 @@
#ifndef Events_ApplyPointImpulse_h__
#define Events_ApplyPointImpulse_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct ApplyPointImpulse : Event
{
EntityID Entity;
glm::vec3 Position;
glm::vec3 Impulse;
};
}
#endif // Events_ApplyPointImpulse_h__
+16
View File
@@ -0,0 +1,16 @@
#ifndef Events_CastRay_h__
#define Events_CastRay_h__
#include "EventBroker.h"
namespace Events
{
struct CastRay : Event
{
glm::vec3 Direction;
};
}
#endif // Events_CastRay_h__
+1
View File
@@ -9,6 +9,7 @@ namespace Events
struct MousePress : Event struct MousePress : Event
{ {
int Button; int Button;
double X, Y;
}; };
} }
+1
View File
@@ -9,6 +9,7 @@ namespace Events
struct MouseRelease : Event struct MouseRelease : Event
{ {
int Button; int Button;
double X, Y;
}; };
} }
+17
View File
@@ -0,0 +1,17 @@
#ifndef Events_RayIntersection_h__
#define Events_RayIntersection_h__
#include "EventBroker.h"
#include "Entity.h"
namespace Events
{
struct RayIntersection : Event
{
EntityID Entity;
};
}
#endif // Events_RayIntersection_h__
+61 -35
View File
@@ -6,43 +6,69 @@
#include "Util/Rectangle.h" #include "Util/Rectangle.h"
#include "EventBroker.h" #include "EventBroker.h"
// HACK: Decouple renderer plz
#include "Renderer.h"
namespace GUI namespace GUI
{ {
//
//class Frame : public Rectangle class Frame : public Rectangle
//{ {
//public: public:
// enum class Anchor enum class Anchor
// { {
// Left, Left,
// Right, Right,
// Top, Top,
// Bottom Bottom
// }; };
//
// // Set up a base frame with an event broker // Set up a base frame with an event broker
// Frame(std::shared_ptr<::EventBroker> eventBroker) Frame(std::shared_ptr<::EventBroker> eventBroker)
// : EventBroker(eventBroker) : EventBroker(eventBroker)
// , Rectangle() , Rectangle()
// { Initialize(); } { Initialize(); }
// // Create a frame as a child // Create a frame as a child
// Frame(std::shared_ptr<Frame> parent) Frame(std::shared_ptr<Frame> parent)
// : Rectangle(static_cast<Rectangle>(*parent)) // Clone parent rectangle using copy constructor : Rectangle(static_cast<Rectangle>(*parent)) // Clone parent rectangle using copy constructor
// { SetParent(parent); Initialize(); } { SetParent(parent); Initialize(); }
//
// virtual void Initialize() { } virtual void Initialize() { }
// std::shared_ptr<Frame> Parent() const { return m_Parent; } std::shared_ptr<Frame> Parent() const { return m_Parent; }
// void SetParent(std::shared_ptr<Frame> parent) void SetParent(std::shared_ptr<Frame> parent)
// { {
// m_Parent = parent; parent->AddChild(std::shared_ptr<Frame>(this));
// EventBroker = parent->EventBroker; m_Parent = parent;
// } EventBroker = parent->EventBroker;
// virtual void Update(double dt) { } }
//
//protected: void AddChild(std::shared_ptr<Frame> child)
// std::shared_ptr<::EventBroker> EventBroker; {
// std::shared_ptr<Frame> m_Parent; m_Children.push_back(child);
//}; if (m_Parent != nullptr)
{
m_Parent->AddChild(child);
}
}
typedef std::list<std::shared_ptr<Frame>>::const_iterator FrameChildrenIterator;
FrameChildrenIterator begin()
{
return m_Children.begin();
}
FrameChildrenIterator end()
{
return m_Children.end();
}
virtual void Update(double dt) { }
virtual void Draw(Renderer* renderer) { }
protected:
std::shared_ptr<::EventBroker> EventBroker;
std::shared_ptr<Frame> m_Parent;
std::list<std::shared_ptr<Frame>> m_Children;
};
} }
+495 -45
View File
@@ -45,28 +45,55 @@ void GameWorld::Initialize()
RegisterComponents(); RegisterComponents();
//{ auto camera = CreateEntity();
// auto camera = CreateEntity(); {
// auto transform = AddComponent<Components::Transform>(camera); auto transform = AddComponent<Components::Transform>(camera);
// transform->Position.z = 20.f; transform->Position.z = 20.f;
// transform->Position.y = 20.f; transform->Position.y = 20.f;
// //transform->Orientation = glm::quat(glm::vec3(glm::pi<float>() / 8.f, 0.f, 0.f)); //transform->Orientation = glm::quat(glm::vec3(glm::pi<float>() / 8.f, 0.f, 0.f));
// auto cameraComp = AddComponent<Components::Camera>(camera); auto cameraComp = AddComponent<Components::Camera>(camera);
// cameraComp->FarClip = 2000.f; cameraComp->FarClip = 2000.f;
// auto freeSteering = AddComponent<Components::FreeSteering>(camera); auto freeSteering = AddComponent<Components::FreeSteering>(camera);
// CommitEntity(camera); }
//} CommitEntity(camera);
auto viewport1 = CreateEntity();
{
auto viewport = AddComponent<Components::Viewport>(viewport1);
viewport->Right = 0.5f;
viewport->Camera = camera;
}
CommitEntity(viewport1);
auto viewport2 = CreateEntity();
{
auto viewport = AddComponent<Components::Viewport>(viewport2);
viewport->Left = 0.5f;
}
CommitEntity(viewport2);
auto player1 = CreateEntity();
{
auto player = AddComponent<Components::Player>(player1);
player->ID = 1;
}
auto player2 = CreateEntity();
{
auto player = AddComponent<Components::Player>(player2);
player->ID = 2;
}
{ {
auto ground = CreateEntity(); auto ground = CreateEntity();
auto transform = AddComponent<Components::Transform>(ground); auto transform = AddComponent<Components::Transform>(ground);
transform->Position = glm::vec3(0, 0, 0); transform->Position = glm::vec3(0, -50, 0);
//transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f); //transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f);
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
auto model = AddComponent<Components::Model>(ground); auto model = AddComponent<Components::Model>(ground);
//model->ModelFile = "Models/TestScene/testScene.obj"; model->ModelFile = "Models/TestScene3/testScene.obj";
model->ModelFile = "Models/Placeholders/Terrain/Terrain2.obj"; //model->ModelFile = "Models/Placeholders/Terrain/Terrain2.obj";
auto physics = AddComponent<Components::Physics>(ground); auto physics = AddComponent<Components::Physics>(ground);
physics->Mass = 10; physics->Mass = 10;
@@ -75,8 +102,8 @@ void GameWorld::Initialize()
auto groundshape = CreateEntity(ground); auto groundshape = CreateEntity(ground);
auto transformshape = AddComponent<Components::Transform>(groundshape); auto transformshape = AddComponent<Components::Transform>(groundshape);
auto meshShape = AddComponent<Components::MeshShape>(groundshape); auto meshShape = AddComponent<Components::MeshShape>(groundshape);
meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain2.obj"; //meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain2.obj";
//meshShape->ResourceName = "Models/TestScene/testScene.obj"; meshShape->ResourceName = "Models/TestScene3/testScene.obj";
CommitEntity(groundshape); CommitEntity(groundshape);
@@ -223,11 +250,14 @@ void GameWorld::Initialize()
transform->Position = glm::vec3(0, 5, 0); transform->Position = glm::vec3(0, 5, 0);
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0)); //transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
auto physics = AddComponent<Components::Physics>(tank); auto physics = AddComponent<Components::Physics>(tank);
physics->Mass = 45000; physics->Mass = 63000 - 16000;
physics->Static = false; physics->Static = false;
auto vehicle = AddComponent<Components::Vehicle>(tank); auto vehicle = AddComponent<Components::Vehicle>(tank);
vehicle->MaxTorque = 5200.f; vehicle->MaxTorque = 36000.f;
AddComponent<Components::TankSteering>(tank); vehicle->MaxSteeringAngle = 90.f;
vehicle->MaxSpeedFullSteeringAngle = 4.f;
auto tankSteering = AddComponent<Components::TankSteering>(tank);
tankSteering->Player = player1;
AddComponent<Components::Input>(tank); AddComponent<Components::Input>(tank);
{ {
@@ -249,24 +279,24 @@ void GameWorld::Initialize()
auto transform = AddComponent<Components::Transform>(chassis); auto transform = AddComponent<Components::Transform>(chassis);
transform->Position = glm::vec3(0, 0, 0); transform->Position = glm::vec3(0, 0, 0);
auto model = AddComponent<Components::Model>(chassis); auto model = AddComponent<Components::Model>(chassis);
model->ModelFile = "Models/Tank/Fix/Chassi.obj"; model->ModelFile = "Models/Tank/tankBody.obj";
} }
{ {
auto tower = CreateEntity(tank); auto tower = CreateEntity(tank);
SetProperty(tower, "Name", "tower"); SetProperty(tower, "Name", "tower");
auto transform = AddComponent<Components::Transform>(tower); auto transform = AddComponent<Components::Transform>(tower);
transform->Position = glm::vec3(0.f, 1.2f, 1.8f); transform->Position = glm::vec3(0.f, 0.68f, 0.9f);
auto model = AddComponent<Components::Model>(tower); auto model = AddComponent<Components::Model>(tower);
model->ModelFile = "Models/Tank/Fix/Top.obj"; model->ModelFile = "Models/Tank/tankTop.obj";
auto towerSteering = AddComponent<Components::TowerSteering>(tower); auto towerSteering = AddComponent<Components::TowerSteering>(tower);
towerSteering->Axis = glm::vec3(0.f, 1.f, 0.f); towerSteering->Axis = glm::vec3(0.f, 1.f, 0.f);
towerSteering->TurnSpeed = glm::pi<float>()/4.f; towerSteering->TurnSpeed = glm::pi<float>()/4.f;
{ {
auto barrel = CreateEntity(tower); auto barrel = CreateEntity(tower);
auto transform = AddComponent<Components::Transform>(barrel); auto transform = AddComponent<Components::Transform>(barrel);
transform->Position = glm::vec3(-0.018f, -0.2, -1.3f); transform->Position = glm::vec3(-0.012f, 0.4f, -0.75);
auto model = AddComponent<Components::Model>(barrel); auto model = AddComponent<Components::Model>(barrel);
model->ModelFile = "Models/Tank/Fix/Barrel.obj"; model->ModelFile = "Models/Tank/tankBarrel.obj";
auto barrelSteering = AddComponent<Components::BarrelSteering>(barrel); auto barrelSteering = AddComponent<Components::BarrelSteering>(barrel);
barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f); barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f);
barrelSteering->TurnSpeed = glm::pi<float>()/4.f; barrelSteering->TurnSpeed = glm::pi<float>()/4.f;
@@ -279,7 +309,7 @@ void GameWorld::Initialize()
transform->Scale = glm::vec3(3.f); transform->Scale = glm::vec3(3.f);
AddComponent<Components::Template>(shot); AddComponent<Components::Template>(shot);
auto physics = AddComponent<Components::Physics>(shot); auto physics = AddComponent<Components::Physics>(shot);
physics->Mass = 10.f; physics->Mass = 25.f;
physics->Static = false; physics->Static = false;
auto modelComponent = AddComponent<Components::Model>(shot); auto modelComponent = AddComponent<Components::Model>(shot);
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj"; modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
@@ -297,22 +327,25 @@ void GameWorld::Initialize()
barrelSteering->ShotTemplate = shot; barrelSteering->ShotTemplate = shot;
} }
CommitEntity(barrel); CommitEntity(barrel);
tankSteering->Barrel = barrel;
} }
CommitEntity(tower);
tankSteering->Turret = tower;
auto cameraTower = CreateEntity(tower);
{ {
auto camera = CreateEntity(tower); auto transform = AddComponent<Components::Transform>(cameraTower);
auto transform = AddComponent<Components::Transform>(camera); transform->Position.z = 11.f;
transform->Position.z = 30.f; transform->Position.y = 4.f;
transform->Position.y = 5.f; //transform->Orientation = glm::quat(glm::vec3(glm::pi<float>() / 8.f, 0.f, 0.f));
//transform->Orientation = glm::quat(glm::vec3(-glm::pi<float>() / 8.f, 0.f, 0.f)); auto cameraComp = AddComponent<Components::Camera>(cameraTower);
transform->Orientation = glm::angleAxis(glm::pi<float>() / 100, glm::vec3(1, 0, 0));
auto cameraComp = AddComponent<Components::Camera>(camera);
cameraComp->FarClip = 2000.f; cameraComp->FarClip = 2000.f;
AddComponent<Components::Input>(camera); //auto freeSteering = AddComponent<Components::FreeSteering>(cameraTower);
AddComponent<Components::Listener>(tank); AddComponent<Components::Listener>(tank);
//auto freeSteering = AddComponent<Components::FreeSteering>(camera);
CommitEntity(camera);
} }
CommitEntity(cameraTower);
GetComponent<Components::Viewport>(viewport1)->Camera = cameraTower;
} }
{ {
@@ -334,7 +367,7 @@ void GameWorld::Initialize()
//Create wheels //Create wheels
float wheelOffset = 0.4f; float wheelOffset = 0.4f;
float springLength = 0.3f; float springLength = 0.3f;
float suspensionStrength = 25.f; float suspensionStrength = 15.f;
{ {
auto wheel = CreateEntity(tank); auto wheel = CreateEntity(tank);
@@ -350,7 +383,7 @@ void GameWorld::Initialize()
Wheel->Radius = 0.6f; Wheel->Radius = 0.6f;
Wheel->Steering = true; Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength; Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 4.f; Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true; Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f; Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f; Wheel->Width = 0.6f;
@@ -380,7 +413,7 @@ void GameWorld::Initialize()
Wheel->Radius = 0.6f; Wheel->Radius = 0.6f;
Wheel->Steering = false; Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength; Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 4.f; Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true; Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f; Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f; Wheel->Width = 0.6f;
@@ -411,7 +444,7 @@ void GameWorld::Initialize()
Wheel->Radius = 0.6f; Wheel->Radius = 0.6f;
Wheel->Steering = true; Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength; Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 4.f; Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true; Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f; Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f; Wheel->Width = 0.6f;
@@ -439,9 +472,9 @@ void GameWorld::Initialize()
Wheel->AxleID = 0; Wheel->AxleID = 0;
Wheel->Mass = 2000; Wheel->Mass = 2000;
Wheel->Radius = 0.6f; Wheel->Radius = 0.6f;
Wheel->Steering = false; Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength; Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 4.f; Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true; Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f; Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f; Wheel->Width = 0.6f;
@@ -473,7 +506,7 @@ void GameWorld::Initialize()
Wheel->Radius = 0.6f; Wheel->Radius = 0.6f;
Wheel->Steering = false; Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength; Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 4.f; Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true; Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f; Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f; Wheel->Width = 0.6f;
@@ -502,7 +535,7 @@ void GameWorld::Initialize()
Wheel->Radius = 0.6f; Wheel->Radius = 0.6f;
Wheel->Steering = false; Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength; Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 4.f; Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true; Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f; Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f; Wheel->Width = 0.6f;
@@ -557,7 +590,7 @@ void GameWorld::Initialize()
Wheel->Radius = 0.6f; Wheel->Radius = 0.6f;
Wheel->Steering = false; Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength; Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 4.f; Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true; Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f; Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f; Wheel->Width = 0.6f;
@@ -586,7 +619,7 @@ void GameWorld::Initialize()
Wheel->Radius = 0.6f; Wheel->Radius = 0.6f;
Wheel->Steering = false; Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength; Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 4.f; Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true; Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f; Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f; Wheel->Width = 0.6f;
@@ -630,7 +663,423 @@ void GameWorld::Initialize()
CommitEntity(tank); CommitEntity(tank);
} }
{
auto tank = CreateEntity();
auto transform = AddComponent<Components::Transform>(tank);
transform->Position = glm::vec3(20, 5, 0);
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
auto physics = AddComponent<Components::Physics>(tank);
physics->Mass = 63000 - 16000;
physics->Static = false;
auto vehicle = AddComponent<Components::Vehicle>(tank);
vehicle->MaxTorque = 36000.f;
vehicle->MaxSteeringAngle = 90.f;
vehicle->MaxSpeedFullSteeringAngle = 4.f;
auto tankSteering = AddComponent<Components::TankSteering>(tank);
tankSteering->Player = player2;
AddComponent<Components::Input>(tank);
{
auto shape = CreateEntity(tank);
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->Width = 1.487f;
// box->Height = 0.727f;
// box->Depth = 2.594f;
}
{
auto chassis = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(chassis);
transform->Position = glm::vec3(0, 0, 0);
auto model = AddComponent<Components::Model>(chassis);
model->ModelFile = "Models/Tank/tankBody.obj";
}
{
auto tower = CreateEntity(tank);
SetProperty(tower, "Name", "tower");
auto transform = AddComponent<Components::Transform>(tower);
transform->Position = glm::vec3(0.f, 0.68f, 0.9f);
auto model = AddComponent<Components::Model>(tower);
model->ModelFile = "Models/Tank/tankTop.obj";
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->Position = glm::vec3(-0.012f, 0.4f, -0.75);
auto model = AddComponent<Components::Model>(barrel);
model->ModelFile = "Models/Tank/tankBarrel.obj";
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->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<Components::Template>(shot);
auto physics = AddComponent<Components::Physics>(shot);
physics->Mass = 25.f;
physics->Static = false;
auto modelComponent = AddComponent<Components::Model>(shot);
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
{
auto shape = CreateEntity(shot);
auto transform = AddComponent<Components::Transform>(shape);
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.5f;
boxShape->Height = 0.5f;
boxShape->Depth = 0.5f;
CommitEntity(shape);
}
CommitEntity(shot);
barrelSteering->ShotTemplate = shot;
}
CommitEntity(barrel);
tankSteering->Barrel = barrel;
}
CommitEntity(tower);
tankSteering->Turret = tower;
auto cameraTower = CreateEntity(tower);
{
auto transform = AddComponent<Components::Transform>(cameraTower);
transform->Position.z = 11.f;
transform->Position.y = 4.f;
//transform->Orientation = glm::quat(glm::vec3(glm::pi<float>() / 8.f, 0.f, 0.f));
auto cameraComp = AddComponent<Components::Camera>(cameraTower);
cameraComp->FarClip = 2000.f;
//auto freeSteering = AddComponent<Components::FreeSteering>(cameraTower);
}
CommitEntity(cameraTower);
GetComponent<Components::Viewport>(viewport2)->Camera = cameraTower;
}
{
auto lightentity = CreateEntity(tank);
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);
// SetProperty(wheelpair, "Name", "WheelPair");
// AddComponent(wheelpair, "WheelPairThingy");
//Create wheels
float wheelOffset = 0.4f;
float springLength = 0.3f;
float suspensionStrength = 15.f;
{
auto wheel = CreateEntity(tank);
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->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
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->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
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->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
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->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
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->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
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->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
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->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
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->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
//Back
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 1.f);
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
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->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 2.95f);
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
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->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
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);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
emitterComponent->ParticleTemplate = particleEntity;
CommitEntity(particleEntity);
}
{
auto wheel = CreateEntity(tank);
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->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
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->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 2.95f);
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
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->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
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);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
emitterComponent->ParticleTemplate = particleEntity;
CommitEntity(particleEntity);
}
CommitEntity(tank);
}
/* /*
for(int i = 0; i < 10; i++) for(int i = 0; i < 10; i++)
@@ -763,6 +1212,7 @@ void GameWorld::RegisterComponents()
{ {
m_ComponentFactory.Register<Components::Transform>([]() { return new Components::Transform(); }); m_ComponentFactory.Register<Components::Transform>([]() { return new Components::Transform(); });
m_ComponentFactory.Register<Components::Template>([]() { return new Components::Template(); }); m_ComponentFactory.Register<Components::Template>([]() { return new Components::Template(); });
m_ComponentFactory.Register<Components::Player>([]() { return new Components::Player(); });
} }
void GameWorld::RegisterSystems() void GameWorld::RegisterSystems()
+3
View File
@@ -13,6 +13,7 @@
//#include "Systems/PlayerSystem.h" //#include "Systems/PlayerSystem.h"
#include "Systems/FreeSteeringSystem.h" #include "Systems/FreeSteeringSystem.h"
#include "Systems/TankSteeringSystem.h" #include "Systems/TankSteeringSystem.h"
#include "Systems/HelicopterSteeringSystem.h"
#include "Systems/RenderSystem.h" #include "Systems/RenderSystem.h"
#include "Systems/SoundSystem.h" #include "Systems/SoundSystem.h"
#include "Systems/PhysicsSystem.h" #include "Systems/PhysicsSystem.h"
@@ -28,6 +29,7 @@
#include "Components/Sprite.h" #include "Components/Sprite.h"
#include "Components/Template.h" #include "Components/Template.h"
#include "Components/Transform.h" #include "Components/Transform.h"
#include "Components/Viewport.h"
#include "Components/Physics.h" #include "Components/Physics.h"
#include "Components/SphereShape.h" #include "Components/SphereShape.h"
@@ -38,6 +40,7 @@
#include "Components/TankSteering.h" #include "Components/TankSteering.h"
#include "Components/TowerSteering.h" #include "Components/TowerSteering.h"
#include "Components/BarrelSteering.h" #include "Components/BarrelSteering.h"
#include "Components/Player.h"
class GameWorld : public World class GameWorld : public World
{ {
+3 -2
View File
@@ -7,6 +7,7 @@
#include "Events/InputCommand.h" #include "Events/InputCommand.h"
#include "Events/MouseMove.h" #include "Events/MouseMove.h"
template <typename EventContext>
class InputController class InputController
{ {
public: public:
@@ -26,8 +27,8 @@ protected:
std::shared_ptr<::EventBroker> EventBroker; std::shared_ptr<::EventBroker> EventBroker;
private: private:
EventRelay<Events::InputCommand> m_EInputCommand; EventRelay<EventContext, Events::InputCommand> m_EInputCommand;
EventRelay<Events::MouseMove> m_EMouseMove; EventRelay<EventContext, Events::MouseMove> m_EMouseMove;
}; };
#endif // InputController_h__ #endif // InputController_h__
+29 -1
View File
@@ -1,5 +1,6 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include "InputManager.h" #include "InputManager.h"
#include <XInput.h>
void InputManager::Initialize() void InputManager::Initialize()
{ {
@@ -12,6 +13,13 @@ void InputManager::Initialize()
void InputManager::Update(double dt) void InputManager::Update(double dt)
{ {
EventBroker->Process<InputManager>();
m_LastKeyState = m_CurrentKeyState;
m_LastMouseState = m_CurrentMouseState;
m_LastMouseX = m_CurrentMouseX;
m_LastMouseY = m_CurrentMouseY;
// Keyboard input // Keyboard input
for (int i = 0; i <= GLFW_KEY_LAST; ++i) for (int i = 0; i <= GLFW_KEY_LAST; ++i)
{ {
@@ -40,17 +48,23 @@ void InputManager::Update(double dt)
m_CurrentMouseState[i] = glfwGetMouseButton(m_GLFWWindow, i); m_CurrentMouseState[i] = glfwGetMouseButton(m_GLFWWindow, i);
if (m_CurrentMouseState[i] != m_LastMouseState[i]) if (m_CurrentMouseState[i] != m_LastMouseState[i])
{ {
double x, y;
glfwGetCursorPos(m_GLFWWindow, &x, &y);
// Publish mouse button events // Publish mouse button events
if (m_CurrentMouseState[i]) if (m_CurrentMouseState[i])
{ {
Events::MousePress e; Events::MousePress e;
e.Button = i; e.Button = i;
e.X = x;
e.Y = y;
EventBroker->Publish(e); EventBroker->Publish(e);
} }
else else
{ {
Events::MouseRelease e; Events::MouseRelease e;
e.Button = i; e.Button = i;
e.X = x;
e.Y = y;
EventBroker->Publish(e); EventBroker->Publish(e);
} }
} }
@@ -89,14 +103,28 @@ void InputManager::Update(double dt)
// } // }
// Xbox360 controller // Xbox360 controller
//using namespace ;
DWORD dwResult; DWORD dwResult;
for (int i = 0; i < XUSER_MAX_COUNT; i++) for (int i = 0; i < MAX_GAMEPADS; i++)
{ {
XINPUT_STATE state = { 0 }; XINPUT_STATE state = { 0 };
// Simply get the state of the controller from XInput. // Simply get the state of the controller from XInput.
dwResult = XInputGetState(i, &state); dwResult = XInputGetState(i, &state);
if (dwResult == 0) if (dwResult == 0)
{ {
if(std::abs(state.Gamepad.sThumbLX) <= XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
state.Gamepad.sThumbLX = 0;
if(std::abs(state.Gamepad.sThumbLY) <= XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
state.Gamepad.sThumbLY = 0;
if(std::abs(state.Gamepad.sThumbRX) <= XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
state.Gamepad.sThumbRX = 0;
if(std::abs(state.Gamepad.sThumbRY) <= XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
state.Gamepad.sThumbRY = 0;
if(std::abs(state.Gamepad.bLeftTrigger) <= XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
state.Gamepad.bLeftTrigger = 0;
if(std::abs(state.Gamepad.bRightTrigger) <= XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
state.Gamepad.bRightTrigger = 0;
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftX)] = state.Gamepad.sThumbLX / 32767.f; m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftX)] = state.Gamepad.sThumbLX / 32767.f;
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftY)] = state.Gamepad.sThumbLY / 32767.f; m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftY)] = state.Gamepad.sThumbLY / 32767.f;
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::RightX)] = state.Gamepad.sThumbRX / 32767.f; m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::RightX)] = state.Gamepad.sThumbRX / 32767.f;
+8 -8
View File
@@ -3,8 +3,6 @@
#include <array> #include <array>
#include <Xinput.h>
#include "EventBroker.h" #include "EventBroker.h"
#include "Events/KeyDown.h" #include "Events/KeyDown.h"
#include "Events/KeyUp.h" #include "Events/KeyUp.h"
@@ -33,15 +31,17 @@ public:
void Initialize(); void Initialize();
static const short MAX_GAMEPADS = 4;
void Update(double dt); void Update(double dt);
private: private:
GLFWwindow* m_GLFWWindow; GLFWwindow* m_GLFWWindow;
std::shared_ptr<::EventBroker> EventBroker; std::shared_ptr<::EventBroker> EventBroker;
EventRelay<Events::LockMouse> m_ELockMouse; EventRelay<InputManager, Events::LockMouse> m_ELockMouse;
bool OnLockMouse(const Events::LockMouse &event); bool OnLockMouse(const Events::LockMouse &event);
EventRelay<Events::UnlockMouse> m_EUnlockMouse; EventRelay<InputManager, Events::UnlockMouse> m_EUnlockMouse;
bool OnUnlockMouse(const Events::UnlockMouse &event); bool OnUnlockMouse(const Events::UnlockMouse &event);
std::array<int, GLFW_KEY_LAST+1> m_CurrentKeyState; std::array<int, GLFW_KEY_LAST+1> m_CurrentKeyState;
@@ -49,11 +49,11 @@ private:
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_CurrentMouseState; std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_CurrentMouseState;
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_LastMouseState; std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_LastMouseState;
typedef std::array<float, static_cast<int>(Gamepad::Axis::LAST) + 1> GamepadAxisState; typedef std::array<float, static_cast<int>(Gamepad::Axis::LAST) + 1> GamepadAxisState;
std::array<GamepadAxisState, XUSER_MAX_COUNT> m_CurrentGamepadAxisState; std::array<GamepadAxisState, MAX_GAMEPADS> m_CurrentGamepadAxisState;
std::array<GamepadAxisState, XUSER_MAX_COUNT> m_LastGamepadAxisState; std::array<GamepadAxisState, MAX_GAMEPADS> m_LastGamepadAxisState;
typedef std::array<bool, static_cast<int>(Gamepad::Button::LAST) + 1> GamepadButtonState; typedef std::array<bool, static_cast<int>(Gamepad::Button::LAST) + 1> GamepadButtonState;
std::array<GamepadButtonState, XUSER_MAX_COUNT> m_CurrentGamepadButtonState; std::array<GamepadButtonState, MAX_GAMEPADS> m_CurrentGamepadButtonState;
std::array<GamepadButtonState, XUSER_MAX_COUNT> m_LastGamepadButtonState; std::array<GamepadButtonState, MAX_GAMEPADS> m_LastGamepadButtonState;
double m_CurrentMouseX, m_CurrentMouseY; double m_CurrentMouseX, m_CurrentMouseY;
double m_LastMouseX, m_LastMouseY; double m_LastMouseX, m_LastMouseY;
+116 -2
View File
@@ -22,6 +22,8 @@ Model::Model(ResourceManager* rm, OBJ &obj)
auto texture = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", currentMaterial->DiffuseTexture.FileName)); auto texture = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", currentMaterial->DiffuseTexture.FileName));
// TODO: Load normal map // TODO: Load normal map
std::shared_ptr<Texture> normalMap = nullptr; std::shared_ptr<Texture> normalMap = nullptr;
if (!currentMaterial->NormalMap.FileName.empty())
normalMap = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", currentMaterial->NormalMap.FileName));
// Load specular map // Load specular map
std::shared_ptr<Texture> specularMap = nullptr; std::shared_ptr<Texture> specularMap = nullptr;
if (!currentMaterial->SpecularMap.FileName.empty()) if (!currentMaterial->SpecularMap.FileName.empty())
@@ -63,7 +65,9 @@ Model::Model(ResourceManager* rm, OBJ &obj)
if (Vertices.size() > 0) if (Vertices.size() > 0)
{ {
CreateBuffers(Vertices, Normals, TextureCoords); CreateTangents();
//getSimilarVertexIndex();
CreateBuffers(Vertices, Normals, TangentNormals, BiTangentNormals, TextureCoords);
} }
else else
{ {
@@ -71,7 +75,7 @@ Model::Model(ResourceManager* rm, OBJ &obj)
} }
} }
void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec3> normals, std::vector<glm::vec2>textureCoords) void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec3> normals, std::vector<glm::vec3> tangents, std::vector<glm::vec3> biTangents, std::vector<glm::vec2>textureCoords)
{ {
LOG_INFO("Generating VertexBuffer"); LOG_INFO("Generating VertexBuffer");
@@ -100,6 +104,32 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
LOG_WARNING("Created empty normal buffer!"); LOG_WARNING("Created empty normal buffer!");
} }
LOG_INFO("Generating TangentNormalsBuffer");
glGenBuffers(1, &TangentNormalsBuffer);
if (tangents.size() > 0)
{
glBindBuffer(GL_ARRAY_BUFFER, TangentNormalsBuffer);
glBufferData(GL_ARRAY_BUFFER, tangents.size() * sizeof(glm::vec3), &tangents[0], GL_STATIC_DRAW);
GLERROR("GLEW: BufferFail, TangentNormalsBuffer");
}
else
{
LOG_WARNING("Created empty tangent buffer!");
}
LOG_INFO("Generating BiTangentNormalsBuffer");
glGenBuffers(1, &BiTangentNormalsBuffer);
if (biTangents.size() > 0)
{
glBindBuffer(GL_ARRAY_BUFFER, BiTangentNormalsBuffer);
glBufferData(GL_ARRAY_BUFFER, biTangents.size() * sizeof(glm::vec3), &biTangents[0], GL_STATIC_DRAW);
GLERROR("GLEW: BufferFail, BiTangentNormalsBuffer");
}
else
{
LOG_WARNING("Created empty biTangent buffer!");
}
LOG_INFO("Generating textureCoordBuffer"); LOG_INFO("Generating textureCoordBuffer");
glGenBuffers(1, &TextureCoordBuffer); glGenBuffers(1, &TextureCoordBuffer);
@@ -130,10 +160,94 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0); glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0);
GLERROR("GLEW: BufferFail5"); GLERROR("GLEW: BufferFail5");
glBindBuffer(GL_ARRAY_BUFFER, TangentNormalsBuffer);
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, 0);
GLERROR("GLEW: BufferFail5");
glBindBuffer(GL_ARRAY_BUFFER, BiTangentNormalsBuffer);
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 0, 0);
GLERROR("GLEW: BufferFail5");
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1); glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2); glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4);
GLERROR("GLEW: BufferFail5"); GLERROR("GLEW: BufferFail5");
} }
bool Model::IsNear( float v1, float v2 )
{
return fabs(v1 - v2) < 0.01f;
}
void Model::getSimilarVertexIndex()
{
for(int i = 0; i < Vertices.size(); i++)
{
for(int t = 0; t < Vertices.size(); t++)
{
if(i != t)
{
if(IsNear(Vertices[i].x, Vertices[t].x)
& IsNear(Vertices[i].y, Vertices[t].y)
& IsNear(Vertices[i].z, Vertices[t].z)
)
{
glm::vec3 tempNormal, tempTangent, tempBiTangent;
tempNormal = glm::normalize(Normals[i] + Normals[t]);
tempTangent = glm::normalize(TangentNormals[i] + TangentNormals[t]);
tempBiTangent = glm::normalize(BiTangentNormals[i] + BiTangentNormals[t]);
Normals[i] = tempNormal;
Normals[t] = tempNormal;
TangentNormals[i] = tempTangent;
TangentNormals[t] = tempTangent;
BiTangentNormals[i] = tempBiTangent;
BiTangentNormals[t] = tempBiTangent;
}
}
}
}
}
void Model::CreateTangents()
{
for(int i = 0; i < Vertices.size(); i += 3)
{
glm::vec3 v0 = Vertices[i];
glm::vec3 v1 = Vertices[i+1];
glm::vec3 v2 = Vertices[i+2];
glm::vec2 uv0 = TextureCoords[i];
glm::vec2 uv1 = TextureCoords[i+1];
glm::vec2 uv2 = TextureCoords[i+2];
//Calculate the edge of the triangle
glm::vec3 edge1 = v1-v0;
glm::vec3 edge2 = v2-v0;
glm::vec2 deltaUV1 = uv1 - uv0;
glm::vec2 deltaUV2 = uv2 - uv0;
float r = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV1.y * deltaUV2.x);
glm::vec3 tangent, biTangent;
tangent = (edge1 * deltaUV2.y - edge2 * deltaUV1.y) * r;
biTangent = (edge2 * deltaUV1.x - edge1 * deltaUV2.x) * r;
TangentNormals.push_back(tangent);
TangentNormals.push_back(tangent);
TangentNormals.push_back(tangent);
BiTangentNormals.push_back(biTangent);
BiTangentNormals.push_back(biTangent);
BiTangentNormals.push_back(biTangent);
}
}
+10
View File
@@ -38,10 +38,14 @@ public:
private: private:
std::vector<glm::vec3> Normals; std::vector<glm::vec3> Normals;
std::vector<glm::vec3> TangentNormals;
std::vector<glm::vec3> BiTangentNormals;
std::vector<glm::vec2> TextureCoords; std::vector<glm::vec2> TextureCoords;
GLuint VertexBuffer; GLuint VertexBuffer;
GLuint NormalBuffer; GLuint NormalBuffer;
GLuint TangentNormalsBuffer;
GLuint BiTangentNormalsBuffer;
GLuint TextureCoordBuffer; GLuint TextureCoordBuffer;
bool Loadobj( bool Loadobj(
@@ -54,8 +58,14 @@ private:
void CreateBuffers( void CreateBuffers(
std::vector<glm::vec3> _Vertices, std::vector<glm::vec3> _Vertices,
std::vector<glm::vec3> _Normals, std::vector<glm::vec3> _Normals,
std::vector<glm::vec3> _Tangents,
std::vector<glm::vec3> _BiTangents,
std::vector<glm::vec2>_TextureCoords std::vector<glm::vec2>_TextureCoords
); );
void CreateTangents();
bool IsNear(float v1, float v2);
void getSimilarVertexIndex();
}; };
#endif // Model_h__ #endif // Model_h__
+2 -2
View File
@@ -22,7 +22,7 @@ void VehicleSetup::buildVehicle(World *world, const hkpWorld* physicsWorld, hkpV
// //
vehicle.m_data = new hkpVehicleData; vehicle.m_data = new hkpVehicleData;
vehicle.m_driverInput = new hkpVehicleDefaultAnalogDriverInput; vehicle.m_driverInput = new hkpVehicleDefaultAnalogDriverInput;
vehicle.m_steering = new hkpVehicleDefaultSteering; vehicle.m_steering = new TankSteering;
vehicle.m_engine = new hkpVehicleDefaultEngine; vehicle.m_engine = new hkpVehicleDefaultEngine;
vehicle.m_transmission = new hkpVehicleDefaultTransmission; vehicle.m_transmission = new hkpVehicleDefaultTransmission;
vehicle.m_brake = new hkpVehicleDefaultBrake; vehicle.m_brake = new hkpVehicleDefaultBrake;
@@ -201,7 +201,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultT
transmission.m_upshiftRPM = 7000.0f; transmission.m_upshiftRPM = 7000.0f;
transmission.m_clutchDelayTime = 0.0f; transmission.m_clutchDelayTime = 0.0f;
transmission.m_reverseGearRatio = 1.2f; transmission.m_reverseGearRatio = 1.0f;
transmission.m_gearsRatio[0] = 3.0f; transmission.m_gearsRatio[0] = 3.0f;
transmission.m_gearsRatio[1] = 2.25f; transmission.m_gearsRatio[1] = 2.25f;
transmission.m_gearsRatio[2] = 1.5f; transmission.m_gearsRatio[2] = 1.5f;
+26
View File
@@ -33,6 +33,32 @@
#include "Components/Wheel.h" #include "Components/Wheel.h"
#include "Components/Transform.h" #include "Components/Transform.h"
/// Tank specific steering implementation. Rear wheels steer in opposite direction
/// to front wheels.
class TankSteering: public hkpVehicleDefaultSteering
{
public:
virtual void calcSteering(const hkReal deltaTime, const hkpVehicleInstance* vehicle, const hkpVehicleDriverInput::FilteredDriverInputOutput& filteredInfoOutput, SteeringAnglesOutput& steeringOutput )
{
hkpVehicleDefaultSteering::calcMainSteeringAngle( deltaTime, vehicle, filteredInfoOutput, steeringOutput );
// Wheels.
for (int w_it = 0; w_it < m_doesWheelSteer.getSize(); w_it++)
{
if ( m_doesWheelSteer[w_it] )
{
steeringOutput.m_wheelsSteeringAngle [w_it] = steeringOutput.m_mainSteeringAngle;
}
else
{
// Steer with front and back wheels to simulate a tank.
steeringOutput.m_wheelsSteeringAngle [w_it] = -steeringOutput.m_mainSteeringAngle;
}
}
}
};
class VehicleSetup class VehicleSetup
{ {
public: public:
+103 -16
View File
@@ -20,7 +20,7 @@ Renderer::Renderer()
m_ShadowMapRes = 2048*6; m_ShadowMapRes = 2048*6;
m_SunPosition = glm::vec3(0, 3.5f, 10); m_SunPosition = glm::vec3(0, 3.5f, 10);
m_SunTarget = glm::vec3(0, 0, 0); m_SunTarget = glm::vec3(0, 0, 0);
m_SunProjection = glm::ortho<float>(-200.f, 200.f, -200.f, 200.f, -100, 200); m_SunProjection = glm::ortho<float>(10.f, -10.f, 10.f, -10.f, 10.f, -10.f);
/* Lights = 0;*/ /* Lights = 0;*/
} }
@@ -572,6 +572,15 @@ void Renderer::FrameBufferTextures()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//Generate and bind normal texture
glGenTextures(1, &m_fSpecularTexture);
glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture);
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); /*glGenTextures(1, &m_fShadowTexture);
glBindTexture(GL_TEXTURE_2D, 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); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
@@ -588,6 +597,7 @@ void Renderer::FrameBufferTextures()
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fDiffuseTexture, 0); 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_ATTACHMENT1, GL_TEXTURE_2D, m_fPositionTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, m_fNormalsTexture, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, m_fNormalsTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, m_fSpecularTexture, 0);
//glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, m_fShadowTexture, 0); //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, m_fShadowTexture, 0);
GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
@@ -626,10 +636,22 @@ void Renderer::DrawFBO()
{ {
DrawShadowMap(); DrawShadowMap();
for (auto &pair : m_Viewports)
{
Viewport &viewport = pair.second;
if (!viewport.Camera)
continue;
int x = viewport.Left * m_Width;
int y = viewport.Top * m_Height;
int width = (viewport.Right - viewport.Left) * m_Width;
int height = (viewport.Bottom - viewport.Top) * m_Height;
/* /*
Base pass Base pass
*/ */
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass);
glViewport(0, 0, m_Width, m_Height);
// Clear G-buffer // Clear G-buffer
GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 }; GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
@@ -644,8 +666,7 @@ void Renderer::DrawFBO()
glCullFace(GL_BACK); glCullFace(GL_BACK);
glViewport(0, 0, m_Width, m_Height); DrawFBOScene(viewport);
DrawFBOScene();
/* /*
Lighting pass Lighting pass
@@ -664,13 +685,14 @@ void Renderer::DrawFBO()
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture); glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
glCullFace(GL_FRONT); glCullFace(GL_FRONT);
DrawLightScene(); DrawLightScene(viewport);
/* /*
Final pass Final pass
*/ */
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(x, y, width, height);
glClear(GL_DEPTH_BUFFER_BIT);
m_FinalPassProgram.Bind(); m_FinalPassProgram.Bind();
@@ -687,16 +709,17 @@ void Renderer::DrawFBO()
glBindVertexArray(m_ScreenQuad); glBindVertexArray(m_ScreenQuad);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 6); glDrawArrays(GL_TRIANGLES, 0, 6);
}
} }
void Renderer::DrawFBOScene() void Renderer::DrawFBOScene(Viewport &viewport)
{ {
// glEnable(GL_DEPTH_TEST);//Tests where objects are and display them correctly // 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 // 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 // glCullFace(GL_BACK); //Make it so that only the back faces are rendered
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //Draws filled polygons glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //Draws filled polygons
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix(); glm::mat4 cameraMatrix = viewport.Camera->ProjectionMatrix() * viewport.Camera->ViewMatrix();
glm::mat4 MVP; glm::mat4 MVP;
glm::mat4 biasMatrix( glm::mat4 biasMatrix(
0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0,
@@ -727,13 +750,18 @@ void Renderer::DrawFBOScene()
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); 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(), "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(), "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(), "V"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix())); glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ProjectionMatrix()));
glBindVertexArray(model->VAO); glBindVertexArray(model->VAO);
for (auto texGroup : model->TextureGroups) for (auto texGroup : model->TextureGroups)
{ {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, *texGroup.Texture); glBindTexture(GL_TEXTURE_2D, *texGroup.Texture);
if (texGroup.NormalMap)
{
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, *texGroup.NormalMap);
}
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1); glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
} }
} }
@@ -752,8 +780,8 @@ void Renderer::DrawFBOScene()
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); 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(), "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(), "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(), "V"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix())); glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ProjectionMatrix()));
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, *texture); glBindTexture(GL_TEXTURE_2D, *texture);
@@ -764,7 +792,7 @@ void Renderer::DrawFBOScene()
void Renderer::DrawLightScene() void Renderer::DrawLightScene(Viewport &viewport)
{ {
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendEquation (GL_FUNC_ADD); glBlendEquation (GL_FUNC_ADD);
@@ -774,7 +802,7 @@ void Renderer::DrawLightScene()
glDepthMask (GL_FALSE); glDepthMask (GL_FALSE);
glBindVertexArray(m_sphereModel->VAO); glBindVertexArray(m_sphereModel->VAO);
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix(); glm::mat4 cameraMatrix = viewport.Camera->ProjectionMatrix() * viewport.Camera->ViewMatrix();
glm::mat4 MVP; glm::mat4 MVP;
for (auto &light : Lights) for (auto &light : Lights)
@@ -783,13 +811,13 @@ void Renderer::DrawLightScene()
glUniform2fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ViewportSize"), 1,glm::value_ptr(glm::vec2(m_Width, m_Height))); 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(), "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(), "V"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix())); glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ProjectionMatrix()));
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(light.SphereModelMatrix)); 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(), "ls"), 1, glm::value_ptr(light.Specular));
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ld"), 1, glm::value_ptr(light.Diffuse)); glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ld"), 1, glm::value_ptr(light.Diffuse));
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "lp"), 1, glm::value_ptr(light.Position)); 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); glUniform3f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "CameraPosition"), viewport.Camera->Position().x, viewport.Camera->Position().y, viewport.Camera->Position().z);
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "specularExponent"), light.SpecularExponent); glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "specularExponent"), light.SpecularExponent);
// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ConstantAttenuation"), light.ConstantAttenuation); // glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ConstantAttenuation"), light.ConstantAttenuation);
// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), light.LinearAttenuation); // glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), light.LinearAttenuation);
@@ -826,3 +854,62 @@ glm::mat4 Renderer::CreateLightMatrix(Light &_light)
return model; return model;
} }
void Renderer::UpdateSunProjection()
{
glm::vec3 NDCCube[] =
{
glm::vec3(-1.f, -1.f, -1.f),
glm::vec3(1.f, -1.f, -1.f),
glm::vec3(-1.f, 1.f, -1.f),
glm::vec3(1.f, 1.f, -1.f),
glm::vec3(-1.f, -1.f, 1.f),
glm::vec3(1.f, -1.f, 1.f),
glm::vec3(-1.f, 1.f, 1.f),
glm::vec3(1.f, 1.f, 1.f)
};
glm::mat4 inverseProjectionViewMatrix = glm::inverse(m_Camera->ViewMatrix()) * glm::inverse(m_Camera->ProjectionMatrix());
//Also * with world matrix for light
for(auto corner : NDCCube)
{
//corner *= inverseProjectionViewMatrix;
}
//Calculate the bounding box of the transformed frustum corners. This will be the view frustum for the shadow map.
//Pass the bounding box's extents to glOrtho or similar to set up the orthographic projection matrix for the shadow map.
}
void Renderer::RegisterViewport(int identifier, float left, float top, float right, float bottom)
{
Viewport v;
v.Left = left;
v.Top = top;
v.Right = right;
v.Bottom = bottom;
v.Camera = nullptr;
m_Viewports[identifier] = v;
}
void Renderer::RegisterCamera(int identifier, float FOV, float nearClip, float farClip)
{
m_Cameras[identifier] = std::make_shared<Camera>(FOV, (float)m_Width / m_Height, nearClip, farClip);
}
void Renderer::UpdateViewport(int viewportIdentifier, int cameraIdentifier)
{
auto &viewport = m_Viewports[viewportIdentifier];
auto camera = m_Cameras[cameraIdentifier];
camera->AspectRatio(((viewport.Right - viewport.Left) * m_Width) / ((viewport.Bottom - viewport.Top) * m_Height));
viewport.Camera = camera;
}
void Renderer::UpdateCamera(int cameraIdentifier, glm::vec3 position, glm::quat orientation, float FOV, float nearClip, float farClip)
{
m_Cameras[cameraIdentifier]->Position(position);
m_Cameras[cameraIdentifier]->Orientation(orientation);
m_Cameras[cameraIdentifier]->FOV(FOV);
m_Cameras[cameraIdentifier]->NearClip(nearClip);
m_Cameras[cameraIdentifier]->FarClip(farClip);
}
+23 -2
View File
@@ -35,6 +35,11 @@ public:
void Draw(double dt); void Draw(double dt);
void DrawText(); void DrawText();
void RegisterViewport(int identifier, float left, float top, float right, float bottom);
void RegisterCamera(int identifier, float FOV, float nearClip, float farClip);
void UpdateViewport(int viewportIdentifier, int cameraIdentifier);
void UpdateCamera(int cameraIdentifier, glm::vec3 position, glm::quat orientation, float FOV, float nearClip, float farClip);
void AddModelToDraw(Model* model, glm::vec3 position, glm::quat orientation, glm::vec3 scale, bool visible, bool shadowCaster); void AddModelToDraw(Model* model, glm::vec3 position, glm::quat orientation, glm::vec3 scale, bool visible, bool shadowCaster);
void AddTextureToDraw(Texture* texture, glm::vec3 position, glm::quat orientation, glm::vec3 scale); void AddTextureToDraw(Texture* texture, glm::vec3 position, glm::quat orientation, glm::vec3 scale);
void AddTextToDraw(); void AddTextToDraw();
@@ -67,6 +72,18 @@ public:
private: private:
int m_Width, m_Height; int m_Width, m_Height;
struct Viewport
{
float Left;
float Top;
float Right;
float Bottom;
std::shared_ptr<Camera> Camera;
};
std::unordered_map<int, Viewport> m_Viewports;
std::unordered_map<int, std::shared_ptr<Camera>> m_Cameras;
struct Light struct Light
{ {
glm::vec3 Position; glm::vec3 Position;
@@ -105,6 +122,7 @@ private:
GLuint m_fDiffuseTexture; GLuint m_fDiffuseTexture;
GLuint m_fPositionTexture; GLuint m_fPositionTexture;
GLuint m_fNormalsTexture; GLuint m_fNormalsTexture;
GLuint m_fSpecularTexture;
GLuint m_fBlendTexture; GLuint m_fBlendTexture;
GLuint m_fbLightingPass; GLuint m_fbLightingPass;
GLuint m_fLightingTexture; GLuint m_fLightingTexture;
@@ -140,10 +158,13 @@ private:
void CreateShadowMap(int resolution); void CreateShadowMap(int resolution);
void FrameBufferTextures(); void FrameBufferTextures();
void DrawFBO(); void DrawFBO();
void DrawFBOScene(); void DrawFBOScene(Viewport &viewport);
void DrawLightScene(); void DrawLightScene(Viewport &viewport);
void BindFragDataLocation(); void BindFragDataLocation();
glm::mat4 CreateLightMatrix(Light &_light); glm::mat4 CreateLightMatrix(Light &_light);
void UpdateSunProjection();
void CreateNormalMapTangent();
GLuint CreateQuad(); GLuint CreateQuad();
void DrawDebugShadowMap(); void DrawDebugShadowMap();
+1 -1
View File
@@ -24,6 +24,6 @@ void main()
vec4 _FragmentColor = DiffuseTexel * vec4(La, 1.0) + LightingTexel; vec4 _FragmentColor = DiffuseTexel * vec4(La, 1.0) + LightingTexel;
FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a); FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
//FragmentColor = ShadowTexel; //FragmentColor = DiffuseTexel;
} }
+13 -1
View File
@@ -2,6 +2,9 @@
layout (binding=0) uniform sampler2D DiffuseTexture; layout (binding=0) uniform sampler2D DiffuseTexture;
layout (binding=1) uniform sampler2D ShadowTexture; layout (binding=1) uniform sampler2D ShadowTexture;
layout (binding=2) uniform sampler2D NormalMapTexture;
layout (binding=3) uniform sampler2D SpecularMapTexture;
in VertexData in VertexData
{ {
@@ -9,11 +12,14 @@ in VertexData
vec3 Normal; vec3 Normal;
vec2 TextureCoord; vec2 TextureCoord;
vec4 ShadowCoord; vec4 ShadowCoord;
vec3 Tangent;
vec3 BiTangent;
} Input; } Input;
out vec4 frag_Diffuse; out vec4 frag_Diffuse;
out vec4 frag_Position; out vec4 frag_Position;
out vec4 frag_Normal; out vec4 frag_Normal;
out vec4 frag_specular;
float Shadow(vec4 ShadowCoord) float Shadow(vec4 ShadowCoord)
{ {
@@ -32,6 +38,7 @@ float Shadow(vec4 ShadowCoord)
void main() void main()
{ {
// Diffuse Texture // Diffuse Texture
frag_Diffuse = texture(DiffuseTexture, Input.TextureCoord) * Shadow(Input.ShadowCoord); frag_Diffuse = texture(DiffuseTexture, Input.TextureCoord) * Shadow(Input.ShadowCoord);
@@ -39,5 +46,10 @@ void main()
frag_Position = vec4(Input.Position.xyz, 1.0); frag_Position = vec4(Input.Position.xyz, 1.0);
// G-buffer Normal // G-buffer Normal
frag_Normal = vec4(Input.Normal, 0.0); mat3 TBN = transpose(mat3(Input.Tangent, Input.BiTangent, Input.Normal));
frag_Normal = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0));
//frag_Normal = vec4(Input.Normal, 0.0);
//G-buffer Specular
frag_specular = texture(SpecularMapTexture, Input.TextureCoord);
} }
+1
View File
@@ -81,4 +81,5 @@ void main()
vec4 NormalTexel = texture(NormalsTexture, TextureCoord); vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
FragColor = phong(vec3(PositionTexel), vec3(NormalTexel)); FragColor = phong(vec3(PositionTexel), vec3(NormalTexel));
//FragColor = NormalTexel;
} }
+6
View File
@@ -9,6 +9,8 @@ uniform mat4 DepthMVP;
layout (location = 0) in vec3 Position; layout (location = 0) in vec3 Position;
layout (location = 1) in vec3 Normal; layout (location = 1) in vec3 Normal;
layout (location = 2) in vec2 TextureCoord; layout (location = 2) in vec2 TextureCoord;
layout (location = 3) in vec3 Tangent;
layout (location = 4) in vec3 BiTangent;
out VertexData out VertexData
{ {
@@ -16,6 +18,8 @@ out VertexData
vec3 Normal; vec3 Normal;
vec2 TextureCoord; vec2 TextureCoord;
vec4 ShadowCoord; vec4 ShadowCoord;
vec3 Tangent;
vec3 BiTangent;
} Output; } Output;
void main() void main()
@@ -26,4 +30,6 @@ void main()
Output.Normal = normalize(vec3(inverse(transpose(V * M)) * vec4(Normal, 0.0))); Output.Normal = normalize(vec3(inverse(transpose(V * M)) * vec4(Normal, 0.0)));
Output.TextureCoord = TextureCoord; Output.TextureCoord = TextureCoord;
Output.ShadowCoord = DepthMVP * vec4(Position, 1.0); Output.ShadowCoord = DepthMVP * vec4(Position, 1.0);
Output.Tangent = normalize(vec3(inverse(transpose(V * M)) * vec4(Tangent, 0.0)));
Output.BiTangent = normalize(vec3(inverse(transpose(V * M)) * vec4(BiTangent, 0.0)));
} }
+1 -1
View File
@@ -19,7 +19,7 @@ public:
void Update(double dt) override; void Update(double dt) override;
EventRelay<Events::KeyDown> m_EKeyDown; EventRelay<DebugSystem, Events::KeyDown> m_EKeyDown;
bool OnKeyDown(const Events::KeyDown &event); bool OnKeyDown(const Events::KeyDown &event);
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override; //void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
+7 -7
View File
@@ -60,27 +60,27 @@ void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const Events::InputCommand &event) bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const Events::InputCommand &event)
{ {
// Movement // Movement
if (event.Command == "vertical") if (event.Command == "cam_vertical")
{ {
Movement.z = -event.Value; Movement.z = -event.Value;
} }
else if (event.Command == "horizontal") else if (event.Command == "cam_horizontal")
{ {
Movement.x = event.Value; Movement.x = event.Value;
} }
else if (event.Command == "normal") else if (event.Command == "cam_normal")
{ {
Movement.y = event.Value; Movement.y = event.Value;
} }
// Speed // Speed
else if (event.Command == "speed") else if (event.Command == "cam_speed")
{ {
SpeedMultiplier = event.Value; SpeedMultiplier = event.Value;
} }
// Mouse click // Mouse click
else if (event.Command == "attack") else if (event.Command == "cam_attack")
{ {
OrientationActive = event.Value > 0; OrientationActive = event.Value > 0;
@@ -96,11 +96,11 @@ bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const E
} }
} }
else if (event.Command == "vertical2") else if (event.Command == "cam_vertical2")
{ {
ControllerOrientation.x = event.Value; ControllerOrientation.x = event.Value;
} }
else if (event.Command == "horizontal2") else if (event.Command == "cam_horizontal2")
{ {
ControllerOrientation.y = -event.Value; ControllerOrientation.y = -event.Value;
} }
+1 -1
View File
@@ -27,7 +27,7 @@ private:
std::unique_ptr<FreeSteeringInputController> m_InputController; std::unique_ptr<FreeSteeringInputController> m_InputController;
}; };
class FreeSteeringSystem::FreeSteeringInputController : InputController class FreeSteeringSystem::FreeSteeringInputController : InputController<FreeSteeringSystem>
{ {
public: public:
FreeSteeringInputController(std::shared_ptr<::EventBroker> eventBroker) FreeSteeringInputController(std::shared_ptr<::EventBroker> eventBroker)
+67
View File
@@ -0,0 +1,67 @@
#include "PrecompiledHeader.h"
#include "HelicopterSteeringSystem.h"
#include "World.h"
void Systems::HelicopterSteeringSystem::RegisterComponents(ComponentFactory* cf)
{
cf->Register<Components::HelicopterSteering>([]() { return new Components::HelicopterSteering(); });
}
void Systems::HelicopterSteeringSystem::Initialize()
{
m_InputController = std::unique_ptr<HelicopterSteeringInputController>(new HelicopterSteeringInputController(EventBroker));
}
void Systems::HelicopterSteeringSystem::Update(double dt)
{
}
void Systems::HelicopterSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (!transform)
return;
auto helicopterComponent = m_World->GetComponent<Components::HelicopterSteering>(entity);
if (helicopterComponent)
{
glm::vec3 controllerRotationEuler = m_InputController->Rotation * (float)dt;
transform->Orientation *= glm::quat(controllerRotationEuler);
Events::ApplyForce e;
e.Entity = entity;
e.DeltaTime = dt;
e.Force = glm::normalize(transform->Orientation * glm::vec3(0, 1, 0)) * (m_InputController->Power * 3000.f * 9.82f * 8.f);
EventBroker->Publish(e);
}
}
bool Systems::HelicopterSteeringSystem::HelicopterSteeringInputController::OnCommand(const Events::InputCommand &event)
{
if (event.Command == "horizontal")
{
Rotation.z = -event.Value;
}
else if (event.Command == "vertical")
{
Rotation.x = -event.Value;
}
else if (event.Command == "normal")
{
Power = event.Value;
}
return true;
}
bool Systems::HelicopterSteeringSystem::HelicopterSteeringInputController::OnMouseMove(const Events::MouseMove &event)
{
return true;
}
void Systems::HelicopterSteeringSystem::HelicopterSteeringInputController::Update(double dt)
{
}
+54
View File
@@ -0,0 +1,54 @@
#include "System.h"
#include "Components/Transform.h"
#include "Components/HelicopterSteering.h"
#include "Events/SetVelocity.h"
#include "Events/ApplyForce.h"
#include "InputController.h"
namespace Systems
{
class HelicopterSteeringSystem : public System
{
public:
HelicopterSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
: System(world, eventBroker) { }
void RegisterComponents(ComponentFactory* cf) override;
void Initialize() override;
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
private:
class HelicopterSteeringInputController;
std::unique_ptr<HelicopterSteeringInputController> m_InputController;
std::map<EntityID, double> m_TimeSinceLastShot;
};
class HelicopterSteeringSystem::HelicopterSteeringInputController : InputController<HelicopterSteeringSystem>
{
public:
HelicopterSteeringInputController(std::shared_ptr<::EventBroker> eventBroker)
: InputController(eventBroker)
, Power(0.f)
{ }
float Power;
glm::vec3 Rotation;
void Update(double dt);
protected:
bool OnCommand(const Events::InputCommand &event) override;
bool OnMouseMove(const Events::MouseMove &event) override;
};
}
+4 -4
View File
@@ -53,7 +53,7 @@ bool Systems::InputSystem::OnKeyDown(const Events::KeyDown &event)
float value; float value;
std::tie(command, value) = bindingIt->second; std::tie(command, value) = bindingIt->second;
m_CommandKeyboardValues[command][event.KeyCode] = value; m_CommandKeyboardValues[command][event.KeyCode] = value;
PublishCommand(0, command, GetCommandTotalValue(command)); PublishCommand(1, command, GetCommandTotalValue(command));
} }
return true; return true;
@@ -68,7 +68,7 @@ bool Systems::InputSystem::OnKeyUp(const Events::KeyUp &event)
float value; float value;
std::tie(command, value) = bindingIt->second; std::tie(command, value) = bindingIt->second;
m_CommandKeyboardValues[command][event.KeyCode] = 0; m_CommandKeyboardValues[command][event.KeyCode] = 0;
PublishCommand(0, command, GetCommandTotalValue(command));; PublishCommand(1, command, GetCommandTotalValue(command));;
} }
return true; return true;
@@ -83,7 +83,7 @@ bool Systems::InputSystem::OnMousePress(const Events::MousePress &event)
float value; float value;
std::tie(command, value) = bindingIt->second; std::tie(command, value) = bindingIt->second;
m_CommandMouseButtonValues[command][event.Button] = value; m_CommandMouseButtonValues[command][event.Button] = value;
PublishCommand(0, command, GetCommandTotalValue(command)); PublishCommand(1, command, GetCommandTotalValue(command));
} }
return true; return true;
@@ -98,7 +98,7 @@ bool Systems::InputSystem::OnMouseRelease(const Events::MouseRelease &event)
float value; float value;
std::tie(command, value) = bindingIt->second; std::tie(command, value) = bindingIt->second;
m_CommandMouseButtonValues[command][event.Button] = 0; m_CommandMouseButtonValues[command][event.Button] = 0;
PublishCommand(0, command, GetCommandTotalValue(command)); PublishCommand(1, command, GetCommandTotalValue(command));
} }
return true; return true;
+11 -11
View File
@@ -45,28 +45,28 @@ private:
std::unordered_map<Gamepad::Button, std::tuple<std::string, float>> m_GamepadButtonBindings; // Gamepad::Button -> command string std::unordered_map<Gamepad::Button, std::tuple<std::string, float>> m_GamepadButtonBindings; // Gamepad::Button -> command string
// Input events // Input events
EventRelay<Events::KeyDown> m_EKeyDown; EventRelay<InputSystem, Events::KeyDown> m_EKeyDown;
bool OnKeyDown(const Events::KeyDown &event); bool OnKeyDown(const Events::KeyDown &event);
EventRelay<Events::KeyUp> m_EKeyUp; EventRelay<InputSystem, Events::KeyUp> m_EKeyUp;
bool OnKeyUp(const Events::KeyUp &event); bool OnKeyUp(const Events::KeyUp &event);
EventRelay<Events::MousePress> m_EMousePress; EventRelay<InputSystem, Events::MousePress> m_EMousePress;
bool OnMousePress(const Events::MousePress &event); bool OnMousePress(const Events::MousePress &event);
EventRelay<Events::MouseRelease> m_EMouseRelease; EventRelay<InputSystem, Events::MouseRelease> m_EMouseRelease;
bool OnMouseRelease(const Events::MouseRelease &event); bool OnMouseRelease(const Events::MouseRelease &event);
EventRelay<Events::GamepadAxis> m_EGamepadAxis; EventRelay<InputSystem, Events::GamepadAxis> m_EGamepadAxis;
bool OnGamepadAxis(const Events::GamepadAxis &event); bool OnGamepadAxis(const Events::GamepadAxis &event);
EventRelay<Events::GamepadButtonDown> m_EGamepadButtonDown; EventRelay<InputSystem, Events::GamepadButtonDown> m_EGamepadButtonDown;
bool OnGamepadButtonDown(const Events::GamepadButtonDown &event); bool OnGamepadButtonDown(const Events::GamepadButtonDown &event);
EventRelay<Events::GamepadButtonUp> m_EGamepadButtonUp; EventRelay<InputSystem, Events::GamepadButtonUp> m_EGamepadButtonUp;
bool OnGamepadButtonUp(const Events::GamepadButtonUp &event); bool OnGamepadButtonUp(const Events::GamepadButtonUp &event);
// Input binding events // Input binding events
EventRelay<Events::BindKey> m_EBindKey; EventRelay<InputSystem, Events::BindKey> m_EBindKey;
bool OnBindKey(const Events::BindKey &event); bool OnBindKey(const Events::BindKey &event);
EventRelay<Events::BindMouseButton> m_EBindMouseButton; EventRelay<InputSystem, Events::BindMouseButton> m_EBindMouseButton;
bool OnBindMouseButton(const Events::BindMouseButton &event); bool OnBindMouseButton(const Events::BindMouseButton &event);
EventRelay<Events::BindGamepadAxis> m_EBindGamepadAxis; EventRelay<InputSystem, Events::BindGamepadAxis> m_EBindGamepadAxis;
bool OnBindGamepadAxis(const Events::BindGamepadAxis &event); bool OnBindGamepadAxis(const Events::BindGamepadAxis &event);
EventRelay<Events::BindGamepadButton> m_EBindGamepadButton; EventRelay<InputSystem, Events::BindGamepadButton> m_EBindGamepadButton;
bool OnBindGamepadButton(const Events::BindGamepadButton &event); bool OnBindGamepadButton(const Events::BindGamepadButton &event);
float GetCommandTotalValue(std::string command); float GetCommandTotalValue(std::string command);
+53 -64
View File
@@ -27,11 +27,15 @@
void Systems::PhysicsSystem::Initialize() void Systems::PhysicsSystem::Initialize()
{ {
m_Accumulator = 0; m_Accumulator = 0;
// Events // Events
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer); EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer);
EVENT_SUBSCRIBE_MEMBER(m_ESetVelocity, &Systems::PhysicsSystem::OnSetVelocity); EVENT_SUBSCRIBE_MEMBER(m_ESetVelocity, &Systems::PhysicsSystem::OnSetVelocity);
EVENT_SUBSCRIBE_MEMBER(m_EApplyForce, &Systems::PhysicsSystem::OnApplyForce);
EVENT_SUBSCRIBE_MEMBER(m_EApplyPointImpulse, &Systems::PhysicsSystem::OnApplyPointImpulse);
hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo); hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
@@ -71,7 +75,7 @@ void Systems::PhysicsSystem::Initialize()
worldInfo.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM); worldInfo.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM);
worldInfo.m_gravity = hkVector4(0.0f, -9.82f, 0.0f); worldInfo.m_gravity = hkVector4(0.0f, -9.82f, 0.0f);
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY; // just fix the entity if the object falls off too far worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_DO_NOTHING;
// You must specify the size of the broad phase - objects should not be simulated outside this region // You must specify the size of the broad phase - objects should not be simulated outside this region
worldInfo.setBroadPhaseWorldSize(1000.0f); worldInfo.setBroadPhaseWorldSize(1000.0f);
@@ -102,6 +106,8 @@ void Systems::PhysicsSystem::Initialize()
SetupVisualDebugger(m_Context); SetupVisualDebugger(m_Context);
m_PhysicsWorld->unmarkForWrite(); m_PhysicsWorld->unmarkForWrite();
m_collisionResolution = new MyCollisionResolution;
} }
} }
@@ -140,13 +146,13 @@ void Systems::PhysicsSystem::Update(double dt)
if (parent) if (parent)
{ {
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity); auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
position = ConvertPosition(absoluteTransform.Position); position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position);
rotation = ConvertRotation(absoluteTransform.Orientation); rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
} }
else else
{ {
position = ConvertPosition(transformComponent->Position); position = GLMVEC3_TO_HKVECTOR4(transformComponent->Position);
rotation = ConvertRotation(transformComponent->Orientation); rotation = GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation);
} }
m_PhysicsWorld->markForWrite(); m_PhysicsWorld->markForWrite();
m_RigidBodies[entity]->setPositionAndRotation(position, rotation); m_RigidBodies[entity]->setPositionAndRotation(position, rotation);
@@ -173,9 +179,6 @@ void Systems::PhysicsSystem::Update(double dt)
hkMonitorStream::getInstance().reset(); hkMonitorStream::getInstance().reset();
m_ThreadPool->clearTimerData(); m_ThreadPool->clearTimerData();
} }
} }
void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
@@ -201,7 +204,7 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
hkQuaternion steeringOrientation = m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_steeringOrientationChassisSpace; hkQuaternion steeringOrientation = m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_steeringOrientationChassisSpace;
hkReal spinAngle = -m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_spinAngle; hkReal spinAngle = -m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_spinAngle;
glm::quat orientation = ConvertRotation(steeringOrientation) * glm::angleAxis<float>(spinAngle, glm::vec3(1, 0, 0)); glm::quat orientation = HKQUATERNION_TO_GLMQUAT(steeringOrientation) * glm::angleAxis<float>(spinAngle, glm::vec3(1, 0, 0));
transformComponent->Orientation = orientation * wheelComponent->OriginalOrientation; transformComponent->Orientation = orientation * wheelComponent->OriginalOrientation;
m_PhysicsWorld->unmarkForWrite(); m_PhysicsWorld->unmarkForWrite();
} }
@@ -210,8 +213,8 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
{ {
auto transformComponentParent = m_World->GetComponent<Components::Transform>(parent); auto transformComponentParent = m_World->GetComponent<Components::Transform>(parent);
transformComponent->Position = ConvertPosition(m_RigidBodies[entity]->getPosition()); transformComponent->Position = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getPosition());
transformComponent->Orientation = ConvertRotation(m_RigidBodies[entity]->getRotation()); transformComponent->Orientation = HKQUATERNION_TO_GLMQUAT(m_RigidBodies[entity]->getRotation());
// TODO: No support for Scale, MIGHT be possible // TODO: No support for Scale, MIGHT be possible
if (transformComponentParent) if (transformComponentParent)
@@ -274,13 +277,9 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
hkpListShape* listShape = new hkpListShape(shapeArray.begin(), shapeArray.getSize(), hkpShapeContainer::REFERENCE_POLICY_INCREMENT); hkpListShape* listShape = new hkpListShape(shapeArray.begin(), shapeArray.getSize(), hkpShapeContainer::REFERENCE_POLICY_INCREMENT);
// Save the listShape for further use // Save the listShape for further use
m_ListShapes[entity] = listShape; m_ListShapes[entity] = listShape;
shape = listShape; //shape = listShape;
hkpBoxShape* box = new hkpBoxShape(listShape->m_aabbHalfExtents, 0.0f);
////////////////////////////////// shape = new hkpBvShape(listShape, box);
//******************************//
// Add a hkpBvShape //
//******************************//
//////////////////////////////////
// Clean up for less memory usage // Clean up for less memory usage
m_Shapes.erase(entity); m_Shapes.erase(entity);
@@ -293,8 +292,8 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
rigidBodyInfo.m_shape = shape; rigidBodyInfo.m_shape = shape;
rigidBodyInfo.m_motionType = hkpMotion::MOTION_DYNAMIC; rigidBodyInfo.m_motionType = hkpMotion::MOTION_DYNAMIC;
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity); auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
hkVector4 position = ConvertPosition(absoluteTransform.Position); hkVector4 position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position);
hkQuaternion rotation = ConvertRotation(absoluteTransform.Orientation); hkQuaternion rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3)); rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3));
rigidBodyInfo.m_rotation.set(rotation(0), rotation(1), rotation(2), rotation(3)); rigidBodyInfo.m_rotation.set(rotation(0), rotation(1), rotation(2), rotation(3));
@@ -324,9 +323,11 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
m_PhysicsWorld->markForWrite(); m_PhysicsWorld->markForWrite();
vehicleSetup.buildVehicle(m_World, m_PhysicsWorld, *m_Vehicles[entity], entity, m_Wheels); vehicleSetup.buildVehicle(m_World, m_PhysicsWorld, *m_Vehicles[entity], entity, m_Wheels);
// Add the vehicle's entities and phantoms to the world // Add the vehicle's entities and phantoms to the world
rigidBody->addContactListener( m_collisionResolution );
m_Vehicles[entity]->addToWorld(m_PhysicsWorld); m_Vehicles[entity]->addToWorld(m_PhysicsWorld);
m_RigidBodies[entity] = rigidBody; m_RigidBodies[entity] = rigidBody;
m_collisionResolution->m_RigidBodies[rigidBody] = entity;
// The vehicle is an action // The vehicle is an action
m_PhysicsWorld->addAction(m_Vehicles[entity]); m_PhysicsWorld->addAction(m_Vehicles[entity]);
@@ -340,8 +341,10 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
else else
{ {
m_PhysicsWorld->markForWrite(); m_PhysicsWorld->markForWrite();
rigidBody->addContactListener( m_collisionResolution );
m_PhysicsWorld->addEntity(rigidBody); m_PhysicsWorld->addEntity(rigidBody);
m_RigidBodies[entity] = rigidBody; m_RigidBodies[entity] = rigidBody;
m_collisionResolution->m_RigidBodies[rigidBody] = entity;
m_PhysicsWorld->unmarkForWrite(); m_PhysicsWorld->unmarkForWrite();
shape->removeReference(); shape->removeReference();
@@ -359,9 +362,9 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
auto childTransformComponent = m_World->GetComponent<Components::Transform>(shapeData.Entity); auto childTransformComponent = m_World->GetComponent<Components::Transform>(shapeData.Entity);
hkVector4 position = ConvertPosition(childTransformComponent->Position); hkVector4 position = GLMVEC3_TO_HKVECTOR4(childTransformComponent->Position);
hkQuaternion rotation = ConvertRotation(childTransformComponent->Orientation); hkQuaternion rotation = GLMQUAT_TO_HKQUATERNION(childTransformComponent->Orientation);
hkVector4 scale = ConvertScale(childTransformComponent->Scale); hkVector4 scale = GLMVEC3_TO_HKVECTOR4(childTransformComponent->Scale);
hkQsTransform transform(position, rotation, scale); hkQsTransform transform(position, rotation, scale);
staticCompoundShape->addInstance(shapeData.Shape, transform); staticCompoundShape->addInstance(shapeData.Shape, transform);
@@ -379,8 +382,8 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
rigidBodyInfo.m_shape = shape; rigidBodyInfo.m_shape = shape;
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED; rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity); auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
hkVector4 position = ConvertPosition(absoluteTransform.Position); hkVector4 position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position);
hkQuaternion rotation = ConvertRotation(absoluteTransform.Orientation); hkQuaternion rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3)); rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3));
rigidBodyInfo.m_rotation.set(rotation(0), rotation(1), rotation(2), rotation(3)); rigidBodyInfo.m_rotation.set(rotation(0), rotation(1), rotation(2), rotation(3));
@@ -394,6 +397,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
m_PhysicsWorld->markForWrite(); m_PhysicsWorld->markForWrite();
m_PhysicsWorld->addEntity(rigidBody); m_PhysicsWorld->addEntity(rigidBody);
m_RigidBodies[entity] = rigidBody; m_RigidBodies[entity] = rigidBody;
m_collisionResolution->m_RigidBodies[rigidBody] = entity;
m_PhysicsWorld->unmarkForWrite(); m_PhysicsWorld->unmarkForWrite();
shape->removeReference(); shape->removeReference();
@@ -411,7 +415,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
{ {
hkpSphereShape* sphereShape = new hkpSphereShape(sphereComponent->Radius); hkpSphereShape* sphereShape = new hkpSphereShape(sphereComponent->Radius);
hkQsTransform transform( ConvertPosition(transformComponent->Position), ConvertRotation(transformComponent->Orientation), ConvertScale(transformComponent->Scale)); hkQsTransform transform( GLMVEC3_TO_HKVECTOR4(transformComponent->Position), GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation), GLMVEC3_TO_HKVECTOR4(transformComponent->Scale));
hkpConvexTransformShape* transformedSphereShape = new hkpConvexTransformShape( sphereShape, transform ); hkpConvexTransformShape* transformedSphereShape = new hkpConvexTransformShape( sphereShape, transform );
m_Shapes[entityParent].push_back(ShapeArrayData(entity, transformedSphereShape)); m_Shapes[entityParent].push_back(ShapeArrayData(entity, transformedSphereShape));
@@ -424,7 +428,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
hkReal thickness = 0.05; hkReal thickness = 0.05;
hkpBoxShape* boxShape = new hkpBoxShape(hkVector4(boxComponent->Width- thickness, boxComponent->Height -thickness, boxComponent->Depth - thickness), thickness); hkpBoxShape* boxShape = new hkpBoxShape(hkVector4(boxComponent->Width- thickness, boxComponent->Height -thickness, boxComponent->Depth - thickness), thickness);
hkQsTransform transform( ConvertPosition(transformComponent->Position), ConvertRotation(transformComponent->Orientation), ConvertScale(transformComponent->Scale)); hkQsTransform transform( GLMVEC3_TO_HKVECTOR4(transformComponent->Position), GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation), GLMVEC3_TO_HKVECTOR4(transformComponent->Scale));
hkpConvexTransformShape* transformedBoxShape = new hkpConvexTransformShape( boxShape, transform ); hkpConvexTransformShape* transformedBoxShape = new hkpConvexTransformShape( boxShape, transform );
m_Shapes[entityParent].push_back(ShapeArrayData(entity, transformedBoxShape)); m_Shapes[entityParent].push_back(ShapeArrayData(entity, transformedBoxShape));
boxShape->removeReference(); boxShape->removeReference();
@@ -532,50 +536,19 @@ void HK_CALL Systems::PhysicsSystem::HavokErrorReport(const char* msg, void*)
LOG_INFO("%s", msg); LOG_INFO("%s", msg);
} }
glm::vec3 Systems::PhysicsSystem::ConvertPosition(const hkVector4 &hkPosition)
{
return glm::vec3(hkPosition(0), hkPosition(1), hkPosition(2));
}
const hkVector4& Systems::PhysicsSystem::ConvertPosition(glm::vec3 glmPosition)
{
return hkVector4( glmPosition.x, glmPosition.y, glmPosition.z);
}
glm::quat Systems::PhysicsSystem::ConvertRotation(const hkQuaternion &hkRotation)
{
return glm::quat(hkRotation(3), hkRotation(0), hkRotation(1), hkRotation(2));
}
const hkQuaternion& Systems::PhysicsSystem::ConvertRotation(glm::quat glmRotation)
{
hkQuaternion quat = hkQuaternion(glmRotation.x, glmRotation.y, glmRotation.z, glmRotation.w);
quat.normalize();
return quat;
}
glm::vec3 Systems::PhysicsSystem::ConvertScale(const hkVector4 &hkScale)
{
return glm::vec3(hkScale(0), hkScale(1), hkScale(2));
}
const hkVector4& Systems::PhysicsSystem::ConvertScale(glm::vec3 glmScale)
{
return hkVector4(glmScale.x, glmScale.y, glmScale.z);
}
bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event) bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
{ {
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity); 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()) if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
{ {
m_PhysicsWorld->markForWrite();
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus; hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus;
deviceStatus->m_positionX = event.PositionX; deviceStatus->m_positionX = event.PositionX;
deviceStatus->m_positionY = event.PositionY; deviceStatus->m_positionY = event.PositionY;
if(event.PositionY > 0)
{
deviceStatus->m_reverseButtonPressed = true;
}
deviceStatus->m_handbrakeButtonPressed = event.Handbrake; deviceStatus->m_handbrakeButtonPressed = event.Handbrake;
m_PhysicsWorld->unmarkForWrite();
} }
return true; return true;
@@ -584,7 +557,23 @@ bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event ) bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event )
{ {
m_PhysicsWorld->markForWrite(); m_PhysicsWorld->markForWrite();
m_RigidBodies[event.Entity]->setLinearVelocity(ConvertPosition(event.Velocity)); m_RigidBodies[event.Entity]->setLinearVelocity(GLMVEC3_TO_HKVECTOR4(event.Velocity));
m_PhysicsWorld->unmarkForWrite();
return true;
}
bool Systems::PhysicsSystem::OnApplyForce(const Events::ApplyForce &event)
{
m_PhysicsWorld->markForWrite();
m_RigidBodies[event.Entity]->applyForce(event.DeltaTime, GLMVEC3_TO_HKVECTOR4(event.Force));
m_PhysicsWorld->unmarkForWrite();
return true;
}
bool Systems::PhysicsSystem::OnApplyPointImpulse( const Events::ApplyPointImpulse &event )
{
m_PhysicsWorld->markForWrite();
m_RigidBodies[event.Entity]->applyPointImpulse(GLMVEC3_TO_HKVECTOR4(event.Impulse), GLMVEC3_TO_HKVECTOR4(event.Position));
m_PhysicsWorld->unmarkForWrite(); m_PhysicsWorld->unmarkForWrite();
return true; return true;
} }
+39 -15
View File
@@ -1,6 +1,16 @@
#ifndef PhysicsSystem_h__ #ifndef PhysicsSystem_h__
#define PhysicsSystem_h__ #define PhysicsSystem_h__
#define HKVECTOR4_TO_GLMVEC3(hkvec) \
glm::vec3(hkvec(0), hkvec(1), hkvec(2))
#define GLMVEC3_TO_HKVECTOR4(glmvec) \
hkVector4(glmvec.x, glmvec.y, glmvec.z)
#define HKQUATERNION_TO_GLMQUAT(gkquat) \
glm::quat(gkquat(3), gkquat(0), gkquat(1), gkquat(2))
#define GLMQUAT_TO_HKQUATERNION(glmquat) \
hkQuaternion(glmquat.x, glmquat.y, glmquat.z, glmquat.w)
#include "System.h" #include "System.h"
#include "Systems/TransformSystem.h" #include "Systems/TransformSystem.h"
#include "Components/Transform.h" #include "Components/Transform.h"
@@ -15,6 +25,8 @@
#include "Components/TowerSteering.h" #include "Components/TowerSteering.h"
#include "Events/TankSteer.h" #include "Events/TankSteer.h"
#include "Events/SetVelocity.h" #include "Events/SetVelocity.h"
#include "Events/ApplyForce.h"
#include "Events/ApplyPointImpulse.h"
#include "OBJ.h" #include "OBJ.h"
// Math and base include // Math and base include
@@ -60,9 +72,27 @@
#include "Physics/VehicleSetup.h" #include "Physics/VehicleSetup.h"
#include <unordered_map> #include <unordered_map>
#include <Physics2012/Dynamics/Collide/ContactListener/hkpContactListener.h>
class MyCollisionResolution: public hkReferencedObject, public hkpContactListener
{
public:
std::unordered_map<hkpRigidBody*, EntityID> m_RigidBodies;
virtual void contactPointCallback( const hkpContactPointEvent& event )
{
EntityID entity1 = m_RigidBodies[event.getBody(0)];
EntityID entity2 = m_RigidBodies[event.getBody(1)];
//LOG_INFO("Entities colliding: %i, %i ", entity1, entity2);
}
};
namespace Systems namespace Systems
{ {
class PhysicsSystem : public System class PhysicsSystem : public System
{ {
public: public:
@@ -83,11 +113,14 @@ private:
hkpWorld* m_PhysicsWorld; hkpWorld* m_PhysicsWorld;
// Events // Events
EventRelay<Events::TankSteer> m_ETankSteer; EventRelay<PhysicsSystem, Events::TankSteer> m_ETankSteer;
bool OnTankSteer(const Events::TankSteer &event); bool OnTankSteer(const Events::TankSteer &event);
EventRelay<PhysicsSystem, Events::SetVelocity> m_ESetVelocity;
EventRelay<Events::SetVelocity> m_ESetVelocity;
bool OnSetVelocity(const Events::SetVelocity &event); bool OnSetVelocity(const Events::SetVelocity &event);
EventRelay<PhysicsSystem, Events::ApplyForce> m_EApplyForce;
bool OnApplyForce(const Events::ApplyForce &event);
EventRelay<PhysicsSystem, Events::ApplyPointImpulse> m_EApplyPointImpulse;
bool OnApplyPointImpulse(const Events::ApplyPointImpulse &event);
void SetUpPhysicsState(EntityID entity, EntityID parent); void SetUpPhysicsState(EntityID entity, EntityID parent);
void TearDownPhysicsState(EntityID entity, EntityID parent); void TearDownPhysicsState(EntityID entity, EntityID parent);
@@ -98,16 +131,6 @@ private:
static void HK_CALL HavokErrorReport(const char* msg, void*); static void HK_CALL HavokErrorReport(const char* msg, void*);
void SetupPhysics(hkpWorld* physicsWorld); void SetupPhysics(hkpWorld* physicsWorld);
// Converterfunctions
glm::vec3 ConvertPosition(const hkVector4 &hkPosition);
const hkVector4& ConvertPosition(glm::vec3 glmPosition);
glm::quat ConvertRotation(const hkQuaternion &hkRotation);
const hkQuaternion& ConvertRotation(glm::quat glmRotation);
glm::vec3 ConvertScale(const hkVector4 &hkScale);
const hkVector4&ConvertScale(glm::vec3 glmScale);
std::unordered_map<EntityID, hkpRigidBody*> m_RigidBodies; std::unordered_map<EntityID, hkpRigidBody*> m_RigidBodies;
hkJobThreadPool* m_ThreadPool; hkJobThreadPool* m_ThreadPool;
@@ -145,8 +168,9 @@ private:
hkpMoppBvTreeShape* MoppShape; hkpMoppBvTreeShape* MoppShape;
}; };
std::unordered_map<EntityID, ExtendedShapeData > m_ExtendedMeshShapes; std::unordered_map<EntityID, ExtendedShapeData > m_ExtendedMeshShapes;
MyCollisionResolution* m_collisionResolution;
}; };
} }
#endif // PhysicsSystem_h__ #endif // PhysicsSystem_h__
+25
View File
@@ -0,0 +1,25 @@
#include "PrecompiledHeader.h"
#include "RaySystem.h"
#include "World.h"
void Systems::RaySystem::Initialize()
{
// Subscribe to events
EVENT_SUBSCRIBE_MEMBER(m_ECastRay, &Systems::RaySystem::OnCastRay);
}
void Systems::RaySystem::Update(double dt)
{
}
void Systems::RaySystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
}
bool Systems::RaySystem::OnCastRay(const Events::CastRay &event)
{
Ray r;
return true;
}
+35
View File
@@ -0,0 +1,35 @@
#ifndef DebugSystem_h__
#define DebugSystem_h__
#include "System.h"
#include "Events/CastRay.h"
namespace Systems
{
class RaySystem : public System
{
public:
RaySystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
: System(world, eventBroker) { }
void Initialize() override;
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
private:
struct Ray
{
glm::vec3 Direction;
};
EventRelay<Events::CastRay> m_ECastRay;
bool OnCastRay(const Events::CastRay &event);
std::list<Ray> m_UnresolvedRays;
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
};
}
#endif // DebugSystem_h__
+57 -35
View File
@@ -2,26 +2,59 @@
#include "RenderSystem.h" #include "RenderSystem.h"
#include "World.h" #include "World.h"
void Systems::RenderSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> component) void Systems::RenderSystem::RegisterResourceTypes(ResourceManager* rm)
{ {
if(type == "Model") rm->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load<OBJ>("OBJ", resourceName)); });
rm->RegisterType("OBJ", [](std::string resourceName) { return new OBJ(resourceName); });
rm->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); });
}
void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
{
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(); });
cf->Register<Components::Viewport>([]() { return new Components::Viewport(); });
}
void Systems::RenderSystem::OnEntityCommit(EntityID entity)
{
auto transform = m_World->GetComponent<Components::Transform>(entity);
auto camera = m_World->GetComponent<Components::Camera>(entity);
if (transform && camera)
{ {
auto modelComponent = std::static_pointer_cast<Components::Model>(component); m_Renderer->RegisterCamera(entity, camera->FOV, camera->NearClip, camera->FarClip);
m_Renderer->UpdateCamera(entity, m_TransformSystem->AbsolutePosition(entity), m_TransformSystem->AbsoluteOrientation(entity), camera->FOV, camera->NearClip, camera->FarClip);
}
auto viewport = m_World->GetComponent<Components::Viewport>(entity);
if (viewport)
{
m_Renderer->RegisterViewport(entity, viewport->Left, viewport->Top, viewport->Right, viewport->Bottom);
if (viewport->Camera != 0)
{
m_Renderer->UpdateViewport(entity, viewport->Camera);
}
} }
} }
void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{ {
auto transformComponent = m_World->GetComponent<Components::Transform>(entity); auto templateComponent = m_World->GetComponent<Components::Template>(entity);
if (transformComponent == nullptr) if (templateComponent)
return; return;
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
// Draw models // Draw models
auto modelComponent = m_World->GetComponent<Components::Model>(entity); auto modelComponent = m_World->GetComponent<Components::Model>(entity);
if (modelComponent != nullptr) if (transformComponent && modelComponent)
{ {
auto model = m_World->GetResourceManager()->Load<Model>("Model", modelComponent->ModelFile); auto model = m_World->GetResourceManager()->Load<Model>("Model", modelComponent->ModelFile);
if (model != nullptr) if (model)
{ {
/*glm::vec3 position = m_TransformSystem->AbsolutePosition(entity); /*glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity); glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity);
@@ -32,7 +65,7 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
} }
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity); auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
if (pointLightComponent != nullptr) if (transformComponent && pointLightComponent)
{ {
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity); glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
m_Renderer->AddPointLightToDraw( m_Renderer->AddPointLightToDraw(
@@ -47,18 +80,27 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
} }
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity); auto cameraComponent = m_World->GetComponent<Components::Camera>(entity);
if (cameraComponent != nullptr) if (transformComponent && cameraComponent)
{ {
m_Renderer->GetCamera()->Position(m_TransformSystem->AbsolutePosition(entity)); m_Renderer->UpdateCamera(entity
m_Renderer->GetCamera()->Orientation(m_TransformSystem->AbsoluteOrientation(entity)); , m_TransformSystem->AbsolutePosition(entity)
, m_TransformSystem->AbsoluteOrientation(entity)
, cameraComponent->FOV
, cameraComponent->NearClip
, cameraComponent->FarClip);
}
m_Renderer->GetCamera()->FOV(cameraComponent->FOV); auto viewportComponent = m_World->GetComponent<Components::Viewport>(entity);
m_Renderer->GetCamera()->NearClip(cameraComponent->NearClip); if (viewportComponent)
m_Renderer->GetCamera()->FarClip(cameraComponent->FarClip); {
if (viewportComponent->Camera != 0)
{
m_Renderer->UpdateViewport(entity, viewportComponent->Camera);
}
} }
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity); auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
if(spriteComponent != nullptr) if (transformComponent && spriteComponent)
{ {
//TEMP //TEMP
Texture* texture = m_World->GetResourceManager()->Load<Texture>("Texture", spriteComponent->SpriteFile); Texture* texture = m_World->GetResourceManager()->Load<Texture>("Texture", spriteComponent->SpriteFile);
@@ -76,23 +118,3 @@ void Systems::RenderSystem::Initialize()
m_Renderer->SetSphereModel(m_World->GetResourceManager()->Load<Model>("Model", "Models/Placeholders/PhysicsTest/Sphere.obj")); m_Renderer->SetSphereModel(m_World->GetResourceManager()->Load<Model>("Model", "Models/Placeholders/PhysicsTest/Sphere.obj"));
} }
void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
{
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)
{
rm->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load<OBJ>("OBJ", resourceName)); });
rm->RegisterType("OBJ", [](std::string resourceName) { return new OBJ(resourceName); });
rm->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); });
}
+2 -1
View File
@@ -13,6 +13,7 @@
#include "Components/Sprite.h" #include "Components/Sprite.h"
#include "Components/PointLight.h" #include "Components/PointLight.h"
#include "Components/DirectionalLight.h" #include "Components/DirectionalLight.h"
#include "Components/Viewport.h"
#include "Components/Template.h" #include "Components/Template.h"
#include "Components/Transform.h" #include "Components/Transform.h"
@@ -34,7 +35,7 @@ public:
std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels; std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels;
void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) override; void OnEntityCommit(EntityID entity) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override; void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
+1 -1
View File
@@ -32,7 +32,7 @@ public:
private: private:
// Events // Events
EventRelay<Events::PlaySound> m_EPlaySound; EventRelay<SoundSystem, Events::PlaySound> m_EPlaySound;
FMOD_RESULT LoadSound(FMOD_SOUND*&, std::string, float, float, bool, float, float); FMOD_RESULT LoadSound(FMOD_SOUND*&, std::string, float, float, bool, float, float);
void PlaySound(FMOD_CHANNEL*, FMOD_SOUND*, float volume, bool loop); void PlaySound(FMOD_CHANNEL*, FMOD_SOUND*, float volume, bool loop);
+60 -47
View File
@@ -11,60 +11,85 @@ void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf )
void Systems::TankSteeringSystem::Initialize() void Systems::TankSteeringSystem::Initialize()
{ {
m_TankInputController = std::unique_ptr<TankSteeringInputController>(new TankSteeringInputController(EventBroker)); for (int i = 0; i < 4; i++)
m_TowerInputController = std::unique_ptr<TowerSteeringInputController>(new TowerSteeringInputController(EventBroker)); {
m_TankInputControllers[i] = std::shared_ptr<TankSteeringInputController>(new TankSteeringInputController(EventBroker, i + 1));
}
} }
void Systems::TankSteeringSystem::Update(double dt) void Systems::TankSteeringSystem::Update(double dt)
{ {
m_TankInputController->Update(dt); for (int i = 0; i < 4; i++)
m_TowerInputController->Update(dt); {
m_TankInputControllers[i]->Update(dt);
}
} }
void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{ {
auto tankSteeringComponent = m_World->GetComponent<Components::TankSteering>(entity); auto tankSteeringComponent = m_World->GetComponent<Components::TankSteering>(entity);
if(tankSteeringComponent) if(!tankSteeringComponent)
{ return;
Events::TankSteer e;
e.Entity = entity; auto playerComponent = m_World->GetComponent<Components::Player>(tankSteeringComponent->Player);
e.PositionX = m_TankInputController->PositionX; if (!playerComponent)
e.PositionY = m_TankInputController->PositionY; return;
e.Handbrake = m_TankInputController->Handbrake;
EventBroker->Publish(e); if (playerComponent->ID == 0)
} return;
auto inputController = m_TankInputControllers[playerComponent->ID - 1];
Events::TankSteer eSteering;
eSteering.Entity = entity;
eSteering.PositionX = inputController->PositionX;
eSteering.PositionY = inputController->PositionY;
eSteering.Handbrake = inputController->Handbrake;
EventBroker->Publish(eSteering);
auto towerSteeringComponent = m_World->GetComponent<Components::TowerSteering>(tankSteeringComponent->Turret);
auto barrelSteeringComponent = m_World->GetComponent<Components::BarrelSteering>(tankSteeringComponent->Barrel);
auto towerSteeringComponent = m_World->GetComponent<Components::TowerSteering>(entity);
if(towerSteeringComponent) if(towerSteeringComponent)
{ {
auto transformComponent = m_World->GetComponent<Components::Transform>(entity); auto transformComponent = m_World->GetComponent<Components::Transform>(tankSteeringComponent->Turret);
glm::quat orientation = glm::angleAxis(towerSteeringComponent->TurnSpeed * m_TowerInputController->TowerDirection * (float)dt, towerSteeringComponent->Axis); glm::quat orientation = glm::angleAxis(towerSteeringComponent->TurnSpeed * inputController->TowerDirection * (float)dt, towerSteeringComponent->Axis);
transformComponent->Orientation *= orientation; transformComponent->Orientation *= orientation;
} }
auto barrelSteeringComponent = m_World->GetComponent<Components::BarrelSteering>(entity);
if(barrelSteeringComponent) if(barrelSteeringComponent)
{ {
auto transformComponent = m_World->GetComponent<Components::Transform>(entity); auto transformComponent = m_World->GetComponent<Components::Transform>(tankSteeringComponent->Barrel);
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity); auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(tankSteeringComponent->Barrel);
glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * m_TowerInputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis); glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * inputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis);
transformComponent->Orientation *= orientation; transformComponent->Orientation *= orientation;
if(m_TowerInputController->Shoot && m_TimeSinceLastShot[entity] > 1.0) if(inputController->Shoot && m_TimeSinceLastShot[tankSteeringComponent->Barrel] > 0.5)
{ {
EntityID clone = m_World->CloneEntity(barrelSteeringComponent->ShotTemplate); EntityID clone = m_World->CloneEntity(barrelSteeringComponent->ShotTemplate);
auto templateAbsoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(barrelSteeringComponent->ShotTemplate); auto templateAbsoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(barrelSteeringComponent->ShotTemplate);
auto cloneTransform = m_World->GetComponent<Components::Transform>(clone); auto cloneTransform = m_World->GetComponent<Components::Transform>(clone);
cloneTransform->Position = templateAbsoluteTransform.Position; cloneTransform->Position = templateAbsoluteTransform.Position;
cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation; cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation;
Events::SetVelocity e; Events::SetVelocity eSetVelocity;
e.Entity = clone; eSetVelocity.Entity = clone;
e.Velocity = absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed); eSetVelocity.Velocity = absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
EventBroker->Publish(e); EventBroker->Publish(eSetVelocity);
m_TimeSinceLastShot[entity] = 0; m_TimeSinceLastShot[tankSteeringComponent->Barrel] = 0;
auto clonePhysicsComponent = m_World->GetComponent<Components::Physics>(clone);
//1,670m/s
//25kg
Events::ApplyPointImpulse ePointImpulse ;
ePointImpulse.Entity = entity;
ePointImpulse.Position = absoluteTransform.Position;
ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 1670.f;
EventBroker->Publish(ePointImpulse);
} }
m_TimeSinceLastShot[entity] += dt; m_TimeSinceLastShot[tankSteeringComponent->Barrel] += dt;
} }
} }
@@ -72,10 +97,7 @@ void Systems::TankSteeringSystem::TankSteeringInputController::Update( double dt
{ {
PositionX = m_Horizontal; PositionX = m_Horizontal;
PositionY = m_Vertical; PositionY = m_Vertical;
}
void Systems::TankSteeringSystem::TowerSteeringInputController::Update( double dt )
{
TowerDirection = m_TowerDirection; TowerDirection = m_TowerDirection;
BarrelDirection = m_BarrelDirection; BarrelDirection = m_BarrelDirection;
Shoot = m_Shoot; Shoot = m_Shoot;
@@ -83,10 +105,16 @@ void Systems::TankSteeringSystem::TowerSteeringInputController::Update( double d
bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const Events::InputCommand &event) bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const Events::InputCommand &event)
{ {
if (event.PlayerID != this->PlayerID)
return false;
float val = event.Value; float val = event.Value;
// Tank
if (event.Command == "horizontal") if (event.Command == "horizontal")
{ {
m_Horizontal = val; m_Horizontal = val;
m_Vertical = -0.4f;
} }
else if (event.Command == "vertical") else if (event.Command == "vertical")
{ {
@@ -98,12 +126,7 @@ bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const E
Handbrake = val > 0; Handbrake = val > 0;
} }
return true; // Turret
}
bool Systems::TankSteeringSystem::TowerSteeringInputController::OnCommand( const Events::InputCommand &event )
{
float val = event.Value;
if(event.Command == "tower_rotation") if(event.Command == "tower_rotation")
{ {
m_TowerDirection = -val; m_TowerDirection = -val;
@@ -117,19 +140,9 @@ bool Systems::TankSteeringSystem::TowerSteeringInputController::OnCommand( const
{ {
m_Shoot = val > 0; m_Shoot = val > 0;
} }
return true; return true;
} }
bool Systems::TankSteeringSystem::TowerSteeringInputController::OnMouseMove( const Events::MouseMove &event )
{
return false;
}
bool Systems::TankSteeringSystem::TankSteeringInputController::OnMouseMove( const Events::MouseMove &event )
{
return false;
}
+21 -27
View File
@@ -3,11 +3,15 @@
#include "System.h" #include "System.h"
#include "Events/TankSteer.h" #include "Events/TankSteer.h"
#include "Events/SetVelocity.h" #include "Events/SetVelocity.h"
#include "Events/ApplyForce.h"
#include "Events/ApplyPointImpulse.h"
#include "Components/Transform.h" #include "Components/Transform.h"
#include "Components/TankSteering.h" #include "Components/TankSteering.h"
#include "Components/TowerSteering.h" #include "Components/TowerSteering.h"
#include "Components/BarrelSteering.h" #include "Components/BarrelSteering.h"
#include "Components/Physics.h"
#include "Components/Vehicle.h" #include "Components/Vehicle.h"
#include "Components/Player.h"
#include "Systems/TransformSystem.h" #include "Systems/TransformSystem.h"
#include "InputController.h" #include "InputController.h"
@@ -28,45 +32,25 @@ namespace Systems
private: private:
class TankSteeringInputController; class TankSteeringInputController;
std::unique_ptr<TankSteeringInputController> m_TankInputController; std::array<std::shared_ptr<TankSteeringInputController>, 4> m_TankInputControllers;
class TowerSteeringInputController;
std::unique_ptr<TowerSteeringInputController> m_TowerInputController;
std::map<EntityID, double> m_TimeSinceLastShot; std::map<EntityID, double> m_TimeSinceLastShot;
}; };
class TankSteeringSystem::TankSteeringInputController : InputController class TankSteeringSystem::TankSteeringInputController : InputController<TankSteeringSystem>
{ {
public: public:
TankSteeringInputController(std::shared_ptr<::EventBroker> eventBroker) TankSteeringInputController(std::shared_ptr<::EventBroker> eventBroker, int playerID)
: InputController(eventBroker) : InputController(eventBroker)
{ {
PlayerID = playerID;
m_Horizontal = 0.f; m_Horizontal = 0.f;
m_Vertical = 0.f; m_Vertical = 0.f;
PositionX = 0; PositionX = 0;
PositionY = 0; PositionY = 0;
Handbrake = false; Handbrake = false;
}
float PositionY;
float PositionX;
bool Handbrake;
void Update(double dt);
protected:
virtual bool OnCommand(const Events::InputCommand &event);
virtual bool OnMouseMove(const Events::MouseMove &event);
private:
float m_Horizontal;
float m_Vertical;
};
class TankSteeringSystem::TowerSteeringInputController : InputController
{
public:
TowerSteeringInputController(std::shared_ptr<::EventBroker> eventBroker)
: InputController(eventBroker)
{
m_TowerDirection = 0.f; m_TowerDirection = 0.f;
m_BarrelDirection = 0.f; m_BarrelDirection = 0.f;
TowerDirection = 0.f; TowerDirection = 0.f;
@@ -75,18 +59,28 @@ namespace Systems
m_Shoot = false; m_Shoot = false;
} }
int PlayerID;
float PositionY;
float PositionX;
bool Handbrake;
float TowerDirection; float TowerDirection;
float BarrelDirection; float BarrelDirection;
bool Shoot; bool Shoot;
void Update(double dt); void Update(double dt);
protected: protected:
virtual bool OnCommand(const Events::InputCommand &event); virtual bool OnCommand(const Events::InputCommand &event);
virtual bool OnMouseMove(const Events::MouseMove &event); //virtual bool OnMouseMove(const Events::MouseMove &event);
private: private:
float m_Horizontal;
float m_Vertical;
float m_TowerDirection; float m_TowerDirection;
float m_BarrelDirection; float m_BarrelDirection;
bool m_Shoot; bool m_Shoot;
}; };
} }
+1
View File
@@ -24,4 +24,5 @@ private:
std::unordered_map<std::string, GLuint> m_TextureCache; std::unordered_map<std::string, GLuint> m_TextureCache;
}; };
#endif // Texture_h__ #endif // Texture_h__
+88 -88
View File
@@ -3,93 +3,93 @@
#include <algorithm> #include <algorithm>
//struct Rectangle struct Rectangle
//{ {
// Rectangle() Rectangle()
// : X(0), Y(0), Width(0), Height(0) { } : X(0), Y(0), Width(0), Height(0) { }
//
// Rectangle(int x, int y, int width = 0, int height = 0) Rectangle(int x, int y, int width = 0, int height = 0)
// : X(x), Y(y), Width(width), Height(height) { } : X(x), Y(y), Width(width), Height(height) { }
//
// /*Rectangle(const Rectangle &rect) /*Rectangle(const Rectangle &rect)
// : X(rect.X), Y(rect.Y), Width(rect.Width), Height(rect.Height) { }*/ : X(rect.X), Y(rect.Y), Width(rect.Width), Height(rect.Height) { }*/
//
// int X; int X;
// int Y; int Y;
// int Width; int Width;
// int Height; int Height;
//
// const int& GetLeft() const { return X; } const int& GetLeft() const { return X; }
// void SetLeft(int left) void SetLeft(int left)
// { {
// Width += X - left; Width += X - left;
// X = left; X = left;
// } }
// int GetRight() const { return X + Width; } int GetRight() const { return X + Width; }
// void SetRight(int right) void SetRight(int right)
// { {
// Width = right - X; Width = right - X;
// } }
// const int& GetTop() const { return Y; } const int& GetTop() const { return Y; }
// void SetTop(int top) void SetTop(int top)
// { {
// Height += Y - top; Height += Y - top;
// Y = top; Y = top;
// } }
// int GetBottom() const { return Y + Height; } int GetBottom() const { return Y + Height; }
// int SetBottom(int bottom) int SetBottom(int bottom)
// { {
// Height = bottom - Y; Height = bottom - Y;
// } }
//
// Rectangle& operator+=(const Rectangle &rhs) Rectangle& operator+=(const Rectangle &rhs)
// { {
// SetLeft(std::min(GetLeft(), rhs.GetLeft())); SetLeft(std::min(GetLeft(), rhs.GetLeft()));
// SetRight(std::max(GetRight(), rhs.GetRight())); SetRight(std::max(GetRight(), rhs.GetRight()));
// SetTop(std::min(GetTop(), rhs.GetTop())); SetTop(std::min(GetTop(), rhs.GetTop()));
// SetBottom(std::max(GetBottom(), rhs.GetBottom())); SetBottom(std::max(GetBottom(), rhs.GetBottom()));
// } }
//
// static bool Intersects(const Rectangle &r1, const Rectangle &r2) static bool Intersects(const Rectangle &r1, const Rectangle &r2)
// { {
// return !(r2.GetLeft() > r1.GetRight() || r2.GetRight() < r1.GetLeft() || r2.GetTop() > r1.GetBottom() || r2.GetBottom() < r1.GetTop()); return !(r2.GetLeft() > r1.GetRight() || r2.GetRight() < r1.GetLeft() || r2.GetTop() > r1.GetBottom() || r2.GetBottom() < r1.GetTop());
// } }
//}; };
//
//inline bool operator==(const Rectangle &r1, const Rectangle &r2) inline bool operator==(const Rectangle &r1, const Rectangle &r2)
//{ {
// return (r1.X == r2.X) && (r1.Y == r2.Y) && (r1.Width == r2.Width) && (r1.Height == r2.Height); return (r1.X == r2.X) && (r1.Y == r2.Y) && (r1.Width == r2.Width) && (r1.Height == r2.Height);
//} }
//
//inline bool operator!=(const Rectangle &lhs, const Rectangle &rhs) inline bool operator!=(const Rectangle &lhs, const Rectangle &rhs)
//{ {
// return !(lhs == rhs); return !(lhs == rhs);
//} }
//
//inline bool operator<(const Rectangle &lhs, const Rectangle &rhs) inline bool operator<(const Rectangle &lhs, const Rectangle &rhs)
//{ {
// return (lhs.Width < rhs.Width) && (lhs.Height < rhs.Height); return (lhs.Width < rhs.Width) && (lhs.Height < rhs.Height);
//} }
//
//inline bool operator>(const Rectangle &lhs, const Rectangle &rhs) inline bool operator>(const Rectangle &lhs, const Rectangle &rhs)
//{ {
// return rhs < lhs; return rhs < lhs;
//} }
//
//inline bool operator<=(const Rectangle &lhs, const Rectangle &rhs) inline bool operator<=(const Rectangle &lhs, const Rectangle &rhs)
//{ {
// return !(lhs > rhs); return !(lhs > rhs);
//} }
//
//inline bool operator>=(const Rectangle &lhs, const Rectangle &rhs) inline bool operator>=(const Rectangle &lhs, const Rectangle &rhs)
//{ {
// return !(lhs < rhs); return !(lhs < rhs);
//} }
//
//inline Rectangle operator+(Rectangle lhs, const Rectangle &rhs) inline Rectangle operator+(Rectangle lhs, const Rectangle &rhs)
//{ {
// lhs += rhs; lhs += rhs;
// return lhs; return lhs;
//} }
#endif // Util_Rectangle_h__ #endif // Util_Rectangle_h__
-28
View File
@@ -1,28 +0,0 @@
#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 */
+2
View File
@@ -36,7 +36,9 @@ void World::Update(double dt)
{ {
for (auto pair : m_Systems) for (auto pair : m_Systems)
{ {
const std::string &type = pair.first;
auto system = pair.second; auto system = pair.second;
m_EventBroker->Process(type);
system->Update(dt); system->Update(dt);
RecursiveUpdate(system, dt, 0); RecursiveUpdate(system, dt, 0);
} }
+44
View File
@@ -0,0 +1,44 @@
#include <boost/any.hpp>
#include "Entity.h"
#include "World.h"
#include "EventBroker.h"
// A slower wrapper class for EntityID to make
// creation of pre-defined entity hierarchies easier
class EntityGroup
{
public:
EntityGroup(World* world, EntityID parent = 0)
: World(world)
, EventBroker(world->EventBroker())
{
m_ID = World->CreateEntity(parent);
Initialize();
World->CommitEntity(m_ID);
}
~EntityGroup()
{
World->RemoveEntity(m_ID);
}
virtual void Initialize() { }
template <class T>
std::shared_ptr<T> AddComponent(std::string componentType)
{
return World->AddComponent<T>(m_ID, componentType);
}
std::shared_ptr<Component> AddComponent(std::string componentType)
{
return World->AddComponent(m_ID, componentType);
}
operator EntityID () const { return m_ID; }
private:
EntityID m_ID;
::World* World;
std::shared_ptr<::EventBroker> EventBroker;
};
+9 -2
View File
@@ -60,7 +60,7 @@
<CompileAsManaged>false</CompileAsManaged> <CompileAsManaged>false</CompileAsManaged>
<BasicRuntimeChecks>Default</BasicRuntimeChecks> <BasicRuntimeChecks>Default</BasicRuntimeChecks>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>MaxSpeed</Optimization> <Optimization>Disabled</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile> </ClCompile>
<Link> <Link>
@@ -111,6 +111,7 @@
<ClCompile Include="..\..\src\Sound.cpp" /> <ClCompile Include="..\..\src\Sound.cpp" />
<ClCompile Include="..\..\src\Systems\DebugSystem.cpp" /> <ClCompile Include="..\..\src\Systems\DebugSystem.cpp" />
<ClCompile Include="..\..\src\Systems\FreeSteeringSystem.cpp" /> <ClCompile Include="..\..\src\Systems\FreeSteeringSystem.cpp" />
<ClCompile Include="..\..\src\Systems\HelicopterSteeringSystem.cpp" />
<ClCompile Include="..\..\src\Systems\InputSystem.cpp" /> <ClCompile Include="..\..\src\Systems\InputSystem.cpp" />
<ClCompile Include="..\..\src\Systems\ParticleSystem.cpp" /> <ClCompile Include="..\..\src\Systems\ParticleSystem.cpp" />
<ClCompile Include="..\..\src\Systems\PhysicsSystem.cpp" /> <ClCompile Include="..\..\src\Systems\PhysicsSystem.cpp" />
@@ -131,6 +132,8 @@
<ClInclude Include="..\..\src\Components\DirectionalLight.h" /> <ClInclude Include="..\..\src\Components\DirectionalLight.h" />
<ClInclude Include="..\..\src\Components\ExtendedMeshShape.h" /> <ClInclude Include="..\..\src\Components\ExtendedMeshShape.h" />
<ClInclude Include="..\..\src\Components\FreeSteering.h" /> <ClInclude Include="..\..\src\Components\FreeSteering.h" />
<ClInclude Include="..\..\src\Components\Health.h" />
<ClInclude Include="..\..\src\Components\HelicopterSteering.h" />
<ClInclude Include="..\..\src\Components\HingeConstraint.h" /> <ClInclude Include="..\..\src\Components\HingeConstraint.h" />
<ClInclude Include="..\..\src\Components\Input.h" /> <ClInclude Include="..\..\src\Components\Input.h" />
<ClInclude Include="..\..\src\Components\Listener.h" /> <ClInclude Include="..\..\src\Components\Listener.h" />
@@ -139,6 +142,7 @@
<ClInclude Include="..\..\src\Components\Particle.h" /> <ClInclude Include="..\..\src\Components\Particle.h" />
<ClInclude Include="..\..\src\Components\ParticleEmitter.h" /> <ClInclude Include="..\..\src\Components\ParticleEmitter.h" />
<ClInclude Include="..\..\src\Components\Physics.h" /> <ClInclude Include="..\..\src\Components\Physics.h" />
<ClInclude Include="..\..\src\Components\Player.h" />
<ClInclude Include="..\..\src\Components\PointLight.h" /> <ClInclude Include="..\..\src\Components\PointLight.h" />
<ClInclude Include="..\..\src\Components\SoundEmitter.h" /> <ClInclude Include="..\..\src\Components\SoundEmitter.h" />
<ClInclude Include="..\..\src\Components\SphereShape.h" /> <ClInclude Include="..\..\src\Components\SphereShape.h" />
@@ -148,11 +152,14 @@
<ClInclude Include="..\..\src\Components\TowerSteering.h" /> <ClInclude Include="..\..\src\Components\TowerSteering.h" />
<ClInclude Include="..\..\src\Components\Transform.h" /> <ClInclude Include="..\..\src\Components\Transform.h" />
<ClInclude Include="..\..\src\Components\Vehicle.h" /> <ClInclude Include="..\..\src\Components\Vehicle.h" />
<ClInclude Include="..\..\src\Components\Viewport.h" />
<ClInclude Include="..\..\src\Components\Wheel.h" /> <ClInclude Include="..\..\src\Components\Wheel.h" />
<ClInclude Include="..\..\src\Components\WheelPair.h" /> <ClInclude Include="..\..\src\Components\WheelPair.h" />
<ClInclude Include="..\..\src\CubemapTexture.h" /> <ClInclude Include="..\..\src\CubemapTexture.h" />
<ClInclude Include="..\..\src\Engine.h" /> <ClInclude Include="..\..\src\Engine.h" />
<ClInclude Include="..\..\src\Entity.h" /> <ClInclude Include="..\..\src\Entity.h" />
<ClInclude Include="..\..\src\Events\ApplyForce.h" />
<ClInclude Include="..\..\src\Events\ApplyPointImpulse.h" />
<ClInclude Include="..\..\src\Events\BindGamepadAxis.h" /> <ClInclude Include="..\..\src\Events\BindGamepadAxis.h" />
<ClInclude Include="..\..\src\Events\BindGamepadButton.h" /> <ClInclude Include="..\..\src\Events\BindGamepadButton.h" />
<ClInclude Include="..\..\src\Events\BindKey.h" /> <ClInclude Include="..\..\src\Events\BindKey.h" />
@@ -189,6 +196,7 @@
<ClInclude Include="..\..\src\System.h" /> <ClInclude Include="..\..\src\System.h" />
<ClInclude Include="..\..\src\Systems\DebugSystem.h" /> <ClInclude Include="..\..\src\Systems\DebugSystem.h" />
<ClInclude Include="..\..\src\Systems\FreeSteeringSystem.h" /> <ClInclude Include="..\..\src\Systems\FreeSteeringSystem.h" />
<ClInclude Include="..\..\src\Systems\HelicopterSteeringSystem.h" />
<ClInclude Include="..\..\src\Systems\InputSystem.h" /> <ClInclude Include="..\..\src\Systems\InputSystem.h" />
<ClInclude Include="..\..\src\Systems\ParticleSystem.h" /> <ClInclude Include="..\..\src\Systems\ParticleSystem.h" />
<ClInclude Include="..\..\src\Systems\PhysicsSystem.h" /> <ClInclude Include="..\..\src\Systems\PhysicsSystem.h" />
@@ -197,7 +205,6 @@
<ClInclude Include="..\..\src\Systems\TankSteeringSystem.h" /> <ClInclude Include="..\..\src\Systems\TankSteeringSystem.h" />
<ClInclude Include="..\..\src\Systems\TransformSystem.h" /> <ClInclude Include="..\..\src\Systems\TransformSystem.h" />
<ClInclude Include="..\..\src\Texture.h" /> <ClInclude Include="..\..\src\Texture.h" />
<ClInclude Include="..\..\src\Util\defferedUtil.h" />
<ClInclude Include="..\..\src\Util\GLError.h" /> <ClInclude Include="..\..\src\Util\GLError.h" />
<ClInclude Include="..\..\src\Util\Rectangle.h" /> <ClInclude Include="..\..\src\Util\Rectangle.h" />
<ClInclude Include="..\..\src\Util\Logging.h" /> <ClInclude Include="..\..\src\Util\Logging.h" />
+42 -1
View File
@@ -63,6 +63,9 @@
<ClCompile Include="..\..\src\Systems\TankSteeringSystem.cpp"> <ClCompile Include="..\..\src\Systems\TankSteeringSystem.cpp">
<Filter>Physics\Systems</Filter> <Filter>Physics\Systems</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\Systems\HelicopterSteeringSystem.cpp">
<Filter>Gameplay\Vehicles\Helicopter\Systems</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="Util"> <Filter Include="Util">
@@ -137,6 +140,24 @@
<Filter Include="Physics\Events"> <Filter Include="Physics\Events">
<UniqueIdentifier>{42ae084f-ade8-402c-87ba-f03f6b846bc8}</UniqueIdentifier> <UniqueIdentifier>{42ae084f-ade8-402c-87ba-f03f6b846bc8}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Gameplay">
<UniqueIdentifier>{5b992473-73e6-485e-8f13-17e0801fb2ca}</UniqueIdentifier>
</Filter>
<Filter Include="Gameplay\Vehicles">
<UniqueIdentifier>{8a78be3a-a3c5-4054-a2f1-1456f3fcbab0}</UniqueIdentifier>
</Filter>
<Filter Include="Gameplay\Vehicles\Helicopter">
<UniqueIdentifier>{8ccc0abe-5bdd-4656-ab11-5708a39c71ae}</UniqueIdentifier>
</Filter>
<Filter Include="Gameplay\Vehicles\Helicopter\Components">
<UniqueIdentifier>{b2416d05-a49e-4fef-a5c4-cd03d8cc2efd}</UniqueIdentifier>
</Filter>
<Filter Include="Gameplay\Vehicles\Helicopter\Systems">
<UniqueIdentifier>{b34c0c95-a887-4cf4-af24-cf7c1f459aa8}</UniqueIdentifier>
</Filter>
<Filter Include="Gameplay\Components">
<UniqueIdentifier>{cb06b441-90b8-46ed-b347-4190dac7185b}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\src\World.h" /> <ClInclude Include="..\..\src\World.h" />
@@ -352,10 +373,30 @@
<ClInclude Include="..\..\src\Events\BindGamepadButton.h"> <ClInclude Include="..\..\src\Events\BindGamepadButton.h">
<Filter>Input\Events</Filter> <Filter>Input\Events</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\Util\defferedUtil.h" /> <ClInclude Include="..\..\src\Components\Viewport.h">
<Filter>Physics\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Health.h">
<Filter>Physics\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\LockMouse.h"> <ClInclude Include="..\..\src\Events\LockMouse.h">
<Filter>Input\Events</Filter> <Filter>Input\Events</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\Components\HelicopterSteering.h">
<Filter>Gameplay\Vehicles\Helicopter\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\HelicopterSteeringSystem.h">
<Filter>Gameplay\Vehicles\Helicopter\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\ApplyForce.h">
<Filter>Physics\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\ApplyPointImpulse.h">
<Filter>Physics\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Player.h">
<Filter>Gameplay\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Listener.h"> <ClInclude Include="..\..\src\Components\Listener.h">
<Filter>Audio\Components</Filter> <Filter>Audio\Components</Filter>
</ClInclude> </ClInclude>