Merge pull request #90 from teamfisk/FrustumCulling

Correct bounding box for explosion effects
This commit is contained in:
2016-02-10 19:16:36 +01:00
7 changed files with 45 additions and 14 deletions
+2 -1
View File
@@ -79,7 +79,8 @@ bool AABBVsAABB(const AABB& a, const AABB& b);
bool AABBVsAABB(const AABB& a, const AABB& b, glm::vec3& minimumTranslation);
// Calculates an absolute AABB from an entity AABB component
boost::optional<EntityAABB> EntityAbsoluteAABB(EntityWrapper& entity);
boost::optional<EntityAABB> EntityAbsoluteAABB(EntityWrapper& entity, bool takeModelBox = false);
boost::optional<EntityAABB> AbsoluteAABBExplosionEffect(EntityWrapper& entity);
}
+1 -1
View File
@@ -4,7 +4,7 @@
// }
// NOTE: condition statement is not executed at all in release mode.
#ifndef DEBUG_IF
#ifndef DEBUG
#ifdef DEBUG
#define DEBUG_IF(c) if(c)
#else
#define DEBUG_IF(c) if(false)
@@ -4,5 +4,8 @@
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="Collidable">
<xs:annotation>
<xs:documentation>Needs a Model or AABB component to work, uses AABB if both are attached.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
+3
View File
@@ -4,5 +4,8 @@
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="Trigger">
<xs:annotation>
<xs:documentation>Needs a Model or AABB component to work, uses AABB if both are attached.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
+28 -2
View File
@@ -565,10 +565,10 @@ bool AABBvsTriangles(const AABB& box,
return hit;
}
boost::optional<EntityAABB> EntityAbsoluteAABB(EntityWrapper& entity)
boost::optional<EntityAABB> EntityAbsoluteAABB(EntityWrapper& entity, bool takeModelBox)
{
AABB modelSpaceBox;
if (entity.HasComponent("AABB")) {
if (entity.HasComponent("AABB") && !takeModelBox) {
ComponentWrapper& cAABB = entity["AABB"];
modelSpaceBox = EntityAABB::FromOriginSize((glm::vec3)cAABB["Origin"], (glm::vec3)cAABB["Size"]);
} else if (entity.HasComponent("Model")) {
@@ -612,4 +612,30 @@ boost::optional<EntityAABB> EntityAbsoluteAABB(EntityWrapper& entity)
return aabb;
}
boost::optional<EntityAABB> AbsoluteAABBExplosionEffect(EntityWrapper& entity)
{
boost::optional<EntityAABB> modelBox = EntityAbsoluteAABB(entity, true);
if (!modelBox) {
return boost::none;
}
bool isRandom = (bool)entity["ExplosionEffect"]["Randomness"];
float random = isRandom ? (float)(double)entity["ExplosionEffect"]["RandomnessScalar"] : 0;
glm::vec3 origin = (glm::vec3)entity["ExplosionEffect"]["ExplosionOrigin"];
glm::vec3 randomVel = (glm::vec3)entity["ExplosionEffect"]["Velocity"];
randomVel *= (random + 1);
float endVelocity = randomVel.y;
if ((bool)entity["ExplosionEffect"]["ExponentialAccelaration"]) {
endVelocity *= endVelocity / 2.f;
}
float maxRadius = (float)(double)entity["ExplosionEffect"]["ExplosionDuration"] * endVelocity;
glm::vec3 size;
AABB explosionBox(origin - (size / 2.f), origin + (size / 2.f));
glm::vec3 mini = glm::min(explosionBox.MinCorner(), (*modelBox).MinCorner());
glm::vec3 maxi = glm::max(explosionBox.MaxCorner(), (*modelBox).MaxCorner());
EntityAABB aabb = AABB(mini, maxi);
aabb.Entity = entity;
return aabb;
}
}
@@ -7,15 +7,13 @@ void FillFrustumOctreeSystem::Update(double dt)
void FillFrustumOctreeSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt)
{
boost::optional<EntityAABB> absoluteAABB;
if (entity.HasComponent("ExplosionEffect")) {
//TODO: Fix hack, get real box by using shader equation.
EntityAABB aabb = AABB(glm::vec3(-300), glm::vec3(300));
aabb.Entity = entity;
m_Octree->AddDynamicObject(aabb);
absoluteAABB = Collision::AbsoluteAABBExplosionEffect(entity);
} else {
boost::optional<EntityAABB> absoluteAABB = Collision::EntityAbsoluteAABB(entity);
if (absoluteAABB) {
m_Octree->AddDynamicObject(*absoluteAABB);
}
absoluteAABB = Collision::EntityAbsoluteAABB(entity, true);
}
}
if (absoluteAABB) {
m_Octree->AddDynamicObject(*absoluteAABB);
}
}
+1 -1
View File
@@ -135,7 +135,7 @@ Model::Model(std::string fileName)
maxi = glm::max(maxi, v.Position);
}
m_Box = AABB(maxi, mini);
m_Box = AABB(mini, maxi);
}
Model::~Model()