00001 // Filename: cullTraverserData.I 00002 // Created by: drose (06Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 //////////////////////////////////////////////////////////////////// 00016 // Function: CullTraverserData::Constructor 00017 // Access: Public 00018 // Description: 00019 //////////////////////////////////////////////////////////////////// 00020 INLINE CullTraverserData:: 00021 CullTraverserData(const NodePath &start, 00022 const TransformState *net_transform, 00023 const RenderState *state, 00024 GeometricBoundingVolume *view_frustum, 00025 Thread *current_thread) : 00026 _node_path(start), 00027 _node_reader(start.node(), current_thread), 00028 _net_transform(net_transform), 00029 _state(state), 00030 _view_frustum(view_frustum), 00031 _cull_planes(CullPlanes::make_empty()), 00032 _draw_mask(DrawMask::all_on()) 00033 { 00034 _node_reader.check_bounds(); 00035 _portal_depth = 0; 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: CullTraverserData::Copy Constructor 00040 // Access: Public 00041 // Description: 00042 //////////////////////////////////////////////////////////////////// 00043 INLINE CullTraverserData:: 00044 CullTraverserData(const CullTraverserData ©) : 00045 _node_path(copy._node_path), 00046 _node_reader(copy._node_reader), 00047 _net_transform(copy._net_transform), 00048 _state(copy._state), 00049 _view_frustum(copy._view_frustum), 00050 _cull_planes(copy._cull_planes), 00051 _draw_mask(copy._draw_mask), 00052 _portal_depth(copy._portal_depth) 00053 { 00054 } 00055 00056 //////////////////////////////////////////////////////////////////// 00057 // Function: CullTraverserData::Copy Assignment Operator 00058 // Access: Public 00059 // Description: 00060 //////////////////////////////////////////////////////////////////// 00061 INLINE void CullTraverserData:: 00062 operator = (const CullTraverserData ©) { 00063 _node_path = copy._node_path; 00064 _node_reader = copy._node_reader; 00065 _net_transform = copy._net_transform; 00066 _state = copy._state; 00067 _view_frustum = copy._view_frustum; 00068 _cull_planes = copy._cull_planes; 00069 _draw_mask = copy._draw_mask; 00070 _portal_depth = copy._portal_depth; 00071 } 00072 00073 //////////////////////////////////////////////////////////////////// 00074 // Function: CullTraverserData::Constructor 00075 // Access: Public 00076 // Description: This constructor creates a CullTraverserData object 00077 // that reflects the next node down in the traversal. 00078 //////////////////////////////////////////////////////////////////// 00079 INLINE CullTraverserData:: 00080 CullTraverserData(const CullTraverserData &parent, PandaNode *child) : 00081 _node_path(parent._node_path, child), 00082 _node_reader(child, parent._node_reader.get_current_thread()), 00083 _net_transform(parent._net_transform), 00084 _state(parent._state), 00085 _view_frustum(parent._view_frustum), 00086 _cull_planes(parent._cull_planes), 00087 _draw_mask(parent._draw_mask) 00088 { 00089 _node_reader.check_bounds(); 00090 _portal_depth = parent._portal_depth; 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: CullTraverserData::Destructor 00095 // Access: Public 00096 // Description: 00097 //////////////////////////////////////////////////////////////////// 00098 INLINE CullTraverserData:: 00099 ~CullTraverserData() { 00100 } 00101 00102 //////////////////////////////////////////////////////////////////// 00103 // Function: CullTraverserData::node 00104 // Access: Published 00105 // Description: Returns the node traversed to so far. 00106 //////////////////////////////////////////////////////////////////// 00107 INLINE PandaNode *CullTraverserData:: 00108 node() const { 00109 return _node_path.node(); 00110 } 00111 00112 //////////////////////////////////////////////////////////////////// 00113 // Function: CullTraverserData::node_reader 00114 // Access: Public 00115 // Description: Returns the PipelineReader for the node traversed to 00116 // so far. 00117 //////////////////////////////////////////////////////////////////// 00118 INLINE PandaNodePipelineReader *CullTraverserData:: 00119 node_reader() { 00120 return &_node_reader; 00121 } 00122 00123 //////////////////////////////////////////////////////////////////// 00124 // Function: CullTraverserData::node_reader 00125 // Access: Public 00126 // Description: Returns the PipelineReader for the node traversed to 00127 // so far. 00128 //////////////////////////////////////////////////////////////////// 00129 INLINE const PandaNodePipelineReader *CullTraverserData:: 00130 node_reader() const { 00131 return &_node_reader; 00132 } 00133 00134 //////////////////////////////////////////////////////////////////// 00135 // Function: CullTraverserData::get_net_transform 00136 // Access: Published 00137 // Description: Returns the net transform: the relative transform 00138 // from root of the scene graph to the current node. 00139 //////////////////////////////////////////////////////////////////// 00140 INLINE const TransformState *CullTraverserData:: 00141 get_net_transform(const CullTraverser *) const { 00142 return _net_transform; 00143 } 00144 00145 //////////////////////////////////////////////////////////////////// 00146 // Function: CullTraverserData::is_in_view 00147 // Access: Published 00148 // Description: Returns true if the current node is within the view 00149 // frustum, false otherwise. If the node's bounding 00150 // volume falls completely within the view frustum, this 00151 // will also reset the view frustum pointer, saving some 00152 // work for future nodes. 00153 //////////////////////////////////////////////////////////////////// 00154 INLINE bool CullTraverserData:: 00155 is_in_view(const DrawMask &camera_mask) { 00156 if (_node_reader.get_transform()->is_invalid()) { 00157 // If the transform is invalid, forget it. 00158 return false; 00159 } 00160 00161 if (!_node_reader.compare_draw_mask(_draw_mask, camera_mask)) { 00162 // If there are no draw bits in common with the camera, the node 00163 // is out. 00164 return false; 00165 } 00166 00167 if (_view_frustum == (GeometricBoundingVolume *)NULL && 00168 _cull_planes->is_empty()) { 00169 // If the transform is valid, but we don't have a frustum or any 00170 // clip planes or occluders, it's always in. 00171 return true; 00172 } 00173 00174 // Otherwise, compare the bounding volume to the frustum. 00175 return is_in_view_impl(); 00176 } 00177 00178 //////////////////////////////////////////////////////////////////// 00179 // Function: CullTraverserData::is_this_node_hidden 00180 // Access: Published 00181 // Description: Returns true if this particular node is hidden, even 00182 // though we might be traversing past this node to find 00183 // a child node that has had show_through() called for 00184 // it. If this returns true, the node should not be 00185 // rendered. 00186 //////////////////////////////////////////////////////////////////// 00187 INLINE bool CullTraverserData:: 00188 is_this_node_hidden(const CullTraverser *trav) const { 00189 return (_draw_mask & PandaNode::get_overall_bit()).is_zero() || 00190 (_draw_mask & trav->get_camera_mask()).is_zero(); 00191 }