#include "Framework.h" using namespace fw; BoundingVolumeTrigger::BoundingVolumeTrigger(AABB* pBV) { m_pTestedAABB = pBV; } BoundingVolumeTrigger::BoundingVolumeTrigger(Sphere* pBV) { m_pTestedSphere = pBV; } BoundingVolumeTrigger::~BoundingVolumeTrigger() { } void BoundingVolumeTrigger::RegisterMainCheckedBV(AABB* pBV) { m_pTestedAABB = pBV; } void BoundingVolumeTrigger::RegisterMainCheckedBV(Sphere* pBV) { m_pTestedSphere = pBV; } void BoundingVolumeTrigger::RegisterBoundingBox(AABB* pBV) { m_boundingBoxesToTest.push_back(pBV); } void BoundingVolumeTrigger::RegisterBoundingSphere(Sphere* pBV) { m_boundingSpheresToTest.push_back(pBV); } /* void BoundingVolumeTrigger::RegisterEvent(Event* pEvent) { m_pCollisionEvents.push_back(pEvent); } */ void BoundingVolumeTrigger::Update() { bool bColision = CheckCollision(); // Invoque tous les events associés à la collision if (bColision) { /* for (uint32 i = 0; i < m_pCollisionEvents.size(); i++) { Event* pEvent = m_pCollisionEvents[i]; pEvent->Trigger(); } */ } } bool BoundingVolumeTrigger::CheckCollision() { bool collided = false; // AABB à tester for (uint32 i = 0; i < m_boundingBoxesToTest.size(); i++) { if (m_pTestedAABB->Contains(*m_boundingBoxesToTest[i]) || m_pTestedSphere->Intersects(*m_boundingBoxesToTest[i])) { collided = true; } if (m_pTestedAABB->Contains(*m_boundingBoxesToTest[i]) || m_pTestedSphere->Intersects(*m_boundingBoxesToTest[i])) { collided = true; } } // Sphere à tester for (uint32 i = 0; i < m_boundingSpheresToTest.size(); i++) { if (m_boundingSpheresToTest[i]->Intersects(*m_pTestedAABB) || m_pTestedSphere->Intersects(*m_boundingSpheresToTest[i])) { collided = true; } } return collided; }