GteBoundingSphere.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 
11 #include <Graphics/GteTransform.h>
12 
13 namespace gte
14 {
15 
17 {
18 public:
19  // Construction and destruction. The default constructor sets the center
20  // to the origin (0,0,0,1) and the radius to 0. A radius of 0 denotes an
21  // invalid bound.
22  ~BoundingSphere();
24  BoundingSphere(BoundingSphere const& sphere);
25 
26  // Assignment.
27  BoundingSphere& operator= (BoundingSphere const& sphere);
28 
29  // Member access. The radius must be nonnegative. When negative, it is
30  // clamped to zero.
31  inline void SetCenter(Vector4<float> const& center);
32  inline void SetRadius(float radius);
33  inline Vector4<float> GetCenter() const;
34  inline float GetRadius() const;
35 
36  // The "positive side" of the plane is the half space to which the
37  // plane normal is directed. The "negative side" is the other half
38  // space. The function returns +1 when the sphere is fully on the
39  // positive side, -1 when the sphere is fully on the negative side, or
40  // 0 when the sphere is transversely cut by the plane (sphere volume on
41  // each side of plane is positive).
42  int WhichSide(CullingPlane const& plane) const;
43 
44  // Increase 'this' to contain the input sphere.
45  void GrowToContain(BoundingSphere const& sphere);
46 
47  // Transform the sphere. If the transform has nonuniform scaling, the
48  // resulting object is an ellipsoid. A sphere is generated to contain
49  // the ellipsoid.
50  void TransformBy(Transform const& transform,
51  BoundingSphere& sphere) const;
52 
53  // This function is valid only for 3-channel points (x,y,z) or 4-channel
54  // vectors (x,y,z,0) or 4-channel points (x,y,z,1). In all cases, the
55  // function accesses only the (x,y,z) values. The stride allows you to
56  // pass in vertex buffer data. Set the stride to zero when the points are
57  // contiguous in memory. The 'data' pointer must be to the first point
58  // (offset 0).
59  void ComputeFromData(int numVertices, int vertexSize, char const* data);
60 
61  // Test for intersection of linear component and bound (points of
62  // intersection not computed). The linear component is parameterized by
63  // P + t*D, where P is a point on the component (the origin) and D is a
64  // unit-length direction vector. The interval [tmin,tmax] is
65  // line: tmin = -INFINITY, tmax = INFINITY
66  // ray: tmin = 0.0f, tmax = INFINITY
67  // segment: tmin >= 0.0f, tmax > tmin
68  // where INFINITY is std::numeric_limits<float>::max().
69  bool TestIntersection(Vector4<float> const& origin,
70  Vector4<float> const& direction, float tmin, float tmax) const;
71 
72  // Test for intersection of the two stationary spheres.
73  bool TestIntersection(BoundingSphere const& sphere) const;
74 
75  // Test for intersection of the two moving spheres. The velocity0 is
76  // for 'this' and the velocity1 is the for the input bound.
77  bool TestIntersection(BoundingSphere const& sphere, float tmax,
78  Vector4<float> const& velocity0, Vector4<float> const& velocity1)
79  const;
80 
81 private:
82  // (center, radius) = (c0, c1, c2, r)
84 };
85 
86 
87 inline void BoundingSphere::SetCenter(Vector4<float> const& center)
88 {
89  mTuple[0] = center[0];
90  mTuple[1] = center[1];
91  mTuple[2] = center[2];
92 }
93 
94 inline void BoundingSphere::SetRadius(float radius)
95 {
96  mTuple[3] = (radius >= 0.0f ? radius : 0.0f);
97 }
98 
100 {
101  return Vector4<float>{ mTuple[0], mTuple[1], mTuple[2], 1.0f };
102 }
103 
104 inline float BoundingSphere::GetRadius() const
105 {
106  return mTuple[3];
107 }
108 
109 
110 }
float GetRadius() const
void SetRadius(float radius)
GLboolean * data
Definition: glcorearb.h:126
Vector4< float > GetCenter() const
GLuint GLenum GLenum transform
Definition: glext.h:10574
Vector4< float > mTuple
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63
void SetCenter(Vector4< float > const &center)


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59