Explosion effects should get a proper sized AABB.
This commit is contained in:
@@ -80,6 +80,7 @@ bool AABBVsAABB(const AABB& a, const AABB& b, glm::vec3& minimumTranslation);
|
|||||||
|
|
||||||
// Calculates an absolute AABB from an entity AABB component
|
// Calculates an absolute AABB from an entity AABB component
|
||||||
boost::optional<EntityAABB> EntityAbsoluteAABB(EntityWrapper& entity);
|
boost::optional<EntityAABB> EntityAbsoluteAABB(EntityWrapper& entity);
|
||||||
|
boost::optional<EntityAABB> AbsoluteAABBExplosionEffect(EntityWrapper& entity);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -612,4 +612,30 @@ boost::optional<EntityAABB> EntityAbsoluteAABB(EntityWrapper& entity)
|
|||||||
return aabb;
|
return aabb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::optional<EntityAABB> AbsoluteAABBExplosionEffect(EntityWrapper& entity)
|
||||||
|
{
|
||||||
|
boost::optional<EntityAABB> modelBox = EntityAbsoluteAABB(entity);
|
||||||
|
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)
|
void FillFrustumOctreeSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt)
|
||||||
{
|
{
|
||||||
|
boost::optional<EntityAABB> absoluteAABB;
|
||||||
if (entity.HasComponent("ExplosionEffect")) {
|
if (entity.HasComponent("ExplosionEffect")) {
|
||||||
//TODO: Fix hack, get real box by using shader equation.
|
absoluteAABB = Collision::AbsoluteAABBExplosionEffect(entity);
|
||||||
EntityAABB aabb = AABB(glm::vec3(-300), glm::vec3(300));
|
|
||||||
aabb.Entity = entity;
|
|
||||||
m_Octree->AddDynamicObject(aabb);
|
|
||||||
} else {
|
} else {
|
||||||
boost::optional<EntityAABB> absoluteAABB = Collision::EntityAbsoluteAABB(entity);
|
absoluteAABB = Collision::EntityAbsoluteAABB(entity);
|
||||||
if (absoluteAABB) {
|
}
|
||||||
m_Octree->AddDynamicObject(*absoluteAABB);
|
if (absoluteAABB) {
|
||||||
}
|
m_Octree->AddDynamicObject(*absoluteAABB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user