Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b9e2d6b96a | |||
| 062242ab8e | |||
| e4e5068727 | |||
| 14feb3659b | |||
| 04cb1f1204 | |||
| d13c19d654 | |||
| 1bd914991a | |||
| 3470a80f40 |
Submodule
+1
Submodule libs/GWEN added at d6ffea4dba
+18
-9
@@ -2,7 +2,8 @@
|
||||
#include "Camera.h"
|
||||
|
||||
Camera::Camera(float yFOV, float aspectRatio, float nearClip, float farClip)
|
||||
{ m_FOV = yFOV;
|
||||
{
|
||||
m_FOV = yFOV;
|
||||
m_AspectRatio = aspectRatio;
|
||||
m_NearClip = nearClip;
|
||||
m_FarClip = farClip;
|
||||
@@ -34,18 +35,21 @@ Camera::Camera(float yFOV, float aspectRatio, float nearClip, float farClip)
|
||||
//}
|
||||
|
||||
void Camera::AspectRatio(float val)
|
||||
{ m_AspectRatio = val;
|
||||
{
|
||||
m_AspectRatio = val;
|
||||
UpdateProjectionMatrix();
|
||||
}
|
||||
|
||||
void Camera::Position(glm::vec3 val)
|
||||
{ m_Position = val;
|
||||
{
|
||||
m_Position = val;
|
||||
UpdateViewMatrix();
|
||||
}
|
||||
|
||||
|
||||
void Camera::Orientation(glm::quat val)
|
||||
{ m_Orientation = val;
|
||||
{
|
||||
m_Orientation = val;
|
||||
UpdateViewMatrix();
|
||||
}
|
||||
|
||||
@@ -62,7 +66,8 @@ void Camera::Orientation(glm::quat val)
|
||||
//}
|
||||
|
||||
void Camera::UpdateProjectionMatrix()
|
||||
{ m_ProjectionMatrix = glm::perspective(
|
||||
{
|
||||
m_ProjectionMatrix = glm::perspective(
|
||||
m_FOV,
|
||||
m_AspectRatio,
|
||||
m_NearClip,
|
||||
@@ -71,20 +76,24 @@ void Camera::UpdateProjectionMatrix()
|
||||
}
|
||||
|
||||
void Camera::UpdateViewMatrix()
|
||||
{ m_ViewMatrix = glm::translate(glm::toMat4(m_Orientation), -m_Position);
|
||||
{
|
||||
m_ViewMatrix = glm::translate(glm::toMat4(m_Orientation), -m_Position);
|
||||
}
|
||||
|
||||
void Camera::FOV(float val)
|
||||
{ m_FOV = val;
|
||||
{
|
||||
m_FOV = val;
|
||||
UpdateProjectionMatrix();
|
||||
}
|
||||
|
||||
void Camera::NearClip(float val)
|
||||
{ m_NearClip = val;
|
||||
{
|
||||
m_NearClip = val;
|
||||
UpdateProjectionMatrix();
|
||||
}
|
||||
|
||||
void Camera::FarClip(float val)
|
||||
{ m_FarClip = val;
|
||||
{
|
||||
m_FarClip = val;
|
||||
UpdateProjectionMatrix();
|
||||
}
|
||||
+2
-1
@@ -2,7 +2,8 @@
|
||||
#define Color_h__
|
||||
|
||||
struct Color
|
||||
{ float r;
|
||||
{
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
};
|
||||
|
||||
+2
-1
@@ -5,7 +5,8 @@
|
||||
#include "Entity.h"
|
||||
|
||||
struct Component
|
||||
{ EntityID Entity;
|
||||
{
|
||||
EntityID Entity;
|
||||
};
|
||||
|
||||
class ComponentFactory : public Factory<Component*> { };
|
||||
|
||||
@@ -7,7 +7,8 @@ namespace Components
|
||||
{
|
||||
// http://bulletphysics.org/mediawiki-1.5.8/index.php/Constraints
|
||||
struct BallSocketConstraint : Component
|
||||
{ // Create constraint between these entities
|
||||
{
|
||||
// Create constraint between these entities
|
||||
EntityID EntityA;
|
||||
EntityID EntityB;
|
||||
// The pivot point in local coordinates
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
#ifndef Components_Bounds_h__
|
||||
#define Components_Bounds_h__
|
||||
|
||||
#include "Component.h"
|
||||
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct Bounds : Component
|
||||
{ //Axis Aligned Bounding Box
|
||||
glm::vec3 Origin;
|
||||
glm::vec3 VolumeVector; //The vector that defines the volume of the BB, it goes from one corner to the opposite one
|
||||
};
|
||||
|
||||
}
|
||||
#endif // !Components_Bounds_h__
|
||||
@@ -7,7 +7,8 @@ namespace Components
|
||||
{
|
||||
|
||||
struct BoxShape : Component
|
||||
{ float Height;
|
||||
{
|
||||
float Height;
|
||||
float Width;
|
||||
float Depth;
|
||||
};
|
||||
|
||||
@@ -7,7 +7,8 @@ namespace Components
|
||||
{
|
||||
|
||||
struct Camera : Component
|
||||
{ Camera() : FOV(glm::radians(45.f)), NearClip(0.1f), FarClip(100.f) { }
|
||||
{
|
||||
Camera() : FOV(glm::radians(45.f)), NearClip(0.1f), FarClip(100.f) { }
|
||||
|
||||
float FOV;
|
||||
float NearClip;
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef Components_Collision_h__
|
||||
#define Components_Collision_h__
|
||||
|
||||
#include "Entity.h"
|
||||
#include "Component.h"
|
||||
#include <vector>
|
||||
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct Collision : Component
|
||||
{ Collision() : Phantom(false), Interested(false) { }
|
||||
|
||||
bool Phantom;
|
||||
bool Interested;
|
||||
std::vector<EntityID> CollidingEntities;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // !Components_Collision_h__
|
||||
@@ -8,7 +8,8 @@ namespace Components
|
||||
{
|
||||
|
||||
struct CustomShape : Component
|
||||
{ std::string fileName;
|
||||
{
|
||||
std::string fileName;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ namespace Components
|
||||
{
|
||||
|
||||
struct DirectionalLight : Component
|
||||
{ float Intensity;
|
||||
{
|
||||
float Intensity;
|
||||
float MaxRange;
|
||||
float SpecularIntensity;
|
||||
Color Color;
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
namespace Components
|
||||
{
|
||||
struct FreeSteering : Component
|
||||
{ float Speed = 35;
|
||||
{
|
||||
float Speed = 35;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ namespace Components
|
||||
{
|
||||
// http://bulletphysics.org/mediawiki-1.5.8/index.php/Constraints
|
||||
struct HingeConstraint : Component
|
||||
{ // Create constraint between these entities
|
||||
{
|
||||
// Create constraint between these entities
|
||||
EntityID EntityA;
|
||||
EntityID EntityB;
|
||||
// The pivot point in local coordinates
|
||||
|
||||
@@ -11,7 +11,8 @@ namespace Components
|
||||
{
|
||||
|
||||
struct Input : Component
|
||||
{ std::array<int, GLFW_KEY_LAST+1> KeyState;
|
||||
{
|
||||
std::array<int, GLFW_KEY_LAST+1> KeyState;
|
||||
std::array<int, GLFW_KEY_LAST+1> LastKeyState;
|
||||
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> MouseState;
|
||||
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> LastMouseState;
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
namespace Components
|
||||
{
|
||||
struct MeshShape : Component
|
||||
{ std::string Filename;
|
||||
{
|
||||
std::string Filename;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace Components
|
||||
{
|
||||
|
||||
struct Model : Component
|
||||
{ Model() : Visible(true), ShadowCaster(true) { }
|
||||
{
|
||||
Model() : Visible(true), ShadowCaster(true) { }
|
||||
std::string ModelFile;
|
||||
Color Color;
|
||||
bool Visible;
|
||||
|
||||
@@ -9,7 +9,8 @@ namespace Components
|
||||
{
|
||||
|
||||
struct ParticleEmitter : Component
|
||||
{ int ParticleTemplate;
|
||||
{
|
||||
int ParticleTemplate;
|
||||
float SpawnFrequency;
|
||||
int SpawnCount;
|
||||
std::vector<Color> ColorSpectrum;
|
||||
|
||||
@@ -7,7 +7,8 @@ namespace Components
|
||||
{
|
||||
|
||||
struct Physics : Component
|
||||
{ float Mass = 0;
|
||||
{
|
||||
float Mass = 0;
|
||||
float Friction = 0;
|
||||
glm::vec3 Gravity = glm::vec3(0, -9.82f, 0);
|
||||
};
|
||||
|
||||
@@ -8,7 +8,8 @@ namespace Components
|
||||
{
|
||||
|
||||
struct PointLight : Component
|
||||
{ float Intensity;
|
||||
{
|
||||
float Intensity;
|
||||
float MaxRange;
|
||||
glm::vec3 Specular;
|
||||
glm::vec3 Diffuse;
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifndef Components_PowerUp_h__
|
||||
#define Components_PowerUp_h__
|
||||
|
||||
#include "Component.h"
|
||||
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct PowerUp : Component
|
||||
{ float Speed;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // !Components_PowerUp_h__
|
||||
@@ -7,7 +7,8 @@ namespace Components
|
||||
{
|
||||
// http://bulletphysics.org/mediawiki-1.5.8/index.php/Constraints
|
||||
struct SliderConstraint : Component
|
||||
{ // Create constraint between these entities
|
||||
{
|
||||
// Create constraint between these entities
|
||||
EntityID EntityA;
|
||||
EntityID EntityB;
|
||||
};
|
||||
|
||||
@@ -9,7 +9,8 @@ namespace Components
|
||||
{
|
||||
|
||||
struct SoundEmitter : Component
|
||||
{ float Gain = 1.f;
|
||||
{
|
||||
float Gain = 1.f;
|
||||
float MaxDistance = 1.f;
|
||||
float ReferenceDistance = 1.f;
|
||||
float Pitch = 1.f;
|
||||
|
||||
@@ -7,7 +7,8 @@ namespace Components
|
||||
{
|
||||
|
||||
struct SphereShape : Component
|
||||
{ float Radius;
|
||||
{
|
||||
float Radius;
|
||||
float RollingFriction;
|
||||
};
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace Components
|
||||
{
|
||||
|
||||
struct Sprite : Component
|
||||
{ std::string SpriteFile;
|
||||
{
|
||||
std::string SpriteFile;
|
||||
Color Color;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifndef Components_Stat_h__
|
||||
#define Components_Stat_h__
|
||||
|
||||
#include "Component.h"
|
||||
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct Stat : Component
|
||||
{ float Health;
|
||||
bool Destroyable;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // !Components_Stat_h__
|
||||
@@ -6,7 +6,8 @@
|
||||
namespace Components
|
||||
{
|
||||
struct StaticMeshShape : Component
|
||||
{ std::string Filename;
|
||||
{
|
||||
std::string Filename;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ namespace Components
|
||||
{
|
||||
|
||||
struct Transform : Component
|
||||
{ Transform()
|
||||
{
|
||||
Transform()
|
||||
: Scale(glm::vec3(1.f)) { }
|
||||
|
||||
glm::vec3 Position;
|
||||
|
||||
+14
-7
@@ -2,7 +2,8 @@
|
||||
#include "CubemapTexture.h"
|
||||
|
||||
CubemapTexture::CubemapTexture(std::string posXFile, std::string negXFile, std::string posYFile, std::string negYFile, std::string posZFile, std::string negZFile)
|
||||
{ m_Loaded = false;
|
||||
{
|
||||
m_Loaded = false;
|
||||
m_Texture = 0;
|
||||
m_TextureFiles[0] = posXFile;
|
||||
m_TextureFiles[1] = negXFile;
|
||||
@@ -13,13 +14,16 @@ CubemapTexture::CubemapTexture(std::string posXFile, std::string negXFile, std::
|
||||
}
|
||||
|
||||
CubemapTexture::~CubemapTexture()
|
||||
{ if (m_Texture != 0)
|
||||
{ //glDeleteTextures(1, &m_Texture);
|
||||
{
|
||||
if (m_Texture != 0)
|
||||
{
|
||||
//glDeleteTextures(1, &m_Texture);
|
||||
}
|
||||
}
|
||||
|
||||
void CubemapTexture::Load()
|
||||
{ m_Loaded = true;
|
||||
{
|
||||
m_Loaded = true;
|
||||
|
||||
m_Texture = SOIL_load_OGL_cubemap(
|
||||
m_TextureFiles[0].c_str(),
|
||||
@@ -33,7 +37,8 @@ void CubemapTexture::Load()
|
||||
0);
|
||||
|
||||
if (m_Texture == 0)
|
||||
{ LOG_ERROR("SOIL cubemap loading error: %s", SOIL_last_result());
|
||||
{
|
||||
LOG_ERROR("SOIL cubemap loading error: %s", SOIL_last_result());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,8 +50,10 @@ void CubemapTexture::Load()
|
||||
}
|
||||
|
||||
void CubemapTexture::Bind(GLenum textureUnit)
|
||||
{ if (!m_Loaded)
|
||||
{ LOG_WARNING("Cubemap \"%s\" was not loaded before being bound! Attempting to load now...", m_TextureFiles[0].c_str());
|
||||
{
|
||||
if (!m_Loaded)
|
||||
{
|
||||
LOG_WARNING("Cubemap \"%s\" was not loaded before being bound! Attempting to load now...", m_TextureFiles[0].c_str());
|
||||
Load();
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -8,7 +8,8 @@ class Engine
|
||||
{
|
||||
public:
|
||||
Engine(int argc, char* argv[])
|
||||
{ m_Renderer = std::make_shared<Renderer>();
|
||||
{
|
||||
m_Renderer = std::make_shared<Renderer>();
|
||||
m_Renderer->Initialize();
|
||||
|
||||
m_World = std::make_shared<GameWorld>(m_Renderer);
|
||||
@@ -20,7 +21,8 @@ public:
|
||||
bool Running() const { return !glfwWindowShouldClose(m_Renderer->GetWindow()); }
|
||||
|
||||
void Tick()
|
||||
{ double currentTime = glfwGetTime();
|
||||
{
|
||||
double currentTime = glfwGetTime();
|
||||
double dt = currentTime - m_LastTime;
|
||||
m_LastTime = currentTime;
|
||||
|
||||
|
||||
+8
-4
@@ -11,16 +11,20 @@ class Factory
|
||||
{
|
||||
public:
|
||||
void Register(std::string name, std::function<T(void)> factoryFunction)
|
||||
{ m_FactoryFunctions[name] = factoryFunction;
|
||||
{
|
||||
m_FactoryFunctions[name] = factoryFunction;
|
||||
}
|
||||
|
||||
T Create(std::string name)
|
||||
{ auto it = m_FactoryFunctions.find(name);
|
||||
{
|
||||
auto it = m_FactoryFunctions.find(name);
|
||||
if (it != m_FactoryFunctions.end())
|
||||
{ return it->second();
|
||||
{
|
||||
return it->second();
|
||||
}
|
||||
else
|
||||
{ return nullptr;
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+26
-43
@@ -2,9 +2,16 @@
|
||||
#include "GameWorld.h"
|
||||
|
||||
void GameWorld::Initialize()
|
||||
{ World::Initialize();
|
||||
{
|
||||
World::Initialize();
|
||||
|
||||
{ auto camera = CreateEntity();
|
||||
m_ResourceManager.Preload("Model", "Models/Placeholders/PhysicsTest/Plane.obj");
|
||||
m_ResourceManager.Preload("Model", "Models/Placeholders/PhysicsTest/ArrowCube.obj");
|
||||
|
||||
RegisterComponents();
|
||||
|
||||
{
|
||||
auto camera = CreateEntity();
|
||||
auto transform = AddComponent<Components::Transform>(camera, "Transform");
|
||||
transform->Position.z = 20.f;
|
||||
transform->Position.y = 20.f;
|
||||
@@ -15,7 +22,8 @@ void GameWorld::Initialize()
|
||||
auto freeSteering = AddComponent<Components::FreeSteering>(camera, "FreeSteering");
|
||||
}
|
||||
|
||||
{ auto terrain = CreateEntity();
|
||||
{
|
||||
auto terrain = CreateEntity();
|
||||
auto transform = AddComponent<Components::Transform>(terrain, "Transform");
|
||||
transform->Position = glm::vec3(0, -5, 0);
|
||||
transform->Scale = glm::vec3(1000.0f, 1, 1000.0f);
|
||||
@@ -37,7 +45,8 @@ void GameWorld::Initialize()
|
||||
|
||||
|
||||
for (int i = 0; i < 1; i++)
|
||||
{ auto entity = CreateEntity();
|
||||
{
|
||||
auto entity = CreateEntity();
|
||||
auto transform = AddComponent<Components::Transform>(entity, "Transform");
|
||||
transform->Scale = glm::vec3(1.0f);
|
||||
transform->Position = glm::vec3(0, 10+i, 0);
|
||||
@@ -53,8 +62,8 @@ void GameWorld::Initialize()
|
||||
box->Depth = 0.5;
|
||||
|
||||
|
||||
{ auto entity1 = CreateEntity();
|
||||
|
||||
{
|
||||
auto entity1 = CreateEntity();
|
||||
|
||||
|
||||
auto transform = AddComponent<Components::Transform>(entity1, "Transform");
|
||||
@@ -90,7 +99,8 @@ void GameWorld::Initialize()
|
||||
|
||||
}
|
||||
|
||||
{ auto entity = CreateEntity();
|
||||
{
|
||||
auto entity = CreateEntity();
|
||||
AddComponent(entity, "Transform");
|
||||
auto emitter = AddComponent<Components::SoundEmitter>(entity, "SoundEmitter");
|
||||
emitter->Path = "Sounds/korvring.wav";
|
||||
@@ -102,39 +112,19 @@ void GameWorld::Initialize()
|
||||
}
|
||||
|
||||
void GameWorld::Update(double dt)
|
||||
{ World::Update(dt);
|
||||
{
|
||||
World::Update(dt);
|
||||
}
|
||||
|
||||
void GameWorld::RegisterComponents()
|
||||
{ m_ComponentFactory.Register("Bounds", []() { return new Components::Bounds(); });
|
||||
m_ComponentFactory.Register("Camera", []() { return new Components::Camera(); });
|
||||
m_ComponentFactory.Register("Collision", []() { return new Components::Collision(); });
|
||||
m_ComponentFactory.Register("DirectionalLight", []() { return new Components::DirectionalLight(); });
|
||||
m_ComponentFactory.Register("Input", []() { return new Components::Input(); });
|
||||
m_ComponentFactory.Register("Model", []() { return new Components::Model(); });
|
||||
m_ComponentFactory.Register("ParticleEmitter", []() { return new Components::ParticleEmitter(); });
|
||||
m_ComponentFactory.Register("PointLight", []() { return new Components::PointLight(); });
|
||||
m_ComponentFactory.Register("SoundEmitter", []() { return new Components::SoundEmitter(); });
|
||||
m_ComponentFactory.Register("Sprite", []() { return new Components::Sprite(); });
|
||||
m_ComponentFactory.Register("Template", []() { return new Components::Template(); });
|
||||
m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); });
|
||||
m_ComponentFactory.Register("FreeSteering", []() { return new Components::FreeSteering(); });
|
||||
|
||||
m_ComponentFactory.Register("Physics", []() { return new Components::Physics(); });
|
||||
m_ComponentFactory.Register("CompoundShape", []() { return new Components::CompoundShape(); });
|
||||
m_ComponentFactory.Register("SphereShape", []() { return new Components::SphereShape(); });
|
||||
m_ComponentFactory.Register("BoxShape", []() { return new Components::BoxShape(); });
|
||||
|
||||
m_ComponentFactory.Register("HingeConstraint", []() { return new Components::HingeConstraint(); });
|
||||
m_ComponentFactory.Register("BallSocketConstraint", []() { return new Components::BallSocketConstraint(); });
|
||||
m_ComponentFactory.Register("SliderConstraint", []() { return new Components::SliderConstraint(); });
|
||||
|
||||
m_ComponentFactory.Register("Vehicle", []() { return new Components::Vehicle(); });
|
||||
m_ComponentFactory.Register("Wheel", []() { return new Components::Wheel(); });
|
||||
{
|
||||
m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); });
|
||||
m_ComponentFactory.Register("Template", []() { return new Components::Template(); });
|
||||
}
|
||||
|
||||
void GameWorld::RegisterSystems()
|
||||
{ m_SystemFactory.Register("TransformSystem", [this]() { return new Systems::TransformSystem(this); });
|
||||
{
|
||||
m_SystemFactory.Register("TransformSystem", [this]() { return new Systems::TransformSystem(this); });
|
||||
//m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); });
|
||||
m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_Renderer); });
|
||||
//m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); });
|
||||
@@ -142,16 +132,13 @@ void GameWorld::RegisterSystems()
|
||||
//m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); });
|
||||
m_SystemFactory.Register("FreeSteeringSystem", [this]() { return new Systems::FreeSteeringSystem(this); });
|
||||
m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this); });
|
||||
|
||||
m_SystemFactory.Register("PhysicsSystem", [this]() { return new Systems::PhysicsSystem(this); });
|
||||
|
||||
m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_Renderer); });
|
||||
|
||||
|
||||
}
|
||||
|
||||
void GameWorld::AddSystems()
|
||||
{ AddSystem("TransformSystem");
|
||||
{
|
||||
AddSystem("TransformSystem");
|
||||
//AddSystem("LevelGenerationSystem");
|
||||
AddSystem("InputSystem");
|
||||
//AddSystem("CollisionSystem");
|
||||
@@ -159,10 +146,6 @@ void GameWorld::AddSystems()
|
||||
//AddSystem("PlayerSystem");
|
||||
AddSystem("FreeSteeringSystem");
|
||||
AddSystem("SoundSystem");
|
||||
|
||||
AddSystem("PhysicsSystem");
|
||||
|
||||
AddSystem("RenderSystem");
|
||||
|
||||
|
||||
}
|
||||
@@ -15,18 +15,14 @@
|
||||
#include "Systems/SoundSystem.h"
|
||||
#include "Systems/PhysicsSystem.h"
|
||||
|
||||
#include "Components/Bounds.h"
|
||||
#include "Components/Camera.h"
|
||||
#include "Components/Collision.h"
|
||||
#include "Components/DirectionalLight.h"
|
||||
#include "Components/Input.h"
|
||||
#include "Components/Model.h"
|
||||
#include "Components/ParticleEmitter.h"
|
||||
#include "Components/PointLight.h"
|
||||
#include "Components/PowerUp.h"
|
||||
#include "Components/SoundEmitter.h"
|
||||
#include "Components/Sprite.h"
|
||||
#include "Components/Stat.h"
|
||||
#include "Components/Template.h"
|
||||
#include "Components/Transform.h"
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef GwenRenderer_h__
|
||||
#define GwenRenderer_h__
|
||||
|
||||
#include <Gwen/Gwen.h>
|
||||
#include <Gwen/BaseRender.h>
|
||||
|
||||
#include "Renderer.h"
|
||||
|
||||
class GwenRenderer : public Gwen::Renderer::Base
|
||||
{
|
||||
public:
|
||||
GwenRenderer(Renderer* renderer)
|
||||
: m_Renderer(renderer) { }
|
||||
|
||||
void Begin() override;
|
||||
void End() override;
|
||||
|
||||
void SetDrawColor(Gwen::Color color) override;
|
||||
void DrawFilledRect(Gwen::Rect rect) override;
|
||||
|
||||
void StartClip() override;
|
||||
void EndClip() override;
|
||||
|
||||
void DrawTexturedRect(Gwen::Texture* pTexture, Gwen::Rect pTargetRect, float u1 = 0.0f, float v1 = 0.0f, float u2 = 1.0f, float v2 = 1.0f) override;
|
||||
void LoadTexture(Gwen::Texture* pTexture) override;
|
||||
void FreeTexture(Gwen::Texture* pTexture) override;
|
||||
Gwen::Color PixelColour(Gwen::Texture* pTexture, unsigned int x, unsigned int y, const Gwen::Color & col_default) override;
|
||||
|
||||
void LoadFont(Gwen::Font* pFont) override;
|
||||
void FreeFont(Gwen::Font* pFont) override;
|
||||
void RenderText(Gwen::Font* pFont, Gwen::Point pos, const Gwen::UnicodeString & text) override;
|
||||
Gwen::Point MeasureText(Gwen::Font* pFont, const Gwen::UnicodeString & text) override;
|
||||
|
||||
private:
|
||||
Renderer* m_Renderer;
|
||||
|
||||
Gwen::Color m_Color;
|
||||
};
|
||||
#endif // GwenRenderer_h__
|
||||
+33
-140
@@ -1,25 +1,24 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Model.h"
|
||||
|
||||
Model::Model(const char* path)
|
||||
{ Loadobj(path, Vertices, Normals, TextureCoords);
|
||||
CreateBuffers(Vertices, Normals, TextureCoords);
|
||||
}
|
||||
|
||||
Model::Model(OBJ &obj)
|
||||
{ OBJ::MaterialInfo* currentMaterial = nullptr;
|
||||
Model::Model(OBJ &obj, ResourceManager* rm)
|
||||
{
|
||||
OBJ::MaterialInfo* currentMaterial = nullptr;
|
||||
TextureGroup* currentTexGroup = nullptr;
|
||||
int index = 0;
|
||||
for (auto face : obj.Faces)
|
||||
{ if (face.Material == nullptr)
|
||||
{ LOG_ERROR("Missing material for .obj file \"%s\"", obj.Path().string().c_str());
|
||||
{
|
||||
if (face.Material == nullptr)
|
||||
{
|
||||
LOG_ERROR("Missing material for .obj file \"%s\"", obj.Path().string().c_str());
|
||||
return;
|
||||
}
|
||||
// New material
|
||||
if (face.Material != currentMaterial)
|
||||
{ currentMaterial = face.Material;
|
||||
{
|
||||
currentMaterial = face.Material;
|
||||
// Load texture
|
||||
std::shared_ptr<Texture> texture = std::make_shared<Texture>(currentMaterial->TextureFile);
|
||||
auto texture = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", currentMaterial->TextureFile));
|
||||
// TODO: Load material parameters
|
||||
// Create new texture group (start index of new group is upcoming index)
|
||||
TextureGroup texGroup = { texture, index, index };
|
||||
@@ -29,18 +28,21 @@ Model::Model(OBJ &obj)
|
||||
|
||||
// Face definitions
|
||||
for (auto faceDef : face.Definitions)
|
||||
{ glm::vec3 vertex;
|
||||
{
|
||||
glm::vec3 vertex;
|
||||
std::tie(vertex.x, vertex.y, vertex.z) = obj.Vertices.at(faceDef.VertexIndex - 1);
|
||||
Vertices.push_back(vertex);
|
||||
|
||||
if (faceDef.NormalIndex != 0)
|
||||
{ glm::vec3 normal;
|
||||
{
|
||||
glm::vec3 normal;
|
||||
std::tie(normal.x, normal.y, normal.z) = obj.Normals.at(faceDef.NormalIndex - 1);
|
||||
Normals.push_back(normal);
|
||||
}
|
||||
|
||||
if (faceDef.TextureCoordIndex != 0)
|
||||
{ glm::vec2 texCoord;
|
||||
{
|
||||
glm::vec2 texCoord;
|
||||
// TODO: W-coord?
|
||||
std::tie(texCoord.x, texCoord.y, std::ignore) = obj.TextureCoords.at(faceDef.TextureCoordIndex - 1);
|
||||
TextureCoords.push_back(texCoord);
|
||||
@@ -52,165 +54,56 @@ Model::Model(OBJ &obj)
|
||||
}
|
||||
|
||||
if (Vertices.size() > 0)
|
||||
{ CreateBuffers(Vertices, Normals, TextureCoords);
|
||||
}
|
||||
}
|
||||
|
||||
bool Model::Loadobj(const char* path, std::vector <glm::vec3> &out_vertices, std::vector <glm::vec3> &out_normals, std::vector <glm::vec2> &out_TextureCoords)
|
||||
{ std::vector< unsigned int > vertexIndices, TextureCoordIndices, normalIndices;
|
||||
std::vector< glm::vec3 > temp_vertices;
|
||||
std::vector< glm::vec2 > temp_TextureCoords;
|
||||
std::vector< glm::vec3 > temp_normals;
|
||||
|
||||
FILE* file = fopen(path, "r");
|
||||
LOG_INFO("Loading .obj file");
|
||||
if( file == NULL )
|
||||
{ LOG_INFO("Load .obj file: failed");
|
||||
return false;
|
||||
}
|
||||
char lineHeader[512];
|
||||
|
||||
while(true)
|
||||
{
|
||||
|
||||
//read the first word of the line
|
||||
int res = fscanf(file, "%s", lineHeader);
|
||||
|
||||
if( res == EOF ) // EOF - End Of File
|
||||
{ for( unsigned int i = 0; i < vertexIndices.size(); i++ )
|
||||
{ unsigned int vertexIndex = vertexIndices[i];
|
||||
glm::vec3 vertex = temp_vertices[ vertexIndex-1];
|
||||
out_vertices.push_back(vertex);
|
||||
|
||||
}
|
||||
|
||||
for( unsigned int i = 0; i < TextureCoordIndices.size(); i++ )
|
||||
{ unsigned int TextureCoordIndex = TextureCoordIndices[i];
|
||||
glm::vec2 TextureCoord = temp_TextureCoords[ TextureCoordIndex-1];
|
||||
out_TextureCoords.push_back(TextureCoord);
|
||||
}
|
||||
|
||||
for( unsigned int i = 0; i < normalIndices.size(); i++ )
|
||||
{ unsigned int normalIndex = normalIndices[i];
|
||||
glm::vec3 normal = temp_normals[ normalIndex-1];
|
||||
out_normals.push_back(normal);
|
||||
}
|
||||
|
||||
|
||||
LOG_INFO("Model Loaded\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if( strcmp( lineHeader, "v" ) == 0 ) // vertex
|
||||
{ glm::vec3 vertex;
|
||||
fscanf(file, "%f %f %f\n", &vertex.x, &vertex.y, &vertex.z);
|
||||
temp_vertices.push_back(vertex);
|
||||
}
|
||||
else if ( strcmp( lineHeader, "vt" ) == 0 ) // texture coordinate
|
||||
{ glm::vec2 TextureCoord;
|
||||
fscanf(file, "%f %f\n", &TextureCoord.x, &TextureCoord.y );
|
||||
temp_TextureCoords.push_back(TextureCoord);
|
||||
}
|
||||
else if( strcmp( lineHeader, "vn" ) == 0 ) // normal
|
||||
{ glm::vec3 normal;
|
||||
fscanf(file, "%f %f %f\n", &normal.x, &normal.y, &normal.z );
|
||||
temp_normals.push_back(normal);
|
||||
}
|
||||
else if( strcmp( lineHeader, "f" ) == 0)
|
||||
{ unsigned int vertexIndex[3], TextureCoordIndex[3], normalIndex[3];
|
||||
int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", &vertexIndex[0], &TextureCoordIndex[0], &normalIndex[0], &vertexIndex[1], &TextureCoordIndex[1], &normalIndex[1],&vertexIndex[2], &TextureCoordIndex[2], &normalIndex[2]);
|
||||
if(matches != 9)
|
||||
{ printf("File can't be read, try exporting with other options\n");
|
||||
return false;
|
||||
}
|
||||
vertexIndices.push_back(vertexIndex[0]);
|
||||
vertexIndices.push_back(vertexIndex[1]);
|
||||
vertexIndices.push_back(vertexIndex[2]);
|
||||
TextureCoordIndices.push_back(TextureCoordIndex[0]);
|
||||
TextureCoordIndices.push_back(TextureCoordIndex[1]);
|
||||
TextureCoordIndices.push_back(TextureCoordIndex[2]);
|
||||
normalIndices.push_back(normalIndex[0]);
|
||||
normalIndices.push_back(normalIndex[1]);
|
||||
normalIndices.push_back(normalIndex[2]);
|
||||
|
||||
}
|
||||
else if ( strcmp( lineHeader, "mtllib" ) == 0 )
|
||||
{
|
||||
|
||||
char fileName[512];
|
||||
fscanf(file, "%s\n", &fileName);
|
||||
|
||||
|
||||
FILE* mtlfile = fopen(fileName, "r");
|
||||
LOG_INFO("Loading .mtl file");
|
||||
if( mtlfile == NULL )
|
||||
{ LOG_INFO("Load .mtl file: failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
char mtllineHeader[512];
|
||||
//read the first word of the line
|
||||
|
||||
while (true)
|
||||
{ int mtlres = fscanf(mtlfile, "%s", mtllineHeader);
|
||||
|
||||
if( mtlres == EOF ) // EOF - End Of File
|
||||
{
|
||||
|
||||
break;
|
||||
}
|
||||
else if ( strcmp( mtllineHeader, "map_Kd" ) == 0 )
|
||||
{ char textureFileName[512];
|
||||
fscanf(mtlfile, "%s", textureFileName);
|
||||
texture.push_back(std::make_shared<Texture>(textureFileName));
|
||||
LOG_INFO("Texture Loaded\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
CreateBuffers(Vertices, Normals, TextureCoords);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING("Loaded OBJ with no vertices!");
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec3> normals, std::vector<glm::vec2>textureCoords)
|
||||
{
|
||||
|
||||
LOG_INFO("Generating VertexBuffer");
|
||||
glGenBuffers(1, &VertexBuffer);
|
||||
if (vertices.size() > 0)
|
||||
{ glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW);
|
||||
GLERROR("GLEW: BufferFail, VertexBuffer");
|
||||
}
|
||||
else
|
||||
{ LOG_WARNING("Created empty vertex buffer!");
|
||||
{
|
||||
LOG_WARNING("Created empty vertex buffer!");
|
||||
}
|
||||
|
||||
LOG_INFO("Generating NormalBuffer");
|
||||
glGenBuffers(1, &NormalBuffer);
|
||||
if (normals.size() > 0)
|
||||
{ glBindBuffer(GL_ARRAY_BUFFER, NormalBuffer);
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, NormalBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(glm::vec3), &normals[0], GL_STATIC_DRAW);
|
||||
GLERROR("GLEW: BufferFail, NormalBuffer");
|
||||
}
|
||||
else
|
||||
{ LOG_WARNING("Created empty normal buffer!");
|
||||
{
|
||||
LOG_WARNING("Created empty normal buffer!");
|
||||
}
|
||||
|
||||
|
||||
LOG_INFO("Generating textureCoordBuffer");
|
||||
glGenBuffers(1, &TextureCoordBuffer);
|
||||
if (textureCoords.size() > 0)
|
||||
{ glBindBuffer(GL_ARRAY_BUFFER, TextureCoordBuffer);
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, TextureCoordBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, textureCoords.size() * sizeof(glm::vec2), &textureCoords[0], GL_STATIC_DRAW);
|
||||
GLERROR("GLEW: BufferFail, TextureCoordBuffer");
|
||||
}
|
||||
else
|
||||
{ LOG_WARNING("Created empty texture coordinate buffer!");
|
||||
{
|
||||
LOG_WARNING("Created empty texture coordinate buffer!");
|
||||
}
|
||||
|
||||
glGenVertexArrays(1, &VAO);
|
||||
|
||||
+5
-4
@@ -10,17 +10,18 @@
|
||||
#include <cstdlib>
|
||||
#include <stack>
|
||||
|
||||
#include "ResourceManager.h"
|
||||
#include "Texture.h"
|
||||
#include "OBJ.h"
|
||||
|
||||
class Model
|
||||
class Model : public Resource
|
||||
{
|
||||
public:
|
||||
Model(OBJ &obj);
|
||||
Model(const char* path);
|
||||
Model(OBJ &obj, ResourceManager* rm);
|
||||
|
||||
struct TextureGroup
|
||||
{ std::shared_ptr<Texture> Texture;
|
||||
{
|
||||
std::shared_ptr<Texture> Texture;
|
||||
unsigned int StartIndex;
|
||||
unsigned int EndIndex;
|
||||
};
|
||||
|
||||
+60
-30
@@ -2,12 +2,14 @@
|
||||
#include "OBJ.h"
|
||||
|
||||
bool OBJ::LoadFromFile(std::string filename)
|
||||
{ m_Path = boost::filesystem::path(filename);
|
||||
{
|
||||
m_Path = boost::filesystem::path(filename);
|
||||
|
||||
// http://paulbourke.net/dataformats/obj/
|
||||
std::ifstream file(m_Path.string());
|
||||
if (!file.is_open())
|
||||
{ LOG_ERROR("Failed to open .obj \"%s\"", m_Path.string().c_str());
|
||||
{
|
||||
LOG_ERROR("Failed to open .obj \"%s\"", m_Path.string().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -15,7 +17,8 @@ bool OBJ::LoadFromFile(std::string filename)
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line))
|
||||
{ if (line.length() == 0)
|
||||
{
|
||||
if (line.length() == 0)
|
||||
continue;
|
||||
|
||||
std::stringstream ss(line);
|
||||
@@ -29,7 +32,8 @@ bool OBJ::LoadFromFile(std::string filename)
|
||||
|
||||
// Material files
|
||||
if (prefix == "mtllib")
|
||||
{ std::string materialFilename;
|
||||
{
|
||||
std::string materialFilename;
|
||||
ss >> materialFilename;
|
||||
m_MaterialPath = m_Path.branch_path() / materialFilename;
|
||||
ParseMaterial();
|
||||
@@ -38,7 +42,8 @@ bool OBJ::LoadFromFile(std::string filename)
|
||||
|
||||
// Material statement
|
||||
if (prefix == "usemtl")
|
||||
{ std::string material;
|
||||
{
|
||||
std::string material;
|
||||
ss >> material;
|
||||
m_CurrentMaterial = &Materials[material];
|
||||
continue;
|
||||
@@ -46,7 +51,8 @@ bool OBJ::LoadFromFile(std::string filename)
|
||||
|
||||
// Vertices
|
||||
if (prefix == "v")
|
||||
{ float x, y, z;
|
||||
{
|
||||
float x, y, z;
|
||||
ss >> x >> y >> z;
|
||||
Vertices.push_back(std::make_tuple(x, y, z));
|
||||
continue;
|
||||
@@ -54,26 +60,30 @@ bool OBJ::LoadFromFile(std::string filename)
|
||||
|
||||
// Normals
|
||||
if (prefix == "vn")
|
||||
{ float x, y, z;
|
||||
{
|
||||
float x, y, z;
|
||||
ss >> x >> y >> z;
|
||||
Normals.push_back(std::make_tuple(x, y, z));
|
||||
}
|
||||
|
||||
// Texture coordinates
|
||||
if (prefix == "vt")
|
||||
{ float u, v, w;
|
||||
{
|
||||
float u, v, w;
|
||||
ss >> u >> v >> w;
|
||||
TextureCoords.push_back(std::make_tuple(u, v, w));
|
||||
}
|
||||
|
||||
// Face definitions
|
||||
if (prefix == "f")
|
||||
{ Face face;
|
||||
{
|
||||
Face face;
|
||||
face.Material = m_CurrentMaterial;
|
||||
|
||||
std::string faceDefString;
|
||||
while (ss >> faceDefString)
|
||||
{ std::stringstream ss2(faceDefString);
|
||||
{
|
||||
std::stringstream ss2(faceDefString);
|
||||
FaceDefinition faceDef = { 0, 0, 0 };
|
||||
|
||||
ss2 >> faceDef.VertexIndex;
|
||||
@@ -82,11 +92,13 @@ bool OBJ::LoadFromFile(std::string filename)
|
||||
continue;
|
||||
|
||||
if (ss2.peek() == '/')
|
||||
{ ss2.ignore();
|
||||
{
|
||||
ss2.ignore();
|
||||
ss2 >> faceDef.NormalIndex;
|
||||
}
|
||||
else
|
||||
{ ss2 >> faceDef.TextureCoordIndex;
|
||||
{
|
||||
ss2 >> faceDef.TextureCoordIndex;
|
||||
ss2.ignore();
|
||||
ss2 >> faceDef.NormalIndex;
|
||||
}
|
||||
@@ -100,10 +112,12 @@ bool OBJ::LoadFromFile(std::string filename)
|
||||
}
|
||||
|
||||
void OBJ::ParseMaterial()
|
||||
{ // http://paulbourke.net/dataformats/mtl/
|
||||
{
|
||||
// http://paulbourke.net/dataformats/mtl/
|
||||
std::ifstream file(m_MaterialPath.string());
|
||||
if (!file.is_open())
|
||||
{ LOG_ERROR("Failed to open .mtl \"%s\"", m_MaterialPath.string().c_str());
|
||||
{
|
||||
LOG_ERROR("Failed to open .mtl \"%s\"", m_MaterialPath.string().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -114,7 +128,8 @@ void OBJ::ParseMaterial()
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line))
|
||||
{ if (line.length() == 0)
|
||||
{
|
||||
if (line.length() == 0)
|
||||
continue;
|
||||
|
||||
std::stringstream ss(line);
|
||||
@@ -124,8 +139,10 @@ void OBJ::ParseMaterial()
|
||||
|
||||
// Create a new material definition
|
||||
if (prefix == "newmtl")
|
||||
{ MaterialInfo mat =
|
||||
{ "",
|
||||
{
|
||||
MaterialInfo mat =
|
||||
{
|
||||
"",
|
||||
std::make_tuple(0.2f, 0.2f, 0.2f),
|
||||
std::make_tuple(0.8f, 0.8f, 0.8f),
|
||||
std::make_tuple(1.0f, 1.0f, 1.0f),
|
||||
@@ -148,44 +165,52 @@ void OBJ::ParseMaterial()
|
||||
|
||||
// Ambient color
|
||||
if (prefix == "Ka")
|
||||
{ float r, g, b;
|
||||
{
|
||||
float r, g, b;
|
||||
ss >> r >> g >> b;
|
||||
currentMaterial->AmbientColor = std::make_tuple(r, g, b);
|
||||
continue;
|
||||
}
|
||||
// Diffuse color
|
||||
if (prefix == "Kd")
|
||||
{ float r, g, b;
|
||||
{
|
||||
float r, g, b;
|
||||
ss >> r >> g >> b;
|
||||
currentMaterial->DiffuseColor = std::make_tuple(r, g, b);
|
||||
continue;
|
||||
}
|
||||
// Specular color
|
||||
if (prefix == "Ks")
|
||||
{ float r, g, b;
|
||||
{
|
||||
float r, g, b;
|
||||
ss >> r >> g >> b;
|
||||
currentMaterial->SpecularColor = std::make_tuple(r, g, b);
|
||||
continue;
|
||||
}
|
||||
// Transmission filter
|
||||
if (prefix == "Tf")
|
||||
{ std::stringstream ss2;
|
||||
{
|
||||
std::stringstream ss2;
|
||||
ss2 << ss.str();
|
||||
|
||||
std::string command;
|
||||
ss2 >> command;
|
||||
if (command == "xyz")
|
||||
{ // TODO: "The "Ks xyz" statement specifies the specular reflectivity using CIEXYZ values."
|
||||
{
|
||||
// TODO: "The "Ks xyz" statement specifies the specular reflectivity using CIEXYZ values."
|
||||
}
|
||||
else if (command == "spectral")
|
||||
{ // TODO: "The "Tf spectral" statement specifies the transmission filter using a spectral curve."
|
||||
{
|
||||
// TODO: "The "Tf spectral" statement specifies the transmission filter using a spectral curve."
|
||||
}
|
||||
else
|
||||
{ float r, g, b;
|
||||
{
|
||||
float r, g, b;
|
||||
ss >> r;
|
||||
// G and B are optional
|
||||
if (!(ss >> g >> b))
|
||||
{ g = r;
|
||||
{
|
||||
g = r;
|
||||
b = r;
|
||||
}
|
||||
currentMaterial->TransmissionFilter = std::make_tuple(r, g, b);
|
||||
@@ -194,22 +219,26 @@ void OBJ::ParseMaterial()
|
||||
}
|
||||
// Optical density
|
||||
if (prefix == "Ni")
|
||||
{ ss >> currentMaterial->OpticalDensity;
|
||||
{
|
||||
ss >> currentMaterial->OpticalDensity;
|
||||
continue;
|
||||
}
|
||||
// Alpha
|
||||
if (prefix == "d" || prefix == "Tr")
|
||||
{ ss >> currentMaterial->Alpha;
|
||||
{
|
||||
ss >> currentMaterial->Alpha;
|
||||
continue;
|
||||
}
|
||||
// Shininess
|
||||
if (prefix == "Ns")
|
||||
{ ss >> currentMaterial->Shininess;
|
||||
{
|
||||
ss >> currentMaterial->Shininess;
|
||||
continue;
|
||||
}
|
||||
// Illumination model
|
||||
if (prefix == "illum")
|
||||
{ int illum = 0;
|
||||
{
|
||||
int illum = 0;
|
||||
ss >> illum;
|
||||
currentMaterial->IlluminationModel = illum;
|
||||
continue;
|
||||
@@ -217,7 +246,8 @@ void OBJ::ParseMaterial()
|
||||
// Texture file
|
||||
// TODO:
|
||||
if (prefix == "map_Ka" || prefix == "map_Kd")
|
||||
{ std::string textureFile;
|
||||
{
|
||||
std::string textureFile;
|
||||
ss >> textureFile;
|
||||
currentMaterial->TextureFile = (m_MaterialPath.branch_path() / textureFile).string();
|
||||
continue;
|
||||
|
||||
@@ -15,7 +15,8 @@ class OBJ
|
||||
{
|
||||
public:
|
||||
struct MaterialInfo
|
||||
{ std::string TextureFile;
|
||||
{
|
||||
std::string TextureFile;
|
||||
std::tuple<float, float, float> AmbientColor;
|
||||
std::tuple<float, float, float> DiffuseColor;
|
||||
std::tuple<float, float, float> SpecularColor;
|
||||
@@ -27,13 +28,15 @@ public:
|
||||
};
|
||||
|
||||
struct FaceDefinition
|
||||
{ int VertexIndex;
|
||||
{
|
||||
int VertexIndex;
|
||||
int TextureCoordIndex;
|
||||
int NormalIndex;
|
||||
};
|
||||
|
||||
struct Face
|
||||
{ Face() : Material(nullptr) { }
|
||||
{
|
||||
Face() : Material(nullptr) { }
|
||||
std::vector<FaceDefinition> Definitions;
|
||||
MaterialInfo* Material;
|
||||
};
|
||||
|
||||
+72
-37
@@ -2,7 +2,8 @@
|
||||
#include "Renderer.h"
|
||||
|
||||
Renderer::Renderer()
|
||||
{ m_VSync = false;
|
||||
{
|
||||
m_VSync = false;
|
||||
#ifdef DEBUG
|
||||
m_DrawNormals = false;
|
||||
m_DrawWireframe = false;
|
||||
@@ -21,9 +22,11 @@ Renderer::Renderer()
|
||||
}
|
||||
|
||||
void Renderer::Initialize()
|
||||
{ // Initialize GLFW
|
||||
{
|
||||
// Initialize GLFW
|
||||
if (!glfwInit())
|
||||
{ LOG_ERROR("GLFW: Initialization failed");
|
||||
{
|
||||
LOG_ERROR("GLFW: Initialization failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -34,7 +37,8 @@ void Renderer::Initialize()
|
||||
//glfwWindowHint(GLFW_SAMPLES, 16);
|
||||
m_Window = glfwCreateWindow(WIDTH, HEIGHT, "OpenGL", nullptr, nullptr);
|
||||
if (!m_Window)
|
||||
{ LOG_ERROR("GLFW: Failed to create window");
|
||||
{
|
||||
LOG_ERROR("GLFW: Failed to create window");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
glfwMakeContextCurrent(m_Window);
|
||||
@@ -53,7 +57,8 @@ void Renderer::Initialize()
|
||||
|
||||
// Initialize GLEW
|
||||
if (glewInit() != GLEW_OK)
|
||||
{ LOG_ERROR("GLEW: Initialization failed");
|
||||
{
|
||||
LOG_ERROR("GLEW: Initialization failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -70,7 +75,8 @@ void Renderer::Initialize()
|
||||
}
|
||||
|
||||
void Renderer::LoadContent()
|
||||
{ auto standardVS = std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex.glsl"));
|
||||
{
|
||||
auto standardVS = std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex.glsl"));
|
||||
auto standardFS = std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment.glsl"));
|
||||
|
||||
m_ShaderProgram.AddShader(standardVS);
|
||||
@@ -112,7 +118,8 @@ void Renderer::LoadContent()
|
||||
}
|
||||
|
||||
void Renderer::CreateShadowMap(int resolution)
|
||||
{ glGenFramebuffers(1, &m_ShadowFrameBuffer);
|
||||
{
|
||||
glGenFramebuffers(1, &m_ShadowFrameBuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_ShadowFrameBuffer);
|
||||
|
||||
// Depth texture
|
||||
@@ -131,12 +138,14 @@ void Renderer::CreateShadowMap(int resolution)
|
||||
glDrawBuffer(GL_NONE);
|
||||
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
{ LOG_ERROR("Framebuffer incomplete!");
|
||||
{
|
||||
LOG_ERROR("Framebuffer incomplete!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
void Renderer::Draw(double dt)
|
||||
{ glDisable(GL_BLEND);
|
||||
{
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
DrawSkybox();
|
||||
DrawShadowMap();
|
||||
@@ -145,11 +154,13 @@ void Renderer::Draw(double dt)
|
||||
#ifdef DEBUG
|
||||
// Draw bounding boxes
|
||||
if (m_DrawBounds)
|
||||
{ glEnable(GL_BLEND);
|
||||
{
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
||||
m_ShaderProgramDebugAABB.Bind();
|
||||
for (auto tuple : AABBsToRender)
|
||||
{ glm::mat4 modelMatrix;
|
||||
{
|
||||
glm::mat4 modelMatrix;
|
||||
bool colliding;
|
||||
std::tie(modelMatrix, colliding) = tuple;
|
||||
// Model matrix
|
||||
@@ -174,7 +185,8 @@ void Renderer::Draw(double dt)
|
||||
}
|
||||
|
||||
void Renderer::DrawSkybox()
|
||||
{ glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glViewport(0, 0, WIDTH, HEIGHT);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
@@ -186,7 +198,8 @@ void Renderer::DrawSkybox()
|
||||
}
|
||||
|
||||
void Renderer::DrawScene()
|
||||
{ glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glViewport(0, 0, WIDTH, HEIGHT);
|
||||
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
@@ -220,7 +233,8 @@ void Renderer::DrawScene()
|
||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), Lights, Light_quadraticAttenuation.data());
|
||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), Lights, Light_spotExponent.data());
|
||||
if (m_DrawWireframe)
|
||||
{ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
{
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
}
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
|
||||
@@ -230,7 +244,8 @@ void Renderer::DrawScene()
|
||||
glm::mat4 MVP;
|
||||
glm::mat4 depthMVP;
|
||||
for (auto tuple : ModelsToRender)
|
||||
{ Model* model;
|
||||
{
|
||||
Model* model;
|
||||
glm::mat4 modelMatrix;
|
||||
bool visible;
|
||||
std::tie(model, modelMatrix, visible, std::ignore) = tuple;
|
||||
@@ -245,7 +260,8 @@ void Renderer::DrawScene()
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||
glBindVertexArray(model->VAO);
|
||||
for (auto texGroup : model->TextureGroups)
|
||||
{ glActiveTexture(GL_TEXTURE0);
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, *texGroup.Texture);
|
||||
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
|
||||
}
|
||||
@@ -254,7 +270,8 @@ void Renderer::DrawScene()
|
||||
#ifdef DEBUG
|
||||
// Debug draw model normals
|
||||
if (m_DrawNormals)
|
||||
{ m_ShaderProgramNormals.Bind();
|
||||
{
|
||||
m_ShaderProgramNormals.Bind();
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
DrawModels(m_ShaderProgramNormals);
|
||||
}
|
||||
@@ -262,7 +279,8 @@ void Renderer::DrawScene()
|
||||
}
|
||||
|
||||
void Renderer::DrawShadowMap()
|
||||
{ glEnable(GL_DEPTH_TEST);
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_FRONT);
|
||||
|
||||
@@ -283,7 +301,8 @@ void Renderer::DrawShadowMap()
|
||||
m_ShaderProgramShadows.Bind();
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
for (auto tuple : ModelsToRender)
|
||||
{ Model* model;
|
||||
{
|
||||
Model* model;
|
||||
glm::mat4 modelMatrix;
|
||||
bool shadow;
|
||||
std::tie(model, modelMatrix, std::ignore, shadow) = tuple;
|
||||
@@ -295,13 +314,15 @@ void Renderer::DrawShadowMap()
|
||||
|
||||
glBindVertexArray(model->VAO);
|
||||
for (auto texGroup : model->TextureGroups)
|
||||
{ glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
|
||||
{
|
||||
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::DrawDebugShadowMap()
|
||||
{ glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glViewport(0, 0, 400, 400);
|
||||
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
@@ -315,7 +336,8 @@ void Renderer::DrawDebugShadowMap()
|
||||
}
|
||||
|
||||
void Renderer::DrawModels(ShaderProgram &shader)
|
||||
{ /*glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
||||
{
|
||||
/*glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
||||
|
||||
glm::mat4 MVP;
|
||||
for (auto tuple : ModelsToRender)
|
||||
@@ -338,17 +360,20 @@ void Renderer::DrawModels(ShaderProgram &shader)
|
||||
}
|
||||
|
||||
void Renderer::DrawText()
|
||||
{ //DrawShitInTextForm
|
||||
{
|
||||
//DrawShitInTextForm
|
||||
}
|
||||
|
||||
void Renderer::AddTextToDraw()
|
||||
{ //Add to draw shit vector
|
||||
{
|
||||
//Add to draw shit vector
|
||||
}
|
||||
|
||||
void Renderer::AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale, bool visible, bool shadowCaster)
|
||||
{ glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
|
||||
void Renderer::AddModelToDraw(Model* model, glm::vec3 position, glm::quat orientation, glm::vec3 scale, bool visible, bool shadowCaster)
|
||||
{
|
||||
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
|
||||
// You can now use ModelMatrix to build the MVP matrix
|
||||
ModelsToRender.push_back(std::make_tuple(model.get(), modelMatrix, visible, shadowCaster));
|
||||
ModelsToRender.push_back(std::make_tuple(model, modelMatrix, visible, shadowCaster));
|
||||
}
|
||||
|
||||
void Renderer::AddPointLightToDraw(
|
||||
@@ -360,7 +385,8 @@ void Renderer::AddPointLightToDraw(
|
||||
float _quadraticAttenuation,
|
||||
float _spotExponent
|
||||
)
|
||||
{ Light_position.push_back(_position.x);
|
||||
{
|
||||
Light_position.push_back(_position.x);
|
||||
Light_position.push_back(_position.y);
|
||||
Light_position.push_back(_position.z);
|
||||
Light_specular.push_back(_specular.x);
|
||||
@@ -377,15 +403,18 @@ void Renderer::AddPointLightToDraw(
|
||||
}
|
||||
|
||||
void Renderer::AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding)
|
||||
{ glm::mat4 model;
|
||||
{
|
||||
glm::mat4 model;
|
||||
model *= glm::translate(origin);
|
||||
model *= glm::scale(volumeVector);
|
||||
AABBsToRender.push_back(std::make_tuple(model, colliding));
|
||||
}
|
||||
|
||||
GLuint Renderer::CreateQuad()
|
||||
{ float quadVertices[] =
|
||||
{ -1.0f, -1.0f, 0.0f,
|
||||
{
|
||||
float quadVertices[] =
|
||||
{
|
||||
-1.0f, -1.0f, 0.0f,
|
||||
1.0f, 1.0f, 0.0f,
|
||||
-1.0f, 1.0f, 0.0f,
|
||||
|
||||
@@ -394,7 +423,8 @@ GLuint Renderer::CreateQuad()
|
||||
1.0f, 1.0f, 0.0f,
|
||||
};
|
||||
float quadTexCoords[] =
|
||||
{ 0.0f, 0.0f,
|
||||
{
|
||||
0.0f, 0.0f,
|
||||
1.0f, 1.0f,
|
||||
0.0f, 1.0f,
|
||||
|
||||
@@ -424,8 +454,10 @@ GLuint Renderer::CreateQuad()
|
||||
}
|
||||
|
||||
GLuint Renderer::CreateAABB()
|
||||
{ float vertices[] =
|
||||
{ // Bottom
|
||||
{
|
||||
float vertices[] =
|
||||
{
|
||||
// Bottom
|
||||
-1.0f, -1.0f, 1.0f, // 0
|
||||
1.0f, -1.0f, 1.0f, // 1
|
||||
1.0f, -1.0f, 1.0f, // 1
|
||||
@@ -474,8 +506,10 @@ GLuint Renderer::CreateAABB()
|
||||
}
|
||||
|
||||
GLuint Renderer::CreateSkybox()
|
||||
{ glm::vec3 skyBoxVertices[] =
|
||||
{ glm::vec3( 1.0f, -1.0f, -1.0f), glm::vec3( 1.0f, -1.0f, 1.0f), glm::vec3( 1.0f, 1.0f, 1.0f), glm::vec3( 1.0f, 1.0f, 1.0f), glm::vec3( 1.0f, 1.0f, -1.0f), glm::vec3( 1.0f, -1.0f, -1.0f),
|
||||
{
|
||||
glm::vec3 skyBoxVertices[] =
|
||||
{
|
||||
glm::vec3( 1.0f, -1.0f, -1.0f), glm::vec3( 1.0f, -1.0f, 1.0f), glm::vec3( 1.0f, 1.0f, 1.0f), glm::vec3( 1.0f, 1.0f, 1.0f), glm::vec3( 1.0f, 1.0f, -1.0f), glm::vec3( 1.0f, -1.0f, -1.0f),
|
||||
glm::vec3(-1.0f, -1.0f, 1.0f), glm::vec3(-1.0f, -1.0f, -1.0f), glm::vec3(-1.0f, 1.0f, -1.0f), glm::vec3(-1.0f, 1.0f, -1.0f), glm::vec3(-1.0f, 1.0f, 1.0f), glm::vec3(-1.0f, -1.0f, 1.0f),
|
||||
glm::vec3(-1.0f, 1.0f, -1.0f), glm::vec3( 1.0f, 1.0f, -1.0f), glm::vec3( 1.0f, 1.0f, 1.0f), glm::vec3( 1.0f, 1.0f, 1.0f), glm::vec3(-1.0f, 1.0f, 1.0f), glm::vec3(-1.0f, 1.0f, -1.0f),
|
||||
glm::vec3(-1.0f, -1.0f, 1.0f), glm::vec3( 1.0f, -1.0f, 1.0f), glm::vec3( 1.0f, -1.0f, -1.0f), glm::vec3( 1.0f, -1.0f, -1.0f), glm::vec3(-1.0f, -1.0f, -1.0f), glm::vec3(-1.0f, -1.0f, 1.0f),
|
||||
@@ -499,7 +533,8 @@ GLuint Renderer::CreateSkybox()
|
||||
return vao;
|
||||
}
|
||||
void Renderer::ClearStuff()
|
||||
{ AABBsToRender.clear();
|
||||
{
|
||||
AABBsToRender.clear();
|
||||
ModelsToRender.clear();
|
||||
Light_position.clear();
|
||||
Light_specular.clear();
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ public:
|
||||
void Draw(double dt);
|
||||
void DrawText();
|
||||
|
||||
void AddModelToDraw(std::shared_ptr<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 AddTextToDraw();
|
||||
void AddPointLightToDraw(
|
||||
glm::vec3 _position,
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
Resource* ResourceManager::CreateResource(std::string resourceType, std::string resourceName)
|
||||
{
|
||||
auto facIt = m_FactoryFunctions.find(resourceType);
|
||||
if (facIt == m_FactoryFunctions.end())
|
||||
{
|
||||
LOG_ERROR("Failed to load resource \"%s\" of type \"%s\": Type not registered", resourceName.c_str(), resourceType.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto resIt = m_ResourceCache.find(resourceName);
|
||||
if (resIt != m_ResourceCache.end())
|
||||
return resIt->second;
|
||||
|
||||
// Call the factory function
|
||||
Resource* resource = facIt->second(resourceName);
|
||||
// Store IDs
|
||||
resource->TypeID = GetTypeID(resourceType);
|
||||
resource->ResourceID = GetNewResourceID(resource->TypeID);
|
||||
// Cache
|
||||
m_ResourceCache[resourceName] = resource;
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
void ResourceManager::RegisterType(std::string resourceType, std::function<Resource*(std::string)> factoryFunction)
|
||||
{
|
||||
m_FactoryFunctions[resourceType] = factoryFunction;
|
||||
}
|
||||
|
||||
void ResourceManager::Preload(std::string resourceType, std::string resourceName)
|
||||
{
|
||||
CreateResource(resourceType, resourceName);
|
||||
}
|
||||
|
||||
unsigned int ResourceManager::GetTypeID(std::string resourceType)
|
||||
{
|
||||
if (m_ResourceTypeIDs.find(resourceType) == m_ResourceTypeIDs.end())
|
||||
{
|
||||
m_ResourceTypeIDs[resourceType] = m_CurrentResourceTypeID++;
|
||||
}
|
||||
return m_ResourceTypeIDs[resourceType];
|
||||
}
|
||||
|
||||
unsigned int ResourceManager::GetNewResourceID(unsigned int typeID)
|
||||
{
|
||||
return m_ResourceCount[typeID]++;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef ResourceManager_h__
|
||||
#define ResourceManager_h__
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Factory.h"
|
||||
|
||||
class Resource
|
||||
{
|
||||
public:
|
||||
unsigned int TypeID;
|
||||
unsigned int ResourceID;
|
||||
};
|
||||
|
||||
class ResourceManager
|
||||
{
|
||||
public:
|
||||
// Registers the factory function of a resource type
|
||||
void RegisterType(std::string resourceType, std::function<Resource*(std::string)> factoryFunction);
|
||||
|
||||
// Loads a resource and caches it for future use
|
||||
void Preload(std::string resourceType, std::string resourceName);
|
||||
|
||||
template <typename T>
|
||||
// Hot-loads a resource and caches it for future use
|
||||
T* Load(std::string resourceType, std::string resourceName);
|
||||
|
||||
template <typename T>
|
||||
// Fetches a preloaded resource
|
||||
T* Fetch(std::string resourceName) const;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::function<Resource*(std::string)>> m_FactoryFunctions; // type -> factory function
|
||||
std::unordered_map<std::string, Resource*> m_ResourceCache; // name -> resource
|
||||
|
||||
// TODO: Getters for IDs
|
||||
unsigned int m_CurrentResourceTypeID = 0;
|
||||
std::unordered_map<std::string, unsigned int> m_ResourceTypeIDs;
|
||||
// Number of resources of a type. Doubles as local ID.
|
||||
std::unordered_map<unsigned int, unsigned int> m_ResourceCount;
|
||||
|
||||
unsigned int GetTypeID(std::string resourceType);
|
||||
unsigned int GetNewResourceID(unsigned int typeID);
|
||||
|
||||
// Internal: Create a resource and cache it
|
||||
Resource* CreateResource(std::string resourceType, std::string resourceName);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
T* ResourceManager::Load(std::string resourceType, std::string resourceName)
|
||||
{
|
||||
return static_cast<T*>(CreateResource(resourceType, resourceName));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* ResourceManager::Fetch(std::string resourceName) const
|
||||
{
|
||||
if (m_ResourceCache.find(resourceName) == m_ResourceCache.end())
|
||||
{
|
||||
LOG_ERROR("Failed to fetch resource \"%s\": Resource not loaded!", resourceName.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return static_cast<T*>(m_ResourceCache.at(resourceName));
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ResourceManager_h__
|
||||
+46
-23
@@ -2,12 +2,14 @@
|
||||
#include "ShaderProgram.h"
|
||||
|
||||
GLuint Shader::CompileShader(GLenum shaderType, std::string fileName)
|
||||
{ LOG_INFO("Compiling shader \"%s\"", fileName.c_str());
|
||||
{
|
||||
LOG_INFO("Compiling shader \"%s\"", fileName.c_str());
|
||||
|
||||
std::string shaderFile;
|
||||
std::ifstream in(fileName, std::ios::in);
|
||||
if (!in)
|
||||
{ LOG_ERROR("Error: Failed to open shader file \"%s\"", fileName.c_str());
|
||||
{
|
||||
LOG_ERROR("Error: Failed to open shader file \"%s\"", fileName.c_str());
|
||||
return 0;
|
||||
}
|
||||
in.seekg(0, std::ios::end);
|
||||
@@ -31,7 +33,8 @@ GLuint Shader::CompileShader(GLenum shaderType, std::string fileName)
|
||||
GLint compileStatus;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &compileStatus);
|
||||
if(compileStatus != GL_TRUE)
|
||||
{ LOG_ERROR("Shader compilation failed");
|
||||
{
|
||||
LOG_ERROR("Shader compilation failed");
|
||||
GLsizei infoLogLength;
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
GLchar* infolog = new GLchar[infoLogLength];
|
||||
@@ -47,64 +50,81 @@ GLuint Shader::CompileShader(GLenum shaderType, std::string fileName)
|
||||
}
|
||||
|
||||
Shader::Shader(GLenum shaderType, std::string fileName) : m_ShaderType(shaderType), m_FileName(fileName)
|
||||
{ m_ShaderHandle = 0;
|
||||
{
|
||||
m_ShaderHandle = 0;
|
||||
}
|
||||
|
||||
Shader::~Shader()
|
||||
{ if (m_ShaderHandle != 0)
|
||||
{ glDeleteShader(m_ShaderHandle);
|
||||
{
|
||||
if (m_ShaderHandle != 0)
|
||||
{
|
||||
glDeleteShader(m_ShaderHandle);
|
||||
}
|
||||
}
|
||||
|
||||
GLuint Shader::Compile()
|
||||
{ m_ShaderHandle = CompileShader(m_ShaderType, m_FileName);
|
||||
{
|
||||
m_ShaderHandle = CompileShader(m_ShaderType, m_FileName);
|
||||
return m_ShaderHandle;
|
||||
}
|
||||
|
||||
GLenum Shader::GetType() const
|
||||
{ return m_ShaderType;
|
||||
{
|
||||
return m_ShaderType;
|
||||
}
|
||||
|
||||
std::string Shader::GetFileName() const
|
||||
{ return m_FileName;
|
||||
{
|
||||
return m_FileName;
|
||||
}
|
||||
|
||||
GLuint Shader::GetHandle() const
|
||||
{ return m_ShaderHandle;
|
||||
{
|
||||
return m_ShaderHandle;
|
||||
}
|
||||
|
||||
bool Shader::IsCompiled() const
|
||||
{ return m_ShaderHandle != 0;
|
||||
{
|
||||
return m_ShaderHandle != 0;
|
||||
}
|
||||
|
||||
ShaderProgram::~ShaderProgram()
|
||||
{ if (m_ShaderProgramHandle != 0)
|
||||
{ glDeleteProgram(m_ShaderProgramHandle);
|
||||
{
|
||||
if (m_ShaderProgramHandle != 0)
|
||||
{
|
||||
glDeleteProgram(m_ShaderProgramHandle);
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderProgram::AddShader(std::shared_ptr<Shader> shader)
|
||||
{ m_Shaders.push_back(shader);
|
||||
{
|
||||
m_Shaders.push_back(shader);
|
||||
}
|
||||
|
||||
void ShaderProgram::Compile()
|
||||
{ for (auto &shader : m_Shaders)
|
||||
{ if (!shader->IsCompiled())
|
||||
{ shader->Compile();
|
||||
{
|
||||
for (auto &shader : m_Shaders)
|
||||
{
|
||||
if (!shader->IsCompiled())
|
||||
{
|
||||
shader->Compile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GLuint ShaderProgram::Link()
|
||||
{ if (m_Shaders.size() == 0)
|
||||
{ LOG_ERROR("Failed to link shader program: No shaders bound");
|
||||
{
|
||||
if (m_Shaders.size() == 0)
|
||||
{
|
||||
LOG_ERROR("Failed to link shader program: No shaders bound");
|
||||
return 0;
|
||||
}
|
||||
|
||||
LOG_INFO("Linking shader program");
|
||||
m_ShaderProgramHandle = glCreateProgram();
|
||||
for (auto &shader : m_Shaders)
|
||||
{ glAttachShader(m_ShaderProgramHandle, shader->GetHandle());
|
||||
{
|
||||
glAttachShader(m_ShaderProgramHandle, shader->GetHandle());
|
||||
}
|
||||
glLinkProgram(m_ShaderProgramHandle);
|
||||
if (GLERROR("glLinkProgram"))
|
||||
@@ -115,16 +135,19 @@ GLuint ShaderProgram::Link()
|
||||
}
|
||||
|
||||
GLuint ShaderProgram::GetHandle()
|
||||
{ return m_ShaderProgramHandle;
|
||||
{
|
||||
return m_ShaderProgramHandle;
|
||||
}
|
||||
|
||||
void ShaderProgram::Bind()
|
||||
{ if (m_ShaderProgramHandle == 0)
|
||||
{
|
||||
if (m_ShaderProgramHandle == 0)
|
||||
return;
|
||||
|
||||
glUseProgram(m_ShaderProgramHandle);
|
||||
}
|
||||
|
||||
void ShaderProgram::Unbind()
|
||||
{ glActiveShaderProgram(0, 0);
|
||||
{
|
||||
glActiveShaderProgram(0, 0);
|
||||
}
|
||||
@@ -3,7 +3,8 @@
|
||||
uniform vec4 Color;
|
||||
|
||||
in VertexData
|
||||
{ vec3 Position;
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
vec3 ShadowCoord;
|
||||
@@ -12,6 +13,7 @@ in VertexData
|
||||
out vec4 FragmentColor;
|
||||
|
||||
void main()
|
||||
{ //FragmentColor = vec4(1.0 - gl_Color.r, 1.0 - gl_Color.g, 1.0 - gl_Color.b, 0.0);
|
||||
{
|
||||
//FragmentColor = vec4(1.0 - gl_Color.r, 1.0 - gl_Color.g, 1.0 - gl_Color.b, 0.0);
|
||||
FragmentColor = Color;
|
||||
}
|
||||
@@ -17,7 +17,8 @@ uniform float quadraticAttenuation[maxNumberOfLights];
|
||||
uniform float spotExponent[maxNumberOfLights];
|
||||
|
||||
in VertexData
|
||||
{ vec3 Position;
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
vec3 ShadowCoord;
|
||||
@@ -52,10 +53,12 @@ void main()
|
||||
//bias = clamp(bias, 0.0, 0.01);
|
||||
float visibility = 1.0;
|
||||
if (Input.ShadowCoord.x >= 0.0 && Input.ShadowCoord.x <= 1.0 && Input.ShadowCoord.y >= 0.0 && Input.ShadowCoord.y <= 1.0)
|
||||
{ float bias = 0.00005;
|
||||
{
|
||||
float bias = 0.00005;
|
||||
vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy);
|
||||
if (shadowMapValue.z < clamp(Input.ShadowCoord.z - bias, 0, 1))
|
||||
{ visibility = 0.3;
|
||||
{
|
||||
visibility = 0.3;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +67,8 @@ void main()
|
||||
float attenuation;
|
||||
|
||||
for(int i = 0; i < numberOfLights && i < maxNumberOfLights; i++)
|
||||
{ // Light
|
||||
{
|
||||
// Light
|
||||
//vec3 lightPosition = vec3(0, 0, 2);
|
||||
vec3 Ls = specular[i]; // Specular light
|
||||
vec3 Ld = diffuse[i]; // Diffuse light
|
||||
|
||||
@@ -5,5 +5,6 @@ uniform mat4 MVP;
|
||||
out vec4 FragmentColor;
|
||||
|
||||
void main()
|
||||
{ FragmentColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
{
|
||||
FragmentColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
@@ -6,20 +6,24 @@ layout(triangles) in;
|
||||
layout(line_strip, max_vertices = 6) out;
|
||||
|
||||
in VertexData
|
||||
{ vec3 Position;
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
} Input[3];
|
||||
|
||||
out VertexData
|
||||
{ vec3 Position;
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{ for (int i = 0; i < gl_in.length(); i++)
|
||||
{ gl_Position = MVP * vec4(Input[i].Position, 1.0);
|
||||
{
|
||||
for (int i = 0; i < gl_in.length(); i++)
|
||||
{
|
||||
gl_Position = MVP * vec4(Input[i].Position, 1.0);
|
||||
EmitVertex();
|
||||
gl_Position = MVP * vec4(Input[i].Position + Input[i].Normal, 1.0);
|
||||
EmitVertex();
|
||||
|
||||
@@ -5,5 +5,6 @@ uniform mat4 MVP;
|
||||
layout(location = 0) out float FragmentDepth;
|
||||
|
||||
void main()
|
||||
{ FragmentDepth = gl_FragCoord.z;
|
||||
{
|
||||
FragmentDepth = gl_FragCoord.z;
|
||||
}
|
||||
@@ -7,13 +7,15 @@ layout(location = 1) in vec3 Normal;
|
||||
layout(location = 2) in vec2 TextureCoord;
|
||||
|
||||
out VertexData
|
||||
{ vec3 Position;
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{ gl_Position = MVP * vec4(Position, 1.0);
|
||||
{
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
|
||||
Output.Position = Position;
|
||||
Output.Normal = Normal;
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
uniform samplerCube CubemapTexture;
|
||||
|
||||
in VertexData
|
||||
{ vec3 TextureCoord;
|
||||
{
|
||||
vec3 TextureCoord;
|
||||
} Input;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{ FragColor = texture(CubemapTexture, Input.TextureCoord);
|
||||
{
|
||||
FragColor = texture(CubemapTexture, Input.TextureCoord);
|
||||
//FragColor = vec4(1.0, 1.0, 1.0, 0.0);
|
||||
}
|
||||
@@ -5,10 +5,12 @@ uniform mat4 MVP;
|
||||
layout(location = 0) in vec3 Position;
|
||||
|
||||
out VertexData
|
||||
{ vec3 TextureCoord;
|
||||
{
|
||||
vec3 TextureCoord;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{ gl_Position = MVP * vec4(Position, 1.0);
|
||||
{
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
Output.TextureCoord = Position;
|
||||
}
|
||||
@@ -8,14 +8,16 @@ layout(location = 1) in vec3 Normal;
|
||||
layout(location = 2) in vec2 TextureCoord;
|
||||
|
||||
out VertexData
|
||||
{ vec3 Position;
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
vec3 ShadowCoord;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{ gl_Position = MVP * vec4(Position, 1.0);
|
||||
{
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
|
||||
Output.Position = Position;
|
||||
Output.Normal = Normal;
|
||||
|
||||
@@ -3,20 +3,23 @@
|
||||
layout(binding = 0) uniform sampler2D DepthTexture;
|
||||
|
||||
in VertexData
|
||||
{ vec3 Position;
|
||||
{
|
||||
vec3 Position;
|
||||
vec2 TextureCoord;
|
||||
} Input;
|
||||
|
||||
out vec4 FragmentColor;
|
||||
|
||||
float LinearizeDepth(float z)
|
||||
{ float n = 0.1; // camera z near
|
||||
{
|
||||
float n = 0.1; // camera z near
|
||||
float f = 800.0; // camera z far
|
||||
return (2.0 * n) / (f + n - z * (f - n));
|
||||
}
|
||||
|
||||
void main()
|
||||
{ float z = texture(DepthTexture, Input.TextureCoord).x;
|
||||
{
|
||||
float z = texture(DepthTexture, Input.TextureCoord).x;
|
||||
vec4 color = vec4(z, z, z, 0);
|
||||
|
||||
FragmentColor = color;
|
||||
|
||||
@@ -4,12 +4,14 @@ layout(location = 0) in vec3 Position;
|
||||
layout(location = 2) in vec2 TextureCoord;
|
||||
|
||||
out VertexData
|
||||
{ vec3 Position;
|
||||
{
|
||||
vec3 Position;
|
||||
vec2 TextureCoord;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{ gl_Position = vec4(Position, 1.0);
|
||||
{
|
||||
gl_Position = vec4(Position, 1.0);
|
||||
|
||||
Output.Position = Position;
|
||||
Output.TextureCoord = TextureCoord;
|
||||
|
||||
+10
-5
@@ -2,7 +2,8 @@
|
||||
#include "Skybox.h"
|
||||
|
||||
Skybox::Skybox(std::string skyboxPath, std::string extension /* = "png" */)
|
||||
{ m_Cubemap = std::make_shared<CubemapTexture>(
|
||||
{
|
||||
m_Cubemap = std::make_shared<CubemapTexture>(
|
||||
skyboxPath + "/right." + extension,
|
||||
skyboxPath + "/left." + extension,
|
||||
skyboxPath + "/top." + extension,
|
||||
@@ -14,8 +15,10 @@ Skybox::Skybox(std::string skyboxPath, std::string extension /* = "png" */)
|
||||
}
|
||||
|
||||
void Skybox::Initialize()
|
||||
{ float cubeVertices[] =
|
||||
{ -1.0f, -1.0f, -1.0f,
|
||||
{
|
||||
float cubeVertices[] =
|
||||
{
|
||||
-1.0f, -1.0f, -1.0f,
|
||||
1.0f, -1.0f, -1.0f,
|
||||
1.0f, 1.0f, -1.0f,
|
||||
-1.0f, 1.0f, -1.0f,
|
||||
@@ -28,7 +31,8 @@ void Skybox::Initialize()
|
||||
//std::copy(cubeVertices, cubeVertices + (3*8 - 1), m_CubeVertices);
|
||||
|
||||
unsigned int cubeIndices[] =
|
||||
{ // Back
|
||||
{
|
||||
// Back
|
||||
0, 2, 3,
|
||||
0, 1, 2,
|
||||
|
||||
@@ -78,7 +82,8 @@ Skybox::~Skybox()
|
||||
}
|
||||
|
||||
void Skybox::Draw()
|
||||
{ m_Cubemap->Bind(GL_TEXTURE0);
|
||||
{
|
||||
m_Cubemap->Bind(GL_TEXTURE0);
|
||||
|
||||
glBindVertexArray(vao);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Sound.h"
|
||||
|
||||
Sound::Sound(std::string path)
|
||||
{
|
||||
m_Buffer = 0;
|
||||
m_Buffer = LoadFile(path);
|
||||
}
|
||||
|
||||
ALuint Sound::LoadFile(std::string path)
|
||||
{
|
||||
char type[4];
|
||||
unsigned long size, chunkSize;
|
||||
short formatType, channels;
|
||||
unsigned long sampleRate, avgBytesPerSec;
|
||||
short bytesPerSample, bitsPerSample;
|
||||
unsigned long dataSize;
|
||||
|
||||
FILE* fp = NULL;
|
||||
fp = fopen(path.c_str(), "rb");
|
||||
|
||||
if (fp == NULL)
|
||||
{
|
||||
LOG_ERROR("Failed to load sound file \"%s\"", path.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
//CHECK FOR VALID WAVE-FILE
|
||||
fread(type, sizeof(char), 4, fp);
|
||||
if (type[0] != 'R' || type[1] != 'I' || type[2] != 'F' || type[3] != 'F')
|
||||
{
|
||||
LOG_ERROR("ERROR: No RIFF in WAVE-file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fread(&size, sizeof(unsigned long), 1, fp);
|
||||
fread(type, sizeof(char), 4, fp);
|
||||
if (type[0] != 'W' || type[1] != 'A' || type[2] != 'V' || type[3] != 'E')
|
||||
{
|
||||
LOG_ERROR("ERROR: Not WAVE-file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fread(type, sizeof(char), 4, fp);
|
||||
if (type[0] != 'f' || type[1] != 'm' || type[2] != 't' || type[3] != ' ')
|
||||
{
|
||||
LOG_ERROR("ERROR: No fmt in WAVE-file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
//READ THE DATA FROM WAVE-FILE
|
||||
fread(&chunkSize, sizeof(unsigned long), 1, fp);
|
||||
fread(&formatType, sizeof(short), 1, fp);
|
||||
fread(&channels, sizeof(short), 1, fp);
|
||||
fread(&sampleRate, sizeof(unsigned long), 1, fp);
|
||||
fread(&avgBytesPerSec, sizeof(unsigned long), 1, fp);
|
||||
fread(&bytesPerSample, sizeof(short), 1, fp);
|
||||
fread(&bitsPerSample, sizeof(short), 1, fp);
|
||||
|
||||
fread(type, sizeof(char), 4, fp);
|
||||
if (type[0] != 'd' || type[1] != 'a' || type[2] != 't' || type[3] != 'a')
|
||||
{
|
||||
LOG_ERROR("ERROR: WAVE-file Missing data");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fread(&dataSize, sizeof(unsigned long), 1, fp);
|
||||
|
||||
unsigned char* buf = new unsigned char[dataSize];
|
||||
fread(buf, sizeof(unsigned char), dataSize, fp);
|
||||
fclose(fp);
|
||||
|
||||
// Create buffer
|
||||
ALuint format = 0;
|
||||
if (bitsPerSample == 8)
|
||||
{
|
||||
if (channels == 1)
|
||||
format = AL_FORMAT_MONO8;
|
||||
else if (channels == 2)
|
||||
format = AL_FORMAT_STEREO8;
|
||||
}
|
||||
if (bitsPerSample == 16)
|
||||
{
|
||||
if (channels == 1)
|
||||
format = AL_FORMAT_MONO16;
|
||||
else if (channels == 2)
|
||||
format = AL_FORMAT_STEREO16;
|
||||
}
|
||||
|
||||
ALuint buffer;
|
||||
alGenBuffers(1, &buffer);
|
||||
alBufferData(buffer, format, buf, dataSize, sampleRate);
|
||||
delete[] buf;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#ifndef Sound_h__
|
||||
#define Sound_h__
|
||||
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
|
||||
#include "ResourceManager.h"
|
||||
|
||||
class Sound : public Resource
|
||||
{
|
||||
public:
|
||||
Sound(std::string path);
|
||||
|
||||
ALuint LoadFile(std::string path);
|
||||
|
||||
operator ALuint() const { return m_Buffer; }
|
||||
|
||||
private:
|
||||
ALuint m_Buffer;
|
||||
};
|
||||
|
||||
#endif // Sound_h__
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Factory.h"
|
||||
#include "Entity.h"
|
||||
#include "Component.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
class World;
|
||||
|
||||
@@ -13,6 +14,9 @@ public:
|
||||
System(World* world) : m_World(world) { }
|
||||
virtual ~System() { }
|
||||
|
||||
virtual void RegisterComponents(ComponentFactory* cf) { }
|
||||
virtual void RegisterResourceTypes(ResourceManager* rm) { }
|
||||
|
||||
virtual void Initialize() { }
|
||||
|
||||
// Called once per system every tick
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#include "FreeSteeringSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
Systems::FreeSteeringSystem::FreeSteeringSystem(World* world) : System(world)
|
||||
void Systems::FreeSteeringSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
|
||||
cf->Register("FreeSteering", []() { return new Components::FreeSteering(); });
|
||||
}
|
||||
|
||||
void Systems::FreeSteeringSystem::Update(double dt)
|
||||
@@ -13,42 +13,53 @@ void Systems::FreeSteeringSystem::Update(double dt)
|
||||
}
|
||||
|
||||
void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{ auto steering = m_World->GetComponent<Components::FreeSteering>(entity, "FreeSteering");
|
||||
{
|
||||
auto steering = m_World->GetComponent<Components::FreeSteering>(entity, "FreeSteering");
|
||||
auto input = m_World->GetComponent<Components::Input>(entity, "Input");
|
||||
if (steering && input)
|
||||
{ auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
|
||||
glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation);
|
||||
glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation);
|
||||
|
||||
float speed = steering->Speed;
|
||||
if (input->KeyState[GLFW_KEY_LEFT_SHIFT])
|
||||
{ speed *= 4.0f;
|
||||
{
|
||||
speed *= 4.0f;
|
||||
}
|
||||
if (input->KeyState[GLFW_KEY_LEFT_ALT])
|
||||
{ speed /= 4.0f;
|
||||
{
|
||||
speed /= 4.0f;
|
||||
}
|
||||
if (input->KeyState[GLFW_KEY_A])
|
||||
{ transform->Position -= Camera_Right * (float)dt * speed;
|
||||
{
|
||||
transform->Position -= Camera_Right * (float)dt * speed;
|
||||
}
|
||||
else if (input->KeyState[GLFW_KEY_D])
|
||||
{ transform->Position += Camera_Right * (float)dt * speed;
|
||||
{
|
||||
transform->Position += Camera_Right * (float)dt * speed;
|
||||
}
|
||||
if (input->KeyState[GLFW_KEY_W])
|
||||
{ transform->Position -= Camera_Forward * (float)dt * speed;
|
||||
{
|
||||
transform->Position -= Camera_Forward * (float)dt * speed;
|
||||
}
|
||||
if (input->KeyState[GLFW_KEY_S])
|
||||
{ transform->Position += Camera_Forward * (float)dt * speed;
|
||||
{
|
||||
transform->Position += Camera_Forward * (float)dt * speed;
|
||||
}
|
||||
if (input->KeyState[GLFW_KEY_SPACE])
|
||||
{ transform->Position += glm::vec3(0, 1, 0) * (float)dt * speed;
|
||||
{
|
||||
transform->Position += glm::vec3(0, 1, 0) * (float)dt * speed;
|
||||
}
|
||||
if (input->KeyState[GLFW_KEY_LEFT_CONTROL])
|
||||
{ transform->Position -= glm::vec3(0, 1, 0) * (float)dt * speed;
|
||||
{
|
||||
transform->Position -= glm::vec3(0, 1, 0) * (float)dt * speed;
|
||||
}
|
||||
|
||||
if (input->MouseState[GLFW_MOUSE_BUTTON_LEFT])
|
||||
{ // TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS // spelling tobias :3
|
||||
{
|
||||
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS // spelling tobias :3
|
||||
//---------------------------------------------------------------------
|
||||
transform->Orientation = glm::angleAxis<float>(input->dY / 300.f, glm::vec3(1, 0, 0)) * transform->Orientation;
|
||||
|
||||
@@ -57,4 +68,4 @@ void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,9 @@ namespace Systems
|
||||
class FreeSteeringSystem : public System
|
||||
{
|
||||
public:
|
||||
FreeSteeringSystem(World* world);
|
||||
FreeSteeringSystem(World* world)
|
||||
: System(world) { }
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
+25
-10
@@ -2,18 +2,26 @@
|
||||
#include "InputSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
void Systems::InputSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("Input", []() { return new Components::Input(); });
|
||||
}
|
||||
|
||||
void Systems::InputSystem::Update(double dt)
|
||||
{ m_LastKeyState = m_CurrentKeyState;
|
||||
{
|
||||
m_LastKeyState = m_CurrentKeyState;
|
||||
m_LastMouseState = m_CurrentMouseState;
|
||||
|
||||
// Keyboard input
|
||||
for (int i = 0; i <= GLFW_KEY_LAST; ++i)
|
||||
{ m_CurrentKeyState[i] = glfwGetKey(m_Renderer->GetWindow(), i);
|
||||
{
|
||||
m_CurrentKeyState[i] = glfwGetKey(m_Renderer->GetWindow(), i);
|
||||
}
|
||||
|
||||
// Mouse buttons
|
||||
for (int i = 0; i <= GLFW_MOUSE_BUTTON_LAST; ++i)
|
||||
{ m_CurrentMouseState[i] = glfwGetMouseButton(m_Renderer->GetWindow(), i);
|
||||
{
|
||||
m_CurrentMouseState[i] = glfwGetMouseButton(m_Renderer->GetWindow(), i);
|
||||
}
|
||||
|
||||
// Cursor position
|
||||
@@ -26,36 +34,43 @@ void Systems::InputSystem::Update(double dt)
|
||||
|
||||
// Lock mouse while holding LMB
|
||||
if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT])
|
||||
{ m_LastMouseX = m_Renderer->WIDTH / 2.f; // xpos;
|
||||
{
|
||||
m_LastMouseX = m_Renderer->WIDTH / 2.f; // xpos;
|
||||
m_LastMouseY = m_Renderer->HEIGHT / 2.f; // ypos;
|
||||
glfwSetCursorPos(m_Renderer->GetWindow(), m_LastMouseX, m_LastMouseY);
|
||||
}
|
||||
// Hide/show cursor with LMB
|
||||
if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT] && !m_LastMouseState[GLFW_MOUSE_BUTTON_LEFT])
|
||||
{ glfwSetInputMode(m_Renderer->GetWindow(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
{
|
||||
glfwSetInputMode(m_Renderer->GetWindow(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
}
|
||||
if (!m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT] && m_LastMouseState[GLFW_MOUSE_BUTTON_LEFT])
|
||||
{ glfwSetInputMode(m_Renderer->GetWindow(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
{
|
||||
glfwSetInputMode(m_Renderer->GetWindow(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Wireframe
|
||||
if (m_CurrentKeyState[GLFW_KEY_F1] && !m_LastKeyState[GLFW_KEY_F1])
|
||||
{ m_Renderer->DrawWireframe(!m_Renderer->DrawWireframe());
|
||||
{
|
||||
m_Renderer->DrawWireframe(!m_Renderer->DrawWireframe());
|
||||
}
|
||||
// Normals
|
||||
if (m_CurrentKeyState[GLFW_KEY_F2] && !m_LastKeyState[GLFW_KEY_F2])
|
||||
{ m_Renderer->DrawNormals(!m_Renderer->DrawNormals());
|
||||
{
|
||||
m_Renderer->DrawNormals(!m_Renderer->DrawNormals());
|
||||
}
|
||||
// Bounds
|
||||
if (m_CurrentKeyState[GLFW_KEY_F3] && !m_LastKeyState[GLFW_KEY_F3])
|
||||
{ m_Renderer->DrawBounds(!m_Renderer->DrawBounds());
|
||||
{
|
||||
m_Renderer->DrawBounds(!m_Renderer->DrawBounds());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Systems::InputSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{ auto input = m_World->GetComponent<Components::Input>(entity, "Input");
|
||||
{
|
||||
auto input = m_World->GetComponent<Components::Input>(entity, "Input");
|
||||
if (input == nullptr)
|
||||
return;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ class InputSystem : public System
|
||||
public:
|
||||
InputSystem(World* world, std::shared_ptr<Renderer> renderer)
|
||||
: System(world), m_Renderer(renderer) { }
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
|
||||
|
||||
Systems::PhysicsSystem::PhysicsSystem(World* world) : System(world)
|
||||
{ m_Broadphase = new btDbvtBroadphase();
|
||||
{
|
||||
m_Broadphase = new btDbvtBroadphase();
|
||||
m_CollisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
m_Dispatcher = new btCollisionDispatcher(m_CollisionConfiguration);
|
||||
m_Solver = new btSequentialImpulseConstraintSolver();
|
||||
@@ -15,17 +16,36 @@ Systems::PhysicsSystem::PhysicsSystem(World* world) : System(world)
|
||||
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("Physics", []() { return new Components::Physics(); });
|
||||
|
||||
cf->Register("CompoundShape", []() { return new Components::CompoundShape(); });
|
||||
cf->Register("SphereShape", []() { return new Components::SphereShape(); });
|
||||
cf->Register("BoxShape", []() { return new Components::BoxShape(); });
|
||||
|
||||
cf->Register("HingeConstraint", []() { return new Components::HingeConstraint(); });
|
||||
cf->Register("BallSocketConstraint", []() { return new Components::BallSocketConstraint(); });
|
||||
cf->Register("SliderConstraint", []() { return new Components::SliderConstraint(); });
|
||||
|
||||
cf->Register("Vehicle", []() { return new Components::Vehicle(); });
|
||||
cf->Register("Wheel", []() { return new Components::Wheel(); });
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::Update(double dt)
|
||||
{ // Update entity transform in physics world
|
||||
{
|
||||
// Update entity transform in physics world
|
||||
for (auto pair : *m_World->GetEntities())
|
||||
{ EntityID entity = pair.first;
|
||||
{
|
||||
EntityID entity = pair.first;
|
||||
EntityID parent = pair.second;
|
||||
|
||||
if (parent != 0)
|
||||
continue;
|
||||
|
||||
if (m_PhysicsData.find(entity) != m_PhysicsData.end())
|
||||
{ PhysicsData* physicsData = &m_PhysicsData[entity];
|
||||
{
|
||||
PhysicsData* physicsData = &m_PhysicsData[entity];
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
|
||||
btTransform transform;
|
||||
@@ -47,7 +67,8 @@ void Systems::PhysicsSystem::Update(double dt)
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{ auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
if (!transformComponent)
|
||||
return;
|
||||
|
||||
@@ -60,8 +81,10 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
||||
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity, "Wheel");
|
||||
|
||||
if (physicsComponent || sphereShapeComponent || boxShapeComponent || meshShapeComponent || staticMeshShapeComponent)
|
||||
{ if (m_PhysicsData.find(entity) == m_PhysicsData.end())
|
||||
{ SetUpPhysicsState(entity, parent);
|
||||
{
|
||||
if (m_PhysicsData.find(entity) == m_PhysicsData.end())
|
||||
{
|
||||
SetUpPhysicsState(entity, parent);
|
||||
}
|
||||
|
||||
if (parent != 0)
|
||||
@@ -80,8 +103,10 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
||||
transformComponent->Orientation.w = transform.getRotation().w();
|
||||
}
|
||||
else
|
||||
{ if (m_PhysicsData.find(entity) != m_PhysicsData.end())
|
||||
{ TearDownPhysicsState(entity, parent);
|
||||
{
|
||||
if (m_PhysicsData.find(entity) != m_PhysicsData.end())
|
||||
{
|
||||
TearDownPhysicsState(entity, parent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,12 +115,15 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
||||
auto hingeComponent = m_World->GetComponent<Components::HingeConstraint>(entity, "HingeConstraint");
|
||||
|
||||
if (ballSocketComponent)
|
||||
{ EntityID entityA = ballSocketComponent->EntityA;
|
||||
{
|
||||
EntityID entityA = ballSocketComponent->EntityA;
|
||||
EntityID entityB = ballSocketComponent->EntityB;
|
||||
|
||||
if (m_Constraints.find(std::make_pair(entityA, entityB)) == m_Constraints.end())
|
||||
{ if (m_PhysicsData.find(entityA) != m_PhysicsData.end() && m_PhysicsData.find(entityB) != m_PhysicsData.end())
|
||||
{ btVector3 pivotA = btVector3(ballSocketComponent->PivotA.x, ballSocketComponent->PivotA.y, ballSocketComponent->PivotA.z);
|
||||
{
|
||||
if (m_PhysicsData.find(entityA) != m_PhysicsData.end() && m_PhysicsData.find(entityB) != m_PhysicsData.end())
|
||||
{
|
||||
btVector3 pivotA = btVector3(ballSocketComponent->PivotA.x, ballSocketComponent->PivotA.y, ballSocketComponent->PivotA.z);
|
||||
btVector3 pivotB = btVector3(ballSocketComponent->PivotB.x, ballSocketComponent->PivotB.y, ballSocketComponent->PivotB.z);
|
||||
|
||||
m_Constraints[std::make_pair(entityA, entityB)] = new btPoint2PointConstraint(*m_PhysicsData[entityA].RigidBody, *m_PhysicsData[entityB].RigidBody, pivotA, pivotB);
|
||||
@@ -105,12 +133,15 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
||||
}
|
||||
}
|
||||
else if (sliderComponent)
|
||||
{ EntityID entityA = sliderComponent->EntityA;
|
||||
{
|
||||
EntityID entityA = sliderComponent->EntityA;
|
||||
EntityID entityB = sliderComponent->EntityB;
|
||||
|
||||
if (m_Constraints.find(std::make_pair(entityA, entityB)) == m_Constraints.end())
|
||||
{ if (m_PhysicsData.find(entityA) != m_PhysicsData.end() && m_PhysicsData.find(entityB) != m_PhysicsData.end())
|
||||
{ btTransform transformA;
|
||||
{
|
||||
if (m_PhysicsData.find(entityA) != m_PhysicsData.end() && m_PhysicsData.find(entityB) != m_PhysicsData.end())
|
||||
{
|
||||
btTransform transformA;
|
||||
m_PhysicsData[entityA].MotionState->getWorldTransform(transformA);
|
||||
btTransform transformB;
|
||||
m_PhysicsData[entityB].MotionState->getWorldTransform(transformB);
|
||||
@@ -121,12 +152,15 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
||||
}
|
||||
}
|
||||
else if (hingeComponent)
|
||||
{ EntityID entityA = hingeComponent->EntityA;
|
||||
{
|
||||
EntityID entityA = hingeComponent->EntityA;
|
||||
EntityID entityB = hingeComponent->EntityB;
|
||||
|
||||
if (m_Constraints.find(std::make_pair(entityA, entityB)) == m_Constraints.end())
|
||||
{ if (m_PhysicsData.find(entityA) != m_PhysicsData.end() && m_PhysicsData.find(entityB) != m_PhysicsData.end())
|
||||
{ btVector3 PivotA = btVector3(hingeComponent->PivotA.x, hingeComponent->PivotA.y, hingeComponent->PivotA.z);
|
||||
{
|
||||
if (m_PhysicsData.find(entityA) != m_PhysicsData.end() && m_PhysicsData.find(entityB) != m_PhysicsData.end())
|
||||
{
|
||||
btVector3 PivotA = btVector3(hingeComponent->PivotA.x, hingeComponent->PivotA.y, hingeComponent->PivotA.z);
|
||||
btVector3 PivotB = btVector3(hingeComponent->PivotB.x, hingeComponent->PivotB.y, hingeComponent->PivotB.z);
|
||||
|
||||
btVector3 AxisA = btVector3(hingeComponent->AxisA.x, hingeComponent->AxisA.y, hingeComponent->AxisA.z);
|
||||
@@ -214,9 +248,11 @@ void Systems::PhysicsSystem::OnComponentRemoved(std::string type, Component* com
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
||||
{ auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
if (!transformComponent)
|
||||
{ LOG_WARNING("Physics component missing transform component on entity %i", entity);
|
||||
{
|
||||
LOG_WARNING("Physics component missing transform component on entity %i", entity);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -228,7 +264,8 @@ void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
||||
auto staticMeshShapeComponent = m_World->GetComponent<Components::StaticMeshShape>(entity, "StaticMeshShape");
|
||||
|
||||
if (compoundShapeComponent && (sphereShapeComponent || boxShapeComponent || meshShapeComponent || staticMeshShapeComponent))
|
||||
{ LOG_WARNING("Entity %i has both compound shape and normal shape! Normal shapes must be children to entity with compound shape.", entity);
|
||||
{
|
||||
LOG_WARNING("Entity %i has both compound shape and normal shape! Normal shapes must be children to entity with compound shape.", entity);
|
||||
}
|
||||
|
||||
PhysicsData* physicsData = &m_PhysicsData[entity];
|
||||
@@ -238,7 +275,8 @@ void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
||||
|
||||
// Set-up compound shape
|
||||
if (compoundShapeComponent)
|
||||
{ btCompoundShape* compoundShape = new btCompoundShape();
|
||||
{
|
||||
btCompoundShape* compoundShape = new btCompoundShape();
|
||||
physicsData->CollisionShape = compoundShape;
|
||||
|
||||
btTransform transform;
|
||||
@@ -247,7 +285,8 @@ void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
||||
|
||||
btVector3 inertia;
|
||||
if (physicsComponent->Mass != 0)
|
||||
{ physicsData->CollisionShape->calculateLocalInertia(physicsComponent->Mass, inertia);
|
||||
{
|
||||
physicsData->CollisionShape->calculateLocalInertia(physicsComponent->Mass, inertia);
|
||||
}
|
||||
|
||||
btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(physicsComponent->Mass, physicsData->MotionState, physicsData->CollisionShape, inertia);
|
||||
@@ -258,26 +297,32 @@ void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
||||
|
||||
// Set-up normal shapes
|
||||
else if (boxShapeComponent)
|
||||
{ physicsData->CollisionShape = new btBoxShape(btVector3(boxShapeComponent->Width, boxShapeComponent->Height, boxShapeComponent->Depth));
|
||||
{
|
||||
physicsData->CollisionShape = new btBoxShape(btVector3(boxShapeComponent->Width, boxShapeComponent->Height, boxShapeComponent->Depth));
|
||||
}
|
||||
else if (sphereShapeComponent)
|
||||
{ physicsData->CollisionShape = new btSphereShape(sphereShapeComponent->Radius);
|
||||
{
|
||||
physicsData->CollisionShape = new btSphereShape(sphereShapeComponent->Radius);
|
||||
}
|
||||
else if (meshShapeComponent)
|
||||
{ // TODO: Collision mesh things go here
|
||||
{
|
||||
// TODO: Collision mesh things go here
|
||||
//new btConvexTriangleMeshShape()
|
||||
}
|
||||
if (boxShapeComponent || sphereShapeComponent || meshShapeComponent || staticMeshShapeComponent)
|
||||
{ btTransform transform;
|
||||
{
|
||||
btTransform transform;
|
||||
transform.setFromOpenGLMatrix(glm::value_ptr(glm::translate(glm::mat4(), transformComponent->Position) * glm::toMat4(transformComponent->Orientation)));
|
||||
|
||||
// If there's a local physics component
|
||||
if (physicsComponent)
|
||||
{ physicsData->MotionState = new btDefaultMotionState(transform);
|
||||
{
|
||||
physicsData->MotionState = new btDefaultMotionState(transform);
|
||||
|
||||
btVector3 inertia;
|
||||
if (physicsComponent->Mass != 0)
|
||||
{ physicsData->CollisionShape->calculateLocalInertia(physicsComponent->Mass, inertia);
|
||||
{
|
||||
physicsData->CollisionShape->calculateLocalInertia(physicsComponent->Mass, inertia);
|
||||
}
|
||||
|
||||
btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(physicsComponent->Mass, physicsData->MotionState, physicsData->CollisionShape, inertia);
|
||||
@@ -286,16 +331,19 @@ void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
||||
m_DynamicsWorld->addRigidBody(physicsData->RigidBody);
|
||||
}
|
||||
else
|
||||
{ // Otherwise, find our base parent and attach to compound shape
|
||||
{
|
||||
// Otherwise, find our base parent and attach to compound shape
|
||||
EntityID baseParent = m_World->GetEntityBaseParent(entity);
|
||||
auto basePhysicsComponent = m_World->GetComponent<Components::Physics>(baseParent, "Physics");
|
||||
if (!basePhysicsComponent)
|
||||
{ LOG_WARNING("Failed to attach orphan collision shape on entity %i: missing physics component on base parent entity %i", entity, baseParent);
|
||||
{
|
||||
LOG_WARNING("Failed to attach orphan collision shape on entity %i: missing physics component on base parent entity %i", entity, baseParent);
|
||||
return;
|
||||
}
|
||||
auto baseCompoundShapeComponent = m_World->GetComponent<Components::CompoundShape>(baseParent, "CompoundShape");
|
||||
if (!baseCompoundShapeComponent)
|
||||
{ LOG_WARNING("Failed to attach orphan collision shape on entity %i: missing compound shape on base parent entity %i", entity, baseParent);
|
||||
{
|
||||
LOG_WARNING("Failed to attach orphan collision shape on entity %i: missing compound shape on base parent entity %i", entity, baseParent);
|
||||
return;
|
||||
}
|
||||
PhysicsData* basePhysicsData = &m_PhysicsData.at(baseParent);
|
||||
@@ -313,7 +361,8 @@ void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::TearDownPhysicsState(EntityID entity, EntityID parent)
|
||||
{ PhysicsData* physicsData = &m_PhysicsData[entity];
|
||||
{
|
||||
PhysicsData* physicsData = &m_PhysicsData[entity];
|
||||
|
||||
delete physicsData->RigidBody;
|
||||
delete physicsData->MotionState;
|
||||
@@ -321,4 +370,3 @@ void Systems::PhysicsSystem::TearDownPhysicsState(EntityID entity, EntityID pare
|
||||
|
||||
m_PhysicsData.erase(entity);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ class PhysicsSystem : public System
|
||||
{
|
||||
public:
|
||||
PhysicsSystem(World* world);
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
||||
@@ -43,7 +45,8 @@ private:
|
||||
|
||||
|
||||
struct PhysicsData
|
||||
{ btRigidBody* RigidBody;
|
||||
{
|
||||
btRigidBody* RigidBody;
|
||||
btMotionState* MotionState;
|
||||
btCollisionShape* CollisionShape;
|
||||
};
|
||||
|
||||
@@ -3,44 +3,37 @@
|
||||
#include "World.h"
|
||||
|
||||
void Systems::RenderSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> component)
|
||||
{ if(type == "Model")
|
||||
{ auto modelComponent = std::static_pointer_cast<Components::Model>(component);
|
||||
{
|
||||
if(type == "Model")
|
||||
{
|
||||
auto modelComponent = std::static_pointer_cast<Components::Model>(component);
|
||||
}
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{ auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
if (transformComponent == nullptr)
|
||||
return;
|
||||
|
||||
// Draw models
|
||||
auto modelComponent = m_World->GetComponent<Components::Model>(entity, "Model");
|
||||
if (modelComponent != nullptr)
|
||||
{ if (m_CachedModels.find(modelComponent->ModelFile) == m_CachedModels.end())
|
||||
{ m_CachedModels[modelComponent->ModelFile] = std::make_shared<Model>(OBJ(modelComponent->ModelFile));
|
||||
{
|
||||
auto model = m_World->GetResourceManager()->Load<Model>("Model", modelComponent->ModelFile);
|
||||
if (model != nullptr)
|
||||
{
|
||||
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||
glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity);
|
||||
glm::vec3 scale = m_TransformSystem->AbsoluteScale(entity);
|
||||
m_Renderer->AddModelToDraw(model, position, orientation, scale, modelComponent->Visible, modelComponent->ShadowCaster);
|
||||
}
|
||||
|
||||
auto model = m_CachedModels[modelComponent->ModelFile];
|
||||
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||
glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity);
|
||||
glm::vec3 scale = m_TransformSystem->AbsoluteScale(entity);
|
||||
m_Renderer->AddModelToDraw(model, position, orientation, scale, modelComponent->Visible, modelComponent->ShadowCaster);
|
||||
}
|
||||
|
||||
// Debug draw bounds
|
||||
#ifdef DEBUG
|
||||
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
|
||||
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
|
||||
if (bounds != nullptr)
|
||||
{ glm::vec3 origin = m_TransformSystem->AbsolutePosition(entity) + (transformComponent->Scale * bounds->Origin);
|
||||
glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector;
|
||||
m_Renderer->AddAABBToDraw(origin, volumeVector, (collision != nullptr && collision->CollidingEntities.size() > 0));
|
||||
}
|
||||
#endif
|
||||
|
||||
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity, "PointLight");
|
||||
if (pointLightComponent != nullptr)
|
||||
{ glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||
{
|
||||
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||
m_Renderer->AddPointLightToDraw(
|
||||
position,
|
||||
pointLightComponent->Specular,
|
||||
@@ -53,7 +46,8 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
|
||||
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity, "Camera");
|
||||
if (cameraComponent != nullptr)
|
||||
{ m_Renderer->GetCamera()->Position(transformComponent->Position);
|
||||
{
|
||||
m_Renderer->GetCamera()->Position(transformComponent->Position);
|
||||
m_Renderer->GetCamera()->Orientation(transformComponent->Orientation);
|
||||
|
||||
m_Renderer->GetCamera()->FOV(cameraComponent->FOV);
|
||||
@@ -63,7 +57,23 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::Initialize()
|
||||
{ m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>("TransformSystem");
|
||||
{
|
||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>("TransformSystem");
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("Camera", []() { return new Components::Camera(); });
|
||||
cf->Register("Model", []() { return new Components::Model(); });
|
||||
cf->Register("Sprite", []() { return new Components::Sprite(); });
|
||||
cf->Register("PointLight", []() { return new Components::PointLight(); });
|
||||
cf->Register("DirectionalLight", []() { return new Components::DirectionalLight(); });
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::RegisterResourceTypes(ResourceManager* rm)
|
||||
{
|
||||
rm->RegisterType("Model", [rm](std::string resourceName) { return new Model(OBJ(resourceName), rm); });
|
||||
rm->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); });
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,11 +7,15 @@
|
||||
#include "Systems/TransformSystem.h"
|
||||
#include "Model.h"
|
||||
#include "Texture.h"
|
||||
#include "Components/Model.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Camera.h"
|
||||
#include "Components/Bounds.h"
|
||||
#include "Components/Collision.h"
|
||||
#include "Components/Model.h"
|
||||
#include "Components/Sprite.h"
|
||||
#include "Components/PointLight.h"
|
||||
#include "Components/DirectionalLight.h"
|
||||
|
||||
#include "Components/Template.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
namespace Systems
|
||||
@@ -23,6 +27,8 @@ public:
|
||||
RenderSystem(World* world, std::shared_ptr<Renderer> renderer)
|
||||
: System(world), m_Renderer(renderer) { }
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void RegisterResourceTypes(ResourceManager* rm) override;
|
||||
void Initialize() override;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels;
|
||||
@@ -30,6 +36,9 @@ public:
|
||||
void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
std::shared_ptr<Renderer> m_Renderer;
|
||||
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
|
||||
|
||||
+42
-94
@@ -4,15 +4,18 @@
|
||||
|
||||
Systems::SoundSystem::SoundSystem(World* world)
|
||||
: System(world)
|
||||
{ //initialize OpenAL
|
||||
{
|
||||
//initialize OpenAL
|
||||
ALCdevice* Device = alcOpenDevice(NULL);
|
||||
ALCcontext* context;
|
||||
if(Device)
|
||||
{ context = alcCreateContext(Device, NULL);
|
||||
{
|
||||
context = alcCreateContext(Device, NULL);
|
||||
alcMakeContextCurrent(context);
|
||||
}
|
||||
else
|
||||
{ LOG_ERROR("OMG OPEN AL FAIL");
|
||||
{
|
||||
LOG_ERROR("OMG OPEN AL FAIL");
|
||||
}
|
||||
|
||||
alGetError();
|
||||
@@ -21,19 +24,31 @@ Systems::SoundSystem::SoundSystem(World* world)
|
||||
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("SoundEmitter", []() { return new Components::SoundEmitter(); });
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::RegisterResourceTypes(ResourceManager* rm)
|
||||
{
|
||||
rm->RegisterType("Sound", [](std::string resourceName) { return new Sound(resourceName); });
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::Update(double dt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{ auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
if (transformComponent == nullptr)
|
||||
return;
|
||||
|
||||
auto entityName = m_World->GetProperty<std::string>(entity, "Name");
|
||||
if (entityName == "Camera")
|
||||
{ glm::vec3 playerPos = transformComponent->Position;
|
||||
{
|
||||
glm::vec3 playerPos = transformComponent->Position;
|
||||
ALfloat listenerPos[3] = { playerPos.x, playerPos.y, -playerPos.z };
|
||||
|
||||
glm::vec3 playerVel = transformComponent->Velocity;
|
||||
@@ -52,7 +67,8 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
|
||||
|
||||
auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity, "SoundEmitter");
|
||||
if(soundEmitter != nullptr)
|
||||
{ ALuint source = m_Sources[soundEmitter];
|
||||
{
|
||||
ALuint source = m_Sources[soundEmitter];
|
||||
alSourcef(source, AL_GAIN, soundEmitter->Gain);
|
||||
//alSourcef(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance);
|
||||
alSourcef(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance);
|
||||
@@ -71,10 +87,11 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::PlaySound(Components::SoundEmitter* emitter, std::string fileName)
|
||||
{ if (m_Sources.find(emitter) == m_Sources.end())
|
||||
{
|
||||
if (m_Sources.find(emitter) == m_Sources.end())
|
||||
return;
|
||||
|
||||
ALuint buffer = LoadFile(fileName);
|
||||
ALuint buffer = *m_World->GetResourceManager()->Load<Sound>("Sound", fileName);
|
||||
if (buffer == 0)
|
||||
return;
|
||||
ALuint source = m_Sources[emitter];
|
||||
@@ -83,115 +100,46 @@ void Systems::SoundSystem::PlaySound(Components::SoundEmitter* emitter, std::str
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::PlaySound(std::shared_ptr<Components::SoundEmitter> emitter)
|
||||
{ ALuint buffer = LoadFile(emitter->Path);
|
||||
{
|
||||
ALuint buffer = *m_World->GetResourceManager()->Load<Sound>("Sound", emitter->Path);
|
||||
ALuint source = m_Sources[emitter.get()];
|
||||
alSourcei(source, AL_BUFFER, buffer);
|
||||
alSourcePlay(m_Sources[emitter.get()]);
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::StopSound(std::shared_ptr<Components::SoundEmitter> emitter)
|
||||
{ alSourceStop(m_Sources[emitter.get()]);
|
||||
{
|
||||
alSourceStop(m_Sources[emitter.get()]);
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> component)
|
||||
{ if(type == "SoundEmitter")
|
||||
{ ALuint source = CreateSource();
|
||||
{
|
||||
if(type == "SoundEmitter")
|
||||
{
|
||||
ALuint source = CreateSource();
|
||||
m_Sources[component.get()] = source;
|
||||
}
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::OnComponentRemoved(std::string type, Component* component)
|
||||
{ if(type == "SoundEmitter")
|
||||
{ if (m_Sources.find(component) != m_Sources.end())
|
||||
{ ALuint source = m_Sources[component];
|
||||
{
|
||||
if(type == "SoundEmitter")
|
||||
{
|
||||
if (m_Sources.find(component) != m_Sources.end())
|
||||
{
|
||||
ALuint source = m_Sources[component];
|
||||
alDeleteSources(1, &source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ALuint Systems::SoundSystem::LoadFile(std::string path)
|
||||
{ if (m_BufferCache.find(path) != m_BufferCache.end())
|
||||
return m_BufferCache[path];
|
||||
|
||||
FILE* fp = NULL;
|
||||
fp = fopen(path.c_str(), "rb");
|
||||
|
||||
if (fp == NULL)
|
||||
{ LOG_ERROR("Failed to load sound file \"%s\"", path.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
//CHECK FOR VALID WAVE-FILE
|
||||
fread(type, sizeof(char), 4, fp);
|
||||
if(type[0]!='R' || type[1]!='I' || type[2]!='F' || type[3]!='F')
|
||||
{ LOG_ERROR("ERROR: No RIFF in WAVE-file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fread(&size, sizeof(unsigned long), 1, fp);
|
||||
fread(type, sizeof(char), 4, fp);
|
||||
if(type[0]!='W' || type[1]!='A' || type[2]!='V' || type[3]!='E')
|
||||
{ LOG_ERROR("ERROR: Not WAVE-file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fread(type, sizeof(char), 4, fp);
|
||||
if(type[0]!='f' || type[1]!='m' || type[2]!='t' || type[3]!=' ')
|
||||
{ LOG_ERROR("ERROR: No fmt in WAVE-file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
//READ THE DATA FROM WAVE-FILE
|
||||
fread(&chunkSize, sizeof(unsigned long), 1, fp);
|
||||
fread(&formatType, sizeof(short), 1, fp);
|
||||
fread(&channels, sizeof(short), 1, fp);
|
||||
fread(&sampleRate, sizeof(unsigned long), 1, fp);
|
||||
fread(&avgBytesPerSec, sizeof(unsigned long), 1, fp);
|
||||
fread(&bytesPerSample, sizeof(short), 1, fp);
|
||||
fread(&bitsPerSample, sizeof(short), 1, fp);
|
||||
|
||||
fread(type, sizeof(char), 4, fp);
|
||||
if(type[0]!='d' || type[1]!='a' || type[2]!='t' || type[3]!='a')
|
||||
{ LOG_ERROR("ERROR: WAVE-file Missing data");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fread(&dataSize, sizeof(unsigned long), 1, fp);
|
||||
|
||||
unsigned char* buf = new unsigned char[dataSize];
|
||||
fread(buf, sizeof(unsigned char), dataSize, fp);
|
||||
fclose(fp);
|
||||
|
||||
// Create buffer
|
||||
ALuint format = 0;
|
||||
if(bitsPerSample == 8)
|
||||
{ if(channels == 1)
|
||||
format = AL_FORMAT_MONO8;
|
||||
else if(channels == 2)
|
||||
format = AL_FORMAT_STEREO8;
|
||||
}
|
||||
if(bitsPerSample == 16)
|
||||
{ if (channels == 1)
|
||||
format = AL_FORMAT_MONO16;
|
||||
else if (channels == 2)
|
||||
format = AL_FORMAT_STEREO16;
|
||||
}
|
||||
|
||||
ALuint buffer;
|
||||
alGenBuffers(1, &buffer);
|
||||
alBufferData(buffer, format, buf, dataSize, sampleRate);
|
||||
delete[] buf;
|
||||
|
||||
m_BufferCache[path] = buffer;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
ALuint Systems::SoundSystem::CreateSource()
|
||||
{ ALuint source;
|
||||
{
|
||||
ALuint source;
|
||||
alGenSources((ALuint)1, &source);
|
||||
|
||||
alDopplerFactor(1); // Numbers greater than 1 will increase Doppler effect, numbers lower than 1 will decrease the Doppler effect
|
||||
alDopplerVelocity(350.f); // Defines the velocity of the sound
|
||||
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-10
@@ -1,12 +1,13 @@
|
||||
#ifndef SoundEmitter_h__
|
||||
#define SoundEmitter_h__
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#include <vector>
|
||||
|
||||
#include "System.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/SoundEmitter.h"
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#include <vector>
|
||||
#include "Sound.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
@@ -15,6 +16,8 @@ class SoundSystem : public System
|
||||
{
|
||||
public:
|
||||
SoundSystem(World* world);
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void RegisterResourceTypes(ResourceManager* rm) override;
|
||||
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
@@ -29,13 +32,12 @@ private:
|
||||
ALuint CreateSource();
|
||||
|
||||
//File-info
|
||||
char type[4];
|
||||
unsigned long size, chunkSize;
|
||||
short formatType, channels;
|
||||
unsigned long sampleRate, avgBytesPerSec;
|
||||
short bytesPerSample, bitsPerSample;
|
||||
unsigned long dataSize;
|
||||
|
||||
//char type[4];
|
||||
//unsigned long size, chunkSize;
|
||||
//short formatType, channels;
|
||||
//unsigned long sampleRate, avgBytesPerSec;
|
||||
//short bytesPerSample, bitsPerSample;
|
||||
//unsigned long dataSize;
|
||||
|
||||
std::map<Component*, ALuint> m_Sources;
|
||||
std::map<std::string, ALuint> m_BufferCache; // string = fileName
|
||||
|
||||
@@ -14,11 +14,13 @@
|
||||
//}
|
||||
|
||||
glm::vec3 Systems::TransformSystem::AbsolutePosition(EntityID entity)
|
||||
{ glm::vec3 absPosition;
|
||||
{
|
||||
glm::vec3 absPosition;
|
||||
glm::quat accumulativeOrientation;
|
||||
|
||||
do
|
||||
{ auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
//absPosition += transform->Position;
|
||||
entity = m_World->GetEntityParent(entity);
|
||||
auto transform2 = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
@@ -26,34 +28,35 @@ glm::vec3 Systems::TransformSystem::AbsolutePosition(EntityID entity)
|
||||
absPosition += transform2->Orientation * transform->Position;
|
||||
else
|
||||
absPosition += transform->Position;
|
||||
}
|
||||
while (entity != 0);
|
||||
} while (entity != 0);
|
||||
|
||||
return absPosition * accumulativeOrientation;
|
||||
}
|
||||
|
||||
glm::quat Systems::TransformSystem::AbsoluteOrientation(EntityID entity)
|
||||
{ glm::quat absOrientation;
|
||||
{
|
||||
glm::quat absOrientation;
|
||||
|
||||
do
|
||||
{ auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
absOrientation *= transform->Orientation;
|
||||
entity = m_World->GetEntityParent(entity);
|
||||
}
|
||||
while (entity != 0);
|
||||
} while (entity != 0);
|
||||
|
||||
return absOrientation;
|
||||
}
|
||||
|
||||
glm::vec3 Systems::TransformSystem::AbsoluteScale(EntityID entity)
|
||||
{ glm::vec3 absScale(1);
|
||||
{
|
||||
glm::vec3 absScale(1);
|
||||
|
||||
do
|
||||
{ auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
absScale *= transform->Scale;
|
||||
entity = m_World->GetEntityParent(entity);
|
||||
}
|
||||
while (entity != 0);
|
||||
} while (entity != 0);
|
||||
|
||||
return absScale;
|
||||
}
|
||||
|
||||
+10
-5
@@ -2,25 +2,30 @@
|
||||
#include "Texture.h"
|
||||
|
||||
Texture::Texture(std::string path)
|
||||
{ Load(path);
|
||||
{
|
||||
Load(path);
|
||||
}
|
||||
|
||||
void Texture::Load(std::string path)
|
||||
{ auto cachedTexture = m_TextureCache.find(path);
|
||||
{
|
||||
auto cachedTexture = m_TextureCache.find(path);
|
||||
if (cachedTexture == m_TextureCache.end())
|
||||
{ m_TextureCache[path] = SOIL_load_OGL_texture(path.c_str(), 0, 0, SOIL_FLAG_INVERT_Y);
|
||||
{
|
||||
m_TextureCache[path] = SOIL_load_OGL_texture(path.c_str(), 0, 0, SOIL_FLAG_INVERT_Y);
|
||||
}
|
||||
|
||||
m_Texture = m_TextureCache[path];
|
||||
}
|
||||
|
||||
void Texture::Bind()
|
||||
{ glActiveTexture(GL_TEXTURE0);
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_Texture);
|
||||
}
|
||||
|
||||
Texture::~Texture()
|
||||
{ glDeleteTextures(1, &m_Texture);
|
||||
{
|
||||
glDeleteTextures(1, &m_Texture);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-1
@@ -6,7 +6,9 @@
|
||||
|
||||
#include <SOIL.h>
|
||||
|
||||
class Texture
|
||||
#include "ResourceManager.h"
|
||||
|
||||
class Texture : public Resource
|
||||
{
|
||||
public:
|
||||
Texture(std::string path);
|
||||
|
||||
+4
-2
@@ -5,9 +5,11 @@
|
||||
#include <iostream>
|
||||
|
||||
inline bool _GLERROR(char* info, char* file, char* func, unsigned int line)
|
||||
{ GLenum error = glGetError();
|
||||
{
|
||||
GLenum error = glGetError();
|
||||
if (error != GL_NO_ERROR)
|
||||
{ _LOG(LOG_LEVEL_ERROR, file, func, line, "GL Error: %s %i %s", info, error, gluErrorString(error));
|
||||
{
|
||||
_LOG(LOG_LEVEL_ERROR, file, func, line, "GL Error: %s %i %s", info, error, gluErrorString(error));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+10
-5
@@ -20,7 +20,8 @@
|
||||
#include <stdarg.h>
|
||||
|
||||
enum _LOG_LEVEL
|
||||
{ LOG_LEVEL_ERROR,
|
||||
{
|
||||
LOG_LEVEL_ERROR,
|
||||
LOG_LEVEL_WARNING,
|
||||
LOG_LEVEL_INFO,
|
||||
LOG_LEVEL_DEBUG
|
||||
@@ -33,14 +34,16 @@ static _LOG_LEVEL LOG_LEVEL = LOG_LEVEL_INFO;
|
||||
#endif
|
||||
|
||||
const static char* _LOG_LEVEL_PREFIX[] =
|
||||
{ "E: ",
|
||||
{
|
||||
"E: ",
|
||||
"W: ",
|
||||
"",
|
||||
"D: "
|
||||
};
|
||||
|
||||
static void _LOG(_LOG_LEVEL logLevel, char* file, char* func, unsigned int line, const char* format, ...)
|
||||
{ if (logLevel > LOG_LEVEL)
|
||||
{
|
||||
if (logLevel > LOG_LEVEL)
|
||||
return;
|
||||
|
||||
va_list args;
|
||||
@@ -53,11 +56,13 @@ static void _LOG(_LOG_LEVEL logLevel, char* file, char* func, unsigned int line,
|
||||
va_end(args);
|
||||
|
||||
if (logLevel == LOG_LEVEL_ERROR)
|
||||
{ std::cerr << file << ":" << line << " " << func << std::endl;
|
||||
{
|
||||
std::cerr << file << ":" << line << " " << func << std::endl;
|
||||
std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
|
||||
}
|
||||
else
|
||||
{ std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
|
||||
{
|
||||
std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
|
||||
}
|
||||
|
||||
delete[] message;
|
||||
|
||||
+54
-28
@@ -2,35 +2,44 @@
|
||||
#include "World.h"
|
||||
|
||||
void World::RecycleEntityID(EntityID id)
|
||||
{ m_RecycledEntityIDs.push(id);
|
||||
{
|
||||
m_RecycledEntityIDs.push(id);
|
||||
}
|
||||
|
||||
EntityID World::GenerateEntityID()
|
||||
{ if (!m_RecycledEntityIDs.empty())
|
||||
{ EntityID id = m_RecycledEntityIDs.top();
|
||||
{
|
||||
if (!m_RecycledEntityIDs.empty())
|
||||
{
|
||||
EntityID id = m_RecycledEntityIDs.top();
|
||||
m_RecycledEntityIDs.pop();
|
||||
return id;
|
||||
}
|
||||
else
|
||||
{ return ++m_LastEntityID;
|
||||
{
|
||||
return ++m_LastEntityID;
|
||||
}
|
||||
}
|
||||
|
||||
void World::RecursiveUpdate(std::shared_ptr<System> system, double dt, EntityID parentEntity)
|
||||
{ for (auto pair : m_EntityParents)
|
||||
{ EntityID child = pair.first;
|
||||
{
|
||||
for (auto pair : m_EntityParents)
|
||||
{
|
||||
EntityID child = pair.first;
|
||||
EntityID parent = pair.second;
|
||||
|
||||
if (parent == parentEntity)
|
||||
{ system->UpdateEntity(dt, child, parent);
|
||||
{
|
||||
system->UpdateEntity(dt, child, parent);
|
||||
RecursiveUpdate(system, dt, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void World::Update(double dt)
|
||||
{ for (auto pair : m_Systems)
|
||||
{ auto system = pair.second;
|
||||
{
|
||||
for (auto pair : m_Systems)
|
||||
{
|
||||
auto system = pair.second;
|
||||
system->Update(dt);
|
||||
RecursiveUpdate(system, dt, 0);
|
||||
}
|
||||
@@ -48,12 +57,14 @@ void World::Update(double dt)
|
||||
//}
|
||||
|
||||
EntityID World::GetEntityParent(EntityID entity)
|
||||
{ auto it = m_EntityParents.find(entity);
|
||||
{
|
||||
auto it = m_EntityParents.find(entity);
|
||||
return it == m_EntityParents.end() ? 0 : it->second;
|
||||
}
|
||||
|
||||
EntityID World::GetEntityBaseParent(EntityID entity)
|
||||
{ EntityID parent = GetEntityParent(entity);
|
||||
{
|
||||
EntityID parent = GetEntityParent(entity);
|
||||
if (parent == 0)
|
||||
return entity;
|
||||
else
|
||||
@@ -61,28 +72,36 @@ EntityID World::GetEntityBaseParent(EntityID entity)
|
||||
}
|
||||
|
||||
bool World::ValidEntity(EntityID entity)
|
||||
{ return m_EntityParents.find(entity) != m_EntityParents.end();
|
||||
{
|
||||
return m_EntityParents.find(entity) != m_EntityParents.end();
|
||||
}
|
||||
|
||||
void World::RemoveEntity(EntityID entity)
|
||||
{ m_EntitiesToRemove.push_back(entity);
|
||||
{
|
||||
m_EntitiesToRemove.push_back(entity);
|
||||
for (auto pair : m_EntityParents)
|
||||
{ if (pair.second == entity)
|
||||
{ m_EntitiesToRemove.push_back(pair.first);
|
||||
{
|
||||
if (pair.second == entity)
|
||||
{
|
||||
m_EntitiesToRemove.push_back(pair.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void World::ProcessEntityRemovals()
|
||||
{ for (auto entity : m_EntitiesToRemove)
|
||||
{ m_EntityParents.erase(entity);
|
||||
{
|
||||
for (auto entity : m_EntitiesToRemove)
|
||||
{
|
||||
m_EntityParents.erase(entity);
|
||||
// Remove components
|
||||
for (auto pair : m_EntityComponents[entity])
|
||||
{ auto type = pair.first;
|
||||
{
|
||||
auto type = pair.first;
|
||||
auto component = pair.second;
|
||||
// Trigger events
|
||||
for (auto pair : m_Systems)
|
||||
{ auto system = pair.second;
|
||||
{
|
||||
auto system = pair.second;
|
||||
system->OnComponentRemoved(type, component.get());
|
||||
}
|
||||
m_ComponentsOfType[type].remove(component);
|
||||
@@ -95,7 +114,8 @@ void World::ProcessEntityRemovals()
|
||||
}
|
||||
|
||||
EntityID World::CreateEntity(EntityID parent /*= 0*/)
|
||||
{ EntityID newEntity = GenerateEntityID();
|
||||
{
|
||||
EntityID newEntity = GenerateEntityID();
|
||||
m_EntityParents.insert(std::pair<EntityID, EntityID>(newEntity, parent));
|
||||
return newEntity;
|
||||
}
|
||||
@@ -106,23 +126,29 @@ World::~World()
|
||||
}
|
||||
|
||||
World::World()
|
||||
{ m_LastEntityID = 0;
|
||||
{
|
||||
m_LastEntityID = 0;
|
||||
}
|
||||
|
||||
void World::Initialize()
|
||||
{ RegisterSystems();
|
||||
{
|
||||
RegisterSystems();
|
||||
AddSystems();
|
||||
for (auto system : m_Systems)
|
||||
{ system.second->Initialize();
|
||||
for (auto pair : m_Systems)
|
||||
{
|
||||
auto system = pair.second;
|
||||
system->RegisterComponents(&m_ComponentFactory);
|
||||
system->RegisterResourceTypes(&m_ResourceManager);
|
||||
system->Initialize();
|
||||
}
|
||||
|
||||
RegisterComponents();
|
||||
}
|
||||
|
||||
std::shared_ptr<Component> World::AddComponent(EntityID entity, std::string componentType)
|
||||
{ return AddComponent<Component>(entity, componentType);
|
||||
{
|
||||
return AddComponent<Component>(entity, componentType);
|
||||
}
|
||||
|
||||
void World::AddSystem(std::string systemType)
|
||||
{ m_Systems[systemType] = std::shared_ptr<System>(m_SystemFactory.Create(systemType));
|
||||
{
|
||||
m_Systems[systemType] = std::shared_ptr<System>(m_SystemFactory.Create(systemType));
|
||||
}
|
||||
|
||||
+20
-10
@@ -10,12 +10,11 @@
|
||||
|
||||
#include <boost/any.hpp>
|
||||
|
||||
#include "Util/logging.h"
|
||||
|
||||
#include "Factory.h"
|
||||
#include "Entity.h"
|
||||
#include "Component.h"
|
||||
#include "System.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
class World
|
||||
{
|
||||
@@ -45,7 +44,8 @@ public:
|
||||
|
||||
template <class T>
|
||||
T GetProperty(EntityID entity, std::string property)
|
||||
{ if(m_EntityProperties.find(entity) == m_EntityProperties.end())
|
||||
{
|
||||
if(m_EntityProperties.find(entity) == m_EntityProperties.end())
|
||||
return T();
|
||||
if(m_EntityProperties[entity].find(property) == m_EntityProperties[entity].end())
|
||||
return T();
|
||||
@@ -54,7 +54,8 @@ public:
|
||||
}
|
||||
|
||||
void SetProperty(EntityID entity, std::string property, boost::any value)
|
||||
{ m_EntityProperties[entity][property] = value;
|
||||
{
|
||||
m_EntityProperties[entity][property] = value;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@@ -71,9 +72,12 @@ public:
|
||||
|
||||
std::unordered_map<EntityID, EntityID>* GetEntities() { return &m_EntityParents; }
|
||||
|
||||
ResourceManager* GetResourceManager() { return &m_ResourceManager; }
|
||||
|
||||
protected:
|
||||
SystemFactory m_SystemFactory;
|
||||
ComponentFactory m_ComponentFactory;
|
||||
ResourceManager m_ResourceManager;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<System>> m_Systems;
|
||||
|
||||
@@ -97,8 +101,10 @@ protected:
|
||||
|
||||
template <class T>
|
||||
std::shared_ptr<T> World::GetSystem(std::string systemType)
|
||||
{ if (m_Systems.find(systemType) == m_Systems.end())
|
||||
{ LOG_WARNING("Tried to get pointer to unregistered system \"%s\"!", systemType.c_str());
|
||||
{
|
||||
if (m_Systems.find(systemType) == m_Systems.end())
|
||||
{
|
||||
LOG_WARNING("Tried to get pointer to unregistered system \"%s\"!", systemType.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -107,9 +113,11 @@ std::shared_ptr<T> World::GetSystem(std::string systemType)
|
||||
|
||||
template <class T>
|
||||
std::shared_ptr<T> World::AddComponent(EntityID entity, std::string componentType)
|
||||
{ std::shared_ptr<T> component = std::shared_ptr<T>(static_cast<T*>(m_ComponentFactory.Create(componentType)));
|
||||
{
|
||||
std::shared_ptr<T> component = std::shared_ptr<T>(static_cast<T*>(m_ComponentFactory.Create(componentType)));
|
||||
if (component == nullptr)
|
||||
{ LOG_ERROR("Failed to attach invalid component \"%s\" to entity #%i", componentType.c_str(), entity);
|
||||
{
|
||||
LOG_ERROR("Failed to attach invalid component \"%s\" to entity #%i", componentType.c_str(), entity);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -117,7 +125,8 @@ std::shared_ptr<T> World::AddComponent(EntityID entity, std::string componentTyp
|
||||
m_ComponentsOfType[componentType].push_back(component);
|
||||
m_EntityComponents[entity][componentType] = component;
|
||||
for (auto pair : m_Systems)
|
||||
{ auto system = pair.second;
|
||||
{
|
||||
auto system = pair.second;
|
||||
system->OnComponentCreated(componentType, component);
|
||||
}
|
||||
return component;
|
||||
@@ -126,7 +135,8 @@ std::shared_ptr<T> World::AddComponent(EntityID entity, std::string componentTyp
|
||||
|
||||
template <class T>
|
||||
T* World::GetComponent(EntityID entity, std::string componentType)
|
||||
{ return (T*)m_EntityComponents[entity][componentType].get();
|
||||
{
|
||||
return (T*)m_EntityComponents[entity][componentType].get();
|
||||
}
|
||||
|
||||
#endif // World_h__
|
||||
+2
-1
@@ -2,7 +2,8 @@
|
||||
#include "Engine.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{ Engine engine(argc, argv);
|
||||
{
|
||||
Engine engine(argc, argv);
|
||||
while (engine.Running())
|
||||
engine.Tick();
|
||||
|
||||
|
||||
@@ -97,8 +97,10 @@
|
||||
<ClCompile Include="..\..\src\OBJ.cpp" />
|
||||
<ClCompile Include="..\..\src\PrecompiledHeader.cpp" />
|
||||
<ClCompile Include="..\..\src\Renderer.cpp" />
|
||||
<ClCompile Include="..\..\src\ResourceManager.cpp" />
|
||||
<ClCompile Include="..\..\src\ShaderProgram.cpp" />
|
||||
<ClCompile Include="..\..\src\Skybox.cpp" />
|
||||
<ClCompile Include="..\..\src\Sound.cpp" />
|
||||
<ClCompile Include="..\..\src\Systems\DebugSystem.cpp" />
|
||||
<ClCompile Include="..\..\src\Systems\FreeSteeringSystem.cpp" />
|
||||
<ClCompile Include="..\..\src\Systems\InputSystem.cpp" />
|
||||
@@ -114,10 +116,8 @@
|
||||
<ClInclude Include="..\..\src\Color.h" />
|
||||
<ClInclude Include="..\..\src\Component.h" />
|
||||
<ClInclude Include="..\..\src\Components\BallSocketConstraint.h" />
|
||||
<ClInclude Include="..\..\src\Components\Bounds.h" />
|
||||
<ClInclude Include="..\..\src\Components\BoxShape.h" />
|
||||
<ClInclude Include="..\..\src\Components\Camera.h" />
|
||||
<ClInclude Include="..\..\src\Components\Collision.h" />
|
||||
<ClInclude Include="..\..\src\Components\CompoundShape.h" />
|
||||
<ClInclude Include="..\..\src\Components\DirectionalLight.h" />
|
||||
<ClInclude Include="..\..\src\Components\FreeSteering.h" />
|
||||
@@ -128,12 +128,10 @@
|
||||
<ClInclude Include="..\..\src\Components\ParticleEmitter.h" />
|
||||
<ClInclude Include="..\..\src\Components\Physics.h" />
|
||||
<ClInclude Include="..\..\src\Components\PointLight.h" />
|
||||
<ClInclude Include="..\..\src\Components\PowerUp.h" />
|
||||
<ClInclude Include="..\..\src\Components\SliderConstraint.h" />
|
||||
<ClInclude Include="..\..\src\Components\SoundEmitter.h" />
|
||||
<ClInclude Include="..\..\src\Components\SphereShape.h" />
|
||||
<ClInclude Include="..\..\src\Components\Sprite.h" />
|
||||
<ClInclude Include="..\..\src\Components\Stat.h" />
|
||||
<ClInclude Include="..\..\src\Components\StaticMeshShape.h" />
|
||||
<ClInclude Include="..\..\src\Components\Template.h" />
|
||||
<ClInclude Include="..\..\src\Components\Transform.h" />
|
||||
@@ -148,8 +146,10 @@
|
||||
<ClInclude Include="..\..\src\OBJ.h" />
|
||||
<ClInclude Include="..\..\src\PrecompiledHeader.h" />
|
||||
<ClInclude Include="..\..\src\Renderer.h" />
|
||||
<ClInclude Include="..\..\src\ResourceManager.h" />
|
||||
<ClInclude Include="..\..\src\ShaderProgram.h" />
|
||||
<ClInclude Include="..\..\src\Skybox.h" />
|
||||
<ClInclude Include="..\..\src\Sound.h" />
|
||||
<ClInclude Include="..\..\src\System.h" />
|
||||
<ClInclude Include="..\..\src\Systems\DebugSystem.h" />
|
||||
<ClInclude Include="..\..\src\Systems\FreeSteeringSystem.h" />
|
||||
|
||||
@@ -4,36 +4,52 @@
|
||||
<ClCompile Include="..\..\src\main.cpp" />
|
||||
<ClCompile Include="..\..\src\GameWorld.cpp" />
|
||||
<ClCompile Include="..\..\src\World.cpp" />
|
||||
<ClCompile Include="..\..\src\Renderer.cpp" />
|
||||
<ClCompile Include="..\..\src\Camera.cpp" />
|
||||
<ClCompile Include="..\..\src\Model.cpp" />
|
||||
<ClCompile Include="..\..\src\Skybox.cpp" />
|
||||
<ClCompile Include="..\..\src\CubemapTexture.cpp" />
|
||||
<ClCompile Include="..\..\src\Texture.cpp" />
|
||||
<ClCompile Include="..\..\src\ShaderProgram.cpp" />
|
||||
<ClCompile Include="..\..\src\OBJ.cpp" />
|
||||
<ClCompile Include="..\..\src\PrecompiledHeader.cpp" />
|
||||
<ClCompile Include="..\..\src\Systems\RenderSystem.cpp">
|
||||
<Filter>Systems</Filter>
|
||||
<Filter>Rendering\Systems</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Systems\TransformSystem.cpp">
|
||||
<Filter>Systems</Filter>
|
||||
<ClCompile Include="..\..\src\Renderer.cpp">
|
||||
<Filter>Rendering</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Systems\InputSystem.cpp">
|
||||
<Filter>Systems</Filter>
|
||||
<ClCompile Include="..\..\src\Skybox.cpp">
|
||||
<Filter>Rendering</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Systems\FreeSteeringSystem.cpp">
|
||||
<Filter>Systems</Filter>
|
||||
<ClCompile Include="..\..\src\Texture.cpp">
|
||||
<Filter>Rendering</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\OBJ.cpp">
|
||||
<Filter>Rendering</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Model.cpp">
|
||||
<Filter>Rendering</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Camera.cpp">
|
||||
<Filter>Rendering</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\CubemapTexture.cpp">
|
||||
<Filter>Rendering</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Systems\PhysicsSystem.cpp">
|
||||
<Filter>Systems</Filter>
|
||||
<Filter>Physics\Systems</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Systems\TransformSystem.cpp">
|
||||
<Filter>Base\Systems</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Systems\DebugSystem.cpp">
|
||||
<Filter>Systems</Filter>
|
||||
<Filter>Base\Systems</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Systems\SoundSystem.cpp">
|
||||
<Filter>Systems</Filter>
|
||||
<Filter>Audio\Systems</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Systems\InputSystem.cpp">
|
||||
<Filter>Input\Systems</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Systems\FreeSteeringSystem.cpp">
|
||||
<Filter>Input\Systems</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ResourceManager.cpp" />
|
||||
<ClCompile Include="..\..\src\Sound.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="Util">
|
||||
@@ -42,11 +58,59 @@
|
||||
<Filter Include="Shaders">
|
||||
<UniqueIdentifier>{8974329a-5c12-4b94-86e7-5931555bc129}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Components">
|
||||
<UniqueIdentifier>{e3f795ca-331e-4905-b423-93f651d93c09}</UniqueIdentifier>
|
||||
<Filter Include="Rendering">
|
||||
<UniqueIdentifier>{aca514ec-84de-423c-a270-ec4399904c5a}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Systems">
|
||||
<UniqueIdentifier>{1a6674dd-e1ce-4a28-a6e8-3f28468bb2f0}</UniqueIdentifier>
|
||||
<Filter Include="Rendering\Components">
|
||||
<UniqueIdentifier>{fcbc3469-7049-4c07-9d76-f8f1e872f042}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Rendering\Systems">
|
||||
<UniqueIdentifier>{f6c5fd1d-7180-42b7-b973-a91bfc3ea189}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Physics">
|
||||
<UniqueIdentifier>{d08cc18b-b7d8-47a7-91af-7283052e4c97}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Physics\Components">
|
||||
<UniqueIdentifier>{1c5d571e-55f4-498b-b64a-2f28ac2cd9b0}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Physics\Systems">
|
||||
<UniqueIdentifier>{635843f6-c94e-4798-8201-db64d11e2a03}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Base">
|
||||
<UniqueIdentifier>{3bd82924-397c-4c5a-959c-971612269374}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Base\Components">
|
||||
<UniqueIdentifier>{c17ff66a-f9f5-4329-a05d-e7bf8a140dd3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Base\Systems">
|
||||
<UniqueIdentifier>{caa1e07f-fa19-4706-bf59-de74a0290763}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Audio">
|
||||
<UniqueIdentifier>{444e18d8-8ab6-413b-b9b0-59a6309e0511}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Audio\Components">
|
||||
<UniqueIdentifier>{a2db813b-1d08-4d48-97ac-2faaff29a1cc}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Audio\Systems">
|
||||
<UniqueIdentifier>{44c41b41-b706-4d88-8d50-abdeb2a828fe}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Input">
|
||||
<UniqueIdentifier>{30c6d948-459c-4fc7-b44d-ecbe5f34203e}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Input\Components">
|
||||
<UniqueIdentifier>{8bcc0a31-3e0d-4342-8d10-ec8edfa03abd}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Input\Systems">
|
||||
<UniqueIdentifier>{93ce6550-7614-46b4-a554-0eec26e6fbf6}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Particle System">
|
||||
<UniqueIdentifier>{0bb544bb-1b0a-487f-88d6-f8ab8a2795f4}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Particle System\Components">
|
||||
<UniqueIdentifier>{a6ca6194-3aa5-46cc-ac05-206f9a400dec}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Particle System\Systems">
|
||||
<UniqueIdentifier>{9f45f029-46c8-4c0d-b44c-dc9bffd3c6a6}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -56,48 +120,6 @@
|
||||
<ClInclude Include="..\..\src\Entity.h" />
|
||||
<ClInclude Include="..\..\src\Component.h" />
|
||||
<ClInclude Include="..\..\src\System.h" />
|
||||
<ClInclude Include="..\..\src\Components\Camera.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Collision.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\DirectionalLight.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Input.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Model.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\ParticleEmitter.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\PointLight.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\PowerUp.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\SoundEmitter.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Sprite.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Stat.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Template.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Transform.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Bounds.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Util\GLError.h">
|
||||
<Filter>Util</Filter>
|
||||
</ClInclude>
|
||||
@@ -106,71 +128,119 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Color.h" />
|
||||
<ClInclude Include="..\..\src\Engine.h" />
|
||||
<ClInclude Include="..\..\src\Renderer.h" />
|
||||
<ClInclude Include="..\..\src\PrecompiledHeader.h" />
|
||||
<ClInclude Include="..\..\src\Camera.h" />
|
||||
<ClInclude Include="..\..\src\Model.h" />
|
||||
<ClInclude Include="..\..\src\Skybox.h" />
|
||||
<ClInclude Include="..\..\src\CubemapTexture.h" />
|
||||
<ClInclude Include="..\..\src\Texture.h" />
|
||||
<ClInclude Include="..\..\src\ShaderProgram.h" />
|
||||
<ClInclude Include="..\..\src\OBJ.h" />
|
||||
<ClInclude Include="..\..\src\Systems\RenderSystem.h">
|
||||
<Filter>Systems</Filter>
|
||||
<ClInclude Include="..\..\src\Components\Model.h">
|
||||
<Filter>Rendering\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Systems\TransformSystem.h">
|
||||
<Filter>Systems</Filter>
|
||||
<ClInclude Include="..\..\src\Components\Sprite.h">
|
||||
<Filter>Rendering\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Systems\InputSystem.h">
|
||||
<Filter>Systems</Filter>
|
||||
<ClInclude Include="..\..\src\Renderer.h">
|
||||
<Filter>Rendering</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Systems\FreeSteeringSystem.h">
|
||||
<Filter>Systems</Filter>
|
||||
<ClInclude Include="..\..\src\Skybox.h">
|
||||
<Filter>Rendering</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\FreeSteering.h">
|
||||
<Filter>Components</Filter>
|
||||
<ClInclude Include="..\..\src\Texture.h">
|
||||
<Filter>Rendering</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Physics.h">
|
||||
<Filter>Components</Filter>
|
||||
<ClInclude Include="..\..\src\OBJ.h">
|
||||
<Filter>Rendering</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\SphereShape.h">
|
||||
<Filter>Components</Filter>
|
||||
<ClInclude Include="..\..\src\Model.h">
|
||||
<Filter>Rendering</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Camera.h">
|
||||
<Filter>Rendering</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\CubemapTexture.h">
|
||||
<Filter>Rendering</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\BoxShape.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Systems\PhysicsSystem.h">
|
||||
<Filter>Systems</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Systems\DebugSystem.h">
|
||||
<Filter>Systems</Filter>
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\CompoundShape.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\SliderConstraint.h">
|
||||
<Filter>Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\HingeConstraint.h">
|
||||
<Filter>Components</Filter>
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\BallSocketConstraint.h">
|
||||
<Filter>Components</Filter>
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\HingeConstraint.h">
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\MeshShape.h">
|
||||
<Filter>Components</Filter>
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Vehicle.h">
|
||||
<Filter>Components</Filter>
|
||||
<ClInclude Include="..\..\src\Components\SliderConstraint.h">
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Wheel.h">
|
||||
<Filter>Components</Filter>
|
||||
<ClInclude Include="..\..\src\Components\SphereShape.h">
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\StaticMeshShape.h">
|
||||
<Filter>Components</Filter>
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Vehicle.h">
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Wheel.h">
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Physics.h">
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Systems\PhysicsSystem.h">
|
||||
<Filter>Physics\Systems</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Transform.h">
|
||||
<Filter>Base\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Template.h">
|
||||
<Filter>Base\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Camera.h">
|
||||
<Filter>Rendering\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Systems\TransformSystem.h">
|
||||
<Filter>Base\Systems</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Systems\DebugSystem.h">
|
||||
<Filter>Base\Systems</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Systems\SoundSystem.h">
|
||||
<Filter>Systems</Filter>
|
||||
<Filter>Audio\Systems</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\SoundEmitter.h">
|
||||
<Filter>Audio\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Systems\RenderSystem.h">
|
||||
<Filter>Rendering\Systems</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Systems\InputSystem.h">
|
||||
<Filter>Input\Systems</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Systems\FreeSteeringSystem.h">
|
||||
<Filter>Input\Systems</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Input.h">
|
||||
<Filter>Input\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\FreeSteering.h">
|
||||
<Filter>Input\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\ParticleEmitter.h">
|
||||
<Filter>Particle System\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\PointLight.h">
|
||||
<Filter>Rendering\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\DirectionalLight.h">
|
||||
<Filter>Rendering\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ResourceManager.h" />
|
||||
<ClInclude Include="..\..\src\Sound.h">
|
||||
<Filter>Audio</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user