SceneNode.cpp
void SceneNode::setTransformation(const glm::mat4 &transformation)
{
_transformation = transformation;
//update _toRootTransformation for this node and all its children
_updateToRootTransformations();
if(!_aabb)
_aabb = new Aabb;
*_aabb = _untransformedAabb->getTransformed( _toRootTransformation );
}
Aabb.cpp
void Aabb::applyTransformation(const glm::mat4 &transformation)
{
glm::vec3 min = glm::vec3( transformation * glm::vec4(_min, 1.0f) );
glm::vec3 max = glm::vec3( transformation * glm::vec4(_max, 1.0f) );
this->reconstructAabb(min, max);
}
Aabb Aabb::getTransformed(const glm::mat4 &transformation) const
{
Aabb aabb = *this;
aabb.applyTransformation(transformation);
return aabb;
}
void Aabb::applyTransformation(const glm::mat4 &transformation)
{
glm::vec3 min = glm::vec3( transformation * glm::vec4(_min, 1.0f) );
glm::vec3 max = glm::vec3( transformation * glm::vec4(_max, 1.0f) );
//to make sure that rotations won't ruin our aabb
glm::vec3 temp = min;
min = glm::min(min, max);
max = glm::max(temp, max);
this->reconstructAabb(min, max);
}
At first it looked like I solved my problem, but after checking how the AABB actually looks in the game I saw that it didn't. At some points in time, the AABB has a volume of 0.
![peotIij.gif](http://i.imgur.com/peotIij.gif)