#include <TAPsBoundingSphere.hpp>


Public Member Functions | |
| BoundingSphere (const BoundingSphere &orig) | |
| Copy Constructor. | |
| BoundingSphere (int id) | |
| BoundingSphere () | |
| Constructor(s) and Destructor. | |
| virtual T | GetRadius () const |
| BoundingSphere< T > & | operator= (BoundingSphere< T > const &orig) |
| virtual void | ScaledBy (T val) |
| virtual void | SetRadius (T radius) |
| virtual std::string | StrInfo () const |
| Return this object info as a string. | |
| virtual T | TestOverlapWith (BoundingVolume< T > const *const that) const |
| virtual bool | TestPointLocation (Vector3< T > const *const pvPoint, TransformationSupport< T > const *const pTransform, Vector3< T > *const pvDistance=NULL) const |
| Test if a point is inside this sphere bounding volume. | |
| virtual bool | TestPointLocation (Vector3< T > const *const pvPoint, Vector3< T > *const pvDistance=NULL) const |
| Test if a point is inside this sphere bounding volume. | |
| virtual | ~BoundingSphere () |
Protected Attributes | |
| T | m_tRadius |
Friends | |
| std::ostream & | operator<< (std::ostream &output, BoundingSphere< T > const &obj) |
Definition at line 28 of file TAPsBoundingSphere.hpp.
| BEGIN_NAMESPACE_TAPs BoundingSphere< T >::BoundingSphere | ( | ) | [inline] |
Constructor(s) and Destructor.
BoundingSphere class is a subclass of BoundingVolume class.
Definition at line 22 of file TAPsBoundingSphere.cpp.
00023 : BoundingVolume<T>( Enum::BOUNDING_SPHERE ), 00024 m_tRadius( 1 ) 00025 {}
| BoundingSphere< T >::BoundingSphere | ( | int | id | ) | [inline] |
Definition at line 28 of file TAPsBoundingSphere.cpp.
00029 : BoundingVolume<T>( Enum::BOUNDING_SPHERE, id ), 00030 m_tRadius( 1 ) 00031 {}
| BoundingSphere< T >::BoundingSphere | ( | const BoundingSphere< T > & | orig | ) | [inline] |
Copy Constructor.
Definition at line 34 of file TAPsBoundingSphere.cpp.
00035 : BoundingVolume<T>( orig ), 00036 m_vCenter( orig.m_vCenter ), 00037 m_tRadius( orig.m_tRadius ) 00038 { 00039 m_vCenter = orig.m_vCenter; 00040 }
| BoundingSphere< T >::~BoundingSphere | ( | ) | [inline, virtual] |
| virtual T BoundingSphere< T >::GetRadius | ( | ) | const [inline, virtual] |
Reimplemented from BoundingVolume< T >.
Definition at line 54 of file TAPsBoundingSphere.hpp.
00054 {return m_tRadius; }
| BoundingSphere<T>& BoundingSphere< T >::operator= | ( | BoundingSphere< T > const & | orig | ) | [inline] |
| void BoundingSphere< T >::ScaledBy | ( | T | val | ) | [inline, virtual] |
Implements BoundingVolume< T >.
Definition at line 75 of file TAPsBoundingSphere.cpp.
00076 { 00077 assert( 0.0 <= val ); 00078 GetTransform().PreApplyUniformScale( val ); 00079 }
| virtual void BoundingSphere< T >::SetRadius | ( | T | radius | ) | [inline, virtual] |
Reimplemented from BoundingVolume< T >.
Definition at line 55 of file TAPsBoundingSphere.hpp.
00055 { m_tRadius = radius; }
| std::string BoundingSphere< T >::StrInfo | ( | ) | const [inline, virtual] |
Return this object info as a string.
Reimplemented from BoundingVolume< T >.
Definition at line 48 of file TAPsBoundingSphere.cpp.
00049 { 00050 std::string str = BoundingVolume<T>::StrInfo(); 00051 std::ostringstream ss; 00052 ss << " Radius: " << m_tRadius; 00053 return str + ss.str() + "\n"; 00054 }
| T BoundingSphere< T >::TestOverlapWith | ( | BoundingVolume< T > const *const | that | ) | const [inline, virtual] |
This function is inherited from BoundingVolume<T> class
Implements BoundingVolume< T >.
Definition at line 247 of file TAPsBoundingSphere.cpp.
00248 { 00249 std::cout << "BoundingSphere<T>::TestOverlapWith( BoundingVolume<T> ) -- NOT IMPLEMENTED YET!!!\n"; 00250 return 0; 00251 }
| bool BoundingSphere< T >::TestPointLocation | ( | Vector3< T > const *const | pvPoint, | |
| TransformationSupport< T > const *const | pTransform, | |||
| Vector3< T > *const | pvDistance = NULL | |||
| ) | const [inline, virtual] |
Test if a point is inside this sphere bounding volume.
This Test Point Location function returns true if the input point input point to the bounding surface in the world (test point) coordinate.
pvDistance is for returning the shortest vector measuring from the input point to the bounding surface.
Therefore, this fn can be used to tell whether the point is inside or outside the bounding volume and how to move it to the surface of the bounding volume with the shortest distance.
Implements BoundingVolume< T >.
Definition at line 159 of file TAPsBoundingSphere.cpp.
00163 { 00164 bool isThePointInsideTheSphere = false; 00165 //--------------------------------------------------------------- 00166 TransformationSupport<T> transform; // default ctor is an identity 00167 if ( pTransform->GetStatusApplyTransformation() ) { 00168 transform.ReturnMatrixTransform() *= pTransform->GetMatrixTransform(); 00169 // The above statement is equivalent to the below statement 00170 //transform.ReturnMatrixTransform() = transform.GetMatrixTransform() * pTransform->GetMatrixTransform(); 00171 transform.EnableStatusApplyTransformation(); 00172 } 00173 if ( GetTransform().GetStatusApplyTransformation() ) { 00174 transform.ReturnMatrixTransform() *= GetTransform().GetMatrixTransform(); 00175 // The above statement is equivalent to the below statement 00176 //transform.ReturnMatrixTransform() = transform.GetMatrixTransform() * GetTransform().GetMatrixTransform(); 00177 transform.EnableStatusApplyTransformation(); 00178 } 00179 //--------------------------------------------------------------- 00180 // In the local coordinate of the bounding sphere, 00181 // the sphere's center is at the origin. 00182 // The sphere has radius and center. 00183 //--------------------------------------------------------------- 00184 // Transform pvPoint to the sphere local coordinate 00185 Vector3<T> location = *pvPoint; 00186 if ( transform.GetStatusApplyTransformation() ) { 00187 //location -= GetTransform().GetTranslation(); 00188 //location = GetTransform().GetMatrixRotation().GetInverse() * location; 00189 location = (transform.GetMatrixTransform().GetInverse() * Vector4<T>(location)).GetVector3(); 00190 } 00191 // Shift the location of point by the cylinder center 00192 // i.e. shift the cylinder to the origin (0,0,0) 00193 location -= GetCenter(); 00194 //--------------------------------------------------------------- 00195 // Now the sphere is centered at the origin. 00196 // And the input point has been transformed into the sphere coordinate. 00197 // The test can be performed below. 00198 T ptRadius = location.Length(); 00199 //=============================================================== 00200 // If the point is INSIDE the sphere 00201 //--------------------------------------------------------------- 00202 // If the point is within the sphere radius 00203 T distance = GetRadius() - ptRadius; 00204 if ( distance >= 0 ) { 00205 if ( pvDistance ) { 00206 (*pvDistance) = location.Normalized() * distance; 00207 //------------------------- 00208 // Now rotate it back by the rotation matrix (from the transform matrix). 00209 // REMARK: Translation (from the transform matrix) is NOT applied back, 00210 // because pvDistance represents a displacement vector from 00211 // the input point to the sphere surface. 00212 if ( transform.GetStatusApplyTransformation() ) { 00213 (*pvDistance) = transform.GetMatrixRotation() * (*pvDistance); 00214 } 00215 //------------------------- 00216 isThePointInsideTheSphere = true; 00217 } 00218 } 00219 //=============================================================== 00220 // If the point is NOT INSIDE the sphere radius 00221 //--------------------------------------------------------------- 00222 else { 00223 if ( pvDistance ) { 00224 (*pvDistance).SetXYZ( 0, 0, 0 ); 00225 } 00226 } 00227 00228 /* 00229 // TEMPORARY CODE 00230 //--------------------------------------------------------------- 00231 // Transform the pvDistance to the world coordinate 00232 if ( pvDistance ) { 00233 if ( !isThePointInsideTheSphere ) { 00234 (*pvDistance).SetXYZ( 0, 0, 0 ); 00235 } 00236 else { 00237 } 00238 } 00239 //*/ 00240 00241 //--------------------------------------------------------------- 00242 return isThePointInsideTheSphere; 00243 }
| bool BoundingSphere< T >::TestPointLocation | ( | Vector3< T > const *const | pvPoint, | |
| Vector3< T > *const | pvDistance = NULL | |||
| ) | const [inline, virtual] |
Test if a point is inside this sphere bounding volume.
This Test Point Location function returns true if the input point (pvPoint) is inside the bounding volume and returns false otherwise.
pvDistance is for returning the shortest vector measuring from the input point to the bounding surface in the world (test point) coordinate.
Therefore, this fn can be used to tell whether the point is inside or outside the bounding volume and how to move it to the surface of the bounding volume with the shortest distance.
Implements BoundingVolume< T >.
Definition at line 86 of file TAPsBoundingSphere.cpp.
00089 { 00090 bool isThePointInsideTheSphere = false; 00091 //--------------------------------------------------------------- 00092 // In the local coordinate of the bounding sphere, 00093 // the sphere's center is at the origin. 00094 // The sphere has radius and center. 00095 //--------------------------------------------------------------- 00096 // Transform pvPoint to the sphere local coordinate 00097 Vector3<T> location = *pvPoint; 00098 if ( GetTransform().GetStatusApplyTransformation() ) { 00099 //location -= GetTransform().GetTranslation(); 00100 //location = GetTransform().GetMatrixRotation().GetInverse() * location; 00101 location = (GetTransform().GetMatrixTransform().GetInverse() * Vector4<T>(location)).GetVector3(); 00102 } 00103 // Shift the location of point by the cylinder center 00104 // i.e. shift the cylinder to the origin (0,0,0) 00105 location -= GetCenter(); 00106 //--------------------------------------------------------------- 00107 // Now the sphere is centered at the origin. 00108 // And the input point has been transformed into the sphere coordinate. 00109 // The test can be performed below. 00110 T ptRadius = location.Length(); 00111 //=============================================================== 00112 // If the point is INSIDE the sphere 00113 //--------------------------------------------------------------- 00114 // If the point is within the sphere radius 00115 T distance = GetRadius() - ptRadius; 00116 if ( distance >= 0 ) { 00117 if ( pvDistance ) { 00118 (*pvDistance) = location.Normalized() * distance; 00119 //------------------------- 00120 // Now rotate it back by the rotation matrix (from the transform matrix). 00121 // REMARK: Translation (from the transform matrix) is NOT applied back, 00122 // because pvDistance represents a displacement vector from 00123 // the input point to the sphere surface. 00124 if ( GetTransform().GetStatusApplyTransformation() ) { 00125 (*pvDistance) = GetTransform().GetMatrixRotation() * (*pvDistance); 00126 } 00127 //------------------------- 00128 isThePointInsideTheSphere = true; 00129 } 00130 } 00131 //=============================================================== 00132 // If the point is NOT INSIDE the sphere radius 00133 //--------------------------------------------------------------- 00134 else { 00135 if ( pvDistance ) { 00136 (*pvDistance).SetXYZ( 0, 0, 0 ); 00137 } 00138 } 00139 00140 /* 00141 // TEMPORARY CODE 00142 //--------------------------------------------------------------- 00143 // Transform the pvDistance to the world coordinate 00144 if ( pvDistance ) { 00145 if ( isThePointInsideTheSphere ) { 00146 } 00147 else { 00148 (*pvDistance).SetXYZ( 0, 0, 0 ); 00149 } 00150 } 00151 //*/ 00152 00153 //--------------------------------------------------------------- 00154 return isThePointInsideTheSphere; 00155 }
| std::ostream& operator<< | ( | std::ostream & | output, | |
| BoundingSphere< T > const & | obj | |||
| ) | [friend] |
Definition at line 34 of file TAPsBoundingSphere.hpp.
00035 { 00036 output << obj.StrInfo(); 00037 return output; 00038 }
T BoundingSphere< T >::m_tRadius [protected] |
Definition at line 158 of file TAPsBoundingSphere.hpp.
1.5.6