BoundingCylinder< T > Class Template Reference

BoundingCylinder class is a subclass of BoundingVolume class. More...

#include <TAPsBoundingCylinder.hpp>

Inheritance diagram for BoundingCylinder< T >:

Inheritance graph
[legend]
Collaboration diagram for BoundingCylinder< T >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 BoundingCylinder (const BoundingCylinder< T > &orig)
 Copy Constructor.
 BoundingCylinder (int id)
 BoundingCylinder ()
 Constructor(s) and Destructor.
virtual T GetHeight () const
virtual T GetRadius () const
BoundingCylinder< T > & operator= (BoundingCylinder< T > const &orig)
virtual void ScaledBy (T val)
virtual void SetHeight (T height)
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 cylinder bounding volume.
virtual bool TestPointLocation (Vector3< T > const *const pvPoint, Vector3< T > *const pvDistance=NULL) const
 Test if a point is inside this cylinder bounding volume.
virtual ~BoundingCylinder ()

Protected Attributes

m_tHeight
m_tRadius

Friends

std::ostream & operator<< (std::ostream &output, BoundingCylinder< T > const &obj)


Detailed Description

template<typename T>
class BoundingCylinder< T >

BoundingCylinder class is a subclass of BoundingVolume class.

Data:
Center is a Vector3<T> inherited from BoundingVolume class.
Radius is scalar.
Height is scalar.
Cylinder is orianted in z-direction from the center with the radius and half height from plus z and negative z.

See also:
TAPsCDLib.hpp for details about Collision Detection implemented in TAPs.

Definition at line 32 of file TAPsBoundingCylinder.hpp.


Constructor & Destructor Documentation

template<typename T>
BEGIN_NAMESPACE_TAPs BoundingCylinder< T >::BoundingCylinder (  )  [inline]

Constructor(s) and Destructor.

BoundingCylinder class is a subclass of BoundingVolume class.

Definition at line 22 of file TAPsBoundingCylinder.cpp.

00023     : BoundingVolume<T>( Enum::BOUNDING_CYLINDER ),
00024       m_tRadius( 1 ),
00025       m_tHeight( 1 )
00026 {}

template<typename T>
BoundingCylinder< T >::BoundingCylinder ( int  id  )  [inline]

Definition at line 29 of file TAPsBoundingCylinder.cpp.

00030     : BoundingVolume<T>( Enum::BOUNDING_CYLINDER, id ),
00031       m_tRadius( 1 ),
00032       m_tHeight( 1 )
00033 {}

template<typename T>
BoundingCylinder< T >::BoundingCylinder ( const BoundingCylinder< T > &  orig  )  [inline]

Copy Constructor.

Definition at line 36 of file TAPsBoundingCylinder.cpp.

00037     : BoundingVolume<T>( orig ),
00038       m_tRadius( orig.m_tRadius ),
00039       m_tHeight( orig.m_tHeight )
00040 {
00041     m_vCenter = orig.m_vCenter;
00042 }

template<typename T>
BoundingCylinder< T >::~BoundingCylinder (  )  [inline, virtual]

Definition at line 45 of file TAPsBoundingCylinder.cpp.

00046 {}


Member Function Documentation

template<typename T>
virtual T BoundingCylinder< T >::GetHeight (  )  const [inline, virtual]

Reimplemented from BoundingVolume< T >.

Definition at line 60 of file TAPsBoundingCylinder.hpp.

00060 {return m_tHeight; }

template<typename T>
virtual T BoundingCylinder< T >::GetRadius (  )  const [inline, virtual]

Reimplemented from BoundingVolume< T >.

Definition at line 58 of file TAPsBoundingCylinder.hpp.

00058 {return m_tRadius; }

template<typename T>
BoundingCylinder<T>& BoundingCylinder< T >::operator= ( BoundingCylinder< T > const &  orig  )  [inline]

template<typename T>
void BoundingCylinder< T >::ScaledBy ( val  )  [inline, virtual]

Implements BoundingVolume< T >.

Definition at line 79 of file TAPsBoundingCylinder.cpp.

00080 {
00081     assert( 0.0 <= val );
00082     GetTransform().PreApplyUniformScale( val );
00083 }

template<typename T>
virtual void BoundingCylinder< T >::SetHeight ( height  )  [inline, virtual]

Reimplemented from BoundingVolume< T >.

Definition at line 61 of file TAPsBoundingCylinder.hpp.

00061 { m_tHeight = height; }

template<typename T>
virtual void BoundingCylinder< T >::SetRadius ( radius  )  [inline, virtual]

Reimplemented from BoundingVolume< T >.

Definition at line 59 of file TAPsBoundingCylinder.hpp.

00059 { m_tRadius = radius; }

template<typename T>
std::string BoundingCylinder< T >::StrInfo (  )  const [inline, virtual]

Return this object info as a string.

Reimplemented from BoundingVolume< T >.

Definition at line 50 of file TAPsBoundingCylinder.cpp.

00051 {
00052     std::string str = BoundingVolume<T>::StrInfo();
00053     std::ostringstream ss;
00054     ss <<   "  Radius: " << m_tRadius;
00055     ss << "\n  Height: " << m_tHeight;
00056     return str + ss.str() + "\n";
00057 }

template<typename T>
T BoundingCylinder< T >::TestOverlapWith ( BoundingVolume< T > const *const   that  )  const [inline, virtual]

This function is inherited from BoundingVolume<T> class

Implements BoundingVolume< T >.

Definition at line 304 of file TAPsBoundingCylinder.cpp.

00305 {
00306     std::cout << "BoundingCylinder<T>::TestOverlapWith( BoundingVolume<T> ) -- NOT IMPLEMENTED YET!!!\n";
00307     return 0;
00308 }

template<typename T>
bool BoundingCylinder< 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 cylinder 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 189 of file TAPsBoundingCylinder.cpp.

00193 {
00194     bool isThePointInsideTheCylinder = false;
00195     //---------------------------------------------------------------
00196     TransformationSupport<T> transform; // default ctor is an identity
00197     if ( pTransform->GetStatusApplyTransformation() ) {
00198         transform.ReturnMatrixTransform() *= pTransform->GetMatrixTransform();
00199         // The above statement is equivalent to the below statement
00200         //transform.ReturnMatrixTransform() = transform.GetMatrixTransform() * pTransform->GetMatrixTransform();
00201         transform.EnableStatusApplyTransformation();
00202     }
00203     if ( GetTransform().GetStatusApplyTransformation() ) {
00204         transform.ReturnMatrixTransform() *= GetTransform().GetMatrixTransform();
00205         // The above statement is equivalent to the below statement
00206         //transform.ReturnMatrixTransform() = transform.GetMatrixTransform() * GetTransform().GetMatrixTransform();
00207         transform.EnableStatusApplyTransformation();
00208     }
00209     //---------------------------------------------------------------
00210     // In the local coordinate of the bounding cylinder, 
00211     // the cylinder axis is parallel to z-axis 
00212     // where it is shifted by the cylinder center.
00213     // The cylinder has radius, height and center.
00214     // Its height is measured from -z and +z axis
00215     // where its center is situated between height/2 in -z and +z axis.
00216     //---------------------------------------------------------------
00217     // Transform pvPoint to the cylinder local coordinate
00218     Vector3<T> location = *pvPoint;
00219     if ( transform.GetStatusApplyTransformation() ) {
00220         //location -= transform.GetTranslation();
00221         //location = transform.GetMatrixRotation().GetInverse() * location;
00222         location = (transform.GetMatrixTransform().GetInverse() * Vector4<T>( location )).GetVector3();
00223     }
00224     // Shift the location of point by the cylinder center
00225     // i.e. shift the cylinder to the origin (0,0,0)
00226     location -= GetCenter();
00227     //---------------------------------------------------------------
00228     // Now the cylinder is centered at the origin with its axis on the z-axis
00229     // where its height is from -height/2 to +height/2.
00230     // And the input point has been transformed into the cylinder coordinate.
00231     // The test can be performed below
00232     T   halfHeight = GetHeight()/2.0;
00233     T   ptRadius = sqrt( location[0]*location[0] + location[1]*location[1] );
00234     //===============================================================
00235     // If the point is INSIDE the cylinder
00236     //---------------------------------------------------------------
00237     // If the point is within the cylinder radius
00238     if ( ptRadius <= GetRadius() ) { 
00239         // If the point is within the cylinder height
00240         if ( -halfHeight <= location[2] && location[2] <= halfHeight ) {
00241             // Find the shortest distance vector from the point to the surface 
00242             // of the cylinder
00243             if ( pvDistance ) {
00244                 //(*pvDistance).SetXYZ( 0, 0, 0 );
00245                 T   difRadius = GetRadius() - ptRadius;
00246                 T   difHeight = halfHeight - fabs( location[2] );
00247                 if ( difRadius <= difHeight ) {
00248                     // If the point is on the z-axis (degenerate case)
00249                     if ( difRadius >= GetRadius() ) {
00250                         (*pvDistance).SetXYZ( 0, GetRadius(), 0 );
00251                     }
00252                     // If the point is NOT on the z-axis
00253                     else {
00254                         Vector2<T> difDirection = Vector2<T>( location[0], location[1] );
00255                         difDirection.Normalized();
00256                         difDirection *= difRadius;
00257                         (*pvDistance).SetXYZ( difDirection[0], difDirection[1], 0 );
00258                     }
00259                 }
00260                 else {
00261                     (*pvDistance).SetXYZ( 0, 0, location[2] >= 0 ? difHeight : -difHeight );
00262                 }
00263                 //-------------------------
00264                 // Now rotate it back by the rotation matrix (from the transform matrix).
00265                 // REMARK: Translation (from the transform matrix) is NOT applied back, 
00266                 //         because pvDistance represents a displacement vector from 
00267                 //         the input point to the cylinder surface.
00268                 if ( transform.GetStatusApplyTransformation() ) {
00269                     (*pvDistance) = transform.GetMatrixRotation() * (*pvDistance);
00270                 }
00271             }
00272             //-------------------------
00273             isThePointInsideTheCylinder = true;
00274         }
00275     }
00276     //===============================================================
00277     // If the point is NOT INSIDE the cylinder radius
00278     //---------------------------------------------------------------
00279     else {
00280         if ( pvDistance ) {
00281             (*pvDistance).SetXYZ( 0, 0, 0 );
00282         }
00283     }
00284 
00285     /*
00286     // TEMPORARY CODE
00287     //---------------------------------------------------------------
00288     // Transform the pvDistance to the world coordinate
00289     if ( pvDistance ) {
00290         if ( !isThePointInsideTheCylinder ) {
00291             (*pvDistance).SetXYZ( 0, 0, 0 );
00292         }
00293         else {
00294         }
00295     }
00296     //*/
00297 
00298     //---------------------------------------------------------------
00299     return isThePointInsideTheCylinder;
00300 }

template<typename T>
bool BoundingCylinder< T >::TestPointLocation ( Vector3< T > const *const   pvPoint,
Vector3< T > *const   pvDistance = NULL 
) const [inline, virtual]

Test if a point is inside this cylinder 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 90 of file TAPsBoundingCylinder.cpp.

00093 {
00094     bool isThePointInsideTheCylinder = false;
00095     //---------------------------------------------------------------
00096     // In the local coordinate of the bounding cylinder, 
00097     // the cylinder axis is parallel to z-axis 
00098     // where it is shifted by the cylinder center.
00099     // The cylinder has radius, height and center.
00100     // Its height is measured from -z and +z axis
00101     // where its center is situated between height/2 in -z and +z axis.
00102     //---------------------------------------------------------------
00103     // Transform pvPoint to the cylinder local coordinate
00104     Vector3<T> location = *pvPoint;
00105     if ( GetTransform().GetStatusApplyTransformation() ) {
00106         //location -= GetTransform().GetTranslation();
00107         //location = GetTransform().GetMatrixRotation().GetInverse() * location;
00108         location = (GetTransform().GetMatrixTransform().GetInverse() * Vector4<T>( location )).GetVector3();
00109     }
00110     // Shift the location of point by the cylinder center
00111     // i.e. shift the cylinder to the origin (0,0,0)
00112     location -= GetCenter();
00113     //---------------------------------------------------------------
00114     // Now the cylinder is centered at the origin with its axis on the z-axis
00115     // where its height is from -height/2 to +height/2.
00116     // And the input point has been transformed into the cylinder coordinate.
00117     // The test can be performed below
00118     T   halfHeight = GetHeight()/2.0;
00119     T   ptRadius = sqrt( location[0]*location[0] + location[1]*location[1] );
00120     //===============================================================
00121     // If the point is INSIDE the cylinder
00122     //---------------------------------------------------------------
00123     // If the point is within the cylinder radius
00124     if ( ptRadius <= GetRadius() ) { 
00125         // If the point is within the cylinder height
00126         if ( -halfHeight <= location[2] && location[2] <= halfHeight ) {
00127             // Find the shortest distance vector from the point to the surface 
00128             // of the cylinder
00129             if ( pvDistance ) {
00130                 T   difRadius = GetRadius() - ptRadius;
00131                 T   difHeight = halfHeight - fabs( location[2] );
00132                 if ( difRadius <= difHeight ) {
00133                     // If the point is on the z-axis (degenerate case)
00134                     if ( difRadius >= GetRadius() ) {
00135                         (*pvDistance).SetXYZ( 0, GetRadius(), 0 );
00136                     }
00137                     // If the point is NOT on the z-axis
00138                     else {
00139                         Vector2<T> difDirection = Vector2<T>( location[0], location[1] );
00140                         difDirection.Normalized();
00141                         difDirection *= difRadius;
00142                         (*pvDistance).SetXYZ( difDirection[0], difDirection[1], 0 );
00143                     }
00144                 }
00145                 else {
00146                     (*pvDistance).SetXYZ( 0, 0, location[2] >= 0 ? difHeight : -difHeight );
00147                 }
00148                 //-------------------------
00149                 // Now rotate it back by the rotation matrix (from the transform matrix).
00150                 // REMARK: Translation (from the transform matrix) is NOT applied back, 
00151                 //         because pvDistance represents a displacement vector from 
00152                 //         the input point to the cylinder surface.
00153                 if ( GetTransform().GetStatusApplyTransformation() ) {
00154                     (*pvDistance) = GetTransform().GetMatrixRotation() * (*pvDistance);
00155                 }
00156             }
00157             //-------------------------
00158             isThePointInsideTheCylinder = true;
00159         }
00160     }
00161     //===============================================================
00162     // If the point is NOT INSIDE the cylinder radius
00163     //---------------------------------------------------------------
00164     else {
00165         if ( pvDistance ) {
00166             (*pvDistance).SetXYZ( 0, 0, 0 );
00167         }
00168     }
00169 
00170     /*
00171     // TEMPORARY CODE
00172     //---------------------------------------------------------------
00173     // Transform the pvDistance to the world coordinate
00174     if ( pvDistance ) {
00175         if ( !isThePointInsideTheCylinder ) {
00176             (*pvDistance).SetXYZ( 0, 0, 0 );
00177         }
00178         else {
00179         }
00180     }
00181     //*/
00182 
00183     //---------------------------------------------------------------
00184     return isThePointInsideTheCylinder;
00185 }


Friends And Related Function Documentation

template<typename T>
std::ostream& operator<< ( std::ostream &  output,
BoundingCylinder< T > const &  obj 
) [friend]

Definition at line 38 of file TAPsBoundingCylinder.hpp.

00039     {
00040         output << obj.StrInfo();
00041         return output;
00042     }


Member Data Documentation

template<typename T>
T BoundingCylinder< T >::m_tHeight [protected]

Definition at line 165 of file TAPsBoundingCylinder.hpp.

template<typename T>
T BoundingCylinder< T >::m_tRadius [protected]

Definition at line 164 of file TAPsBoundingCylinder.hpp.


The documentation for this class was generated from the following files:

Generated on Mon Oct 13 11:44:23 2008 for TAPs by  doxygen 1.5.6