175 lines
6.5 KiB
Plaintext
175 lines
6.5 KiB
Plaintext
// Filename: cullTraverserData.I
|
|
// Created by: drose (06Mar02)
|
|
//
|
|
////////////////////////////////////////////////////////////////////
|
|
//
|
|
// PANDA 3D SOFTWARE
|
|
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
|
//
|
|
// All use of this software is subject to the terms of the Panda 3d
|
|
// Software license. You should have received a copy of this license
|
|
// along with this source code; you will also find a current copy of
|
|
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
|
//
|
|
// To contact the maintainers of this program write to
|
|
// panda3d-general@lists.sourceforge.net .
|
|
//
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Function: CullTraverserData::Constructor
|
|
// Access: Public
|
|
// Description:
|
|
////////////////////////////////////////////////////////////////////
|
|
INLINE CullTraverserData::
|
|
CullTraverserData(const NodePath &start,
|
|
const TransformState *modelview_transform,
|
|
const RenderState *state,
|
|
GeometricBoundingVolume *view_frustum,
|
|
GeometricBoundingVolume *guard_band) :
|
|
_node_path(start),
|
|
_modelview_transform(modelview_transform),
|
|
_state(state),
|
|
_view_frustum(view_frustum),
|
|
_guard_band(guard_band),
|
|
_cull_planes(CullPlanes::make_empty())
|
|
{
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Function: CullTraverserData::Copy Constructor
|
|
// Access: Public
|
|
// Description:
|
|
////////////////////////////////////////////////////////////////////
|
|
INLINE CullTraverserData::
|
|
CullTraverserData(const CullTraverserData ©) :
|
|
_node_path(copy._node_path),
|
|
_modelview_transform(copy._modelview_transform),
|
|
_state(copy._state),
|
|
_view_frustum(copy._view_frustum),
|
|
_guard_band(copy._guard_band),
|
|
_cull_planes(copy._cull_planes)
|
|
{
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Function: CullTraverserData::Copy Assignment Operator
|
|
// Access: Public
|
|
// Description:
|
|
////////////////////////////////////////////////////////////////////
|
|
INLINE void CullTraverserData::
|
|
operator = (const CullTraverserData ©) {
|
|
_node_path = copy._node_path;
|
|
_modelview_transform = copy._modelview_transform;
|
|
_state = copy._state;
|
|
_view_frustum = copy._view_frustum;
|
|
_guard_band = copy._guard_band;
|
|
_cull_planes = copy._cull_planes;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Function: CullTraverserData::Constructor
|
|
// Access: Public
|
|
// Description: This constructor creates a CullTraverserData object
|
|
// that reflects the next node down in the traversal.
|
|
////////////////////////////////////////////////////////////////////
|
|
INLINE CullTraverserData::
|
|
CullTraverserData(const CullTraverserData &parent, PandaNode *child) :
|
|
_node_path(parent._node_path, child),
|
|
_modelview_transform(parent._modelview_transform),
|
|
_state(parent._state),
|
|
_view_frustum(parent._view_frustum),
|
|
_guard_band(parent._guard_band),
|
|
_cull_planes(parent._cull_planes)
|
|
{
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Function: CullTraverserData::Destructor
|
|
// Access: Public
|
|
// Description:
|
|
////////////////////////////////////////////////////////////////////
|
|
INLINE CullTraverserData::
|
|
~CullTraverserData() {
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Function: CullTraverserData::node
|
|
// Access: Public
|
|
// Description: Returns the node traversed to so far.
|
|
////////////////////////////////////////////////////////////////////
|
|
INLINE PandaNode *CullTraverserData::
|
|
node() const {
|
|
return _node_path.node();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Function: CullTraverserData::get_modelview_transform
|
|
// Access: Public
|
|
// Description: Returns the modelview transform: the relative
|
|
// transform from the camera to the model.
|
|
////////////////////////////////////////////////////////////////////
|
|
INLINE const TransformState *CullTraverserData::
|
|
get_modelview_transform() const {
|
|
return _modelview_transform;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Function: CullTraverserData::is_in_view
|
|
// Access: Public
|
|
// Description: Returns true if the current node is within the view
|
|
// frustum, false otherwise. If the node's bounding
|
|
// volume falls completely within the view frustum, this
|
|
// will also reset the view frustum pointer, saving some
|
|
// work for future nodes.
|
|
////////////////////////////////////////////////////////////////////
|
|
INLINE bool CullTraverserData::
|
|
is_in_view(const DrawMask &camera_mask) {
|
|
if (node()->get_transform()->is_invalid()) {
|
|
// If the transform is invalid, forget it.
|
|
return false;
|
|
}
|
|
|
|
if ((node()->get_draw_mask() & camera_mask).is_zero()) {
|
|
// If there are no draw bits in common with the camera, the node
|
|
// is out.
|
|
return false;
|
|
}
|
|
|
|
if (_view_frustum == (GeometricBoundingVolume *)NULL &&
|
|
_cull_planes->is_empty()) {
|
|
// If the transform is valid, but we don't have a frustum or any
|
|
// clip planes, it's always in.
|
|
return true;
|
|
}
|
|
|
|
// Otherwise, compare the bounding volume to the frustum.
|
|
return is_in_view_impl();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Function: CullTraverserData::test_within_clip_planes
|
|
// Access: Public
|
|
// Description: Returns the BoundingVolume intersection bits
|
|
// appropriate for the intersection of the current clip
|
|
// planes with the current node.
|
|
//
|
|
// That is, if the current node is within all clip
|
|
// planes (and will not be clipped at all), returns
|
|
// BoundingVolume::IF_all. If it is completely behind
|
|
// at least one clip plane, returns
|
|
// BoundingVolume::IF_intersection. If it is partially
|
|
// behind one or more clip planes, returns
|
|
// BoundingVolume::IF_some.
|
|
////////////////////////////////////////////////////////////////////
|
|
INLINE int CullTraverserData::
|
|
test_within_clip_planes(const CullTraverser *trav) const {
|
|
const ClipPlaneAttrib *cpa = _state->get_clip_plane();
|
|
if (cpa != (ClipPlaneAttrib *)NULL) {
|
|
return test_within_clip_planes_impl(trav, cpa);
|
|
}
|
|
// No clip plane attrib; therefore, the node is not clipped at
|
|
// all.
|
|
return BoundingVolume::IF_all | BoundingVolume::IF_possible | BoundingVolume::IF_some;
|
|
}
|