VR-Forces 4.0.4 Class Documentation
include/geometry/bvIntersector.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002 ** Copyright (c) 2004 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 *******************************************************************************/
00005 /*******************************************************************************
00006 ** $RCSfile: bvIntersector.h,v $ $Revision: 1.6 $ $State: Exp $
00007 *******************************************************************************/
00008 
00009 #ifndef bvIntersector_H
00010 #define bvIntersector_H
00011 
00012 class Dt3dBoundingVolume;
00013 class DtVector;
00014 class DtDcm;
00015 
00016 #include "geometry/geometryDefines.h"
00017 #include "geometry/boundingVolumeFace.h"
00018 
00019 // ------------------
00020 // Fast how to use guide:
00021 // ------------------
00022 //    Test a bounding volume for intersection with another object 
00023 //    by passing the following parameters:
00024 //          Bounding volume of interest,
00025 //          Position and orientation of the BV, 
00026 //          Other object with which you wish to test intersection, 
00027 //          Position and orientation of the other object.
00028 //
00029 //    Note:
00030 //    The positions and orientations can be in ANY coordinate system,
00031 //    provided:
00032 //          1. they are ALL defined in the SAME CS.
00033 //          2. the coordinate system has the same scale as the dimensions.
00034 //             (we typically use meters for everything, so you shouldn't
00035 //             have to worry about this ever)
00036 //          3. it is a Cartesian coordinate system (not polar, cylindrical etc.)
00037 //
00038 //
00039 // ------------------
00040 // High level concepts:
00041 // ------------------
00042 //
00043 // Please read the bounding volume header.  I don't want to replicate
00044 // information here, since the chances of it getting out of date are too
00045 // high.
00046 //
00047 // A bounding volume (BV) is like a box, with a length, width and height.
00048 // It is centered at an origin.  The origin may be offset from a position.
00049 //
00050 // So, the conceptual pieces of any bounding volume in any coordinate system are:
00051 //    1. dimensions of the "box" 
00052 //    2. position of the box
00053 //    3. offset of the origin from the position, may be zero. 
00054 //    4. orientation of the box, relative to the coordinate system
00055 //
00056 // There are three coordinate systems (CSs) involved:
00057 //    1. The lattice coordinate system in which the first BV is defined.
00058 //    2. The lattice coordinate system in which the second object is defined.
00059 //    3. The reference, or common coordinate system.  This the is CS
00060 //       in which both objects can be concurrently situated.  
00061 //       Often it is the CS of the terrain database. 
00062 //       The position and orientation we specify are in this common,
00063 //       reference CS.
00064 //
00065 // We also need a way of "moving" from one coordinate system to the other.
00066 // This is called a transformation.  The scales are the same in all of our
00067 // coordinate systems.  Hence, compared to an arbitrary CS transformation,
00068 // we can optimize our transformation and use just a translation and a 
00069 // rotation (orientation).
00070 //
00071 //
00072 //  ***                                                                  *** 
00073 //  *   Some might find this conceptually hard, but it is key to           *
00074 //  *   to understanding:                                                  *
00075 //  *   The transformation from lattice to reference coordinate systems    *
00076 //  *   is the same as the transformation from the origin in reference     *
00077 //  *   coordinates to the orientation in reference coordinates.           * 
00078 //  *   i.e. you can use the same transformation to either switch between  *
00079 //  *   two different coordinate systems, or to switch between two         *
00080 //  *   locations in the same coordinate system.                           *
00081 //  ***                                                                  *** 
00082 //  
00083 //
00084 // So, the conceptual pieces of a bounding volume, and the coordinate
00085 // system in which they are specified are:
00086 //    - (latticeCS) dimensions of the "box" 
00087 //    - (latticeCS) position of the box (always zero)
00088 //    - (latticeCS) offset of the origin from the local position, may be zero. 
00089 //    - (latticeCS) origin (local position + local offset)
00090 //    - (latticeCS) orientation of the box (always the same as the latticeCS)
00091 //
00092 //    - (refCS) dimensions of the "box" (always same as lattice dimensions)
00093 //    - (refCS) position (often of an associated entity) 
00094 //    - (refCS) offset of the origin from the reference position, may be zero. 
00095 //    - (refCS) origin (reference position + reference offset)
00096 //    - (refCS) orientation of the box 
00097 //
00098 //    - transformation from the latticeCS to the refCS
00099 //       - translation (same as refCS position)
00100 //       - rotation    (same as refCS orientation)
00101 //       - scale       (always 1 since we have defined it that way)
00102 //       - skew        (never skewed since we have defined it that way)
00103 //
00104 //
00105 
00106 class DT_DLL_geometry DtBVIntersector
00107 {
00108 
00109 public: // constructors, operators etc.
00110 
00111    DtBVIntersector();
00112    DtBVIntersector( const DtBVIntersector & orig );
00113 
00114    virtual ~DtBVIntersector();
00115 
00116    DtBVIntersector& operator=( const DtBVIntersector & orig );
00117 
00118 
00119 public:
00121    // Intersection tests
00122    //
00123    // Test if a bounding volume would intersect with another object
00124    // were they at the given positions and orientations which are
00125    // all specified in the common reference coordinate system.
00126 
00127    // Bounding volume & bounding volume intersection.
00128    virtual bool intersectsBoundingVolume(
00129       const Dt3dBoundingVolume & bv,
00130       const DtVector& bvPosition, const DtDcm& bvOrientation,
00131       const Dt3dBoundingVolume & secondBV,
00132       const DtVector& secondBVPosition, const DtDcm& secondBVOrientation ) const;
00133 
00134    // Bounding volume & point intersection.
00135    virtual bool intersectsPoint(
00136       const Dt3dBoundingVolume& bv,
00137       const DtVector& bvPosition, const DtDcm& bvOrientation,
00138       const DtVector& pointPosition ) const;
00139 
00140    // Bounding volume & chord intersection.
00141    //
00142    // If there was an intersection, distInChordLengthsFirst and
00143    // distInChordLengthslast give the distance along the chord in chord
00144    // lengths to the first and last encounters with the bounding volume along
00145    // the line.  If the chord represents velocity, these are the enter and
00146    // exit times.  The faces of the first and last encounters are faceFirst
00147    // and faceLast.
00148    virtual bool intersectsLineOfChord(
00149       const Dt3dBoundingVolume & bv,
00150       const DtVector& bvPosition, const DtDcm& bvOrientation,
00151       const DtVector& point1, const DtVector& point2,
00152       double& distInChordLengthsFirst, double& distInChordLengthsLast,
00153       DtBoundingVolumeFace& faceFirst, DtBoundingVolumeFace& faceLast ) const;
00154 
00155    // Bounding volume & chord intersection.
00156    //
00157    // The following method performs the same as the above, plus returns the
00158    // points of the first and last encounters with the bounding volume along
00159    // the line (pointFirst and pointLast).
00160    virtual bool intersectsLineOfChord(
00161       const Dt3dBoundingVolume & bv,
00162       const DtVector& bvPosition, const DtDcm& bvOrientation,
00163       const DtVector& point1, const DtVector& point2,
00164       double& distInChordLengthsFirst, double& distInChordLengthsLast,
00165       DtBoundingVolumeFace& faceFirst, DtBoundingVolumeFace& faceLast,
00166       DtVector& pointFirst, DtVector& pointLast ) const;
00167 
00168    // The following method returns the incidence angle between a
00169    // vector and a face of a bounding volume.  The orientation of the
00170    // BV is passed to the routine along with a ray. 
00171    // The returned angle is always positive and in radians.
00172    virtual double incidenceAngle(const Dt3dBoundingVolume & bv,
00173       const DtDcm & bvOrientation,
00174       const DtVector& rayWorld, 
00175       DtBoundingVolumeFace& face) const;
00176 
00177 protected:
00178    // If the bounding spheres don't intersect, there is no way the bounding 
00179    // volumes can intersect.
00180    // However, the converse is not true, i.e. false positives are possible
00181    // with this test.  Use as a fast first test.
00182    virtual bool intersectsMaxBoundingSphere(const Dt3dBoundingVolume & bv,
00183       const DtVector & bvPosition,
00184       const Dt3dBoundingVolume& secondBV,
00185       const DtVector & secondBVPosition) const;
00186 
00187 public:
00188    // Updates world bounding volume based on lattice BV and reference orientation.
00189    virtual DtDcm calcRefBV(const Dt3dBoundingVolume & bv,
00190                             const DtVector & bvPosition,
00191                             const DtDcm& latticeToRef ) const;
00192 
00193    // Updates origin based on oriented BV and offset.
00194    virtual DtVector calcRefOrigin(const Dt3dBoundingVolume & bv,
00195                                    const DtVector & bvPosition,
00196                                    const DtDcm& latticeToRef ) const;
00197 
00198 protected:
00199    // The following method takes a column vector from a bounding
00200    // volume matrix (columnVector), two faces perpendicular to this
00201    // column vector (facePos and faceNeg), a vector giving the center
00202    // of a bounding volume (point1ToBVCenter), and a ray (ray) and
00203    // uses them to refine intersection parameters passed
00204    // to it.  These intersection parameters are the distance of
00205    // first encounter (distFirst), distance of last encounter
00206    // (distLast), face of first encounter (faceFirst), and face of
00207    // last encounter (faceLast).  The routine returns false if
00208    // there is no chance of further intersection, otherwise it
00209    // returns true.
00210    virtual bool refineSegmentIntersection(
00211       const DtVector& columnVector, const DtVector& point1ToBVCenter,
00212       const DtVector& ray, double& distFirst, double& distLast,
00213       DtBoundingVolumeFace& faceFirst, DtBoundingVolumeFace& faceLast,
00214       const DtBoundingVolumeFace facePos, const DtBoundingVolumeFace faceNeg) const;
00215 
00216 protected:
00217    // No member data.  
00218    // Member data may be added later to hold temporary values as
00219    // an optimization step.
00220    
00221 };
00222 
00223 
00224 #endif
00225 

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)