ScummVM API documentation
dgIntersections.h
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #ifndef __dgIntersections__
23 #define __dgIntersections__
24 
25 #include "dgStdafx.h"
26 #include "dgDebug.h"
27 #include "dgVector.h"
28 
29 
30 class dgPlane;
31 class dgObject;
32 class dgPolyhedra;
33 
34 DG_MSC_VECTOR_ALIGMENT
36 public:
37  dgFastRayTest(const dgVector &l0, const dgVector &l1);
38 
39  dgInt32 BoxTest(const dgVector &minBox, const dgVector &maxBox) const;
40  dgInt32 BoxTestSimd(const dgVector &minBox, const dgVector &maxBox) const;
41 
42  dgFloat32 PolygonIntersect(const dgVector &normal, const dgFloat32 *const polygon, dgInt32 strideInBytes, const dgInt32 *const indexArray, dgInt32 indexCount) const;
43  dgFloat32 PolygonIntersectSimd(const dgVector &normal, const dgFloat32 *const polygon, dgInt32 strideInBytes, const dgInt32 *const indexArray, dgInt32 indexCount) const;
44 
45  void Reset(dgFloat32 t) {
46  m_dpInv = m_dpBaseInv.Scale(dgFloat32(1.0f) / t);
47  }
48 
49  dgVector m_p0;
50  dgVector m_p1;
51  dgVector m_diff;
52  dgVector m_dpInv;
53  dgVector m_dpBaseInv;
54  dgVector m_minT;
55  dgVector m_maxT;
56 
57  dgVector m_ray_xxxx;
58  dgVector m_ray_yyyy;
59  dgVector m_ray_zzzz;
60  dgVector m_zero;
61  dgInt32 m_isParallel[4];
62 
63  dgFloat32 m_dirError;
64  dgFloat32 m_magRayTest;
65 } DG_GCC_VECTOR_ALIGMENT;
66 
67 
68 
69 enum dgIntersectStatus {
70  t_StopSearh,
71  t_ContinueSearh
72 };
73 
74 typedef dgIntersectStatus(*dgAABBIntersectCallback)(void *context,
75  const dgFloat32 *const polygon, dgInt32 strideInBytes,
76  const dgInt32 *const indexArray, dgInt32 indexCount);
77 
78 typedef dgFloat32(*dgRayIntersectCallback)(void *context,
79  const dgFloat32 *const polygon, dgInt32 strideInBytes,
80  const dgInt32 *const indexArray, dgInt32 indexCount);
81 
82 
84 public:
85  dgVector m_Origin;
86  dgVector m_NormalOut;
87  dgObject *m_HitObjectOut;
88  dgFloat32 m_ParametricIntersctionOut;
89 };
90 
91 
92 bool dgApi dgRayBoxClip(dgVector &ray_p0, dgVector &ray_p1, const dgVector &boxP0, const dgVector &boxP1);
93 
94 /*
95 dgFloat32 dgRayPolygonIntersect (const dgVector& ray_p0,
96  const dgVector& ray_p1,
97  const dgVector& normal,
98  const dgFloat32* const polygon,
99  dgInt32 strideInBytes,
100  const dgInt32* const indexArray,
101  dgInt32 indexCount);
102 
103 dgFloat32 dgRayPolygonIntersectSimd (const dgVector& ray_p0,
104  const dgVector& ray_p1,
105  const dgVector& normal,
106  const dgFloat32* const polygon,
107  dgInt32 strideInBytes,
108  const dgInt32* const indexArray,
109  dgInt32 indexCount);
110 
111 */
112 
113 dgVector dgApi dgPointToRayDistance(const dgVector &point, const dgVector &ray_p0, const dgVector &ray_p1);
114 
115 void dgApi dgRayToRayDistance(const dgVector &ray_p0,
116  const dgVector &ray_p1,
117  const dgVector &ray_q0,
118  const dgVector &ray_q1,
119  dgVector &p0Out,
120  dgVector &p1Out);
121 
122 dgVector dgPointToTriangleDistance(const dgVector &point, const dgVector &p0, const dgVector &p1, const dgVector &p2);
123 dgBigVector dgPointToTriangleDistance(const dgBigVector &point, const dgBigVector &p0, const dgBigVector &p1, const dgBigVector &p2);
124 
125 bool dgApi dgPointToPolygonDistance(const dgVector &point, const dgFloat32 *const polygon, dgInt32 strideInInBytes,
126  const dgInt32 *const indexArray, dgInt32 indexCount, dgFloat32 bailOutDistance, dgVector &pointOut);
127 
128 
129 /*
130 dgInt32 dgApi dgConvexPolyhedraToPlaneIntersection (
131  const dgPolyhedra& convexPolyhedra,
132  const dgFloat32 polyhedraVertexArray[],
133  int polyhedraVertexStrideInBytes,
134  const dgPlane& plane,
135  dgVector* intersectionOut,
136  dgInt32 maxSize);
137 
138 
139 dgInt32 dgApi ConvecxPolygonToConvexPolygonIntersection (
140  dgInt32 polygonIndexCount_1,
141  const dgInt32 polygonIndexArray_1[],
142  dgInt32 convexPolygonStrideInBytes_1,
143  const dgFloat32 convexPolygonVertex_1[],
144  dgInt32 polygonIndexCount_2,
145  const dgInt32 polygonIndexArray_2[],
146  dgInt32 convexPolygonStrideInBytes_2,
147  const dgFloat32 convexPolygonVertex_2[],
148  dgVector* intersectionOut,
149  dgInt32 maxSize);
150 
151 
152 dgInt32 dgApi dgConvexIntersection (const dgVector convexPolyA[], dgInt32 countA,
153  const dgVector convexPolyB[], dgInt32 countB,
154  dgVector output[]);
155 
156 */
157 
158 DG_INLINE dgInt32 dgOverlapTest(const dgVector &p0, const dgVector &p1, const dgVector &q0, const dgVector &q1) {
159  return ((p0.m_x < q1.m_x) && (p1.m_x > q0.m_x) && (p0.m_z < q1.m_z) && (p1.m_z > q0.m_z) && (p0.m_y < q1.m_y) && (p1.m_y > q0.m_y));
160 }
161 
162 DG_INLINE dgInt32 dgOverlapTestSimd(const dgVector &p0, const dgVector &p1, const dgVector &q0, const dgVector &q1) {
163 #ifdef DG_BUILD_SIMD_CODE
164  simd_type test = simd_and_v(simd_cmplt_v((simd_type &)p0, (simd_type &) q1), simd_cmpgt_v((simd_type &)p1, (simd_type &) q0));
165  dgInt32 ret = _mm_movemask_ps(test);
166  return ((ret & 0x07) == 0x07);
167 
168 #else
169  return 0;
170 #endif
171 }
172 
173 
174 dgBigVector LineTriangleIntersection(const dgBigVector &l0, const dgBigVector &l1, const dgBigVector &A, const dgBigVector &B, const dgBigVector &C);
175 
176 #endif
Definition: dgPlane.h:29
Definition: dgIntersections.h:35
Definition: dgIntersections.h:83
Definition: dgVector.h:86
Definition: dgPolyhedra.h:76
Definition: dgVector.h:104