// Author: Hector Navarro (hnavarro@ciens.ucv.ve)
//         Juan Carlos De Abreu (jcabreur@gmail.com)
//
// This class define an inherent ICollisionDetection that use AABB and OBB to
// to detect collision between two geometries.

#ifndef AABB_TREE_COLLISION_DETECTION_H__
#define AABB_TREE_COLLISION_DETECTION_H__

#include "../global.h"
#include "../Math/Matrix.h"
#include "collision_detection.h"
#include "../Base/Memory/SmartPointer.h"
#include "../Scene/scene_nodes/geometry_node.h"

BEGIN_TEG_NAMESPACE();

class OBB;
class AABB;
class AABBNode;

class AABBTreeCollision : public ICollisionDetection {
 public:
  // AABBTreeCollision constructors and destructor.
  AABBTreeCollision();
  AABBTreeCollision(
      const SmartPointer<GeometryNode>& geometry1,
      const SmartPointer<GeometryNode>& geometry2);
  ~AABBTreeCollision();

  // Method to detect collision between the two geometries stored.
  virtual bool Detect();

 private:
  // Methods to detect collision between two OBB, two AABB and two AABBNode.
  bool Detect(const OBB& bb1, const OBB& bb2);
  bool Detect(const AABB& bb1, const AABB& bb2);
  bool Detect(const SmartPointer<AABBNode>& node1,
              const SmartPointer<AABBNode>& node2);

  // AABBTreeCollision Attributes.
  Mat4f model_view1_, model_view2_;
  SmartPointer<GeometryNode> geometry1_, geometry2_;
  DISALLOW_COPY_AND_ASSIGN(AABBTreeCollision);
};

END_TEG_NAMESPACE();

#endif  // AABB_TREE_COLLISION_DETECTION_H__
