Turned the Transform namespace into TransformSystem so it would be able to subscribe to EntityDeleted and clean up after itself
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
#include "../Core/AABB.h"
|
||||
#include "Rendering/RawModelCustom.h"
|
||||
//#include "Rendering/RawModelAssimp.h"
|
||||
#include "../Core/Transform.h"
|
||||
#include "../Core/TransformSystem.h"
|
||||
#include "../Core/Entity.h"
|
||||
#include "../Core/EntityWrapper.h"
|
||||
#include "EntityAABB.h"
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#ifndef Transform_h__
|
||||
#define Transform_h__
|
||||
|
||||
#include "../GLM.h"
|
||||
#include "World.h"
|
||||
#include "EntityWrapper.h"
|
||||
|
||||
namespace Transform
|
||||
{
|
||||
|
||||
//glm::mat4 AbsoluteTransformation(EntityWrapper entity);
|
||||
glm::vec3 AbsolutePosition(EntityWrapper entity);
|
||||
glm::vec3 AbsolutePosition(World* world, EntityID entity);
|
||||
glm::vec3 AbsoluteOrientationEuler(EntityWrapper entity);
|
||||
glm::quat AbsoluteOrientation(EntityWrapper entity);
|
||||
glm::quat AbsoluteOrientation(World* world, EntityID entity);
|
||||
glm::vec3 AbsoluteScale(EntityWrapper entity);
|
||||
glm::vec3 AbsoluteScale(World* world, EntityID entity);
|
||||
glm::mat4 ModelMatrix(EntityWrapper entity);
|
||||
glm::mat4 ModelMatrix(EntityID entity, World* world);
|
||||
glm::vec3 TransformPoint(const glm::vec3& point, const glm::mat4& matrix);
|
||||
|
||||
|
||||
extern int RecalculatedPositions;
|
||||
extern int RecalculatedOrientations;
|
||||
extern int RecalculatedScales;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef Transform_h__
|
||||
#define Transform_h__
|
||||
|
||||
#include "../GLM.h"
|
||||
#include "System.h"
|
||||
#include "EEntityDeleted.h"
|
||||
|
||||
class TransformSystem : public System
|
||||
{
|
||||
public:
|
||||
TransformSystem(SystemParams params);
|
||||
|
||||
//glm::mat4 AbsoluteTransformation(EntityWrapper entity);
|
||||
static glm::vec3 AbsolutePosition(EntityWrapper entity);
|
||||
static glm::vec3 AbsolutePosition(World* world, EntityID entity);
|
||||
static glm::vec3 AbsoluteOrientationEuler(EntityWrapper entity);
|
||||
static glm::quat AbsoluteOrientation(EntityWrapper entity);
|
||||
static glm::quat AbsoluteOrientation(World* world, EntityID entity);
|
||||
static glm::vec3 AbsoluteScale(EntityWrapper entity);
|
||||
static glm::vec3 AbsoluteScale(World* world, EntityID entity);
|
||||
static glm::mat4 ModelMatrix(EntityWrapper entity);
|
||||
static glm::mat4 ModelMatrix(EntityID entity, World* world);
|
||||
static glm::vec3 TransformPoint(const glm::vec3& point, const glm::mat4& matrix);
|
||||
|
||||
static int RecalculatedPositions;
|
||||
static int RecalculatedOrientations;
|
||||
static int RecalculatedScales;
|
||||
|
||||
private:
|
||||
static std::unordered_map<EntityWrapper, glm::vec3> PositionCache;
|
||||
static std::unordered_map<EntityWrapper, glm::quat> OrientationCache;
|
||||
static std::unordered_map<EntityWrapper, glm::vec3> ScaleCache;
|
||||
static std::unordered_map<EntityWrapper, glm::mat4> MatrixCache;
|
||||
|
||||
EventRelay<TransformSystem, Events::EntityDeleted> m_EEntityDeleted;
|
||||
bool OnEntityDeleted(const Events::EntityDeleted& e);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "../GLM.h"
|
||||
#include "../Core/ComponentWrapper.h"
|
||||
#include "RenderJob.h"
|
||||
#include "../Core/Transform.h"
|
||||
#include "../Core/TransformSystem.h"
|
||||
#include "../Core/World.h"
|
||||
|
||||
struct DirectionalLightJob : RenderJob
|
||||
@@ -16,7 +16,7 @@ struct DirectionalLightJob : RenderJob
|
||||
: RenderJob()
|
||||
{
|
||||
|
||||
Direction = glm::vec4(0,0,-1,0) * glm::inverse(Transform::AbsoluteOrientation(m_World, transformComponent.EntityID));
|
||||
Direction = glm::vec4(0,0,-1,0) * glm::inverse(TransformSystem::AbsoluteOrientation(m_World, transformComponent.EntityID));
|
||||
//Direction = glm::vec4((glm::vec3)directionalLightComponent["Direction"], 0.f);
|
||||
Color = (glm::vec4)directionalLightComponent["Color"];
|
||||
Intensity = (double)directionalLightComponent["Intensity"];
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "../Core/ResourceManager.h"
|
||||
#include "Camera.h"
|
||||
#include "../Core/World.h"
|
||||
#include "../Core/Transform.h"
|
||||
#include "../Core/TransformSystem.h"
|
||||
#include "Skeleton.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "BlendTree.h"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "../GLM.h"
|
||||
#include "../Core/ComponentWrapper.h"
|
||||
#include "RenderJob.h"
|
||||
#include "../Core/Transform.h"
|
||||
#include "../Core/TransformSystem.h"
|
||||
#include "../Core/World.h"
|
||||
|
||||
struct PointLightJob : RenderJob
|
||||
@@ -16,7 +16,7 @@ struct PointLightJob : RenderJob
|
||||
: RenderJob()
|
||||
{
|
||||
Position = glm::vec4((glm::vec3)transformComponent["Position"], 1.0f);
|
||||
Position = glm::vec4(Transform::AbsolutePosition(m_World, transformComponent.EntityID), 1.f);
|
||||
Position = glm::vec4(TransformSystem::AbsolutePosition(m_World, transformComponent.EntityID), 1.f);
|
||||
Color = (glm::vec4)pointLightComponent["Color"];
|
||||
Radius = (double)pointLightComponent["Radius"];
|
||||
Intensity = (double)pointLightComponent["Intensity"];
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "ModelJob.h"
|
||||
#include "Renderer.h"
|
||||
#include "PointLightJob.h"
|
||||
#include "../Core/Transform.h"
|
||||
#include "../Core/TransformSystem.h"
|
||||
#include "../Core/EPlayerSpawned.h"
|
||||
#include "../Core/Octree.h"
|
||||
#include "../Collision/EntityAABB.h"
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "../Core/EventBroker.h"
|
||||
#include "ImGuiRenderPass.h"
|
||||
#include "Camera.h"
|
||||
#include "../Core/Transform.h"
|
||||
#include "../Core/TransformSystem.h"
|
||||
#include "imgui/imgui.h"
|
||||
#include "TextPass.h"
|
||||
#include "Util/CommonFunctions.h"
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "../Core/ResourceManager.h"
|
||||
#include "Camera.h"
|
||||
#include "../Core/World.h"
|
||||
#include "../Core/Transform.h"
|
||||
#include "../Core/TransformSystem.h"
|
||||
#include "Skeleton.h"
|
||||
|
||||
struct SpriteJob : RenderJob
|
||||
@@ -37,7 +37,7 @@ struct SpriteJob : RenderJob
|
||||
BlurBackground = (bool)cSprite["BlurBackground"];
|
||||
|
||||
Entity = cSprite.EntityID;
|
||||
Position = Transform::AbsolutePosition(world, cSprite.EntityID);
|
||||
Position = TransformSystem::AbsolutePosition(world, cSprite.EntityID);
|
||||
Depth = 0;
|
||||
if (depthSorted) {
|
||||
glm::vec3 viewpos = glm::vec3(camera->ViewMatrix() * glm::vec4(Position, 1));
|
||||
@@ -50,7 +50,7 @@ struct SpriteJob : RenderJob
|
||||
FillColor = fillColor;
|
||||
FillPercentage = fillPercentage;
|
||||
|
||||
glm::vec3 scale = Transform::AbsoluteScale(world, cSprite.EntityID);
|
||||
glm::vec3 scale = TransformSystem::AbsoluteScale(world, cSprite.EntityID);
|
||||
|
||||
if((bool)cSprite["KeepRatio"] == true) {
|
||||
if(scale.y >= scale.x) {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "Core/EventBroker.h"
|
||||
#include "../Engine/Core/ResourceManager.h"
|
||||
#include "../Engine/Core/ConfigFile.h"
|
||||
#include "Core/Transform.h" // Absolute transform
|
||||
#include "Core/TransformSystem.h"
|
||||
#include "Sound/Sound.h"
|
||||
#include "../Engine/Sound/EPlayQueueOnEntity.h"
|
||||
#include "Sound/EPlaySoundOnEntity.h"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define AmmoPickupSystem_h__
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "Core/Transform.h"
|
||||
#include "Core/TransformSystem.h"
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Core/EntityFile.h"
|
||||
#include "Core/EPickupSpawned.h"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "Common.h"
|
||||
#include "Core/System.h"
|
||||
#include "Core/Transform.h"
|
||||
#include "Core/TransformSystem.h"
|
||||
#include "Core/ECaptured.h"
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define DamageIndicatorSystem_h__
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "Core/Transform.h"
|
||||
#include "Core/TransformSystem.h"
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Core/EntityFile.h"
|
||||
#include "Core/EPlayerDamage.h"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define PickupSpawnSystem_h__
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "Core/Transform.h"
|
||||
#include "Core/TransformSystem.h"
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Core/EntityFile.h"
|
||||
#include "Core/EPickupSpawned.h"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "GLM.h"
|
||||
#include "Core/System.h"
|
||||
#include "Events/ESpawnerSpawn.h"
|
||||
#include "Core/Transform.h"
|
||||
#include "Core/TransformSystem.h"
|
||||
#include "Core/EntityFile.h"
|
||||
|
||||
class SpawnerSystem : public System
|
||||
|
||||
@@ -151,9 +151,9 @@ bool RayVsModel(const Ray& ray,
|
||||
const glm::mat4& modelMatrix)
|
||||
{
|
||||
for (int i = 0; i < modelIndices.size();) {
|
||||
glm::vec3 v0 = Transform::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v1 = Transform::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v2 = Transform::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v0 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v1 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v2 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
if (RayVsTriangle(ray, v0, v1, v2)) {
|
||||
return true;
|
||||
}
|
||||
@@ -204,9 +204,9 @@ bool RayVsModel(const Ray& ray,
|
||||
outDistance = INFINITY;
|
||||
bool hit = false;
|
||||
for (int i = 0; i < modelIndices.size();) {
|
||||
glm::vec3 v0 = Transform::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v1 = Transform::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v2 = Transform::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v0 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v1 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v2 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
float dist = outDistance;
|
||||
float u;
|
||||
float v;
|
||||
@@ -565,9 +565,9 @@ Output AABBvsTriangles(const AABB& box,
|
||||
glm::vec3 originalBoxVelocity(boxVelocity);
|
||||
for (int i = 0; i < modelIndices.size(); ) {
|
||||
std::array<glm::vec3, 3> triVertices = {
|
||||
Transform::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix),
|
||||
Transform::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix),
|
||||
Transform::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix)
|
||||
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix),
|
||||
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix),
|
||||
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix)
|
||||
};
|
||||
glm::vec3 outVec;
|
||||
bool collideWithGround = isOnGround;
|
||||
@@ -674,7 +674,7 @@ boost::optional<EntityAABB> EntityAbsoluteAABB(EntityWrapper& entity, bool takeM
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
glm::mat4 modelMat = Transform::ModelMatrix(entity);
|
||||
glm::mat4 modelMat = TransformSystem::ModelMatrix(entity);
|
||||
glm::vec3 mini(INFINITY);
|
||||
glm::vec3 maxi(-INFINITY);
|
||||
glm::vec3 maxCorner = modelSpaceBox.MaxCorner();
|
||||
@@ -685,7 +685,7 @@ boost::optional<EntityAABB> EntityAbsoluteAABB(EntityWrapper& entity, bool takeM
|
||||
corner.x = bits.test(0) ? maxCorner.x : minCorner.x;
|
||||
corner.y = bits.test(1) ? maxCorner.y : minCorner.y;
|
||||
corner.z = bits.test(2) ? maxCorner.z : minCorner.z;
|
||||
corner = Transform::TransformPoint(corner, modelMat);
|
||||
corner = TransformSystem::TransformPoint(corner, modelMat);
|
||||
mini = glm::min(mini, corner);
|
||||
maxi = glm::max(maxi, corner);
|
||||
}
|
||||
@@ -741,7 +741,7 @@ boost::optional<EntityAABB> EntityFirstHitByRay(const Ray& ray, std::vector<Enti
|
||||
continue;
|
||||
}
|
||||
float u, v;
|
||||
if (RayVsModel(ray, model->Vertices(), model->m_RawModel->m_Indices, Transform::ModelMatrix(entityBox.Entity), outDistance, u, v)) {
|
||||
if (RayVsModel(ray, model->Vertices(), model->m_RawModel->m_Indices, TransformSystem::ModelMatrix(entityBox.Entity), outDistance, u, v)) {
|
||||
outIntersectPos = ray.Origin() + outDistance * ray.Direction();
|
||||
return entityBox;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
||||
continue;
|
||||
}
|
||||
float u, v;
|
||||
hit = Collision::RayVsModel(ray, model->Vertices(), model->m_Indices, Transform::ModelMatrix(boxB.Entity), dist, u, v);
|
||||
hit = Collision::RayVsModel(ray, model->Vertices(), model->m_Indices, TransformSystem::ModelMatrix(boxB.Entity), dist, u, v);
|
||||
} else {
|
||||
hit = Collision::RayVsAABB(ray, boxB, dist);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
||||
continue;
|
||||
}
|
||||
|
||||
glm::mat4 modelMatrix = Transform::ModelMatrix(boxB.Entity);
|
||||
glm::mat4 modelMatrix = TransformSystem::ModelMatrix(boxB.Entity);
|
||||
|
||||
glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"];
|
||||
bool isOnGround = (bool)cPhysics["IsOnGround"];
|
||||
|
||||
@@ -15,7 +15,7 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
|
||||
if (triggerEntity.HasComponent("Model")) {
|
||||
try {
|
||||
triggerModel = ResourceManager::Load<RawModel, true>(triggerEntity["Model"]["Resource"]);
|
||||
triggerModelMat = Transform::ModelMatrix(triggerEntity);
|
||||
triggerModelMat = TransformSystem::ModelMatrix(triggerEntity);
|
||||
} catch (const std::exception&) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,28 @@
|
||||
#include "Core/Transform.h"
|
||||
#include "Core/TransformSystem.h"
|
||||
|
||||
namespace Transform
|
||||
std::unordered_map<EntityWrapper, glm::vec3> TransformSystem::PositionCache;
|
||||
std::unordered_map<EntityWrapper, glm::quat> TransformSystem::OrientationCache;
|
||||
std::unordered_map<EntityWrapper, glm::vec3> TransformSystem::ScaleCache;
|
||||
std::unordered_map<EntityWrapper, glm::mat4> TransformSystem::MatrixCache;
|
||||
|
||||
int TransformSystem::RecalculatedPositions = 0;
|
||||
int TransformSystem::RecalculatedOrientations = 0;
|
||||
int TransformSystem::RecalculatedScales = 0;
|
||||
|
||||
TransformSystem::TransformSystem(SystemParams params)
|
||||
: System(params)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &TransformSystem::OnEntityDeleted);
|
||||
}
|
||||
|
||||
std::unordered_map<EntityWrapper, glm::vec3> PositionCache;
|
||||
std::unordered_map<EntityWrapper, glm::quat> OrientationCache;
|
||||
std::unordered_map<EntityWrapper, glm::vec3> ScaleCache;
|
||||
std::unordered_map<EntityWrapper, glm::mat4> MatrixCache;
|
||||
|
||||
int RecalculatedPositions = 0;
|
||||
int RecalculatedOrientations = 0;
|
||||
int RecalculatedScales = 0;
|
||||
|
||||
bool TransformSystem::OnEntityDeleted(const Events::EntityDeleted& e)
|
||||
{
|
||||
// Clean up deleted entity
|
||||
PositionCache.erase(e.DeletedEntity);
|
||||
OrientationCache.erase(e.DeletedEntity);
|
||||
ScaleCache.erase(e.DeletedEntity);
|
||||
MatrixCache.erase(e.DeletedEntity);
|
||||
return true;
|
||||
}
|
||||
|
||||
//glm::mat4 Transform::AbsoluteTransformation(EntityWrapper entity)
|
||||
@@ -26,12 +37,12 @@ int RecalculatedScales = 0;
|
||||
// return t;
|
||||
//}
|
||||
|
||||
glm::vec3 Transform::AbsolutePosition(World* world, EntityID entity)
|
||||
glm::vec3 TransformSystem::AbsolutePosition(World* world, EntityID entity)
|
||||
{
|
||||
return Transform::AbsolutePosition(EntityWrapper(world, entity));
|
||||
return TransformSystem::AbsolutePosition(EntityWrapper(world, entity));
|
||||
}
|
||||
|
||||
glm::vec3 Transform::AbsolutePosition(EntityWrapper entity)
|
||||
glm::vec3 TransformSystem::AbsolutePosition(EntityWrapper entity)
|
||||
{
|
||||
if (!entity.Valid()) {
|
||||
return glm::vec3();
|
||||
@@ -45,7 +56,7 @@ glm::vec3 Transform::AbsolutePosition(EntityWrapper entity)
|
||||
} else {
|
||||
EntityWrapper parent = entity.Parent();
|
||||
// Calculate position
|
||||
glm::vec3 position = AbsolutePosition(parent) + Transform::AbsoluteOrientation(parent) * (Transform::AbsoluteScale(parent) * (const glm::vec3&)cTransformPosition);
|
||||
glm::vec3 position = AbsolutePosition(parent) + TransformSystem::AbsoluteOrientation(parent) * (TransformSystem::AbsoluteScale(parent) * (const glm::vec3&)cTransformPosition);
|
||||
// Cache it
|
||||
PositionCache[entity] = position;
|
||||
RecalculatedPositions++;
|
||||
@@ -55,7 +66,7 @@ glm::vec3 Transform::AbsolutePosition(EntityWrapper entity)
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 Transform::AbsoluteOrientationEuler(EntityWrapper entity)
|
||||
glm::vec3 TransformSystem::AbsoluteOrientationEuler(EntityWrapper entity)
|
||||
{
|
||||
glm::vec3 orientation;
|
||||
|
||||
@@ -68,12 +79,12 @@ glm::vec3 Transform::AbsoluteOrientationEuler(EntityWrapper entity)
|
||||
return orientation;
|
||||
}
|
||||
|
||||
glm::quat Transform::AbsoluteOrientation(World* world, EntityID entity)
|
||||
glm::quat TransformSystem::AbsoluteOrientation(World* world, EntityID entity)
|
||||
{
|
||||
return Transform::AbsoluteOrientation(EntityWrapper(world, entity));
|
||||
return TransformSystem::AbsoluteOrientation(EntityWrapper(world, entity));
|
||||
}
|
||||
|
||||
glm::quat Transform::AbsoluteOrientation(EntityWrapper entity)
|
||||
glm::quat TransformSystem::AbsoluteOrientation(EntityWrapper entity)
|
||||
{
|
||||
if (!entity.Valid()) {
|
||||
return glm::quat();
|
||||
@@ -97,12 +108,12 @@ glm::quat Transform::AbsoluteOrientation(EntityWrapper entity)
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 Transform::AbsoluteScale(World* world, EntityID entity)
|
||||
glm::vec3 TransformSystem::AbsoluteScale(World* world, EntityID entity)
|
||||
{
|
||||
return Transform::AbsoluteScale(EntityWrapper(world, entity));
|
||||
return TransformSystem::AbsoluteScale(EntityWrapper(world, entity));
|
||||
}
|
||||
|
||||
glm::vec3 Transform::AbsoluteScale(EntityWrapper entity)
|
||||
glm::vec3 TransformSystem::AbsoluteScale(EntityWrapper entity)
|
||||
{
|
||||
if (!entity.Valid()) {
|
||||
return glm::vec3(1.f);
|
||||
@@ -126,12 +137,12 @@ glm::vec3 Transform::AbsoluteScale(EntityWrapper entity)
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 Transform::ModelMatrix(EntityID entityID, World* world)
|
||||
glm::mat4 TransformSystem::ModelMatrix(EntityID entityID, World* world)
|
||||
{
|
||||
return ModelMatrix(EntityWrapper(world, entityID));
|
||||
}
|
||||
|
||||
glm::mat4 Transform::ModelMatrix(EntityWrapper entity)
|
||||
glm::mat4 TransformSystem::ModelMatrix(EntityWrapper entity)
|
||||
{
|
||||
auto cacheIt = MatrixCache.find(entity);
|
||||
ComponentWrapper cTransform = entity["Transform"];
|
||||
@@ -145,7 +156,7 @@ glm::mat4 Transform::ModelMatrix(EntityWrapper entity)
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 Transform::TransformPoint(const glm::vec3& point, const glm::mat4& matrix)
|
||||
glm::vec3 TransformSystem::TransformPoint(const glm::vec3& point, const glm::mat4& matrix)
|
||||
{
|
||||
return glm::vec3(matrix * glm::vec4(point.x, point.y, point.z, 1));
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
#include "Core/TransformSystem.h"
|
||||
|
||||
std::unordered_map<EntityWrapper, glm::vec3> TransformSystem::PositionCache;
|
||||
std::unordered_map<EntityWrapper, glm::quat> TransformSystem::OrientationCache;
|
||||
std::unordered_map<EntityWrapper, glm::vec3> TransformSystem::ScaleCache;
|
||||
std::unordered_map<EntityWrapper, glm::mat4> TransformSystem::MatrixCache;
|
||||
|
||||
int TransformSystem::RecalculatedPositions = 0;
|
||||
int TransformSystem::RecalculatedOrientations = 0;
|
||||
int TransformSystem::RecalculatedScales = 0;
|
||||
|
||||
TransformSystem::TransformSystem(SystemParams params)
|
||||
: System(params)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &TransformSystem::OnEntityDeleted);
|
||||
}
|
||||
|
||||
bool TransformSystem::OnEntityDeleted(const Events::EntityDeleted& e)
|
||||
{
|
||||
// Clean up deleted entity
|
||||
PositionCache.erase(e.DeletedEntity);
|
||||
OrientationCache.erase(e.DeletedEntity);
|
||||
ScaleCache.erase(e.DeletedEntity);
|
||||
MatrixCache.erase(e.DeletedEntity);
|
||||
return true;
|
||||
}
|
||||
|
||||
//glm::mat4 Transform::AbsoluteTransformation(EntityWrapper entity)
|
||||
//{
|
||||
// glm::mat4 t = glm::mat4(1.f);
|
||||
//
|
||||
// while (entity.Valid()) {
|
||||
// t = glm::translate((const glm::vec3&)entity["Transform"]["Position"]) * glm::toMat4(glm::quat((const glm::vec3&)entity["Transform"]["Orientation"])) * glm::scale((const glm::vec3&)entity["Transform"]["Scale"]) * t;
|
||||
// entity = entity.Parent();
|
||||
// }
|
||||
//
|
||||
// return t;
|
||||
//}
|
||||
|
||||
glm::vec3 TransformSystem::AbsolutePosition(World* world, EntityID entity)
|
||||
{
|
||||
return TransformSystem::AbsolutePosition(EntityWrapper(world, entity));
|
||||
}
|
||||
|
||||
glm::vec3 TransformSystem::AbsolutePosition(EntityWrapper entity)
|
||||
{
|
||||
if (!entity.Valid()) {
|
||||
return glm::vec3();
|
||||
}
|
||||
|
||||
auto cacheIt = PositionCache.find(entity);
|
||||
ComponentWrapper cTransform = entity["Transform"];
|
||||
ComponentWrapper::SubscriptProxy cTransformPosition = cTransform["Position"];
|
||||
if (cacheIt != PositionCache.end() && !cTransformPosition.Dirty(DirtySetType::Transform)) {
|
||||
return cacheIt->second;
|
||||
} else {
|
||||
EntityWrapper parent = entity.Parent();
|
||||
// Calculate position
|
||||
glm::vec3 position = AbsolutePosition(parent) + TransformSystem::AbsoluteOrientation(parent) * (TransformSystem::AbsoluteScale(parent) * (const glm::vec3&)cTransformPosition);
|
||||
// Cache it
|
||||
PositionCache[entity] = position;
|
||||
RecalculatedPositions++;
|
||||
// Unset dirty flag
|
||||
cTransformPosition.SetDirty(DirtySetType::Transform, false);
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 TransformSystem::AbsoluteOrientationEuler(EntityWrapper entity)
|
||||
{
|
||||
glm::vec3 orientation;
|
||||
|
||||
while (entity.Valid()) {
|
||||
ComponentWrapper transform = entity["Transform"];
|
||||
orientation += (Field<glm::vec3>)transform["Orientation"];
|
||||
entity = entity.Parent();
|
||||
}
|
||||
|
||||
return orientation;
|
||||
}
|
||||
|
||||
glm::quat TransformSystem::AbsoluteOrientation(World* world, EntityID entity)
|
||||
{
|
||||
return TransformSystem::AbsoluteOrientation(EntityWrapper(world, entity));
|
||||
}
|
||||
|
||||
glm::quat TransformSystem::AbsoluteOrientation(EntityWrapper entity)
|
||||
{
|
||||
if (!entity.Valid()) {
|
||||
return glm::quat();
|
||||
}
|
||||
|
||||
auto cacheIt = OrientationCache.find(entity);
|
||||
ComponentWrapper cTransform = entity["Transform"];
|
||||
ComponentWrapper::SubscriptProxy cTransformOrientation = cTransform["Orientation"];
|
||||
if (cacheIt != OrientationCache.end() && !cTransformOrientation.Dirty(DirtySetType::Transform)) {
|
||||
return cacheIt->second;
|
||||
} else {
|
||||
EntityWrapper parent = entity.Parent();
|
||||
// Calculate orientation
|
||||
glm::quat orientation = AbsoluteOrientation(parent) * glm::quat((const glm::vec3&)cTransformOrientation);
|
||||
// Cache it
|
||||
OrientationCache[entity] = orientation;
|
||||
RecalculatedOrientations++;
|
||||
// Unset dirty flag
|
||||
cTransformOrientation.SetDirty(DirtySetType::Transform, false);
|
||||
return orientation;
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 TransformSystem::AbsoluteScale(World* world, EntityID entity)
|
||||
{
|
||||
return TransformSystem::AbsoluteScale(EntityWrapper(world, entity));
|
||||
}
|
||||
|
||||
glm::vec3 TransformSystem::AbsoluteScale(EntityWrapper entity)
|
||||
{
|
||||
if (!entity.Valid()) {
|
||||
return glm::vec3(1.f);
|
||||
}
|
||||
|
||||
auto cacheIt = ScaleCache.find(entity);
|
||||
ComponentWrapper cTransform = entity["Transform"];
|
||||
ComponentWrapper::SubscriptProxy cTransformScale = cTransform["Scale"];
|
||||
if (cacheIt != ScaleCache.end() && !cTransformScale.Dirty(DirtySetType::Transform)) {
|
||||
return cacheIt->second;
|
||||
} else {
|
||||
EntityWrapper parent = entity.Parent();
|
||||
// Calculate scale
|
||||
glm::vec3 scale = AbsoluteScale(parent) * (const glm::vec3&)cTransformScale;
|
||||
// Cache it
|
||||
ScaleCache[entity] = scale;
|
||||
RecalculatedPositions++;
|
||||
// Unset dirty flag
|
||||
cTransformScale.SetDirty(DirtySetType::Transform, false);
|
||||
return scale;
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 TransformSystem::ModelMatrix(EntityID entityID, World* world)
|
||||
{
|
||||
return ModelMatrix(EntityWrapper(world, entityID));
|
||||
}
|
||||
|
||||
glm::mat4 TransformSystem::ModelMatrix(EntityWrapper entity)
|
||||
{
|
||||
auto cacheIt = MatrixCache.find(entity);
|
||||
ComponentWrapper cTransform = entity["Transform"];
|
||||
bool isDirty = cTransform["Position"].Dirty(DirtySetType::Transform) || cTransform["Orientation"].Dirty(DirtySetType::Transform) || cTransform["Scale"].Dirty(DirtySetType::Transform);
|
||||
if (cacheIt != MatrixCache.end() && !isDirty && false) {
|
||||
return cacheIt->second;
|
||||
} else {
|
||||
glm::mat4 matrix = glm::translate(AbsolutePosition(entity)) * glm::toMat4(AbsoluteOrientation(entity)) * glm::scale(AbsoluteScale(entity));
|
||||
MatrixCache[entity] = matrix;
|
||||
return matrix;
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 TransformSystem::TransformPoint(const glm::vec3& point, const glm::mat4& matrix)
|
||||
{
|
||||
return glm::vec3(matrix * glm::vec4(point.x, point.y, point.z, 1));
|
||||
}
|
||||
@@ -52,7 +52,7 @@ void EditorRenderSystem::Update(double dt)
|
||||
}
|
||||
|
||||
EntityWrapper entity(m_World, cModel.EntityID);
|
||||
glm::mat4 modelMatrix = Transform::ModelMatrix(entity.ID, entity.World);
|
||||
glm::mat4 modelMatrix = TransformSystem::ModelMatrix(entity.ID, entity.World);
|
||||
for (auto matGroup : model->MaterialGroups()) {
|
||||
std::shared_ptr<ModelJob> modelJob = std::make_shared<ModelJob>(model, scene.Camera, modelMatrix, matGroup, cModel, entity.World, glm::vec4(0), 0.f, false, false);
|
||||
if (cModel["Transparent"]) {
|
||||
|
||||
@@ -75,9 +75,9 @@ void EditorSystem::Update(double dt)
|
||||
if (isAnyParentMissingTransform(m_CurrentSelection.ID)) {
|
||||
return;
|
||||
}
|
||||
(Field<glm::vec3>)m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(m_CurrentSelection);
|
||||
(Field<glm::vec3>)m_Widget["Transform"]["Position"] = TransformSystem::AbsolutePosition(m_CurrentSelection);
|
||||
if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) {
|
||||
m_Widget["Transform"]["Orientation"] = Transform::AbsoluteOrientationEuler(m_CurrentSelection);
|
||||
m_Widget["Transform"]["Orientation"] = TransformSystem::AbsoluteOrientationEuler(m_CurrentSelection);
|
||||
} else {
|
||||
m_Widget["Transform"]["Orientation"] = glm::vec3(0, 0, 0);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ void EditorSystem::Enable()
|
||||
eSetCamera.CameraEntity = m_EditorCamera;
|
||||
m_EventBroker->Publish(eSetCamera);
|
||||
if (m_ActualCamera.Valid()) {
|
||||
(Field<glm::vec3>)m_EditorCamera["Transform"]["Position"] = Transform::AbsolutePosition(m_ActualCamera);
|
||||
(Field<glm::vec3>)m_EditorCamera["Transform"]["Position"] = TransformSystem::AbsolutePosition(m_ActualCamera);
|
||||
}
|
||||
|
||||
// Pause the world we're editing
|
||||
@@ -213,15 +213,15 @@ bool EditorSystem::OnWidgetDelta(const Events::WidgetDelta& e)
|
||||
glm::vec3 parentScale(1.f);
|
||||
EntityWrapper parent = m_CurrentSelection.Parent();
|
||||
if (parent.Valid()) {
|
||||
parentOrientation = glm::inverse(Transform::AbsoluteOrientation(parent));
|
||||
parentScale = Transform::AbsoluteScale(parent);
|
||||
parentOrientation = glm::inverse(TransformSystem::AbsoluteOrientation(parent));
|
||||
parentScale = TransformSystem::AbsoluteScale(parent);
|
||||
}
|
||||
(Field<glm::vec3>)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation / parentScale;
|
||||
} else if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) {
|
||||
glm::vec3 parentScale(1.f);
|
||||
EntityWrapper parent = m_CurrentSelection.Parent();
|
||||
if (parent.Valid()) {
|
||||
parentScale = Transform::AbsoluteScale(parent);
|
||||
parentScale = TransformSystem::AbsoluteScale(parent);
|
||||
}
|
||||
glm::quat selectionOri = glm::quat((glm::vec3)m_CurrentSelection["Transform"]["Orientation"]);
|
||||
glm::vec3 localTranslation = selectionOri * e.Translation / parentScale;
|
||||
@@ -312,7 +312,7 @@ void EditorSystem::setWidgetMode(EditorGUI::WidgetMode mode)
|
||||
break;
|
||||
}
|
||||
|
||||
m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(m_CurrentSelection.World, m_CurrentSelection.ID);
|
||||
m_Widget["Transform"]["Position"] = TransformSystem::AbsolutePosition(m_CurrentSelection.World, m_CurrentSelection.ID);
|
||||
}
|
||||
|
||||
bool EditorSystem::isAnyParentMissingTransform(EntityID entityID)
|
||||
|
||||
@@ -71,7 +71,7 @@ void RenderSystem::fillSprites(std::list<std::shared_ptr<RenderJob>>& jobs, Worl
|
||||
float minScale = (float)(double)indicator["MinScale"];
|
||||
bool hasTeam = indicator["VisibleForSingleTeamOnly"];
|
||||
isIndicator = true;
|
||||
glm::vec3 pos = Transform::AbsolutePosition(entity);
|
||||
glm::vec3 pos = TransformSystem::AbsolutePosition(entity);
|
||||
|
||||
|
||||
EntityWrapper entityTeam;
|
||||
@@ -138,7 +138,7 @@ void RenderSystem::fillSprites(std::list<std::shared_ptr<RenderJob>>& jobs, Worl
|
||||
modelMatrix[3][2] = pos.z;
|
||||
modelMatrix[3][3] = 1.0f;
|
||||
|
||||
glm::mat4 tranformationMatrix = modelMatrix * glm::scale(Transform::AbsoluteScale(entity));
|
||||
glm::mat4 tranformationMatrix = modelMatrix * glm::scale(TransformSystem::AbsoluteScale(entity));
|
||||
glm::vec4 tmp = tranformationMatrix * glm::vec4(glm::vec3(0.5, 0.5, 0), 1.0f);
|
||||
glm::vec2 projectedTopRight = m_Camera->WorldToScreen(glm::vec3(tmp), m_Renderer->GetViewportSize());
|
||||
tmp = tranformationMatrix * glm::vec4(glm::vec3(-0.5, -0.5, 0), 1.0f);
|
||||
@@ -151,7 +151,7 @@ void RenderSystem::fillSprites(std::list<std::shared_ptr<RenderJob>>& jobs, Worl
|
||||
modelMatrix = tranformationMatrix;
|
||||
}
|
||||
else {
|
||||
modelMatrix = Transform::ModelMatrix(entity.ID, world);
|
||||
modelMatrix = TransformSystem::ModelMatrix(entity.ID, world);
|
||||
}
|
||||
|
||||
|
||||
@@ -250,7 +250,7 @@ void RenderSystem::fillModels(RenderScene::Queues &Jobs)
|
||||
|
||||
bool isShielded = m_World->HasComponent(cModel.EntityID, "Shielded") || m_World->HasComponent(cModel.EntityID, "Player");
|
||||
|
||||
glm::mat4 modelMatrix = Transform::ModelMatrix(cModel.EntityID, m_World);
|
||||
glm::mat4 modelMatrix = TransformSystem::ModelMatrix(cModel.EntityID, m_World);
|
||||
//Loop through all materialgroups of a model
|
||||
for (auto matGroup : model->MaterialGroups()) {
|
||||
//If the model has an explosioneffect component, we will add an explosioneffectjob
|
||||
@@ -422,7 +422,7 @@ void RenderSystem::fillText(std::list<std::shared_ptr<RenderJob>>& jobs, World*
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 modelMatrix = Transform::ModelMatrix(textComponent.EntityID, world);
|
||||
glm::mat4 modelMatrix = TransformSystem::ModelMatrix(textComponent.EntityID, world);
|
||||
std::shared_ptr<TextJob> textJob = std::shared_ptr<TextJob>(new TextJob(modelMatrix, font, textComponent));
|
||||
jobs.push_back(textJob);
|
||||
|
||||
@@ -440,8 +440,8 @@ void RenderSystem::Update(double dt)
|
||||
|
||||
// Update the current camera used for rendering
|
||||
if (m_CurrentCamera.Valid()) {
|
||||
m_Camera->SetPosition(Transform::AbsolutePosition(m_CurrentCamera));
|
||||
m_Camera->SetOrientation(Transform::AbsoluteOrientation(m_CurrentCamera));
|
||||
m_Camera->SetPosition(TransformSystem::AbsolutePosition(m_CurrentCamera));
|
||||
m_Camera->SetOrientation(TransformSystem::AbsoluteOrientation(m_CurrentCamera));
|
||||
}
|
||||
|
||||
RenderScene scene;
|
||||
|
||||
@@ -113,7 +113,7 @@ void SoundManager::updateEmitters(double dt)
|
||||
if (!m_World->ValidEntity(m_World->GetParent(it->first))) {
|
||||
return;
|
||||
}
|
||||
glm::vec3 nextPos = Transform::AbsolutePosition(m_World, it->first);
|
||||
glm::vec3 nextPos = TransformSystem::AbsolutePosition(m_World, it->first);
|
||||
// Calculate velocity
|
||||
glm::vec3 velocity = glm::vec3(nextPos - previousPos) / (float)dt;
|
||||
setSourcePos(it->second->ALsource, nextPos);
|
||||
@@ -147,11 +147,11 @@ void SoundManager::updateListener(double dt)
|
||||
if (listener.IsChildOf(m_LocalPlayer) || listener == m_LocalPlayer) {
|
||||
glm::vec3 previousPos;
|
||||
alGetListener3f(AL_POSITION, &previousPos.x, &previousPos.y, &previousPos.z); // Get previous pos
|
||||
glm::vec3 nextPos = Transform::AbsolutePosition(listener); // Get next (current) pos
|
||||
glm::vec3 nextPos = TransformSystem::AbsolutePosition(listener); // Get next (current) pos
|
||||
glm::vec3 velocity = glm::vec3(nextPos - previousPos) / (float)dt; // Calculate velocity
|
||||
setListenerPos(nextPos);
|
||||
setListenerVel(velocity);
|
||||
setListenerOri(glm::eulerAngles(Transform::AbsoluteOrientation(listener)));
|
||||
setListenerOri(glm::eulerAngles(TransformSystem::AbsoluteOrientation(listener)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-6
@@ -127,6 +127,7 @@ Game::Game(int argc, char* argv[])
|
||||
// All systems with orderlevel 0 will be updated first.
|
||||
unsigned int updateOrderLevel = 0;
|
||||
m_SystemPipeline->AddSystem<InterpolationSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<TransformSystem>(updateOrderLevel);
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<SoundSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<RaptorCopterSystem>(updateOrderLevel);
|
||||
@@ -249,12 +250,12 @@ void Game::Tick()
|
||||
m_EventBroker->Swap();
|
||||
m_EventBroker->Clear();
|
||||
|
||||
//LOG_DEBUG("Recalculated positions: %i", Transform::RecalculatedPositions);
|
||||
//LOG_DEBUG("Recalculated orientations: %i", Transform::RecalculatedOrientations);
|
||||
//LOG_DEBUG("Recalculated scales: %i", Transform::RecalculatedScales);
|
||||
Transform::RecalculatedPositions = 0;
|
||||
Transform::RecalculatedOrientations = 0;
|
||||
Transform::RecalculatedScales = 0;
|
||||
//LOG_DEBUG("Recalculated positions: %i", TransformSystem::RecalculatedPositions);
|
||||
//LOG_DEBUG("Recalculated orientations: %i", TransformSystem::RecalculatedOrientations);
|
||||
//LOG_DEBUG("Recalculated scales: %i", TransformSystem::RecalculatedScales);
|
||||
TransformSystem::RecalculatedPositions = 0;
|
||||
TransformSystem::RecalculatedOrientations = 0;
|
||||
TransformSystem::RecalculatedScales = 0;
|
||||
}
|
||||
|
||||
int Game::parseArgs(int argc, char* argv[])
|
||||
|
||||
@@ -68,12 +68,12 @@ void CapturePointArrowHUDSystem::Update(double dt)
|
||||
|
||||
if(currentOwner != redTeamEnum) {
|
||||
//This capturePoint is not owned by the red team and is therefor an eligible target for red team
|
||||
glm::vec3 targetPos = Transform::AbsolutePosition(capturePointEntity);
|
||||
glm::vec3 targetPos = TransformSystem::AbsolutePosition(capturePointEntity);
|
||||
redTargets.insert(std::pair<int, glm::vec3>(capturePointID, targetPos));
|
||||
}
|
||||
if(currentOwner != blueTeamEnum) {
|
||||
//This capturePoint is not owned by the blue team and is therefor an eligible target for blue team
|
||||
glm::vec3 targetPos = Transform::AbsolutePosition(capturePointEntity);
|
||||
glm::vec3 targetPos = TransformSystem::AbsolutePosition(capturePointEntity);
|
||||
blueTargets.insert(std::pair<int, glm::vec3>(capturePointID, targetPos));
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ void CapturePointArrowHUDSystem::Update(double dt)
|
||||
}
|
||||
|
||||
Field<glm::vec3> arrowOri = arrowEntity["Transform"]["Orientation"];
|
||||
glm::vec3 lookVector = glm::normalize(Transform::AbsolutePosition(arrowEntity) - pos); //Maybe should be player instead
|
||||
glm::vec3 lookVector = glm::normalize(TransformSystem::AbsolutePosition(arrowEntity) - pos); //Maybe should be player instead
|
||||
float pitch = std::asin(-lookVector.y);
|
||||
float yaw = std::atan2(lookVector.x, lookVector.z);
|
||||
arrowOri.x(pitch);
|
||||
@@ -164,7 +164,7 @@ void CapturePointArrowHUDSystem::Update(double dt)
|
||||
arrowOri.z(0.f);
|
||||
EntityWrapper parent = arrowEntity.Parent();
|
||||
if (parent.Valid()) {
|
||||
arrowOri -= Transform::AbsoluteOrientationEuler(parent);
|
||||
arrowOri -= TransformSystem::AbsoluteOrientationEuler(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,8 +175,8 @@ bool CapturePointArrowHUDSystem::OnCapturePointCaptured(Events::Captured& e)
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_RedTeamCurrentTarget = Transform::AbsolutePosition(e.RedTeamNextCapturePoint);
|
||||
m_BlueTeamCurrentTarget = Transform::AbsolutePosition(e.BlueTeamNextCapturePoint);
|
||||
m_RedTeamCurrentTarget = TransformSystem::AbsolutePosition(e.RedTeamNextCapturePoint);
|
||||
m_BlueTeamCurrentTarget = TransformSystem::AbsolutePosition(e.BlueTeamNextCapturePoint);
|
||||
|
||||
m_InitialtargetsSet = true;
|
||||
return 0;
|
||||
|
||||
@@ -87,7 +87,7 @@ float DamageIndicatorSystem::CalculateAngle(EntityWrapper player, glm::vec3 enem
|
||||
auto enemyPlayerVector = glm::normalize(playerPosition - enemyPosition);
|
||||
|
||||
//get the rotationvector relative to the z-axis
|
||||
auto rotationVectorVec3 = glm::vec3(glm::toMat4(Transform::AbsoluteOrientation(player))*glm::vec4(0, 0, 1, 0));
|
||||
auto rotationVectorVec3 = glm::vec3(glm::toMat4(TransformSystem::AbsoluteOrientation(player))*glm::vec4(0, 0, 1, 0));
|
||||
//rotate the direction-vector 90 degrees to get the players side-vector
|
||||
auto playerSideVector = glm::vec3(glm::rotateY(rotationVectorVec3, 1.57f));
|
||||
|
||||
|
||||
@@ -76,9 +76,9 @@ EntityWrapper SpawnerSystem::Spawn(EntityWrapper spawner, EntityWrapper parent /
|
||||
void SpawnerSystem::transformEntityToSpawnPoint(EntityWrapper spawnedEntity, EntityWrapper spawnPoint)
|
||||
{
|
||||
// Set its position and orientation to that of the SpawnPoint
|
||||
spawnedEntity["Transform"]["Position"] = Transform::AbsolutePosition(spawnPoint.World, spawnPoint.ID);
|
||||
spawnedEntity["Transform"]["Position"] = TransformSystem::AbsolutePosition(spawnPoint.World, spawnPoint.ID);
|
||||
// TODO: Quaternions, bitch
|
||||
spawnedEntity["Transform"]["Orientation"] = glm::eulerAngles(Transform::AbsoluteOrientation(spawnPoint));
|
||||
spawnedEntity["Transform"]["Orientation"] = glm::eulerAngles(TransformSystem::AbsoluteOrientation(spawnPoint));
|
||||
}
|
||||
|
||||
bool SpawnerSystem::spawnedEntityIsColliding(EntityWrapper spawnedEntity, EntityWrapper spawnPoint, const std::string& dontCollideComponent)
|
||||
@@ -113,7 +113,7 @@ bool SpawnerSystem::spawnedEntityIsColliding(EntityWrapper spawnedEntity, Entity
|
||||
spawnedBox,
|
||||
model->Vertices(),
|
||||
model->m_Indices,
|
||||
Transform::ModelMatrix(otherEntity))) {
|
||||
TransformSystem::ModelMatrix(otherEntity))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,8 +218,8 @@ void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
|
||||
// Tracer
|
||||
EntityWrapper tracerSpawner = weaponModelEntity.FirstChildByName("WeaponMuzzle");
|
||||
if (tracerSpawner.Valid()) {
|
||||
glm::vec3 origin = Transform::AbsolutePosition(tracerSpawner);
|
||||
glm::vec3 direction = glm::quat(Transform::AbsoluteOrientationEuler(tracerSpawner)) * glm::vec3(0, 0, -1);
|
||||
glm::vec3 origin = TransformSystem::AbsolutePosition(tracerSpawner);
|
||||
glm::vec3 direction = glm::quat(TransformSystem::AbsoluteOrientationEuler(tracerSpawner)) * glm::vec3(0, 0, -1);
|
||||
float distance = traceRayDistance(origin, direction);
|
||||
EntityWrapper ray = SpawnerSystem::Spawn(tracerSpawner);
|
||||
if (ray.Valid()) {
|
||||
|
||||
@@ -233,8 +233,8 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
|
||||
if (weaponModelEntity.Valid()) {
|
||||
EntityWrapper spawner = weaponModelEntity.FirstChildByName("WeaponMuzzle");
|
||||
for (auto& angles : pelletAngles) {
|
||||
glm::vec3 direction = Transform::AbsoluteOrientation(spawner) * glm::quat(glm::vec3(angles, 0.f)) * glm::vec3(0, 0, -1);
|
||||
float distance = traceRayDistance(Transform::AbsolutePosition(spawner), direction);
|
||||
glm::vec3 direction = TransformSystem::AbsoluteOrientation(spawner) * glm::quat(glm::vec3(angles, 0.f)) * glm::vec3(0, 0, -1);
|
||||
float distance = traceRayDistance(TransformSystem::AbsolutePosition(spawner), direction);
|
||||
EntityWrapper ray = SpawnerSystem::Spawn(spawner);
|
||||
((Field<glm::vec3>)ray["Transform"]["Scale"]).z(distance / 100.f);
|
||||
Field<glm::vec3> orientation = ray["Transform"]["Orientation"];
|
||||
@@ -274,7 +274,7 @@ void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& w
|
||||
|
||||
glm::vec3 maxRange = direction * 2.f;
|
||||
EntityWrapper camera = wi.Player.FirstChildByName("Camera");
|
||||
glm::vec3 cameraPosition = Transform::AbsolutePosition(camera);
|
||||
glm::vec3 cameraPosition = TransformSystem::AbsolutePosition(camera);
|
||||
if (!camera.Valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ void SidearmWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
|
||||
// Tracer
|
||||
EntityWrapper tracerSpawner = weaponModelEntity.FirstChildByName("WeaponMuzzle");
|
||||
if (tracerSpawner.Valid()) {
|
||||
glm::vec3 origin = Transform::AbsolutePosition(tracerSpawner);
|
||||
glm::vec3 direction = Transform::AbsoluteOrientation(tracerSpawner) * glm::vec3(0, 0, -1);
|
||||
glm::vec3 origin = TransformSystem::AbsolutePosition(tracerSpawner);
|
||||
glm::vec3 direction = TransformSystem::AbsoluteOrientation(tracerSpawner) * glm::vec3(0, 0, -1);
|
||||
float distance = traceRayDistance(origin, direction);
|
||||
EntityWrapper ray = SpawnerSystem::Spawn(tracerSpawner);
|
||||
((Field<glm::vec3>)ray["Transform"]["Scale"]).z(distance / 100.f);
|
||||
|
||||
Reference in New Issue
Block a user