GteBspNode.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 <Graphics/GteNode.h>
12 
13 // Binary Separating Plane (BSP) nodes. The "positive" side of a plane is the
14 // half-space to which the plane normal points. The "negative" side of a
15 // a plane is the complementary half-space.
16 
17 namespace gte
18 {
19 
20 class GTE_IMPEXP BspNode : public Node
21 {
22 public:
23  // Construction. The base class Node has three children and is not
24  // allowed to grow. The first and last children (indices 0 and 2) are the
25  // positive and negative children of the binary tree. The positive child
26  // corresponds to the positive side of the separating plane. The negative
27  // child corresponds to the negative side of the separating plane. The
28  // middle child slot is where additional geometry may be attached such as
29  // the triangles that are coplanar with the separating plane.
30  BspNode();
31  BspNode(Plane3<float> const& modelPlane);
32 
33  // These methods should be used instead of the attach/detach methods in
34  // the Node base class.
35  inline std::shared_ptr<Spatial> AttachPositiveChild(
36  std::shared_ptr<Spatial> const& child);
37 
38  inline std::shared_ptr<Spatial> AttachCoplanarChild(
39  std::shared_ptr<Spatial> const& child);
40 
41  inline std::shared_ptr<Spatial> AttachNegativeChild(
42  std::shared_ptr<Spatial> const& child);
43 
44  inline std::shared_ptr<Spatial> DetachPositiveChild();
45  inline std::shared_ptr<Spatial> DetachCoplanarChild();
46  inline std::shared_ptr<Spatial> DetachNegativeChild();
47  inline std::shared_ptr<Spatial> GetPositiveChild();
48  inline std::shared_ptr<Spatial> GetCoplanarChild();
49  inline std::shared_ptr<Spatial> GetNegativeChild();
50 
51  // Member access.
52  void SetModelPlane(Plane3<float> const& plane);
53  Plane3<float> GetModelPlane() const;
54  Plane3<float> GetWorldPlane() const;
55 
56  // Determine the portion of the scene that contains the point.
57  Spatial* GetContainingNode(Vector4<float> const& point);
58 
59 protected:
60  // Support for conversions from planes to 4-tuples.
61  void NormalizePlane(Vector4<float>& plane);
62  void SetWorldPlane(Plane3<float> const& plane);
63 
64  // Support for the geometric update.
65  virtual void UpdateWorldData(double applicationTime);
66 
67  // Support for hierarchical culling.
68  virtual void GetVisibleSet(Culler& culler,
69  std::shared_ptr<Camera> const& camera, bool noCull);
70 
71  // Determine whether the point is fully on one side of the world plane.
72  // The function returns +1 if the point is on the positive side of the
73  // plane, -1 if the point is on the negative side of the plane, or 0 if
74  // the point is on the plane.
75  int WhichSide(Vector4<float> const& point) const;
76 
77  // Determine whether the view frustum is fully on one side of the world
78  // plane. The function returns +1 if the view frustum is fully on the
79  // positive side of the plane, -1 if the view frustum is fully on the
80  // negative side of the plane, or 0 if the view frustum straddles the
81  // plane. The world camera coordinate system is used for the test.
82  int WhichSide(std::shared_ptr<Camera> const& camera) const;
83 
85 };
86 
87 
88 inline std::shared_ptr<Spatial> BspNode::AttachPositiveChild(
89  std::shared_ptr<Spatial> const& child)
90 {
91  return SetChild(0, child);
92 }
93 
94 inline std::shared_ptr<Spatial> BspNode::AttachCoplanarChild(
95  std::shared_ptr<Spatial> const& child)
96 {
97  return SetChild(1, child);
98 }
99 
100 inline std::shared_ptr<Spatial> BspNode::AttachNegativeChild(
101  std::shared_ptr<Spatial> const& child)
102 {
103  return SetChild(2, child);
104 }
105 
106 inline std::shared_ptr<Spatial> BspNode::DetachPositiveChild()
107 {
108  return DetachChildAt(0);
109 }
110 
111 inline std::shared_ptr<Spatial> BspNode::DetachCoplanarChild()
112 {
113  return DetachChildAt(1);
114 }
115 
116 inline std::shared_ptr<Spatial> BspNode::DetachNegativeChild()
117 {
118  return DetachChildAt(2);
119 }
120 
121 inline std::shared_ptr<Spatial> BspNode::GetPositiveChild()
122 {
123  return GetChild(0);
124 }
125 
126 inline std::shared_ptr<Spatial> BspNode::GetCoplanarChild()
127 {
128  return GetChild(1);
129 }
130 
131 inline std::shared_ptr<Spatial> BspNode::GetNegativeChild()
132 {
133  return GetChild(2);
134 }
135 
136 
137 }
std::shared_ptr< Spatial > GetNegativeChild()
Definition: GteBspNode.h:131
std::shared_ptr< Spatial > DetachNegativeChild()
Definition: GteBspNode.h:116
std::shared_ptr< Spatial > GetCoplanarChild()
Definition: GteBspNode.h:126
std::shared_ptr< Spatial > DetachPositiveChild()
Definition: GteBspNode.h:106
std::shared_ptr< Spatial > AttachNegativeChild(std::shared_ptr< Spatial > const &child)
Definition: GteBspNode.h:100
std::shared_ptr< Spatial > GetPositiveChild()
Definition: GteBspNode.h:121
std::shared_ptr< Spatial > AttachCoplanarChild(std::shared_ptr< Spatial > const &child)
Definition: GteBspNode.h:94
std::shared_ptr< Spatial > AttachPositiveChild(std::shared_ptr< Spatial > const &child)
Definition: GteBspNode.h:88
std::shared_ptr< Spatial > DetachCoplanarChild()
Definition: GteBspNode.h:111
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63
Vector4< float > mWorldPlane
Definition: GteBspNode.h:84


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