I'll create a GUI interface using Visual Basic, see if I can track an IP address

This commit is contained in:
2014-05-24 20:37:55 +02:00
parent 2fbcad4dbf
commit 07c74ff9f5
14 changed files with 401 additions and 85 deletions
+11 -23
View File
@@ -9,10 +9,7 @@ Camera::Camera(float yFOV, float aspectRatio, float nearClip, float farClip)
m_FarClip = farClip;
m_Position = glm::vec3(0.0);
/*m_Pitch = 0.f;
m_Yaw = 0.f;*/
UpdateProjectionMatrix();
UpdateViewMatrix();
}
@@ -34,12 +31,6 @@ Camera::Camera(float yFOV, float aspectRatio, float nearClip, float farClip)
// return orientation;
//}
void Camera::AspectRatio(float val)
{
m_AspectRatio = val;
UpdateProjectionMatrix();
}
void Camera::Position(glm::vec3 val)
{
m_Position = val;
@@ -65,16 +56,6 @@ void Camera::Orientation(glm::quat val)
// UpdateViewMatrix();
//}
void Camera::UpdateProjectionMatrix()
{
m_ProjectionMatrix = glm::perspective(
m_FOV,
m_AspectRatio,
m_NearClip,
m_FarClip
);
}
void Camera::UpdateViewMatrix()
{
m_ViewMatrix = glm::toMat4(glm::inverse(m_Orientation)) * glm::translate(-m_Position);
@@ -83,17 +64,24 @@ void Camera::UpdateViewMatrix()
void Camera::FOV(float val)
{
m_FOV = val;
UpdateProjectionMatrix();
}
void Camera::NearClip(float val)
{
m_NearClip = val;
UpdateProjectionMatrix();
}
void Camera::FarClip(float val)
{
m_FarClip = val;
UpdateProjectionMatrix();
}
}
glm::mat4 Camera::ProjectionMatrix(float aspectRatio)
{
return glm::perspective(
m_FOV,
aspectRatio,
m_NearClip,
m_FarClip
);
}
+7 -19
View File
@@ -1,60 +1,48 @@
#ifndef Camera_h__
#define Camera_h__
//#include "PrecompiledHeader.h"
class Camera
{
public:
Camera(float yFOV, float aspectRatio, float nearClip, float farClip);
Camera(float yFOV, float nearClip, float farClip);
glm::vec3 Forward();
glm::vec3 Right();
float AspectRatio() const { return m_AspectRatio; }
void AspectRatio(float val);
glm::vec3 Position() const { return m_Position; }
void Position(glm::vec3 val);
void SetPosition(glm::vec3 val);
glm::quat Orientation() const { return m_Orientation; }
void Orientation(glm::quat val);
void SetOrientation(glm::quat val);
/*float Pitch() const { return m_Pitch; }
void Pitch(float val);
float Yaw() const { return m_Yaw; }
void Yaw(float val);*/
glm::mat4 ProjectionMatrix() const { return m_ProjectionMatrix; }
void ProjectionMatrix(glm::mat4 val) { m_ProjectionMatrix = val; }
glm::mat4 ProjectionMatrix(float aspectRatio);
glm::mat4 ViewMatrix() const { return m_ViewMatrix; }
void ViewMatrix(glm::mat4 val) { m_ViewMatrix = val; }
float FOV() const { return m_FOV; }
void FOV(float val);
void SetFOV(float val);
float NearClip() const { return m_NearClip; }
void NearClip(float val);
void SetNearClip(float val);
float FarClip() const { return m_FarClip; }
void FarClip(float val);
void SetFarClip(float val);
private:
void UpdateProjectionMatrix();
void UpdateViewMatrix();
float m_FOV;
float m_AspectRatio;
float m_NearClip;
float m_FarClip;
glm::vec3 m_Position;
glm::quat m_Orientation;
//float m_Pitch;
//float m_Yaw;
glm::mat4 m_ProjectionMatrix;
glm::mat4 m_ViewMatrix;
};
+7 -2
View File
@@ -1,7 +1,9 @@
#include <string>
#include <sstream>
#include "ResourceManager.h"
#include "EventBroker.h"
#include "RenderQueue.h"
#include "Renderer.h"
#include "InputManager.h"
#include "GUI/Frame.h"
@@ -12,6 +14,8 @@ class Engine
public:
Engine(int argc, char* argv[])
{
m_ResourceManager = std::make_shared<ResourceManager>();
m_EventBroker = std::make_shared<EventBroker>();
m_Renderer = std::make_shared<Renderer>();
@@ -19,7 +23,7 @@ public:
m_InputManager = std::make_shared<InputManager>(m_Renderer->GetWindow(), m_EventBroker);
//m_UIParent = std::make_shared<GUI::Frame>(m_EventBroker);
m_FrameStack = std::make_shared<GUI::Frame>(m_EventBroker, m_Renderer);
m_World = std::make_shared<GameWorld>(m_EventBroker, m_Renderer);
m_World->Initialize();
@@ -44,10 +48,11 @@ public:
}
private:
std::shared_ptr<ResourceManager> m_ResourceManager;
std::shared_ptr<EventBroker> m_EventBroker;
std::shared_ptr<Renderer> m_Renderer;
std::shared_ptr<InputManager> m_InputManager;
//std::shared_ptr<GUI::Frame> m_UIParent;
std::shared_ptr<GUI::Frame> m_FrameStack;
// TODO: This should ultimately live in GameFrame
std::shared_ptr<GameWorld> m_World;
+18
View File
@@ -0,0 +1,18 @@
#ifndef Events_SetViewportCamera_h__
#define Events_SetViewportCamera_h__
#include "EventBroker.h"
#include "Entity.h"
namespace Events
{
struct SetViewportCamera : Event
{
std::string ViewportFrame;
EntityID CameraEntity;
};
}
#endif // Events_SetViewportCamera_h__
+48 -14
View File
@@ -2,12 +2,14 @@
#define GUI_Frame_h__
#include <memory>
#include <map>
#include "Util/Rectangle.h"
#include "EventBroker.h"
// HACK: Decouple renderer plz
#include "ResourceManager.h"
#include "Renderer.h"
#include "RenderQueue.h"
#include "Texture.h"
namespace GUI
{
@@ -24,13 +26,16 @@ public:
};
// Set up a base frame with an event broker
Frame(std::shared_ptr<::EventBroker> eventBroker)
Frame(std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: EventBroker(eventBroker)
, Rectangle()
, ResourceManager(resourceManager)
, Rectangle()
, m_Name("UIParent")
{ Initialize(); }
// Create a frame as a child
Frame(std::shared_ptr<Frame> parent)
Frame(std::shared_ptr<Frame> parent, std::string name)
: Rectangle(static_cast<Rectangle>(*parent)) // Clone parent rectangle using copy constructor
, m_Name(name)
{ SetParent(parent); Initialize(); }
virtual void Initialize() { }
@@ -40,18 +45,15 @@ public:
parent->AddChild(std::shared_ptr<Frame>(this));
m_Parent = parent;
EventBroker = parent->EventBroker;
ResourceManager = parent->ResourceManager;
}
void AddChild(std::shared_ptr<Frame> child)
{
m_Children.push_back(child);
if (m_Parent != nullptr)
{
m_Parent->AddChild(child);
}
m_Children.push_back(std::make_pair(child->Name(), child));
}
typedef std::list<std::shared_ptr<Frame>>::const_iterator FrameChildrenIterator;
typedef std::map<std::string, std::shared_ptr<Frame>>::const_iterator FrameChildrenIterator;
FrameChildrenIterator begin()
{
return m_Children.begin();
@@ -61,13 +63,45 @@ public:
return m_Children.end();
}
virtual void Update(double dt) { }
virtual void Draw(Renderer* renderer) { }
std::string Name() const { return m_Name; }
void SetName(std::string val) { m_Name = val; }
virtual void Update(double dt)
{
for (auto &pair : m_Children)
{
pair.second->Update(dt);
}
}
void DrawLayered(std::shared_ptr<Renderer> renderer)
{
renderer->SetViewport(GetLeft(), GetTop(), GetRight(), GetBottom());
this->Draw(renderer);
renderer->Draw();
for (auto &pair : m_Children)
{
pair.second->Draw(renderer);
}
}
virtual void Draw(std::shared_ptr<Renderer> renderer)
{
renderer->SetViewport(GetLeft(), GetTop(), GetRight(), GetBottom());
renderer->Draw();
}
protected:
std::shared_ptr<::EventBroker> EventBroker;
std::shared_ptr<::ResourceManager> ResourceManager;
std::string m_Name;
std::shared_ptr<Frame> m_Parent;
std::list<std::shared_ptr<Frame>> m_Children;
std::multimap<std::string, std::shared_ptr<Frame>> m_Children; // name -> frame
};
}
+52
View File
@@ -0,0 +1,52 @@
#ifndef GUI_TextureFrame_h__
#define GUI_TextureFrame_h__
#include "GUI/Frame.h"
#include "Texture.h"
namespace GUI
{
class TextureFrame : public Frame
{
public:
TextureFrame(std::shared_ptr<Frame> parent, std::string name)
: Frame(parent, name) { }
void Update(double dt) override
{
Frame::Update(dt);
}
void Draw(std::shared_ptr<Renderer> renderer) override
{
if (m_Texture == nullptr)
return;
RenderQueue<SpriteJob> rq;
auto textureAsset = ResourceManager->Load<Texture>("Texture", m_Texture);
SpriteJob job;
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform->Orientation).z, glm::vec3(0, 0, -1));
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position);
*glm::toMat4(orientation2D)
* glm::scale(absoluteTransform.Scale);
EnqueueSprite(spriteQueue, textureAsset, modelMatrix);
}
std::shared_ptr<::Texture> Texture() const { return m_Texture; }
void SetTexture(std::string resourceName)
{
m_Texture = std::shared_ptr<::Texture>(ResourceManager->Load<::Texture>("Texture", resourceName));
}
protected:
std::shared_ptr<::Texture> m_Texture;
};
}
#endif // GUI_TextureFrame_h__
+55 -3
View File
@@ -4,6 +4,11 @@
#include <memory>
#include "GUI/Frame.h"
#include "World.h"
#include "Components/Transform.h"
#include "Components/Camera.h"
#include "RenderQueue.h"
#include "Camera.h"
namespace GUI
{
@@ -11,9 +16,56 @@ namespace GUI
class Viewport : public Frame
{
public:
// Create a frame as a child
Viewport(std::shared_ptr<Frame> parent)
: Frame(parent) { }
Viewport(std::shared_ptr<Frame> parent, std::string name, std::shared_ptr<World> world)
: Frame(parent, name)
, m_World(world)
{ }
EntityID CameraEntity() const { return m_CameraEntity; }
void SetCameraEntity(EntityID cameraEntity)
{
m_CameraEntity = cameraEntity;
auto transformComponent = m_World->GetComponent<Components::Transform>(cameraEntity);
if (!transformComponent)
return;
auto cameraComponent = m_World->GetComponent<Components::Camera>(cameraEntity);
if (!cameraComponent)
return;
m_Camera = std::make_shared<Camera>(cameraComponent->FOV, cameraComponent->NearClip, cameraComponent->FarClip);
}
void Initialize() override
{
}
void Update(double dt) override
{
auto transformComponent = m_World->GetComponent<Components::Transform>(m_CameraEntity);
if (!transformComponent)
return;
auto cameraComponent = m_World->GetComponent<Components::Camera>(m_CameraEntity);
if (!cameraComponent)
return;
m_Camera->SetFOV(cameraComponent->FOV);
m_Camera->SetNearClip(cameraComponent->NearClip);
m_Camera->SetFarClip(cameraComponent->FarClip);
}
void Draw(std::shared_ptr<Renderer> renderer) override
{
renderer->SetCamera(m_Camera);
Frame::Draw(renderer);
}
private:
std::shared_ptr<World> m_World;
std::shared_ptr<Camera> m_Camera;
EntityID m_CameraEntity;
};
}
+144
View File
@@ -0,0 +1,144 @@
#ifndef GUI_WorldFrame_h__
#define GUI_WorldFrame_h__
#include "GUI/Frame.h"
#include "GUI/Viewport.h"
#include "RenderQueue.h"
#include "World.h"
#include "Systems/TransformSystem.h"
#include "Events/SetViewportCamera.h"
#include "Components/Transform.h"
#include "Components/Model.h"
#include "Components/Sprite.h"
#include "Components/PointLight.h"
namespace GUI
{
class WorldFrame : public Frame
{
public:
WorldFrame(std::shared_ptr<Frame> parent, std::string name, std::shared_ptr<World> world)
: Frame(parent, name)
, m_World(world)
{ }
void Initialize() override
{
EVENT_SUBSCRIBE_MEMBER(m_ESetViewportCamera, &WorldFrame::OnSetViewportCamera);
m_World->Initialize();
}
void Update(double dt) override
{
m_World->Update(dt);
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
}
void Draw(std::shared_ptr<Renderer> renderer) override
{
renderer->Flush();
RenderQueue<ModelJob> modelQueue;
RenderQueue<SpriteJob> spriteQueue;
for (auto &pair : *m_World->GetEntities())
{
EntityID entity = pair.first;
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (!transform)
continue;
auto modelComponent = m_World->GetComponent<Components::Model>(entity);
if (modelComponent)
{
auto modelAsset = ResourceManager->Load<Model>("Model", modelComponent->ModelFile);
if (modelAsset)
{
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
glm::mat4 modelMatrix = glm::translate(glm::mat4(), absoluteTransform.Position)
* glm::toMat4(absoluteTransform.Orientation)
* glm::scale(absoluteTransform.Scale);
EnqueueModel(modelQueue, modelAsset, modelMatrix);
}
}
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
if (spriteComponent)
{
auto textureAsset = ResourceManager->Load<Texture>("Texture", spriteComponent->SpriteFile);
if (textureAsset)
{
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform->Orientation).z, glm::vec3(0, 0, -1));
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position);
* glm::toMat4(orientation2D)
* glm::scale(absoluteTransform.Scale);
EnqueueSprite(spriteQueue, textureAsset, modelMatrix);
}
}
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
if (pointLightComponent)
{
// TODO: Push lights to renderer
// renderer->PushLight(...);
}
}
renderer->PushQueue(rq);
Frame::Draw(renderer);
}
protected:
std::shared_ptr<World> m_World;
private:
EventRelay<Frame, Events::SetViewportCamera> m_ESetViewportCamera;
bool OnSetViewportCamera(const Events::SetViewportCamera &event)
{
auto itpair = m_Children.equal_range(event.ViewportFrame);
for (auto it = itpair.first; it != itpair.second; ++it)
{
auto viewportFrame = std::dynamic_pointer_cast<GUI::Viewport>(it->second);
if (!viewportFrame)
continue;
viewportFrame->SetCamera(event.CameraEntity);
}
}
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
void EnqueueModel(RenderQueue<ModelJob> &renderQueue, Model* model, glm::mat4 modelMatrix)
{
for (auto texGroup : model->TextureGroups)
{
ModelJob job;
job.TextureID = texGroup.Texture->ResourceID;
job.DiffuseTexture = *texGroup.Texture;
job.NormalTexture = *texGroup.NormalMap;
job.SpecularTexture = *texGroup.SpecularMap;
job.VAO = model->VAO;
job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = modelMatrix;
renderQueue.Add(job);
}
}
void EnqueueSprite(RenderQueue<SpriteJob> &renderQueue, Texture* texture, glm::mat4 modelMatrix)
{
SpriteJob job;
job.TextureID = texture->ResourceID;
job.Texture = *texture;
job.ModelMatrix = modelMatrix;
}
};
}
#endif // GUI_WorldFrame_h__
+35 -16
View File
@@ -12,24 +12,13 @@ class RenderQueue;
struct RenderJob
{
friend class RenderQueue;
unsigned int Layer;
unsigned int ViewportID;
unsigned int TextureID;
GLuint DiffuseTexture;
GLuint NormalTexture;
GLuint SpecularTexture;
GLuint VAO;
unsigned int StartIndex;
unsigned int EndIndex;
glm::mat4 ModelMatrix;
template <typename JobType>
friend class RenderQueue<JobType>;
protected:
uint64_t Hash;
void CalculateHash()
virtual void CalculateHash() = 0;
{
Hash = ViewportID << 58 // 6 bits
| TextureID << 42; // 16 bits
@@ -41,10 +30,40 @@ protected:
}
};
struct ModelJob : RenderJob
{
unsigned int TextureID;
GLuint DiffuseTexture;
GLuint NormalTexture;
GLuint SpecularTexture;
GLuint VAO;
unsigned int StartIndex;
unsigned int EndIndex;
glm::mat4 ModelMatrix;
void CalculateHash() override
{
Hash = TextureID;
}
};
struct SpriteJob : RenderJob
{
unsigned int TextureID;
GLuint Texture;
glm::mat4 ModelMatrix;
void CalculateHash() override
{
Hash = TextureID;
}
};
template <typename JobType>
class RenderQueue
{
public:
void Add(RenderJob &job)
void Add(JobType &job)
{
job.CalculateHash();
m_Jobs.push_front(job);
@@ -57,7 +76,7 @@ public:
}
private:
std::forward_list<RenderJob> m_Jobs;
std::forward_list<JobType> m_Jobs;
};
#endif // RenderQueue_h__
+5 -5
View File
@@ -372,10 +372,10 @@ void Renderer::AddTextureToDraw(Texture* texture, glm::vec3 position, glm::quat
}
void Renderer::AddPointLightToDraw(
glm::vec3 _position,
glm::vec3 _specular,
glm::vec3 _diffuse,
float _specularExponent,
glm::vec3 _position,
glm::vec3 _specular,
glm::vec3 _diffuse,
float _specularExponent,
float _ConstantAttenuation,
float _LinearAttenuation,
float _QuadraticAttenuation
@@ -826,7 +826,7 @@ void Renderer::DrawLightScene(Viewport &viewport)
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), LAtt);
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), QAtt);
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
};
glEnable (GL_DEPTH_TEST);
glDepthMask (GL_TRUE);
+1 -2
View File
@@ -88,14 +88,13 @@ public:
std::unordered_map<EntityID, EntityID>* GetEntities() { return &m_EntityParents; }
ResourceManager* GetResourceManager() { return &m_ResourceManager; }
//ResourceManager* GetResourceManager() { return &m_ResourceManager; }
std::shared_ptr<::EventBroker> EventBroker() { return m_EventBroker; }
protected:
std::shared_ptr<::EventBroker> m_EventBroker;
SystemFactory m_SystemFactory;
ComponentFactory m_ComponentFactory;
ResourceManager m_ResourceManager;
std::unordered_map<std::string, std::shared_ptr<System>> m_Systems;
+3 -1
View File
@@ -1,6 +1,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.30110.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Returngeance", "Returngeance\Returngeance.vcxproj", "{E8B4A2A2-882B-402A-98A7-8B4F7233C8B3}"
EndProject
Project("{F088123C-0E9E-452A-89E6-6BA2F21D5CAC}") = "ModelingProject1", "ModelingProject1\ModelingProject1.modelproj", "{B35F204C-3377-457E-AC9E-D9606F421191}"
+3
View File
@@ -174,11 +174,14 @@
<ClInclude Include="..\..\src\Events\MouseRelease.h" />
<ClInclude Include="..\..\src\Events\PlaySound.h" />
<ClInclude Include="..\..\src\Events\SetVelocity.h" />
<ClInclude Include="..\..\src\Events\SetViewportCamera.h" />
<ClInclude Include="..\..\src\Events\TankSteer.h" />
<ClInclude Include="..\..\src\Factory.h" />
<ClInclude Include="..\..\src\GameWorld.h" />
<ClInclude Include="..\..\src\GUI\Frame.h" />
<ClInclude Include="..\..\src\EventBroker.h" />
<ClInclude Include="..\..\src\GUI\WorldFrame.h" />
<ClInclude Include="..\..\src\GUI\TextureFrame.h" />
<ClInclude Include="..\..\src\GUI\Viewport.h" />
<ClInclude Include="..\..\src\InputController.h" />
<ClInclude Include="..\..\src\InputManager.h" />
@@ -158,6 +158,9 @@
<Filter Include="Gameplay\Components">
<UniqueIdentifier>{cb06b441-90b8-46ed-b347-4190dac7185b}</UniqueIdentifier>
</Filter>
<Filter Include="Rendering\Events">
<UniqueIdentifier>{a025d51e-594d-4844-983b-f683726bf1bf}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\World.h" />
@@ -397,6 +400,15 @@
<ClInclude Include="..\..\src\Components\Player.h">
<Filter>Gameplay\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\GUI\TextureFrame.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="..\..\src\GUI\WorldFrame.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\SetViewportCamera.h">
<Filter>Rendering\Events</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\src\Shaders\Fragment2.glsl">