Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/gobj/boundedObject.cxx

Go to the documentation of this file.
00001 // Filename: boundedObject.cxx
00002 // Created by:  drose (02Oct99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "boundedObject.h"
00020 #include "config_gobj.h"
00021 
00022 #include "boundingSphere.h"
00023 
00024 TypeHandle BoundedObject::_type_handle;
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: BoundedObject::Destructor
00028 //       Access: Public, Virtual
00029 //  Description:
00030 ////////////////////////////////////////////////////////////////////
00031 BoundedObject::
00032 ~BoundedObject() {
00033 }
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: BoundedObject::get_bound
00037 //       Access: Published
00038 //  Description: Returns the current bounding volume on this node,
00039 //               possibly forcing a recompute.  A node's bounding
00040 //               volume encloses only the node itself, irrespective of
00041 //               the nodes above or below it in the graph.  This is
00042 //               different from the bounding volumes on the arcs,
00043 //               which enclose all geometry below them.
00044 ////////////////////////////////////////////////////////////////////
00045 const BoundingVolume &BoundedObject::
00046 get_bound() const {
00047   {
00048     CDReader cdata(_cycler);
00049     if (cdata->_bound_type == BVT_static) {
00050       CDWriter cdata_w(((BoundedObject *)this)->_cycler, cdata);
00051       cdata_w->_flags &= ~F_bound_stale;
00052       return *cdata_w->_bound;
00053     }
00054     
00055     if (!is_bound_stale() && cdata->_bound != (BoundingVolume *)NULL) {
00056       return *cdata->_bound;
00057     }
00058 
00059     // We need to recompute the bounding volume.  First, we need to
00060     // release the old CDReader, so we can make a CDWriter in
00061     // recompute_bound.
00062   }
00063 
00064   // Now it's safe to recompute the bounds.
00065   ((BoundedObject *)this)->recompute_bound();
00066   CDReader cdata(_cycler);
00067   return *cdata->_bound;
00068 }
00069 
00070 ////////////////////////////////////////////////////////////////////
00071 //     Function: BoundedObject::CData::make_copy
00072 //       Access: Public, Virtual
00073 //  Description:
00074 ////////////////////////////////////////////////////////////////////
00075 CycleData *BoundedObject::CData::
00076 make_copy() const {
00077   return new CData(*this);
00078 }
00079 
00080 ////////////////////////////////////////////////////////////////////
00081 //     Function: BoundedObject::propagate_stale_bound
00082 //       Access: Protected, Virtual
00083 //  Description: Called by BoundedObject::mark_bound_stale(), this
00084 //               should make sure that all bounding volumes that
00085 //               depend on this one are marked stale also.
00086 ////////////////////////////////////////////////////////////////////
00087 void BoundedObject::
00088 propagate_stale_bound() {
00089 }
00090 
00091 ////////////////////////////////////////////////////////////////////
00092 //     Function: BoundedObject::recompute_bound
00093 //       Access: Protected, Virtual
00094 //  Description: Recomputes the dynamic bounding volume for this
00095 //               object.  The default behavior is the compute an empty
00096 //               bounding volume; this may be overridden to extend it
00097 //               to create a nonempty bounding volume.  However, after
00098 //               calling this function, it is guaranteed that the
00099 //               _bound pointer will not be shared with any other
00100 //               stage of the pipeline, and this new pointer is
00101 //               returned.
00102 ////////////////////////////////////////////////////////////////////
00103 BoundingVolume *BoundedObject::
00104 recompute_bound() {
00105   CDWriter cdata(_cycler);
00106   switch (cdata->_bound_type) {
00107   case BVT_static:
00108     // Don't change it if it's a static volume.
00109     break;
00110 
00111   case BVT_dynamic_sphere:
00112     cdata->_bound = new BoundingSphere;
00113     break;
00114 
00115   default:
00116     gobj_cat.error()
00117       << "Unexpected _bound_type: " << (int)cdata->_bound_type
00118       << " in BoundedObject::recompute_bound()\n";
00119     cdata->_bound = new BoundingSphere;
00120   }
00121 
00122   cdata->_flags &= ~F_bound_stale;
00123 
00124   // Now the _bound is new and empty.
00125   return cdata->_bound;
00126 }

Generated on Fri May 2 00:39:15 2003 for Panda by doxygen1.3