Merge branch 'OctTree' of github.com:teamfisk/TacticalZ into OctTree
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
#ifndef CollisionSystem_h__
|
||||||
|
#define CollisionSystem_h__
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <glm/common.hpp>
|
||||||
|
|
||||||
|
#include "Common.h"
|
||||||
|
#include "Core/System.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Core/EKeyUp.h"
|
||||||
|
|
||||||
|
class CollisionSystem : public System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CollisionSystem(EventBroker* eventBroker)
|
||||||
|
: System(eventBroker, "AABB")
|
||||||
|
{
|
||||||
|
//TODO: Debug stuff, remove later.
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &CollisionSystem::OnKeyUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Update(World* world, ComponentWrapper& collision, double dt) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
EventRelay<CollisionSystem, Events::KeyUp> m_EKeyUp;
|
||||||
|
bool OnKeyUp(const Events::KeyUp &event);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
#ifndef Events_TriggerEnter_h__
|
||||||
|
#define Events_TriggerEnter_h__
|
||||||
|
|
||||||
|
#include "../Core/EventBroker.h"
|
||||||
|
#include "../Core/Entity.h"
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
/** Thrown once, when an entity is completely inside a trigger. */
|
||||||
|
struct TriggerTouch : Event
|
||||||
|
{
|
||||||
|
/** The id of the entity that touches the trigger. */
|
||||||
|
EntityID Entity;
|
||||||
|
/** The id of the trigger entity. */
|
||||||
|
EntityID Trigger;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Thrown once, when an entity has completely left a trigger. */
|
||||||
|
struct TriggerLeave : Event
|
||||||
|
{
|
||||||
|
/** The id of the entity that left the trigger. */
|
||||||
|
EntityID Entity;
|
||||||
|
/** The id of the trigger entity. */
|
||||||
|
EntityID Trigger;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Thrown when an entity is completely inside a trigger. */
|
||||||
|
struct TriggerEnter : Event
|
||||||
|
{
|
||||||
|
/** The id of the entity that entered the trigger. */
|
||||||
|
EntityID Entity;
|
||||||
|
/** The id of the trigger entity. */
|
||||||
|
EntityID Trigger;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef TriggerSystem_h__
|
||||||
|
#define TriggerSystem_h__
|
||||||
|
|
||||||
|
#include <glm/common.hpp>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
#include "Core/System.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "ETrigger.h"
|
||||||
|
|
||||||
|
class TriggerSystem : public System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TriggerSystem(EventBroker* eventBroker)
|
||||||
|
: System(eventBroker, "Trigger")
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual void Update(World* world, ComponentWrapper& collision, double dt) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unordered_map<EntityID, std::unordered_set<EntityID>> m_EntitiesInTrigger;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -17,119 +17,119 @@ class EventBroker;
|
|||||||
|
|
||||||
class BaseEventRelay
|
class BaseEventRelay
|
||||||
{
|
{
|
||||||
friend class EventBroker;
|
friend class EventBroker;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BaseEventRelay(std::string contextTypeName, std::string eventTypeName)
|
BaseEventRelay(std::string contextTypeName, std::string eventTypeName)
|
||||||
: m_ContextTypeName(contextTypeName)
|
: m_ContextTypeName(contextTypeName)
|
||||||
, m_EventTypeName(eventTypeName)
|
, m_EventTypeName(eventTypeName)
|
||||||
, m_Broker(nullptr)
|
, m_Broker(nullptr)
|
||||||
{ }
|
{ }
|
||||||
~BaseEventRelay();
|
~BaseEventRelay();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool Receive(const std::shared_ptr<Event> event) = 0;
|
virtual bool Receive(const std::shared_ptr<Event> event) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string m_ContextTypeName;
|
std::string m_ContextTypeName;
|
||||||
std::string m_EventTypeName;
|
std::string m_EventTypeName;
|
||||||
EventBroker* m_Broker;
|
EventBroker* m_Broker;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename ContextType, typename EventType>
|
template <typename ContextType, typename EventType>
|
||||||
class EventRelay : public BaseEventRelay
|
class EventRelay : public BaseEventRelay
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::function<bool(const EventType&)> CallbackType;
|
typedef std::function<bool(const EventType&)> CallbackType;
|
||||||
|
|
||||||
EventRelay()
|
EventRelay()
|
||||||
: m_Callback(nullptr)
|
: m_Callback(nullptr)
|
||||||
, BaseEventRelay(typeid(ContextType).name(), typeid(EventType).name())
|
, BaseEventRelay(typeid(ContextType).name(), typeid(EventType).name())
|
||||||
{ }
|
{ }
|
||||||
EventRelay(CallbackType callback)
|
EventRelay(CallbackType callback)
|
||||||
: m_Callback(callback)
|
: m_Callback(callback)
|
||||||
, BaseEventRelay(typeid(ContextType).name(), typeid(EventType).name())
|
, BaseEventRelay(typeid(ContextType).name(), typeid(EventType).name())
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool Receive(const std::shared_ptr<Event> event) override;
|
bool Receive(const std::shared_ptr<Event> event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CallbackType m_Callback;
|
CallbackType m_Callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename ContextType, typename EventType>
|
template <typename ContextType, typename EventType>
|
||||||
bool EventRelay<ContextType, EventType>::Receive(const std::shared_ptr<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.get()));
|
return m_Callback(*static_cast<const EventType*>(event.get()));
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EventBroker
|
class EventBroker
|
||||||
{
|
{
|
||||||
template <typename ContextType, typename EventType> friend class EventRelay;
|
template <typename ContextType, typename EventType> friend class EventRelay;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EventBroker()
|
EventBroker()
|
||||||
{
|
{
|
||||||
m_EventQueueRead = std::make_shared<EventQueue_t>();
|
m_EventQueueRead = std::make_shared<EventQueue_t>();
|
||||||
m_EventQueueWrite = std::make_shared<EventQueue_t>();
|
m_EventQueueWrite = std::make_shared<EventQueue_t>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Subscribe(BaseEventRelay &relay);
|
void Subscribe(BaseEventRelay &relay);
|
||||||
template <typename EventType>
|
template <typename EventType>
|
||||||
void Publish(const EventType &event);
|
void Publish(const EventType &event);
|
||||||
/*
|
/*
|
||||||
Process all events in a given context.
|
Process all events in a given context.
|
||||||
Returns: Number of events processed
|
Returns: Number of events processed
|
||||||
*/
|
*/
|
||||||
template <typename ContextType>
|
template <typename ContextType>
|
||||||
int Process();
|
int Process();
|
||||||
int Process(std::string contextTypeName);
|
int Process(std::string contextTypeName);
|
||||||
void Swap();
|
void Swap();
|
||||||
void Clear();
|
void Clear();
|
||||||
void Unsubscribe(BaseEventRelay &relay);
|
void Unsubscribe(BaseEventRelay &relay);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_IsProcessing = false;
|
bool m_IsProcessing = false;
|
||||||
|
|
||||||
typedef std::string ContextTypeName_t; // typeid(ContextType).name()
|
typedef std::string ContextTypeName_t; // typeid(ContextType).name()
|
||||||
typedef std::string EventTypeName_t; // typeid(EventType).name()
|
typedef std::string EventTypeName_t; // typeid(EventType).name()
|
||||||
|
|
||||||
typedef std::unordered_multimap<EventTypeName_t, BaseEventRelay*> EventRelays_t;
|
typedef std::unordered_multimap<EventTypeName_t, BaseEventRelay*> EventRelays_t;
|
||||||
typedef std::unordered_map<ContextTypeName_t, EventRelays_t> ContextRelays_t;
|
typedef std::unordered_map<ContextTypeName_t, EventRelays_t> ContextRelays_t;
|
||||||
ContextRelays_t m_ContextRelays;
|
ContextRelays_t m_ContextRelays;
|
||||||
std::vector<BaseEventRelay*> m_RelaysToSubscribe;
|
std::vector<BaseEventRelay*> m_RelaysToSubscribe;
|
||||||
std::vector<BaseEventRelay*> m_RelaysToUnsubscribe;
|
std::vector<BaseEventRelay*> m_RelaysToUnsubscribe;
|
||||||
|
|
||||||
typedef std::list<std::pair<EventTypeName_t, std::shared_ptr<Event>>> EventQueue_t;
|
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_EventQueueRead;
|
||||||
std::shared_ptr<EventQueue_t> m_EventQueueWrite;
|
std::shared_ptr<EventQueue_t> m_EventQueueWrite;
|
||||||
|
|
||||||
void subscribeImmediate(BaseEventRelay& relay);
|
void subscribeImmediate(BaseEventRelay& relay);
|
||||||
void unsubscribeImmediate(BaseEventRelay& relay);
|
void unsubscribeImmediate(BaseEventRelay& relay);
|
||||||
};
|
};
|
||||||
|
|
||||||
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))));
|
m_EventQueueWrite->push_back(std::make_pair(typeid(EventType).name(), std::shared_ptr<EventType>(new EventType(event))));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ContextType>
|
template <typename ContextType>
|
||||||
int EventBroker::Process()
|
int EventBroker::Process()
|
||||||
{
|
{
|
||||||
const std::string contextTypeName = typeid(ContextType).name();
|
const std::string contextTypeName = typeid(ContextType).name();
|
||||||
return Process(contextTypeName);
|
return Process(contextTypeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -10,16 +10,16 @@ class System
|
|||||||
friend class SystemPipeline;
|
friend class SystemPipeline;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
System(const EventBroker* eventBroker, std::string componentType)
|
System(EventBroker* eventBroker, std::string componentType)
|
||||||
: m_EventBroker(eventBroker)
|
: m_EventBroker(eventBroker)
|
||||||
, m_ComponentType(componentType)
|
, m_ComponentType(componentType)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual void Update(World* world, ComponentWrapper& component, double dt) = 0;
|
virtual void Update(World* world, ComponentWrapper& component, double dt) = 0;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
const EventBroker* m_EventBroker;
|
|
||||||
std::string m_ComponentType;
|
std::string m_ComponentType;
|
||||||
|
EventBroker* m_EventBroker;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
class SystemPipeline
|
class SystemPipeline
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SystemPipeline(const EventBroker* eventBroker)
|
SystemPipeline(EventBroker* eventBroker)
|
||||||
: m_EventBroker(eventBroker)
|
: m_EventBroker(eventBroker)
|
||||||
{ }
|
{ }
|
||||||
~SystemPipeline()
|
~SystemPipeline()
|
||||||
@@ -51,7 +51,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const EventBroker* m_EventBroker;
|
EventBroker* m_EventBroker;
|
||||||
std::unordered_map<std::string, std::vector<System*>> m_Systems;
|
std::unordered_map<std::string, std::vector<System*>> m_Systems;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
#ifndef Events_Picking_h__
|
||||||
|
#define Events_Picking_h__
|
||||||
|
|
||||||
|
#include "../OpenGL.h"
|
||||||
|
#include "../GLM.h"
|
||||||
|
|
||||||
|
#include "../Core/EventBroker.h"
|
||||||
|
#include "Util/ScreenCoords.h"
|
||||||
|
#include "FrameBuffer.h"
|
||||||
|
#include "../Core/Entity.h"
|
||||||
|
#include "Util/UnorderedMapVec2.h"
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
/** Thrown Every frame, use functions to pick*/
|
||||||
|
struct Picking : Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Picking(FrameBuffer* pickingBuffer, GLuint* depthBuffer, glm::mat4 projectionMatrix, glm::mat4 viewMatrix, Rectangle resolution, const std::unordered_map<glm::vec2, EntityID>* pickingColorsToEntity)
|
||||||
|
: PickingBuffer(pickingBuffer)
|
||||||
|
, DepthBuffer(depthBuffer)
|
||||||
|
, ProjectionMatrix(projectionMatrix)
|
||||||
|
, ViewMatrix(viewMatrix)
|
||||||
|
, Resolution(resolution)
|
||||||
|
, PickingColorsToEntity(pickingColorsToEntity)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct PickData
|
||||||
|
{
|
||||||
|
//Picked Entity
|
||||||
|
EntityID Entity;
|
||||||
|
//World position of the "pick"
|
||||||
|
glm::vec3 Position;
|
||||||
|
};
|
||||||
|
|
||||||
|
PickData Pick(glm::vec2 screenCoord) const
|
||||||
|
{
|
||||||
|
PickData pickData;
|
||||||
|
|
||||||
|
ScreenCoords::PixelData data = ScreenCoords::ToPixelData(screenCoord, PickingBuffer, *DepthBuffer);
|
||||||
|
|
||||||
|
auto it = PickingColorsToEntity->find(glm::vec2(data.Color[0], data.Color[1]));
|
||||||
|
if (it != PickingColorsToEntity->end()) {
|
||||||
|
pickData.Entity = it->second;
|
||||||
|
} else {
|
||||||
|
pickData.Entity = -1;
|
||||||
|
}
|
||||||
|
pickData.Position = ScreenCoords::ToWorldPos(screenCoord.x, Resolution.Width - screenCoord.y, data.Depth, Resolution, ProjectionMatrix, ViewMatrix);
|
||||||
|
|
||||||
|
return pickData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
FrameBuffer* PickingBuffer;
|
||||||
|
GLuint* DepthBuffer;
|
||||||
|
const glm::mat4 ProjectionMatrix;
|
||||||
|
const glm::mat4 ViewMatrix;
|
||||||
|
const Rectangle Resolution;
|
||||||
|
const std::unordered_map<glm::vec2, EntityID>* PickingColorsToEntity;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -11,15 +11,24 @@
|
|||||||
#include "FrameBuffer.h"
|
#include "FrameBuffer.h"
|
||||||
#include "../Core/World.h"
|
#include "../Core/World.h"
|
||||||
|
|
||||||
|
#include "../Core/EventBroker.h"
|
||||||
|
#include "EPicking.h"
|
||||||
|
|
||||||
class Renderer : public IRenderer
|
class Renderer : public IRenderer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Renderer(EventBroker* eventBroker)
|
||||||
|
: m_EventBroker(eventBroker)
|
||||||
|
{ }
|
||||||
|
|
||||||
virtual void Initialize() override;
|
virtual void Initialize() override;
|
||||||
virtual void Update(double dt) override;
|
virtual void Update(double dt) override;
|
||||||
virtual void Draw(RenderQueueCollection& rq) override;
|
virtual void Draw(RenderQueueCollection& rq) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//----------------------Variables----------------------//
|
//----------------------Variables----------------------//
|
||||||
|
EventBroker* m_EventBroker;
|
||||||
|
|
||||||
Texture* m_ErrorTexture;
|
Texture* m_ErrorTexture;
|
||||||
Texture* m_WhiteTexture;
|
Texture* m_WhiteTexture;
|
||||||
float m_CameraMoveSpeed;
|
float m_CameraMoveSpeed;
|
||||||
@@ -31,8 +40,6 @@ private:
|
|||||||
Model* m_UnitQuad;
|
Model* m_UnitQuad;
|
||||||
Model* m_UnitSphere;
|
Model* m_UnitSphere;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::unordered_map<glm::vec2, EntityID> m_PickingColorsToEntity;
|
std::unordered_map<glm::vec2, EntityID> m_PickingColorsToEntity;
|
||||||
|
|
||||||
//----------------------Functions----------------------//
|
//----------------------Functions----------------------//
|
||||||
|
|||||||
@@ -11,6 +11,13 @@ class ScreenCoords
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScreenCoords() = delete;
|
ScreenCoords() = delete;
|
||||||
|
|
||||||
|
struct PixelData
|
||||||
|
{
|
||||||
|
int Color[2];
|
||||||
|
float Depth;
|
||||||
|
};
|
||||||
|
|
||||||
//Return world position from given screenspace coordinates and depth value in viewspace.
|
//Return world position from given screenspace coordinates and depth value in viewspace.
|
||||||
static glm::vec3 ToWorldPos(glm::vec2 screenCoord, float depth, Rectangle resolution, glm::mat4 cameraProjectionMat, glm::mat4 cameraViewMat);
|
static glm::vec3 ToWorldPos(glm::vec2 screenCoord, float depth, Rectangle resolution, glm::mat4 cameraProjectionMat, glm::mat4 cameraViewMat);
|
||||||
static glm::vec3 ToWorldPos(float x, float y, float depth, Rectangle resolution, glm::mat4 cameraProjectionMat, glm::mat4 cameraViewMat);
|
static glm::vec3 ToWorldPos(float x, float y, float depth, Rectangle resolution, glm::mat4 cameraProjectionMat, glm::mat4 cameraViewMat);
|
||||||
@@ -18,8 +25,8 @@ public:
|
|||||||
static glm::vec3 ToWorldPos(float x, float y, float depth, float screenWidth, float screenHeight, glm::mat4 cameraProjectionMat, glm::mat4 cameraViewMat);
|
static glm::vec3 ToWorldPos(float x, float y, float depth, float screenWidth, float screenHeight, glm::mat4 cameraProjectionMat, glm::mat4 cameraViewMat);
|
||||||
//Return data from the given buffers at the coordinates given in screenspace. Buffer should probably have a texture that covers the screen.
|
//Return data from the given buffers at the coordinates given in screenspace. Buffer should probably have a texture that covers the screen.
|
||||||
//Data is given as R = x, B = y, and
|
//Data is given as R = x, B = y, and
|
||||||
static glm::vec3 ToPixelData(glm::vec2 screenCoord, FrameBuffer* PickDataBuffer, GLuint DepthBuffer);
|
static PixelData ToPixelData(glm::vec2 screenCoord, FrameBuffer* PickDataBuffer, GLuint DepthBuffer);
|
||||||
static glm::vec3 ToPixelData(float x, float y, FrameBuffer* PickDataBuffer, GLuint DepthBuffer);
|
static PixelData ToPixelData(float x, float y, FrameBuffer* PickDataBuffer, GLuint DepthBuffer);
|
||||||
//Return EntityID of the clicked coordinate in given screenspace coordinates.
|
//Return EntityID of the clicked coordinate in given screenspace coordinates.
|
||||||
//EntityID ScreenCoordsToEntityID(glm::vec2 screenCoord, float depth);
|
//EntityID ScreenCoordsToEntityID(glm::vec2 screenCoord, float depth);
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "Core/EntityXMLFile.h"
|
#include "Core/EntityXMLFile.h"
|
||||||
#include "Core/SystemPipeline.h"
|
#include "Core/SystemPipeline.h"
|
||||||
#include "RaptorCopterSystem.h"
|
#include "RaptorCopterSystem.h"
|
||||||
|
#include "PlayerSystem.h"
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#ifndef PlayerSystem_h__
|
||||||
|
#define PlayerSystem_h__
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <glm/common.hpp>
|
||||||
|
|
||||||
|
#include "Common.h"
|
||||||
|
#include "Core/System.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Core/EKeyDown.h"
|
||||||
|
#include "Core/EKeyUp.h"
|
||||||
|
|
||||||
|
struct KeyInput
|
||||||
|
{
|
||||||
|
bool Forward = false;
|
||||||
|
bool Left = false;
|
||||||
|
bool Back = false;
|
||||||
|
bool Right = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PlayerSystem : public System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PlayerSystem(EventBroker* eventBroker)
|
||||||
|
: System(eventBroker, "Player")
|
||||||
|
{
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &PlayerSystem::OnKeyDown);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &PlayerSystem::OnKeyUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Update(World* world, ComponentWrapper& player, double dt) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
float m_Speed = 5;
|
||||||
|
glm::vec3 m_Direction;
|
||||||
|
KeyInput input;
|
||||||
|
|
||||||
|
EventRelay<PlayerSystem, Events::KeyDown> m_EKeyDown;
|
||||||
|
bool OnKeyDown(const Events::KeyDown &event);
|
||||||
|
EventRelay<PlayerSystem, Events::KeyUp> m_EKeyUp;
|
||||||
|
bool OnKeyUp(const Events::KeyUp &event);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -4,10 +4,12 @@
|
|||||||
class RaptorCopterSystem : public System
|
class RaptorCopterSystem : public System
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RaptorCopterSystem(const EventBroker* eventBroker)
|
RaptorCopterSystem(EventBroker* eventBroker)
|
||||||
: System(eventBroker, "RaptorCopter")
|
: System(eventBroker, "RaptorCopter")
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
virtual void Initialize() { }
|
||||||
|
|
||||||
virtual void Update(World* world, ComponentWrapper& raptorCopter, double dt) override
|
virtual void Update(World* world, ComponentWrapper& raptorCopter, double dt) override
|
||||||
{
|
{
|
||||||
ComponentWrapper& transform = world->GetComponent(raptorCopter.EntityID, "Transform");
|
ComponentWrapper& transform = world->GetComponent(raptorCopter.EntityID, "Transform");
|
||||||
|
|||||||
@@ -5,4 +5,7 @@
|
|||||||
<xs:include schemaLocation="Components/Model.xsd"/>
|
<xs:include schemaLocation="Components/Model.xsd"/>
|
||||||
<xs:include schemaLocation="Components/Test.xsd"/>
|
<xs:include schemaLocation="Components/Test.xsd"/>
|
||||||
<xs:include schemaLocation="Components/RaptorCopter.xsd"/>
|
<xs:include schemaLocation="Components/RaptorCopter.xsd"/>
|
||||||
|
<xs:include schemaLocation="Components/Player.xsd"/>
|
||||||
|
<xs:include schemaLocation="Components/AABB.xsd"/>
|
||||||
|
<xs:include schemaLocation="Components/Trigger.xsd"/>
|
||||||
</xs:schema>
|
</xs:schema>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<c:AABB>
|
||||||
|
<BoxCenter X="0" Y="0" Z="0"/>
|
||||||
|
<BoxSize X="1" Y="1" Z="1"/>
|
||||||
|
</c:AABB>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
|
||||||
|
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||||
|
|
||||||
|
<xs:element name="AABB">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:all>
|
||||||
|
<xs:element name="BoxCenter" type="t:Vector" minOccurs="0"/>
|
||||||
|
<xs:element name="BoxSize" type="t:Vector" minOccurs="0"/>
|
||||||
|
</xs:all>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<c:Player>
|
||||||
|
<Velocity X="0" Y="0" Z="0"/>
|
||||||
|
</c:Player>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
|
||||||
|
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||||
|
|
||||||
|
<xs:element name="Player">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:all>
|
||||||
|
<xs:element name="Velocity" type="t:Vector" minOccurs="0"/>
|
||||||
|
</xs:all>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<c:Trigger>
|
||||||
|
</c:Trigger>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
|
||||||
|
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||||
|
|
||||||
|
<xs:element name="Trigger">
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
||||||
@@ -31,6 +31,19 @@
|
|||||||
</c:Model>
|
</c:Model>
|
||||||
</Components>
|
</Components>
|
||||||
</Entity>
|
</Entity>
|
||||||
|
<Entity>
|
||||||
|
<Components>
|
||||||
|
<c:Player>
|
||||||
|
<Velocity X="0" Y="0" Z="0"/>
|
||||||
|
</c:Player>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="2.5"/>
|
||||||
|
</c:Transform>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Core/UnitCube.obj</Resource>
|
||||||
|
</c:Model>
|
||||||
|
</Components>
|
||||||
|
</Entity>
|
||||||
<Entity>
|
<Entity>
|
||||||
<Components>
|
<Components>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
@@ -48,7 +61,7 @@
|
|||||||
<Components>
|
<Components>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Position X="0" Y="0"/>
|
<Position X="0" Y="0"/>
|
||||||
<Orientation X="0.0" Y="0" Z="0.0"/>
|
<Orientation X="0.0" Y="0" Z="1.0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
<c:Model>
|
<c:Model>
|
||||||
<Resource>Models/Core/UnitRaptor.obj</Resource>
|
<Resource>Models/Core/UnitRaptor.obj</Resource>
|
||||||
@@ -59,8 +72,8 @@
|
|||||||
<Entity>
|
<Entity>
|
||||||
<Components>
|
<Components>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Position X="0" Y="0"/>
|
<Position X="-0.01" Y="0.55"/>
|
||||||
<Orientation X="0" Y="0" Z="0"/>
|
<Orientation X="0" Y="0" Z="-1"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
<c:RaptorCopter>
|
<c:RaptorCopter>
|
||||||
<Speed>20</Speed>
|
<Speed>20</Speed>
|
||||||
@@ -71,19 +84,7 @@
|
|||||||
<Entity>
|
<Entity>
|
||||||
<Components>
|
<Components>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Position X="0" Y="0.4"/>
|
<Position X="0" Y="0"/>
|
||||||
<Scale X="0.1" Y="0.4" Z="0.1"/>
|
|
||||||
</c:Transform>
|
|
||||||
<c:Model>
|
|
||||||
<Resource>Models/Core/UnitCylinder.obj</Resource>
|
|
||||||
<Color R="1" G="0.4" B="0.8"/>
|
|
||||||
</c:Model>
|
|
||||||
</Components>
|
|
||||||
</Entity>
|
|
||||||
<Entity>
|
|
||||||
<Components>
|
|
||||||
<c:Transform>
|
|
||||||
<Position X="0" Y="0.6"/>
|
|
||||||
<Scale X="1.7" Y="0.03" Z="0.1"/>
|
<Scale X="1.7" Y="0.03" Z="0.1"/>
|
||||||
<Orientation X="0" Y="0" Z="0"/>
|
<Orientation X="0" Y="0" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
@@ -96,7 +97,7 @@
|
|||||||
<Entity>
|
<Entity>
|
||||||
<Components>
|
<Components>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Position X="0" Y="0.6"/>
|
<Position X="0" Y="0"/>
|
||||||
<Scale X="1.7" Y="0.03" Z="0.1"/>
|
<Scale X="1.7" Y="0.03" Z="0.1"/>
|
||||||
<Orientation X="0" Y="1.57" Z="0"/>
|
<Orientation X="0" Y="1.57" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
<xs:element ref="c:Model" minOccurs="0"/>
|
<xs:element ref="c:Model" minOccurs="0"/>
|
||||||
<xs:element ref="c:Test" minOccurs="0"/>
|
<xs:element ref="c:Test" minOccurs="0"/>
|
||||||
<xs:element ref="c:RaptorCopter" minOccurs="0"/>
|
<xs:element ref="c:RaptorCopter" minOccurs="0"/>
|
||||||
|
<xs:element ref="c:Player" minOccurs="0"/>
|
||||||
</xs:all>
|
</xs:all>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ out vec4 TextureFragment;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
TextureFragment = vec4(PickingColor, 0, 1);
|
TextureFragment = vec4(PickingColor/255, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,12 @@ file(GLOB SOURCE_FILES_GUI
|
|||||||
)
|
)
|
||||||
source_group(GUI FILES ${SOURCE_FILES_GUI})
|
source_group(GUI FILES ${SOURCE_FILES_GUI})
|
||||||
|
|
||||||
|
file(GLOB SOURCE_FILES_Collision
|
||||||
|
"${INCLUDE_PATH}/Collision/*.h"
|
||||||
|
"Collision/*.cpp"
|
||||||
|
)
|
||||||
|
source_group(Collision FILES ${SOURCE_FILES_Collision})
|
||||||
|
|
||||||
set(SOURCE_FILES
|
set(SOURCE_FILES
|
||||||
${SOURCE_FILES_Core}
|
${SOURCE_FILES_Core}
|
||||||
${SOURCE_FILES_Core_Util}
|
${SOURCE_FILES_Core_Util}
|
||||||
@@ -78,6 +84,7 @@ set(SOURCE_FILES
|
|||||||
${SOURCE_FILES_GUI}
|
${SOURCE_FILES_GUI}
|
||||||
${SOURCE_FILES_Rendering}
|
${SOURCE_FILES_Rendering}
|
||||||
${SOURCE_FILES_Rendering_Util}
|
${SOURCE_FILES_Rendering_Util}
|
||||||
|
${SOURCE_FILES_Collision}
|
||||||
)
|
)
|
||||||
|
|
||||||
set(LIBRARIES
|
set(LIBRARIES
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "Core/Collision.h"
|
#include "Collision/Collision.h"
|
||||||
#include "Engine/GLM.h"
|
#include "Engine/GLM.h"
|
||||||
|
|
||||||
namespace Collision
|
namespace Collision
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#include "Collision/CollisionSystem.h"
|
||||||
|
|
||||||
|
|
||||||
|
void CollisionSystem::Update(World * world, ComponentWrapper & collision, double dt)
|
||||||
|
{
|
||||||
|
m_EventBroker->Process<CollisionSystem>();
|
||||||
|
(glm::vec3&)collision["Center"] = (glm::vec3)world->GetComponent(collision.EntityID, "Transform")["Position"];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CollisionSystem::OnKeyUp(const Events::KeyUp & event)
|
||||||
|
{
|
||||||
|
if (event.KeyCode == GLFW_KEY_Z) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#include "Collision/TriggerSystem.h"
|
||||||
|
#include "Core/AABB.h"
|
||||||
|
|
||||||
|
void TriggerSystem::Update(World* world, ComponentWrapper& trigger, double dt)
|
||||||
|
{
|
||||||
|
auto players = world->GetComponents("Player");
|
||||||
|
if (players == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//WTODO: Assumes box exists.
|
||||||
|
ComponentWrapper& cBox = world->GetComponent(trigger.EntityID, "AABB");
|
||||||
|
AABB aabb;
|
||||||
|
aabb.CreateFromCenter(cBox["BoxCenter"], cBox["BoxSize"]);
|
||||||
|
for (auto& c : *players) {
|
||||||
|
|
||||||
|
Events::TriggerEnter e;
|
||||||
|
e.Trigger = trigger.EntityID;
|
||||||
|
e.Entity = 41;
|
||||||
|
m_EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <bitset>
|
#include <bitset>
|
||||||
|
|
||||||
#include "Core/OctTree.h"
|
#include "Core/OctTree.h"
|
||||||
#include "Core/Collision.h"
|
#include "Collision/Collision.h"
|
||||||
#include "Core/World.h"
|
#include "Core/World.h"
|
||||||
#include "Rendering/Camera.h"
|
#include "Rendering/Camera.h"
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ glm::vec3 RenderQueueFactory::AbsolutePosition(World* world, EntityID entity)
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
ComponentWrapper transform = world->GetComponent(entity, "Transform");
|
ComponentWrapper transform = world->GetComponent(entity, "Transform");
|
||||||
position += AbsoluteOrientation(world, entity) * (glm::vec3)transform["Position"];
|
position += (glm::vec3)transform["Position"];
|
||||||
entity = world->GetParent(entity);
|
entity = world->GetParent(entity);
|
||||||
} while (entity != 0);
|
} while (entity != 0);
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
void Renderer::Initialize()
|
void Renderer::Initialize()
|
||||||
{
|
{
|
||||||
InitializeWindow();
|
InitializeWindow();
|
||||||
|
|
||||||
// Create default camera
|
// Create default camera
|
||||||
m_DefaultCamera = new ::Camera((float)m_Resolution.Width / m_Resolution.Height, glm::radians(45.f), 0.01f, 5000.f);
|
m_DefaultCamera = new ::Camera((float)m_Resolution.Width / m_Resolution.Height, glm::radians(45.f), 0.01f, 5000.f);
|
||||||
m_DefaultCamera->SetPosition(glm::vec3(0, 0, 10));
|
m_DefaultCamera->SetPosition(glm::vec3(0, 0, 10));
|
||||||
@@ -116,23 +115,6 @@ void Renderer::InputUpdate(double dt)
|
|||||||
|
|
||||||
static double mousePosX, mousePosY;
|
static double mousePosX, mousePosY;
|
||||||
glfwGetCursorPos(m_Window, &mousePosX, &mousePosY);
|
glfwGetCursorPos(m_Window, &mousePosX, &mousePosY);
|
||||||
if (glfwGetMouseButton(m_Window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS) {
|
|
||||||
glm::vec3 data = ScreenCoords::ToPixelData(mousePosX, m_Resolution.Height - mousePosY, &m_PickingBuffer, m_DepthBuffer);
|
|
||||||
glm::vec2 color = glm::vec2(data);
|
|
||||||
float depth = data.z;
|
|
||||||
|
|
||||||
glm::vec3 viewPos = ScreenCoords::ToWorldPos(mousePosX, m_Resolution.Height - mousePosY, depth, m_Resolution, m_Camera->ProjectionMatrix(), m_Camera->ViewMatrix());
|
|
||||||
// glm::vec3 worldPos = glm::vec3(glm::inverse(m_Camera->ViewMatrix()) * glm::vec4(viewPos, 1.f));
|
|
||||||
|
|
||||||
//printf("R: %f, G: %f, Depth: %f\n", color.r, color.g, depth);
|
|
||||||
//printf("view: x: %f, y: %f z: %f, Length: %f\n\n", viewPos.x, viewPos.y, viewPos.z, glm::length(viewPos));
|
|
||||||
|
|
||||||
if (color != glm::vec2(0, 0)) {
|
|
||||||
EntityID pickedEntity = m_PickingColorsToEntity[color];
|
|
||||||
printf("Picked Entity: %i", pickedEntity);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (glfwGetKey(m_Window, GLFW_KEY_SPACE) == GLFW_PRESS) {
|
if (glfwGetKey(m_Window, GLFW_KEY_SPACE) == GLFW_PRESS) {
|
||||||
|
|
||||||
@@ -158,7 +140,8 @@ void Renderer::InputUpdate(double dt)
|
|||||||
|
|
||||||
void Renderer::Update(double dt)
|
void Renderer::Update(double dt)
|
||||||
{
|
{
|
||||||
InputUpdate(dt);
|
m_EventBroker->Process<Renderer>();
|
||||||
|
InputUpdate(dt);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,10 +196,12 @@ void Renderer::DrawScene(RenderQueueCollection& rq)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
GLERROR("DrawScene Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::PickingPass(RenderQueueCollection& rq)
|
void Renderer::PickingPass(RenderQueueCollection& rq)
|
||||||
{
|
{
|
||||||
|
m_PickingColorsToEntity.clear();
|
||||||
m_PickingBuffer.Bind();
|
m_PickingBuffer.Bind();
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
@@ -225,7 +210,7 @@ void Renderer::PickingPass(RenderQueueCollection& rq)
|
|||||||
|
|
||||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
int r = 30;
|
int r = 1;
|
||||||
int g = 0;
|
int g = 0;
|
||||||
//TODO: Render: Add code for more jobs than modeljobs.
|
//TODO: Render: Add code for more jobs than modeljobs.
|
||||||
|
|
||||||
@@ -237,8 +222,18 @@ void Renderer::PickingPass(RenderQueueCollection& rq)
|
|||||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||||
|
|
||||||
if (modelJob) {
|
if (modelJob) {
|
||||||
glm::vec2 pickColor = glm::vec2(r/255.f, g/255.f);
|
//---------------
|
||||||
m_PickingColorsToEntity[pickColor] = modelJob->Entity;
|
//TODO: Renderer: IMPORTANT: Fixa detta så det inte loopar igenom listan varje frame.
|
||||||
|
//---------------
|
||||||
|
int pickColor[2] = { r, g };
|
||||||
|
for (auto i : m_PickingColorsToEntity) {
|
||||||
|
if(modelJob->Entity == i.second) {
|
||||||
|
pickColor[0] = i.first.x;
|
||||||
|
pickColor[1] = i.first.y;
|
||||||
|
r -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_PickingColorsToEntity[glm::vec2(pickColor[0], pickColor[1])] = modelJob->Entity;
|
||||||
|
|
||||||
|
|
||||||
//Render picking stuff
|
//Render picking stuff
|
||||||
@@ -246,19 +241,32 @@ void Renderer::PickingPass(RenderQueueCollection& rq)
|
|||||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->ModelMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->ModelMatrix));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
|
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
|
||||||
glUniform2fv(glGetUniformLocation(ShaderHandle, "PickingColor"), 1, glm::value_ptr(pickColor));
|
glUniform2fv(glGetUniformLocation(ShaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
||||||
|
|
||||||
glBindVertexArray(modelJob->Model->VAO);
|
glBindVertexArray(modelJob->Model->VAO);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
|
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
|
||||||
r+=50;
|
r += 1;
|
||||||
if(r > 255) {
|
if(r > 255) {
|
||||||
r = 0;
|
r = 0;
|
||||||
g+=50;
|
g += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_PickingBuffer.Unbind();
|
m_PickingBuffer.Unbind();
|
||||||
|
GLERROR("PickingPass Error");
|
||||||
|
|
||||||
|
//Publish pick event every frame with the pick data that can be picked by the event
|
||||||
|
Events::Picking pickEvent = Events::Picking(
|
||||||
|
&m_PickingBuffer,
|
||||||
|
&m_DepthBuffer,
|
||||||
|
m_Camera->ProjectionMatrix(),
|
||||||
|
m_Camera->ViewMatrix(),
|
||||||
|
m_Resolution,
|
||||||
|
&m_PickingColorsToEntity);
|
||||||
|
|
||||||
|
m_EventBroker->Publish(pickEvent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -300,7 +308,7 @@ void Renderer::InitializeTextures()
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
GenerateTexture(&m_PickingTexture, GL_CLAMP_TO_BORDER, GL_LINEAR,
|
GenerateTexture(&m_PickingTexture, GL_CLAMP_TO_BORDER, GL_LINEAR,
|
||||||
glm::vec2(m_Resolution.Width, m_Resolution.Height), GL_RG8, GL_RG, GL_FLOAT);
|
glm::vec2(m_Resolution.Width, m_Resolution.Height), GL_RG8, GL_RG, GL_UNSIGNED_BYTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type)
|
void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type)
|
||||||
|
|||||||
@@ -29,22 +29,31 @@ glm::vec3 ScreenCoords::ToWorldPos(glm::vec2 screenCoord, float depth, float scr
|
|||||||
return ToWorldPos(screenCoord.x, screenCoord.y, depth, screenWidth, screenHeight, cameraProjectionMat, cameraViewMat);
|
return ToWorldPos(screenCoord.x, screenCoord.y, depth, screenWidth, screenHeight, cameraProjectionMat, cameraViewMat);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 ScreenCoords::ToPixelData(float x, float y, FrameBuffer* PickDataBuffer, GLuint DepthBuffer)
|
ScreenCoords::PixelData ScreenCoords::ToPixelData(float x, float y, FrameBuffer* PickDataBuffer, GLuint DepthBuffer)
|
||||||
{
|
{
|
||||||
PickDataBuffer->Bind();
|
PickDataBuffer->Bind();
|
||||||
glm::vec2 pixelData;
|
unsigned char pdata[2];
|
||||||
glReadPixels(x, y, 1, 1, GL_RG, GL_FLOAT, &pixelData);
|
glReadPixels(x, y, 1, 1, GL_RG, GL_UNSIGNED_BYTE, &pdata);
|
||||||
PickDataBuffer->Unbind();
|
PickDataBuffer->Unbind();
|
||||||
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, DepthBuffer);
|
glBindFramebuffer(GL_FRAMEBUFFER, DepthBuffer);
|
||||||
float depthData;
|
float depthData;
|
||||||
glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depthData);
|
glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depthData);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
return glm::vec3(pixelData, depthData);
|
PixelData p;
|
||||||
|
p.Color[0] = (int)pdata[0];
|
||||||
|
p.Color[1] = (int)pdata[1];
|
||||||
|
p.Depth = depthData;
|
||||||
|
|
||||||
|
GLERROR("ScreenCoords::ToPixelData Error");
|
||||||
|
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 ScreenCoords::ToPixelData(glm::vec2 screenCoord, FrameBuffer* PickDataBuffer, GLuint DepthBuffer)
|
ScreenCoords::PixelData ScreenCoords::ToPixelData(glm::vec2 screenCoord, FrameBuffer* PickDataBuffer, GLuint DepthBuffer)
|
||||||
{
|
{
|
||||||
return ToPixelData(screenCoord.x, screenCoord.y, PickDataBuffer, DepthBuffer);
|
return ToPixelData(screenCoord.x, screenCoord.y, PickDataBuffer, DepthBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ file(GLOB SOURCE_FILES
|
|||||||
set(SOURCE_FILES
|
set(SOURCE_FILES
|
||||||
${SOURCE_FILES}
|
${SOURCE_FILES}
|
||||||
"Game.cpp"
|
"Game.cpp"
|
||||||
|
"PlayerSystem.cpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
set(LIBRARIES
|
set(LIBRARIES
|
||||||
|
|||||||
+42
-39
@@ -1,39 +1,40 @@
|
|||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
|
#include "Collision/TriggerSystem.h"
|
||||||
|
|
||||||
Game::Game(int argc, char* argv[])
|
Game::Game(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
|
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
|
||||||
ResourceManager::RegisterType<Model>("Model");
|
ResourceManager::RegisterType<Model>("Model");
|
||||||
ResourceManager::RegisterType<Texture>("Texture");
|
ResourceManager::RegisterType<Texture>("Texture");
|
||||||
ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile");
|
ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile");
|
||||||
|
|
||||||
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
|
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||||
LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get<int>("Debug.LogLevel", 1));
|
LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get<int>("Debug.LogLevel", 1));
|
||||||
|
|
||||||
// Create the core event broker
|
// Create the core event broker
|
||||||
m_EventBroker = new EventBroker();
|
m_EventBroker = new EventBroker();
|
||||||
|
|
||||||
m_RenderQueueFactory = new RenderQueueFactory();
|
m_RenderQueueFactory = new RenderQueueFactory();
|
||||||
|
|
||||||
// Create the renderer
|
// Create the renderer
|
||||||
m_Renderer = new Renderer();
|
m_Renderer = new Renderer(m_EventBroker);
|
||||||
m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false));
|
m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false));
|
||||||
m_Renderer->SetVSYNC(m_Config->Get<bool>("Video.VSYNC", false));
|
m_Renderer->SetVSYNC(m_Config->Get<bool>("Video.VSYNC", false));
|
||||||
m_Renderer->SetResolution(Rectangle(
|
m_Renderer->SetResolution(Rectangle(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
m_Config->Get<int>("Video.Width", 1280),
|
m_Config->Get<int>("Video.Width", 1280),
|
||||||
m_Config->Get<int>("Video.Height", 720)
|
m_Config->Get<int>("Video.Height", 720)
|
||||||
));
|
));
|
||||||
m_Renderer->Initialize();
|
m_Renderer->Initialize();
|
||||||
|
|
||||||
// Create input manager
|
// Create input manager
|
||||||
m_InputManager = new InputManager(m_Renderer->Window(), m_EventBroker);
|
m_InputManager = new InputManager(m_Renderer->Window(), m_EventBroker);
|
||||||
|
|
||||||
// Create the root level GUI frame
|
// Create the root level GUI frame
|
||||||
m_FrameStack = new GUI::Frame(m_EventBroker);
|
m_FrameStack = new GUI::Frame(m_EventBroker);
|
||||||
m_FrameStack->Width = m_Renderer->Resolution().Width;
|
m_FrameStack->Width = m_Renderer->Resolution().Width;
|
||||||
m_FrameStack->Height = m_Renderer->Resolution().Height;
|
m_FrameStack->Height = m_Renderer->Resolution().Height;
|
||||||
|
|
||||||
// Create a world
|
// Create a world
|
||||||
m_World = new World();
|
m_World = new World();
|
||||||
@@ -41,44 +42,46 @@ Game::Game(int argc, char* argv[])
|
|||||||
if (!mapToLoad.empty()) {
|
if (!mapToLoad.empty()) {
|
||||||
ResourceManager::Load<EntityXMLFile>(mapToLoad)->PopulateWorld(m_World);
|
ResourceManager::Load<EntityXMLFile>(mapToLoad)->PopulateWorld(m_World);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create system pipeline
|
// Create system pipeline
|
||||||
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
||||||
m_SystemPipeline->AddSystem<RaptorCopterSystem>();
|
m_SystemPipeline->AddSystem<RaptorCopterSystem>();
|
||||||
|
m_SystemPipeline->AddSystem<PlayerSystem>();
|
||||||
|
m_SystemPipeline->AddSystem<TriggerSystem>();
|
||||||
|
|
||||||
m_LastTime = glfwGetTime();
|
m_LastTime = glfwGetTime();
|
||||||
|
|
||||||
testIntialize();
|
testIntialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::~Game()
|
Game::~Game()
|
||||||
{
|
{
|
||||||
delete m_FrameStack;
|
delete m_FrameStack;
|
||||||
delete m_EventBroker;
|
delete m_EventBroker;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::Tick()
|
void Game::Tick()
|
||||||
{
|
{
|
||||||
double currentTime = glfwGetTime();
|
double currentTime = glfwGetTime();
|
||||||
double dt = currentTime - m_LastTime;
|
double dt = currentTime - m_LastTime;
|
||||||
m_LastTime = currentTime;
|
m_LastTime = currentTime;
|
||||||
|
|
||||||
m_EventBroker->Swap();
|
m_EventBroker->Swap();
|
||||||
m_InputManager->Update(dt);
|
m_InputManager->Update(dt);
|
||||||
m_Renderer->Update(dt);
|
m_EventBroker->Swap();
|
||||||
m_EventBroker->Swap();
|
|
||||||
|
|
||||||
// Iterate through systems and update world!
|
// Iterate through systems and update world!
|
||||||
m_SystemPipeline->Update(m_World, dt);
|
m_SystemPipeline->Update(m_World, dt);
|
||||||
testTick(dt);
|
testTick(dt);
|
||||||
|
m_Renderer->Update(dt);
|
||||||
|
|
||||||
m_RenderQueueFactory->Update(m_World);
|
m_RenderQueueFactory->Update(m_World);
|
||||||
m_Renderer->Draw(m_RenderQueueFactory->RenderQueues());
|
m_Renderer->Draw(m_RenderQueueFactory->RenderQueues());
|
||||||
|
|
||||||
m_EventBroker->Swap();
|
m_EventBroker->Swap();
|
||||||
m_EventBroker->Clear();
|
m_EventBroker->Clear();
|
||||||
|
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
#include "PlayerSystem.h"
|
||||||
|
|
||||||
|
|
||||||
|
void PlayerSystem::Update(World * world, ComponentWrapper & player, double dt)
|
||||||
|
{
|
||||||
|
if (input.Forward) {
|
||||||
|
m_Direction.z = -1;
|
||||||
|
} else if (input.Back) {
|
||||||
|
m_Direction.z = 1;
|
||||||
|
} else {
|
||||||
|
m_Direction.z = 0;
|
||||||
|
}
|
||||||
|
if (input.Left) {
|
||||||
|
m_Direction.x = -1;
|
||||||
|
} else if (input.Right) {
|
||||||
|
m_Direction.x = 1;
|
||||||
|
} else {
|
||||||
|
m_Direction.x = 0;
|
||||||
|
}
|
||||||
|
m_EventBroker->Process<PlayerSystem>();
|
||||||
|
ComponentWrapper& transform = world->GetComponent(player.EntityID, "Transform");
|
||||||
|
(glm::vec3&)player["Velocity"] = m_Speed * float(dt) * m_Direction;
|
||||||
|
(glm::vec3&)transform["Position"] += (glm::vec3)player["Velocity"];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PlayerSystem::OnKeyDown(const Events::KeyDown & event)
|
||||||
|
{
|
||||||
|
if (event.KeyCode == GLFW_KEY_W) {
|
||||||
|
input.Forward = true;
|
||||||
|
}
|
||||||
|
if (event.KeyCode == GLFW_KEY_A) {
|
||||||
|
input.Left = true;
|
||||||
|
}
|
||||||
|
if (event.KeyCode == GLFW_KEY_S) {
|
||||||
|
input.Back = true;
|
||||||
|
}
|
||||||
|
if (event.KeyCode == GLFW_KEY_D) {
|
||||||
|
input.Right = true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PlayerSystem::OnKeyUp(const Events::KeyUp & event)
|
||||||
|
{
|
||||||
|
if (event.KeyCode == GLFW_KEY_W) {
|
||||||
|
input.Forward = false;
|
||||||
|
}
|
||||||
|
if (event.KeyCode == GLFW_KEY_A) {
|
||||||
|
input.Left = false;
|
||||||
|
}
|
||||||
|
if (event.KeyCode == GLFW_KEY_S) {
|
||||||
|
input.Back = false;
|
||||||
|
}
|
||||||
|
if (event.KeyCode == GLFW_KEY_D) {
|
||||||
|
input.Right = false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <boost/test/execution_monitor.hpp>
|
#include <boost/test/execution_monitor.hpp>
|
||||||
using boost::unit_test_framework::test_suite;
|
using boost::unit_test_framework::test_suite;
|
||||||
using boost::unit_test_framework::test_case;
|
using boost::unit_test_framework::test_case;
|
||||||
#include "Engine\Core\Collision.h"
|
#include "Engine/Collision/Collision.h"
|
||||||
#include "Engine/Core/AABB.h"
|
#include "Engine/Core/AABB.h"
|
||||||
#include "Engine/Core/Ray.h"
|
#include "Engine/Core/Ray.h"
|
||||||
#include <stdlib.h>//srand
|
#include <stdlib.h>//srand
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ Game::Game(int argc, char* argv[]) : someOctTree(AABB(-0.5f*worldSize, 0.5f*worl
|
|||||||
m_RenderQueueFactory = new RenderQueueFactory();
|
m_RenderQueueFactory = new RenderQueueFactory();
|
||||||
|
|
||||||
// Create the renderer
|
// Create the renderer
|
||||||
m_Renderer = new Renderer();
|
m_Renderer = new Renderer(m_EventBroker);
|
||||||
m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false));
|
m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false));
|
||||||
m_Renderer->SetVSYNC(m_Config->Get<bool>("Video.VSYNC", false));
|
m_Renderer->SetVSYNC(m_Config->Get<bool>("Video.VSYNC", false));
|
||||||
m_Renderer->SetResolution(Rectangle(
|
m_Renderer->SetResolution(Rectangle(
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include "Rendering/RenderQueueFactory.h"
|
#include "Rendering/RenderQueueFactory.h"
|
||||||
|
|
||||||
#include "OctTreeTestHardCodedTestWorld.h"
|
#include "OctTreeTestHardCodedTestWorld.h"
|
||||||
#include "Core\Collision.h"
|
#include "Collision/Collision.h"
|
||||||
|
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <boost/test/execution_monitor.hpp>
|
#include <boost/test/execution_monitor.hpp>
|
||||||
using boost::unit_test_framework::test_suite;
|
using boost::unit_test_framework::test_suite;
|
||||||
using boost::unit_test_framework::test_case;
|
using boost::unit_test_framework::test_case;
|
||||||
#include <Engine\Core\Collision.h>
|
#include "Engine/Collision/Collision.h"
|
||||||
#include "Engine/Core/AABB.h"
|
#include "Engine/Core/AABB.h"
|
||||||
#include "Engine/Core/Ray.h"
|
#include "Engine/Core/Ray.h"
|
||||||
#include <stdlib.h>//srand
|
#include <stdlib.h>//srand
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <bitset>
|
#include <bitset>
|
||||||
|
|
||||||
#include "OldOctTree.h"
|
#include "OldOctTree.h"
|
||||||
#include "Core/Collision.h"
|
#include "Collision/Collision.h"
|
||||||
#include "Core/World.h"
|
#include "Core/World.h"
|
||||||
#include "Rendering/Camera.h"
|
#include "Rendering/Camera.h"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user