?

Log in

No account? Create an account
14 июл, 2006 @ 17:20 Найдена ошибка в gmtl

Автор: Neonic | RGDEngine

функцию я у себя уже поправил и в CVS обновил. Тест колижена начал работать намного точнее, хотя на старых тачках все же не очень хорошо... Буду немного менять алгоритм теста и таки выведу создание колижен объектов в отдельную структуру, чтобы не мешать рендеру.

Из-за следующего ниже кода я потратил кучу времени. Стало быть, это 1 вариант (рабочий), дальше могут быть отличия, но это уже зависит от разработчиков gmtl.

template<class DATA_TYPE>
   bool intersect( const AABox<DATA_TYPE>& aabb1, const Vec<DATA_TYPE, 3>& path1,
                   const AABox<DATA_TYPE>& aabb2, const Vec<DATA_TYPE, 3>& path2,
                   DATA_TYPE& firstContact, DATA_TYPE& secondContact )
   {
      // Algorithm taken from Gamasutra's article, "Simple Intersection Test for
      // Games" - http://www.gamasutra.com/features/19991018/Gomez_3.htm
      //
      // This algorithm is solved from the frame of reference of box1
      //
      // 2006.07.14 rewritten by Breshin "Neonic" Alexey (gaba@male.ru)

      // Get the relative path (in normalized time)
      Vec<DATA_TYPE, 3> path = path2 - path1;

      // The first time of overlap along each axis
      Vec<DATA_TYPE, 3> overlap1(DATA_TYPE(0), DATA_TYPE(0), DATA_TYPE(0));

      // The second time of overlap along each axis
      Vec<DATA_TYPE, 3> overlap2(DATA_TYPE(1), DATA_TYPE(1), DATA_TYPE(1));

      // Check if the boxes already overlap
      if (gmtl::intersect(aabb1, aabb2))
      {
         firstContact = secondContact = DATA_TYPE(0);
         return true;
      }

      // calculating extents
      Point<DATA_TYPE, 3> ext1 = (aabb1.getMax()-aabb1.getMin())*0.5f;
      Point<DATA_TYPE, 3> ext2 = (aabb2.getMax()-aabb2.getMin())*0.5f;
      // calculating boxes at new positions
      AABox<DATA_TYPE> box1(pos1-ext1, pos1+ext1);
      AABox<DATA_TYPE> box2(pos2-ext2, pos2+ext2);
      // calculating dynamic boxes
      gmtl::extendVolume(box1,aabb1);
      gmtl::extendVolume(box2,aabb2);

      // Find the possible first and last times of overlap along each axis
      for (int i=0; i<3; ++i)
      {
         if ((box1.getMax()[i] < box2.getMin()[i]) && (path[i] < DATA_TYPE(0)))
         {
            overlap1[i] = (box1.getMax()[i] - box2.getMin()[i]) / path[i];
         }
         else if ((box2.getMax()[i] < box1.getMin()[i]) && (path[i] > DATA_TYPE(0)))
         {
            overlap1[i] = (box1.getMin()[i] - box2.getMax()[i]) / path[i];
         }

         if ((box2.getMax()[i] > box1.getMin()[i]) && (path[i] < DATA_TYPE(0)))
         {
            overlap2[i] = (box1.getMin()[i] - box2.getMax()[i]) / path[i];
         }
         else if ((box1.getMax()[i] > box2.getMin()[i]) && (path[i] > DATA_TYPE(0)))
         {
            overlap2[i] = (box1.getMax()[i] - box2.getMin()[i]) / path[i];
         }
      }

      // Calculate the first time of overlap
      firstContact = Math::Max(overlap1[0], overlap1[1], overlap1[2]);

      // Calculate the second time of overlap
      secondContact = Math::Min(overlap2[0], overlap2[1], overlap2[2]);

      // There could only have been a collision if the first overlap time
      // occurred before the second overlap time
      return firstContact <= secondContact;
   }

Ссылка

gdrobot:
Для этой записи комментарии отключены.