Wm4IntrSegment3Box3.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "Wm4FoundationPCH.h"
00018 #include "Wm4IntrSegment3Box3.h"
00019 #include "Wm4IntrLine3Box3.h"
00020
00021 namespace Wm4
00022 {
00023
00024 template <class Real>
00025 IntrSegment3Box3<Real>::IntrSegment3Box3 (const Segment3<Real>& rkSegment,
00026 const Box3<Real>& rkBox, bool bSolid)
00027 :
00028 m_rkSegment(rkSegment),
00029 m_rkBox(rkBox)
00030 {
00031 m_bSolid = bSolid;
00032 }
00033
00034 template <class Real>
00035 const Segment3<Real>& IntrSegment3Box3<Real>::GetSegment () const
00036 {
00037 return m_rkSegment;
00038 }
00039
00040 template <class Real>
00041 const Box3<Real>& IntrSegment3Box3<Real>::GetBox () const
00042 {
00043 return m_rkBox;
00044 }
00045
00046 template <class Real>
00047 bool IntrSegment3Box3<Real>::Test ()
00048 {
00049 Real afAWdU[3], afADdU[3], afAWxDdU[3], fRhs;
00050
00051 Vector3<Real> kDiff = m_rkSegment.Origin - m_rkBox.Center;
00052
00053 afAWdU[0] = Math<Real>::FAbs(m_rkSegment.Direction.Dot(m_rkBox.Axis[0]));
00054 afADdU[0] = Math<Real>::FAbs(kDiff.Dot(m_rkBox.Axis[0]));
00055 fRhs = m_rkBox.Extent[0] + m_rkSegment.Extent*afAWdU[0];
00056 if (afADdU[0] > fRhs)
00057 {
00058 return false;
00059 }
00060
00061 afAWdU[1] = Math<Real>::FAbs(m_rkSegment.Direction.Dot(m_rkBox.Axis[1]));
00062 afADdU[1] = Math<Real>::FAbs(kDiff.Dot(m_rkBox.Axis[1]));
00063 fRhs = m_rkBox.Extent[1] + m_rkSegment.Extent*afAWdU[1];
00064 if (afADdU[1] > fRhs)
00065 {
00066 return false;
00067 }
00068
00069 afAWdU[2] = Math<Real>::FAbs(m_rkSegment.Direction.Dot(m_rkBox.Axis[2]));
00070 afADdU[2] = Math<Real>::FAbs(kDiff.Dot(m_rkBox.Axis[2]));
00071 fRhs = m_rkBox.Extent[2] + m_rkSegment.Extent*afAWdU[2];
00072 if (afADdU[2] > fRhs)
00073 {
00074 return false;
00075 }
00076
00077 Vector3<Real> kWxD = m_rkSegment.Direction.Cross(kDiff);
00078
00079 afAWxDdU[0] = Math<Real>::FAbs(kWxD.Dot(m_rkBox.Axis[0]));
00080 fRhs = m_rkBox.Extent[1]*afAWdU[2] + m_rkBox.Extent[2]*afAWdU[1];
00081 if (afAWxDdU[0] > fRhs)
00082 {
00083 return false;
00084 }
00085
00086 afAWxDdU[1] = Math<Real>::FAbs(kWxD.Dot(m_rkBox.Axis[1]));
00087 fRhs = m_rkBox.Extent[0]*afAWdU[2] + m_rkBox.Extent[2]*afAWdU[0];
00088 if (afAWxDdU[1] > fRhs)
00089 {
00090 return false;
00091 }
00092
00093 afAWxDdU[2] = Math<Real>::FAbs(kWxD.Dot(m_rkBox.Axis[2]));
00094 fRhs = m_rkBox.Extent[0]*afAWdU[1] + m_rkBox.Extent[1]*afAWdU[0];
00095 if (afAWxDdU[2] > fRhs)
00096 {
00097 return false;
00098 }
00099
00100 return true;
00101 }
00102
00103 template <class Real>
00104 bool IntrSegment3Box3<Real>::Find ()
00105 {
00106 Real fT0 = -m_rkSegment.Extent, fT1 = m_rkSegment.Extent;
00107 return IntrLine3Box3<Real>::DoClipping(fT0,fT1,m_rkSegment.Origin,
00108 m_rkSegment.Direction,m_rkBox,m_bSolid,m_iQuantity,m_akPoint,
00109 m_iIntersectionType);
00110 }
00111
00112 template <class Real>
00113 int IntrSegment3Box3<Real>::GetQuantity () const
00114 {
00115 return m_iQuantity;
00116 }
00117
00118 template <class Real>
00119 const Vector3<Real>& IntrSegment3Box3<Real>::GetPoint (int i) const
00120 {
00121 assert(0 <= i && i < m_iQuantity);
00122 return m_akPoint[i];
00123 }
00124
00125
00126
00127
00128
00129 template WM4_FOUNDATION_ITEM
00130 class IntrSegment3Box3<float>;
00131
00132 template WM4_FOUNDATION_ITEM
00133 class IntrSegment3Box3<double>;
00134
00135 }