VR-Forces 4.7 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
bvIntersector.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2004 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 /*******************************************************************************
6 ** $RCSfile: bvIntersector.h,v $ $Revision: 1.6 $ $State: Exp $
7 *******************************************************************************/
8 
9 #ifndef bvIntersector_H
10 #define bvIntersector_H
11 
12 class Dt3dBoundingVolume;
13 class DtDcm;
14 
17 #include <matrix/vlVector.h>
18 
19 // ------------------
20 // Fast how to use guide:
21 // ------------------
22 // Test a bounding volume for intersection with another object
23 // by passing the following parameters:
24 // Bounding volume of interest,
25 // Position and orientation of the BV,
26 // Other object with which you wish to test intersection,
27 // Position and orientation of the other object.
28 //
29 // Note:
30 // The positions and orientations can be in ANY coordinate system,
31 // provided:
32 // 1. they are ALL defined in the SAME CS.
33 // 2. the coordinate system has the same scale as the dimensions.
34 // (we typically use meters for everything, so you shouldn't
35 // have to worry about this ever)
36 // 3. it is a Cartesian coordinate system (not polar, cylindrical etc.)
37 //
38 //
39 // ------------------
40 // High level concepts:
41 // ------------------
42 //
43 // Please read the bounding volume header. I don't want to replicate
44 // information here, since the chances of it getting out of date are too
45 // high.
46 //
47 // A bounding volume (BV) is like a box, with a length, width and height.
48 // It is centered at an origin. The origin may be offset from a position.
49 //
50 // So, the conceptual pieces of any bounding volume in any coordinate system are:
51 // 1. dimensions of the "box"
52 // 2. position of the box
53 // 3. offset of the origin from the position, may be zero.
54 // 4. orientation of the box, relative to the coordinate system
55 //
56 // There are three coordinate systems (CSs) involved:
57 // 1. The lattice coordinate system in which the first BV is defined.
58 // 2. The lattice coordinate system in which the second object is defined.
59 // 3. The reference, or common coordinate system. This the is CS
60 // in which both objects can be concurrently situated.
61 // Often it is the CS of the terrain database.
62 // The position and orientation we specify are in this common,
63 // reference CS.
64 //
65 // We also need a way of "moving" from one coordinate system to the other.
66 // This is called a transformation. The scales are the same in all of our
67 // coordinate systems. Hence, compared to an arbitrary CS transformation,
68 // we can optimize our transformation and use just a translation and a
69 // rotation (orientation).
70 //
71 //
72 // *** ***
73 // * Some might find this conceptually hard, but it is key to *
74 // * to understanding: *
75 // * The transformation from lattice to reference coordinate systems *
76 // * is the same as the transformation from the origin in reference *
77 // * coordinates to the orientation in reference coordinates. *
78 // * i.e. you can use the same transformation to either switch between *
79 // * two different coordinate systems, or to switch between two *
80 // * locations in the same coordinate system. *
81 // *** ***
82 //
83 //
84 // So, the conceptual pieces of a bounding volume, and the coordinate
85 // system in which they are specified are:
86 // - (latticeCS) dimensions of the "box"
87 // - (latticeCS) position of the box (always zero)
88 // - (latticeCS) offset of the origin from the local position, may be zero.
89 // - (latticeCS) origin (local position + local offset)
90 // - (latticeCS) orientation of the box (always the same as the latticeCS)
91 //
92 // - (refCS) dimensions of the "box" (always same as lattice dimensions)
93 // - (refCS) position (often of an associated entity)
94 // - (refCS) offset of the origin from the reference position, may be zero.
95 // - (refCS) origin (reference position + reference offset)
96 // - (refCS) orientation of the box
97 //
98 // - transformation from the latticeCS to the refCS
99 // - translation (same as refCS position)
100 // - rotation (same as refCS orientation)
101 // - scale (always 1 since we have defined it that way)
102 // - skew (never skewed since we have defined it that way)
103 //
104 //
105 
107 {
108 
109 public: // constructors, operators etc.
110 
111  DtBvIntersector();
112  DtBvIntersector( const DtBvIntersector & orig );
113 
114  virtual ~DtBvIntersector();
115 
116  DtBvIntersector& operator=( const DtBvIntersector & orig );
117 
118 
119 public:
121  // Intersection tests
122  //
123  // Test if a bounding volume would intersect with another object
124  // were they at the given positions and orientations which are
125  // all specified in the common reference coordinate system.
126 
127  // Bounding volume & bounding volume intersection.
128  virtual bool intersectsBoundingVolume(
129  const Dt3dBoundingVolume & bv,
130  const DtVector& bvPosition, const DtDcm& bvOrientation,
131  const Dt3dBoundingVolume & secondBV,
132  const DtVector& secondBVPosition, const DtDcm& secondBVOrientation ) const;
133 
134  // Bounding volume & point intersection.
135  virtual bool intersectsPoint(
136  const Dt3dBoundingVolume& bv,
137  const DtVector& bvPosition, const DtDcm& bvOrientation,
138  const DtVector& pointPosition ) const;
139 
140  // Bounding volume & chord intersection.
141  //
142  // If there was an intersection, distInChordLengthsFirst and
143  // distInChordLengthslast give the distance along the chord in chord
144  // lengths to the first and last encounters with the bounding volume along
145  // the line. If the chord represents velocity, these are the enter and
146  // exit times. The faces of the first and last encounters are faceFirst
147  // and faceLast.
148  virtual bool intersectsLineOfChord(
149  const Dt3dBoundingVolume & bv,
150  const DtVector& bvPosition, const DtDcm& bvOrientation,
151  const DtVector& point1, const DtVector& point2,
152  double& distInChordLengthsFirst, double& distInChordLengthsLast,
153  DtBoundingVolumeFace& faceFirst, DtBoundingVolumeFace& faceLast ) const;
154 
155  // Bounding volume & chord intersection.
156  //
157  // The following method performs the same as the above, plus returns the
158  // points of the first and last encounters with the bounding volume along
159  // the line (pointFirst and pointLast).
160  virtual bool intersectsLineOfChord(
161  const Dt3dBoundingVolume & bv,
162  const DtVector& bvPosition, const DtDcm& bvOrientation,
163  const DtVector& point1, const DtVector& point2,
164  double& distInChordLengthsFirst, double& distInChordLengthsLast,
165  DtBoundingVolumeFace& faceFirst, DtBoundingVolumeFace& faceLast,
166  DtVector& pointFirst, DtVector& pointLast ) const;
167 
168  // The following method returns the incidence angle between a
169  // vector and a face of a bounding volume. The orientation of the
170  // BV is passed to the routine along with a ray.
171  // The returned angle is always positive and in radians.
172  virtual double incidenceAngle(const Dt3dBoundingVolume & bv,
173  const DtDcm & bvOrientation,
174  const DtVector& rayWorld,
175  DtBoundingVolumeFace& face) const;
176 
177 protected:
178  // If the bounding spheres don't intersect, there is no way the bounding
179  // volumes can intersect.
180  // However, the converse is not true, i.e. false positives are possible
181  // with this test. Use as a fast first test.
182  virtual bool intersectsMaxBoundingSphere(const Dt3dBoundingVolume & bv,
183  const DtVector & bvPosition,
184  const Dt3dBoundingVolume& secondBV,
185  const DtVector & secondBVPosition) const;
186 
187 public:
188  // Updates world bounding volume based on lattice BV and reference orientation.
189  virtual DtDcm calcRefBV(const Dt3dBoundingVolume & bv,
190  const DtVector & bvPosition,
191  const DtDcm& latticeToRef ) const;
192 
193  // Updates origin based on oriented BV and offset.
194  virtual DtVector calcRefOrigin(const Dt3dBoundingVolume & bv,
195  const DtVector & bvPosition,
196  const DtDcm& latticeToRef ) const;
197 
198 protected:
199  // The following method takes a column vector from a bounding
200  // volume matrix (columnVector), two faces perpendicular to this
201  // column vector (facePos and faceNeg), a vector giving the center
202  // of a bounding volume (point1ToBVCenter), and a ray (ray) and
203  // uses them to refine intersection parameters passed
204  // to it. These intersection parameters are the distance of
205  // first encounter (distFirst), distance of last encounter
206  // (distLast), face of first encounter (faceFirst), and face of
207  // last encounter (faceLast). The routine returns false if
208  // there is no chance of further intersection, otherwise it
209  // returns true.
210  virtual bool refineSegmentIntersection(
211  const DtVector& columnVector, const DtVector& point1ToBVCenter,
212  const DtVector& ray, double& distFirst, double& distLast,
213  DtBoundingVolumeFace& faceFirst, DtBoundingVolumeFace& faceLast,
214  const DtBoundingVolumeFace facePos, const DtBoundingVolumeFace faceNeg) const;
215 
216 protected:
217  // No member data.
218  // Member data may be added later to hold temporary values as
219  // an optimization step.
220 
221 };
222 
223 
224 #endif
225 

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)