Merge branch 'master' into gui
Conflicts: src/GUI/Frame.h src/InputManager.cpp
This commit is contained in:
+1
-1
Submodule assets updated: 672e8a2b11...15ac02523a
@@ -7,6 +7,8 @@
|
|||||||
struct Component
|
struct Component
|
||||||
{
|
{
|
||||||
EntityID Entity;
|
EntityID Entity;
|
||||||
|
|
||||||
|
virtual Component* Clone() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ComponentFactory : public Factory<Component*> { };
|
class ComponentFactory : public Factory<Component*> { };
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef BarrelSteering_h__
|
||||||
|
#define BarrelSteering_h__
|
||||||
|
|
||||||
|
#include "Component.h"
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct BarrelSteering : Component
|
||||||
|
{
|
||||||
|
BarrelSteering()
|
||||||
|
: TurnSpeed(1.f), Axis(glm::vec3(0,1,0)){ }
|
||||||
|
float TurnSpeed;
|
||||||
|
glm::vec3 Axis;
|
||||||
|
EntityID ShotTemplate;
|
||||||
|
float ShotSpeed;
|
||||||
|
|
||||||
|
virtual BarrelSteering* Clone() const override { return new BarrelSteering(*this); }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // BarrelSteering_h__
|
||||||
@@ -6,14 +6,16 @@
|
|||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Box : Component
|
struct BoxShape : Component
|
||||||
{
|
{
|
||||||
Box()
|
BoxShape()
|
||||||
: Width(1.f), Height(1.f), Depth(1.f){ }
|
: Width(1.f), Height(1.f), Depth(1.f){ }
|
||||||
|
|
||||||
float Width;
|
float Width;
|
||||||
float Height;
|
float Height;
|
||||||
float Depth;
|
float Depth;
|
||||||
|
|
||||||
|
virtual BoxShape* Clone() const override { return new BoxShape(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,8 @@ struct Camera : Component
|
|||||||
float FOV;
|
float FOV;
|
||||||
float NearClip;
|
float NearClip;
|
||||||
float FarClip;
|
float FarClip;
|
||||||
|
|
||||||
|
virtual Camera* Clone() const override { return new Camera(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ struct DirectionalLight : Component
|
|||||||
float MaxRange;
|
float MaxRange;
|
||||||
float SpecularIntensity;
|
float SpecularIntensity;
|
||||||
Color Color;
|
Color Color;
|
||||||
|
|
||||||
|
virtual DirectionalLight* Clone() const override { return new DirectionalLight(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ struct FreeSteering : Component
|
|||||||
{
|
{
|
||||||
FreeSteering() : Speed(35) { }
|
FreeSteering() : Speed(35) { }
|
||||||
float Speed;
|
float Speed;
|
||||||
|
|
||||||
|
virtual FreeSteering* Clone() const override { return new FreeSteering(*this); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef Components_HingeConstraint_h__
|
||||||
|
#define Components_HingeConstraint_h__
|
||||||
|
|
||||||
|
#include "Component.h"
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct HingeConstraint : Component
|
||||||
|
{
|
||||||
|
EntityID LinkedEntity;
|
||||||
|
glm::vec3 Pivot;
|
||||||
|
glm::vec3 Axis;
|
||||||
|
|
||||||
|
virtual HingeConstraint* Clone() const override { return new HingeConstraint(*this); }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // Components_HingeConstraint_h__
|
||||||
@@ -18,6 +18,8 @@ struct Input : Component
|
|||||||
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> LastMouseState;
|
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> LastMouseState;
|
||||||
float dX, dY;
|
float dX, dY;
|
||||||
float WheelDelta;
|
float WheelDelta;
|
||||||
|
|
||||||
|
virtual Input* Clone() const override { return new Input(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef Components_MeshShape_h__
|
||||||
|
#define Components_MeshShape_h__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "Component.h"
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct MeshShape : Component
|
||||||
|
{
|
||||||
|
std::string ResourceName;
|
||||||
|
|
||||||
|
virtual MeshShape* Clone() const override { return new MeshShape(*this); }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // !Components_MeshShape_h__
|
||||||
@@ -16,6 +16,8 @@ struct Model : Component
|
|||||||
Color Color;
|
Color Color;
|
||||||
bool Visible;
|
bool Visible;
|
||||||
bool ShadowCaster;
|
bool ShadowCaster;
|
||||||
|
|
||||||
|
virtual Model* Clone() const override { return new Model(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef Components_Particle_h__
|
||||||
|
#define Components_Particle_h__
|
||||||
|
|
||||||
|
#include "System.h"
|
||||||
|
#include "Component.h"
|
||||||
|
#include "Color.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct Particle : Component
|
||||||
|
{
|
||||||
|
std::vector<Color> ColorSpectrum;
|
||||||
|
std::vector<glm::vec3> ScaleSpectrum;
|
||||||
|
double LifeTime;
|
||||||
|
std::vector<glm::vec3> VelocitySpectrum;
|
||||||
|
std::vector<float> AngularVelocitySpectrum;
|
||||||
|
std::vector<glm::vec3> OrientationSpectrum; //Keep?
|
||||||
|
|
||||||
|
virtual Particle* Clone() const override { return new Particle(*this); }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // !Components_Particle_h__
|
||||||
@@ -5,20 +5,39 @@
|
|||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Systems { class ParticleSystem; }
|
||||||
|
|
||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
|
|
||||||
struct ParticleEmitter : Component
|
struct ParticleEmitter : Component
|
||||||
{
|
{
|
||||||
int ParticleTemplate;
|
friend class Systems::ParticleSystem;
|
||||||
|
|
||||||
|
ParticleEmitter()
|
||||||
|
: SpawnFrequency(0)
|
||||||
|
, SpawnCount(0)
|
||||||
|
, SpreadAngle(0)
|
||||||
|
, LifeTime(0)
|
||||||
|
, TimeSinceLastSpawn(0) { }
|
||||||
|
|
||||||
|
EntityID ParticleTemplate;
|
||||||
float SpawnFrequency;
|
float SpawnFrequency;
|
||||||
|
float Speed;
|
||||||
int SpawnCount;
|
int SpawnCount;
|
||||||
std::vector<Color> ColorSpectrum;
|
std::vector<Color> ColorSpectrum;
|
||||||
std::vector<float> ScaleSpectrum;
|
std::vector<glm::vec3> ScaleSpectrum;
|
||||||
float SpreadAngle;
|
float SpreadAngle;
|
||||||
float LifeTime;
|
double LifeTime;
|
||||||
std::vector<float[3]> VelocitySpectrum;
|
bool UseGoalVelocity;
|
||||||
std::vector<float[3]> AngularVelocitySpectrum;
|
glm::vec3 GoalVelocity;
|
||||||
|
std::vector<float> AngularVelocitySpectrum;
|
||||||
|
std::vector<glm::vec3> OrientationSpectrum; //Keep?
|
||||||
|
|
||||||
|
virtual ParticleEmitter* Clone() const override { return new ParticleEmitter(*this); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
double TimeSinceLastSpawn;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ struct Physics : Component
|
|||||||
|
|
||||||
float Mass;
|
float Mass;
|
||||||
bool Static;
|
bool Static;
|
||||||
|
|
||||||
|
virtual Physics* Clone() const override { return new Physics(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,13 +9,24 @@ namespace Components
|
|||||||
|
|
||||||
struct PointLight : Component
|
struct PointLight : Component
|
||||||
{
|
{
|
||||||
float Intensity;
|
PointLight()
|
||||||
float MaxRange;
|
: Specular(1.0f, 1.0f, 1.0f)
|
||||||
|
, Diffuse(1.0f, 1.0f, 1.0f)
|
||||||
|
, specularExponent(50.0f)
|
||||||
|
, ConstantAttenuation(1.0f)
|
||||||
|
, LinearAttenuation(0.f)
|
||||||
|
, QuadraticAttenuation(3.f)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation;
|
||||||
|
Color color;
|
||||||
|
|
||||||
glm::vec3 Specular;
|
glm::vec3 Specular;
|
||||||
glm::vec3 Diffuse;
|
glm::vec3 Diffuse;
|
||||||
float constantAttenuation, linearAttenuation, quadraticAttenuation;
|
float specularExponent;
|
||||||
float spotExponent;
|
float Scale;
|
||||||
Color color;
|
|
||||||
|
virtual PointLight* Clone() const override { return new PointLight(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ struct SoundEmitter : Component
|
|||||||
float Pitch;
|
float Pitch;
|
||||||
bool Loop;
|
bool Loop;
|
||||||
std::string Path;
|
std::string Path;
|
||||||
|
|
||||||
|
virtual SoundEmitter* Clone() const override { return new SoundEmitter(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,14 @@
|
|||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Sphere : Component
|
struct SphereShape : Component
|
||||||
{
|
{
|
||||||
Sphere()
|
SphereShape()
|
||||||
: Radius(1.f){ }
|
: Radius(1.f){ }
|
||||||
|
|
||||||
float Radius;
|
float Radius;
|
||||||
|
|
||||||
|
virtual SphereShape* Clone() const override { return new SphereShape(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,8 @@ struct Sprite : Component
|
|||||||
{
|
{
|
||||||
std::string SpriteFile;
|
std::string SpriteFile;
|
||||||
Color Color;
|
Color Color;
|
||||||
|
|
||||||
|
virtual Sprite* Clone() const override { return new Sprite(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef TankSteering_h__
|
||||||
|
#define TankSteering_h__
|
||||||
|
|
||||||
|
#include "Component.h"
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
struct TankSteering : Component
|
||||||
|
{
|
||||||
|
TankSteering* Clone() const override { return new TankSteering(*this); }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TankSteering_h__
|
||||||
@@ -6,7 +6,12 @@
|
|||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Template : Component { };
|
struct Template
|
||||||
|
: public Component
|
||||||
|
{
|
||||||
|
virtual Template* Clone() const override { return nullptr; }
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !Components_Template_h__
|
#endif // !Components_Template_h__
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#ifndef TowerSteering_h__
|
||||||
|
#define TowerSteering_h__
|
||||||
|
|
||||||
|
#include "Component.h"
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct TowerSteering : Component
|
||||||
|
{
|
||||||
|
TowerSteering()
|
||||||
|
: TurnSpeed(1.f), Axis(glm::vec3(0,1,0)){ }
|
||||||
|
|
||||||
|
float TurnSpeed;
|
||||||
|
glm::vec3 Axis;
|
||||||
|
virtual TowerSteering* Clone() const override { return new TowerSteering(*this); }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TowerSteering_h__
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Transform : Component
|
struct Transform : public Component
|
||||||
{
|
{
|
||||||
Transform()
|
Transform()
|
||||||
: Scale(glm::vec3(1.f)) { }
|
: Scale(glm::vec3(1.f)) { }
|
||||||
@@ -15,6 +15,8 @@ struct Transform : Component
|
|||||||
glm::quat Orientation;
|
glm::quat Orientation;
|
||||||
glm::vec3 Velocity;
|
glm::vec3 Velocity;
|
||||||
glm::vec3 Scale;
|
glm::vec3 Scale;
|
||||||
|
|
||||||
|
virtual Transform* Clone() const override { return new Transform(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ namespace Components
|
|||||||
struct Vehicle : Component
|
struct Vehicle : Component
|
||||||
{
|
{
|
||||||
Vehicle()
|
Vehicle()
|
||||||
: MaxTorque(500.0f), MinRPM(1000.0f), OptimalRPM(5500.0f), MaxRPM(7500.0f), MaxSteeringAngle(35), TopSpeed(50.0f) { }
|
: MaxTorque(1000.0f), MinRPM(1000.0f), OptimalRPM(3000.0f), MaxRPM(4000.0f), MaxSteeringAngle(35), TopSpeed(130.0f),
|
||||||
|
MaxSpeedFullSteeringAngle(40.0f), SpringDamping(1.f){ }
|
||||||
|
|
||||||
float MaxTorque;
|
float MaxTorque;
|
||||||
float MinRPM;
|
float MinRPM;
|
||||||
@@ -18,7 +19,12 @@ struct Vehicle : Component
|
|||||||
float MaxRPM;
|
float MaxRPM;
|
||||||
// Degrees
|
// Degrees
|
||||||
float MaxSteeringAngle;
|
float MaxSteeringAngle;
|
||||||
|
//TopSpeed not working fully yet
|
||||||
float TopSpeed;
|
float TopSpeed;
|
||||||
|
float MaxSpeedFullSteeringAngle;
|
||||||
|
float SpringDamping;
|
||||||
|
|
||||||
|
Vehicle* Clone() const override { return new Vehicle(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ struct Wheel : Component
|
|||||||
|
|
||||||
Wheel()
|
Wheel()
|
||||||
: AxleID(0), Radius(0), Width(0), Mass(0), Steering(false), DownDirection(glm::vec3(0, -1, 0)), Friction(1.5f), SlipAngle(0.0f),
|
: AxleID(0), Radius(0), Width(0), Mass(0), Steering(false), DownDirection(glm::vec3(0, -1, 0)), Friction(1.5f), SlipAngle(0.0f),
|
||||||
MaxBreakingTorque(1500.0f), ConnectedToHandbrake(false), SuspensionStrength(50.0f) { }
|
MaxBreakingTorque(1500.0f), ConnectedToHandbrake(false), SuspensionStrength(50.0f), TorqueRatio(0.25f) { }
|
||||||
|
|
||||||
// The Hardpoint MUST be positioned INSIDE the chassis.
|
// The Hardpoint MUST be positioned INSIDE the chassis.
|
||||||
glm::vec3 Hardpoint;
|
glm::vec3 Hardpoint;
|
||||||
@@ -30,10 +30,14 @@ struct Wheel : Component
|
|||||||
float SlipAngle;
|
float SlipAngle;
|
||||||
float MaxBreakingTorque;
|
float MaxBreakingTorque;
|
||||||
bool ConnectedToHandbrake;
|
bool ConnectedToHandbrake;
|
||||||
|
// The wheels total TorqueRatio must be equal to 1
|
||||||
|
float TorqueRatio;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int ID;
|
int ID;
|
||||||
glm::quat OriginalOrientation;
|
glm::quat OriginalOrientation;
|
||||||
|
|
||||||
|
Wheel* Clone() const override { return new Wheel(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef Components_WheelPair_h__
|
||||||
|
#define Components_WheelPair_h__
|
||||||
|
|
||||||
|
#include "Component.h"
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct WheelPair : Component
|
||||||
|
{
|
||||||
|
// Flag for pair wheels
|
||||||
|
|
||||||
|
virtual WheelPair* Clone() const override { return new WheelPair(*this); }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // Components_WheelPair_h__
|
||||||
+2
-2
@@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
m_InputManager = std::make_shared<InputManager>(m_Renderer->GetWindow(), m_EventBroker);
|
m_InputManager = std::make_shared<InputManager>(m_Renderer->GetWindow(), m_EventBroker);
|
||||||
|
|
||||||
m_UIParent = std::make_shared<GUI::Frame>(m_EventBroker);
|
//m_UIParent = std::make_shared<GUI::Frame>(m_EventBroker);
|
||||||
|
|
||||||
m_World = std::make_shared<GameWorld>(m_EventBroker, m_Renderer);
|
m_World = std::make_shared<GameWorld>(m_EventBroker, m_Renderer);
|
||||||
m_World->Initialize();
|
m_World->Initialize();
|
||||||
@@ -46,7 +46,7 @@ private:
|
|||||||
std::shared_ptr<EventBroker> m_EventBroker;
|
std::shared_ptr<EventBroker> m_EventBroker;
|
||||||
std::shared_ptr<Renderer> m_Renderer;
|
std::shared_ptr<Renderer> m_Renderer;
|
||||||
std::shared_ptr<InputManager> m_InputManager;
|
std::shared_ptr<InputManager> m_InputManager;
|
||||||
std::shared_ptr<GUI::Frame> m_UIParent;
|
//std::shared_ptr<GUI::Frame> m_UIParent;
|
||||||
// TODO: This should ultimately live in GameFrame
|
// TODO: This should ultimately live in GameFrame
|
||||||
std::shared_ptr<GameWorld> m_World;
|
std::shared_ptr<GameWorld> m_World;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#ifndef Events_BindGamepadAxis_h__
|
||||||
|
#define Events_BindGamepadAxis_h__
|
||||||
|
|
||||||
|
#include <boost/any.hpp>
|
||||||
|
|
||||||
|
#include "EventBroker.h"
|
||||||
|
#include "Events/GamepadAxis.h"
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct BindGamepadAxis : Event
|
||||||
|
{
|
||||||
|
Gamepad::Axis Axis;
|
||||||
|
std::string Command;
|
||||||
|
float Value;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // Events_BindGamepadAxis_h__
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#ifndef Events_BindGamepadButton_h__
|
||||||
|
#define Events_BindGamepadButton_h__
|
||||||
|
|
||||||
|
#include <boost/any.hpp>
|
||||||
|
|
||||||
|
#include "EventBroker.h"
|
||||||
|
#include "Events/GamepadButton.h"
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct BindGamepadButton : Event
|
||||||
|
{
|
||||||
|
Gamepad::Button Button;
|
||||||
|
std::string Command;
|
||||||
|
float Value;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // Events_BindGamepadButton_h__
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef Events_BindKey_h__
|
#ifndef Events_BindKey_h__
|
||||||
#define Events_BindKey_h__
|
#define Events_BindKey_h__
|
||||||
|
|
||||||
|
#include <boost/any.hpp>
|
||||||
|
|
||||||
#include "EventBroker.h"
|
#include "EventBroker.h"
|
||||||
|
|
||||||
namespace Events
|
namespace Events
|
||||||
@@ -10,6 +12,7 @@ struct BindKey : Event
|
|||||||
{
|
{
|
||||||
int KeyCode;
|
int KeyCode;
|
||||||
std::string Command;
|
std::string Command;
|
||||||
|
float Value;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#ifndef Events_GamepadAxis_h__
|
||||||
|
#define Events_GamepadAxis_h__
|
||||||
|
|
||||||
|
#include "EventBroker.h"
|
||||||
|
|
||||||
|
namespace Gamepad
|
||||||
|
{
|
||||||
|
enum class Axis
|
||||||
|
{
|
||||||
|
LeftX,
|
||||||
|
LeftY,
|
||||||
|
RightX,
|
||||||
|
RightY,
|
||||||
|
LeftTrigger,
|
||||||
|
RightTrigger,
|
||||||
|
LAST = RightTrigger
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct GamepadAxis : Event
|
||||||
|
{
|
||||||
|
int GamepadID;
|
||||||
|
Gamepad::Axis Axis;
|
||||||
|
float Value;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // Events_GamepadAxis_h__
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
#ifndef Events_GamepadButton_h__
|
||||||
|
#define Events_GamepadButton_h__
|
||||||
|
|
||||||
|
#include "EventBroker.h"
|
||||||
|
|
||||||
|
namespace Gamepad
|
||||||
|
{
|
||||||
|
enum class Button
|
||||||
|
{
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Start,
|
||||||
|
Back,
|
||||||
|
LeftThumb,
|
||||||
|
RightThumb,
|
||||||
|
LeftShoulder,
|
||||||
|
RightShoulder,
|
||||||
|
A,
|
||||||
|
B,
|
||||||
|
X,
|
||||||
|
Y,
|
||||||
|
LAST = Y
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct GamepadButtonDown : Event
|
||||||
|
{
|
||||||
|
int GamepadID;
|
||||||
|
Gamepad::Button Button;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GamepadButtonUp : Event
|
||||||
|
{
|
||||||
|
int GamepadID;
|
||||||
|
Gamepad::Button Button;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // Events_GamepadButton_h__
|
||||||
@@ -12,7 +12,7 @@ struct InputCommand : Event
|
|||||||
{
|
{
|
||||||
unsigned int PlayerID;
|
unsigned int PlayerID;
|
||||||
std::string Command;
|
std::string Command;
|
||||||
boost::any Value;
|
float Value;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef Events_SetVelocity_h__
|
||||||
|
#define Events_SetVelocity_h__
|
||||||
|
#include "Entity.h"
|
||||||
|
#include "EventBroker.h"
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct SetVelocity : Event
|
||||||
|
{
|
||||||
|
EntityID Entity;
|
||||||
|
glm::vec3 Velocity;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // Events_SetVelocity_h__
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef Events_TankSteer_h__
|
||||||
|
#define Events_TankSteer_h__
|
||||||
|
#include "Entity.h"
|
||||||
|
#include "EventBroker.h"
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct TankSteer : Event
|
||||||
|
{
|
||||||
|
EntityID Entity;
|
||||||
|
float PositionX;
|
||||||
|
float PositionY;
|
||||||
|
bool Handbrake;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // Events_TankSteer_h__
|
||||||
+75
-76
@@ -1,76 +1,75 @@
|
|||||||
#ifndef GUI_Frame_h__
|
//#ifndef GUI_Frame_h__
|
||||||
#define GUI_Frame_h__
|
//#define GUI_Frame_h__
|
||||||
|
//
|
||||||
#include <memory>
|
//#include <memory>
|
||||||
|
//
|
||||||
#include "Util/Rectangle.h"
|
//#include "Util/Rectangle.h"
|
||||||
#include "EventBroker.h"
|
//#include "EventBroker.h"
|
||||||
|
//
|
||||||
// HACK: Decouple renderer plz
|
//// HACK: Decouple renderer plz
|
||||||
#include "Renderer.h"
|
//#include "Renderer.h"
|
||||||
|
//
|
||||||
namespace GUI
|
//namespace GUI
|
||||||
{
|
//{
|
||||||
|
//
|
||||||
class Frame : public Rectangle
|
//class Frame : public Rectangle
|
||||||
{
|
//{
|
||||||
public:
|
//public:
|
||||||
enum class Anchor
|
// enum class Anchor
|
||||||
{
|
// {
|
||||||
Left,
|
// Left,
|
||||||
Right,
|
// Right,
|
||||||
Top,
|
// Top,
|
||||||
Bottom
|
// Bottom
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
// Set up a base frame with an event broker
|
// // Set up a base frame with an event broker
|
||||||
Frame(std::shared_ptr<::EventBroker> eventBroker)
|
// Frame(std::shared_ptr<::EventBroker> eventBroker)
|
||||||
: EventBroker(eventBroker)
|
// : EventBroker(eventBroker)
|
||||||
, Rectangle()
|
// , Rectangle()
|
||||||
{ Initialize(); }
|
// { Initialize(); }
|
||||||
// Create a frame as a child
|
// // Create a frame as a child
|
||||||
Frame(std::shared_ptr<Frame> parent)
|
// Frame(std::shared_ptr<Frame> parent)
|
||||||
: Rectangle(static_cast<Rectangle>(*parent)) // Clone parent rectangle using copy constructor
|
// : Rectangle(static_cast<Rectangle>(*parent)) // Clone parent rectangle using copy constructor
|
||||||
{ SetParent(parent); Initialize(); }
|
// { SetParent(parent); Initialize(); }
|
||||||
|
//
|
||||||
virtual void Initialize() { }
|
// virtual void Initialize() { }
|
||||||
|
// std::shared_ptr<Frame> Parent() const { return m_Parent; }
|
||||||
std::shared_ptr<Frame> Parent() const { return m_Parent; }
|
// void SetParent(std::shared_ptr<Frame> parent)
|
||||||
void SetParent(std::shared_ptr<Frame> parent)
|
// {
|
||||||
{
|
// parent->AddChild(std::shared_ptr<Frame>(this));
|
||||||
parent->AddChild(std::shared_ptr<Frame>(this));
|
// m_Parent = parent;
|
||||||
m_Parent = parent;
|
// EventBroker = parent->EventBroker;
|
||||||
EventBroker = parent->EventBroker;
|
// }
|
||||||
}
|
//
|
||||||
|
// void AddChild(std::shared_ptr<Frame> child)
|
||||||
void AddChild(std::shared_ptr<Frame> child)
|
// {
|
||||||
{
|
// m_Children.push_back(child);
|
||||||
m_Children.push_back(child);
|
// if (m_Parent != nullptr)
|
||||||
if (m_Parent != nullptr)
|
// {
|
||||||
{
|
// m_Parent->AddChild(child);
|
||||||
m_Parent->AddChild(child);
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
|
// typedef std::list<std::shared_ptr<Frame>>::const_iterator FrameChildrenIterator;
|
||||||
typedef std::list<std::shared_ptr<Frame>>::const_iterator FrameChildrenIterator;
|
// FrameChildrenIterator begin()
|
||||||
FrameChildrenIterator begin()
|
// {
|
||||||
{
|
// return m_Children.begin();
|
||||||
return m_Children.begin();
|
// }
|
||||||
}
|
// FrameChildrenIterator end()
|
||||||
FrameChildrenIterator end()
|
// {
|
||||||
{
|
// return m_Children.end();
|
||||||
return m_Children.end();
|
// }
|
||||||
}
|
//
|
||||||
|
// virtual void Update(double dt) { }
|
||||||
virtual void Update(double dt) { }
|
// virtual void Draw(Renderer* renderer) { }
|
||||||
virtual void Draw(Renderer* renderer) { }
|
//
|
||||||
|
//protected:
|
||||||
protected:
|
// std::shared_ptr<::EventBroker> EventBroker;
|
||||||
std::shared_ptr<::EventBroker> EventBroker;
|
// std::shared_ptr<Frame> m_Parent;
|
||||||
std::shared_ptr<Frame> m_Parent;
|
// std::list<std::shared_ptr<Frame>> m_Children;
|
||||||
std::list<std::shared_ptr<Frame>> m_Children;
|
//};
|
||||||
};
|
//
|
||||||
|
//}
|
||||||
}
|
//
|
||||||
|
//#endif // GUI_Frame_h__
|
||||||
#endif // GUI_Frame_h__
|
|
||||||
|
|||||||
+642
-143
@@ -8,11 +8,50 @@ void GameWorld::Initialize()
|
|||||||
m_ResourceManager.Preload("Model", "Models/Placeholders/PhysicsTest/Plane.obj");
|
m_ResourceManager.Preload("Model", "Models/Placeholders/PhysicsTest/Plane.obj");
|
||||||
m_ResourceManager.Preload("Model", "Models/Placeholders/PhysicsTest/ArrowCube.obj");
|
m_ResourceManager.Preload("Model", "Models/Placeholders/PhysicsTest/ArrowCube.obj");
|
||||||
|
|
||||||
BindKey(GLFW_KEY_W, "+forward");
|
BindKey(GLFW_KEY_W, "vertical", 1.f);
|
||||||
BindKey(GLFW_KEY_S, "+backward");
|
BindKey(GLFW_KEY_S, "vertical", -1.f);
|
||||||
BindKey(GLFW_KEY_A, "+left");
|
BindKey(GLFW_KEY_A, "horizontal", -1.f);
|
||||||
BindKey(GLFW_KEY_D, "+right");
|
BindKey(GLFW_KEY_D, "horizontal", 1.f);
|
||||||
BindKey(GLFW_KEY_SPACE, "+up");
|
BindGamepadAxis(Gamepad::Axis::LeftX, "horizontal", 1.f);
|
||||||
|
BindGamepadAxis(Gamepad::Axis::RightTrigger, "vertical", 1.f);
|
||||||
|
BindGamepadAxis(Gamepad::Axis::LeftTrigger, "vertical", -1.f);
|
||||||
|
|
||||||
|
BindKey(GLFW_KEY_UP, "barrel_rotation", 1.f);
|
||||||
|
BindKey(GLFW_KEY_DOWN, "barrel_rotation", -1.f);
|
||||||
|
BindKey(GLFW_KEY_LEFT, "tower_rotation", -1.f);
|
||||||
|
BindKey(GLFW_KEY_RIGHT, "tower_rotation", 1.f);
|
||||||
|
BindGamepadAxis(Gamepad::Axis::RightX, "tower_rotation", 1.f);
|
||||||
|
BindGamepadAxis(Gamepad::Axis::RightY, "barrel_rotation", 1.f);
|
||||||
|
|
||||||
|
BindKey(GLFW_KEY_SPACE, "handbrake", 1.f);
|
||||||
|
BindGamepadButton(Gamepad::Button::A, "handbrake", 1.f);
|
||||||
|
|
||||||
|
BindKey(GLFW_KEY_Z, "shoot", 1.f);
|
||||||
|
|
||||||
|
//BindGamepadButton(Gamepad::Button::Up, "Gamepad::Button::Up", 1.f);
|
||||||
|
//BindGamepadButton(Gamepad::Button::Down, "Gamepad::Button::Down", 1.f);
|
||||||
|
//BindGamepadButton(Gamepad::Button::Left, "Gamepad::Button::Left", 1.f);
|
||||||
|
//BindGamepadButton(Gamepad::Button::Right, "Gamepad::Button::Right", 1.f);
|
||||||
|
//BindGamepadButton(Gamepad::Button::Start, "Gamepad::Button::Start", 1.f);
|
||||||
|
//BindGamepadButton(Gamepad::Button::Back, "Gamepad::Button::Back", 1.f);
|
||||||
|
//BindGamepadButton(Gamepad::Button::LeftThumb, "Gamepad::Button::LeftThumb", 1.f);
|
||||||
|
//BindGamepadButton(Gamepad::Button::RightThumb, "Gamepad::Button::RightThumb", 1.f);
|
||||||
|
//BindGamepadButton(Gamepad::Button::LeftShoulder, "Gamepad::Button::LeftShoulder", 1.f);
|
||||||
|
//BindGamepadButton(Gamepad::Button::RightShoulder, "Gamepad::Button::RightShoulder", 1.f);
|
||||||
|
//BindGamepadButton(Gamepad::Button::A, "Gamepad::Button::A", 1.f);
|
||||||
|
//BindGamepadButton(Gamepad::Button::B, "Gamepad::Button::B", 1.f);
|
||||||
|
//BindGamepadButton(Gamepad::Button::X, "Gamepad::Button::X", 1.f);
|
||||||
|
//BindGamepadButton(Gamepad::Button::Y, "Gamepad::Button::Y", 1.f);
|
||||||
|
//
|
||||||
|
// BindKey(GLFW_KEY_UP, "vertical", -1.f);
|
||||||
|
// BindKey(GLFW_KEY_DOWN, "vertical", 1.f);
|
||||||
|
// BindKey(GLFW_KEY_LEFT, "horizontal", -1.f);
|
||||||
|
// BindKey(GLFW_KEY_RIGHT, "horizontal", 1.f);
|
||||||
|
/*
|
||||||
|
BindKey(GLFW_KEY_Q, "+tower_right");
|
||||||
|
BindKey(GLFW_KEY_E, "+tower_left");
|
||||||
|
|
||||||
|
BindKey(GLFW_KEY_Q, "+up");
|
||||||
BindKey(GLFW_KEY_LEFT_CONTROL, "+down");
|
BindKey(GLFW_KEY_LEFT_CONTROL, "+down");
|
||||||
BindKey(GLFW_KEY_LEFT_ALT, "+slow");
|
BindKey(GLFW_KEY_LEFT_ALT, "+slow");
|
||||||
BindKey(GLFW_KEY_LEFT_SHIFT, "+fast");
|
BindKey(GLFW_KEY_LEFT_SHIFT, "+fast");
|
||||||
@@ -20,6 +59,12 @@ void GameWorld::Initialize()
|
|||||||
BindMouseButton(GLFW_MOUSE_BUTTON_2, "+attack2");
|
BindMouseButton(GLFW_MOUSE_BUTTON_2, "+attack2");
|
||||||
BindMouseButton(GLFW_MOUSE_BUTTON_3, "+attack3");
|
BindMouseButton(GLFW_MOUSE_BUTTON_3, "+attack3");
|
||||||
|
|
||||||
|
|
||||||
|
BindKey(GLFW_KEY_UP, "+cam_forward");
|
||||||
|
BindKey(GLFW_KEY_DOWN, "+cam_backward");
|
||||||
|
BindKey(GLFW_KEY_LEFT, "+cam_left");
|
||||||
|
BindKey(GLFW_KEY_RIGHT, "+cam_right");*/
|
||||||
|
|
||||||
RegisterComponents();
|
RegisterComponents();
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -38,63 +83,96 @@ void GameWorld::Initialize()
|
|||||||
{
|
{
|
||||||
auto ground = CreateEntity();
|
auto ground = CreateEntity();
|
||||||
auto transform = AddComponent<Components::Transform>(ground, "Transform");
|
auto transform = AddComponent<Components::Transform>(ground, "Transform");
|
||||||
transform->Position = glm::vec3(0, -5, 0);
|
transform->Position = glm::vec3(0, 0, 0);
|
||||||
transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f);
|
//transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f);
|
||||||
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
||||||
auto model = AddComponent<Components::Model>(ground, "Model");
|
auto model = AddComponent<Components::Model>(ground, "Model");
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj";
|
//model->ModelFile = "Models/TestScene/testScene.obj";
|
||||||
auto box = AddComponent<Components::Box>(ground, "Box");
|
model->ModelFile = "Models/Placeholders/Terrain/Terrain2.obj";
|
||||||
box->Width = 200;
|
|
||||||
box->Height = 5;
|
|
||||||
box->Depth = 200;
|
|
||||||
|
|
||||||
auto physics = AddComponent<Components::Physics>(ground, "Physics");
|
auto physics = AddComponent<Components::Physics>(ground, "Physics");
|
||||||
physics->Mass = 10;
|
physics->Mass = 10;
|
||||||
physics->Static = true;
|
physics->Static = true;
|
||||||
|
|
||||||
|
|
||||||
|
auto groundshape = CreateEntity(ground);
|
||||||
|
auto transformshape = AddComponent<Components::Transform>(groundshape, "Transform");
|
||||||
|
auto meshShape = AddComponent<Components::MeshShape>(groundshape, "MeshShape");
|
||||||
|
meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain2.obj";
|
||||||
|
//meshShape->ResourceName = "Models/TestScene/testScene.obj";
|
||||||
|
|
||||||
|
|
||||||
|
CommitEntity(groundshape);
|
||||||
CommitEntity(ground);
|
CommitEntity(ground);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
|
/*{
|
||||||
auto jeep = CreateEntity();
|
auto jeep = CreateEntity();
|
||||||
auto transform = AddComponent<Components::Transform>(jeep, "Transform");
|
auto transform = AddComponent<Components::Transform>(jeep, "Transform");
|
||||||
transform->Position = glm::vec3(0, 2, 0);
|
transform->Position = glm::vec3(0, 5, 0);
|
||||||
|
transform->Orientation = glm::angleAxis(glm::pi<float>()/2, glm::vec3(0, 1, 0));
|
||||||
auto physics = AddComponent<Components::Physics>(jeep, "Physics");
|
auto physics = AddComponent<Components::Physics>(jeep, "Physics");
|
||||||
physics->Mass = 1200;
|
physics->Mass = 1800;
|
||||||
auto box = AddComponent<Components::Box>(jeep, "Box");
|
physics->Static = false;
|
||||||
box->Width = 1.487f;
|
|
||||||
box->Height = 0.727f;
|
|
||||||
box->Depth = 2.594f;
|
|
||||||
auto vehicle = AddComponent<Components::Vehicle>(jeep, "Vehicle");
|
auto vehicle = AddComponent<Components::Vehicle>(jeep, "Vehicle");
|
||||||
|
|
||||||
AddComponent<Components::Input>(jeep, "Input");
|
AddComponent<Components::Input>(jeep, "Input");
|
||||||
|
|
||||||
|
{
|
||||||
|
auto shape = CreateEntity(jeep);
|
||||||
|
auto transform = AddComponent<Components::Transform>(shape, "Transform");
|
||||||
|
auto meshShape = AddComponent<Components::MeshShape>(shape, "MeshShape");
|
||||||
|
meshShape->ResourceName = "Models/Jeep/Chassi/ChassiCollision.obj";
|
||||||
|
CommitEntity(shape);
|
||||||
|
|
||||||
|
// auto box = AddComponent<Components::Box>(jeep, "Box");
|
||||||
|
// box->Width = 1.487f;
|
||||||
|
// box->Height = 0.727f;
|
||||||
|
// box->Depth = 2.594f;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto chassis = CreateEntity(jeep);
|
auto chassis = CreateEntity(jeep);
|
||||||
auto transform = AddComponent<Components::Transform>(chassis, "Transform");
|
auto transform = AddComponent<Components::Transform>(chassis, "Transform");
|
||||||
transform->Position = glm::vec3(0, -0.6577f, 0);
|
transform->Position = glm::vec3(0, 0, 0); // 0.6577f
|
||||||
auto model = AddComponent<Components::Model>(chassis, "Model");
|
auto model = AddComponent<Components::Model>(chassis, "Model");
|
||||||
model->ModelFile = "Models/JeepV2/Chassi/chassi.OBJ";
|
model->ModelFile = "Models/Jeep/Chassi/chassi.obj";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto lightentity = CreateEntity(jeep);
|
||||||
|
auto transform = AddComponent<Components::Transform>(lightentity, "Transform");
|
||||||
|
transform->Position = glm::vec3(0, 15, 0);
|
||||||
|
auto light = AddComponent<Components::PointLight>(lightentity, "PointLight");
|
||||||
|
light->Diffuse = glm::vec3(128.f/255.f, 172.f/255.f, 242.f/255.f);
|
||||||
|
light->Specular = glm::vec3(1.f);
|
||||||
|
light->constantAttenuation = 0.3f;
|
||||||
|
light->linearAttenuation = 0.003f;
|
||||||
|
light->quadraticAttenuation = 0.002f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Create wheels
|
||||||
|
float wheelOffset = 0.4f;
|
||||||
|
float springLength = 0.3f;
|
||||||
|
float suspensionStrength = 35.f;
|
||||||
{
|
{
|
||||||
auto wheel = CreateEntity(jeep);
|
auto wheel = CreateEntity(jeep);
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
transform->Position = glm::vec3(1.4f, 0.5546f - 0.6577f - 0.2, -0.9242f);
|
transform->Position = glm::vec3(1.9f, 0.5546f - wheelOffset, -0.9242f);
|
||||||
transform->Scale = glm::vec3(1.0f);
|
transform->Scale = glm::vec3(1.0f);
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj";
|
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
|
||||||
Wheel->AxleID = 0;
|
Wheel->AxleID = 0;
|
||||||
Wheel->Mass = 50;
|
Wheel->Mass = 50;
|
||||||
Wheel->Radius = 0.837f;
|
Wheel->Radius = 0.837f;
|
||||||
Wheel->Steering = true;
|
Wheel->Steering = true;
|
||||||
Wheel->SuspensionStrength = 40.f;
|
Wheel->SuspensionStrength = suspensionStrength;
|
||||||
Wheel->Friction = 4.0f;
|
Wheel->Friction = 4.f;
|
||||||
Wheel->ConnectedToHandbrake = true;
|
Wheel->ConnectedToHandbrake = true;
|
||||||
CommitEntity(wheel);
|
CommitEntity(wheel);
|
||||||
}
|
}
|
||||||
@@ -102,19 +180,19 @@ void GameWorld::Initialize()
|
|||||||
{
|
{
|
||||||
auto wheel = CreateEntity(jeep);
|
auto wheel = CreateEntity(jeep);
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
transform->Position = glm::vec3(-1.4f, 0.5546f - 0.6577f - 0.2, -0.9242f);
|
transform->Position = glm::vec3(-1.9f, 0.5546f - wheelOffset, -0.9242f);
|
||||||
transform->Scale = glm::vec3(1.0f);
|
transform->Scale = glm::vec3(1.0f);
|
||||||
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj";
|
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
|
||||||
Wheel->AxleID = 0;
|
Wheel->AxleID = 0;
|
||||||
Wheel->Mass = 50;
|
Wheel->Mass = 50;
|
||||||
Wheel->Radius = 0.837f;
|
Wheel->Radius = 0.837f;
|
||||||
Wheel->Steering = true;
|
Wheel->Steering = true;
|
||||||
Wheel->SuspensionStrength = 40.f;
|
Wheel->SuspensionStrength = suspensionStrength;
|
||||||
Wheel->Friction = 4.0f;
|
Wheel->Friction = 4.f;
|
||||||
Wheel->ConnectedToHandbrake = true;
|
Wheel->ConnectedToHandbrake = true;
|
||||||
CommitEntity(wheel);
|
CommitEntity(wheel);
|
||||||
}
|
}
|
||||||
@@ -122,145 +200,545 @@ void GameWorld::Initialize()
|
|||||||
{
|
{
|
||||||
auto wheel = CreateEntity(jeep);
|
auto wheel = CreateEntity(jeep);
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
transform->Position = glm::vec3(0.2726f, 0.2805f - 0.6577f, 1.9307f);
|
transform->Position = glm::vec3(0.2726f, 0.2805f - wheelOffset, 1.9307f);
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj";
|
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
|
||||||
Wheel->AxleID = 1;
|
Wheel->AxleID = 1;
|
||||||
Wheel->Mass = 10;
|
Wheel->Mass = 50;
|
||||||
Wheel->Radius = 0.737f;
|
Wheel->Radius = 0.737f;
|
||||||
Wheel->Steering = false;
|
Wheel->Steering = false;
|
||||||
Wheel->SuspensionStrength = 50.f;
|
Wheel->SuspensionStrength = suspensionStrength;
|
||||||
Wheel->Friction = 4.0f;
|
Wheel->Friction = 4.f;
|
||||||
|
Wheel->ConnectedToHandbrake = true;
|
||||||
CommitEntity(wheel);
|
CommitEntity(wheel);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto wheel = CreateEntity(jeep);
|
auto wheel = CreateEntity(jeep);
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
transform->Position = glm::vec3(-0.2726f, 0.2805f - 0.6577f, 1.9307f);
|
transform->Position = glm::vec3(-0.2726f, 0.2805f - wheelOffset, 1.9307f);
|
||||||
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj";
|
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
|
||||||
Wheel->AxleID = 1;
|
Wheel->AxleID = 1;
|
||||||
Wheel->Mass = 10;
|
Wheel->Mass = 50;
|
||||||
Wheel->Radius = 0.737f;
|
Wheel->Radius = 0.737f;
|
||||||
Wheel->Steering = false;
|
Wheel->Steering = false;
|
||||||
Wheel->SuspensionStrength = 50.f;
|
Wheel->SuspensionStrength = suspensionStrength;
|
||||||
Wheel->Friction = 4.0f;
|
Wheel->Friction = 4.f;
|
||||||
|
Wheel->ConnectedToHandbrake = true;
|
||||||
CommitEntity(wheel);
|
CommitEntity(wheel);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommitEntity(jeep);
|
CommitEntity(jeep);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
auto tank = CreateEntity();
|
||||||
|
auto transform = AddComponent<Components::Transform>(tank, "Transform");
|
||||||
|
transform->Position = glm::vec3(0, 5, 0);
|
||||||
|
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
|
||||||
|
auto physics = AddComponent<Components::Physics>(tank, "Physics");
|
||||||
|
physics->Mass = 45000;
|
||||||
|
physics->Static = false;
|
||||||
|
auto vehicle = AddComponent<Components::Vehicle>(tank, "Vehicle");
|
||||||
|
vehicle->MaxTorque = 5200.f;
|
||||||
|
AddComponent<Components::TankSteering>(tank, "TankSteering");
|
||||||
|
AddComponent<Components::Input>(tank, "Input");
|
||||||
|
|
||||||
|
{
|
||||||
|
auto shape = CreateEntity(tank);
|
||||||
|
auto transform = AddComponent<Components::Transform>(shape, "Transform");
|
||||||
|
auto meshShape = AddComponent<Components::MeshShape>(shape, "MeshShape");
|
||||||
|
meshShape->ResourceName = "Models/Tank/Fix/ChassiCollision.obj";
|
||||||
|
CommitEntity(shape);
|
||||||
|
|
||||||
|
// auto box = AddComponent<Components::Box>(jeep, "Box");
|
||||||
|
// box->Width = 1.487f;
|
||||||
|
// box->Height = 0.727f;
|
||||||
|
// box->Depth = 2.594f;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto chassis = CreateEntity(tank);
|
||||||
|
auto transform = AddComponent<Components::Transform>(chassis, "Transform");
|
||||||
|
transform->Position = glm::vec3(0, 0, 0);
|
||||||
|
auto model = AddComponent<Components::Model>(chassis, "Model");
|
||||||
|
model->ModelFile = "Models/Tank/Fix/Chassi.obj";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto tower = CreateEntity(tank);
|
||||||
|
SetProperty(tower, "Name", "tower");
|
||||||
|
auto transform = AddComponent<Components::Transform>(tower, "Transform");
|
||||||
|
transform->Position = glm::vec3(0.f, 1.2f, 1.8f);
|
||||||
|
auto model = AddComponent<Components::Model>(tower, "Model");
|
||||||
|
model->ModelFile = "Models/Tank/Fix/Top.obj";
|
||||||
|
auto towerSteering = AddComponent<Components::TowerSteering>(tower, "TowerSteering");
|
||||||
|
towerSteering->Axis = glm::vec3(0.f, 1.f, 0.f);
|
||||||
|
towerSteering->TurnSpeed = glm::pi<float>()/4.f;
|
||||||
|
{
|
||||||
|
auto barrel = CreateEntity(tower);
|
||||||
|
auto transform = AddComponent<Components::Transform>(barrel, "Transform");
|
||||||
|
transform->Position = glm::vec3(-0.018f, -0.2, -1.3f);
|
||||||
|
auto model = AddComponent<Components::Model>(barrel, "Model");
|
||||||
|
model->ModelFile = "Models/Tank/Fix/Barrel.obj";
|
||||||
|
auto barrelSteering = AddComponent<Components::BarrelSteering>(barrel, "BarrelSteering");
|
||||||
|
barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f);
|
||||||
|
barrelSteering->TurnSpeed = glm::pi<float>()/4.f;
|
||||||
|
barrelSteering->ShotSpeed = 70.f;
|
||||||
|
{
|
||||||
|
auto shot = CreateEntity(barrel);
|
||||||
|
auto transform = AddComponent<Components::Transform>(shot, "Transform");
|
||||||
|
transform->Position = glm::vec3(0.35f, 0.f, -2.f);
|
||||||
|
transform->Orientation = glm::angleAxis(-glm::pi<float>()/2.f, glm::vec3(1, 0, 0));
|
||||||
|
transform->Scale = glm::vec3(3.f);
|
||||||
|
AddComponent(shot, "Template");
|
||||||
|
auto physics = AddComponent<Components::Physics>(shot, "Physics");
|
||||||
|
physics->Mass = 10.f;
|
||||||
|
physics->Static = false;
|
||||||
|
auto modelComponent = AddComponent<Components::Model>(shot, "Model");
|
||||||
|
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
|
||||||
|
|
||||||
|
{
|
||||||
|
auto shape = CreateEntity(shot);
|
||||||
|
auto transform = AddComponent<Components::Transform>(shape, "Transform");
|
||||||
|
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
|
||||||
|
boxShape->Width = 0.5f;
|
||||||
|
boxShape->Height = 0.5f;
|
||||||
|
boxShape->Depth = 0.5f;
|
||||||
|
CommitEntity(shape);
|
||||||
|
}
|
||||||
|
CommitEntity(shot);
|
||||||
|
barrelSteering->ShotTemplate = shot;
|
||||||
|
}
|
||||||
|
CommitEntity(barrel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto lightentity = CreateEntity(tank);
|
||||||
|
auto transform = AddComponent<Components::Transform>(lightentity, "Transform");
|
||||||
|
transform->Position = glm::vec3(0, 0, 0);
|
||||||
|
auto light = AddComponent<Components::PointLight>(lightentity, "PointLight");
|
||||||
|
//light->Diffuse = glm::vec3(128.f/255.f, 172.f/255.f, 242.f/255.f);
|
||||||
|
//light->Specular = glm::vec3(1.f);
|
||||||
|
/*light->ConstantAttenuation = 0.3f;
|
||||||
|
light->LinearAttenuation = 0.003f;
|
||||||
|
light->QuadraticAttenuation = 0.002f;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
// auto wheelpair = CreateEntity(tank);
|
||||||
|
// SetProperty(wheelpair, "Name", "WheelPair");
|
||||||
|
// AddComponent(wheelpair, "WheelPairThingy");
|
||||||
|
|
||||||
|
//Create wheels
|
||||||
|
float wheelOffset = 0.4f;
|
||||||
|
float springLength = 0.3f;
|
||||||
|
float suspensionStrength = 25.f;
|
||||||
|
|
||||||
|
{
|
||||||
|
auto wheel = CreateEntity(tank);
|
||||||
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
|
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -2.6f);
|
||||||
|
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
|
||||||
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
|
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
|
||||||
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
|
||||||
|
Wheel->AxleID = 0;
|
||||||
|
Wheel->Mass = 2000;
|
||||||
|
Wheel->Radius = 0.6f;
|
||||||
|
Wheel->Steering = true;
|
||||||
|
Wheel->SuspensionStrength = suspensionStrength;
|
||||||
|
Wheel->Friction = 4.f;
|
||||||
|
Wheel->ConnectedToHandbrake = true;
|
||||||
|
Wheel->TorqueRatio = 0.125f;
|
||||||
|
Wheel->Width = 0.6f;
|
||||||
|
{
|
||||||
|
auto shape = CreateEntity(wheel);
|
||||||
|
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
|
||||||
|
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
|
||||||
|
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
|
||||||
|
boxShape->Width = 0.7f;
|
||||||
|
boxShape->Height = 0.34f;
|
||||||
|
boxShape->Depth = 0.7f;
|
||||||
|
CommitEntity(shape);
|
||||||
|
}
|
||||||
|
CommitEntity(wheel);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto wheel = CreateEntity(tank);
|
||||||
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
|
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -0.83f);
|
||||||
|
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
|
||||||
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
|
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
|
||||||
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
|
||||||
|
Wheel->AxleID = 0;
|
||||||
|
Wheel->Mass = 2000;
|
||||||
|
Wheel->Radius = 0.6f;
|
||||||
|
Wheel->Steering = false;
|
||||||
|
Wheel->SuspensionStrength = suspensionStrength;
|
||||||
|
Wheel->Friction = 4.f;
|
||||||
|
Wheel->ConnectedToHandbrake = true;
|
||||||
|
Wheel->TorqueRatio = 0.125f;
|
||||||
|
Wheel->Width = 0.6f;
|
||||||
|
{
|
||||||
|
auto shape = CreateEntity(wheel);
|
||||||
|
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
|
||||||
|
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
|
||||||
|
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
|
||||||
|
boxShape->Width = 0.7f;
|
||||||
|
boxShape->Height = 0.34f;
|
||||||
|
boxShape->Depth = 0.7f;
|
||||||
|
CommitEntity(shape);
|
||||||
|
}
|
||||||
|
CommitEntity(wheel);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto wheel = CreateEntity(tank);
|
||||||
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
|
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -2.6f);
|
||||||
|
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
|
||||||
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
|
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
|
||||||
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
|
||||||
|
Wheel->AxleID = 0;
|
||||||
|
Wheel->Mass = 2000;
|
||||||
|
Wheel->Radius = 0.6f;
|
||||||
|
Wheel->Steering = true;
|
||||||
|
Wheel->SuspensionStrength = suspensionStrength;
|
||||||
|
Wheel->Friction = 4.f;
|
||||||
|
Wheel->ConnectedToHandbrake = true;
|
||||||
|
Wheel->TorqueRatio = 0.125f;
|
||||||
|
Wheel->Width = 0.6f;
|
||||||
|
{
|
||||||
|
auto shape = CreateEntity(wheel);
|
||||||
|
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
|
||||||
|
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
|
||||||
|
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
|
||||||
|
boxShape->Width = 0.7f;
|
||||||
|
boxShape->Height = 0.34f;
|
||||||
|
boxShape->Depth = 0.7f;
|
||||||
|
CommitEntity(shape);
|
||||||
|
}
|
||||||
|
CommitEntity(wheel);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto wheel = CreateEntity(tank);
|
||||||
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
|
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -0.83f);
|
||||||
|
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
|
||||||
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
|
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
|
||||||
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
|
||||||
|
Wheel->AxleID = 0;
|
||||||
|
Wheel->Mass = 2000;
|
||||||
|
Wheel->Radius = 0.6f;
|
||||||
|
Wheel->Steering = false;
|
||||||
|
Wheel->SuspensionStrength = suspensionStrength;
|
||||||
|
Wheel->Friction = 4.f;
|
||||||
|
Wheel->ConnectedToHandbrake = true;
|
||||||
|
Wheel->TorqueRatio = 0.125f;
|
||||||
|
Wheel->Width = 0.6f;
|
||||||
|
{
|
||||||
|
auto shape = CreateEntity(wheel);
|
||||||
|
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
|
||||||
|
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
|
||||||
|
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
|
||||||
|
boxShape->Width = 0.7f;
|
||||||
|
boxShape->Height = 0.34f;
|
||||||
|
boxShape->Depth = 0.7f;
|
||||||
|
CommitEntity(shape);
|
||||||
|
}
|
||||||
|
CommitEntity(wheel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Back
|
||||||
|
{
|
||||||
|
auto wheel = CreateEntity(tank);
|
||||||
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
|
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 1.f);
|
||||||
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
|
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
|
||||||
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
|
||||||
|
Wheel->AxleID = 1;
|
||||||
|
Wheel->Mass = 2000;
|
||||||
|
Wheel->Radius = 0.6f;
|
||||||
|
Wheel->Steering = false;
|
||||||
|
Wheel->SuspensionStrength = suspensionStrength;
|
||||||
|
Wheel->Friction = 4.f;
|
||||||
|
Wheel->ConnectedToHandbrake = true;
|
||||||
|
Wheel->TorqueRatio = 0.125f;
|
||||||
|
Wheel->Width = 0.6f;
|
||||||
|
{
|
||||||
|
auto shape = CreateEntity(wheel);
|
||||||
|
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
|
||||||
|
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
|
||||||
|
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
|
||||||
|
boxShape->Width = 0.7f;
|
||||||
|
boxShape->Height = 0.34f;
|
||||||
|
boxShape->Depth = 0.7f;
|
||||||
|
CommitEntity(shape);
|
||||||
|
}
|
||||||
|
CommitEntity(wheel);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto wheel = CreateEntity(tank);
|
||||||
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
|
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 2.95f);
|
||||||
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
|
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
|
||||||
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
|
||||||
|
Wheel->AxleID = 1;
|
||||||
|
Wheel->Mass = 2000;
|
||||||
|
Wheel->Radius = 0.6f;
|
||||||
|
Wheel->Steering = false;
|
||||||
|
Wheel->SuspensionStrength = suspensionStrength;
|
||||||
|
Wheel->Friction = 4.f;
|
||||||
|
Wheel->ConnectedToHandbrake = true;
|
||||||
|
Wheel->TorqueRatio = 0.125f;
|
||||||
|
Wheel->Width = 0.6f;
|
||||||
|
{
|
||||||
|
auto shape = CreateEntity(wheel);
|
||||||
|
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
|
||||||
|
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
|
||||||
|
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
|
||||||
|
boxShape->Width = 0.7f;
|
||||||
|
boxShape->Height = 0.34f;
|
||||||
|
boxShape->Depth = 0.7f;
|
||||||
|
CommitEntity(shape);
|
||||||
|
}
|
||||||
|
CommitEntity(wheel);
|
||||||
|
|
||||||
|
auto entity = CreateEntity(tank);
|
||||||
|
auto transformComponent = AddComponent<Components::Transform>(entity, "Transform");
|
||||||
|
transformComponent->Position = glm::vec3(2,-1.7,2.0);
|
||||||
|
transformComponent->Scale = glm::vec3(3,3,3);
|
||||||
|
transformComponent->Orientation = glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0));
|
||||||
|
auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity, "ParticleEmitter");
|
||||||
|
emitterComponent->SpawnCount = 2;
|
||||||
|
emitterComponent->SpawnFrequency = 0.005;
|
||||||
|
emitterComponent->SpreadAngle = glm::pi<float>();
|
||||||
|
emitterComponent->UseGoalVelocity = false;
|
||||||
|
emitterComponent->LifeTime = 0.5;
|
||||||
|
//emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
|
||||||
|
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
|
||||||
|
CommitEntity(entity);
|
||||||
|
|
||||||
|
auto particleEntity = CreateEntity(entity);
|
||||||
|
auto TEMP = AddComponent<Components::Transform>(particleEntity, "Transform");
|
||||||
|
TEMP->Scale = glm::vec3(0);
|
||||||
|
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity, "Sprite");
|
||||||
|
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
|
||||||
|
emitterComponent->ParticleTemplate = particleEntity;
|
||||||
|
|
||||||
|
CommitEntity(particleEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto wheel = CreateEntity(tank);
|
||||||
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
|
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 1.f);
|
||||||
|
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
|
||||||
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
|
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
|
||||||
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
|
||||||
|
Wheel->AxleID = 1;
|
||||||
|
Wheel->Mass = 2000;
|
||||||
|
Wheel->Radius = 0.6f;
|
||||||
|
Wheel->Steering = false;
|
||||||
|
Wheel->SuspensionStrength = suspensionStrength;
|
||||||
|
Wheel->Friction = 4.f;
|
||||||
|
Wheel->ConnectedToHandbrake = true;
|
||||||
|
Wheel->TorqueRatio = 0.125f;
|
||||||
|
Wheel->Width = 0.6f;
|
||||||
|
{
|
||||||
|
auto shape = CreateEntity(wheel);
|
||||||
|
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
|
||||||
|
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
|
||||||
|
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
|
||||||
|
boxShape->Width = 0.7f;
|
||||||
|
boxShape->Height = 0.34f;
|
||||||
|
boxShape->Depth = 0.7f;
|
||||||
|
CommitEntity(shape);
|
||||||
|
}
|
||||||
|
CommitEntity(wheel);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto wheel = CreateEntity(tank);
|
||||||
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
|
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 2.95f);
|
||||||
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
|
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
|
||||||
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
|
||||||
|
Wheel->AxleID = 1;
|
||||||
|
Wheel->Mass = 2000;
|
||||||
|
Wheel->Radius = 0.6f;
|
||||||
|
Wheel->Steering = false;
|
||||||
|
Wheel->SuspensionStrength = suspensionStrength;
|
||||||
|
Wheel->Friction = 4.f;
|
||||||
|
Wheel->ConnectedToHandbrake = true;
|
||||||
|
Wheel->TorqueRatio = 0.125f;
|
||||||
|
Wheel->Width = 0.6f;
|
||||||
|
{
|
||||||
|
auto shape = CreateEntity(wheel);
|
||||||
|
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
|
||||||
|
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
|
||||||
|
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
|
||||||
|
boxShape->Width = 0.7f;
|
||||||
|
boxShape->Height = 0.34f;
|
||||||
|
boxShape->Depth = 0.7f;
|
||||||
|
CommitEntity(shape);
|
||||||
|
}
|
||||||
|
CommitEntity(wheel);
|
||||||
|
|
||||||
|
auto entity = CreateEntity(tank);
|
||||||
|
auto transformComponent = AddComponent<Components::Transform>(entity, "Transform");
|
||||||
|
transformComponent->Position = glm::vec3(-2,-1.7,2.0);
|
||||||
|
transformComponent->Scale = glm::vec3(3,3,3);
|
||||||
|
transformComponent->Orientation = glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0));
|
||||||
|
auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity, "ParticleEmitter");
|
||||||
|
emitterComponent->SpawnCount = 2;
|
||||||
|
emitterComponent->SpawnFrequency = 0.005;
|
||||||
|
emitterComponent->SpreadAngle = glm::pi<float>();
|
||||||
|
emitterComponent->UseGoalVelocity = false;
|
||||||
|
emitterComponent->LifeTime = 0.5;
|
||||||
|
//emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
|
||||||
|
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
|
||||||
|
CommitEntity(entity);
|
||||||
|
|
||||||
|
auto particleEntity = CreateEntity(entity);
|
||||||
|
auto TEMP = AddComponent<Components::Transform>(particleEntity, "Transform");
|
||||||
|
TEMP->Scale = glm::vec3(0);
|
||||||
|
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity, "Sprite");
|
||||||
|
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
|
||||||
|
emitterComponent->ParticleTemplate = particleEntity;
|
||||||
|
|
||||||
|
CommitEntity(particleEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommitEntity(tank);
|
||||||
|
{
|
||||||
|
auto camera = CreateEntity(tank);
|
||||||
|
auto transform = AddComponent<Components::Transform>(camera, "Transform");
|
||||||
|
transform->Position.z = 30.f;
|
||||||
|
transform->Position.y = 5.f;
|
||||||
|
//transform->Orientation = glm::quat(glm::vec3(-glm::pi<float>() / 8.f, 0.f, 0.f));
|
||||||
|
transform->Orientation = glm::angleAxis(glm::pi<float>() / 100, glm::vec3(1,0,0));
|
||||||
|
auto cameraComp = AddComponent<Components::Camera>(camera, "Camera");
|
||||||
|
cameraComp->FarClip = 2000.f;
|
||||||
|
AddComponent(camera, "Input");
|
||||||
|
auto freeSteering = AddComponent<Components::FreeSteering>(camera, "FreeSteering");
|
||||||
|
CommitEntity(camera);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
{
|
|
||||||
// Front Right Wheel
|
|
||||||
auto ent = CreateEntity(car);
|
|
||||||
auto transform = AddComponent<Components::Transform>(ent, "Transform");
|
|
||||||
transform->Scale = glm::vec3(1)/glm::vec3(3, 1, 5);
|
|
||||||
transform->Position = glm::vec3(1.1f, -1.5f, -1.3f);
|
|
||||||
auto Wheel = AddComponent<Components::Wheel>(ent, "Wheel");
|
|
||||||
Wheel->Hardpoint = glm::vec3(1.1f, 0.f, -1.3f);// HACK: make into component
|
|
||||||
Wheel->AxleID = 0;
|
|
||||||
Wheel->Mass = 10;
|
|
||||||
Wheel->Radius = 0.5f;
|
|
||||||
Wheel->Steering = true;
|
|
||||||
Wheel->SuspensionStrength = 20.f;
|
|
||||||
auto model = AddComponent<Components::Model>(ent, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
|
||||||
CommitEntity(ent);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// Front Left Wheel
|
|
||||||
auto ent = CreateEntity(car);
|
|
||||||
auto transform = AddComponent<Components::Transform>(ent, "Transform");
|
|
||||||
transform->Scale = glm::vec3(1)/glm::vec3(3, 1, 5);
|
|
||||||
transform->Position = glm::vec3(-1.1f, -1.5f, -1.3f);
|
|
||||||
auto Wheel = AddComponent<Components::Wheel>(ent, "Wheel");
|
|
||||||
Wheel->Hardpoint = glm::vec3(-1.1f, 0.f, -1.3f);
|
|
||||||
Wheel->AxleID = 0;
|
|
||||||
Wheel->Mass = 10;
|
|
||||||
Wheel->Radius = 0.5f;
|
|
||||||
Wheel->Steering = true;
|
|
||||||
Wheel->SuspensionStrength = 20.f;
|
|
||||||
auto model = AddComponent<Components::Model>(ent, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
|
||||||
CommitEntity(ent);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// Back Right Wheel
|
|
||||||
auto ent = CreateEntity(car);
|
|
||||||
auto transform = AddComponent<Components::Transform>(ent, "Transform");
|
|
||||||
transform->Scale = glm::vec3(1)/glm::vec3(3, 1, 5);
|
|
||||||
transform->Position = glm::vec3(1.1f, -1.5f, 1.3f);
|
|
||||||
auto Wheel = AddComponent<Components::Wheel>(ent, "Wheel");
|
|
||||||
Wheel->Hardpoint = glm::vec3(1.1f, 0.f, 1.3f);
|
|
||||||
Wheel->AxleID = 1;
|
|
||||||
Wheel->Mass = 10;
|
|
||||||
Wheel->Radius = 0.5f;
|
|
||||||
Wheel->Steering = false;
|
|
||||||
Wheel->ConnectedToHandbrake = true;
|
|
||||||
Wheel->SuspensionStrength = 20.f;
|
|
||||||
auto model = AddComponent<Components::Model>(ent, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
|
||||||
CommitEntity(ent);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// Back Left Wheel
|
|
||||||
auto ent = CreateEntity(car);
|
|
||||||
auto transform = AddComponent<Components::Transform>(ent, "Transform");
|
|
||||||
transform->Scale = glm::vec3(1)/glm::vec3(3, 1, 5);
|
|
||||||
transform->Position = glm::vec3(-1.1f, -1.5f, 1.3f);
|
|
||||||
auto Wheel = AddComponent<Components::Wheel>(ent, "Wheel");
|
|
||||||
Wheel->Hardpoint = glm::vec3(-1.1f, 0.f, 1.3f);
|
|
||||||
Wheel->AxleID = 1;
|
|
||||||
Wheel->Mass = 10;
|
|
||||||
Wheel->Radius = 0.5f;
|
|
||||||
Wheel->Steering = false;
|
|
||||||
Wheel->ConnectedToHandbrake = true;
|
|
||||||
Wheel->SuspensionStrength = 20.f;
|
|
||||||
auto model = AddComponent<Components::Model>(ent, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
|
||||||
CommitEntity(ent);
|
|
||||||
}
|
|
||||||
|
|
||||||
CommitEntity(car);
|
/*
|
||||||
}
|
for(int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
auto entity = CreateEntity();
|
||||||
|
auto transform = AddComponent<Components::Transform>(entity, "Transform");
|
||||||
|
transform->Position = glm::vec3(30 + i*0.1f, 0 + i*0.1f, 10 + i*0.1f);
|
||||||
|
transform->Scale = glm::vec3(0);
|
||||||
|
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Models/Placeholders/ShatterTest/" << i+1 << ".obj";
|
||||||
|
|
||||||
|
auto model = AddComponent<Components::Model>(entity, "Model");
|
||||||
|
model->ModelFile = ss.str();
|
||||||
|
|
||||||
|
auto physics = AddComponent<Components::Physics>(entity, "Physics");
|
||||||
|
physics->Mass = 100;
|
||||||
|
physics->Static = true;
|
||||||
|
auto meshShape = AddComponent<Components::MeshShape>(entity, "MeshShape");
|
||||||
|
meshShape->ResourceName = ss.str();
|
||||||
|
|
||||||
|
CommitEntity(entity);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
for(int i = 0; i < 1; i++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < 15; y++)
|
||||||
|
{
|
||||||
|
for (int x = -5; x < 5; x++)
|
||||||
|
{
|
||||||
|
auto brick = CreateEntity();
|
||||||
|
auto transform = AddComponent<Components::Transform>(brick, "Transform");
|
||||||
|
transform->Position = glm::vec3(x + 0.01f, y * 0.3f + 0.01f, -20);
|
||||||
|
transform->Position.x += (y % 2)*0.5f;
|
||||||
|
transform->Scale = glm::vec3(1, 0.3f, 0.4f);
|
||||||
|
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
||||||
|
auto model = AddComponent<Components::Model>(brick, "Model");
|
||||||
|
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
||||||
|
|
||||||
|
auto physics = AddComponent<Components::Physics>(brick, "Physics");
|
||||||
|
physics->Mass = 3;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
auto shape = CreateEntity(brick);
|
||||||
|
auto transformshape = AddComponent<Components::Transform>(shape, "Transform");
|
||||||
|
auto box = AddComponent<Components::BoxShape>(shape, "BoxShape");
|
||||||
|
box->Width = 0.5f;
|
||||||
|
box->Height = 0.15f;
|
||||||
|
box->Depth = 0.3f;
|
||||||
|
CommitEntity(shape);
|
||||||
|
CommitEntity(brick);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*for (int x = 0; x < 5; x++)
|
||||||
|
for (int y = 0; y < 5; y++)
|
||||||
|
{
|
||||||
|
auto cube = CreateEntity();
|
||||||
|
auto transform = AddComponent<Components::Transform>(cube, "Transform");
|
||||||
|
transform->Position = glm::vec3(3 * x + 0.1f + -20.f, 3 * y + 0.1f + 1.f, 0);
|
||||||
|
transform->Scale = glm::vec3(3);
|
||||||
|
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
||||||
|
auto model = AddComponent<Components::Model>(cube, "Model");
|
||||||
|
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
||||||
|
|
||||||
|
auto physics = AddComponent<Components::Physics>(cube, "Physics");
|
||||||
|
physics->Mass = 100;
|
||||||
|
auto box = AddComponent<Components::BoxShape>(cube, "BoxShape");
|
||||||
|
box->Width = 1.5f;
|
||||||
|
box->Height = 1.5f;
|
||||||
|
box->Depth = 1.5f;
|
||||||
|
CommitEntity(cube);
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++)
|
|
||||||
{
|
|
||||||
auto cube = CreateEntity();
|
|
||||||
auto transform = AddComponent<Components::Transform>(cube, "Transform");
|
|
||||||
transform->Position = glm::vec3(20, 10 + i * 2, 0);
|
|
||||||
transform->Scale = glm::vec3(1);
|
|
||||||
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
|
||||||
auto model = AddComponent<Components::Model>(cube, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
|
||||||
|
|
||||||
auto physics = AddComponent<Components::Physics>(cube, "Physics");
|
/*{
|
||||||
physics->Mass = 100;
|
|
||||||
auto box = AddComponent<Components::Box>(cube, "Box");
|
|
||||||
box->Width = 0.5f;
|
|
||||||
box->Height = 0.5f;
|
|
||||||
box->Depth = 0.5f;
|
|
||||||
CommitEntity(cube);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto entity = CreateEntity();
|
auto entity = CreateEntity();
|
||||||
AddComponent(entity, "Transform");
|
AddComponent(entity, "Transform");
|
||||||
auto emitter = AddComponent<Components::SoundEmitter>(entity, "SoundEmitter");
|
auto emitter = AddComponent<Components::SoundEmitter>(entity, "SoundEmitter");
|
||||||
emitter->Path = "Sounds/korvring.wav";
|
emitter->Path = "Sounds/korvring.wav";
|
||||||
emitter->Loop = true;
|
emitter->Loop = true;
|
||||||
//GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(emitter);
|
GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(emitter);
|
||||||
CommitEntity(entity);
|
CommitEntity(entity);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameWorld::Update(double dt)
|
void GameWorld::Update(double dt)
|
||||||
@@ -281,9 +759,10 @@ void GameWorld::RegisterSystems()
|
|||||||
m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_EventBroker); });
|
m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_EventBroker); });
|
||||||
m_SystemFactory.Register("DebugSystem", [this]() { return new Systems::DebugSystem(this, m_EventBroker); });
|
m_SystemFactory.Register("DebugSystem", [this]() { return new Systems::DebugSystem(this, m_EventBroker); });
|
||||||
//m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); });
|
//m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); });
|
||||||
////m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); });
|
m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this, m_EventBroker); });
|
||||||
//m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); });
|
//m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); });
|
||||||
m_SystemFactory.Register("FreeSteeringSystem", [this]() { return new Systems::FreeSteeringSystem(this, m_EventBroker); });
|
m_SystemFactory.Register("FreeSteeringSystem", [this]() { return new Systems::FreeSteeringSystem(this, m_EventBroker); });
|
||||||
|
m_SystemFactory.Register("TankSteeringSystem", [this]() { return new Systems::TankSteeringSystem(this, m_EventBroker); });
|
||||||
m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this, m_EventBroker); });
|
m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this, m_EventBroker); });
|
||||||
m_SystemFactory.Register("PhysicsSystem", [this]() { return new Systems::PhysicsSystem(this, m_EventBroker); });
|
m_SystemFactory.Register("PhysicsSystem", [this]() { return new Systems::PhysicsSystem(this, m_EventBroker); });
|
||||||
m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_EventBroker, m_Renderer); });
|
m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_EventBroker, m_Renderer); });
|
||||||
@@ -296,19 +775,21 @@ void GameWorld::AddSystems()
|
|||||||
AddSystem("InputSystem");
|
AddSystem("InputSystem");
|
||||||
AddSystem("DebugSystem");
|
AddSystem("DebugSystem");
|
||||||
//AddSystem("CollisionSystem");
|
//AddSystem("CollisionSystem");
|
||||||
////AddSystem("ParticleSystem");
|
AddSystem("ParticleSystem");
|
||||||
//AddSystem("PlayerSystem");
|
//AddSystem("PlayerSystem");
|
||||||
AddSystem("FreeSteeringSystem");
|
AddSystem("FreeSteeringSystem");
|
||||||
|
AddSystem("TankSteeringSystem");
|
||||||
AddSystem("SoundSystem");
|
AddSystem("SoundSystem");
|
||||||
AddSystem("PhysicsSystem");
|
AddSystem("PhysicsSystem");
|
||||||
AddSystem("RenderSystem");
|
AddSystem("RenderSystem");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameWorld::BindKey(int keyCode, std::string command)
|
void GameWorld::BindKey(int keyCode, std::string command, float value)
|
||||||
{
|
{
|
||||||
Events::BindKey e;
|
Events::BindKey e;
|
||||||
e.KeyCode = keyCode;
|
e.KeyCode = keyCode;
|
||||||
e.Command = command;
|
e.Command = command;
|
||||||
|
e.Value = value;
|
||||||
m_EventBroker->Publish(e);
|
m_EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,3 +800,21 @@ void GameWorld::BindMouseButton(int button, std::string command)
|
|||||||
e.Command = command;
|
e.Command = command;
|
||||||
m_EventBroker->Publish(e);
|
m_EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameWorld::BindGamepadAxis(Gamepad::Axis axis, std::string command, float value)
|
||||||
|
{
|
||||||
|
Events::BindGamepadAxis e;
|
||||||
|
e.Axis = axis;
|
||||||
|
e.Command = command;
|
||||||
|
e.Value = value;
|
||||||
|
m_EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameWorld::BindGamepadButton(Gamepad::Button button, std::string command, float value)
|
||||||
|
{
|
||||||
|
Events::BindGamepadButton e;
|
||||||
|
e.Button = button;
|
||||||
|
e.Command = command;
|
||||||
|
e.Value = value;
|
||||||
|
m_EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
|||||||
+12
-4
@@ -9,9 +9,10 @@
|
|||||||
#include "Systems/InputSystem.h"
|
#include "Systems/InputSystem.h"
|
||||||
#include "Systems/DebugSystem.h"
|
#include "Systems/DebugSystem.h"
|
||||||
//#include "Systems/LevelGenerationSystem.h"
|
//#include "Systems/LevelGenerationSystem.h"
|
||||||
//#include "Systems/ParticleSystem.h"
|
#include "Systems/ParticleSystem.h"
|
||||||
//#include "Systems/PlayerSystem.h"
|
//#include "Systems/PlayerSystem.h"
|
||||||
#include "Systems/FreeSteeringSystem.h"
|
#include "Systems/FreeSteeringSystem.h"
|
||||||
|
#include "Systems/TankSteeringSystem.h"
|
||||||
#include "Systems/RenderSystem.h"
|
#include "Systems/RenderSystem.h"
|
||||||
#include "Systems/SoundSystem.h"
|
#include "Systems/SoundSystem.h"
|
||||||
#include "Systems/PhysicsSystem.h"
|
#include "Systems/PhysicsSystem.h"
|
||||||
@@ -21,6 +22,7 @@
|
|||||||
#include "Components/Input.h"
|
#include "Components/Input.h"
|
||||||
#include "Components/Model.h"
|
#include "Components/Model.h"
|
||||||
#include "Components/ParticleEmitter.h"
|
#include "Components/ParticleEmitter.h"
|
||||||
|
#include "Components/Particle.h"
|
||||||
#include "Components/PointLight.h"
|
#include "Components/PointLight.h"
|
||||||
#include "Components/SoundEmitter.h"
|
#include "Components/SoundEmitter.h"
|
||||||
#include "Components/Sprite.h"
|
#include "Components/Sprite.h"
|
||||||
@@ -28,10 +30,14 @@
|
|||||||
#include "Components/Transform.h"
|
#include "Components/Transform.h"
|
||||||
|
|
||||||
#include "Components/Physics.h"
|
#include "Components/Physics.h"
|
||||||
#include "Components/Sphere.h"
|
#include "Components/SphereShape.h"
|
||||||
#include "Components/Box.h"
|
#include "Components/BoxShape.h"
|
||||||
#include "Components/Vehicle.h"
|
#include "Components/Vehicle.h"
|
||||||
#include "Components/Wheel.h"
|
#include "Components/Wheel.h"
|
||||||
|
#include "Components/HingeConstraint.h"
|
||||||
|
#include "Components/TankSteering.h"
|
||||||
|
#include "Components/TowerSteering.h"
|
||||||
|
#include "Components/BarrelSteering.h"
|
||||||
|
|
||||||
class GameWorld : public World
|
class GameWorld : public World
|
||||||
{
|
{
|
||||||
@@ -50,8 +56,10 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::shared_ptr<Renderer> m_Renderer;
|
std::shared_ptr<Renderer> m_Renderer;
|
||||||
|
|
||||||
void BindKey(int keyCode, std::string command);
|
void BindKey(int keyCode, std::string command, float value);
|
||||||
void BindMouseButton(int button, std::string command);
|
void BindMouseButton(int button, std::string command);
|
||||||
|
void BindGamepadAxis(Gamepad::Axis axis, std::string command, float value);
|
||||||
|
void BindGamepadButton(Gamepad::Button button, std::string command, float value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GameWorld_h__
|
#endif // GameWorld_h__
|
||||||
|
|||||||
+110
-6
@@ -1,6 +1,12 @@
|
|||||||
#include "PrecompiledHeader.h"
|
#include "PrecompiledHeader.h"
|
||||||
#include "InputManager.h"
|
#include "InputManager.h"
|
||||||
|
|
||||||
|
void InputManager::Initialize()
|
||||||
|
{
|
||||||
|
m_LastGamepadAxisState = std::array<GamepadAxisState, XUSER_MAX_COUNT>();
|
||||||
|
m_LastGamepadButtonState = std::array<GamepadButtonState, XUSER_MAX_COUNT>();
|
||||||
|
}
|
||||||
|
|
||||||
void InputManager::Update(double dt)
|
void InputManager::Update(double dt)
|
||||||
{
|
{
|
||||||
m_LastKeyState = m_CurrentKeyState;
|
m_LastKeyState = m_CurrentKeyState;
|
||||||
@@ -19,13 +25,13 @@ void InputManager::Update(double dt)
|
|||||||
{
|
{
|
||||||
Events::KeyDown e;
|
Events::KeyDown e;
|
||||||
e.KeyCode = i;
|
e.KeyCode = i;
|
||||||
m_EventBroker->Publish<Events::KeyDown>(e);
|
m_EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Events::KeyUp e;
|
Events::KeyUp e;
|
||||||
e.KeyCode = i;
|
e.KeyCode = i;
|
||||||
m_EventBroker->Publish<Events::KeyUp>(e);
|
m_EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,7 +51,7 @@ void InputManager::Update(double dt)
|
|||||||
e.Button = i;
|
e.Button = i;
|
||||||
e.X = x;
|
e.X = x;
|
||||||
e.Y = y;
|
e.Y = y;
|
||||||
m_EventBroker->Publish<Events::MousePress>(e);
|
m_EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -53,12 +59,12 @@ void InputManager::Update(double dt)
|
|||||||
e.Button = i;
|
e.Button = i;
|
||||||
e.X = x;
|
e.X = x;
|
||||||
e.Y = y;
|
e.Y = y;
|
||||||
m_EventBroker->Publish<Events::MouseRelease>(e);
|
m_EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cursor position
|
// Mouse movement
|
||||||
glfwGetCursorPos(m_GLFWWindow, &m_CurrentMouseX, &m_CurrentMouseY);
|
glfwGetCursorPos(m_GLFWWindow, &m_CurrentMouseX, &m_CurrentMouseY);
|
||||||
m_CurrentMouseDeltaX = m_CurrentMouseX - m_LastMouseX;
|
m_CurrentMouseDeltaX = m_CurrentMouseX - m_LastMouseX;
|
||||||
m_CurrentMouseDeltaY = m_CurrentMouseY - m_LastMouseY;
|
m_CurrentMouseDeltaY = m_CurrentMouseY - m_LastMouseY;
|
||||||
@@ -70,7 +76,7 @@ void InputManager::Update(double dt)
|
|||||||
e.Y = m_CurrentMouseY;
|
e.Y = m_CurrentMouseY;
|
||||||
e.DeltaX = m_CurrentMouseDeltaX;
|
e.DeltaX = m_CurrentMouseDeltaX;
|
||||||
e.DeltaY = m_CurrentMouseDeltaY;
|
e.DeltaY = m_CurrentMouseDeltaY;
|
||||||
m_EventBroker->Publish<Events::MouseMove>(e);
|
m_EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// // Lock mouse while holding LMB
|
// // Lock mouse while holding LMB
|
||||||
@@ -89,4 +95,102 @@ void InputManager::Update(double dt)
|
|||||||
// {
|
// {
|
||||||
// glfwSetInputMode(m_GLFWWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
// glfwSetInputMode(m_GLFWWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// Xbox360 controller
|
||||||
|
using namespace Windows;
|
||||||
|
DWORD dwResult;
|
||||||
|
for (int i = 0; i < XUSER_MAX_COUNT; i++)
|
||||||
|
{
|
||||||
|
XINPUT_STATE state = { 0 };
|
||||||
|
// Simply get the state of the controller from XInput.
|
||||||
|
dwResult = XInputGetState(i, &state);
|
||||||
|
if (dwResult == 0)
|
||||||
|
{
|
||||||
|
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftX)] = state.Gamepad.sThumbLX / 32767.f;
|
||||||
|
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftY)] = state.Gamepad.sThumbLY / 32767.f;
|
||||||
|
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::RightX)] = state.Gamepad.sThumbRX / 32767.f;
|
||||||
|
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::RightY)] = state.Gamepad.sThumbRY / 32767.f;
|
||||||
|
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftTrigger)] = state.Gamepad.bLeftTrigger / 255.f;
|
||||||
|
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::RightTrigger)] = state.Gamepad.bRightTrigger / 255.f;
|
||||||
|
PublishGamepadAxisIfChanged(i, Gamepad::Axis::LeftX);
|
||||||
|
PublishGamepadAxisIfChanged(i, Gamepad::Axis::LeftY);
|
||||||
|
PublishGamepadAxisIfChanged(i, Gamepad::Axis::RightX);
|
||||||
|
PublishGamepadAxisIfChanged(i, Gamepad::Axis::RightY);
|
||||||
|
PublishGamepadAxisIfChanged(i, Gamepad::Axis::LeftTrigger);
|
||||||
|
PublishGamepadAxisIfChanged(i, Gamepad::Axis::RightTrigger);
|
||||||
|
|
||||||
|
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Up)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP);
|
||||||
|
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Down)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN);
|
||||||
|
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Left)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT);
|
||||||
|
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Right)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT);
|
||||||
|
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Start)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_START);
|
||||||
|
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Back)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK);
|
||||||
|
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::LeftThumb)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB);
|
||||||
|
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::RightThumb)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB);
|
||||||
|
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::LeftShoulder)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER);
|
||||||
|
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::RightShoulder)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER);
|
||||||
|
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::A)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_A);
|
||||||
|
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::B)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_B);
|
||||||
|
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::X)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_X);
|
||||||
|
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Y)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_Y);
|
||||||
|
PublishGamepadButtonIfChanged(i, Gamepad::Button::Up);
|
||||||
|
PublishGamepadButtonIfChanged(i, Gamepad::Button::Down);
|
||||||
|
PublishGamepadButtonIfChanged(i, Gamepad::Button::Left);
|
||||||
|
PublishGamepadButtonIfChanged(i, Gamepad::Button::Right);
|
||||||
|
PublishGamepadButtonIfChanged(i, Gamepad::Button::Start);
|
||||||
|
PublishGamepadButtonIfChanged(i, Gamepad::Button::Back);
|
||||||
|
PublishGamepadButtonIfChanged(i, Gamepad::Button::LeftThumb);
|
||||||
|
PublishGamepadButtonIfChanged(i, Gamepad::Button::RightThumb);
|
||||||
|
PublishGamepadButtonIfChanged(i, Gamepad::Button::LeftShoulder);
|
||||||
|
PublishGamepadButtonIfChanged(i, Gamepad::Button::RightShoulder);
|
||||||
|
PublishGamepadButtonIfChanged(i, Gamepad::Button::A);
|
||||||
|
PublishGamepadButtonIfChanged(i, Gamepad::Button::B);
|
||||||
|
PublishGamepadButtonIfChanged(i, Gamepad::Button::X);
|
||||||
|
PublishGamepadButtonIfChanged(i, Gamepad::Button::Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_LastKeyState = m_CurrentKeyState;
|
||||||
|
m_LastMouseState = m_CurrentMouseState;
|
||||||
|
m_LastMouseX = m_CurrentMouseX;
|
||||||
|
m_LastMouseY = m_CurrentMouseY;
|
||||||
|
m_LastGamepadAxisState = m_CurrentGamepadAxisState;
|
||||||
|
m_LastGamepadButtonState = m_CurrentGamepadButtonState;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputManager::PublishGamepadAxisIfChanged(int gamepadID, Gamepad::Axis axis)
|
||||||
|
{
|
||||||
|
float currentValue = m_CurrentGamepadAxisState[gamepadID][static_cast<int>(axis)];
|
||||||
|
float lastValue = m_LastGamepadAxisState[gamepadID][static_cast<int>(axis)];
|
||||||
|
if (currentValue != lastValue)
|
||||||
|
{
|
||||||
|
Events::GamepadAxis e;
|
||||||
|
e.GamepadID = gamepadID;
|
||||||
|
e.Axis = axis;
|
||||||
|
e.Value = currentValue;
|
||||||
|
m_EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputManager::PublishGamepadButtonIfChanged(int gamepadID, Gamepad::Button button)
|
||||||
|
{
|
||||||
|
bool currentState = m_CurrentGamepadButtonState[gamepadID][static_cast<int>(button)];
|
||||||
|
float lastState = m_LastGamepadButtonState[gamepadID][static_cast<int>(button)];
|
||||||
|
if (currentState != lastState)
|
||||||
|
{
|
||||||
|
if (currentState == true)
|
||||||
|
{
|
||||||
|
Events::GamepadButtonDown e;
|
||||||
|
e.GamepadID = gamepadID;
|
||||||
|
e.Button = button;
|
||||||
|
m_EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Events::GamepadButtonUp e;
|
||||||
|
e.GamepadID = gamepadID;
|
||||||
|
e.Button = button;
|
||||||
|
m_EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-1
@@ -3,12 +3,21 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
namespace Windows
|
||||||
|
{
|
||||||
|
#include <Xinput.h>
|
||||||
|
#undef min
|
||||||
|
#undef max
|
||||||
|
}
|
||||||
|
|
||||||
#include "EventBroker.h"
|
#include "EventBroker.h"
|
||||||
#include "Events/KeyDown.h"
|
#include "Events/KeyDown.h"
|
||||||
#include "Events/KeyUp.h"
|
#include "Events/KeyUp.h"
|
||||||
#include "Events/MousePress.h"
|
#include "Events/MousePress.h"
|
||||||
#include "Events/MouseRelease.h"
|
#include "Events/MouseRelease.h"
|
||||||
#include "Events/MouseMove.h"
|
#include "Events/MouseMove.h"
|
||||||
|
#include "Events/GamepadAxis.h"
|
||||||
|
#include "Events/GamepadButton.h"
|
||||||
|
|
||||||
class InputManager
|
class InputManager
|
||||||
{
|
{
|
||||||
@@ -22,7 +31,10 @@ public:
|
|||||||
, m_LastMouseState()
|
, m_LastMouseState()
|
||||||
, m_CurrentMouseX(0), m_CurrentMouseY(0)
|
, m_CurrentMouseX(0), m_CurrentMouseY(0)
|
||||||
, m_LastMouseX(0), m_LastMouseY(0)
|
, m_LastMouseX(0), m_LastMouseY(0)
|
||||||
, m_CurrentMouseDeltaX(0), m_CurrentMouseDeltaY(0) { }
|
, m_CurrentMouseDeltaX(0), m_CurrentMouseDeltaY(0)
|
||||||
|
{ Initialize(); }
|
||||||
|
|
||||||
|
void Initialize();
|
||||||
|
|
||||||
void Update(double dt);
|
void Update(double dt);
|
||||||
|
|
||||||
@@ -34,9 +46,19 @@ private:
|
|||||||
std::array<int, GLFW_KEY_LAST+1> m_LastKeyState;
|
std::array<int, GLFW_KEY_LAST+1> m_LastKeyState;
|
||||||
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_CurrentMouseState;
|
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_CurrentMouseState;
|
||||||
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_LastMouseState;
|
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_LastMouseState;
|
||||||
|
typedef std::array<float, static_cast<int>(Gamepad::Axis::LAST) + 1> GamepadAxisState;
|
||||||
|
std::array<GamepadAxisState, XUSER_MAX_COUNT> m_CurrentGamepadAxisState;
|
||||||
|
std::array<GamepadAxisState, XUSER_MAX_COUNT> m_LastGamepadAxisState;
|
||||||
|
typedef std::array<bool, static_cast<int>(Gamepad::Button::LAST) + 1> GamepadButtonState;
|
||||||
|
std::array<GamepadButtonState, XUSER_MAX_COUNT> m_CurrentGamepadButtonState;
|
||||||
|
std::array<GamepadButtonState, XUSER_MAX_COUNT> m_LastGamepadButtonState;
|
||||||
|
|
||||||
double m_CurrentMouseX, m_CurrentMouseY;
|
double m_CurrentMouseX, m_CurrentMouseY;
|
||||||
double m_LastMouseX, m_LastMouseY;
|
double m_LastMouseX, m_LastMouseY;
|
||||||
double m_CurrentMouseDeltaX, m_CurrentMouseDeltaY;
|
double m_CurrentMouseDeltaX, m_CurrentMouseDeltaY;
|
||||||
|
|
||||||
|
void PublishGamepadAxisIfChanged(int gamepadID, Gamepad::Axis axis);
|
||||||
|
void PublishGamepadButtonIfChanged(int gamepadID, Gamepad::Button button);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // InputManager_h__
|
#endif // InputManager_h__
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
#include "PrecompiledHeader.h"
|
#include "PrecompiledHeader.h"
|
||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
|
|
||||||
Model::Model(OBJ &obj, ResourceManager* rm)
|
Model::Model(ResourceManager* rm, OBJ &obj)
|
||||||
{
|
{
|
||||||
OBJ::MaterialInfo* currentMaterial = nullptr;
|
OBJ::MaterialInfo* currentMaterial = nullptr;
|
||||||
TextureGroup* currentTexGroup = nullptr;
|
TextureGroup* currentTexGroup = nullptr;
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@
|
|||||||
class Model : public Resource
|
class Model : public Resource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Model(OBJ &obj, ResourceManager* rm);
|
Model(ResourceManager* rm, OBJ &obj);
|
||||||
|
|
||||||
struct TextureGroup
|
struct TextureGroup
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ bool OBJ::LoadFromFile(std::string filename)
|
|||||||
std::ifstream file(m_Path.string());
|
std::ifstream file(m_Path.string());
|
||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
{
|
{
|
||||||
LOG_ERROR("Failed to open .obj \"%s\"", m_Path.string().c_str());
|
LOG_ERROR("Failed to open .obj \"%s\": %s", m_Path.string().c_str(), strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,9 @@
|
|||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
class OBJ
|
#include "ResourceManager.h"
|
||||||
|
|
||||||
|
class OBJ : public Resource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct MaterialInfo
|
struct MaterialInfo
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ void VehicleSetup::buildVehicle(World *world, const hkpWorld* physicsWorld, hkpV
|
|||||||
|
|
||||||
setupWheelCollide(physicsWorld, vehicle, *static_cast<hkpVehicleRayCastWheelCollide*>(vehicle.m_wheelCollide));
|
setupWheelCollide(physicsWorld, vehicle, *static_cast<hkpVehicleRayCastWheelCollide*>(vehicle.m_wheelCollide));
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check that all components are present.
|
// Check that all components are present.
|
||||||
//
|
//
|
||||||
@@ -105,7 +104,7 @@ void VehicleSetup::setupVehicleData(const hkpWorld* world, hkpVehicleData& data
|
|||||||
data.m_torquePitchFactor = 0.5f;
|
data.m_torquePitchFactor = 0.5f;
|
||||||
data.m_torqueYawFactor = 0.35f;
|
data.m_torqueYawFactor = 0.35f;
|
||||||
|
|
||||||
data.m_chassisUnitInertiaYaw = 1.0f;
|
data.m_chassisUnitInertiaYaw = 0.8f;
|
||||||
data.m_chassisUnitInertiaRoll = 1.0f;
|
data.m_chassisUnitInertiaRoll = 1.0f;
|
||||||
data.m_chassisUnitInertiaPitch = 1.0f;
|
data.m_chassisUnitInertiaPitch = 1.0f;
|
||||||
|
|
||||||
@@ -165,7 +164,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultS
|
|||||||
|
|
||||||
// [mph/h] The steering angle decreases linearly
|
// [mph/h] The steering angle decreases linearly
|
||||||
// based on your overall max speed of the vehicle.
|
// based on your overall max speed of the vehicle.
|
||||||
steering.m_maxSpeedFullSteeringAngle = 70.0f * (1.605f / 3.6f); //MPH???!
|
steering.m_maxSpeedFullSteeringAngle = vehicleComponent.MaxSpeedFullSteeringAngle; // * (1.605f / 3.6f); //MPH???!
|
||||||
|
|
||||||
for (int i = 0; i < m_Wheels.size(); i++)
|
for (int i = 0; i < m_Wheels.size(); i++)
|
||||||
{
|
{
|
||||||
@@ -198,20 +197,21 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultT
|
|||||||
transmission.m_gearsRatio.setSize(numberOfGears);
|
transmission.m_gearsRatio.setSize(numberOfGears);
|
||||||
transmission.m_wheelsTorqueRatio.setSize(data.m_numWheels);
|
transmission.m_wheelsTorqueRatio.setSize(data.m_numWheels);
|
||||||
|
|
||||||
transmission.m_downshiftRPM = 3500.0f;
|
transmission.m_downshiftRPM = 3500.0f; //HACK: Should be in VehicleComponent
|
||||||
transmission.m_upshiftRPM = 6500.0f;
|
transmission.m_upshiftRPM = 7000.0f;
|
||||||
|
|
||||||
transmission.m_clutchDelayTime = 0.0f;
|
transmission.m_clutchDelayTime = 0.0f;
|
||||||
transmission.m_reverseGearRatio = 1.0f;
|
transmission.m_reverseGearRatio = 1.2f;
|
||||||
transmission.m_gearsRatio[0] = 2.0f;
|
transmission.m_gearsRatio[0] = 3.0f;
|
||||||
transmission.m_gearsRatio[1] = 1.5f;
|
transmission.m_gearsRatio[1] = 2.25f;
|
||||||
transmission.m_gearsRatio[2] = 1.0f;
|
transmission.m_gearsRatio[2] = 1.5f;
|
||||||
transmission.m_gearsRatio[3] = 0.75f;
|
transmission.m_gearsRatio[3] = 1.0f;
|
||||||
transmission.m_wheelsTorqueRatio[0] = 0.2f;
|
|
||||||
transmission.m_wheelsTorqueRatio[1] = 0.2f;
|
|
||||||
transmission.m_wheelsTorqueRatio[2] = 0.3f;
|
|
||||||
transmission.m_wheelsTorqueRatio[3] = 0.3f;
|
|
||||||
|
|
||||||
|
for(int i = 0; i < m_Wheels.size(); i++)
|
||||||
|
{
|
||||||
|
// The wheels total TorqueRatio must be equal to 1
|
||||||
|
transmission.m_wheelsTorqueRatio[i] = m_Wheels[i].WheelComponent->TorqueRatio;
|
||||||
|
}
|
||||||
|
|
||||||
transmission.m_primaryTransmissionRatio = hkpVehicleDefaultTransmission::calculatePrimaryTransmissionRatio(
|
transmission.m_primaryTransmissionRatio = hkpVehicleDefaultTransmission::calculatePrimaryTransmissionRatio(
|
||||||
vehicleComponent.TopSpeed,
|
vehicleComponent.TopSpeed,
|
||||||
@@ -246,9 +246,8 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultS
|
|||||||
suspension.m_wheelParams[i].m_length = suspensionLength;
|
suspension.m_wheelParams[i].m_length = suspensionLength;
|
||||||
suspension.m_wheelSpringParams[i].m_strength = m_Wheels[i].WheelComponent->SuspensionStrength;
|
suspension.m_wheelSpringParams[i].m_strength = m_Wheels[i].WheelComponent->SuspensionStrength;
|
||||||
|
|
||||||
const float wd = 3.0f;
|
suspension.m_wheelSpringParams[i].m_dampingCompression = vehicleComponent.SpringDamping;
|
||||||
suspension.m_wheelSpringParams[i].m_dampingCompression = wd;
|
suspension.m_wheelSpringParams[i].m_dampingRelaxation = vehicleComponent.SpringDamping;
|
||||||
suspension.m_wheelSpringParams[i].m_dampingRelaxation = wd;
|
|
||||||
|
|
||||||
|
|
||||||
suspension.m_wheelParams[i].m_hardpointChassisSpace.set(m_Wheels[i].WheelComponent->Hardpoint.x, m_Wheels[i].WheelComponent->Hardpoint.y, m_Wheels[i].WheelComponent->Hardpoint.z);
|
suspension.m_wheelParams[i].m_hardpointChassisSpace.set(m_Wheels[i].WheelComponent->Hardpoint.x, m_Wheels[i].WheelComponent->Hardpoint.y, m_Wheels[i].WheelComponent->Hardpoint.z);
|
||||||
@@ -267,7 +266,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultA
|
|||||||
aerodynamics.m_liftCoefficient = -0.3f;
|
aerodynamics.m_liftCoefficient = -0.3f;
|
||||||
|
|
||||||
// Extra gavity applies in world space (independent of m_chassisCoordinateSystem).
|
// Extra gavity applies in world space (independent of m_chassisCoordinateSystem).
|
||||||
aerodynamics.m_extraGravityws.set(0.0f, -5.0f, 0.0f);
|
aerodynamics.m_extraGravityws.set(0.0f, -8.0f, 0.0f); // fuck this shit
|
||||||
}
|
}
|
||||||
|
|
||||||
void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultVelocityDamper& velocityDamper, Components::Vehicle vehicleComponent)
|
void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultVelocityDamper& velocityDamper, Components::Vehicle vehicleComponent)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <Physics2012/Vehicle/Engine/Default/hkpVehicleDefaultEngine.h>
|
#include <Physics2012/Vehicle/Engine/Default/hkpVehicleDefaultEngine.h>
|
||||||
#include <Physics2012/Vehicle/VelocityDamper/Default/hkpVehicleDefaultVelocityDamper.h>
|
#include <Physics2012/Vehicle/VelocityDamper/Default/hkpVehicleDefaultVelocityDamper.h>
|
||||||
#include <Physics2012/Vehicle/Steering/Default/hkpVehicleDefaultSteering.h>
|
#include <Physics2012/Vehicle/Steering/Default/hkpVehicleDefaultSteering.h>
|
||||||
|
#include <Physics2012/Vehicle/Steering/hkpVehicleSteering.h>
|
||||||
#include <Physics2012/Vehicle/Suspension/Default/hkpVehicleDefaultSuspension.h>
|
#include <Physics2012/Vehicle/Suspension/Default/hkpVehicleDefaultSuspension.h>
|
||||||
#include <Physics2012/Vehicle/Transmission/Default/hkpVehicleDefaultTransmission.h>
|
#include <Physics2012/Vehicle/Transmission/Default/hkpVehicleDefaultTransmission.h>
|
||||||
#include <Physics2012/Vehicle/WheelCollide/RayCast/hkpVehicleRayCastWheelCollide.h>
|
#include <Physics2012/Vehicle/WheelCollide/RayCast/hkpVehicleRayCastWheelCollide.h>
|
||||||
@@ -42,6 +43,7 @@ public:
|
|||||||
{
|
{
|
||||||
Components::Wheel* WheelComponent;
|
Components::Wheel* WheelComponent;
|
||||||
Components::Transform* TransformComponent;
|
Components::Transform* TransformComponent;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<WheelData> m_Wheels;
|
std::vector<WheelData> m_Wheels;
|
||||||
@@ -58,6 +60,7 @@ public:
|
|||||||
virtual void setupComponent(const hkpVehicleData& data, hkpVehicleDefaultVelocityDamper& velocityDamper, Components::Vehicle vehicleComponent);
|
virtual void setupComponent(const hkpVehicleData& data, hkpVehicleDefaultVelocityDamper& velocityDamper, Components::Vehicle vehicleComponent);
|
||||||
|
|
||||||
virtual void setupWheelCollide(const hkpWorld* world, const hkpVehicleInstance& vehicle, hkpVehicleRayCastWheelCollide& wheelCollide);
|
virtual void setupWheelCollide(const hkpWorld* world, const hkpVehicleInstance& vehicle, hkpVehicleRayCastWheelCollide& wheelCollide);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // Physics_Vehicle_h__
|
#endif // Physics_Vehicle_h__
|
||||||
|
|||||||
+465
-184
@@ -13,12 +13,15 @@ Renderer::Renderer()
|
|||||||
m_DrawWireframe = false;
|
m_DrawWireframe = false;
|
||||||
m_DrawBounds = false;
|
m_DrawBounds = false;
|
||||||
#endif
|
#endif
|
||||||
|
Gamma = 2.2f;
|
||||||
m_ShadowMapRes = 2048;
|
CAtt = 1.0f;
|
||||||
|
LAtt = 0.0f;
|
||||||
|
QAtt = 3.0f;
|
||||||
|
m_ShadowMapRes = 2048*8;
|
||||||
m_SunPosition = glm::vec3(0, 3.5f, 10);
|
m_SunPosition = glm::vec3(0, 3.5f, 10);
|
||||||
m_SunTarget = glm::vec3(0, 0, 0);
|
m_SunTarget = glm::vec3(0, 0, 0);
|
||||||
m_SunProjection = glm::ortho<float>(-100, 100, -100, 100, -100, 100);
|
m_SunProjection = glm::ortho<float>(-200.f, 200.f, -200.f, 200.f, -100, 200);
|
||||||
Lights = 0;
|
/* Lights = 0;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::Initialize()
|
void Renderer::Initialize()
|
||||||
@@ -76,7 +79,7 @@ void Renderer::Initialize()
|
|||||||
|
|
||||||
void Renderer::LoadContent()
|
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"));
|
auto standardFS = std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment.glsl"));
|
||||||
|
|
||||||
m_ShaderProgram.AddShader(standardVS);
|
m_ShaderProgram.AddShader(standardVS);
|
||||||
@@ -90,11 +93,6 @@ void Renderer::LoadContent()
|
|||||||
m_ShaderProgramNormals.Compile();
|
m_ShaderProgramNormals.Compile();
|
||||||
m_ShaderProgramNormals.Link();
|
m_ShaderProgramNormals.Link();
|
||||||
|
|
||||||
m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ShadowMap.vert.glsl")));
|
|
||||||
m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ShadowMap.frag.glsl")));
|
|
||||||
m_ShaderProgramShadows.Compile();
|
|
||||||
m_ShaderProgramShadows.Link();
|
|
||||||
|
|
||||||
m_ShaderProgramShadowsDrawDepth.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/VisualizeDepth.vert.glsl")));
|
m_ShaderProgramShadowsDrawDepth.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/VisualizeDepth.vert.glsl")));
|
||||||
m_ShaderProgramShadowsDrawDepth.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/VisualizeDepth.frag.glsl")));
|
m_ShaderProgramShadowsDrawDepth.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/VisualizeDepth.frag.glsl")));
|
||||||
m_ShaderProgramShadowsDrawDepth.Compile();
|
m_ShaderProgramShadowsDrawDepth.Compile();
|
||||||
@@ -108,13 +106,124 @@ void Renderer::LoadContent()
|
|||||||
m_ShaderProgramSkybox.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Skybox.vert.glsl")));
|
m_ShaderProgramSkybox.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Skybox.vert.glsl")));
|
||||||
m_ShaderProgramSkybox.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Skybox.frag.glsl")));
|
m_ShaderProgramSkybox.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Skybox.frag.glsl")));
|
||||||
m_ShaderProgramSkybox.Compile();
|
m_ShaderProgramSkybox.Compile();
|
||||||
m_ShaderProgramSkybox.Link();
|
m_ShaderProgramSkybox.Link();*/
|
||||||
|
|
||||||
m_Skybox = std::make_shared<Skybox>("Textures/Skybox/Sunset", "jpg");
|
m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ShadowMap.vert.glsl")));
|
||||||
|
m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ShadowMap.frag.glsl")));
|
||||||
|
m_ShaderProgramShadows.Compile();
|
||||||
|
m_ShaderProgramShadows.Link();
|
||||||
|
|
||||||
m_DebugAABB = CreateAABB();
|
m_FirstPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex.glsl")));
|
||||||
|
m_FirstPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment.glsl")));
|
||||||
|
m_FirstPassProgram.Compile();
|
||||||
|
|
||||||
|
glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 0, "frag_Diffuse");
|
||||||
|
glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 1, "frag_Position");
|
||||||
|
glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 2, "frag_Normal");
|
||||||
|
m_FirstPassProgram.Link();
|
||||||
|
|
||||||
|
m_SecondPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex2.glsl")));
|
||||||
|
m_SecondPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment2.glsl")));
|
||||||
|
m_SecondPassProgram.Compile();
|
||||||
|
m_SecondPassProgram.Link();
|
||||||
|
|
||||||
|
m_SecondPassProgram_Debug.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex2.glsl")));
|
||||||
|
m_SecondPassProgram_Debug.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment2-Debug.glsl")));
|
||||||
|
m_SecondPassProgram_Debug.Compile();
|
||||||
|
m_SecondPassProgram_Debug.Link();
|
||||||
|
|
||||||
|
m_FinalPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/FinalPass.vert.glsl")));
|
||||||
|
m_FinalPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FinalPass.frag.glsl")));
|
||||||
|
m_FinalPassProgram.Compile();
|
||||||
|
m_FinalPassProgram.Link();
|
||||||
m_ScreenQuad = CreateQuad();
|
m_ScreenQuad = CreateQuad();
|
||||||
CreateShadowMap(m_ShadowMapRes);
|
CreateShadowMap(m_ShadowMapRes);
|
||||||
|
FrameBufferTextures();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::Draw(double dt)
|
||||||
|
{
|
||||||
|
if(glfwGetKey(m_Window, GLFW_KEY_F1))
|
||||||
|
{
|
||||||
|
m_QuadView = false;
|
||||||
|
}
|
||||||
|
if(glfwGetKey(m_Window, GLFW_KEY_F2))
|
||||||
|
{
|
||||||
|
m_QuadView = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(glfwGetKey(m_Window, GLFW_KEY_KP_1))
|
||||||
|
{
|
||||||
|
Gamma -= 0.3f * dt;
|
||||||
|
LOG_INFO("Gamma_UP: %f", Gamma);
|
||||||
|
}
|
||||||
|
if(glfwGetKey(m_Window, GLFW_KEY_KP_4))
|
||||||
|
{
|
||||||
|
Gamma += 0.3f * dt;
|
||||||
|
LOG_INFO("Gamma_DOWN: %f", Gamma);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(glfwGetKey(m_Window, GLFW_KEY_1))
|
||||||
|
{
|
||||||
|
if(glfwGetKey(m_Window, GLFW_KEY_KP_ADD))
|
||||||
|
{
|
||||||
|
CAtt += 0.5f * dt;
|
||||||
|
LOG_INFO("Const: %f", CAtt);
|
||||||
|
}
|
||||||
|
if(glfwGetKey(m_Window, GLFW_KEY_KP_SUBTRACT))
|
||||||
|
{
|
||||||
|
CAtt -= 0.5f * dt;
|
||||||
|
LOG_INFO("Const: %f", CAtt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(glfwGetKey(m_Window, GLFW_KEY_2))
|
||||||
|
{
|
||||||
|
if(glfwGetKey(m_Window, GLFW_KEY_KP_ADD))
|
||||||
|
{
|
||||||
|
LAtt += 0.5f * dt;
|
||||||
|
LOG_INFO("Linear: %f", LAtt);
|
||||||
|
}
|
||||||
|
if(glfwGetKey(m_Window, GLFW_KEY_KP_SUBTRACT))
|
||||||
|
{
|
||||||
|
LAtt -= 0.5f * dt;
|
||||||
|
LOG_INFO("Linear: %f", LAtt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(glfwGetKey(m_Window, GLFW_KEY_3))
|
||||||
|
{
|
||||||
|
if(glfwGetKey(m_Window, GLFW_KEY_KP_ADD))
|
||||||
|
{
|
||||||
|
QAtt += 0.5f * dt;
|
||||||
|
LOG_INFO("Quadratic: %f", QAtt);
|
||||||
|
}
|
||||||
|
if(glfwGetKey(m_Window, GLFW_KEY_KP_SUBTRACT))
|
||||||
|
{
|
||||||
|
QAtt -= 0.5f * dt;
|
||||||
|
LOG_INFO("Quadratic: %f", QAtt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
|
DrawFBO();
|
||||||
|
|
||||||
|
ClearStuff();
|
||||||
|
glfwSwapBuffers(m_Window);
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma region TempRegion
|
||||||
|
|
||||||
|
void Renderer::DrawSkybox()
|
||||||
|
{
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
glViewport(0, 0, m_Width, m_Height);
|
||||||
|
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
m_ShaderProgramSkybox.Bind();
|
||||||
|
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * glm::toMat4(glm::inverse(m_Camera->Orientation()));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(cameraMatrix));
|
||||||
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
m_Skybox->Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::CreateShadowMap(int resolution)
|
void Renderer::CreateShadowMap(int resolution)
|
||||||
@@ -137,169 +246,35 @@ void Renderer::CreateShadowMap(int resolution)
|
|||||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_ShadowDepthTexture, 0);
|
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_ShadowDepthTexture, 0);
|
||||||
glDrawBuffer(GL_NONE);
|
glDrawBuffer(GL_NONE);
|
||||||
|
|
||||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
{
|
|
||||||
LOG_ERROR("Framebuffer incomplete!");
|
LOG_ERROR("Framebuffer incomplete!");
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Renderer::Draw(double dt)
|
|
||||||
{
|
|
||||||
glDisable(GL_BLEND);
|
|
||||||
|
|
||||||
DrawSkybox();
|
|
||||||
DrawShadowMap();
|
|
||||||
DrawScene();
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
// Draw bounding boxes
|
|
||||||
if (m_DrawBounds)
|
|
||||||
{
|
|
||||||
glEnable(GL_BLEND);
|
|
||||||
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
|
||||||
m_ShaderProgramDebugAABB.Bind();
|
|
||||||
for (auto tuple : AABBsToRender)
|
|
||||||
{
|
|
||||||
glm::mat4 modelMatrix;
|
|
||||||
bool colliding;
|
|
||||||
std::tie(modelMatrix, colliding) = tuple;
|
|
||||||
// Model matrix
|
|
||||||
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
|
||||||
glm::mat4 MVP = cameraMatrix * modelMatrix;
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
|
||||||
// Color
|
|
||||||
glm::vec4 color(1.f, 1.f, 1.f, 0.f);
|
|
||||||
if (colliding)
|
|
||||||
color = glm::vec4(1.f, 0.f, 0.f, 0.f);
|
|
||||||
glUniform4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "Color"), 1, glm::value_ptr(color));
|
|
||||||
glBindVertexArray(m_DebugAABB);
|
|
||||||
glDrawArrays(GL_LINES, 0, 24);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawDebugShadowMap();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ClearStuff();
|
|
||||||
glfwSwapBuffers(m_Window);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::DrawSkybox()
|
|
||||||
{
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
||||||
glViewport(0, 0, m_Width, m_Height);
|
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
m_ShaderProgramSkybox.Bind();
|
|
||||||
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * glm::toMat4(glm::inverse(m_Camera->Orientation()));
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(cameraMatrix));
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
||||||
m_Skybox->Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::DrawScene()
|
|
||||||
{
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
||||||
glViewport(0, 0, m_Width, m_Height);
|
|
||||||
|
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
|
||||||
//glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
glEnable(GL_CULL_FACE);
|
|
||||||
glCullFace(GL_BACK);
|
|
||||||
#ifdef DEBUG
|
|
||||||
glDisable(GL_CULL_FACE);
|
|
||||||
glPolygonMode(GL_BACK, GL_LINE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Draw models
|
|
||||||
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate(-m_Camera->Position() * glm::vec3(1, 0, 0));
|
|
||||||
glm::mat4 depthCamera = m_SunProjection * depthViewMatrix;
|
|
||||||
glm::mat4 biasMatrix(
|
|
||||||
0.5, 0.0, 0.0, 0.0,
|
|
||||||
0.0, 0.5, 0.0, 0.0,
|
|
||||||
0.0, 0.0, 0.5, 0.0,
|
|
||||||
0.5, 0.5, 0.5, 1.0
|
|
||||||
);
|
|
||||||
|
|
||||||
m_ShaderProgram.Bind();
|
|
||||||
glUniform1i(glGetUniformLocation(m_ShaderProgram.GetHandle(), "numberOfLights"), Lights);
|
|
||||||
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), Lights, Light_position.data());
|
|
||||||
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), Lights, Light_specular.data());
|
|
||||||
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "diffuse"), Lights, Light_diffuse.data());
|
|
||||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), Lights, Light_constantAttenuation.data());
|
|
||||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), Lights, Light_linearAttenuation.data());
|
|
||||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), Lights, Light_quadraticAttenuation.data());
|
|
||||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), Lights, Light_spotExponent.data());
|
|
||||||
if (m_DrawWireframe)
|
|
||||||
{
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
|
||||||
}
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
|
|
||||||
//DrawModels(m_ShaderProgram);
|
|
||||||
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
|
||||||
glm::mat4 depthCameraMatrix = biasMatrix * depthCamera;
|
|
||||||
glm::mat4 MVP;
|
|
||||||
glm::mat4 depthMVP;
|
|
||||||
for (auto tuple : ModelsToRender)
|
|
||||||
{
|
|
||||||
Model* model;
|
|
||||||
glm::mat4 modelMatrix;
|
|
||||||
bool visible;
|
|
||||||
std::tie(model, modelMatrix, visible, std::ignore) = tuple;
|
|
||||||
if (!visible)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
MVP = cameraMatrix * modelMatrix;
|
|
||||||
depthMVP = depthCameraMatrix * modelMatrix;
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
|
||||||
glBindVertexArray(model->VAO);
|
|
||||||
for (auto texGroup : model->TextureGroups)
|
|
||||||
{
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, *texGroup.Texture);
|
|
||||||
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
// Debug draw model normals
|
|
||||||
if (m_DrawNormals)
|
|
||||||
{
|
|
||||||
m_ShaderProgramNormals.Bind();
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
||||||
DrawModels(m_ShaderProgramNormals);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::DrawShadowMap()
|
void Renderer::DrawShadowMap()
|
||||||
{
|
{
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);//Tests where objects are and display them correctly
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE); //removes triangles on the wrong side of the object
|
||||||
glCullFace(GL_FRONT);
|
glCullFace(GL_BACK); //Make it so that only the back faces are rendered
|
||||||
|
|
||||||
|
//Binds the FBO and sets the veiwport, witch in effect is how large the shadowmap is and what resolution it has.
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_ShadowFrameBuffer);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_ShadowFrameBuffer);
|
||||||
glViewport(0, 0, m_ShadowMapRes, m_ShadowMapRes);
|
glViewport(0, 0, m_ShadowMapRes, m_ShadowMapRes);
|
||||||
|
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
//glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
//glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate(-m_Camera->Position() * glm::vec3(1, 0, 0));
|
//Creates the "camera" for the shadowmap from the direction of the sun.
|
||||||
// glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0));
|
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0));
|
||||||
glm::mat4 depthCamera = m_SunProjection * depthViewMatrix;
|
glm::mat4 depthCamera = m_SunProjection * depthViewMatrix;
|
||||||
|
|
||||||
//glm::mat4 cameraMatrix = depthProjectionMatrix * m_Camera->ViewMatrix();
|
|
||||||
|
|
||||||
glm::mat4 MVP;
|
glm::mat4 MVP;
|
||||||
|
|
||||||
m_ShaderProgramShadows.Bind();
|
m_ShaderProgramShadows.Bind();
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //Draws filled polygons
|
||||||
|
|
||||||
|
//For each model, render them to the shadowmap
|
||||||
for (auto tuple : ModelsToRender)
|
for (auto tuple : ModelsToRender)
|
||||||
{
|
{
|
||||||
Model* model;
|
Model* model;
|
||||||
@@ -318,6 +293,8 @@ void Renderer::DrawShadowMap()
|
|||||||
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
|
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::DrawDebugShadowMap()
|
void Renderer::DrawDebugShadowMap()
|
||||||
@@ -376,30 +353,44 @@ void Renderer::AddModelToDraw(Model* model, glm::vec3 position, glm::quat orient
|
|||||||
ModelsToRender.push_back(std::make_tuple(model, modelMatrix, visible, shadowCaster));
|
ModelsToRender.push_back(std::make_tuple(model, modelMatrix, visible, shadowCaster));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renderer::AddTextureToDraw(Texture* texture, glm::vec3 position, glm::quat orientation, glm::vec3 scale)
|
||||||
|
{
|
||||||
|
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
|
||||||
|
|
||||||
|
glm::vec3 camToParticle = glm::normalize(m_Camera->Position() - position);
|
||||||
|
glm::vec3 up = glm::vec3(0,1,0);
|
||||||
|
glm::vec3 rightVec = glm::normalize(glm::cross(up, camToParticle));
|
||||||
|
glm::vec3 up2 = glm::normalize(glm::cross(camToParticle, rightVec));
|
||||||
|
|
||||||
|
glm::mat4 billboardMatrix;
|
||||||
|
billboardMatrix[0] = glm::vec4(rightVec, 0);
|
||||||
|
billboardMatrix[1] = glm::vec4(up2, 0);
|
||||||
|
billboardMatrix[2] = glm::vec4(camToParticle, 0);
|
||||||
|
//billboardMatrix[3] = glm::vec4(position, 0);
|
||||||
|
|
||||||
|
TexturesToRender.push_back(std::make_tuple(texture, modelMatrix, billboardMatrix));
|
||||||
|
}
|
||||||
|
|
||||||
void Renderer::AddPointLightToDraw(
|
void Renderer::AddPointLightToDraw(
|
||||||
glm::vec3 _position,
|
glm::vec3 _position,
|
||||||
glm::vec3 _specular,
|
glm::vec3 _specular,
|
||||||
glm::vec3 _diffuse,
|
glm::vec3 _diffuse,
|
||||||
float _constantAttenuation,
|
float _specularExponent,
|
||||||
float _linearAttenuation,
|
float _ConstantAttenuation,
|
||||||
float _quadraticAttenuation,
|
float _LinearAttenuation,
|
||||||
float _spotExponent
|
float _QuadraticAttenuation
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Light_position.push_back(_position.x);
|
Light light;
|
||||||
Light_position.push_back(_position.y);
|
light.Position = _position;
|
||||||
Light_position.push_back(_position.z);
|
light.Diffuse = _diffuse;
|
||||||
Light_specular.push_back(_specular.x);
|
light.Specular = _specular;
|
||||||
Light_specular.push_back(_specular.y);
|
light.SpecularExponent = _specularExponent;
|
||||||
Light_specular.push_back(_specular.z);
|
light.ConstantAttenuation = _ConstantAttenuation;
|
||||||
Light_diffuse.push_back(_diffuse.x);
|
light.LinearAttenuation = _LinearAttenuation;
|
||||||
Light_diffuse.push_back(_diffuse.y);
|
light.QuadraticAttenuation = _QuadraticAttenuation;
|
||||||
Light_diffuse.push_back(_diffuse.z);
|
light.SphereModelMatrix = CreateLightMatrix(light);
|
||||||
Light_constantAttenuation.push_back(_constantAttenuation);
|
Lights.push_back(light);
|
||||||
Light_linearAttenuation.push_back(_linearAttenuation);
|
|
||||||
Light_quadraticAttenuation.push_back(_quadraticAttenuation);
|
|
||||||
Light_spotExponent.push_back(_spotExponent);
|
|
||||||
Lights = Light_constantAttenuation.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding)
|
void Renderer::AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding)
|
||||||
@@ -532,16 +523,306 @@ GLuint Renderer::CreateSkybox()
|
|||||||
|
|
||||||
return vao;
|
return vao;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::ClearStuff()
|
void Renderer::ClearStuff()
|
||||||
{
|
{
|
||||||
AABBsToRender.clear();
|
AABBsToRender.clear();
|
||||||
ModelsToRender.clear();
|
ModelsToRender.clear();
|
||||||
Light_position.clear();
|
TexturesToRender.clear();
|
||||||
Light_specular.clear();
|
Lights.clear();
|
||||||
Light_diffuse.clear();
|
|
||||||
Light_constantAttenuation.clear();
|
|
||||||
Light_linearAttenuation.clear();
|
|
||||||
Light_quadraticAttenuation.clear();
|
|
||||||
Light_spotExponent.clear();
|
|
||||||
Lights = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
void Renderer::FrameBufferTextures()
|
||||||
|
{
|
||||||
|
m_fbBasePass = 0;
|
||||||
|
m_fDepthBuffer = 0;
|
||||||
|
|
||||||
|
glGenFramebuffers(1, &m_fbBasePass);
|
||||||
|
glGenRenderbuffers(1, &m_fDepthBuffer);
|
||||||
|
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, m_fDepthBuffer);
|
||||||
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Width, m_Height);
|
||||||
|
|
||||||
|
//Generate and bind diffuse texture
|
||||||
|
glGenTextures(1, &m_fDiffuseTexture);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
|
||||||
|
//Generate and bind position texture
|
||||||
|
glGenTextures(1, &m_fPositionTexture);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
|
||||||
|
//Generate and bind normal texture
|
||||||
|
glGenTextures(1, &m_fNormalsTexture);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
|
||||||
|
/*glGenTextures(1, &m_fShadowTexture);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_fShadowTexture);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);*/
|
||||||
|
|
||||||
|
//Bind fb
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, m_fbBasePass);
|
||||||
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_fDepthBuffer);
|
||||||
|
|
||||||
|
//Attach textures to the FB
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fDiffuseTexture, 0);
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, m_fPositionTexture, 0);
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, m_fNormalsTexture, 0);
|
||||||
|
//glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, m_fShadowTexture, 0);
|
||||||
|
|
||||||
|
GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||||
|
if(fbStatus != GL_FRAMEBUFFER_COMPLETE)
|
||||||
|
{
|
||||||
|
LOG_ERROR("DeferredLighting:Init: m_fbBasePass incomplete: 0x%x\n", fbStatus);
|
||||||
|
//exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_fbLightingPass = 0;
|
||||||
|
glGenFramebuffers(1, &m_fbLightingPass);
|
||||||
|
|
||||||
|
glGenTextures(1, &m_fLightingTexture);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, m_fbLightingPass);
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fLightingTexture, 0);
|
||||||
|
|
||||||
|
fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||||
|
if(fbStatus != GL_FRAMEBUFFER_COMPLETE)
|
||||||
|
{
|
||||||
|
LOG_ERROR("DeferredLighting:Init: m_fbLightingPass incomplete: 0x%x\n", fbStatus);
|
||||||
|
//exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::DrawFBO()
|
||||||
|
{
|
||||||
|
DrawShadowMap();
|
||||||
|
|
||||||
|
/*
|
||||||
|
Base pass
|
||||||
|
*/
|
||||||
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass);
|
||||||
|
|
||||||
|
// Clear G-buffer
|
||||||
|
GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
|
||||||
|
glDrawBuffers(3, windowBuffClear);
|
||||||
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Execute the first render stage which will fill out the internal buffers with data(??)
|
||||||
|
m_FirstPassProgram.Bind();
|
||||||
|
GLenum windowBuffOpaque[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
|
||||||
|
glDrawBuffers(3, windowBuffOpaque);
|
||||||
|
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
|
||||||
|
glViewport(0, 0, m_Width, m_Height);
|
||||||
|
DrawFBOScene();
|
||||||
|
|
||||||
|
/*
|
||||||
|
Lighting pass
|
||||||
|
*/
|
||||||
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbLightingPass);
|
||||||
|
GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 };
|
||||||
|
glDrawBuffers(1, lightingPassAttachments);
|
||||||
|
|
||||||
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
m_SecondPassProgram.Bind();
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
|
||||||
|
|
||||||
|
glCullFace(GL_FRONT);
|
||||||
|
DrawLightScene();
|
||||||
|
|
||||||
|
/*
|
||||||
|
Final pass
|
||||||
|
*/
|
||||||
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
m_FinalPassProgram.Bind();
|
||||||
|
|
||||||
|
// Ambient light
|
||||||
|
glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.1f, 0.1f, 0.1f)));
|
||||||
|
glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
|
||||||
|
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
glBindVertexArray(m_ScreenQuad);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::DrawFBOScene()
|
||||||
|
{
|
||||||
|
// glEnable(GL_DEPTH_TEST);//Tests where objects are and display them correctly
|
||||||
|
// glEnable(GL_CULL_FACE); //removes triangles on the wrong side of the object
|
||||||
|
// glCullFace(GL_BACK); //Make it so that only the back faces are rendered
|
||||||
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //Draws filled polygons
|
||||||
|
|
||||||
|
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
||||||
|
glm::mat4 MVP;
|
||||||
|
glm::mat4 biasMatrix(
|
||||||
|
0.5, 0.0, 0.0, 0.0,
|
||||||
|
0.0, 0.5, 0.0, 0.0,
|
||||||
|
0.0, 0.0, 0.5, 0.0,
|
||||||
|
0.5, 0.5, 0.5, 1.0
|
||||||
|
);
|
||||||
|
|
||||||
|
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0));
|
||||||
|
glm::mat4 depthCamera = m_SunProjection * depthViewMatrix;
|
||||||
|
glm::mat4 depthCameraMatrix = biasMatrix * depthCamera;
|
||||||
|
glm::mat4 depthMVP;
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
|
||||||
|
|
||||||
|
for (auto tuple : ModelsToRender)
|
||||||
|
{
|
||||||
|
Model* model;
|
||||||
|
glm::mat4 modelMatrix;
|
||||||
|
bool visible;
|
||||||
|
std::tie(model, modelMatrix, visible, std::ignore) = tuple;
|
||||||
|
if (!visible)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
MVP = cameraMatrix * modelMatrix;
|
||||||
|
depthMVP = depthCameraMatrix * modelMatrix;
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
|
||||||
|
glBindVertexArray(model->VAO);
|
||||||
|
for (auto texGroup : model->TextureGroups)
|
||||||
|
{
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, *texGroup.Texture);
|
||||||
|
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto tuple : TexturesToRender)
|
||||||
|
{
|
||||||
|
Texture* texture;
|
||||||
|
glm::mat4 modelMatrix;
|
||||||
|
glm::mat4 billboardMatrix;
|
||||||
|
std::tie(texture, modelMatrix, billboardMatrix) = tuple;
|
||||||
|
|
||||||
|
//MVP = cameraMatrix * glm::inverse(glm::toMat4(m_Camera->Orientation()) * modelMatrix );
|
||||||
|
MVP = cameraMatrix * modelMatrix * billboardMatrix;
|
||||||
|
|
||||||
|
depthMVP = depthCameraMatrix * modelMatrix;
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||||
|
glBindVertexArray(m_ScreenQuad);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Renderer::DrawLightScene()
|
||||||
|
{
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendEquation (GL_FUNC_ADD);
|
||||||
|
glBlendFunc(GL_ONE,GL_ONE);
|
||||||
|
|
||||||
|
glDisable (GL_DEPTH_TEST);
|
||||||
|
glDepthMask (GL_FALSE);
|
||||||
|
glBindVertexArray(m_sphereModel->VAO);
|
||||||
|
|
||||||
|
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
||||||
|
glm::mat4 MVP;
|
||||||
|
|
||||||
|
for (auto &light : Lights)
|
||||||
|
{
|
||||||
|
MVP = cameraMatrix * light.SphereModelMatrix;
|
||||||
|
|
||||||
|
glUniform2fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ViewportSize"), 1,glm::value_ptr(glm::vec2(m_Width, m_Height)));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(light.SphereModelMatrix));
|
||||||
|
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ls"), 1, glm::value_ptr(light.Specular));
|
||||||
|
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ld"), 1, glm::value_ptr(light.Diffuse));
|
||||||
|
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "lp"), 1, glm::value_ptr(light.Position));
|
||||||
|
glUniform3f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "CameraPosition"), m_Camera->Position().x, m_Camera->Position().y, m_Camera->Position().z);
|
||||||
|
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "specularExponent"), light.SpecularExponent);
|
||||||
|
// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ConstantAttenuation"), light.ConstantAttenuation);
|
||||||
|
// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), light.LinearAttenuation);
|
||||||
|
// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), light.QuadraticAttenuation);
|
||||||
|
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ConstantAttenuation"), CAtt);
|
||||||
|
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), LAtt);
|
||||||
|
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), QAtt);
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
|
||||||
|
};
|
||||||
|
glEnable (GL_DEPTH_TEST);
|
||||||
|
glDepthMask (GL_TRUE);
|
||||||
|
glDisable (GL_BLEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::SetSphereModel( Model* _model )
|
||||||
|
{
|
||||||
|
m_sphereModel = _model;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::mat4 Renderer::CreateLightMatrix(Light &_light)
|
||||||
|
{
|
||||||
|
// float c = _light.ConstantAttenuation;
|
||||||
|
// float l = _light.LinearAttenuation;
|
||||||
|
// float q = _light.QuadraticAttenuation;
|
||||||
|
float c = CAtt;
|
||||||
|
float l = LAtt;
|
||||||
|
float q = QAtt;
|
||||||
|
float cutOffRadius = abs(sqrt((-4*c*q) + pow(l, 2) + (1024*q) - l) / (2*q));
|
||||||
|
|
||||||
|
glm::mat4 model;
|
||||||
|
model *= glm::translate(_light.Position);
|
||||||
|
model *= glm::scale(glm::vec3(cutOffRadius));
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+55
-13
@@ -12,6 +12,7 @@
|
|||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
#include "Components/PointLight.h"
|
#include "Components/PointLight.h"
|
||||||
#include "Skybox.h"
|
#include "Skybox.h"
|
||||||
|
#include "ResourceManager.h"
|
||||||
|
|
||||||
class Renderer
|
class Renderer
|
||||||
{
|
{
|
||||||
@@ -25,14 +26,7 @@ public:
|
|||||||
int Height() const { return m_Height; }
|
int Height() const { return m_Height; }
|
||||||
|
|
||||||
std::list<std::tuple<Model*, glm::mat4, bool, bool>> ModelsToRender;
|
std::list<std::tuple<Model*, glm::mat4, bool, bool>> ModelsToRender;
|
||||||
int Lights;
|
std::list<std::tuple<Texture*, glm::mat4, glm::mat4>> TexturesToRender;
|
||||||
std::vector<float> Light_position;
|
|
||||||
std::vector<float> Light_specular;
|
|
||||||
std::vector<float> Light_diffuse;
|
|
||||||
std::vector<float> Light_constantAttenuation;
|
|
||||||
std::vector<float> Light_linearAttenuation;
|
|
||||||
std::vector<float> Light_quadraticAttenuation;
|
|
||||||
std::vector<float> Light_spotExponent;
|
|
||||||
std::list<std::tuple<glm::mat4, bool>> AABBsToRender;
|
std::list<std::tuple<glm::mat4, bool>> AABBsToRender;
|
||||||
|
|
||||||
Renderer();
|
Renderer();
|
||||||
@@ -42,15 +36,16 @@ public:
|
|||||||
void DrawText();
|
void DrawText();
|
||||||
|
|
||||||
void AddModelToDraw(Model* model, glm::vec3 position, glm::quat orientation, glm::vec3 scale, bool visible, bool shadowCaster);
|
void AddModelToDraw(Model* model, glm::vec3 position, glm::quat orientation, glm::vec3 scale, bool visible, bool shadowCaster);
|
||||||
|
void AddTextureToDraw(Texture* texture, glm::vec3 position, glm::quat orientation, glm::vec3 scale);
|
||||||
void AddTextToDraw();
|
void AddTextToDraw();
|
||||||
void AddPointLightToDraw(
|
void AddPointLightToDraw(
|
||||||
glm::vec3 _position,
|
glm::vec3 _position,
|
||||||
glm::vec3 _specular,
|
glm::vec3 _specular,
|
||||||
glm::vec3 _diffuse,
|
glm::vec3 _diffuse,
|
||||||
float _constantAttenuation,
|
float _specularExponent,
|
||||||
float _linearAttenuation,
|
float _ConstantAttenuation,
|
||||||
float _quadraticAttenuation,
|
float _LinearAttenuation,
|
||||||
float _spotExponent
|
float _QuadraticAttenuation
|
||||||
);
|
);
|
||||||
void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding);
|
void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding);
|
||||||
|
|
||||||
@@ -67,8 +62,25 @@ public:
|
|||||||
void DrawBounds(bool val) { m_DrawBounds = val; }
|
void DrawBounds(bool val) { m_DrawBounds = val; }
|
||||||
void DrawSkybox();
|
void DrawSkybox();
|
||||||
|
|
||||||
|
void SetSphereModel(Model* _model);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_Width, m_Height;
|
int m_Width, m_Height;
|
||||||
|
|
||||||
|
struct Light
|
||||||
|
{
|
||||||
|
glm::vec3 Position;
|
||||||
|
glm::vec3 Specular;
|
||||||
|
glm::vec3 Diffuse;
|
||||||
|
float SpecularExponent;
|
||||||
|
glm::mat4 SphereModelMatrix;
|
||||||
|
float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation;
|
||||||
|
};
|
||||||
|
|
||||||
|
float Gamma;
|
||||||
|
|
||||||
|
std::list<Light> Lights;
|
||||||
|
|
||||||
GLFWwindow* m_Window;
|
GLFWwindow* m_Window;
|
||||||
GLint m_glVersion[2];
|
GLint m_glVersion[2];
|
||||||
GLchar* m_glVendor;
|
GLchar* m_glVendor;
|
||||||
@@ -76,6 +88,7 @@ private:
|
|||||||
bool m_DrawNormals;
|
bool m_DrawNormals;
|
||||||
bool m_DrawWireframe;
|
bool m_DrawWireframe;
|
||||||
bool m_DrawBounds;
|
bool m_DrawBounds;
|
||||||
|
float CAtt, LAtt, QAtt;
|
||||||
|
|
||||||
std::shared_ptr<Skybox> m_Skybox;
|
std::shared_ptr<Skybox> m_Skybox;
|
||||||
|
|
||||||
@@ -85,24 +98,53 @@ private:
|
|||||||
glm::mat4 m_SunProjection;
|
glm::mat4 m_SunProjection;
|
||||||
|
|
||||||
GLuint m_DebugAABB;
|
GLuint m_DebugAABB;
|
||||||
GLuint m_ScreenQuad;
|
|
||||||
GLuint m_ShadowFrameBuffer;
|
GLuint m_ShadowFrameBuffer;
|
||||||
GLuint m_ShadowDepthTexture;
|
GLuint m_ShadowDepthTexture;
|
||||||
|
|
||||||
|
GLuint m_fbBasePass;
|
||||||
|
GLuint m_fDiffuseTexture;
|
||||||
|
GLuint m_fPositionTexture;
|
||||||
|
GLuint m_fNormalsTexture;
|
||||||
|
GLuint m_fBlendTexture;
|
||||||
|
GLuint m_fbLightingPass;
|
||||||
|
GLuint m_fLightingTexture;
|
||||||
|
GLuint m_fShadowTexture;
|
||||||
|
|
||||||
|
GLuint m_fDepthBuffer;
|
||||||
|
GLenum draw_bufs[2];
|
||||||
|
GLuint m_ScreenQuad;
|
||||||
|
Model* m_sphereModel;
|
||||||
|
|
||||||
|
bool m_QuadView;
|
||||||
|
|
||||||
std::shared_ptr<Camera> m_Camera;
|
std::shared_ptr<Camera> m_Camera;
|
||||||
|
|
||||||
ShaderProgram m_ShaderProgram;
|
ShaderProgram m_ShaderProgram;
|
||||||
|
ShaderProgram m_FirstPassProgram;
|
||||||
|
ShaderProgram m_SecondPassProgram;
|
||||||
|
ShaderProgram m_SecondPassProgram_Debug;
|
||||||
|
ShaderProgram m_FinalPassProgram;
|
||||||
|
|
||||||
ShaderProgram m_ShaderProgramNormals;
|
ShaderProgram m_ShaderProgramNormals;
|
||||||
ShaderProgram m_ShaderProgramShadows;
|
ShaderProgram m_ShaderProgramShadows;
|
||||||
ShaderProgram m_ShaderProgramShadowsDrawDepth;
|
ShaderProgram m_ShaderProgramShadowsDrawDepth;
|
||||||
ShaderProgram m_ShaderProgramDebugAABB;
|
ShaderProgram m_ShaderProgramDebugAABB;
|
||||||
ShaderProgram m_ShaderProgramSkybox;
|
ShaderProgram m_ShaderProgramSkybox;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ClearStuff();
|
void ClearStuff();
|
||||||
void DrawScene();
|
void DrawScene();
|
||||||
void DrawModels(ShaderProgram &shader);
|
void DrawModels(ShaderProgram &shader);
|
||||||
void DrawShadowMap();
|
void DrawShadowMap();
|
||||||
void CreateShadowMap(int resolution);
|
void CreateShadowMap(int resolution);
|
||||||
|
void FrameBufferTextures();
|
||||||
|
void DrawFBO();
|
||||||
|
void DrawFBOScene();
|
||||||
|
void DrawLightScene();
|
||||||
|
void BindFragDataLocation();
|
||||||
|
glm::mat4 CreateLightMatrix(Light &_light);
|
||||||
|
|
||||||
GLuint CreateQuad();
|
GLuint CreateQuad();
|
||||||
void DrawDebugShadowMap();
|
void DrawDebugShadowMap();
|
||||||
GLuint CreateAABB();
|
GLuint CreateAABB();
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ Resource* ResourceManager::CreateResource(std::string resourceType, std::string
|
|||||||
resource->TypeID = GetTypeID(resourceType);
|
resource->TypeID = GetTypeID(resourceType);
|
||||||
resource->ResourceID = GetNewResourceID(resource->TypeID);
|
resource->ResourceID = GetNewResourceID(resource->TypeID);
|
||||||
// Cache
|
// Cache
|
||||||
m_ResourceCache[resourceName] = resource;
|
m_ResourceCache[std::make_pair(resourceType, resourceName)] = resource;
|
||||||
|
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ void ResourceManager::RegisterType(std::string resourceType, std::function<Resou
|
|||||||
|
|
||||||
void ResourceManager::Preload(std::string resourceType, std::string resourceName)
|
void ResourceManager::Preload(std::string resourceType, std::string resourceName)
|
||||||
{
|
{
|
||||||
if (IsResourceLoaded(resourceName))
|
if (IsResourceLoaded(resourceType, resourceName))
|
||||||
{
|
{
|
||||||
LOG_WARNING("Attempted to preload resource \"%s\" multiple times!", resourceName);
|
LOG_WARNING("Attempted to preload resource \"%s\" multiple times!", resourceName);
|
||||||
return;
|
return;
|
||||||
@@ -54,7 +54,7 @@ unsigned int ResourceManager::GetNewResourceID(unsigned int typeID)
|
|||||||
return m_ResourceCount[typeID]++;
|
return m_ResourceCount[typeID]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ResourceManager::IsResourceLoaded(std::string resourceName)
|
bool ResourceManager::IsResourceLoaded(std::string resourceType, std::string resourceName)
|
||||||
{
|
{
|
||||||
return m_ResourceCache.find(resourceName) != m_ResourceCache.end();
|
return m_ResourceCache.find(std::make_pair(resourceType, resourceName)) != m_ResourceCache.end();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include "Util/UnorderedMapPair.h"
|
||||||
#include "Factory.h"
|
#include "Factory.h"
|
||||||
|
|
||||||
class Resource
|
class Resource
|
||||||
@@ -28,7 +29,7 @@ public:
|
|||||||
void Preload(std::string resourceType, std::string resourceName);
|
void Preload(std::string resourceType, std::string resourceName);
|
||||||
|
|
||||||
// Checks if a resource is in cache
|
// Checks if a resource is in cache
|
||||||
bool IsResourceLoaded(std::string resourceName);
|
bool IsResourceLoaded(std::string resourceType, std::string resourceName);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
// Hot-loads a resource and caches it for future use
|
// Hot-loads a resource and caches it for future use
|
||||||
@@ -40,7 +41,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, std::function<Resource*(std::string)>> m_FactoryFunctions; // type -> factory function
|
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
|
std::unordered_map<std::pair<std::string, std::string>, Resource*> m_ResourceCache; // (type, name) -> resource
|
||||||
|
|
||||||
// TODO: Getters for IDs
|
// TODO: Getters for IDs
|
||||||
unsigned int m_CurrentResourceTypeID;
|
unsigned int m_CurrentResourceTypeID;
|
||||||
@@ -60,7 +61,7 @@ private:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
T* ResourceManager::Load(std::string resourceType, std::string resourceName)
|
T* ResourceManager::Load(std::string resourceType, std::string resourceName)
|
||||||
{
|
{
|
||||||
auto it = m_ResourceCache.find(resourceName);
|
auto it = m_ResourceCache.find(std::make_pair(resourceType, resourceName));
|
||||||
if (it != m_ResourceCache.end())
|
if (it != m_ResourceCache.end())
|
||||||
return static_cast<T*>(it->second);
|
return static_cast<T*>(it->second);
|
||||||
|
|
||||||
@@ -79,7 +80,7 @@ T* ResourceManager::Load(std::string resourceType, std::string resourceName)
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
T* ResourceManager::Fetch(std::string resourceName) const
|
T* ResourceManager::Fetch(std::string resourceName) const
|
||||||
{
|
{
|
||||||
auto it = m_ResourceCache.find(resourceName);
|
auto it = m_ResourceCache.find(std::make_pair(resourceType, resourceName));
|
||||||
if (it == m_ResourceCache.end())
|
if (it == m_ResourceCache.end())
|
||||||
{
|
{
|
||||||
LOG_ERROR("Failed to fetch resource \"%s\": Resource not loaded!", resourceName.c_str());
|
LOG_ERROR("Failed to fetch resource \"%s\": Resource not loaded!", resourceName.c_str());
|
||||||
|
|||||||
@@ -103,6 +103,11 @@ void ShaderProgram::AddShader(std::shared_ptr<Shader> shader)
|
|||||||
|
|
||||||
void ShaderProgram::Compile()
|
void ShaderProgram::Compile()
|
||||||
{
|
{
|
||||||
|
if (m_ShaderProgramHandle == 0)
|
||||||
|
{
|
||||||
|
m_ShaderProgramHandle = glCreateProgram();
|
||||||
|
}
|
||||||
|
|
||||||
for (auto &shader : m_Shaders)
|
for (auto &shader : m_Shaders)
|
||||||
{
|
{
|
||||||
if (!shader->IsCompiled())
|
if (!shader->IsCompiled())
|
||||||
@@ -121,7 +126,7 @@ GLuint ShaderProgram::Link()
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("Linking shader program");
|
LOG_INFO("Linking shader program");
|
||||||
m_ShaderProgramHandle = glCreateProgram();
|
|
||||||
for (auto &shader : m_Shaders)
|
for (auto &shader : m_Shaders)
|
||||||
{
|
{
|
||||||
glAttachShader(m_ShaderProgramHandle, shader->GetHandle());
|
glAttachShader(m_ShaderProgramHandle, shader->GetHandle());
|
||||||
|
|||||||
+1
-1
@@ -61,7 +61,7 @@ class ShaderProgram
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ShaderProgram()
|
ShaderProgram()
|
||||||
: m_ShaderProgramHandle(0) { }
|
: m_ShaderProgramHandle(0) { }
|
||||||
~ShaderProgram();
|
~ShaderProgram();
|
||||||
|
|
||||||
void AddShader(std::shared_ptr<Shader> shader);
|
void AddShader(std::shared_ptr<Shader> shader);
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#version 430
|
||||||
|
|
||||||
|
uniform vec3 La;
|
||||||
|
uniform float Gamma;
|
||||||
|
|
||||||
|
layout (binding=0) uniform sampler2D DiffuseTexture;
|
||||||
|
layout (binding=1) uniform sampler2D LightingTexture;
|
||||||
|
layout (binding=2) uniform sampler2D ShadowTexture;
|
||||||
|
|
||||||
|
in VertexData
|
||||||
|
{
|
||||||
|
vec3 Position;
|
||||||
|
vec2 TextureCoord;
|
||||||
|
} Input;
|
||||||
|
|
||||||
|
out vec4 FragmentColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 DiffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
|
||||||
|
vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord);
|
||||||
|
vec4 ShadowTexel = texture(ShadowTexture, Input.TextureCoord);
|
||||||
|
|
||||||
|
|
||||||
|
vec4 _FragmentColor = DiffuseTexel * vec4(La, 1.0) + LightingTexel;
|
||||||
|
FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
|
||||||
|
//FragmentColor = ShadowTexel;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#version 430
|
||||||
|
|
||||||
|
layout(location = 0) in vec3 Position;
|
||||||
|
|
||||||
|
out VertexData
|
||||||
|
{
|
||||||
|
vec3 Position;
|
||||||
|
vec2 TextureCoord;
|
||||||
|
} Output;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vec4(Position, 1.0);
|
||||||
|
Output.Position = Position;
|
||||||
|
Output.TextureCoord = (vec2(Position) + 1) / 2;
|
||||||
|
}
|
||||||
+26
-96
@@ -1,113 +1,43 @@
|
|||||||
#version 430
|
#version 430
|
||||||
|
|
||||||
uniform mat4 model;
|
layout (binding=0) uniform sampler2D DiffuseTexture;
|
||||||
uniform mat4 view;
|
layout (binding=1) uniform sampler2D ShadowTexture;
|
||||||
|
|
||||||
layout(binding=0) uniform sampler2D texture0;
|
|
||||||
layout(binding=1) uniform sampler2D shadowMap;
|
|
||||||
|
|
||||||
const int maxNumberOfLights = 82;
|
|
||||||
uniform int numberOfLights;
|
|
||||||
uniform vec3 position[maxNumberOfLights];
|
|
||||||
uniform vec3 specular[maxNumberOfLights];
|
|
||||||
uniform vec3 diffuse[maxNumberOfLights];
|
|
||||||
uniform float constantAttenuation[maxNumberOfLights];
|
|
||||||
uniform float linearAttenuation[maxNumberOfLights];
|
|
||||||
uniform float quadraticAttenuation[maxNumberOfLights];
|
|
||||||
uniform float spotExponent[maxNumberOfLights];
|
|
||||||
|
|
||||||
in VertexData
|
in VertexData
|
||||||
{
|
{
|
||||||
vec3 Position;
|
vec3 Position;
|
||||||
vec3 Normal;
|
vec3 Normal;
|
||||||
vec2 TextureCoord;
|
vec2 TextureCoord;
|
||||||
vec3 ShadowCoord;
|
vec4 ShadowCoord;
|
||||||
} Input;
|
} Input;
|
||||||
|
|
||||||
vec3 scene_ambient = vec3(0.5, 0.5, 0.5);
|
out vec4 frag_Diffuse;
|
||||||
|
out vec4 frag_Position;
|
||||||
|
out vec4 frag_Normal;
|
||||||
|
|
||||||
out vec4 fragmentColor;
|
float Shadow(vec4 ShadowCoord)
|
||||||
|
{
|
||||||
|
//float cosTheta = clamp(dot(Input.Normal, 1.0), 0.0, 1.0);
|
||||||
|
float bias = 0.0005; // cosTheta is dot( n,l ), clamped between 0 and 1
|
||||||
|
bias = clamp(bias, 0.0, 0.01);
|
||||||
|
if( texture(ShadowTexture, Input.ShadowCoord.xy).z < ShadowCoord.z - bias)
|
||||||
|
{
|
||||||
|
return 0.3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
// Diffuse Texture
|
||||||
|
frag_Diffuse = texture(DiffuseTexture, Input.TextureCoord) * Shadow(Input.ShadowCoord);
|
||||||
|
|
||||||
// Texture
|
// G-buffer Position
|
||||||
vec4 texel = texture2D(texture0, Input.TextureCoord);
|
frag_Position = vec4(Input.Position.xyz, 1.0);
|
||||||
//vec4 texel = (blend.x * texel0) + (blend.y * texel1) + (blend.z * texel2);
|
|
||||||
|
|
||||||
//
|
// G-buffer Normal
|
||||||
// Phong shading
|
frag_Normal = vec4(Input.Normal, 0.0);
|
||||||
//
|
|
||||||
|
|
||||||
// Ambient light
|
|
||||||
vec3 La = scene_ambient; // Ambient light
|
|
||||||
vec3 Ks = vec3(0.3, 0.3, 0.3); // Specular reflectance
|
|
||||||
vec3 Kd = vec3(1.0, 1.0, 1.0); // Diffuse reflectance
|
|
||||||
vec3 Ka = vec3(1.0, 1.0, 1.0); // Ambient reflectance
|
|
||||||
vec3 Is;
|
|
||||||
vec3 Id;
|
|
||||||
|
|
||||||
// Shadows
|
|
||||||
//float cosTheta = clamp(dot(Input.Normal, vec3(0, 1, 0)), 0.0, 1.0);
|
|
||||||
//float bias = 0.001 * tan(acos(cosTheta)); // cosTheta is dot( n,l ), clamped between 0 and 1
|
|
||||||
//bias = clamp(bias, 0.0, 0.01);
|
|
||||||
float visibility = 1.0;
|
|
||||||
/*if (Input.ShadowCoord.x >= 0.0 && Input.ShadowCoord.x <= 1.0 && Input.ShadowCoord.y >= 0.0 && Input.ShadowCoord.y <= 1.0)
|
|
||||||
{
|
|
||||||
float bias = 0.00005;
|
|
||||||
vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy);
|
|
||||||
if (shadowMapValue.z < clamp(Input.ShadowCoord.z - bias, 0, 1))
|
|
||||||
{
|
|
||||||
visibility = 0.3;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
vec3 totalLighting = La * Ka * visibility;
|
|
||||||
|
|
||||||
float attenuation;
|
|
||||||
|
|
||||||
for(int i = 0; i < numberOfLights && i < maxNumberOfLights; i++)
|
|
||||||
{
|
|
||||||
// Light
|
|
||||||
//vec3 lightPosition = vec3(0, 0, 2);
|
|
||||||
vec3 Ls = specular[i]; // Specular light
|
|
||||||
vec3 Ld = diffuse[i]; // Diffuse light
|
|
||||||
|
|
||||||
vec3 lightPosView = vec3(view * vec4(position[i], 1.0));
|
|
||||||
vec3 surfacePosition = vec3(model * vec4(Input.Position, 1.0));
|
|
||||||
vec3 surfacePosView = vec3(view * vec4(surfacePosition, 1.0));
|
|
||||||
vec3 surfaceToLight = normalize(lightPosView - surfacePosView);
|
|
||||||
mat3 normalMatrix = transpose(inverse(mat3(view * model)));
|
|
||||||
vec3 surfaceNormal = normalize(normalMatrix * Input.Normal);
|
|
||||||
|
|
||||||
float dist = length(position[i] - surfacePosition);
|
|
||||||
|
|
||||||
attenuation = 1.0 / (constantAttenuation[i]
|
|
||||||
+ linearAttenuation[i] * dist
|
|
||||||
+ quadraticAttenuation[i] * pow(dist, 2.0));
|
|
||||||
//attenuation = attenuation * pow(clampedCosine, spotExponent[i]);
|
|
||||||
|
|
||||||
// Diffuse light
|
|
||||||
float dotProd = dot(surfaceToLight, surfaceNormal);
|
|
||||||
dotProd = max(dotProd, 0.0);
|
|
||||||
|
|
||||||
Id = Ld * Kd * abs(dotProd) * attenuation;
|
|
||||||
|
|
||||||
// Specular light
|
|
||||||
vec3 reflection = reflect(-surfaceToLight, surfaceNormal);
|
|
||||||
float dotSpecular = dot(reflection, normalize(-surfacePosView));
|
|
||||||
dotSpecular = max(dotSpecular, 0.0);
|
|
||||||
float specularFactor = pow(dotSpecular, 30.0); // Specular factor
|
|
||||||
|
|
||||||
Is = attenuation * Ls * Ks * specularFactor;
|
|
||||||
|
|
||||||
totalLighting = totalLighting + Id + Is;
|
|
||||||
}
|
|
||||||
|
|
||||||
fragmentColor = vec4(totalLighting, 1.0) * texel;
|
|
||||||
|
|
||||||
|
|
||||||
//fragmentColor = vec4(Id, 1.0) * texel;
|
|
||||||
|
|
||||||
//fragmentColor = texel;
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#version 430
|
||||||
|
|
||||||
|
layout (binding=0) uniform sampler2D DiffuseTexture;
|
||||||
|
layout (binding=1) uniform sampler2D PositionTexture;
|
||||||
|
layout (binding=2) uniform sampler2D NormalTexture;
|
||||||
|
|
||||||
|
in VertexData
|
||||||
|
{
|
||||||
|
vec3 Position;
|
||||||
|
vec3 Normal;
|
||||||
|
vec2 TextureCoord;
|
||||||
|
} Input;
|
||||||
|
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
void DrawQuadrant(vec4 texel, vec2 quadrant)
|
||||||
|
{
|
||||||
|
if (-quadrant.x * Input.Position.x < 0 && -quadrant.y * Input.Position.y < 0)
|
||||||
|
{
|
||||||
|
FragColor = texel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 DiffuseTexel = texture2D(DiffuseTexture, Input.TextureCoord);
|
||||||
|
vec4 PositionTexel = texture2D(PositionTexture, Input.TextureCoord);
|
||||||
|
vec4 NormalTexel = texture2D(NormalTexture, Input.TextureCoord);
|
||||||
|
|
||||||
|
//FragColor = texture2D(DiffuseTexture, Input.TextureCoord * 2 + vec2(0, -1));
|
||||||
|
DrawQuadrant(texture2D(DiffuseTexture, Input.TextureCoord * 2), vec2(-1, 1));
|
||||||
|
DrawQuadrant(texture2D(PositionTexture, Input.TextureCoord * 2), vec2(1, 1));
|
||||||
|
DrawQuadrant(texture2D(NormalTexture, Input.TextureCoord * 2), vec2(-1, -1));
|
||||||
|
|
||||||
|
vec4 AllTexel = texture2D(DiffuseTexture, Input.TextureCoord*2)*texture2D(PositionTexture, Input.TextureCoord*2)*texture2D(NormalTexture, Input.TextureCoord*2);
|
||||||
|
DrawQuadrant(AllTexel, vec2(1, -1));
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
#version 430
|
||||||
|
|
||||||
|
layout (binding=0) uniform sampler2D PositionTexture;
|
||||||
|
layout (binding=1) uniform sampler2D NormalsTexture;
|
||||||
|
|
||||||
|
uniform vec2 ViewportSize;
|
||||||
|
uniform mat4 MVP;
|
||||||
|
uniform mat4 M;
|
||||||
|
uniform mat4 V;
|
||||||
|
uniform mat4 P;
|
||||||
|
uniform vec3 la;
|
||||||
|
uniform vec3 ls;
|
||||||
|
uniform vec3 ld;
|
||||||
|
uniform vec3 lp;
|
||||||
|
uniform float specularExponent;
|
||||||
|
uniform vec3 CameraPosition;
|
||||||
|
uniform float ConstantAttenuation;
|
||||||
|
uniform float LinearAttenuation;
|
||||||
|
uniform float QuadraticAttenuation;
|
||||||
|
|
||||||
|
const vec3 ks = vec3(1.0, 1.0, 1.0);
|
||||||
|
const vec3 kd = vec3(1.0, 1.0, 1.0);
|
||||||
|
const vec3 ka = vec3(1.0, 1.0, 1.0);
|
||||||
|
const float kshine = 1.0;
|
||||||
|
|
||||||
|
in VertexData
|
||||||
|
{
|
||||||
|
vec3 Position;
|
||||||
|
vec2 TextureCoord;
|
||||||
|
} Input;
|
||||||
|
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
vec4 phong(vec3 position, vec3 normal)
|
||||||
|
{
|
||||||
|
// Diffuse
|
||||||
|
vec3 lightPos = vec3(V * vec4(lp, 1.0));
|
||||||
|
vec3 distanceToLight = lightPos - position;
|
||||||
|
vec3 directionToLight = normalize(distanceToLight);
|
||||||
|
float dotProd = dot(directionToLight, normal);
|
||||||
|
dotProd = max(dotProd, 0.0);
|
||||||
|
vec3 Id = kd * ld * dotProd;
|
||||||
|
|
||||||
|
// Specular
|
||||||
|
//vec3 reflection = reflect(-directionToLight, normal);
|
||||||
|
vec3 surfaceToViewer = normalize(-position);
|
||||||
|
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
|
||||||
|
float dotSpecular = max(dot(halfWay, normal), 0.0);
|
||||||
|
float specularFactor = pow(dotSpecular, specularExponent * 2.0);
|
||||||
|
vec3 Is = ks * ls * specularFactor;
|
||||||
|
|
||||||
|
//Attenuation
|
||||||
|
float dist = distance(lightPos, position);
|
||||||
|
//float attenuation = -log(min(1.0, dist / LightRadius));
|
||||||
|
|
||||||
|
float attenuation = 1.0 / (ConstantAttenuation + (LinearAttenuation * dist) + (QuadraticAttenuation * dist * dist));
|
||||||
|
|
||||||
|
//float attenuation = 1.0 / (1.0 - 0.0001 * pow(dist, 2));
|
||||||
|
|
||||||
|
//float attenuation = clamp(0.0, 1.0, 1.0 / (0.001 + (0.001 * dist) + (0.001 * dist * dist)));
|
||||||
|
|
||||||
|
//float attenuation = 1.0 / dot(directionToLight, directionToLight);
|
||||||
|
|
||||||
|
//float att_s = 5;
|
||||||
|
//float attenuation = pow(dist, 2) / pow(5.0, 2);
|
||||||
|
//attenuation = 1.0 / (1.0 + attenuation * att_s);
|
||||||
|
//att_s = 1.0 / (1.0 + att_s);
|
||||||
|
//attenuation = attenuation / (1.0 - att_s);
|
||||||
|
|
||||||
|
//float radius = 5.0;
|
||||||
|
//float alpha = dist / radius;
|
||||||
|
//float dampingFactor = 1.0 - pow(alpha, 3);
|
||||||
|
|
||||||
|
return vec4((Id + Is) * attenuation, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 TextureCoord = gl_FragCoord.xy / ViewportSize;
|
||||||
|
vec4 PositionTexel = texture(PositionTexture, TextureCoord);
|
||||||
|
vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
|
||||||
|
|
||||||
|
FragColor = phong(vec3(PositionTexel), vec3(NormalTexel));
|
||||||
|
}
|
||||||
+10
-7
@@ -1,26 +1,29 @@
|
|||||||
#version 430
|
#version 430
|
||||||
|
|
||||||
uniform mat4 MVP;
|
uniform mat4 MVP;
|
||||||
|
uniform mat4 M;
|
||||||
|
uniform mat4 V;
|
||||||
|
uniform mat4 P;
|
||||||
uniform mat4 DepthMVP;
|
uniform mat4 DepthMVP;
|
||||||
|
|
||||||
layout(location = 0) in vec3 Position;
|
layout (location = 0) in vec3 Position;
|
||||||
layout(location = 1) in vec3 Normal;
|
layout (location = 1) in vec3 Normal;
|
||||||
layout(location = 2) in vec2 TextureCoord;
|
layout (location = 2) in vec2 TextureCoord;
|
||||||
|
|
||||||
out VertexData
|
out VertexData
|
||||||
{
|
{
|
||||||
vec3 Position;
|
vec3 Position;
|
||||||
vec3 Normal;
|
vec3 Normal;
|
||||||
vec2 TextureCoord;
|
vec2 TextureCoord;
|
||||||
vec3 ShadowCoord;
|
vec4 ShadowCoord;
|
||||||
} Output;
|
} Output;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = MVP * vec4(Position, 1.0);
|
gl_Position = MVP * vec4(Position, 1.0);
|
||||||
|
|
||||||
Output.Position = Position;
|
Output.Position = vec3(V * M * vec4(Position, 1.0));
|
||||||
Output.Normal = Normal;
|
Output.Normal = normalize(vec3(inverse(transpose(V * M)) * vec4(Normal, 0.0)));
|
||||||
Output.TextureCoord = TextureCoord;
|
Output.TextureCoord = TextureCoord;
|
||||||
Output.ShadowCoord = vec3(DepthMVP * vec4(Position, 1.0));
|
Output.ShadowCoord = DepthMVP * vec4(Position, 1.0);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#version 430
|
||||||
|
|
||||||
|
uniform mat4 MVP;
|
||||||
|
|
||||||
|
layout (location = 0) in vec3 Position;
|
||||||
|
layout (location = 2) in vec2 TextureCoord;
|
||||||
|
|
||||||
|
uniform mat4 depthBiasMVP;
|
||||||
|
|
||||||
|
out VertexData
|
||||||
|
{
|
||||||
|
vec3 Position;
|
||||||
|
vec2 TextureCoord;
|
||||||
|
} Output;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = MVP * vec4(Position, 1.0);
|
||||||
|
Output.Position = Position;
|
||||||
|
Output.TextureCoord = (vec2(Position) + 1.0) / 2.0;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#version 430
|
|
||||||
|
|
||||||
in vec2 TexCoord0;
|
|
||||||
in vec3 Normal0;
|
|
||||||
in vec3 WorldPos0;
|
|
||||||
|
|
||||||
layout (location = 0) out vec3 WorldPosOut;
|
|
||||||
layout (location = 1) out vec3 DiffuseOut;
|
|
||||||
layout (location = 2) out vec3 NormalOut;
|
|
||||||
layout (location = 3) out vec3 TexCoordOut;
|
|
||||||
|
|
||||||
uniform sampler2D gColorMap;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
WorldPosOut = WorldPos0;
|
|
||||||
DiffuseOut = texture(gColorMap, TexCoord0).xyz;
|
|
||||||
NormalOut = normalize(Normal0);
|
|
||||||
TexCoordOut = vec3(TexCoord0, 0.0);
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#version 430
|
|
||||||
|
|
||||||
layout (location = 0) in vec3 Position;
|
|
||||||
layout (location = 1) in vec2 TexCoord;
|
|
||||||
layout (location = 2) in vec3 Normal;
|
|
||||||
|
|
||||||
uniform mat4 gWVP;
|
|
||||||
uniform mat4 gWorld;
|
|
||||||
|
|
||||||
out vec2 TexCoord0;
|
|
||||||
out vec3 Normal0;
|
|
||||||
out vec3 WorldPos0;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = gWVP * vec4(Position, 1.0);
|
|
||||||
TexCoord0 = TexCoord;
|
|
||||||
Normal0 = (gWorld * vec4(Normal, 0.0)).xyz;
|
|
||||||
WorldPos0 = (gWorld * vec4(Position, 1.0)).xyz;
|
|
||||||
}
|
|
||||||
@@ -38,38 +38,38 @@ void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
|||||||
bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const Events::InputCommand &event)
|
bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||||
{
|
{
|
||||||
// Movement
|
// Movement
|
||||||
if (event.Command == "+forward")
|
if (event.Command == "+cam_forward")
|
||||||
{
|
{
|
||||||
Movement.z += -1.f;
|
Movement.z += -1.f;
|
||||||
}
|
}
|
||||||
else if (event.Command == "-forward")
|
else if (event.Command == "-cam_forward")
|
||||||
{
|
{
|
||||||
Movement.z -= -1.f;
|
Movement.z -= -1.f;
|
||||||
}
|
}
|
||||||
else if (event.Command == "+backward")
|
else if (event.Command == "+cam_backward")
|
||||||
{
|
{
|
||||||
Movement.z += 1.f;
|
Movement.z += 1.f;
|
||||||
}
|
}
|
||||||
else if (event.Command == "-backward")
|
else if (event.Command == "-cam_backward")
|
||||||
{
|
{
|
||||||
Movement.z -= 1.f;
|
Movement.z -= 1.f;
|
||||||
}
|
}
|
||||||
else if (event.Command == "+right")
|
else if (event.Command == "+cam_right")
|
||||||
{
|
|
||||||
Movement.x += 1.f;
|
|
||||||
}
|
|
||||||
else if (event.Command == "-right")
|
|
||||||
{
|
{
|
||||||
Movement.x -= 1.f;
|
Movement.x -= 1.f;
|
||||||
}
|
}
|
||||||
else if (event.Command == "+left")
|
else if (event.Command == "-cam_right")
|
||||||
{
|
{
|
||||||
Movement.x += -1.f;
|
Movement.x += 1.f;
|
||||||
}
|
}
|
||||||
else if (event.Command == "-left")
|
else if (event.Command == "+cam_left")
|
||||||
{
|
{
|
||||||
Movement.x -= -1.f;
|
Movement.x -= -1.f;
|
||||||
}
|
}
|
||||||
|
else if (event.Command == "-cam_left")
|
||||||
|
{
|
||||||
|
Movement.x += -1.f;
|
||||||
|
}
|
||||||
else if (event.Command == "+up")
|
else if (event.Command == "+up")
|
||||||
{
|
{
|
||||||
Movement.y += 1.f;
|
Movement.y += 1.f;
|
||||||
|
|||||||
+101
-15
@@ -10,12 +10,17 @@ void Systems::InputSystem::RegisterComponents(ComponentFactory* cf)
|
|||||||
void Systems::InputSystem::Initialize()
|
void Systems::InputSystem::Initialize()
|
||||||
{
|
{
|
||||||
// Subscribe to events
|
// Subscribe to events
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Systems::InputSystem::OnKeyDown)
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Systems::InputSystem::OnKeyDown);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Systems::InputSystem::OnKeyUp)
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Systems::InputSystem::OnKeyUp);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &Systems::InputSystem::OnMousePress)
|
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &Systems::InputSystem::OnMousePress);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &Systems::InputSystem::OnMouseRelease)
|
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &Systems::InputSystem::OnMouseRelease);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EBindKey, &Systems::InputSystem::OnBindKey)
|
EVENT_SUBSCRIBE_MEMBER(m_EGamepadAxis, &Systems::InputSystem::OnGamepadAxis);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EBindMouseButton, &Systems::InputSystem::OnBindMouseButton)
|
EVENT_SUBSCRIBE_MEMBER(m_EGamepadButtonDown, &Systems::InputSystem::OnGamepadButtonDown);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EGamepadButtonUp, &Systems::InputSystem::OnGamepadButtonUp);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EBindKey, &Systems::InputSystem::OnBindKey);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EBindMouseButton, &Systems::InputSystem::OnBindMouseButton);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EBindGamepadAxis, &Systems::InputSystem::OnBindGamepadAxis);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EBindGamepadButton, &Systems::InputSystem::OnBindGamepadButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::InputSystem::Update(double dt)
|
void Systems::InputSystem::Update(double dt)
|
||||||
@@ -44,7 +49,11 @@ bool Systems::InputSystem::OnKeyDown(const Events::KeyDown &event)
|
|||||||
auto bindingIt = m_KeyBindings.find(event.KeyCode);
|
auto bindingIt = m_KeyBindings.find(event.KeyCode);
|
||||||
if (bindingIt != m_KeyBindings.end())
|
if (bindingIt != m_KeyBindings.end())
|
||||||
{
|
{
|
||||||
PublishCommand(0, bindingIt->second, false);
|
std::string command;
|
||||||
|
float value;
|
||||||
|
std::tie(command, value) = bindingIt->second;
|
||||||
|
m_CommandValues[command] += value;
|
||||||
|
PublishCommand(0, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -55,7 +64,11 @@ bool Systems::InputSystem::OnKeyUp(const Events::KeyUp &event)
|
|||||||
auto bindingIt = m_KeyBindings.find(event.KeyCode);
|
auto bindingIt = m_KeyBindings.find(event.KeyCode);
|
||||||
if (bindingIt != m_KeyBindings.end())
|
if (bindingIt != m_KeyBindings.end())
|
||||||
{
|
{
|
||||||
PublishCommand(0, bindingIt->second, true);
|
std::string command;
|
||||||
|
float value;
|
||||||
|
std::tie(command, value) = bindingIt->second;
|
||||||
|
m_CommandValues[command] -= value;
|
||||||
|
PublishCommand(0, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -66,7 +79,7 @@ bool Systems::InputSystem::OnMousePress(const Events::MousePress &event)
|
|||||||
auto bindingIt = m_MouseButtonBindings.find(event.Button);
|
auto bindingIt = m_MouseButtonBindings.find(event.Button);
|
||||||
if (bindingIt != m_MouseButtonBindings.end())
|
if (bindingIt != m_MouseButtonBindings.end())
|
||||||
{
|
{
|
||||||
PublishCommand(0, bindingIt->second, false);
|
PublishCommand(0, bindingIt->second, 1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -77,12 +90,57 @@ bool Systems::InputSystem::OnMouseRelease(const Events::MouseRelease &event)
|
|||||||
auto bindingIt = m_MouseButtonBindings.find(event.Button);
|
auto bindingIt = m_MouseButtonBindings.find(event.Button);
|
||||||
if (bindingIt != m_MouseButtonBindings.end())
|
if (bindingIt != m_MouseButtonBindings.end())
|
||||||
{
|
{
|
||||||
PublishCommand(0, bindingIt->second, true);
|
PublishCommand(0, bindingIt->second, 1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Systems::InputSystem::OnGamepadAxis(const Events::GamepadAxis &event)
|
||||||
|
{
|
||||||
|
auto bindingIt = m_GamepadAxisBindings.find(event.Axis);
|
||||||
|
if (bindingIt != m_GamepadAxisBindings.end())
|
||||||
|
{
|
||||||
|
std::string command;
|
||||||
|
float value;
|
||||||
|
std::tie(command, value) = bindingIt->second;
|
||||||
|
PublishCommand(event.GamepadID + 1, command, event.Value * value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Systems::InputSystem::OnGamepadButtonDown(const Events::GamepadButtonDown &event)
|
||||||
|
{
|
||||||
|
auto bindingIt = m_GamepadButtonBindings.find(event.Button);
|
||||||
|
if (bindingIt != m_GamepadButtonBindings.end())
|
||||||
|
{
|
||||||
|
std::string command;
|
||||||
|
float value;
|
||||||
|
std::tie(command, value) = bindingIt->second;
|
||||||
|
m_CommandValues[command] += value;
|
||||||
|
PublishCommand(event.GamepadID + 1, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Systems::InputSystem::OnGamepadButtonUp(const Events::GamepadButtonUp &event)
|
||||||
|
{
|
||||||
|
auto bindingIt = m_GamepadButtonBindings.find(event.Button);
|
||||||
|
if (bindingIt != m_GamepadButtonBindings.end())
|
||||||
|
{
|
||||||
|
std::string command;
|
||||||
|
float value;
|
||||||
|
std::tie(command, value) = bindingIt->second;
|
||||||
|
m_CommandValues[command] -= value;
|
||||||
|
PublishCommand(event.GamepadID + 1, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Systems::InputSystem::OnBindKey(const Events::BindKey &event)
|
bool Systems::InputSystem::OnBindKey(const Events::BindKey &event)
|
||||||
{
|
{
|
||||||
if (event.Command.empty())
|
if (event.Command.empty())
|
||||||
@@ -91,7 +149,7 @@ bool Systems::InputSystem::OnBindKey(const Events::BindKey &event)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_KeyBindings[event.KeyCode] = event.Command;
|
m_KeyBindings[event.KeyCode] = std::make_tuple(event.Command, event.Value);
|
||||||
LOG_DEBUG("Input: Bound key %c to %s", (char)event.KeyCode, event.Command.c_str());
|
LOG_DEBUG("Input: Bound key %c to %s", (char)event.KeyCode, event.Command.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,17 +171,45 @@ bool Systems::InputSystem::OnBindMouseButton(const Events::BindMouseButton &even
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::InputSystem::PublishCommand(int playerID, std::string command, bool release /*= false*/)
|
bool Systems::InputSystem::OnBindGamepadAxis(const Events::BindGamepadAxis &event)
|
||||||
{
|
{
|
||||||
if (release && command.at(0) == '+')
|
if (event.Command.empty())
|
||||||
{
|
{
|
||||||
command[0] = '-';
|
m_GamepadAxisBindings.erase(event.Axis);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_GamepadAxisBindings[event.Axis] = std::make_tuple(event.Command, event.Value);
|
||||||
|
LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Axis, event.Command.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Systems::InputSystem::OnBindGamepadButton(const Events::BindGamepadButton &event)
|
||||||
|
{
|
||||||
|
if (event.Command.empty())
|
||||||
|
{
|
||||||
|
m_GamepadButtonBindings.erase(event.Button);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_GamepadButtonBindings[event.Button] = std::make_tuple(event.Command, event.Value);
|
||||||
|
LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Button, event.Command.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::InputSystem::PublishCommand(int playerID, std::string command, float value)
|
||||||
|
{
|
||||||
Events::InputCommand e;
|
Events::InputCommand e;
|
||||||
e.PlayerID = playerID;
|
e.PlayerID = playerID;
|
||||||
e.Command = command;
|
e.Command = command;
|
||||||
|
e.Value = value;
|
||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
|
|
||||||
LOG_DEBUG("Input: Published command %s for player %i", e.Command.c_str(), playerID);
|
LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, playerID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <boost/any.hpp>
|
||||||
|
|
||||||
#include "System.h"
|
#include "System.h"
|
||||||
#include "Components/Input.h"
|
#include "Components/Input.h"
|
||||||
@@ -10,8 +11,12 @@
|
|||||||
#include "Events/KeyDown.h"
|
#include "Events/KeyDown.h"
|
||||||
#include "Events/MousePress.h"
|
#include "Events/MousePress.h"
|
||||||
#include "Events/MouseRelease.h"
|
#include "Events/MouseRelease.h"
|
||||||
|
#include "Events/GamepadAxis.h"
|
||||||
|
#include "Events/GamepadButton.h"
|
||||||
#include "Events/BindKey.h"
|
#include "Events/BindKey.h"
|
||||||
#include "Events/BindMouseButton.h"
|
#include "Events/BindMouseButton.h"
|
||||||
|
#include "Events/BindGamepadAxis.h"
|
||||||
|
#include "Events/BindGamepadButton.h"
|
||||||
#include "Events/InputCommand.h"
|
#include "Events/InputCommand.h"
|
||||||
|
|
||||||
namespace Systems
|
namespace Systems
|
||||||
@@ -29,9 +34,12 @@ public:
|
|||||||
void Update(double dt) override;
|
void Update(double dt) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::unordered_map<std::string, float> m_CommandValues; // command string -> command current value
|
||||||
// Input binding tables
|
// Input binding tables
|
||||||
std::unordered_map<int, std::string> m_KeyBindings; // GLFW_KEY... -> command string
|
std::unordered_map<int, std::tuple<std::string, float>> m_KeyBindings; // GLFW_KEY... -> command string & value
|
||||||
std::unordered_map<int, std::string> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string
|
std::unordered_map<int, std::string> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string
|
||||||
|
std::unordered_map<Gamepad::Axis, std::tuple<std::string, float>> m_GamepadAxisBindings; // Gamepad::Axis -> command string & value
|
||||||
|
std::unordered_map<Gamepad::Button, std::tuple<std::string, float>> m_GamepadButtonBindings; // Gamepad::Button -> command string
|
||||||
|
|
||||||
// Input events
|
// Input events
|
||||||
EventRelay<Events::KeyDown> m_EKeyDown;
|
EventRelay<Events::KeyDown> m_EKeyDown;
|
||||||
@@ -42,13 +50,23 @@ private:
|
|||||||
bool OnMousePress(const Events::MousePress &event);
|
bool OnMousePress(const Events::MousePress &event);
|
||||||
EventRelay<Events::MouseRelease> m_EMouseRelease;
|
EventRelay<Events::MouseRelease> m_EMouseRelease;
|
||||||
bool OnMouseRelease(const Events::MouseRelease &event);
|
bool OnMouseRelease(const Events::MouseRelease &event);
|
||||||
|
EventRelay<Events::GamepadAxis> m_EGamepadAxis;
|
||||||
|
bool OnGamepadAxis(const Events::GamepadAxis &event);
|
||||||
|
EventRelay<Events::GamepadButtonDown> m_EGamepadButtonDown;
|
||||||
|
bool OnGamepadButtonDown(const Events::GamepadButtonDown &event);
|
||||||
|
EventRelay<Events::GamepadButtonUp> m_EGamepadButtonUp;
|
||||||
|
bool OnGamepadButtonUp(const Events::GamepadButtonUp &event);
|
||||||
// Input binding events
|
// Input binding events
|
||||||
EventRelay<Events::BindKey> m_EBindKey;
|
EventRelay<Events::BindKey> m_EBindKey;
|
||||||
bool OnBindKey(const Events::BindKey &event);
|
bool OnBindKey(const Events::BindKey &event);
|
||||||
EventRelay<Events::BindMouseButton> m_EBindMouseButton;
|
EventRelay<Events::BindMouseButton> m_EBindMouseButton;
|
||||||
bool OnBindMouseButton(const Events::BindMouseButton &event);
|
bool OnBindMouseButton(const Events::BindMouseButton &event);
|
||||||
|
EventRelay<Events::BindGamepadAxis> m_EBindGamepadAxis;
|
||||||
|
bool OnBindGamepadAxis(const Events::BindGamepadAxis &event);
|
||||||
|
EventRelay<Events::BindGamepadButton> m_EBindGamepadButton;
|
||||||
|
bool OnBindGamepadButton(const Events::BindGamepadButton &event);
|
||||||
|
|
||||||
void PublishCommand(int playerID, std::string command, bool release = false);
|
void PublishCommand(int playerID, std::string command, float value);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,208 @@
|
|||||||
|
#include "PrecompiledHeader.h"
|
||||||
|
#include "ParticleSystem.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "World.h"
|
||||||
|
|
||||||
|
void Systems::ParticleSystem::Initialize()
|
||||||
|
{
|
||||||
|
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>("TransformSystem");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::ParticleSystem::Update(double dt)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||||
|
{
|
||||||
|
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||||
|
if(!transformComponent)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto emitterComponent = m_World->GetComponent<Components::ParticleEmitter>(entity, "ParticleEmitter");
|
||||||
|
if(emitterComponent)
|
||||||
|
{
|
||||||
|
emitterComponent->TimeSinceLastSpawn += dt;
|
||||||
|
auto emitterTransformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||||
|
if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency)
|
||||||
|
{
|
||||||
|
SpawnParticles(entity);
|
||||||
|
emitterComponent->TimeSinceLastSpawn = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<ParticleData>::iterator it;
|
||||||
|
for(it = m_ParticleEmitter[entity].begin(); it != m_ParticleEmitter[entity].end();)
|
||||||
|
{
|
||||||
|
EntityID particleID = (it)->ParticleID;
|
||||||
|
auto transformComponent = m_World->GetComponent<Components::Transform>(particleID, "Transform");
|
||||||
|
auto particleComponent = m_World->GetComponent<Components::Particle>(particleID, "Particle");
|
||||||
|
|
||||||
|
double timeLived = glfwGetTime() - it->SpawnTime;
|
||||||
|
if(timeLived > particleComponent->LifeTime)
|
||||||
|
{
|
||||||
|
m_World->RemoveEntity(particleID);
|
||||||
|
it = m_ParticleEmitter[entity].erase(it);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// FIX: calculate once
|
||||||
|
float timeProgress = timeLived / particleComponent->LifeTime;
|
||||||
|
// ColorInterpolation(timeProgress, particleComponent->ColorSpectrum, color);
|
||||||
|
// Scale interpolation
|
||||||
|
if(particleComponent->ScaleSpectrum.size() > 1)
|
||||||
|
VectorInterpolation(timeProgress, particleComponent->ScaleSpectrum, transformComponent->Scale);
|
||||||
|
// Velocity interpolation
|
||||||
|
if(particleComponent->VelocitySpectrum.size() > 1)
|
||||||
|
VectorInterpolation(timeProgress, particleComponent->VelocitySpectrum, transformComponent->Velocity);
|
||||||
|
|
||||||
|
// Angular velocity interpolation
|
||||||
|
if (particleComponent->AngularVelocitySpectrum.size() != 0)
|
||||||
|
{
|
||||||
|
if(particleComponent->AngularVelocitySpectrum.size() > 1)
|
||||||
|
{
|
||||||
|
ScalarInterpolation(timeProgress, particleComponent->AngularVelocitySpectrum, it->AngularVelocity);
|
||||||
|
transformComponent->Orientation = glm::angleAxis(it->AngularVelocity, it->Orientation);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
transformComponent->Orientation *= glm::angleAxis(it->AngularVelocity, it->Orientation);
|
||||||
|
//it->Orientation = glm::angleAxis(it->AngularVelocity, it->Orientation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Angular velocity interpolation
|
||||||
|
if(particleComponent->OrientationSpectrum.size() > 1)
|
||||||
|
{
|
||||||
|
VectorInterpolation(timeProgress, particleComponent->OrientationSpectrum, it->Orientation);
|
||||||
|
glm::vec3 v1 = (particleComponent->OrientationSpectrum[0]);
|
||||||
|
glm::vec3 v2 = (it->Orientation);
|
||||||
|
glm::vec3 v3 = glm::normalize(glm::cross(v1,v2));
|
||||||
|
float angle = glm::acos(glm::dot(v1, v2) / (glm::length(v1) * glm::length(v2)));
|
||||||
|
|
||||||
|
transformComponent->Orientation = glm::angleAxis(angle, v3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
transformComponent->Position += transformComponent->Velocity * (float)dt;
|
||||||
|
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::ParticleSystem::RegisterComponents(ComponentFactory* cf)
|
||||||
|
{
|
||||||
|
cf->Register("ParticleEmitter", []() { return new Components::ParticleEmitter(); });
|
||||||
|
cf->Register("Particle", []() { return new Components::Particle(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
|
||||||
|
{
|
||||||
|
auto emitterComponent = m_World->GetComponent<Components::ParticleEmitter>(emitterID, "ParticleEmitter");
|
||||||
|
auto emitterTransform = m_World->GetComponent<Components::Transform>(emitterID, "Transform");
|
||||||
|
glm::vec3 emitterPos = m_TransformSystem->AbsolutePosition(emitterID);
|
||||||
|
glm::quat emitterOrientation = emitterTransform->Orientation;
|
||||||
|
|
||||||
|
float tempSpeed = 4;
|
||||||
|
glm::vec3 speed = glm::vec3(tempSpeed);
|
||||||
|
|
||||||
|
for(int i = 0; i < emitterComponent->SpawnCount; i++)
|
||||||
|
{
|
||||||
|
auto ent = m_World->CloneEntity(emitterComponent->ParticleTemplate);
|
||||||
|
|
||||||
|
auto particleTransform = m_World->GetComponent<Components::Transform>(ent, "Transform");
|
||||||
|
particleTransform->Position = emitterPos;
|
||||||
|
|
||||||
|
particleTransform->Orientation = emitterOrientation;
|
||||||
|
//The emitter's orientation as "start value" times the default direction for emitter. Times the speed, and then rotate on x and y axis with the randomized spread angle.
|
||||||
|
float spreadAngle = emitterComponent->SpreadAngle;
|
||||||
|
particleTransform->Velocity = emitterOrientation * glm::vec3(0, 0, -1) * speed *
|
||||||
|
glm::normalize(glm::angleAxis(RandomizeAngle(spreadAngle), glm::vec3(1, 0, 0))) *
|
||||||
|
glm::normalize(glm::angleAxis(RandomizeAngle(spreadAngle), glm::vec3(0, 1, 0))) *
|
||||||
|
glm::normalize(glm::angleAxis(RandomizeAngle(spreadAngle), glm::vec3(0, 0, 1)));
|
||||||
|
|
||||||
|
auto particle = m_World->AddComponent<Components::Particle>(ent, "Particle");
|
||||||
|
particle->LifeTime = emitterComponent->LifeTime;
|
||||||
|
particle->ScaleSpectrum = emitterComponent->ScaleSpectrum;
|
||||||
|
particle->VelocitySpectrum.push_back(particleTransform->Velocity);
|
||||||
|
|
||||||
|
if (emitterComponent->ScaleSpectrum.size() > 0)
|
||||||
|
{
|
||||||
|
if (emitterComponent->ScaleSpectrum.size() > 1)
|
||||||
|
{
|
||||||
|
particle->ScaleSpectrum = emitterComponent->ScaleSpectrum;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
particleTransform->Scale = emitterComponent->ScaleSpectrum[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
particleTransform->Scale = glm::vec3(1, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(emitterComponent->UseGoalVelocity)
|
||||||
|
particle->VelocitySpectrum.push_back(emitterComponent->GoalVelocity);
|
||||||
|
particle->OrientationSpectrum = emitterComponent->OrientationSpectrum;
|
||||||
|
if(particle->OrientationSpectrum.size() != 0)
|
||||||
|
particleTransform->Orientation = glm::angleAxis(0.f, particle->OrientationSpectrum[0]);
|
||||||
|
particle->AngularVelocitySpectrum = emitterComponent->AngularVelocitySpectrum;
|
||||||
|
|
||||||
|
|
||||||
|
ParticleData data;
|
||||||
|
data.ParticleID = ent;
|
||||||
|
data.SpawnTime = glfwGetTime();
|
||||||
|
if (particle->AngularVelocitySpectrum.size() != 0)
|
||||||
|
data.AngularVelocity = particle->AngularVelocitySpectrum[0];
|
||||||
|
if (particle->OrientationSpectrum.size() != 0)
|
||||||
|
data.Orientation = particle->OrientationSpectrum[0];
|
||||||
|
else data.Orientation = emitterOrientation * glm::vec3(0,0,-1);
|
||||||
|
|
||||||
|
m_ParticleEmitter[emitterID].push_back(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Randomizes between -spreadAngle/2 and spreadAngle/2
|
||||||
|
float Systems::ParticleSystem::RandomizeAngle(float spreadAngle)
|
||||||
|
{
|
||||||
|
return ((float)rand() / ((float)RAND_MAX + 1) * spreadAngle) - spreadAngle/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Interpolates the velocity of the particle
|
||||||
|
void Systems::ParticleSystem::VectorInterpolation(double timeProgress, std::vector<glm::vec3> spectrum, glm::vec3 &v)
|
||||||
|
{
|
||||||
|
float dAxisValue = glm::abs(spectrum[0].x - spectrum[1].x);
|
||||||
|
if(spectrum[0].x > spectrum[1].x)
|
||||||
|
dAxisValue *= -1;
|
||||||
|
v.x = spectrum[0].x + dAxisValue * timeProgress;
|
||||||
|
dAxisValue = glm::abs(spectrum[0].y - spectrum[1].y);
|
||||||
|
if (spectrum[0].y > spectrum[1].y)
|
||||||
|
dAxisValue *= -1;
|
||||||
|
v.y = spectrum[0].y + dAxisValue * timeProgress;
|
||||||
|
dAxisValue = glm::abs(spectrum[0].z - spectrum[1].z);
|
||||||
|
if(spectrum[0].z > spectrum[1].z)
|
||||||
|
dAxisValue *= -1;
|
||||||
|
v.z = spectrum[0].z + dAxisValue * timeProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
// void Systems::ParticleSystem::ColorInterpolation(double timeProgress, std::vector<Color> spectrum, Color &c)
|
||||||
|
// {
|
||||||
|
// float dColor = glm::abs(spectrum[0].r - spectrum[1].r);
|
||||||
|
// c.r = spectrum[0].r + dColor * timeProgress;
|
||||||
|
// dColor = glm::abs(spectrum[0].g - spectrum[1].g);
|
||||||
|
// c.g = spectrum[0].g + dColor * timeProgress;
|
||||||
|
// dColor = glm::abs(spectrum[0].b - spectrum[1].b);
|
||||||
|
// c.b = spectrum[0].b + dColor * timeProgress;
|
||||||
|
// }
|
||||||
|
|
||||||
|
void Systems::ParticleSystem::ScalarInterpolation(double timeProgress, std::vector<float> spectrum, float &alpha)
|
||||||
|
{
|
||||||
|
float dAlpha = glm::abs(spectrum[0] - spectrum[1]);
|
||||||
|
if(spectrum[0] > spectrum[1])
|
||||||
|
dAlpha *= -1;
|
||||||
|
alpha = spectrum[0] + dAlpha * timeProgress;
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
#ifndef ParticleSystem_h__
|
||||||
|
#define ParticleSystem_h__
|
||||||
|
|
||||||
|
#include "System.h"
|
||||||
|
#include "Systems/TransformSystem.h"
|
||||||
|
#include "Components/Transform.h"
|
||||||
|
#include "Components/ParticleEmitter.h"
|
||||||
|
#include "Components/Particle.h"
|
||||||
|
#include "Components/Model.h"
|
||||||
|
#include "Components/PointLight.h"
|
||||||
|
#include "Color.h"
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
namespace Systems
|
||||||
|
{
|
||||||
|
|
||||||
|
struct ParticleData
|
||||||
|
{
|
||||||
|
EntityID ParticleID;
|
||||||
|
double SpawnTime;
|
||||||
|
float AngularVelocity;
|
||||||
|
glm::vec3 Orientation;
|
||||||
|
Color color;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ParticleSystem : public System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ParticleSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||||
|
: System(world, eventBroker) { }
|
||||||
|
|
||||||
|
void RegisterComponents(ComponentFactory* cf) override;
|
||||||
|
void Update(double dt) override;
|
||||||
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
void Initialize() override;
|
||||||
|
private:
|
||||||
|
void SpawnParticles(EntityID emitterID);
|
||||||
|
float RandomizeAngle(float spreadAngle);
|
||||||
|
//void ScaleInterpolation(double timeProgress, std::vector<float> spectrum, glm::vec3 &scale);
|
||||||
|
void VectorInterpolation(double timeProgress, std::vector<glm::vec3> spectrum, glm::vec3 &velocity);
|
||||||
|
//void ColorInterpolation(double timeProgress, std::vector<Color> spectrum, Color &color);
|
||||||
|
void ScalarInterpolation(double timeProgress, std::vector<float> spectrum, float &alpha);
|
||||||
|
void Billboard();
|
||||||
|
std::map<EntityID, std::list<ParticleData>> m_ParticleEmitter;
|
||||||
|
std::map<EntityID, double> m_TimeSinceLastSpawn;
|
||||||
|
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // !ParticleSystem_h__
|
||||||
+390
-225
@@ -28,45 +28,94 @@
|
|||||||
void Systems::PhysicsSystem::Initialize()
|
void Systems::PhysicsSystem::Initialize()
|
||||||
{
|
{
|
||||||
m_Accumulator = 0;
|
m_Accumulator = 0;
|
||||||
|
|
||||||
|
// Events
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_ESetVelocity, &Systems::PhysicsSystem::OnSetVelocity);
|
||||||
|
|
||||||
|
hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer
|
||||||
|
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
|
||||||
|
hkBaseSystem::init(memoryRouter, HavokErrorReport);
|
||||||
|
|
||||||
|
|
||||||
|
// Get the number of physical threads available on the system
|
||||||
|
hkHardwareInfo hwInfo;
|
||||||
|
hkGetHardwareInfo(hwInfo);
|
||||||
|
m_TotalNumThreadsUsed = hwInfo.m_numThreads;
|
||||||
|
|
||||||
|
// We use one less than this for our thread pool, because we must also use this thread for our simulation
|
||||||
|
hkCpuJobThreadPoolCinfo threadPoolCinfo;
|
||||||
|
threadPoolCinfo.m_numThreads = m_TotalNumThreadsUsed - 1;
|
||||||
|
|
||||||
|
// This line enables timers collection, by allocating 200 Kb per thread. If you leave this at its default (0),
|
||||||
|
// timer collection will not be enabled.
|
||||||
|
threadPoolCinfo.m_timerBufferPerThreadAllocation = 200000;
|
||||||
|
m_ThreadPool = new hkCpuJobThreadPool(threadPoolCinfo);
|
||||||
|
|
||||||
|
hkJobQueueCinfo info;
|
||||||
|
info.m_jobQueueHwSetup.m_numCpuThreads = m_TotalNumThreadsUsed;
|
||||||
|
m_JobQueue = new hkJobQueue(info);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Enable monitors for this thread.
|
||||||
|
//
|
||||||
|
|
||||||
|
// Monitors have been enabled for thread pool threads already (see above comment).
|
||||||
|
hkMonitorStream::getInstance().resize(200000);
|
||||||
|
|
||||||
{
|
{
|
||||||
hkMemorySystem::FrameInfo finfo(500 * 1024); // Allocate 500KB of Physics solver buffer
|
|
||||||
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
|
|
||||||
hkBaseSystem::init(memoryRouter, HavokErrorReport);
|
|
||||||
|
|
||||||
|
|
||||||
hkpWorldCinfo worldInfo;
|
hkpWorldCinfo worldInfo;
|
||||||
|
|
||||||
|
// Set the simulation type of the world to multi-threaded.
|
||||||
|
worldInfo.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED;
|
||||||
|
|
||||||
worldInfo.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM);
|
worldInfo.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM);
|
||||||
worldInfo.m_gravity = hkVector4(0.0f, -9.8f, 0.0f);
|
worldInfo.m_gravity = hkVector4(0.0f, -9.82f, 0.0f);
|
||||||
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY; // just fix the entity if the object falls off too far
|
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY; // just fix the entity if the object falls off too far
|
||||||
|
|
||||||
// You must specify the size of the broad phase - objects should not be simulated outside this region
|
// You must specify the size of the broad phase - objects should not be simulated outside this region
|
||||||
worldInfo.setBroadPhaseWorldSize(1000.0f);
|
worldInfo.setBroadPhaseWorldSize(1000.0f);
|
||||||
m_PhysicsWorld = new hkpWorld(worldInfo);
|
m_PhysicsWorld = new hkpWorld(worldInfo);
|
||||||
|
|
||||||
|
// When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks
|
||||||
|
// to make sure only one thread is modifying the world at once to prevent multithreaded bugs. Each thread
|
||||||
|
// must call markForRead / markForWrite before it modifies the world to enable these checks.
|
||||||
|
m_PhysicsWorld->markForWrite();
|
||||||
|
|
||||||
|
// Register all collision agents, even though only box - box will be used in this particular example.
|
||||||
|
// It's important to register collision agents before adding any entities to the world.
|
||||||
|
hkpAgentRegisterUtil::registerAllAgents(m_PhysicsWorld->getCollisionDispatcher());
|
||||||
|
|
||||||
|
// We need to register all modules we will be running multi-threaded with the job queue
|
||||||
|
m_PhysicsWorld->registerWithJobQueue(m_JobQueue);
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialize the visual debugger so we can connect remotely to the simulation
|
||||||
|
// The context must exist beyond the use of the VDB instance, and you can make
|
||||||
|
// whatever contexts you like for your own viewer types.
|
||||||
|
//
|
||||||
|
m_Context = new hkpPhysicsContext;
|
||||||
|
hkpPhysicsContext::registerAllPhysicsProcesses(); // all the physics viewers
|
||||||
|
m_Context->addWorld(m_PhysicsWorld); // add the physics world so the viewers can see it
|
||||||
|
|
||||||
|
SetupVisualDebugger(m_Context);
|
||||||
|
|
||||||
|
m_PhysicsWorld->unmarkForWrite();
|
||||||
}
|
}
|
||||||
// Register all collision agents, even though only box - box will be used in this particular example.
|
|
||||||
// It's important to register collision agents before adding any entities to the world.
|
|
||||||
hkpAgentRegisterUtil::registerAllAgents(m_PhysicsWorld->getCollisionDispatcher());
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialize the visual debugger so we can connect remotely to the simulation
|
|
||||||
// The context must exist beyond the use of the VDB instance, and you can make
|
|
||||||
// whatever contexts you like for your own viewer types.
|
|
||||||
//
|
|
||||||
hkpPhysicsContext* context = new hkpPhysicsContext;
|
|
||||||
hkpPhysicsContext::registerAllPhysicsProcesses(); // all the physics viewers
|
|
||||||
context->addWorld(m_PhysicsWorld); // add the physics world so the viewers can see it
|
|
||||||
SetupVisualDebugger(context);
|
|
||||||
|
|
||||||
//SetupPhysics(m_PhysicsWorld);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
|
void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
|
||||||
{
|
{
|
||||||
cf->Register("Physics", []() { return new Components::Physics(); });
|
cf->Register("Physics", []() { return new Components::Physics(); });
|
||||||
cf->Register("Box", []() { return new Components::Box(); });
|
cf->Register("BoxShape", []() { return new Components::BoxShape(); });
|
||||||
cf->Register("Sphere", []() { return new Components::Sphere(); });
|
cf->Register("SphereShape", []() { return new Components::SphereShape(); });
|
||||||
cf->Register("Vehicle", []() { return new Components::Vehicle(); });
|
cf->Register("Vehicle", []() { return new Components::Vehicle(); });
|
||||||
cf->Register("Wheel", []() { return new Components::Wheel(); });
|
cf->Register("Wheel", []() { return new Components::Wheel(); });
|
||||||
|
cf->Register("MeshShape", []() { return new Components::MeshShape(); });
|
||||||
|
cf->Register("HingeConstraint", []() { return new Components::HingeConstraint(); });
|
||||||
|
cf->Register("WheelPair", []() { return new Components::WheelPair(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::PhysicsSystem::Update(double dt)
|
void Systems::PhysicsSystem::Update(double dt)
|
||||||
@@ -74,6 +123,7 @@ void Systems::PhysicsSystem::Update(double dt)
|
|||||||
for (auto pair : *m_World->GetEntities())
|
for (auto pair : *m_World->GetEntities())
|
||||||
{
|
{
|
||||||
EntityID entity = pair.first;
|
EntityID entity = pair.first;
|
||||||
|
EntityID parent = pair.second;
|
||||||
|
|
||||||
if (m_RigidBodies.find(entity) == m_RigidBodies.end())
|
if (m_RigidBodies.find(entity) == m_RigidBodies.end())
|
||||||
continue;
|
continue;
|
||||||
@@ -82,29 +132,50 @@ void Systems::PhysicsSystem::Update(double dt)
|
|||||||
if (!transformComponent)
|
if (!transformComponent)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
if(m_RigidBodies[entity]->isActive())
|
if(m_RigidBodies[entity]->isActive())
|
||||||
{
|
{
|
||||||
hkVector4 position(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z);
|
hkVector4 position;
|
||||||
hkQuaternion rotation(transformComponent->Orientation.x, transformComponent->Orientation.y, transformComponent->Orientation.z, transformComponent->Orientation.w);
|
hkQuaternion rotation;
|
||||||
|
|
||||||
|
if (parent)
|
||||||
|
{
|
||||||
|
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
|
||||||
|
position = ConvertPosition(absoluteTransform.Position);
|
||||||
|
rotation = ConvertRotation(absoluteTransform.Orientation);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
position = ConvertPosition(transformComponent->Position);
|
||||||
|
rotation = ConvertRotation(transformComponent->Orientation);
|
||||||
|
}
|
||||||
|
m_PhysicsWorld->markForWrite();
|
||||||
m_RigidBodies[entity]->setPositionAndRotation(position, rotation);
|
m_RigidBodies[entity]->setPositionAndRotation(position, rotation);
|
||||||
|
m_PhysicsWorld->unmarkForWrite();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const double timestep = 1 / 60.0;
|
||||||
|
|
||||||
|
|
||||||
static const double timestep = 1 / 30.0;
|
|
||||||
m_Accumulator += dt;
|
m_Accumulator += dt;
|
||||||
while (m_Accumulator >= timestep)
|
while (m_Accumulator >= timestep)
|
||||||
{
|
{
|
||||||
m_PhysicsWorld->stepDeltaTime(timestep);
|
m_PhysicsWorld->stepMultithreaded(m_JobQueue, m_ThreadPool, timestep);
|
||||||
|
//m_PhysicsWorld->stepDeltaTime(timestep);
|
||||||
|
|
||||||
m_Accumulator -= timestep;
|
m_Accumulator -= timestep;
|
||||||
|
|
||||||
|
m_Context->syncTimers(m_ThreadPool);
|
||||||
|
// Step the visual debugger
|
||||||
|
StepVisualDebugger();
|
||||||
|
|
||||||
|
// Clear accumulated timer data in this thread and all slave threads
|
||||||
|
hkMonitorStream::getInstance().reset();
|
||||||
|
m_ThreadPool->clearTimerData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step the visual debugger
|
|
||||||
StepVisualDebugger();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||||
@@ -119,6 +190,7 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
|||||||
EntityID car = m_World->GetEntityParent(entity);
|
EntityID car = m_World->GetEntityParent(entity);
|
||||||
if(m_Vehicles.find(car) != m_Vehicles.end())
|
if(m_Vehicles.find(car) != m_Vehicles.end())
|
||||||
{
|
{
|
||||||
|
m_PhysicsWorld->markForWrite();
|
||||||
m_Vehicles[car]->getChassis()->activate();
|
m_Vehicles[car]->getChassis()->activate();
|
||||||
|
|
||||||
hkVector4 hardPoint = m_Vehicles[car]->m_suspension->m_wheelParams[wheelComponent->ID].m_hardpointChassisSpace;
|
hkVector4 hardPoint = m_Vehicles[car]->m_suspension->m_wheelParams[wheelComponent->ID].m_hardpointChassisSpace;
|
||||||
@@ -129,40 +201,28 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
|||||||
|
|
||||||
hkQuaternion steeringOrientation = m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_steeringOrientationChassisSpace;
|
hkQuaternion steeringOrientation = m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_steeringOrientationChassisSpace;
|
||||||
hkReal spinAngle = -m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_spinAngle;
|
hkReal spinAngle = -m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_spinAngle;
|
||||||
glm::quat orientation = glm::quat(steeringOrientation(3), steeringOrientation(0), steeringOrientation(1), steeringOrientation(2)) * glm::angleAxis<float>(spinAngle, glm::vec3(1, 0, 0));
|
glm::quat orientation = ConvertRotation(steeringOrientation) * glm::angleAxis<float>(spinAngle, glm::vec3(1, 0, 0));
|
||||||
transformComponent->Orientation = orientation * wheelComponent->OriginalOrientation;
|
transformComponent->Orientation = orientation * wheelComponent->OriginalOrientation;
|
||||||
|
m_PhysicsWorld->unmarkForWrite();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(m_Vehicles.find(entity) != m_Vehicles.end())
|
|
||||||
{
|
|
||||||
hkVector4 position = m_RigidBodies[entity]->getPosition();
|
|
||||||
transformComponent->Position = glm::vec3(position(0), position(1), position(2));
|
|
||||||
hkQuaternion orientation = m_RigidBodies[entity]->getRotation();
|
|
||||||
transformComponent->Orientation = glm::quat(orientation(3),orientation(0), orientation(1), orientation(2));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(m_RigidBodies.find(entity) != m_RigidBodies.end())
|
else if(m_RigidBodies.find(entity) != m_RigidBodies.end())
|
||||||
{
|
{
|
||||||
if(m_RigidBodies[entity]->isActive())
|
auto transformComponentParent = m_World->GetComponent<Components::Transform>(parent, "Transform");
|
||||||
|
|
||||||
|
transformComponent->Position = ConvertPosition(m_RigidBodies[entity]->getPosition());
|
||||||
|
transformComponent->Orientation = ConvertRotation(m_RigidBodies[entity]->getRotation());
|
||||||
|
// TODO: No support for Scale, MIGHT be possible
|
||||||
|
|
||||||
|
if (transformComponentParent)
|
||||||
{
|
{
|
||||||
hkVector4 position = m_RigidBodies[entity]->getPosition();
|
transformComponent->Position -= transformComponentParent->Position;
|
||||||
transformComponent->Position = glm::vec3(position(0), position(1), position(2));
|
transformComponent->Position = transformComponent->Position * transformComponentParent->Orientation;
|
||||||
hkQuaternion orientation = m_RigidBodies[entity]->getRotation();
|
transformComponent->Orientation = transformComponent->Orientation * glm::inverse(transformComponentParent->Orientation);
|
||||||
transformComponent->Orientation = glm::quat(orientation(3),orientation(0), orientation(1), orientation(2));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// HACK: Vehicle test-controls
|
|
||||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(entity, "Vehicle");
|
|
||||||
auto inputComponent = m_World->GetComponent<Components::Input>(entity, "Input");
|
|
||||||
if (vehicleComponent && inputComponent)
|
|
||||||
{
|
|
||||||
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[entity]->m_deviceStatus;
|
|
||||||
deviceStatus->m_positionY = inputComponent->KeyState[GLFW_KEY_UP] * -1 + inputComponent->KeyState[GLFW_KEY_DOWN] * 1;
|
|
||||||
deviceStatus->m_positionX = inputComponent->KeyState[GLFW_KEY_LEFT] * -1 + inputComponent->KeyState[GLFW_KEY_RIGHT] * 1;
|
|
||||||
deviceStatus->m_handbrakeButtonPressed = inputComponent->KeyState[GLFW_KEY_RIGHT_CONTROL];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||||
@@ -171,7 +231,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
|||||||
if (!transformComponent)
|
if (!transformComponent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity, "Wheel");
|
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity, "Wheel");
|
||||||
if (wheelComponent)
|
if (wheelComponent)
|
||||||
{
|
{
|
||||||
@@ -180,201 +239,250 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
|||||||
m_Wheels.push_back(entity);
|
m_Wheels.push_back(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EntityID entityParent = m_World->GetEntityBaseParent(entity);
|
||||||
|
|
||||||
|
auto sphereComponent = m_World->GetComponent<Components::SphereShape>(entity, "SphereShape");
|
||||||
|
auto boxComponent = m_World->GetComponent<Components::BoxShape>(entity, "BoxShape");
|
||||||
|
auto meshShapeComponent = m_World->GetComponent<Components::MeshShape >(entity, "MeshShape");
|
||||||
|
|
||||||
|
if(entityParent == entity && (sphereComponent || boxComponent || meshShapeComponent))
|
||||||
|
{
|
||||||
|
LOG_ERROR("Entity: %i , Only the children can have a shapeComponent", entity);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity, "Physics");
|
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity, "Physics");
|
||||||
if (!physicsComponent)
|
if (physicsComponent)
|
||||||
return;
|
|
||||||
|
|
||||||
auto sphereComponent = m_World->GetComponent<Components::Sphere >(entity, "Sphere");
|
|
||||||
auto boxComponent = m_World->GetComponent<Components::Box >(entity, "Box");
|
|
||||||
|
|
||||||
|
|
||||||
hkpConvexShape* shape;
|
|
||||||
hkpRigidBodyCinfo rigidBodyInfo;
|
|
||||||
hkMassProperties massProperties;
|
|
||||||
|
|
||||||
if (sphereComponent)
|
|
||||||
{
|
{
|
||||||
shape = new hkpSphereShape(sphereComponent->Radius);
|
hkpShape* shape;
|
||||||
rigidBodyInfo.m_shape = shape;
|
if(entityParent != entity)
|
||||||
|
|
||||||
if (physicsComponent->Static)
|
|
||||||
{
|
{
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
|
LOG_ERROR("Entity: %i , Only the baseparent can have a PhysicsComponent", entity);
|
||||||
}
|
return;
|
||||||
else
|
|
||||||
{
|
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_SPHERE_INERTIA;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hkpInertiaTensorComputer::computeSphereVolumeMassProperties(sphereComponent->Radius, physicsComponent->Mass, massProperties);
|
if(! physicsComponent->Static) // Not static
|
||||||
|
|
||||||
}
|
|
||||||
else if (boxComponent)
|
|
||||||
{
|
|
||||||
hkReal thickness = 0.05;
|
|
||||||
shape = new hkpBoxShape(hkVector4(boxComponent->Width - thickness, boxComponent->Height - thickness, boxComponent->Depth - thickness));
|
|
||||||
rigidBodyInfo.m_shape = shape;
|
|
||||||
if (physicsComponent->Static)
|
|
||||||
{
|
{
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
|
hkArray<hkpShape*> shapeArray;
|
||||||
}
|
for (auto &shapeData : m_Shapes[entity])
|
||||||
else
|
|
||||||
{
|
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;
|
|
||||||
}
|
|
||||||
hkpInertiaTensorComputer::computeBoxSurfaceMassProperties(hkVector4(boxComponent->Width - thickness, boxComponent->Height - thickness, boxComponent->Depth - thickness), physicsComponent->Mass, thickness, massProperties);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
rigidBodyInfo.m_position.set(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z);
|
|
||||||
rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
|
|
||||||
rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass;
|
|
||||||
rigidBodyInfo.m_mass = massProperties.m_mass;
|
|
||||||
|
|
||||||
// Create RigidBody
|
|
||||||
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
|
|
||||||
|
|
||||||
|
|
||||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle >(entity, "Vehicle");
|
|
||||||
if (vehicleComponent && m_Vehicles.find(entity) == m_Vehicles.end())
|
|
||||||
{
|
|
||||||
for (int i = 0; i < m_Wheels.size(); i++)
|
|
||||||
{
|
|
||||||
if(m_World->GetEntityParent(m_Wheels[i]) != entity)
|
|
||||||
{
|
{
|
||||||
m_Wheels.erase(m_Wheels.begin() + i);
|
shapeArray.pushBack(shapeData.Shape);
|
||||||
i--;
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Create a hkpListShape* of all the childEntities collected in m_ShapeArrays
|
||||||
|
hkpListShape* listShape = new hkpListShape(shapeArray.begin(), shapeArray.getSize(), hkpShapeContainer::REFERENCE_POLICY_INCREMENT);
|
||||||
|
// Save the listShape for further use
|
||||||
|
m_ListShapes[entity] = listShape;
|
||||||
|
shape = listShape;
|
||||||
|
|
||||||
|
//////////////////////////////////
|
||||||
|
//******************************//
|
||||||
|
// Add a hkpBvShape //
|
||||||
|
//******************************//
|
||||||
|
//////////////////////////////////
|
||||||
|
|
||||||
|
// Clean up for less memory usage
|
||||||
|
m_Shapes.erase(entity);
|
||||||
|
|
||||||
|
hkMassProperties massProperties;
|
||||||
|
hkpInertiaTensorComputer::computeShapeVolumeMassProperties(shape, physicsComponent->Mass, massProperties);
|
||||||
|
|
||||||
|
hkpRigidBodyCinfo rigidBodyInfo;
|
||||||
|
{
|
||||||
|
rigidBodyInfo.m_shape = shape;
|
||||||
|
rigidBodyInfo.m_motionType = hkpMotion::MOTION_DYNAMIC;
|
||||||
|
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
|
||||||
|
hkVector4 position = ConvertPosition(absoluteTransform.Position);
|
||||||
|
hkQuaternion rotation = ConvertRotation(absoluteTransform.Orientation);
|
||||||
|
rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3));
|
||||||
|
rigidBodyInfo.m_rotation.set(rotation(0), rotation(1), rotation(2), rotation(3));
|
||||||
|
|
||||||
|
rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
|
||||||
|
//rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass; //HACK: CENTER OF MASS ALWAYS IN THE CENTER
|
||||||
|
rigidBodyInfo.m_mass = massProperties.m_mass;
|
||||||
|
}
|
||||||
|
// Create RigidBody
|
||||||
|
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
|
||||||
|
|
||||||
|
auto vehicleComponent = m_World->GetComponent<Components::Vehicle >(entity, "Vehicle");
|
||||||
|
if (vehicleComponent && m_Vehicles.find(entity) == m_Vehicles.end())
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_Wheels.size(); i++)
|
||||||
|
{
|
||||||
|
if(m_World->GetEntityParent(m_Wheels[i]) != entity)
|
||||||
|
{
|
||||||
|
m_Wheels.erase(m_Wheels.begin() + i);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
VehicleSetup vehicleSetup;
|
||||||
|
// Create the basic vehicle.
|
||||||
|
m_Vehicles[entity] = new hkpVehicleInstance(rigidBody);
|
||||||
|
m_PhysicsWorld->markForWrite();
|
||||||
|
vehicleSetup.buildVehicle(m_World, m_PhysicsWorld, *m_Vehicles[entity], entity, m_Wheels);
|
||||||
|
// Add the vehicle's entities and phantoms to the world
|
||||||
|
m_Vehicles[entity]->addToWorld(m_PhysicsWorld);
|
||||||
|
|
||||||
|
m_RigidBodies[entity] = rigidBody;
|
||||||
|
|
||||||
|
// The vehicle is an action
|
||||||
|
m_PhysicsWorld->addAction(m_Vehicles[entity]);
|
||||||
|
m_PhysicsWorld->unmarkForWrite();
|
||||||
|
|
||||||
|
//m_Vehicles[entity]->m_rpm = 0.0f; // Not sure why this one should be here
|
||||||
|
m_Wheels.clear();
|
||||||
|
shape->removeReference();
|
||||||
|
rigidBody->removeReference();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_PhysicsWorld->markForWrite();
|
||||||
|
m_PhysicsWorld->addEntity(rigidBody);
|
||||||
|
m_RigidBodies[entity] = rigidBody;
|
||||||
|
m_PhysicsWorld->unmarkForWrite();
|
||||||
|
|
||||||
|
shape->removeReference();
|
||||||
|
rigidBody->removeReference();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VehicleSetup vehicleSetup;
|
else // Static
|
||||||
|
|
||||||
// Create the basic vehicle.
|
|
||||||
m_Vehicles[entity] = new hkpVehicleInstance(rigidBody);
|
|
||||||
vehicleSetup.buildVehicle(m_World, m_PhysicsWorld, *m_Vehicles[entity], entity, m_Wheels);
|
|
||||||
// Add the vehicle's entities and phantoms to the world
|
|
||||||
m_Vehicles[entity]->addToWorld(m_PhysicsWorld);
|
|
||||||
|
|
||||||
m_RigidBodies[entity] = rigidBody;
|
|
||||||
|
|
||||||
// The vehicle is an action
|
|
||||||
m_PhysicsWorld->addAction(m_Vehicles[entity]);
|
|
||||||
|
|
||||||
//m_Vehicles[entity]->m_rpm = 0.0f; // Not sure why this one should be here
|
|
||||||
m_Wheels.clear();
|
|
||||||
shape->removeReference();
|
|
||||||
rigidBody->removeReference();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_PhysicsWorld->addEntity(rigidBody);
|
|
||||||
m_RigidBodies[entity] = rigidBody;
|
|
||||||
shape->removeReference();
|
|
||||||
rigidBody->removeReference();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
|
|
||||||
void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
|
||||||
{
|
|
||||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
|
||||||
if (!transformComponent)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity, "Physics");
|
|
||||||
if (!physicsComponent)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto sphereComponent = m_World->GetComponent<Components::Sphere >(entity, "Sphere");
|
|
||||||
auto boxComponent = m_World->GetComponent<Components::Box >(entity, "Box");
|
|
||||||
|
|
||||||
|
|
||||||
hkpConvexShape* shape;
|
|
||||||
hkpRigidBodyCinfo rigidBodyInfo;
|
|
||||||
hkMassProperties massProperties;
|
|
||||||
|
|
||||||
|
|
||||||
if (sphereComponent)
|
|
||||||
{
|
|
||||||
shape = new hkpSphereShape(sphereComponent->Radius);
|
|
||||||
rigidBodyInfo.m_shape = shape;
|
|
||||||
|
|
||||||
if (physicsComponent->Static)
|
|
||||||
{
|
{
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
|
// Create the hkpStaticCompoundShape and add the instances.
|
||||||
}
|
// "meshShape" should not be modified by the user in any way after adding it as an instance.
|
||||||
else
|
hkpStaticCompoundShape* staticCompoundShape = new hkpStaticCompoundShape();
|
||||||
{
|
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_SPHERE_INERTIA;
|
|
||||||
}
|
|
||||||
|
|
||||||
hkpInertiaTensorComputer::computeSphereVolumeMassProperties(sphereComponent->Radius, physicsComponent->Mass, massProperties);
|
for (auto &shapeData : m_Shapes[entity])
|
||||||
|
{
|
||||||
|
|
||||||
}
|
auto childTransformComponent = m_World->GetComponent<Components::Transform>(shapeData.Entity, "Transform");
|
||||||
else if (boxComponent)
|
|
||||||
{
|
|
||||||
hkReal thickness = 0.05;
|
|
||||||
shape = new hkpBoxShape(hkVector4(boxComponent->Width - thickness, boxComponent->Height - thickness, boxComponent->Depth - thickness));
|
|
||||||
rigidBodyInfo.m_shape = shape;
|
|
||||||
if (physicsComponent->Static)
|
|
||||||
{
|
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;
|
|
||||||
}
|
|
||||||
hkpInertiaTensorComputer::computeBoxSurfaceMassProperties(hkVector4(boxComponent->Width - thickness, boxComponent->Height - thickness, boxComponent->Depth - thickness), physicsComponent->Mass, thickness, massProperties);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
rigidBodyInfo.m_position.set(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z);
|
hkVector4 position = ConvertPosition(childTransformComponent->Position);
|
||||||
rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
|
hkQuaternion rotation = ConvertRotation(childTransformComponent->Orientation);
|
||||||
rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass;
|
hkVector4 scale = ConvertScale(childTransformComponent->Scale);
|
||||||
rigidBodyInfo.m_mass = massProperties.m_mass;
|
hkQsTransform transform(position, rotation, scale);
|
||||||
|
|
||||||
// Create RigidBody
|
staticCompoundShape->addInstance(shapeData.Shape, transform);
|
||||||
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
|
}
|
||||||
|
|
||||||
|
// This must be called after adding the instances and before using the shape.
|
||||||
|
staticCompoundShape->bake();
|
||||||
|
shape = staticCompoundShape;
|
||||||
|
m_Shapes.erase(entity);
|
||||||
|
hkMassProperties massProperties;
|
||||||
|
hkpInertiaTensorComputer::computeShapeVolumeMassProperties(shape, physicsComponent->Mass, massProperties);
|
||||||
|
|
||||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle >(entity, "Vehicle");
|
hkpRigidBodyCinfo rigidBodyInfo;
|
||||||
if (vehicleComponent && m_Vehicles.find(entity) == m_Vehicles.end())
|
{
|
||||||
{
|
rigidBodyInfo.m_shape = shape;
|
||||||
VehicleSetup vehicleSetup;
|
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
|
||||||
|
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
|
||||||
|
hkVector4 position = ConvertPosition(absoluteTransform.Position);
|
||||||
|
hkQuaternion rotation = ConvertRotation(absoluteTransform.Orientation);
|
||||||
|
rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3));
|
||||||
|
rigidBodyInfo.m_rotation.set(rotation(0), rotation(1), rotation(2), rotation(3));
|
||||||
|
|
||||||
// Create the basic vehicle.
|
rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
|
||||||
m_Vehicles[entity] = new hkpVehicleInstance(rigidBody);
|
//rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass; //HACK: CENTER OF MASS ALWAYS IN THE CENTER
|
||||||
vehicleSetup.buildVehicle(m_PhysicsWorld, *m_Vehicles[entity]);
|
rigidBodyInfo.m_mass = massProperties.m_mass;
|
||||||
// Add the vehicle's entities and phantoms to the world
|
}
|
||||||
m_Vehicles[entity]->addToWorld(m_PhysicsWorld);
|
// Create RigidBody
|
||||||
|
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
|
||||||
|
|
||||||
|
m_PhysicsWorld->markForWrite();
|
||||||
|
m_PhysicsWorld->addEntity(rigidBody);
|
||||||
m_RigidBodies[entity] = rigidBody;
|
m_RigidBodies[entity] = rigidBody;
|
||||||
|
m_PhysicsWorld->unmarkForWrite();
|
||||||
// The vehicle is an action
|
|
||||||
m_PhysicsWorld->addAction(m_Vehicles[entity]);
|
|
||||||
|
|
||||||
//m_Vehicles[entity]->m_rpm = 0.0f; // Not sure why this one should be here
|
|
||||||
|
|
||||||
shape->removeReference();
|
shape->removeReference();
|
||||||
rigidBody->removeReference();
|
rigidBody->removeReference();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_PhysicsWorld->addEntity(rigidBody);
|
|
||||||
m_RigidBodies[entity] = rigidBody;
|
//TODO: COMMENT THIS SECTION
|
||||||
shape->removeReference();
|
if(sphereComponent)
|
||||||
rigidBody->removeReference();
|
{
|
||||||
|
hkpSphereShape* sphereShape = new hkpSphereShape(sphereComponent->Radius);
|
||||||
|
|
||||||
|
hkQsTransform transform( ConvertPosition(transformComponent->Position), ConvertRotation(transformComponent->Orientation), ConvertScale(transformComponent->Scale));
|
||||||
|
hkpConvexTransformShape* transformedSphereShape = new hkpConvexTransformShape( sphereShape, transform );
|
||||||
|
|
||||||
|
m_Shapes[entityParent].push_back(ShapeArrayData(entity, transformedSphereShape));
|
||||||
|
|
||||||
|
sphereShape->removeReference();
|
||||||
|
}
|
||||||
|
//TODO: COMMENT THIS SECTION
|
||||||
|
else if(boxComponent)
|
||||||
|
{
|
||||||
|
hkReal thickness = 0.05;
|
||||||
|
hkpBoxShape* boxShape = new hkpBoxShape(hkVector4(boxComponent->Width- thickness, boxComponent->Height -thickness, boxComponent->Depth - thickness), thickness);
|
||||||
|
|
||||||
|
hkQsTransform transform( ConvertPosition(transformComponent->Position), ConvertRotation(transformComponent->Orientation), ConvertScale(transformComponent->Scale));
|
||||||
|
hkpConvexTransformShape* transformedBoxShape = new hkpConvexTransformShape( boxShape, transform );
|
||||||
|
m_Shapes[entityParent].push_back(ShapeArrayData(entity, transformedBoxShape));
|
||||||
|
boxShape->removeReference();
|
||||||
|
}
|
||||||
|
else if(meshShapeComponent)
|
||||||
|
{
|
||||||
|
std::vector<hkReal>* vertices = new std::vector<hkReal>;
|
||||||
|
std::vector<hkUint16>* vertexIndices = new std::vector<hkUint16>;
|
||||||
|
auto meshShape = m_World->GetResourceManager()->Load<OBJ>("OBJ", meshShapeComponent->ResourceName);
|
||||||
|
|
||||||
|
for (auto &vertex : meshShape->Vertices)
|
||||||
|
{
|
||||||
|
hkReal x, y, z;
|
||||||
|
std::tie(x, y, z) = vertex;
|
||||||
|
vertices->push_back(x);
|
||||||
|
vertices->push_back(y);
|
||||||
|
vertices->push_back(z);
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (auto &face : meshShape->Faces)
|
||||||
|
{
|
||||||
|
for (auto &faceDef : face.Definitions)
|
||||||
|
{
|
||||||
|
vertexIndices->push_back(faceDef.VertexIndex - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hkpExtendedMeshShape* mesh = new hkpExtendedMeshShape();
|
||||||
|
hkReal thickness = 0.05f; // HACK: Convex radius should be 0 for static shapes and 0.05 for dynamic shapes.
|
||||||
|
mesh->setRadius(thickness);
|
||||||
|
{
|
||||||
|
hkpExtendedMeshShape::TrianglesSubpart part;
|
||||||
|
part.m_numTriangleShapes = meshShape->Faces.size();
|
||||||
|
part.m_indexBase = vertexIndices->data();
|
||||||
|
part.m_indexStriding = sizeof(hkUint16) * 3;
|
||||||
|
|
||||||
|
part.m_numVertices = vertices->size() / 3;
|
||||||
|
part.m_vertexBase = vertices->data();
|
||||||
|
part.m_vertexStriding = sizeof(hkReal) * 3;
|
||||||
|
|
||||||
|
part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16;
|
||||||
|
|
||||||
|
mesh->addTrianglesSubpart(part);
|
||||||
|
}
|
||||||
|
hkpMoppCompilerInput mci;
|
||||||
|
hkpMoppCode* code = hkpMoppUtility::buildCode( mesh, mci );
|
||||||
|
hkpMoppBvTreeShape* moppShape = new hkpMoppBvTreeShape(mesh, code);
|
||||||
|
|
||||||
|
m_ExtendedMeshShapes[entity].Code = code;
|
||||||
|
m_ExtendedMeshShapes[entity].MoppShape = moppShape;
|
||||||
|
m_Shapes[entityParent].push_back(ShapeArrayData(entity, moppShape)); //HACK: Should maybe have transform, not sure yet
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Systems::PhysicsSystem::TearDownPhysicsState(EntityID entity, EntityID parent)
|
void Systems::PhysicsSystem::TearDownPhysicsState(EntityID entity, EntityID parent)
|
||||||
{
|
{
|
||||||
@@ -396,6 +504,7 @@ void Systems::PhysicsSystem::SetupVisualDebugger(hkpPhysicsContext* worlds)
|
|||||||
{
|
{
|
||||||
// Setup the visual debugger
|
// Setup the visual debugger
|
||||||
hkArray<hkProcessContext*> contexts;
|
hkArray<hkProcessContext*> contexts;
|
||||||
|
|
||||||
contexts.pushBack(worlds);
|
contexts.pushBack(worlds);
|
||||||
|
|
||||||
m_VisualDebugger = new hkVisualDebugger(contexts);
|
m_VisualDebugger = new hkVisualDebugger(contexts);
|
||||||
@@ -423,3 +532,59 @@ void HK_CALL Systems::PhysicsSystem::HavokErrorReport(const char* msg, void*)
|
|||||||
LOG_INFO("%s", msg);
|
LOG_INFO("%s", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
glm::vec3 Systems::PhysicsSystem::ConvertPosition(const hkVector4 &hkPosition)
|
||||||
|
{
|
||||||
|
return glm::vec3(hkPosition(0), hkPosition(1), hkPosition(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
const hkVector4& Systems::PhysicsSystem::ConvertPosition(glm::vec3 glmPosition)
|
||||||
|
{
|
||||||
|
return hkVector4( glmPosition.x, glmPosition.y, glmPosition.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::quat Systems::PhysicsSystem::ConvertRotation(const hkQuaternion &hkRotation)
|
||||||
|
{
|
||||||
|
return glm::quat(hkRotation(3), hkRotation(0), hkRotation(1), hkRotation(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
const hkQuaternion& Systems::PhysicsSystem::ConvertRotation(glm::quat glmRotation)
|
||||||
|
{
|
||||||
|
hkQuaternion quat = hkQuaternion(glmRotation.x, glmRotation.y, glmRotation.z, glmRotation.w);
|
||||||
|
quat.normalize();
|
||||||
|
return quat;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 Systems::PhysicsSystem::ConvertScale(const hkVector4 &hkScale)
|
||||||
|
{
|
||||||
|
return glm::vec3(hkScale(0), hkScale(1), hkScale(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
const hkVector4& Systems::PhysicsSystem::ConvertScale(glm::vec3 glmScale)
|
||||||
|
{
|
||||||
|
return hkVector4(glmScale.x, glmScale.y, glmScale.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
|
||||||
|
{
|
||||||
|
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity, "Vehicle");
|
||||||
|
if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
|
||||||
|
{
|
||||||
|
m_PhysicsWorld->markForWrite();
|
||||||
|
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus;
|
||||||
|
deviceStatus->m_positionX = event.PositionX;
|
||||||
|
deviceStatus->m_positionY = event.PositionY;
|
||||||
|
deviceStatus->m_handbrakeButtonPressed = event.Handbrake;
|
||||||
|
m_PhysicsWorld->unmarkForWrite();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event )
|
||||||
|
{
|
||||||
|
m_PhysicsWorld->markForWrite();
|
||||||
|
m_RigidBodies[event.Entity]->setLinearVelocity(ConvertPosition(event.Velocity));
|
||||||
|
m_PhysicsWorld->unmarkForWrite();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,12 +2,20 @@
|
|||||||
#define PhysicsSystem_h__
|
#define PhysicsSystem_h__
|
||||||
|
|
||||||
#include "System.h"
|
#include "System.h"
|
||||||
|
#include "Systems/TransformSystem.h"
|
||||||
#include "Components/Transform.h"
|
#include "Components/Transform.h"
|
||||||
#include "Components/Physics.h"
|
#include "Components/Physics.h"
|
||||||
#include "Components/Sphere.h"
|
#include "Components/BoxShape.h"
|
||||||
#include "Components/Box.h"
|
#include "Components/SphereShape.h"
|
||||||
#include "Components/Vehicle.h"
|
#include "Components/Vehicle.h"
|
||||||
#include "Components/Input.h"
|
#include "Components/Input.h"
|
||||||
|
#include "Components/MeshShape.h"
|
||||||
|
#include "Components/HingeConstraint.h"
|
||||||
|
#include "Components/WheelPair.h"
|
||||||
|
#include "Components/TowerSteering.h"
|
||||||
|
#include "Events/TankSteer.h"
|
||||||
|
#include "Events/SetVelocity.h"
|
||||||
|
#include "OBJ.h"
|
||||||
|
|
||||||
// Math and base include
|
// Math and base include
|
||||||
#include <Common/Base/hkBase.h>
|
#include <Common/Base/hkBase.h>
|
||||||
@@ -34,6 +42,21 @@
|
|||||||
#include <Common/Visualize/hkVisualDebugger.h>
|
#include <Common/Visualize/hkVisualDebugger.h>
|
||||||
#include <Physics2012/Utilities/VisualDebugger/hkpPhysicsContext.h>
|
#include <Physics2012/Utilities/VisualDebugger/hkpPhysicsContext.h>
|
||||||
|
|
||||||
|
#include <Physics2012/Collide/Shape/Compound/Collection/ExtendedMeshShape/hkpExtendedMeshShape.h>
|
||||||
|
#include <Physics2012/Collide/Shape/Compound/Tree/Mopp/hkpMoppBvTreeShape.h>
|
||||||
|
#include <Physics2012/Collide/Shape/Compound/Tree/Mopp/hkpMoppUtility.h>
|
||||||
|
|
||||||
|
#include <Common/Base/Thread/JobQueue/hkJobQueue.h>
|
||||||
|
#include <Common/Base/Thread/Job/ThreadPool/Cpu/hkCpuJobThreadPool.h>
|
||||||
|
#include <Common/Base/DebugUtil/MultiThreadCheck/hkMultiThreadCheck.h>
|
||||||
|
#include <Physics/Constraint/Data/Hinge/hkpHingeConstraintData.h>
|
||||||
|
#include <Physics/Constraint/Data/LimitedHinge/hkpLimitedHingeConstraintData.h>
|
||||||
|
|
||||||
|
#include <Physics2012/Collide/Shape/Compound/Collection/List/hkpListShape.h>
|
||||||
|
#include <Physics2012/Internal/Collide/StaticCompound/hkpStaticCompoundShape.h>
|
||||||
|
#include <Physics2012/Collide/Util/ShapeShrinker/hkpShapeShrinker.h>
|
||||||
|
#include <Physics2012/Collide/Shape/Misc/Bv/hkpBvShape.h>
|
||||||
|
|
||||||
#include "Physics/VehicleSetup.h"
|
#include "Physics/VehicleSetup.h"
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@@ -59,6 +82,13 @@ private:
|
|||||||
double m_Accumulator;
|
double m_Accumulator;
|
||||||
hkpWorld* m_PhysicsWorld;
|
hkpWorld* m_PhysicsWorld;
|
||||||
|
|
||||||
|
// Events
|
||||||
|
EventRelay<Events::TankSteer> m_ETankSteer;
|
||||||
|
bool OnTankSteer(const Events::TankSteer &event);
|
||||||
|
|
||||||
|
EventRelay<Events::SetVelocity> m_ESetVelocity;
|
||||||
|
bool OnSetVelocity(const Events::SetVelocity &event);
|
||||||
|
|
||||||
void SetUpPhysicsState(EntityID entity, EntityID parent);
|
void SetUpPhysicsState(EntityID entity, EntityID parent);
|
||||||
void TearDownPhysicsState(EntityID entity, EntityID parent);
|
void TearDownPhysicsState(EntityID entity, EntityID parent);
|
||||||
|
|
||||||
@@ -68,11 +98,53 @@ private:
|
|||||||
static void HK_CALL HavokErrorReport(const char* msg, void*);
|
static void HK_CALL HavokErrorReport(const char* msg, void*);
|
||||||
void SetupPhysics(hkpWorld* physicsWorld);
|
void SetupPhysics(hkpWorld* physicsWorld);
|
||||||
|
|
||||||
|
// Converterfunctions
|
||||||
|
glm::vec3 ConvertPosition(const hkVector4 &hkPosition);
|
||||||
|
const hkVector4& ConvertPosition(glm::vec3 glmPosition);
|
||||||
|
|
||||||
|
glm::quat ConvertRotation(const hkQuaternion &hkRotation);
|
||||||
|
const hkQuaternion& ConvertRotation(glm::quat glmRotation);
|
||||||
|
|
||||||
|
glm::vec3 ConvertScale(const hkVector4 &hkScale);
|
||||||
|
const hkVector4&ConvertScale(glm::vec3 glmScale);
|
||||||
|
|
||||||
std::unordered_map<EntityID, hkpRigidBody*> m_RigidBodies;
|
std::unordered_map<EntityID, hkpRigidBody*> m_RigidBodies;
|
||||||
|
|
||||||
|
hkJobThreadPool* m_ThreadPool;
|
||||||
|
hkJobQueue* m_JobQueue;
|
||||||
|
int m_TotalNumThreadsUsed;
|
||||||
|
hkpPhysicsContext* m_Context;
|
||||||
|
|
||||||
std::unordered_map<EntityID, hkpVehicleInstance*> m_Vehicles;
|
std::unordered_map<EntityID, hkpVehicleInstance*> m_Vehicles;
|
||||||
std::vector<EntityID> m_Wheels;
|
std::vector<EntityID> m_Wheels;
|
||||||
|
|
||||||
hkpVehicleInstance* Systems::PhysicsSystem::createVehicle(VehicleSetup& vehicleSetup, hkpRigidBody* chassis);
|
hkpVehicleInstance* Systems::PhysicsSystem::createVehicle(VehicleSetup& vehicleSetup, hkpRigidBody* chassis);
|
||||||
|
|
||||||
|
|
||||||
|
struct ShapeArrayData
|
||||||
|
{
|
||||||
|
ShapeArrayData(EntityID entity, hkpShape* shape)
|
||||||
|
{
|
||||||
|
Entity = entity;
|
||||||
|
Shape = shape;
|
||||||
|
}
|
||||||
|
EntityID Entity;
|
||||||
|
hkpShape* Shape;
|
||||||
|
};
|
||||||
|
std::unordered_map<EntityID, std::list<ShapeArrayData>> m_Shapes;
|
||||||
|
std::unordered_map<EntityID, hkpListShape*> m_ListShapes;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct ExtendedShapeData
|
||||||
|
{
|
||||||
|
hkpExtendedMeshShape* ExtendedMeshShape;
|
||||||
|
std::vector<hkReal>* Vertices;
|
||||||
|
std::vector<hkUint16>* VertexIndices;
|
||||||
|
hkpMoppCode* Code;
|
||||||
|
hkpMoppBvTreeShape* MoppShape;
|
||||||
|
};
|
||||||
|
std::unordered_map<EntityID, ExtendedShapeData > m_ExtendedMeshShapes;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
auto model = m_World->GetResourceManager()->Load<Model>("Model", modelComponent->ModelFile);
|
auto model = m_World->GetResourceManager()->Load<Model>("Model", modelComponent->ModelFile);
|
||||||
if (model != nullptr)
|
if (model != nullptr)
|
||||||
{
|
{
|
||||||
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
/*glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||||
glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity);
|
glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity);
|
||||||
glm::vec3 scale = m_TransformSystem->AbsoluteScale(entity);
|
glm::vec3 scale = m_TransformSystem->AbsoluteScale(entity);*/
|
||||||
m_Renderer->AddModelToDraw(model, position, orientation, scale, modelComponent->Visible, modelComponent->ShadowCaster);
|
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
|
||||||
|
m_Renderer->AddModelToDraw(model, absoluteTransform.Position, absoluteTransform.Orientation, absoluteTransform.Scale, modelComponent->Visible, modelComponent->ShadowCaster);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,10 +39,11 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
position,
|
position,
|
||||||
pointLightComponent->Specular,
|
pointLightComponent->Specular,
|
||||||
pointLightComponent->Diffuse,
|
pointLightComponent->Diffuse,
|
||||||
pointLightComponent->constantAttenuation,
|
pointLightComponent->specularExponent,
|
||||||
pointLightComponent->linearAttenuation,
|
pointLightComponent->ConstantAttenuation,
|
||||||
pointLightComponent->quadraticAttenuation,
|
pointLightComponent->LinearAttenuation,
|
||||||
pointLightComponent->spotExponent);
|
pointLightComponent->QuadraticAttenuation
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity, "Camera");
|
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity, "Camera");
|
||||||
@@ -54,11 +56,24 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
m_Renderer->GetCamera()->NearClip(cameraComponent->NearClip);
|
m_Renderer->GetCamera()->NearClip(cameraComponent->NearClip);
|
||||||
m_Renderer->GetCamera()->FarClip(cameraComponent->FarClip);
|
m_Renderer->GetCamera()->FarClip(cameraComponent->FarClip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity, "Sprite");
|
||||||
|
if(spriteComponent != nullptr)
|
||||||
|
{
|
||||||
|
//TEMP
|
||||||
|
Texture* texture = m_World->GetResourceManager()->Load<Texture>("Texture", spriteComponent->SpriteFile);
|
||||||
|
//glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
|
auto transform = m_World->GetComponent<Components::Transform>(spriteComponent->Entity, "Transform");
|
||||||
|
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(transform->Orientation).z, glm::vec3(0, 0, -1));
|
||||||
|
m_Renderer->AddTextureToDraw(texture, transform->Position, orientation2D, transform->Scale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::RenderSystem::Initialize()
|
void Systems::RenderSystem::Initialize()
|
||||||
{
|
{
|
||||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>("TransformSystem");
|
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>("TransformSystem");
|
||||||
|
|
||||||
|
m_Renderer->SetSphereModel(m_World->GetResourceManager()->Load<Model>("Model", "Models/Placeholders/PhysicsTest/Sphere.obj"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
|
void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
|
||||||
@@ -72,7 +87,8 @@ void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
|
|||||||
|
|
||||||
void Systems::RenderSystem::RegisterResourceTypes(ResourceManager* rm)
|
void Systems::RenderSystem::RegisterResourceTypes(ResourceManager* rm)
|
||||||
{
|
{
|
||||||
rm->RegisterType("Model", [rm](std::string resourceName) { return new Model(OBJ(resourceName), rm); });
|
rm->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load<OBJ>("OBJ", resourceName)); });
|
||||||
|
rm->RegisterType("OBJ", [](std::string resourceName) { return new OBJ(resourceName); });
|
||||||
rm->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); });
|
rm->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,135 @@
|
|||||||
|
#include "PrecompiledHeader.h"
|
||||||
|
#include "TankSteeringSystem.h"
|
||||||
|
#include "World.h"
|
||||||
|
|
||||||
|
void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf )
|
||||||
|
{
|
||||||
|
cf->Register("TankSteering", []() { return new Components::TankSteering(); });
|
||||||
|
cf->Register("TowerSteering", []() { return new Components::TowerSteering(); });
|
||||||
|
cf->Register("BarrelSteering", []() { return new Components::BarrelSteering(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::TankSteeringSystem::Initialize()
|
||||||
|
{
|
||||||
|
m_TankInputController = std::unique_ptr<TankSteeringInputController>(new TankSteeringInputController(EventBroker));
|
||||||
|
m_TowerInputController = std::unique_ptr<TowerSteeringInputController>(new TowerSteeringInputController(EventBroker));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::TankSteeringSystem::Update(double dt)
|
||||||
|
{
|
||||||
|
m_TankInputController->Update(dt);
|
||||||
|
m_TowerInputController->Update(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||||
|
{
|
||||||
|
auto tankSteeringComponent = m_World->GetComponent<Components::TankSteering>(entity, "TankSteering");
|
||||||
|
if(tankSteeringComponent)
|
||||||
|
{
|
||||||
|
Events::TankSteer e;
|
||||||
|
e.Entity = entity;
|
||||||
|
e.PositionX = m_TankInputController->PositionX;
|
||||||
|
e.PositionY = m_TankInputController->PositionY;
|
||||||
|
e.Handbrake = m_TankInputController->Handbrake;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto towerSteeringComponent = m_World->GetComponent<Components::TowerSteering>(entity, "TowerSteering");
|
||||||
|
if(towerSteeringComponent)
|
||||||
|
{
|
||||||
|
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||||
|
glm::quat orientation = glm::angleAxis(towerSteeringComponent->TurnSpeed * m_TowerInputController->TowerDirection * (float)dt, towerSteeringComponent->Axis);
|
||||||
|
transformComponent->Orientation *= orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto barrelSteeringComponent = m_World->GetComponent<Components::BarrelSteering>(entity, "BarrelSteering");
|
||||||
|
if(barrelSteeringComponent)
|
||||||
|
{
|
||||||
|
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||||
|
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
|
||||||
|
glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * m_TowerInputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis);
|
||||||
|
transformComponent->Orientation *= orientation;
|
||||||
|
|
||||||
|
if(m_TowerInputController->Shoot && m_TimeSinceLastShot[entity] > 1.0)
|
||||||
|
{
|
||||||
|
EntityID clone = m_World->CloneEntity(barrelSteeringComponent->ShotTemplate);
|
||||||
|
auto templateAbsoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(barrelSteeringComponent->ShotTemplate);
|
||||||
|
auto cloneTransform = m_World->GetComponent<Components::Transform>(clone, "Transform");
|
||||||
|
cloneTransform->Position = templateAbsoluteTransform.Position;
|
||||||
|
cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation;
|
||||||
|
Events::SetVelocity e;
|
||||||
|
e.Entity = clone;
|
||||||
|
e.Velocity = absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
m_TimeSinceLastShot[entity] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_TimeSinceLastShot[entity] += dt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::TankSteeringSystem::TankSteeringInputController::Update( double dt )
|
||||||
|
{
|
||||||
|
PositionX = m_Horizontal;
|
||||||
|
PositionY = m_Vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::TankSteeringSystem::TowerSteeringInputController::Update( double dt )
|
||||||
|
{
|
||||||
|
TowerDirection = m_TowerDirection;
|
||||||
|
BarrelDirection = m_BarrelDirection;
|
||||||
|
Shoot = m_Shoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||||
|
{
|
||||||
|
float val = event.Value;
|
||||||
|
if (event.Command == "horizontal")
|
||||||
|
{
|
||||||
|
m_Horizontal = val;
|
||||||
|
}
|
||||||
|
else if (event.Command == "vertical")
|
||||||
|
{
|
||||||
|
m_Vertical = -val;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (event.Command == "handbrake")
|
||||||
|
{
|
||||||
|
Handbrake = val > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Systems::TankSteeringSystem::TowerSteeringInputController::OnCommand( const Events::InputCommand &event )
|
||||||
|
{
|
||||||
|
float val = event.Value;
|
||||||
|
if(event.Command == "tower_rotation")
|
||||||
|
{
|
||||||
|
m_TowerDirection = -val;
|
||||||
|
}
|
||||||
|
else if(event.Command == "barrel_rotation")
|
||||||
|
{
|
||||||
|
m_BarrelDirection = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (event.Command == "shoot")
|
||||||
|
{
|
||||||
|
m_Shoot = val > 0;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Systems::TankSteeringSystem::TowerSteeringInputController::OnMouseMove( const Events::MouseMove &event )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Systems::TankSteeringSystem::TankSteeringInputController::OnMouseMove( const Events::MouseMove &event )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
#include <array>
|
||||||
|
|
||||||
|
#include "System.h"
|
||||||
|
#include "Events/TankSteer.h"
|
||||||
|
#include "Events/SetVelocity.h"
|
||||||
|
#include "Components/Transform.h"
|
||||||
|
#include "Components/TankSteering.h"
|
||||||
|
#include "Components/TowerSteering.h"
|
||||||
|
#include "Components/BarrelSteering.h"
|
||||||
|
#include "Components/Vehicle.h"
|
||||||
|
#include "Systems/TransformSystem.h"
|
||||||
|
#include "InputController.h"
|
||||||
|
|
||||||
|
namespace Systems
|
||||||
|
{
|
||||||
|
|
||||||
|
class TankSteeringSystem : public System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TankSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||||
|
: System(world, eventBroker) { }
|
||||||
|
|
||||||
|
void RegisterComponents(ComponentFactory* cf) override;
|
||||||
|
void Initialize() override;
|
||||||
|
|
||||||
|
void Update(double dt) override;
|
||||||
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
class TankSteeringInputController;
|
||||||
|
std::unique_ptr<TankSteeringInputController> m_TankInputController;
|
||||||
|
class TowerSteeringInputController;
|
||||||
|
std::unique_ptr<TowerSteeringInputController> m_TowerInputController;
|
||||||
|
|
||||||
|
std::map<EntityID, double> m_TimeSinceLastShot;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TankSteeringSystem::TankSteeringInputController : InputController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TankSteeringInputController(std::shared_ptr<::EventBroker> eventBroker)
|
||||||
|
: InputController(eventBroker)
|
||||||
|
{
|
||||||
|
m_Horizontal = 0.f;
|
||||||
|
m_Vertical = 0.f;
|
||||||
|
PositionX = 0;
|
||||||
|
PositionY = 0;
|
||||||
|
Handbrake = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float PositionY;
|
||||||
|
float PositionX;
|
||||||
|
bool Handbrake;
|
||||||
|
void Update(double dt);
|
||||||
|
protected:
|
||||||
|
virtual bool OnCommand(const Events::InputCommand &event);
|
||||||
|
virtual bool OnMouseMove(const Events::MouseMove &event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
float m_Horizontal;
|
||||||
|
float m_Vertical;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TankSteeringSystem::TowerSteeringInputController : InputController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TowerSteeringInputController(std::shared_ptr<::EventBroker> eventBroker)
|
||||||
|
: InputController(eventBroker)
|
||||||
|
{
|
||||||
|
m_TowerDirection = 0.f;
|
||||||
|
m_BarrelDirection = 0.f;
|
||||||
|
TowerDirection = 0.f;
|
||||||
|
BarrelDirection = 0.f;
|
||||||
|
|
||||||
|
m_Shoot = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float TowerDirection;
|
||||||
|
float BarrelDirection;
|
||||||
|
bool Shoot;
|
||||||
|
void Update(double dt);
|
||||||
|
protected:
|
||||||
|
virtual bool OnCommand(const Events::InputCommand &event);
|
||||||
|
virtual bool OnMouseMove(const Events::MouseMove &event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
float m_TowerDirection;
|
||||||
|
float m_BarrelDirection;
|
||||||
|
bool m_Shoot;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
@@ -24,10 +24,10 @@ glm::vec3 Systems::TransformSystem::AbsolutePosition(EntityID entity)
|
|||||||
//absPosition += transform->Position;
|
//absPosition += transform->Position;
|
||||||
entity = m_World->GetEntityParent(entity);
|
entity = m_World->GetEntityParent(entity);
|
||||||
auto transform2 = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
auto transform2 = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||||
if (entity != 0)
|
if (entity == 0)
|
||||||
absPosition += transform2->Orientation * transform->Position;
|
|
||||||
else
|
|
||||||
absPosition += transform->Position;
|
absPosition += transform->Position;
|
||||||
|
else
|
||||||
|
absPosition = transform2->Orientation * (absPosition + transform->Position);
|
||||||
} while (entity != 0);
|
} while (entity != 0);
|
||||||
|
|
||||||
return absPosition * accumulativeOrientation;
|
return absPosition * accumulativeOrientation;
|
||||||
@@ -60,3 +60,34 @@ glm::vec3 Systems::TransformSystem::AbsoluteScale(EntityID entity)
|
|||||||
|
|
||||||
return absScale;
|
return absScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Components::Transform Systems::TransformSystem::AbsoluteTransform(EntityID entity)
|
||||||
|
{
|
||||||
|
glm::vec3 absPosition;
|
||||||
|
glm::quat absOrientation;
|
||||||
|
glm::vec3 absScale(1);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||||
|
entity = m_World->GetEntityParent(entity);
|
||||||
|
auto transform2 = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||||
|
|
||||||
|
// Position
|
||||||
|
if (entity == 0)
|
||||||
|
absPosition += transform->Position;
|
||||||
|
else
|
||||||
|
absPosition = transform2->Orientation * (absPosition + transform->Position);
|
||||||
|
// Orientation
|
||||||
|
absOrientation = transform->Orientation * absOrientation;
|
||||||
|
// Scale
|
||||||
|
absScale *= transform->Scale;
|
||||||
|
} while (entity != 0);
|
||||||
|
|
||||||
|
Components::Transform transform;
|
||||||
|
transform.Position = absPosition;
|
||||||
|
transform.Orientation = absOrientation;
|
||||||
|
transform.Scale = absScale;
|
||||||
|
|
||||||
|
return transform;
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public:
|
|||||||
//void Update(double dt) override;
|
//void Update(double dt) override;
|
||||||
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
|
||||||
|
Components::Transform AbsoluteTransform(EntityID entity);
|
||||||
glm::vec3 AbsolutePosition(EntityID entity);
|
glm::vec3 AbsolutePosition(EntityID entity);
|
||||||
glm::quat AbsoluteOrientation(EntityID entity);
|
glm::quat AbsoluteOrientation(EntityID entity);
|
||||||
glm::vec3 AbsoluteScale(EntityID entity);
|
glm::vec3 AbsoluteScale(EntityID entity);
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ void Texture::Load(std::string path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_Texture = m_TextureCache[path];
|
m_Texture = m_TextureCache[path];
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_Texture);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::Bind()
|
void Texture::Bind()
|
||||||
|
|||||||
+95
-95
@@ -1,95 +1,95 @@
|
|||||||
#ifndef Util_Rectangle_h__
|
//#ifndef Util_Rectangle_h__
|
||||||
#define Util_Rectangle_h__
|
//#define Util_Rectangle_h__
|
||||||
|
//
|
||||||
#include <algorithm>
|
//#include <algorithm>
|
||||||
|
//
|
||||||
struct Rectangle
|
//struct Rectangle
|
||||||
{
|
//{
|
||||||
Rectangle()
|
// Rectangle()
|
||||||
: X(0), Y(0), Width(0), Height(0) { }
|
// : X(0), Y(0), Width(0), Height(0) { }
|
||||||
|
//
|
||||||
Rectangle(int x, int y, int width = 0, int height = 0)
|
// Rectangle(int x, int y, int width = 0, int height = 0)
|
||||||
: X(x), Y(y), Width(width), Height(height) { }
|
// : X(x), Y(y), Width(width), Height(height) { }
|
||||||
|
//
|
||||||
/*Rectangle(const Rectangle &rect)
|
// /*Rectangle(const Rectangle &rect)
|
||||||
: X(rect.X), Y(rect.Y), Width(rect.Width), Height(rect.Height) { }*/
|
// : X(rect.X), Y(rect.Y), Width(rect.Width), Height(rect.Height) { }*/
|
||||||
|
//
|
||||||
int X;
|
// int X;
|
||||||
int Y;
|
// int Y;
|
||||||
int Width;
|
// int Width;
|
||||||
int Height;
|
// int Height;
|
||||||
|
//
|
||||||
const int& GetLeft() const { return X; }
|
// const int& GetLeft() const { return X; }
|
||||||
void SetLeft(int left)
|
// void SetLeft(int left)
|
||||||
{
|
// {
|
||||||
Width += X - left;
|
// Width += X - left;
|
||||||
X = left;
|
// X = left;
|
||||||
}
|
// }
|
||||||
int GetRight() const { return X + Width; }
|
// int GetRight() const { return X + Width; }
|
||||||
void SetRight(int right)
|
// void SetRight(int right)
|
||||||
{
|
// {
|
||||||
Width = right - X;
|
// Width = right - X;
|
||||||
}
|
// }
|
||||||
const int& GetTop() const { return Y; }
|
// const int& GetTop() const { return Y; }
|
||||||
void SetTop(int top)
|
// void SetTop(int top)
|
||||||
{
|
// {
|
||||||
Height += Y - top;
|
// Height += Y - top;
|
||||||
Y = top;
|
// Y = top;
|
||||||
}
|
// }
|
||||||
int GetBottom() const { return Y + Height; }
|
// int GetBottom() const { return Y + Height; }
|
||||||
int SetBottom(int bottom)
|
// int SetBottom(int bottom)
|
||||||
{
|
// {
|
||||||
Height = bottom - Y;
|
// Height = bottom - Y;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Rectangle& operator+=(const Rectangle &rhs)
|
// Rectangle& operator+=(const Rectangle &rhs)
|
||||||
{
|
// {
|
||||||
SetLeft(std::min(GetLeft(), rhs.GetLeft()));
|
// SetLeft(std::min(GetLeft(), rhs.GetLeft()));
|
||||||
SetRight(std::max(GetRight(), rhs.GetRight()));
|
// SetRight(std::max(GetRight(), rhs.GetRight()));
|
||||||
SetTop(std::min(GetTop(), rhs.GetTop()));
|
// SetTop(std::min(GetTop(), rhs.GetTop()));
|
||||||
SetBottom(std::max(GetBottom(), rhs.GetBottom()));
|
// SetBottom(std::max(GetBottom(), rhs.GetBottom()));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
static bool Intersects(const Rectangle &r1, const Rectangle &r2)
|
// static bool Intersects(const Rectangle &r1, const Rectangle &r2)
|
||||||
{
|
// {
|
||||||
return !(r2.GetLeft() > r1.GetRight() || r2.GetRight() < r1.GetLeft() || r2.GetTop() > r1.GetBottom() || r2.GetBottom() < r1.GetTop());
|
// return !(r2.GetLeft() > r1.GetRight() || r2.GetRight() < r1.GetLeft() || r2.GetTop() > r1.GetBottom() || r2.GetBottom() < r1.GetTop());
|
||||||
}
|
// }
|
||||||
};
|
//};
|
||||||
|
//
|
||||||
inline bool operator==(const Rectangle &r1, const Rectangle &r2)
|
//inline bool operator==(const Rectangle &r1, const Rectangle &r2)
|
||||||
{
|
//{
|
||||||
return (r1.X == r2.X) && (r1.Y == r2.Y) && (r1.Width == r2.Width) && (r1.Height == r2.Height);
|
// return (r1.X == r2.X) && (r1.Y == r2.Y) && (r1.Width == r2.Width) && (r1.Height == r2.Height);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
inline bool operator!=(const Rectangle &lhs, const Rectangle &rhs)
|
//inline bool operator!=(const Rectangle &lhs, const Rectangle &rhs)
|
||||||
{
|
//{
|
||||||
return !(lhs == rhs);
|
// return !(lhs == rhs);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
inline bool operator<(const Rectangle &lhs, const Rectangle &rhs)
|
//inline bool operator<(const Rectangle &lhs, const Rectangle &rhs)
|
||||||
{
|
//{
|
||||||
return (lhs.Width < rhs.Width) && (lhs.Height < rhs.Height);
|
// return (lhs.Width < rhs.Width) && (lhs.Height < rhs.Height);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
inline bool operator>(const Rectangle &lhs, const Rectangle &rhs)
|
//inline bool operator>(const Rectangle &lhs, const Rectangle &rhs)
|
||||||
{
|
//{
|
||||||
return rhs < lhs;
|
// return rhs < lhs;
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
inline bool operator<=(const Rectangle &lhs, const Rectangle &rhs)
|
//inline bool operator<=(const Rectangle &lhs, const Rectangle &rhs)
|
||||||
{
|
//{
|
||||||
return !(lhs > rhs);
|
// return !(lhs > rhs);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
inline bool operator>=(const Rectangle &lhs, const Rectangle &rhs)
|
//inline bool operator>=(const Rectangle &lhs, const Rectangle &rhs)
|
||||||
{
|
//{
|
||||||
return !(lhs < rhs);
|
// return !(lhs < rhs);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
inline Rectangle operator+(Rectangle lhs, const Rectangle &rhs)
|
//inline Rectangle operator+(Rectangle lhs, const Rectangle &rhs)
|
||||||
{
|
//{
|
||||||
lhs += rhs;
|
// lhs += rhs;
|
||||||
return lhs;
|
// return lhs;
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
#endif // Util_Rectangle_h__
|
//#endif // Util_Rectangle_h__
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef Util_UnorderedMapPair_h__
|
||||||
|
#define Util_UnorderedMapPair_h__
|
||||||
|
|
||||||
|
#include <boost/functional/hash.hpp>
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
template<typename S, typename T> struct hash<pair<S, T>>
|
||||||
|
{
|
||||||
|
inline size_t operator()(const pair<S, T> & v) const
|
||||||
|
{
|
||||||
|
size_t seed = 0;
|
||||||
|
boost::hash_combine(seed, v.first);
|
||||||
|
boost::hash_combine(seed, v.second);
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // Util_UnorderedMapPair_h__
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#ifndef UTIL_H
|
||||||
|
#define UTIL_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define ZERO_MEM(a) memset(a, 0, sizeof(a))
|
||||||
|
|
||||||
|
#define ARRAY_SIZE_IN_ELEMENTS(a) (sizeof(a)/sizeof(a[0]))
|
||||||
|
|
||||||
|
#define INVALID_OGL_VALUE 0xFFFFFFFF
|
||||||
|
|
||||||
|
#define SAFE_DELETE(p) if (p) { delete p; p = NULL; }
|
||||||
|
|
||||||
|
#define GLExitIfError() \
|
||||||
|
{ \
|
||||||
|
GLenum Error = glGetError(); \
|
||||||
|
\
|
||||||
|
if (Error != GL_NO_ERROR) { \
|
||||||
|
printf("OpenGL error in %s:%d: 0x%x\n", __FILE__, __LINE__, Error); \
|
||||||
|
exit(0); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define GLCheckError() (glGetError() == GL_NO_ERROR)
|
||||||
|
|
||||||
|
#endif /* UTIL_H */
|
||||||
+61
-7
@@ -22,16 +22,13 @@ EntityID World::GenerateEntityID()
|
|||||||
|
|
||||||
void World::RecursiveUpdate(std::shared_ptr<System> system, double dt, EntityID parentEntity)
|
void World::RecursiveUpdate(std::shared_ptr<System> system, double dt, EntityID parentEntity)
|
||||||
{
|
{
|
||||||
for (auto pair : m_EntityParents)
|
for (auto &pair : m_EntityParents)
|
||||||
{
|
{
|
||||||
EntityID child = pair.first;
|
EntityID child = pair.first;
|
||||||
EntityID parent = pair.second;
|
EntityID parent = pair.second;
|
||||||
|
|
||||||
if (parent == parentEntity)
|
system->UpdateEntity(dt, child, parent);
|
||||||
{
|
//RecursiveUpdate(system, dt, child);
|
||||||
system->UpdateEntity(dt, child, parent);
|
|
||||||
RecursiveUpdate(system, dt, child);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,6 +90,7 @@ void World::ProcessEntityRemovals()
|
|||||||
for (auto entity : m_EntitiesToRemove)
|
for (auto entity : m_EntitiesToRemove)
|
||||||
{
|
{
|
||||||
m_EntityParents.erase(entity);
|
m_EntityParents.erase(entity);
|
||||||
|
m_EntityChildren.erase(entity);
|
||||||
// Remove components
|
// Remove components
|
||||||
for (auto pair : m_EntityComponents[entity])
|
for (auto pair : m_EntityComponents[entity])
|
||||||
{
|
{
|
||||||
@@ -116,7 +114,8 @@ void World::ProcessEntityRemovals()
|
|||||||
EntityID World::CreateEntity(EntityID parent /*= 0*/)
|
EntityID World::CreateEntity(EntityID parent /*= 0*/)
|
||||||
{
|
{
|
||||||
EntityID newEntity = GenerateEntityID();
|
EntityID newEntity = GenerateEntityID();
|
||||||
m_EntityParents.insert(std::pair<EntityID, EntityID>(newEntity, parent));
|
m_EntityParents[newEntity] = parent;
|
||||||
|
m_EntityChildren[parent].push_back(newEntity);
|
||||||
return newEntity;
|
return newEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +146,62 @@ void World::CommitEntity(EntityID entity)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void World::AddComponent(EntityID entity, std::string componentType, std::shared_ptr<Component> component)
|
||||||
|
{
|
||||||
|
component->Entity = entity;
|
||||||
|
m_ComponentsOfType[componentType].push_back(component);
|
||||||
|
m_EntityComponents[entity][componentType] = component;
|
||||||
|
for (auto pair : m_Systems)
|
||||||
|
{
|
||||||
|
auto system = pair.second;
|
||||||
|
system->OnComponentCreated(componentType, component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void World::AddSystem(std::string systemType)
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EntityID World::CloneEntity(EntityID entity, EntityID parent /* = 0 */)
|
||||||
|
{
|
||||||
|
int clone = CreateEntity(parent);
|
||||||
|
|
||||||
|
for (auto pair : m_EntityComponents[entity])
|
||||||
|
{
|
||||||
|
auto type = pair.first;
|
||||||
|
if (type == "Template")
|
||||||
|
continue;
|
||||||
|
auto component = std::shared_ptr<Component>(pair.second->Clone());
|
||||||
|
if (component != nullptr)
|
||||||
|
{
|
||||||
|
AddComponent(clone, type, component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto itChildren = m_EntityChildren.find(entity);
|
||||||
|
if (itChildren != m_EntityChildren.end())
|
||||||
|
{
|
||||||
|
for (EntityID child : itChildren->second)
|
||||||
|
{
|
||||||
|
CloneEntity(child, clone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CommitEntity(clone);
|
||||||
|
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<EntityID> World::GetEntityChildren(EntityID entity)
|
||||||
|
{
|
||||||
|
auto it = m_EntityChildren.find(entity);
|
||||||
|
if (it == m_EntityChildren.end())
|
||||||
|
{
|
||||||
|
return std::list<EntityID>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+22
-11
@@ -37,6 +37,7 @@ public:
|
|||||||
std::shared_ptr<T> GetSystem(std::string systemType);
|
std::shared_ptr<T> GetSystem(std::string systemType);
|
||||||
|
|
||||||
EntityID CreateEntity(EntityID parent = 0);
|
EntityID CreateEntity(EntityID parent = 0);
|
||||||
|
EntityID CloneEntity(EntityID entity, EntityID parent = 0);
|
||||||
|
|
||||||
void RemoveEntity(EntityID entity);
|
void RemoveEntity(EntityID entity);
|
||||||
|
|
||||||
@@ -44,6 +45,7 @@ public:
|
|||||||
|
|
||||||
EntityID GetEntityParent(EntityID entity);
|
EntityID GetEntityParent(EntityID entity);
|
||||||
EntityID GetEntityBaseParent(EntityID entity);
|
EntityID GetEntityBaseParent(EntityID entity);
|
||||||
|
std::list<EntityID> GetEntityChildren(EntityID entity);
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
T GetProperty(EntityID entity, std::string property)
|
T GetProperty(EntityID entity, std::string property)
|
||||||
@@ -61,6 +63,11 @@ public:
|
|||||||
m_EntityProperties[entity][property] = value;
|
m_EntityProperties[entity][property] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetProperty(EntityID entity, std::string property, char* value)
|
||||||
|
{
|
||||||
|
m_EntityProperties[entity][property] = std::string(value);
|
||||||
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
std::shared_ptr<T> AddComponent(EntityID entity, std::string componentType);
|
std::shared_ptr<T> AddComponent(EntityID entity, std::string componentType);
|
||||||
std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType);
|
std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType);
|
||||||
@@ -90,13 +97,16 @@ protected:
|
|||||||
|
|
||||||
EntityID m_LastEntityID;
|
EntityID m_LastEntityID;
|
||||||
std::stack<EntityID> m_RecycledEntityIDs;
|
std::stack<EntityID> m_RecycledEntityIDs;
|
||||||
// A bottom to top tree. A map of child entities to parent entities.
|
|
||||||
std::unordered_map<EntityID, EntityID> m_EntityParents;
|
|
||||||
std::unordered_map<EntityID, std::unordered_map<std::string, boost::any>> m_EntityProperties;
|
|
||||||
|
|
||||||
|
std::unordered_map<EntityID, EntityID> m_EntityParents; // child -> parent
|
||||||
|
std::unordered_map<EntityID, std::list<EntityID>> m_EntityChildren; // parent -> child
|
||||||
|
std::unordered_map<EntityID, std::unordered_map<std::string, boost::any>> m_EntityProperties;
|
||||||
std::unordered_map<std::string, std::list<std::shared_ptr<Component>>> m_ComponentsOfType;
|
std::unordered_map<std::string, std::list<std::shared_ptr<Component>>> m_ComponentsOfType;
|
||||||
std::unordered_map<EntityID, std::map<std::string, std::shared_ptr<Component>>> m_EntityComponents;
|
std::unordered_map<EntityID, std::map<std::string, std::shared_ptr<Component>>> m_EntityComponents;
|
||||||
|
|
||||||
|
// Internal: Add a component to an entity
|
||||||
|
void AddComponent(EntityID entity, std::string componentType, std::shared_ptr<Component> component);
|
||||||
|
|
||||||
std::list<EntityID> m_EntitiesToRemove;
|
std::list<EntityID> m_EntitiesToRemove;
|
||||||
void ProcessEntityRemovals();
|
void ProcessEntityRemovals();
|
||||||
|
|
||||||
@@ -128,14 +138,8 @@ std::shared_ptr<T> World::AddComponent(EntityID entity, std::string componentTyp
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
component->Entity = entity;
|
AddComponent(entity, componentType, component);
|
||||||
m_ComponentsOfType[componentType].push_back(component);
|
|
||||||
m_EntityComponents[entity][componentType] = component;
|
|
||||||
for (auto pair : m_Systems)
|
|
||||||
{
|
|
||||||
auto system = pair.second;
|
|
||||||
system->OnComponentCreated(componentType, component);
|
|
||||||
}
|
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +147,14 @@ std::shared_ptr<T> World::AddComponent(EntityID entity, std::string componentTyp
|
|||||||
template <class T>
|
template <class T>
|
||||||
T* World::GetComponent(EntityID entity, std::string componentType)
|
T* World::GetComponent(EntityID entity, std::string componentType)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/*auto it0 = m_EntityComponents.find(entity);
|
||||||
|
|
||||||
|
if (it0 == m_EntityComponents.end())
|
||||||
|
return nullptr;*/
|
||||||
|
|
||||||
auto components = m_EntityComponents[entity];
|
auto components = m_EntityComponents[entity];
|
||||||
|
|
||||||
auto it = components.find(componentType);
|
auto it = components.find(componentType);
|
||||||
if (it != components.end())
|
if (it != components.end())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
#include "PrecompiledHeader.h"
|
|
||||||
#include "gBuffer.h"
|
|
||||||
|
|
||||||
bool GBuffer::Init(unsigned int WindowWidth, unsigned int WindowHeight)
|
|
||||||
{
|
|
||||||
// Create the FBO
|
|
||||||
glGenFramebuffers(1, &m_fbo);
|
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo);
|
|
||||||
|
|
||||||
// Create the gbuffer textures
|
|
||||||
glGenTextures(ARRAY_SIZE_IN_ELEMENTS(m_textures), m_textures);
|
|
||||||
glGenTextures(1, &m_depthTexture);
|
|
||||||
|
|
||||||
for (unsigned int i = 0 ; i < ARRAY_SIZE_IN_ELEMENTS(m_textures) ; i++) {
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_textures[i]);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, WindowWidth, WindowHeight, 0, GL_RGB, GL_FLOAT, NULL);
|
|
||||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, m_textures[i], 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// depth
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_depthTexture);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, WindowWidth, WindowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
|
|
||||||
NULL);
|
|
||||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthTexture, 0);
|
|
||||||
|
|
||||||
GLenum DrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
|
|
||||||
glDrawBuffers(ARRAY_SIZE_IN_ELEMENTS(DrawBuffers), DrawBuffers);
|
|
||||||
|
|
||||||
GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
|
||||||
|
|
||||||
if (Status != GL_FRAMEBUFFER_COMPLETE) {
|
|
||||||
printf("FB error, status: 0x%x\n", Status);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// restore default FBO
|
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
#ifndef gBuffer_h__
|
|
||||||
#define gBuffer_h__
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
class GBuffer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
enum GBUFFER_TEXTURE_TYPE {
|
|
||||||
GBUFFER_TEXTURE_TYPE_POSITION,
|
|
||||||
GBUFFER_TEXTURE_TYPE_DIFFUSE,
|
|
||||||
GBUFFER_TEXTURE_TYPE_NORMAL,
|
|
||||||
GBUFFER_TEXTURE_TYPE_TEXCOORD,
|
|
||||||
GBUFFER_NUM_TEXTURES
|
|
||||||
};
|
|
||||||
|
|
||||||
GBuffer();
|
|
||||||
|
|
||||||
~GBuffer();
|
|
||||||
|
|
||||||
bool Init(unsigned int WindowWidth, unsigned int WindowHeight);
|
|
||||||
|
|
||||||
void BindForWriting();
|
|
||||||
|
|
||||||
void BindForReading();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
GLuint m_fbo;
|
|
||||||
GLuint m_textures[GBUFFER_NUM_TEXTURES];
|
|
||||||
GLuint m_depthTexture;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //gBuffer_h__
|
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<VSPerformanceSession Version="1.00">
|
||||||
|
<Options>
|
||||||
|
<Solution>Returngeance.sln</Solution>
|
||||||
|
<CollectionMethod>Sampling</CollectionMethod>
|
||||||
|
<AllocationMethod>None</AllocationMethod>
|
||||||
|
<AddReport>true</AddReport>
|
||||||
|
<ResourceBasedAnalysisSelected>true</ResourceBasedAnalysisSelected>
|
||||||
|
<UniqueReport>Timestamp</UniqueReport>
|
||||||
|
<SamplingMethod>Cycles</SamplingMethod>
|
||||||
|
<CycleCount>10000000</CycleCount>
|
||||||
|
<PageFaultCount>10</PageFaultCount>
|
||||||
|
<SysCallCount>10</SysCallCount>
|
||||||
|
<SamplingCounter Name="" ReloadValue="00000000000f4240" DisplayName="" />
|
||||||
|
<RelocateBinaries>false</RelocateBinaries>
|
||||||
|
<HardwareCounters EnableHWCounters="false" />
|
||||||
|
<EtwSettings />
|
||||||
|
<PdhSettings>
|
||||||
|
<PdhCountersEnabled>false</PdhCountersEnabled>
|
||||||
|
<PdhCountersRate>500</PdhCountersRate>
|
||||||
|
<PdhCounters>
|
||||||
|
<PdhCounter>\Memory\Pages/sec</PdhCounter>
|
||||||
|
<PdhCounter>\PhysicalDisk(_Total)\Avg. Disk Queue Length</PdhCounter>
|
||||||
|
<PdhCounter>\Processor(_Total)\% Processor Time</PdhCounter>
|
||||||
|
</PdhCounters>
|
||||||
|
</PdhSettings>
|
||||||
|
</Options>
|
||||||
|
<ExcludeSmallFuncs>true</ExcludeSmallFuncs>
|
||||||
|
<InteractionProfilingEnabled>false</InteractionProfilingEnabled>
|
||||||
|
<JScriptProfilingEnabled>false</JScriptProfilingEnabled>
|
||||||
|
<PreinstrumentEvent>
|
||||||
|
<InstrEventExclude>false</InstrEventExclude>
|
||||||
|
</PreinstrumentEvent>
|
||||||
|
<PostinstrumentEvent>
|
||||||
|
<InstrEventExclude>false</InstrEventExclude>
|
||||||
|
</PostinstrumentEvent>
|
||||||
|
<Binaries>
|
||||||
|
<ProjBinary>
|
||||||
|
<Path>bin\Debug\Returngeance.exe</Path>
|
||||||
|
<ArgumentTimestamp>01/01/0001 00:00:00</ArgumentTimestamp>
|
||||||
|
<Instrument>true</Instrument>
|
||||||
|
<Sample>true</Sample>
|
||||||
|
<ExternalWebsite>false</ExternalWebsite>
|
||||||
|
<InteractionProfilingEnabled>false</InteractionProfilingEnabled>
|
||||||
|
<IsLocalJavascript>false</IsLocalJavascript>
|
||||||
|
<IsWindowsStoreApp>false</IsWindowsStoreApp>
|
||||||
|
<IsWWA>false</IsWWA>
|
||||||
|
<LaunchProject>true</LaunchProject>
|
||||||
|
<OverrideProjectSettings>false</OverrideProjectSettings>
|
||||||
|
<LaunchMethod>Executable</LaunchMethod>
|
||||||
|
<ExecutablePath>bin\Debug\Returngeance.exe</ExecutablePath>
|
||||||
|
<StartupDirectory>..\bin\Debug</StartupDirectory>
|
||||||
|
<Arguments>
|
||||||
|
</Arguments>
|
||||||
|
<NetAppHost>IIS</NetAppHost>
|
||||||
|
<NetBrowser>InternetExplorer</NetBrowser>
|
||||||
|
<ExcludeSmallFuncs>true</ExcludeSmallFuncs>
|
||||||
|
<JScriptProfilingEnabled>false</JScriptProfilingEnabled>
|
||||||
|
<PreinstrumentEvent>
|
||||||
|
<InstrEventExclude>false</InstrEventExclude>
|
||||||
|
</PreinstrumentEvent>
|
||||||
|
<PostinstrumentEvent>
|
||||||
|
<InstrEventExclude>false</InstrEventExclude>
|
||||||
|
</PostinstrumentEvent>
|
||||||
|
<ProjRef>{E8B4A2A2-882B-402A-98A7-8B4F7233C8B3}|Returngeance\Returngeance.vcxproj</ProjRef>
|
||||||
|
<ProjPath>Returngeance\Returngeance.vcxproj</ProjPath>
|
||||||
|
<ProjName>Returngeance</ProjName>
|
||||||
|
</ProjBinary>
|
||||||
|
</Binaries>
|
||||||
|
<Reports>
|
||||||
|
<Report>
|
||||||
|
<Path>Returngeance140427.vsp</Path>
|
||||||
|
</Report>
|
||||||
|
<Report>
|
||||||
|
<Path>Returngeance140427(1).vsp</Path>
|
||||||
|
</Report>
|
||||||
|
</Reports>
|
||||||
|
<Launches>
|
||||||
|
<ProjBinary>
|
||||||
|
<Path>:PB:{E8B4A2A2-882B-402A-98A7-8B4F7233C8B3}|Returngeance\Returngeance.vcxproj</Path>
|
||||||
|
</ProjBinary>
|
||||||
|
</Launches>
|
||||||
|
</VSPerformanceSession>
|
||||||
@@ -39,33 +39,33 @@
|
|||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<PropertyGroup Label="UserMacros" />
|
<PropertyGroup Label="UserMacros" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<IncludePath>$(HAVOK_2013_1_0_r1_ROOT)\Source;$(BOOST_1_55_0_ROOT);$(SolutionDir)\..\src;$(SolutionDir)\..\libs;$(SolutionDir)\..\libs\glew-1.10.0\include;$(SolutionDir)\..\libs\glfw-3.0.4\include;$(SolutionDir)\..\libs\glm-0.9.5.3;$(SolutionDir)\..\libs\openal-soft-1.15.1\include;$(SolutionDir)\..\libs\bullet-2.82-r2704\src;$(SolutionDir)\..\libs\SOIL\src;$(IncludePath)</IncludePath>
|
<IncludePath>$(HAVOK_2013_1_0_r1_ROOT)\Source;$(BOOST_1_55_0_ROOT);$(SolutionDir)\..\src;$(SolutionDir)\..\libs;$(SolutionDir)\..\libs\glew-1.10.0\include;$(SolutionDir)\..\libs\glfw-3.0.4\include;$(SolutionDir)\..\libs\glm-0.9.5.3;$(SolutionDir)\..\libs\openal-soft-1.15.1\include;$(SolutionDir)\..\libs\bullet-2.82-r2704\src;$(SolutionDir)\..\libs\SOIL\src;$(DXSDK_DIR)\Include;$(IncludePath)</IncludePath>
|
||||||
<LibraryPath>$(HAVOK_2013_1_0_r1_ROOT)\Lib\win32_vs2012_win7\debug_dll;$(BOOST_1_55_0_ROOT)\lib32-msvc-11.0;$(SolutionDir)\..\libs\glew-1.10.0\lib\Debug\Win32;$(SolutionDir)\..\libs\glfw-3.0.4\lib\Debug;$(SolutionDir)\..\libs\openal-soft-1.15.1\lib\Win32\Debug;$(SolutionDir)\..\libs\bullet-2.82-r2704\lib\Debug;$(SolutionDir)\..\libs\SOIL\lib\Debug;$(LibraryPath)</LibraryPath>
|
<LibraryPath>$(HAVOK_2013_1_0_r1_ROOT)\Lib\win32_vs2012_win7\debug_dll;$(BOOST_1_55_0_ROOT)\lib32-msvc-11.0;$(SolutionDir)\..\libs\glew-1.10.0\lib\Debug\Win32;$(SolutionDir)\..\libs\glfw-3.0.4\lib\Debug;$(SolutionDir)\..\libs\openal-soft-1.15.1\lib\Win32\Debug;$(SolutionDir)\..\libs\bullet-2.82-r2704\lib\Debug;$(SolutionDir)\..\libs\SOIL\lib\Debug;$(LibraryPath);$(DXSDK_DIR)\Lib\x86</LibraryPath>
|
||||||
<OutDir>$(SolutionDir)\..\bin\$(Configuration)\</OutDir>
|
<OutDir>$(SolutionDir)\..\bin\$(Configuration)\</OutDir>
|
||||||
<IntDir>$(SolutionDir)\..\obj\$(Configuration)\</IntDir>
|
<IntDir>$(SolutionDir)\..\obj\$(Configuration)\</IntDir>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<IncludePath>$(HAVOK_2013_1_0_r1_ROOT)\Source;$(BOOST_1_55_0_ROOT);$(SolutionDir)\..\src;$(SolutionDir)\..\libs;$(SolutionDir)\..\libs\glew-1.10.0\include;$(SolutionDir)\..\libs\glfw-3.0.4\include;$(SolutionDir)\..\libs\glm-0.9.5.3;$(SolutionDir)\..\libs\openal-soft-1.15.1\include;$(SolutionDir)\..\libs\bullet-2.82-r2704\src;$(SolutionDir)\..\libs\SOIL\src;$(IncludePath)</IncludePath>
|
<IncludePath>$(HAVOK_2013_1_0_r1_ROOT)\Source;$(BOOST_1_55_0_ROOT);$(SolutionDir)\..\src;$(SolutionDir)\..\libs;$(SolutionDir)\..\libs\glew-1.10.0\include;$(SolutionDir)\..\libs\glfw-3.0.4\include;$(SolutionDir)\..\libs\glm-0.9.5.3;$(SolutionDir)\..\libs\openal-soft-1.15.1\include;$(SolutionDir)\..\libs\bullet-2.82-r2704\src;$(SolutionDir)\..\libs\SOIL\src;$(DXSDK_DIR)\Include;$(IncludePath)</IncludePath>
|
||||||
<LibraryPath>$(HAVOK_2013_1_0_r1_ROOT)\Lib\win32_vs2012_win7\release_dll;$(BOOST_1_55_0_ROOT)\lib32-msvc-11.0;$(SolutionDir)\..\libs\glfw-3.0.4\lib\Release;$(SolutionDir)\..\libs\glew-1.10.0\lib\Release\Win32;$(SolutionDir)\..\libs\openal-soft-1.15.1\lib\Win32\Release;$(SolutionDir)\..\libs\bullet-2.82-r2704\lib\Release;$(SolutionDir)\..\libs\SOIL\lib\Release;$(LibraryPath)</LibraryPath>
|
<LibraryPath>$(HAVOK_2013_1_0_r1_ROOT)\Lib\win32_vs2012_win7\release_dll;$(BOOST_1_55_0_ROOT)\lib32-msvc-11.0;$(SolutionDir)\..\libs\glfw-3.0.4\lib\Release;$(SolutionDir)\..\libs\glew-1.10.0\lib\Release\Win32;$(SolutionDir)\..\libs\openal-soft-1.15.1\lib\Win32\Release;$(SolutionDir)\..\libs\bullet-2.82-r2704\lib\Release;$(SolutionDir)\..\libs\SOIL\lib\Release;$(LibraryPath);$(DXSDK_DIR)\Lib\x86</LibraryPath>
|
||||||
<OutDir>$(SolutionDir)\..\bin\$(Configuration)\</OutDir>
|
<OutDir>$(SolutionDir)\..\bin\$(Configuration)\</OutDir>
|
||||||
<IntDir>$(SolutionDir)\..\obj\$(Configuration)\</IntDir>
|
<IntDir>$(SolutionDir)\..\obj\$(Configuration)\</IntDir>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<Optimization>Disabled</Optimization>
|
<PreprocessorDefinitions>_X86_;_WINDOWS;WIN32;_WIN32;_DEBUG;HK_DEBUG;HK_DEBUG_SLOW;_XT_STATICLINK;_CONSOLE;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;HK_CONFIG_SIMD=1;DEBUG;_CRT_SECURE_NO_WARNINGS;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<SDLCheck>true</SDLCheck>
|
|
||||||
<PreprocessorDefinitions>_WINDOWS;WIN32;_WIN32;_DEBUG;HK_DEBUG;HK_DEBUG_SLOW;_XT_STATICLINK;_CONSOLE;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;HK_CONFIG_SIMD=1;DEBUG;_CRT_SECURE_NO_WARNINGS;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||||
<PrecompiledHeaderFile>PrecompiledHeader.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>PrecompiledHeader.h</PrecompiledHeaderFile>
|
||||||
<BrowseInformation>true</BrowseInformation>
|
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||||
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
|
|
||||||
<CompileAsManaged>false</CompileAsManaged>
|
<CompileAsManaged>false</CompileAsManaged>
|
||||||
|
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
||||||
|
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32d.lib;glfw3.lib;hkBase.lib;hkVisualize.lib;hkInternal.lib;hkSerialize.lib;hkGeometryUtilities.lib;hkcdInternal.lib;hkcdCollide.lib;hkpCollide.lib;hkpConstraint.lib;hkpConstraintSolver.lib;hkpDynamics.lib;hkpInternal.lib;hkpUtilities.lib;hkSceneData.lib;hkpVehicle.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;XInput9_1_0.lib;glew32d.lib;glfw3.lib;hkBase.lib;hkVisualize.lib;hkInternal.lib;hkSerialize.lib;hkGeometryUtilities.lib;hkcdInternal.lib;hkcdCollide.lib;hkpCollide.lib;hkpConstraint.lib;hkpConstraintSolver.lib;hkpDynamics.lib;hkpInternal.lib;hkpUtilities.lib;hkSceneData.lib;hkpVehicle.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<AdditionalOptions> /ignore:4221</AdditionalOptions>
|
<AdditionalOptions> /ignore:4221</AdditionalOptions>
|
||||||
</Link>
|
</Link>
|
||||||
<CustomBuildStep />
|
<CustomBuildStep />
|
||||||
@@ -80,7 +80,7 @@
|
|||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_X86_;_CRT_SECURE_NO_WARNINGS;_MBCS;HK_CONFIG_SIMD=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||||
<PrecompiledHeaderFile>PrecompiledHeader.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>PrecompiledHeader.h</PrecompiledHeaderFile>
|
||||||
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
|
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32.lib;glfw3.lib;hkBase.lib;hkVisualize.lib;hkInternal.lib;hkSerialize.lib;hkGeometryUtilities.lib;hkcdInternal.lib;hkcdCollide.lib;hkpCollide.lib;hkpConstraint.lib;hkpConstraintSolver.lib;hkpDynamics.lib;hkpInternal.lib;hkpUtilities.lib;hkSceneData.lib;hkpVehicle.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;XInput9_1_0.lib;glew32.lib;glfw3.lib;hkBase.lib;hkVisualize.lib;hkInternal.lib;hkSerialize.lib;hkGeometryUtilities.lib;hkcdInternal.lib;hkcdCollide.lib;hkpCollide.lib;hkpConstraint.lib;hkpConstraintSolver.lib;hkpDynamics.lib;hkpInternal.lib;hkpUtilities.lib;hkSceneData.lib;hkpVehicle.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
<CustomBuildStep />
|
<CustomBuildStep />
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
@@ -112,9 +112,11 @@
|
|||||||
<ClCompile Include="..\..\src\Systems\DebugSystem.cpp" />
|
<ClCompile Include="..\..\src\Systems\DebugSystem.cpp" />
|
||||||
<ClCompile Include="..\..\src\Systems\FreeSteeringSystem.cpp" />
|
<ClCompile Include="..\..\src\Systems\FreeSteeringSystem.cpp" />
|
||||||
<ClCompile Include="..\..\src\Systems\InputSystem.cpp" />
|
<ClCompile Include="..\..\src\Systems\InputSystem.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\Systems\ParticleSystem.cpp" />
|
||||||
<ClCompile Include="..\..\src\Systems\PhysicsSystem.cpp" />
|
<ClCompile Include="..\..\src\Systems\PhysicsSystem.cpp" />
|
||||||
<ClCompile Include="..\..\src\Systems\RenderSystem.cpp" />
|
<ClCompile Include="..\..\src\Systems\RenderSystem.cpp" />
|
||||||
<ClCompile Include="..\..\src\Systems\SoundSystem.cpp" />
|
<ClCompile Include="..\..\src\Systems\SoundSystem.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\Systems\TankSteeringSystem.cpp" />
|
||||||
<ClCompile Include="..\..\src\Systems\TransformSystem.cpp" />
|
<ClCompile Include="..\..\src\Systems\TransformSystem.cpp" />
|
||||||
<ClCompile Include="..\..\src\Texture.cpp" />
|
<ClCompile Include="..\..\src\Texture.cpp" />
|
||||||
<ClCompile Include="..\..\src\World.cpp" />
|
<ClCompile Include="..\..\src\World.cpp" />
|
||||||
@@ -123,27 +125,39 @@
|
|||||||
<ClInclude Include="..\..\src\Camera.h" />
|
<ClInclude Include="..\..\src\Camera.h" />
|
||||||
<ClInclude Include="..\..\src\Color.h" />
|
<ClInclude Include="..\..\src\Color.h" />
|
||||||
<ClInclude Include="..\..\src\Component.h" />
|
<ClInclude Include="..\..\src\Component.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Box.h" />
|
<ClInclude Include="..\..\src\Components\BarrelSteering.h" />
|
||||||
|
<ClInclude Include="..\..\src\Components\BoxShape.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Camera.h" />
|
<ClInclude Include="..\..\src\Components\Camera.h" />
|
||||||
<ClInclude Include="..\..\src\Components\DirectionalLight.h" />
|
<ClInclude Include="..\..\src\Components\DirectionalLight.h" />
|
||||||
|
<ClInclude Include="..\..\src\Components\ExtendedMeshShape.h" />
|
||||||
<ClInclude Include="..\..\src\Components\FreeSteering.h" />
|
<ClInclude Include="..\..\src\Components\FreeSteering.h" />
|
||||||
|
<ClInclude Include="..\..\src\Components\HingeConstraint.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Input.h" />
|
<ClInclude Include="..\..\src\Components\Input.h" />
|
||||||
|
<ClInclude Include="..\..\src\Components\MeshShape.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Model.h" />
|
<ClInclude Include="..\..\src\Components\Model.h" />
|
||||||
|
<ClInclude Include="..\..\src\Components\Particle.h" />
|
||||||
<ClInclude Include="..\..\src\Components\ParticleEmitter.h" />
|
<ClInclude Include="..\..\src\Components\ParticleEmitter.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Physics.h" />
|
<ClInclude Include="..\..\src\Components\Physics.h" />
|
||||||
<ClInclude Include="..\..\src\Components\PointLight.h" />
|
<ClInclude Include="..\..\src\Components\PointLight.h" />
|
||||||
<ClInclude Include="..\..\src\Components\SoundEmitter.h" />
|
<ClInclude Include="..\..\src\Components\SoundEmitter.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Sphere.h" />
|
<ClInclude Include="..\..\src\Components\SphereShape.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Sprite.h" />
|
<ClInclude Include="..\..\src\Components\Sprite.h" />
|
||||||
|
<ClInclude Include="..\..\src\Components\TankSteering.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Template.h" />
|
<ClInclude Include="..\..\src\Components\Template.h" />
|
||||||
|
<ClInclude Include="..\..\src\Components\TowerSteering.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Transform.h" />
|
<ClInclude Include="..\..\src\Components\Transform.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Vehicle.h" />
|
<ClInclude Include="..\..\src\Components\Vehicle.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Wheel.h" />
|
<ClInclude Include="..\..\src\Components\Wheel.h" />
|
||||||
|
<ClInclude Include="..\..\src\Components\WheelPair.h" />
|
||||||
<ClInclude Include="..\..\src\CubemapTexture.h" />
|
<ClInclude Include="..\..\src\CubemapTexture.h" />
|
||||||
<ClInclude Include="..\..\src\Engine.h" />
|
<ClInclude Include="..\..\src\Engine.h" />
|
||||||
<ClInclude Include="..\..\src\Entity.h" />
|
<ClInclude Include="..\..\src\Entity.h" />
|
||||||
|
<ClInclude Include="..\..\src\Events\BindGamepadAxis.h" />
|
||||||
|
<ClInclude Include="..\..\src\Events\BindGamepadButton.h" />
|
||||||
<ClInclude Include="..\..\src\Events\BindKey.h" />
|
<ClInclude Include="..\..\src\Events\BindKey.h" />
|
||||||
<ClInclude Include="..\..\src\Events\BindMouseButton.h" />
|
<ClInclude Include="..\..\src\Events\BindMouseButton.h" />
|
||||||
|
<ClInclude Include="..\..\src\Events\GamepadAxis.h" />
|
||||||
|
<ClInclude Include="..\..\src\Events\GamepadButton.h" />
|
||||||
<ClInclude Include="..\..\src\Events\InputCommand.h" />
|
<ClInclude Include="..\..\src\Events\InputCommand.h" />
|
||||||
<ClInclude Include="..\..\src\Events\KeyDown.h" />
|
<ClInclude Include="..\..\src\Events\KeyDown.h" />
|
||||||
<ClInclude Include="..\..\src\Events\KeyUp.h" />
|
<ClInclude Include="..\..\src\Events\KeyUp.h" />
|
||||||
@@ -151,6 +165,8 @@
|
|||||||
<ClInclude Include="..\..\src\Events\MousePress.h" />
|
<ClInclude Include="..\..\src\Events\MousePress.h" />
|
||||||
<ClInclude Include="..\..\src\Events\MouseRelease.h" />
|
<ClInclude Include="..\..\src\Events\MouseRelease.h" />
|
||||||
<ClInclude Include="..\..\src\Events\PlaySound.h" />
|
<ClInclude Include="..\..\src\Events\PlaySound.h" />
|
||||||
|
<ClInclude Include="..\..\src\Events\SetVelocity.h" />
|
||||||
|
<ClInclude Include="..\..\src\Events\TankSteer.h" />
|
||||||
<ClInclude Include="..\..\src\Factory.h" />
|
<ClInclude Include="..\..\src\Factory.h" />
|
||||||
<ClInclude Include="..\..\src\GameWorld.h" />
|
<ClInclude Include="..\..\src\GameWorld.h" />
|
||||||
<ClInclude Include="..\..\src\GUI\Frame.h" />
|
<ClInclude Include="..\..\src\GUI\Frame.h" />
|
||||||
@@ -172,19 +188,27 @@
|
|||||||
<ClInclude Include="..\..\src\Systems\DebugSystem.h" />
|
<ClInclude Include="..\..\src\Systems\DebugSystem.h" />
|
||||||
<ClInclude Include="..\..\src\Systems\FreeSteeringSystem.h" />
|
<ClInclude Include="..\..\src\Systems\FreeSteeringSystem.h" />
|
||||||
<ClInclude Include="..\..\src\Systems\InputSystem.h" />
|
<ClInclude Include="..\..\src\Systems\InputSystem.h" />
|
||||||
|
<ClInclude Include="..\..\src\Systems\ParticleSystem.h" />
|
||||||
<ClInclude Include="..\..\src\Systems\PhysicsSystem.h" />
|
<ClInclude Include="..\..\src\Systems\PhysicsSystem.h" />
|
||||||
<ClInclude Include="..\..\src\Systems\RenderSystem.h" />
|
<ClInclude Include="..\..\src\Systems\RenderSystem.h" />
|
||||||
<ClInclude Include="..\..\src\Systems\SoundSystem.h" />
|
<ClInclude Include="..\..\src\Systems\SoundSystem.h" />
|
||||||
|
<ClInclude Include="..\..\src\Systems\TankSteeringSystem.h" />
|
||||||
<ClInclude Include="..\..\src\Systems\TransformSystem.h" />
|
<ClInclude Include="..\..\src\Systems\TransformSystem.h" />
|
||||||
<ClInclude Include="..\..\src\Texture.h" />
|
<ClInclude Include="..\..\src\Texture.h" />
|
||||||
|
<ClInclude Include="..\..\src\Util\defferedUtil.h" />
|
||||||
<ClInclude Include="..\..\src\Util\GLError.h" />
|
<ClInclude Include="..\..\src\Util\GLError.h" />
|
||||||
<ClInclude Include="..\..\src\Util\Rectangle.h" />
|
<ClInclude Include="..\..\src\Util\Rectangle.h" />
|
||||||
<ClInclude Include="..\..\src\Util\Logging.h" />
|
<ClInclude Include="..\..\src\Util\Logging.h" />
|
||||||
|
<ClInclude Include="..\..\src\Util\UnorderedMapPair.h" />
|
||||||
<ClInclude Include="..\..\src\World.h" />
|
<ClInclude Include="..\..\src\World.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\..\src\Shaders\AABB.frag.glsl" />
|
<None Include="..\..\src\Shaders\AABB.frag.glsl" />
|
||||||
|
<None Include="..\..\src\Shaders\FinalPass.frag.glsl" />
|
||||||
|
<None Include="..\..\src\Shaders\FinalPass.vert.glsl" />
|
||||||
<None Include="..\..\src\Shaders\Fragment.glsl" />
|
<None Include="..\..\src\Shaders\Fragment.glsl" />
|
||||||
|
<None Include="..\..\src\Shaders\Fragment2-Debug.glsl" />
|
||||||
|
<None Include="..\..\src\Shaders\Fragment2.glsl" />
|
||||||
<None Include="..\..\src\Shaders\Normals.frag.glsl" />
|
<None Include="..\..\src\Shaders\Normals.frag.glsl" />
|
||||||
<None Include="..\..\src\Shaders\Normals.geo.glsl" />
|
<None Include="..\..\src\Shaders\Normals.geo.glsl" />
|
||||||
<None Include="..\..\src\Shaders\ShadowMap.frag.glsl" />
|
<None Include="..\..\src\Shaders\ShadowMap.frag.glsl" />
|
||||||
@@ -192,6 +216,7 @@
|
|||||||
<None Include="..\..\src\Shaders\Skybox.frag.glsl" />
|
<None Include="..\..\src\Shaders\Skybox.frag.glsl" />
|
||||||
<None Include="..\..\src\Shaders\Skybox.vert.glsl" />
|
<None Include="..\..\src\Shaders\Skybox.vert.glsl" />
|
||||||
<None Include="..\..\src\Shaders\Vertex.glsl" />
|
<None Include="..\..\src\Shaders\Vertex.glsl" />
|
||||||
|
<None Include="..\..\src\Shaders\Vertex2.glsl" />
|
||||||
<None Include="..\..\src\Shaders\VisualizeDepth.frag.glsl" />
|
<None Include="..\..\src\Shaders\VisualizeDepth.frag.glsl" />
|
||||||
<None Include="..\..\src\Shaders\VisualizeDepth.vert.glsl" />
|
<None Include="..\..\src\Shaders\VisualizeDepth.vert.glsl" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -50,11 +50,19 @@
|
|||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\ResourceManager.cpp" />
|
<ClCompile Include="..\..\src\ResourceManager.cpp" />
|
||||||
<ClCompile Include="..\..\src\Sound.cpp" />
|
<ClCompile Include="..\..\src\Sound.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\Systems\ParticleSystem.cpp">
|
||||||
|
<Filter>Particle System\Systems</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\EventBroker.cpp" />
|
<ClCompile Include="..\..\src\EventBroker.cpp" />
|
||||||
<ClCompile Include="..\..\src\Physics\VehicleSetup.cpp" />
|
<ClCompile Include="..\..\src\Physics\VehicleSetup.cpp">
|
||||||
|
<Filter>Physics</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\InputManager.cpp">
|
<ClCompile Include="..\..\src\InputManager.cpp">
|
||||||
<Filter>Input</Filter>
|
<Filter>Input</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\Systems\TankSteeringSystem.cpp">
|
||||||
|
<Filter>Physics\Systems</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="Util">
|
<Filter Include="Util">
|
||||||
@@ -126,6 +134,9 @@
|
|||||||
<Filter Include="Input\Events">
|
<Filter Include="Input\Events">
|
||||||
<UniqueIdentifier>{ee125b77-b275-4841-abc9-374957a89916}</UniqueIdentifier>
|
<UniqueIdentifier>{ee125b77-b275-4841-abc9-374957a89916}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="Physics\Events">
|
||||||
|
<UniqueIdentifier>{42ae084f-ade8-402c-87ba-f03f6b846bc8}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\World.h" />
|
<ClInclude Include="..\..\src\World.h" />
|
||||||
@@ -226,19 +237,42 @@
|
|||||||
<ClInclude Include="..\..\src\Sound.h">
|
<ClInclude Include="..\..\src\Sound.h">
|
||||||
<Filter>Audio</Filter>
|
<Filter>Audio</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\Physics\VehicleSetup.h" />
|
|
||||||
<ClInclude Include="..\..\src\Components\Box.h">
|
|
||||||
<Filter>Physics\Components</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\Components\Sphere.h">
|
|
||||||
<Filter>Physics\Components</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\Components\Vehicle.h">
|
<ClInclude Include="..\..\src\Components\Vehicle.h">
|
||||||
<Filter>Physics\Components</Filter>
|
<Filter>Physics\Components</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\Components\Wheel.h">
|
<ClInclude Include="..\..\src\Components\Wheel.h">
|
||||||
<Filter>Physics\Components</Filter>
|
<Filter>Physics\Components</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Physics\VehicleSetup.h">
|
||||||
|
<Filter>Physics</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Components\BoxShape.h">
|
||||||
|
<Filter>Physics\Components</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Components\SphereShape.h">
|
||||||
|
<Filter>Physics\Components</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Components\MeshShape.h">
|
||||||
|
<Filter>Physics\Components</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Util\UnorderedMapPair.h">
|
||||||
|
<Filter>Util</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Components\HingeConstraint.h">
|
||||||
|
<Filter>Physics\Components</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Components\ExtendedMeshShape.h">
|
||||||
|
<Filter>Physics\Components</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Components\WheelPair.h">
|
||||||
|
<Filter>Physics\Components</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Systems\ParticleSystem.h">
|
||||||
|
<Filter>Particle System\Systems</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Components\Particle.h">
|
||||||
|
<Filter>Particle System\Components</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\GUI\Frame.h">
|
<ClInclude Include="..\..\src\GUI\Frame.h">
|
||||||
<Filter>GUI</Filter>
|
<Filter>GUI</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -285,12 +319,43 @@
|
|||||||
<ClInclude Include="..\..\src\GUI\Viewport.h">
|
<ClInclude Include="..\..\src\GUI\Viewport.h">
|
||||||
<Filter>GUI</Filter>
|
<Filter>GUI</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Physics\VehicleSetup.h">
|
||||||
|
<Filter>Physics</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Components\TankSteering.h">
|
||||||
|
<Filter>Physics\Components</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Events\TankSteer.h">
|
||||||
|
<Filter>Physics\Events</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Systems\TankSteeringSystem.h">
|
||||||
|
<Filter>Physics\Systems</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Components\TowerSteering.h">
|
||||||
|
<Filter>Physics\Components</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Components\BarrelSteering.h">
|
||||||
|
<Filter>Physics\Components</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Events\SetVelocity.h">
|
||||||
|
<Filter>Physics\Events</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Events\GamepadAxis.h">
|
||||||
|
<Filter>Input\Events</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Events\GamepadButton.h">
|
||||||
|
<Filter>Input\Events</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Events\BindGamepadAxis.h">
|
||||||
|
<Filter>Input\Events</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Events\BindGamepadButton.h">
|
||||||
|
<Filter>Input\Events</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Util\defferedUtil.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\..\src\Shaders\AABB.frag.glsl">
|
<None Include="..\..\src\Shaders\Fragment2.glsl">
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="..\..\src\Shaders\Fragment.glsl">
|
|
||||||
<Filter>Shaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="..\..\src\Shaders\Normals.frag.glsl">
|
<None Include="..\..\src\Shaders\Normals.frag.glsl">
|
||||||
@@ -314,11 +379,29 @@
|
|||||||
<None Include="..\..\src\Shaders\Vertex.glsl">
|
<None Include="..\..\src\Shaders\Vertex.glsl">
|
||||||
<Filter>Shaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="..\..\src\Shaders\Vertex2.glsl">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
<None Include="..\..\src\Shaders\VisualizeDepth.frag.glsl">
|
<None Include="..\..\src\Shaders\VisualizeDepth.frag.glsl">
|
||||||
<Filter>Shaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="..\..\src\Shaders\VisualizeDepth.vert.glsl">
|
<None Include="..\..\src\Shaders\VisualizeDepth.vert.glsl">
|
||||||
<Filter>Shaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="..\..\src\Shaders\AABB.frag.glsl">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="..\..\src\Shaders\Fragment.glsl">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="..\..\src\Shaders\Fragment2-Debug.glsl">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="..\..\src\Shaders\FinalPass.vert.glsl">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="..\..\src\Shaders\FinalPass.frag.glsl">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user