//=========================================================================== bool cCollisionAABBInternal::computeCollision(cVector3d& a_segmentPointA, cVector3d& a_segmentPointB, cCollisionAABBBox &a_lineBox, cCollisionRecorder& a_recorder, cCollisionSettings& a_settings) { // if a line's bounding box does not intersect the node's bounding box, // there can be no intersection if (!intersect(m_bbox, a_lineBox)) { return (false); } if (m_testLineBox) { if (!hitBoundingBox( (const double*)(&m_bbox.m_min), (const double*)(&m_bbox.m_max), (const double*)(&a_segmentPointA), (const double*)(&a_segmentPointB))) return (false); } // initialize objects for calls to left and right subtrees cVector3d l_colPoint, r_colPoint; bool l_result = false; bool r_result = false; // check collision between line and left subtree node; it will only // return true if the distance between the segment origin and this // triangle is less than the current closest intersecting triangle // (whose distance squared is in l_colSquareDistance) if ( m_leftSubTree && m_leftSubTree->computeCollision( a_segmentPointA, a_segmentPointB, a_lineBox, a_recorder, a_settings)) { l_result = true; } // check collision between line and right subtree node; it will only // return true if the distance between the segment origin and this // triangle is less than the current closest intersecting triangle // (whose distance squared is in r_colSquareDistance) if ( m_rightSubTree && m_rightSubTree->computeCollision( a_segmentPointA, a_segmentPointB, a_lineBox, a_recorder, a_settings)) { r_result = true; } // return result return (l_result || r_result); }
//=========================================================================== bool cCollisionAABBInternal::computeCollision(cVector3d& a_segmentPointA, cVector3d& a_segmentDirection, cCollisionAABBBox &a_lineBox, cTriangle*& a_colTriangle, cVector3d& a_colPoint, double& a_colSquareDistance) { // if a line's bounding box does not intersect the node's bounding box, // there can be no intersection if (!intersect(m_bbox, a_lineBox)) { return (false); } if (m_testLineBox) { // Avoid unnecessary copying by casting straight to double... //double minB[3]; //double maxB[3]; //double origin[3]; //double dir[3]; //minB[0] = m_bbox.getLowerX(); minB[1] = m_bbox.getLowerY(); minB[2] = m_bbox.getLowerZ(); //maxB[0] = m_bbox.getUpperX(); maxB[1] = m_bbox.getUpperY(); maxB[2] = m_bbox.getUpperZ(); //origin[0] = a_segmentPointA.x; origin[1] = a_segmentPointA.y; origin[2] = a_segmentPointA.z; //dir[0] = a_segmentDirection.x; dir[1] = a_segmentDirection.y; dir[2] = a_segmentDirection.z; //if (!hitBoundingBox(minB, maxB, origin, dir)) if (!hitBoundingBox( (const double*)(&m_bbox.m_min), (const double*)(&m_bbox.m_max), (const double*)(&a_segmentPointA), (const double*)(&a_segmentDirection))) return (false); } // initialize objects for calls to left and right subtrees cTriangle *l_colTriangle, *r_colTriangle; cVector3d l_colPoint, r_colPoint; double l_colSquareDistance = a_colSquareDistance; double r_colSquareDistance = a_colSquareDistance; bool l_result = false; bool r_result = false; // check collision between line and left subtree node; it will only // return true if the distance between the segment origin and this // triangle is less than the current closest intersecting triangle // (whose distance squared is in l_colSquareDistance) if ( m_leftSubTree && m_leftSubTree->computeCollision(a_segmentPointA, a_segmentDirection, a_lineBox, l_colTriangle, l_colPoint, l_colSquareDistance) ) { l_result = true; } // check collision between line and right subtree node; it will only // return true if the distance between the segment origin and this // triangle is less than the current closest intersecting triangle // (whose distance squared is in r_colSquareDistance) if ( m_rightSubTree && m_rightSubTree->computeCollision(a_segmentPointA, a_segmentDirection, a_lineBox, r_colTriangle, r_colPoint, r_colSquareDistance) ) { r_result = true; } // if there is an intersection in either subtree, return the closest one if ((l_result && !r_result) || (l_result && r_result && (l_colSquareDistance <= r_colSquareDistance))) { a_colTriangle = l_colTriangle; a_colPoint = l_colPoint; a_colSquareDistance = l_colSquareDistance; } else { a_colTriangle = r_colTriangle; a_colPoint = r_colPoint; a_colSquareDistance = r_colSquareDistance; } // return result return (l_result || r_result); }