Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4708 in orxonox.OLD for orxonox/trunk/src


Ignore:
Timestamp:
Jun 26, 2005, 6:51:31 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: the cd now supports rotations in the detection

Location:
orxonox/trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc

    r4705 r4708  
    643643{
    644644  /* first check all axis */
    645   Vector t = nodeA->getAbsCoor() + *boxA->center - ( nodeB->getAbsCoor() + *boxB->center);
     645  Vector t;
    646646  float rA = 0.0f;
    647647  float rB = 0.0f;
    648648  Vector l;
     649  Vector rotAxisA[3];
     650  Vector rotAxisB[3];
     651
     652  rotAxisA[0] =  nodeA->getAbsDir().apply(boxA->axis[0]);
     653  rotAxisA[1] =  nodeA->getAbsDir().apply(boxA->axis[1]);
     654  rotAxisA[2] =  nodeA->getAbsDir().apply(boxA->axis[2]);
     655
     656  rotAxisB[0] =  nodeB->getAbsDir().apply(boxB->axis[0]);
     657  rotAxisB[1] =  nodeB->getAbsDir().apply(boxB->axis[1]);
     658  rotAxisB[2] =  nodeB->getAbsDir().apply(boxB->axis[2]);
     659
     660  t = nodeA->getAbsCoor() + nodeA->getAbsDir().apply(*boxA->center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(*boxB->center));
     661
     662//   printf("\n");
     663//   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[0].x, boxA->axis[0].y, boxA->axis[0].z, rotAxisA[0].x, rotAxisA[0].y, rotAxisA[0].z);
     664//   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[1].x, boxA->axis[1].y, boxA->axis[1].z, rotAxisA[1].x, rotAxisA[1].y, rotAxisA[1].z);
     665//   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[2].x, boxA->axis[2].y, boxA->axis[2].z, rotAxisA[2].x, rotAxisA[2].y, rotAxisA[2].z);
     666//
     667//   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[0].x, boxB->axis[0].y, boxB->axis[0].z, rotAxisB[0].x, rotAxisB[0].y, rotAxisB[0].z);
     668//   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[1].x, boxB->axis[1].y, boxB->axis[1].z, rotAxisB[1].x, rotAxisB[1].y, rotAxisB[1].z);
     669//   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[2].x, boxB->axis[2].y, boxB->axis[2].z, rotAxisB[2].x, rotAxisB[2].y, rotAxisB[2].z);
     670
    649671
    650672  /* All 3 axis of the object A */
     
    653675    rA = 0.0f;
    654676    rB = 0.0f;
    655     l = boxA->axis[j];
    656 
    657     rA += fabs(boxA->halfLength[0] * boxA->axis[0].dot(l));
    658     rA += fabs(boxA->halfLength[1] * boxA->axis[1].dot(l));
    659     rA += fabs(boxA->halfLength[2] * boxA->axis[2].dot(l));
    660 
    661     rB += fabs(boxB->halfLength[0] * boxB->axis[0].dot(l));
    662     rB += fabs(boxB->halfLength[1] * boxB->axis[1].dot(l));
    663     rB += fabs(boxB->halfLength[2] * boxB->axis[2].dot(l));
     677    l = rotAxisA[j];
     678
     679    rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l));
     680    rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l));
     681    rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l));
     682
     683    rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l));
     684    rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l));
     685    rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l));
    664686
    665687    PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
     
    677699    rA = 0.0f;
    678700    rB = 0.0f;
    679     l = boxB->axis[j];
    680 
    681     rA += fabs(boxA->halfLength[0] * boxA->axis[0].dot(l));
    682     rA += fabs(boxA->halfLength[1] * boxA->axis[1].dot(l));
    683     rA += fabs(boxA->halfLength[2] * boxA->axis[2].dot(l));
    684 
    685     rB += fabs(boxB->halfLength[0] * boxB->axis[0].dot(l));
    686     rB += fabs(boxB->halfLength[1] * boxB->axis[1].dot(l));
    687     rB += fabs(boxB->halfLength[2] * boxB->axis[2].dot(l));
     701    l = rotAxisB[j];
     702
     703    rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l));
     704    rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l));
     705    rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l));
     706
     707    rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l));
     708    rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l));
     709    rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l));
    688710
    689711    PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
     
    705727      rA = 0.0f;
    706728      rB = 0.0f;
    707       l = boxA->axis[j].cross(boxB->axis[k]);
    708 
    709       rA += fabs(boxA->halfLength[0] * boxA->axis[0].dot(l));
    710       rA += fabs(boxA->halfLength[1] * boxA->axis[1].dot(l));
    711       rA += fabs(boxA->halfLength[2] * boxA->axis[2].dot(l));
    712 
    713       rB += fabs(boxB->halfLength[0] * boxB->axis[0].dot(l));
    714       rB += fabs(boxB->halfLength[1] * boxB->axis[1].dot(l));
    715       rB += fabs(boxB->halfLength[2] * boxB->axis[2].dot(l));
     729      l = rotAxisA[j].cross(rotAxisB[k]);
     730
     731      rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l));
     732      rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l));
     733      rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l));
     734
     735      rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l));
     736      rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l));
     737      rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l));
    716738
    717739      PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
     
    731753  return true;
    732754}
     755
     756
    733757
    734758
  • orxonox/trunk/src/subprojects/collision_detection/collision_detection.cc

    r4707 r4708  
    4444bool drawModel;
    4545
    46 TestEntity* a;
     46Environment* a;
    4747Environment* b;
    4848
     
    6969  entityList = new tList<WorldEntity>();
    7070
    71   a = new TestEntity(); a->setName("Clown1");
    72   //a = new Environment(); a->setName("Clown");
     71  //a = new TestEntity(); a->setName("Clown1");
     72  a = new Environment(); a->setName("Clown");
    7373  b = new Environment(); b->setName("Jaeger");
     74
    7475  b->setRelCoor(0.0, 0.0, -10.0);
     76  b->setRelDir(Quaternion(-M_PI/2.0f, Vector(0.0, 1.0, 0.0)));
    7577
    7678//   TestEntity* c = new TestEntity(); c->setName("Colwn2");
     
    7981  entityList->add(a);
    8082  entityList->add(b);
    81 //   entityList->add(c);
    8283
    8384  CDEngine::getInstance()->setEntityList(entityList);
     
    225226
    226227
    227   tIterator<WorldEntity>* iterator = entityList->getIterator(); /* get the iterator - JAVA style */
    228   WorldEntity* entity = iterator->nextElement();   /* this returns the FIRST element */
    229   while( entity != NULL)                        /* nextElement() will return NULL at the end */
     228  tIterator<WorldEntity>* iterator = entityList->getIterator();
     229  WorldEntity* entity = iterator->nextElement();
     230  while( entity != NULL)
    230231  {
    231232    entity->tick(dt);
    232     entity = iterator->nextElement();       /* give back the next element or NULL if last */
     233    entity = iterator->nextElement();
    233234  }
    234235  delete iterator;
     
    238239void Framework::moduleDraw() const
    239240{
    240   //CDEngine::getInstance()->drawBV(depth, drawMode);
    241 
    242   tIterator<WorldEntity>* iterator = entityList->getIterator(); /* get the iterator - JAVA style */
    243   WorldEntity* entity = iterator->nextElement();   /* this returns the FIRST element */
    244   while( entity != NULL)                        /* nextElement() will return NULL at the end */
     241  tIterator<WorldEntity>* iterator = entityList->getIterator();
     242  WorldEntity* entity = iterator->nextElement();
     243  while( entity != NULL)
    245244  {
    246245    if( likely(drawModel))
    247246    entity->draw();
    248247    entity->drawBVTree(depth, drawMode);
    249     entity = iterator->nextElement();       /* give back the next element or NULL if last */
     248    entity = iterator->nextElement();
    250249  }
    251250  delete iterator;
Note: See TracChangeset for help on using the changeset viewer.