Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.