本文整理汇总了C++中Box3::Axis方法的典型用法代码示例。如果您正苦于以下问题:C++ Box3::Axis方法的具体用法?C++ Box3::Axis怎么用?C++ Box3::Axis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box3
的用法示例。
在下文中一共展示了Box3::Axis方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestIntersection
//----------------------------------------------------------------------------
bool Mgc::TestIntersection (const Line3& rkLine, const Box3& rkBox)
{
Real fAWdU[3], fAWxDdU[3], fRhs;
Vector3 kDiff = rkLine.Origin() - rkBox.Center();
Vector3 kWxD = rkLine.Direction().Cross(kDiff);
fAWdU[1] = Math::FAbs(rkLine.Direction().Dot(rkBox.Axis(1)));
fAWdU[2] = Math::FAbs(rkLine.Direction().Dot(rkBox.Axis(2)));
fAWxDdU[0] = Math::FAbs(kWxD.Dot(rkBox.Axis(0)));
fRhs = rkBox.Extent(1)*fAWdU[2] + rkBox.Extent(2)*fAWdU[1];
if ( fAWxDdU[0] > fRhs )
return false;
fAWdU[0] = Math::FAbs(rkLine.Direction().Dot(rkBox.Axis(0)));
fAWxDdU[1] = Math::FAbs(kWxD.Dot(rkBox.Axis(1)));
fRhs = rkBox.Extent(0)*fAWdU[2] + rkBox.Extent(2)*fAWdU[0];
if ( fAWxDdU[1] > fRhs )
return false;
fAWxDdU[2] = Math::FAbs(kWxD.Dot(rkBox.Axis(2)));
fRhs = rkBox.Extent(0)*fAWdU[1] + rkBox.Extent(1)*fAWdU[0];
if ( fAWxDdU[2] > fRhs )
return false;
return true;
}
示例2: FindIntersection
//----------------------------------------------------------------------------
bool Mgc::FindIntersection (const Segment3& rkSegment, const Box3& rkBox,
int& riQuantity, Vector3 akPoint[2])
{
// convert segment to box coordinates
Vector3 kDiff = rkSegment.Origin() - rkBox.Center();
Vector3 kOrigin(
kDiff.Dot(rkBox.Axis(0)),
kDiff.Dot(rkBox.Axis(1)),
kDiff.Dot(rkBox.Axis(2))
);
Vector3 kDirection(
rkSegment.Direction().Dot(rkBox.Axis(0)),
rkSegment.Direction().Dot(rkBox.Axis(1)),
rkSegment.Direction().Dot(rkBox.Axis(2))
);
Real fT0 = 0.0f, fT1 = 1.0f;
bool bIntersects = FindIntersection(kOrigin,kDirection,rkBox.Extents(),
fT0,fT1);
if ( bIntersects )
{
if ( fT0 > 0.0f )
{
if ( fT1 < 1.0f )
{
riQuantity = 2;
akPoint[0] = rkSegment.Origin() + fT0*rkSegment.Direction();
akPoint[1] = rkSegment.Origin() + fT1*rkSegment.Direction();
}
else
{
riQuantity = 1;
akPoint[0] = rkSegment.Origin() + fT0*rkSegment.Direction();
}
}
else // fT0 == 0
{
if ( fT1 < 1.0f )
{
riQuantity = 1;
akPoint[0] = rkSegment.Origin() + fT1*rkSegment.Direction();
}
else // fT1 == 1
{
// segment entirely in box
riQuantity = 0;
}
}
}
else
{
riQuantity = 0;
}
return bIntersects;
}
示例3: BoxProjection
void Wml::BoxProjection (const Vector3<Real>& rkAxis,
const Box3<Real>& rkBox, Real& rfMin, Real& rfMax)
{
Real fOrigin = rkAxis.Dot(rkBox.Center());
Real fMaximumExtent =
Math<Real>::FAbs(rkBox.Extent(0)*rkAxis.Dot(rkBox.Axis(0))) +
Math<Real>::FAbs(rkBox.Extent(1)*rkAxis.Dot(rkBox.Axis(1))) +
Math<Real>::FAbs(rkBox.Extent(2)*rkAxis.Dot(rkBox.Axis(2)));
rfMin = fOrigin - fMaximumExtent;
rfMax = fOrigin + fMaximumExtent;
}
示例4: Culled
bool Wml::Culled (const Plane3<Real>& rkPlane, const Box3<Real>& rkBox)
{
Real fTmp[3] =
{
rkBox.Extent(0)*(rkPlane.GetNormal().Dot(rkBox.Axis(0))),
rkBox.Extent(1)*(rkPlane.GetNormal().Dot(rkBox.Axis(1))),
rkBox.Extent(2)*(rkPlane.GetNormal().Dot(rkBox.Axis(2)))
};
Real fRadius = Math<Real>::FAbs(fTmp[0]) + Math<Real>::FAbs(fTmp[1]) +
Math<Real>::FAbs(fTmp[2]);
Real fPseudoDistance = rkPlane.DistanceTo(rkBox.Center());
return fPseudoDistance <= -fRadius;
}
示例5: MinimalBoxForAngles
//----------------------------------------------------------------------------
static void MinimalBoxForAngles (int iQuantity, const Vector3* akPoint,
Real afAngle[3], Box3& rkBox)
{
Real fCos0 = Math::Cos(afAngle[0]);
Real fSin0 = Math::Sin(afAngle[0]);
Real fCos1 = Math::Cos(afAngle[1]);
Real fSin1 = Math::Sin(afAngle[1]);
Vector3 kAxis(fCos0*fSin1,fSin0*fSin1,fCos1);
Matrix3 kRot;
kRot.FromAxisAngle(kAxis,afAngle[2]);
Vector3 kMin = akPoint[0]*kRot, kMax = kMin;
for (int i = 1; i < iQuantity; i++)
{
Vector3 kTest = akPoint[i]*kRot;
if ( kTest.x < kMin.x )
kMin.x = kTest.x;
else if ( kTest.x > kMax.x )
kMax.x = kTest.x;
if ( kTest.y < kMin.y )
kMin.y = kTest.y;
else if ( kTest.y > kMax.y )
kMax.y = kTest.y;
if ( kTest.z < kMin.z )
kMin.z = kTest.z;
else if ( kTest.z > kMax.z )
kMax.z = kTest.z;
}
Vector3 kMid = 0.5f*(kMax + kMin);
Vector3 kRng = 0.5f*(kMax - kMin);
rkBox.Center() = kRot*kMid;
rkBox.Axis(0) = kRot.GetColumn(0);
rkBox.Axis(1) = kRot.GetColumn(1);
rkBox.Axis(2) = kRot.GetColumn(2);
rkBox.Extent(0) = kRng.x;
rkBox.Extent(1) = kRng.y;
rkBox.Extent(2) = kRng.z;
}
示例6: if
void MinBox3<Real>::MinimalBoxForAngles (int iQuantity,
const Vector3<Real>* akPoint, Real afAngle[3], Box3<Real>& rkBox)
{
Real fCos0 = Math<Real>::Cos(afAngle[0]);
Real fSin0 = Math<Real>::Sin(afAngle[0]);
Real fCos1 = Math<Real>::Cos(afAngle[1]);
Real fSin1 = Math<Real>::Sin(afAngle[1]);
Vector3<Real> kAxis(fCos0*fSin1,fSin0*fSin1,fCos1);
Matrix3<Real> kRot(kAxis,afAngle[2]);
Vector3<Real> kMin = akPoint[0]*kRot, kMax = kMin;
for (int i = 1; i < iQuantity; i++)
{
Vector3<Real> kTest = akPoint[i]*kRot;
if ( kTest.X() < kMin.X() )
kMin.X() = kTest.X();
else if ( kTest.X() > kMax.X() )
kMax.X() = kTest.X();
if ( kTest.Y() < kMin.Y() )
kMin.Y() = kTest.Y();
else if ( kTest.Y() > kMax.Y() )
kMax.Y() = kTest.Y();
if ( kTest.Z() < kMin.Z() )
kMin.Z() = kTest.Z();
else if ( kTest.Z() > kMax.Z() )
kMax.Z() = kTest.Z();
}
Vector3<Real> kMid = ((Real)0.5)*(kMax + kMin);
Vector3<Real> kRng = ((Real)0.5)*(kMax - kMin);
rkBox.Center() = kRot*kMid;
rkBox.Axis(0) = kRot.GetColumn(0);
rkBox.Axis(1) = kRot.GetColumn(1);
rkBox.Axis(2) = kRot.GetColumn(2);
rkBox.Extent(0) = kRng.X();
rkBox.Extent(1) = kRng.Y();
rkBox.Extent(2) = kRng.Z();
}
示例7: InBox
bool Wml::InBox (const Vector3<Real>& rkPoint, const Box3<Real>& rkBox,
Real fEpsilon)
{
Vector3<Real> kDiff = rkPoint - rkBox.Center();
for (int i = 0; i < 3; i++)
{
Real fCoeff = kDiff.Dot(rkBox.Axis(i));
if ( Math<Real>::FAbs(fCoeff) > rkBox.Extent(i) + fEpsilon )
return false;
}
return true;
}
示例8: if
Box3<Real> Wml::ContOrientedBox (int iQuantity, const Vector3<Real>* akPoint)
{
Box3<Real> kBox;
GaussPointsFit(iQuantity,akPoint,kBox.Center(),kBox.Axes(),
kBox.Extents());
// Let C be the box center and let U0, U1, and U2 be the box axes. Each
// input point is of the form X = C + y0*U0 + y1*U1 + y2*U2. The
// following code computes min(y0), max(y0), min(y1), max(y1), min(y2),
// and max(y2). The box center is then adjusted to be
// C' = C + 0.5*(min(y0)+max(y0))*U0 + 0.5*(min(y1)+max(y1))*U1 +
// 0.5*(min(y2)+max(y2))*U2
Vector3<Real> kDiff = akPoint[0] - kBox.Center();
Real fY0Min = kDiff.Dot(kBox.Axis(0)), fY0Max = fY0Min;
Real fY1Min = kDiff.Dot(kBox.Axis(1)), fY1Max = fY1Min;
Real fY2Min = kDiff.Dot(kBox.Axis(2)), fY2Max = fY2Min;
for (int i = 1; i < iQuantity; i++)
{
kDiff = akPoint[i] - kBox.Center();
Real fY0 = kDiff.Dot(kBox.Axis(0));
if ( fY0 < fY0Min )
fY0Min = fY0;
else if ( fY0 > fY0Max )
fY0Max = fY0;
Real fY1 = kDiff.Dot(kBox.Axis(1));
if ( fY1 < fY1Min )
fY1Min = fY1;
else if ( fY1 > fY1Max )
fY1Max = fY1;
Real fY2 = kDiff.Dot(kBox.Axis(2));
if ( fY2 < fY2Min )
fY2Min = fY2;
else if ( fY2 > fY2Max )
fY2Max = fY2;
}
kBox.Center() += (((Real)0.5)*(fY0Min+fY0Max))*kBox.Axis(0) +
(((Real)0.5)*(fY1Min+fY1Max))*kBox.Axis(1) +
(((Real)0.5)*(fY2Min+fY2Max))*kBox.Axis(2);
kBox.Extent(0) = ((Real)0.5)*(fY0Max - fY0Min);
kBox.Extent(1) = ((Real)0.5)*(fY1Max - fY1Min);
kBox.Extent(2) = ((Real)0.5)*(fY2Max - fY2Min);
return kBox;
}
示例9:
Vector3<Real> Wml::GetPoint (int iIndex, const Box3<Real>& rkBox)
{
Vector3<Real> kPoint = rkBox.Center();
if ( iIndex & 4 )
kPoint += rkBox.Extent(2)*rkBox.Axis(2);
else
kPoint -= rkBox.Extent(2)*rkBox.Axis(2);
if ( iIndex & 2 )
kPoint += rkBox.Extent(1)*rkBox.Axis(1);
else
kPoint -= rkBox.Extent(1)*rkBox.Axis(1);
if ( iIndex & 1 )
kPoint += rkBox.Extent(0)*rkBox.Axis(0);
else
kPoint -= rkBox.Extent(0)*rkBox.Axis(0);
return kPoint;
}
示例10: ContOrientedBox
bool Wml::ContOrientedBox (int iQuantity, const Vector3<Real>* akPoint,
const bool* abValid, Box3<Real>& rkBox)
{
if ( !GaussPointsFit(iQuantity,akPoint,abValid,rkBox.Center(),
rkBox.Axes(),rkBox.Extents()) )
{
return false;
}
// Let C be the box center and let U0, U1, and U2 be the box axes. Each
// input point is of the form X = C + y0*U0 + y1*U1 + y2*U2. The
// following code computes min(y0), max(y0), min(y1), max(y1), min(y2),
// and max(y2). The box center is then adjusted to be
// C' = C + 0.5*(min(y0)+max(y0))*U0 + 0.5*(min(y1)+max(y1))*U1 +
// 0.5*(min(y2)+max(y2))*U2
// get first valid vertex
Vector3<Real> kDiff;
Real fY0Min = (Real)0.0, fY0Max = (Real)0.0;
Real fY1Min = (Real)0.0, fY1Max = (Real)0.0;
Real fY2Min = (Real)0.0, fY2Max = (Real)0.0;
int i;
for (i = 0; i < iQuantity; i++)
{
if ( abValid[i] )
{
kDiff = akPoint[i] - rkBox.Center();
fY0Min = kDiff.Dot(rkBox.Axis(0));
fY0Max = fY0Min;
fY1Min = kDiff.Dot(rkBox.Axis(1));
fY1Max = fY1Min;
fY2Min = kDiff.Dot(rkBox.Axis(2));
fY2Max = fY2Min;
break;
}
}
for (i++; i < iQuantity; i++)
{
if ( abValid[i] )
{
kDiff = akPoint[i] - rkBox.Center();
Real fY0 = kDiff.Dot(rkBox.Axis(0));
if ( fY0 < fY0Min )
fY0Min = fY0;
else if ( fY0 > fY0Max )
fY0Max = fY0;
Real fY1 = kDiff.Dot(rkBox.Axis(1));
if ( fY1 < fY1Min )
fY1Min = fY1;
else if ( fY1 > fY1Max )
fY1Max = fY1;
Real fY2 = kDiff.Dot(rkBox.Axis(2));
if ( fY2 < fY2Min )
fY2Min = fY2;
else if ( fY2 > fY2Max )
fY2Max = fY2;
}
}
rkBox.Center() += (0.5f*(fY0Min+fY0Max))*rkBox.Axis(0)
+ (0.5f*(fY1Min+fY1Max))*rkBox.Axis(1) +
(0.5f*(fY2Min+fY2Max))*rkBox.Axis(2);
rkBox.Extent(0) = 0.5f*(fY0Max - fY0Min);
rkBox.Extent(1) = 0.5f*(fY1Max - fY1Min);
rkBox.Extent(2) = 0.5f*(fY2Max - fY2Min);
return true;
}
示例11: GetBoxConfiguration
void Wml::GetBoxConfiguration (const Vector3<Real>& rkAxis,
const Box3<Real>& rkBox, ContactConfig<Real>& rkConfig)
{
// Description of coordinate ordering scheme for ContactConfig.m_aiIndex.
//
// Vertex number (up/down) vs. sign of extent (only matters in mapping
// back)
// 012
// 0 ---
// 1 +--
// 2 -+-
// 3 ++-
// 4 --+
// 5 +-+
// 6 -++
// 7 +++
//
// When it returns an ordering in the ContactConfig, it is also
// guarenteed to be in-order (if 4 vertices, then they are guarunteed in
// an order that will create a box, e.g. 0,1,3,2).
//
// assert: akAxis is an array containing unit length vectors
Real afAxis[3] =
{
rkAxis.Dot(rkBox.Axis(0)),
rkAxis.Dot(rkBox.Axis(1)),
rkAxis.Dot(rkBox.Axis(2))
};
Real afAAxis[3] =
{
Math<Real>::FAbs(afAxis[0]),
Math<Real>::FAbs(afAxis[1]),
Math<Real>::FAbs(afAxis[2])
};
Real fMaxProjectedExtent;
if ( afAAxis[0] < Math<Real>::EPSILON )
{
if ( afAAxis[1] < Math<Real>::EPSILON )
{
// face-face
rkConfig.m_kMap = m44;
fMaxProjectedExtent = afAAxis[2]*rkBox.Extent(2);
// faces have normals along axis[2]
if ( afAxis[2] > (Real)0.0 )
{
rkConfig.m_aiIndex[0] = 0;
rkConfig.m_aiIndex[1] = 1;
rkConfig.m_aiIndex[2] = 3;
rkConfig.m_aiIndex[3] = 2;
rkConfig.m_aiIndex[4] = 6;
rkConfig.m_aiIndex[5] = 7;
rkConfig.m_aiIndex[6] = 5;
rkConfig.m_aiIndex[7] = 4;
}
else
{
rkConfig.m_aiIndex[0] = 6;
rkConfig.m_aiIndex[1] = 7;
rkConfig.m_aiIndex[2] = 5;
rkConfig.m_aiIndex[3] = 4;
rkConfig.m_aiIndex[4] = 0;
rkConfig.m_aiIndex[5] = 1;
rkConfig.m_aiIndex[6] = 3;
rkConfig.m_aiIndex[7] = 2;
}
}
else if ( afAAxis[2] < Math<Real>::EPSILON )
{
// face-face
rkConfig.m_kMap = m44;
fMaxProjectedExtent = afAAxis[1]*rkBox.Extent(1);
// faces have normals along axis[1]
if ( afAxis[1] > (Real)0.0 )
{
rkConfig.m_aiIndex[0] = 4;
rkConfig.m_aiIndex[1] = 5;
rkConfig.m_aiIndex[2] = 1;
rkConfig.m_aiIndex[3] = 0;
rkConfig.m_aiIndex[4] = 2;
rkConfig.m_aiIndex[5] = 3;
rkConfig.m_aiIndex[6] = 7;
rkConfig.m_aiIndex[7] = 6;
}
else
{
rkConfig.m_aiIndex[0] = 2;
rkConfig.m_aiIndex[1] = 3;
rkConfig.m_aiIndex[2] = 7;
rkConfig.m_aiIndex[3] = 6;
//.........这里部分代码省略.........
示例12: SqrDistance
//----------------------------------------------------------------------------
Real Mgc::SqrDistance (const Line3& rkLine, const Box3& rkBox,
Real* pfLParam, Real* pfBParam0, Real* pfBParam1, Real* pfBParam2)
{
#ifdef _DEBUG
// The four parameters pointers are either all non-null or all null.
if ( pfLParam )
{
assert( pfBParam0 && pfBParam1 && pfBParam2 );
}
else
{
assert( !pfBParam0 && !pfBParam1 && !pfBParam2 );
}
#endif
// compute coordinates of line in box coordinate system
Vector3 kDiff = rkLine.Origin() - rkBox.Center();
Vector3 kPnt(kDiff.Dot(rkBox.Axis(0)),kDiff.Dot(rkBox.Axis(1)),
kDiff.Dot(rkBox.Axis(2)));
Vector3 kDir(rkLine.Direction().Dot(rkBox.Axis(0)),
rkLine.Direction().Dot(rkBox.Axis(1)),
rkLine.Direction().Dot(rkBox.Axis(2)));
// Apply reflections so that direction vector has nonnegative components.
bool bReflect[3];
int i;
for (i = 0; i < 3; i++)
{
if ( kDir[i] < 0.0f )
{
kPnt[i] = -kPnt[i];
kDir[i] = -kDir[i];
bReflect[i] = true;
}
else
{
bReflect[i] = false;
}
}
Real fSqrDistance = 0.0f;
if ( kDir.x > 0.0f )
{
if ( kDir.y > 0.0f )
{
if ( kDir.z > 0.0f )
{
// (+,+,+)
CaseNoZeros(kPnt,kDir,rkBox,pfLParam,fSqrDistance);
}
else
{
// (+,+,0)
Case0(0,1,2,kPnt,kDir,rkBox,pfLParam,fSqrDistance);
}
}
else
{
if ( kDir.z > 0.0f )
{
// (+,0,+)
Case0(0,2,1,kPnt,kDir,rkBox,pfLParam,fSqrDistance);
}
else
{
// (+,0,0)
Case00(0,1,2,kPnt,kDir,rkBox,pfLParam,fSqrDistance);
}
}
}
else
{
if ( kDir.y > 0.0f )
{
if ( kDir.z > 0.0f )
{
// (0,+,+)
Case0(1,2,0,kPnt,kDir,rkBox,pfLParam,fSqrDistance);
}
else
{
// (0,+,0)
Case00(1,0,2,kPnt,kDir,rkBox,pfLParam,fSqrDistance);
}
}
else
{
if ( kDir.z > 0.0f )
{
// (0,0,+)
Case00(2,0,1,kPnt,kDir,rkBox,pfLParam,fSqrDistance);
}
else
{
// (0,0,0)
Case000(kPnt,rkBox,fSqrDistance);
if ( pfLParam )
*pfLParam = 0.0f;
//.........这里部分代码省略.........
示例13: FindIntersection
bool Wml::FindIntersection (const Box3<Real>& rkBox,
const Vector3<Real>& rkBoxVelocity, const Sphere3<Real>& rkSphere,
const Vector3<Real>& rkSphVelocity, Real& rfTFirst, Real fTMax,
int& riQuantity, Vector3<Real>& rkP)
{
// Find intersections relative to the coordinate system of the box.
// The sphere is transformed to the box coordinates and the velocity of
// the sphere is relative to the box.
Vector3<Real> kCDiff = rkSphere.Center() - rkBox.Center();
Vector3<Real> kVel = rkSphVelocity - rkBoxVelocity;
Real fAx = kCDiff.Dot(rkBox.Axis(0));
Real fAy = kCDiff.Dot(rkBox.Axis(1));
Real fAz = kCDiff.Dot(rkBox.Axis(2));
Real fVx = kVel.Dot(rkBox.Axis(0));
Real fVy = kVel.Dot(rkBox.Axis(1));
Real fVz = kVel.Dot(rkBox.Axis(2));
// flip coordinate frame into the first octant
int iSignX = 1;
if ( fAx < (Real)0.0 )
{
fAx = -fAx;
fVx = -fVx;
iSignX = -1;
}
int iSignY = 1;
if ( fAy < (Real)0.0 )
{
fAy = -fAy;
fVy = -fVy;
iSignY = -1;
}
int iSignZ = 1;
if ( fAz < (Real)0.0 )
{
fAz = -fAz;
fVz = -fVz;
iSignZ = -1;
}
// intersection coordinates
Real fIx, fIy, fIz;
int iRetVal;
if ( fAx <= rkBox.Extent(0) )
{
if ( fAy <= rkBox.Extent(1) )
{
if ( fAz <= rkBox.Extent(2) )
{
// sphere center inside box
rfTFirst = (Real)0.0;
riQuantity = 0;
return false;
}
else
{
// sphere above face on axis Z
iRetVal = FindFaceRegionIntersection(rkBox.Extent(0),
rkBox.Extent(1),rkBox.Extent(2),fAx,fAy,fAz,fVx,fVy,fVz,
rfTFirst,rkSphere.Radius(),fIx,fIy,fIz,true);
}
}
else
{
if ( fAz <= rkBox.Extent(2) )
{
// sphere above face on axis Y
iRetVal = FindFaceRegionIntersection(rkBox.Extent(0),
rkBox.Extent(2),rkBox.Extent(1),fAx,fAz,fAy,fVx,fVz,fVy,
rfTFirst,rkSphere.Radius(),fIx,fIz,fIy,true);
}
else
{
// sphere is above the edge formed by faces y and z
iRetVal = FindEdgeRegionIntersection(rkBox.Extent(1),
rkBox.Extent(0),rkBox.Extent(2),fAy,fAx,fAz,fVy,fVx,fVz,
rfTFirst,rkSphere.Radius(),fIy,fIx,fIz,true);
}
}
}
else
{
if ( fAy <= rkBox.Extent(1) )
{
if ( fAz <= rkBox.Extent(2) )
{
// sphere above face on axis X
iRetVal = FindFaceRegionIntersection(rkBox.Extent(1),
rkBox.Extent(2),rkBox.Extent(0),fAy,fAz,fAx,fVy,fVz,fVx,
rfTFirst,rkSphere.Radius(),fIy,fIz,fIx,true);
}
else
{
// sphere is above the edge formed by faces x and z
iRetVal = FindEdgeRegionIntersection(rkBox.Extent(0),
rkBox.Extent(1),rkBox.Extent(2),fAx,fAy,fAz,fVx,fVy,fVz,
rfTFirst,rkSphere.Radius(),fIx,fIy,fIz,true);
//.........这里部分代码省略.........
示例14: TestIntersection
bool Wml::TestIntersection (const Box3<Real>& rkBox,
const Sphere3<Real>& rkSphere)
{
// Test for intersection in the coordinate system of the box by
// transforming the sphere into that coordinate system.
Vector3<Real> kCDiff = rkSphere.Center() - rkBox.Center();
Real fAx = Math<Real>::FAbs(kCDiff.Dot(rkBox.Axis(0)));
Real fAy = Math<Real>::FAbs(kCDiff.Dot(rkBox.Axis(1)));
Real fAz = Math<Real>::FAbs(kCDiff.Dot(rkBox.Axis(2)));
Real fDx = fAx - rkBox.Extent(0);
Real fDy = fAy - rkBox.Extent(1);
Real fDz = fAz - rkBox.Extent(2);
if ( fAx <= rkBox.Extent(0) )
{
if ( fAy <= rkBox.Extent(1) )
{
if ( fAz <= rkBox.Extent(2) )
{
// sphere center inside box
return true;
}
else
{
// potential sphere-face intersection with face z
return fDz <= rkSphere.Radius();
}
}
else
{
if ( fAz <= rkBox.Extent(2) )
{
// potential sphere-face intersection with face y
return fDy <= rkSphere.Radius();
}
else
{
// potential sphere-edge intersection with edge formed
// by faces y and z
Real fRSqr = rkSphere.Radius()*rkSphere.Radius();
return fDy*fDy + fDz*fDz <= fRSqr;
}
}
}
else
{
if ( fAy <= rkBox.Extent(1) )
{
if ( fAz <= rkBox.Extent(2) )
{
// potential sphere-face intersection with face x
return fDx <= rkSphere.Radius();
}
else
{
// potential sphere-edge intersection with edge formed
// by faces x and z
Real fRSqr = rkSphere.Radius()*rkSphere.Radius();
return fDx*fDx + fDz*fDz <= fRSqr;
}
}
else
{
if ( fAz <= rkBox.Extent(2) )
{
// potential sphere-edge intersection with edge formed
// by faces x and y
Real fRSqr = rkSphere.Radius()*rkSphere.Radius();
return fDx*fDx + fDy*fDy <= fRSqr;
}
else
{
// potential sphere-vertex intersection at corner formed
// by faces x,y,z
Real fRSqr = rkSphere.Radius()*rkSphere.Radius();
return fDx*fDx + fDy*fDy + fDz*fDz <= fRSqr;
}
}
}
}