GteIntrRay3AlignedBox3.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <Mathematics/GteRay.h>
12 
13 // The queries consider the box to be a solid.
14 //
15 // The test-intersection queries use the method of separating axes. The
16 // find-intersection queries use parametric clipping against the six faces of
17 // the box.
18 
19 namespace gte
20 {
21 
22 template <typename Real>
23 class TIQuery<Real, Ray3<Real>, AlignedBox3<Real>>
24  :
25  public TIQuery<Real, Line3<Real>, AlignedBox3<Real>>
26 {
27 public:
28  struct Result
29  :
30  public TIQuery<Real, Line3<Real>, AlignedBox3<Real>>::Result
31  {
32  // No additional information to compute.
33  };
34 
35  Result operator()(Ray3<Real> const& ray, AlignedBox3<Real> const& box);
36 
37 protected:
38  void DoQuery(Vector3<Real> const& rayOrigin,
39  Vector3<Real> const& rayDirection, Vector3<Real> const& boxExtent,
40  Result& result);
41 };
42 
43 template <typename Real>
44 class FIQuery<Real, Ray3<Real>, AlignedBox3<Real>>
45  :
46  public FIQuery<Real, Line3<Real>, AlignedBox3<Real>>
47 {
48 public:
49  struct Result
50  :
51  public FIQuery<Real, Line3<Real>, AlignedBox3<Real>>::Result
52  {
53  // No additional information to compute.
54  };
55 
56  Result operator()(Ray3<Real> const& ray, AlignedBox3<Real> const& box);
57 
58 protected:
59  void DoQuery(Vector3<Real> const& rayOrigin,
60  Vector3<Real> const& rayDirection, Vector3<Real> const& boxExtent,
61  Result& result);
62 };
63 
64 
65 template <typename Real>
68  Ray3<Real> const& ray, AlignedBox3<Real> const& box)
69 {
70  // Get the centered form of the aligned box. The axes are implicitly
71  // Axis[d] = Vector3<Real>::Unit(d).
72  Vector3<Real> boxCenter, boxExtent;
73  box.GetCenteredForm(boxCenter, boxExtent);
74 
75  // Transform the ray to the aligned-box coordinate system.
76  Vector3<Real> rayOrigin = ray.origin - boxCenter;
77 
78  Result result;
79  DoQuery(rayOrigin, ray.direction, boxExtent, result);
80  return result;
81 }
82 
83 template <typename Real>
85  Vector3<Real> const& rayOrigin, Vector3<Real> const& rayDirection,
86  Vector3<Real> const& boxExtent, Result& result)
87 {
88  for (int i = 0; i < 3; ++i)
89  {
90  if (std::abs(rayOrigin[i]) > boxExtent[i]
91  && rayOrigin[i] * rayDirection[i] >= (Real)0)
92  {
93  result.intersect = false;
94  return;
95  }
96  }
97 
98  TIQuery<Real, Line3<Real>, AlignedBox3<Real>>::DoQuery(rayOrigin,
99  rayDirection, boxExtent, result);
100 }
101 
102 template <typename Real>
105  Ray3<Real> const& ray, AlignedBox3<Real> const& box)
106 {
107  // Get the centered form of the aligned box. The axes are implicitly
108  // Axis[d] = Vector3<Real>::Unit(d).
109  Vector3<Real> boxCenter, boxExtent;
110  box.GetCenteredForm(boxCenter, boxExtent);
111 
112  // Transform the ray to the aligned-box coordinate system.
113  Vector3<Real> rayOrigin = ray.origin - boxCenter;
114 
115  Result result;
116  DoQuery(rayOrigin, ray.direction, boxExtent, result);
117  for (int i = 0; i < result.numPoints; ++i)
118  {
119  result.point[i] =
120  ray.origin + result.lineParameter[i] * ray.direction;
121  }
122  return result;
123 }
124 
125 template <typename Real>
127  Vector3<Real> const& rayOrigin, Vector3<Real> const& rayDirection,
128  Vector3<Real> const& boxExtent, Result& result)
129 {
130  FIQuery<Real, Line3<Real>, AlignedBox3<Real>>::DoQuery(rayOrigin,
131  rayDirection, boxExtent, result);
132 
133  if (result.intersect)
134  {
135  // The line containing the ray intersects the box; the t-interval is
136  // [t0,t1]. The ray intersects the box as long as [t0,t1] overlaps
137  // the ray t-interval (0,+infinity).
138  if (result.lineParameter[1] >= (Real)0)
139  {
140  if (result.lineParameter[0] < (Real)0)
141  {
142  result.lineParameter[0] = (Real)0;
143  }
144  }
145  else
146  {
147  result.intersect = false;
148  result.numPoints = 0;
149  }
150  }
151 }
152 
153 
154 }
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
Definition: GteBSNumber.h:966
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
GLuint64EXT * result
Definition: glext.h:10003


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00