HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BV_Overlap.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  */
7 
8 #ifndef __BV_Overlap_h__
9 #define __BV_Overlap_h__
10 
11 #include "BV_API.h"
12 #include <SYS/SYS_Types.h>
13 #include <UT/UT_Vector3.h>
14 #include <UT/UT_VectorTypes.h>
15 
17 public:
18  void computeNormal();
19  void transform(const UT_Matrix3 &R, const UT_Vector3 &T);
20 
21  UT_Vector3 myP[3], myNormal;
22 };
23 
24 class BV_API bvQuad {
25 public:
26  /// Returns two non-overlapping triangles from the vertices of this
27  /// (coplanar) quadrilateral. Returns false if this is a skew quadrilateral
28  /// The degenerate case will have ta as the correct triangle
29  bool dissect(bvTriangle &ta,
30  bvTriangle &tb,
31  bool &degen) const;
32  /// Returns true if the quadrilateral is coplanar
33  bool isCoplanar() const;
34  UT_Vector3 myP[4];
35 };
36 
37 
38 /// A class for determining if geometry objects overlap
40 {
41 public:
42  // Code for doTriBoxOverlap and doTriTriOverlap is modified from
43  // OPCODE 1.3 - Optimized Collision Detection Engine.
44  // doTriTriOverlap is based on Tomas Moller's "A fast triangle-triangle
45  // intersection test", Journal of graphic tools 2(2):25-30, 1997
46  // OPCODE license (actually there is no license) permit the
47  // usage of its code in any commercial program.
48  // See http://www.codercorner.com/Opcode.htm
49 
50  /// Returns true if two coplanar triangles overlap.
51  static bool doCoplanarTriTriOverlap(const bvTriangle &tri1,
52  const bvTriangle &tri2,
53  fpreal tol = 0.0f);
54 
55  /// Returns true if two triangles overlap
56  static bool doTriTriOverlap(const bvTriangle &tri1,
57  const bvTriangle &tri2,
58  fpreal tol=0.0f);
59 
60  /// Returns the intersection points when two triangles overlap
61  static bool doTriTriOverlap(const bvTriangle &tri1,
62  const bvTriangle &tri2,
63  bool &coplanar,
64  UT_Vector3 &isectpt1,
65  UT_Vector3 &isectpt2,
66  fpreal tol=0.0f);
67 
68  /// Returns true if two coplanar quadrilaterals overlap
69  static bool doCoplanarQuadQuadOverlap(const bvQuad &q1,
70  const bvQuad &q2,
71  fpreal tol=0.0f);
72 
73  /// Returns true if a plane and a box overlap
74  static bool doPlaneBoxOverlap(const UT_Vector3& normal,
75  const fpreal d,
76  const UT_Vector3& maxbox,
77  fpreal tol = 0.0f);
78 
79  /// Uses the Seperating Axis Theorem (SAT) to test for triangle/box
80  /// intersection. The lite version avoids edge tests, but may generate
81  /// false positives.
82  static bool doTriBoxOverlap(const bvTriangle &tri,
83  const UT_Vector3 &ra,
84  const UT_Matrix3 &R,
85  const UT_Vector3 &T,
86  // fpreal tol=0.f,
87  bool lite=false);
88 
89  /// This checks for overlaps for two static OBBs. This method is based on
90  /// the Seperating Axis Theorem (SAT). The lite version of this,
91  /// algorithm, dubbed SAT-lite, satistically has only about 15% chance
92  /// of reporting disjoint bounding boxes as intersecting.
93  /// However, this may improve runtime in some situations since this
94  /// is 2.5 times faster than the original SAT, by only checking
95  /// the face-face axis (and ignoring the edges). This may generate
96  /// false positives however.
97  static bool doBoxBoxOverlap(const UT_Vector3 &ra,
98  const UT_Vector3 &rb,
99  const UT_Matrix3 &R,
100  const UT_Vector3 &T,
101  fpreal tol=0.f,
102  bool lite=false);
103  /// Given an AABB (with radii ra -- half of dimension) and center at origin
104  /// calculate an AABB (parallel to the original AABB) that contains the
105  /// original AABB and an OBB by applying xform to the original AABB.
106  static void calcAABB(const UT_Vector3 &ra,
107  const UT_DMatrix4 &xform,
108  UT_Vector3 &rnew,
109  UT_Vector3 &Tnew);
110  static void calcAABB(const UT_Vector3 &ra,
111  const UT_DMatrix4 &xform,
112  const UT_Matrix3 &R,
113  const UT_Vector3 &T,
114  UT_Vector3 &rnew,
115  UT_Vector3 &Tnew);
116 
117  /// Given two OBBs (second determined by a relative transform R & T),
118  /// checks for overlaps between the OBBs with each
119  /// containing one original OBB and the OBB after applying xform.
120  static bool doBoxBoxOverlap(const UT_Vector3 &ra,
121  const UT_Vector3 &rb,
122  const UT_DMatrix4 &xform1,
123  const UT_DMatrix4 &xform2,
124  const UT_Matrix3 &R,
125  const UT_Vector3 &T,
126  fpreal tol,
127  bool lite = false,
128  bool useOBB = true);
129 
130 private:
131  static bool doCoplanarTriTriOverlap(const UT_Vector3& n,
132  const UT_Vector3& v0,
133  const UT_Vector3& v1,
134  const UT_Vector3& v2,
135  const UT_Vector3& u0,
136  const UT_Vector3& u1,
137  const UT_Vector3& u2);
138 
139 };
140 
141 #endif
142 
143 
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
GLdouble u1
Definition: glad.h:2676
A class for determining if geometry objects overlap.
Definition: BV_Overlap.h:39
GLdouble n
Definition: glcorearb.h:2008
GLfloat f
Definition: glcorearb.h:1926
GLdouble GLdouble u2
Definition: glad.h:2676
GA_API const UT_StringHolder transform
GLfloat v0
Definition: glcorearb.h:816
#define BV_API
Definition: BV_API.h:10
fpreal64 fpreal
Definition: SYS_Types.h:277
GLfloat GLfloat v1
Definition: glcorearb.h:817