X3DShapeNode.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00027 //
00029 #ifndef __X3DSHAPENODE_H__
00030 #define __X3DSHAPENODE_H__
00031 
00032 #include "X3DChildNode.h"
00033 #include "X3DBoundedObject.h"
00034 #include "X3DAppearanceNode.h"
00035 #include "X3DGeometryNode.h"
00036 #include "DependentNodeFields.h"
00037 #include "H3DDisplayListObject.h"
00038 
00039 namespace H3D {
00046   class H3DAPI_API X3DShapeNode : 
00047     public X3DChildNode,
00048     public X3DBoundedObject,
00049     public H3DDisplayListObject {
00050   public:
00054     typedef DependentSFNode< X3DAppearanceNode,
00055                              FieldRef<H3DDisplayListObject, 
00056                                       H3DDisplayListObject::DisplayList,
00057                                       &H3DDisplayListObject::displayList >, 
00058                              true > 
00059     SFAppearanceNode;
00060         
00062     typedef TypedSFNode< X3DGeometryNode > SFHapticGeometry;
00063  
00071     class SFGeometryNode: 
00072       public DependentSFNode< X3DGeometryNode, 
00073       FieldRef< H3DDisplayListObject,
00074       H3DDisplayListObject::DisplayList,
00075       &H3DDisplayListObject::displayList >, true > {
00076         typedef DependentSFNode< X3DGeometryNode, 
00077         FieldRef< H3DDisplayListObject,
00078                   H3DDisplayListObject::DisplayList,
00079                   &H3DDisplayListObject::displayList >, true > BaseField;
00080     public:
00081     
00083       SFGeometryNode(): 
00084         owner( NULL ) {}
00085 
00088       ~SFGeometryNode() {
00089         value = NULL;
00090       }
00091 
00098       virtual void onAdd( Node *n ) {
00099         BaseField::onAdd( n );
00100         if( n && owner->use_geometry_bound ) {
00101           X3DGeometryNode *g = static_cast< X3DGeometryNode * >( n );
00102           g->bound->route( owner->bound );
00103         }
00104       }
00105       
00112       virtual void onRemove( Node *n ) {
00113         BaseField::onRemove( n );
00114         if( n && owner->use_geometry_bound ) {
00115           X3DGeometryNode *g = static_cast< X3DGeometryNode * >( n );
00116           g->bound->unroute( owner->bound );
00117         }
00118       }
00119 
00120       // the shape node that the instance of the SFGeometry field
00121       // is in.
00122       X3DShapeNode *owner;
00123 
00124     };
00125 
00126 
00128     X3DShapeNode( Inst< SFAppearanceNode > _appearance     = 0,
00129                   Inst< SFGeometryNode   > _geometry       = 0,
00130                   Inst< SFHapticGeometry > _hapticGeometry = 0,
00131                   Inst< SFNode           > _metadata       = 0,
00132                   Inst< SFBound          > _bound          = 0,
00133                   Inst< SFVec3f          > _bboxCenter     = 0,
00134                   Inst< SFVec3f          > _bboxSize       = 0
00135                   );
00136 
00137     
00142     virtual void initialize() {
00143       const Vec3f &size = bboxSize->getValue();
00144       if( size.x == -1 && size.y == -1 && size.z == -1 ) {
00145         use_geometry_bound = true;
00146         X3DGeometryNode *g = 
00147           static_cast< X3DGeometryNode * >( geometry->getValue() );
00148         if( g ) {
00149           g->bound->route( this->bound );
00150         }
00151       } else {
00152         BoxBound *bb = new BoxBound();
00153         bb->center->setValue( bboxCenter->getValue() );
00154         bb->size->setValue( bboxSize->getValue() );
00155         bound->setValue( bb );
00156       }
00157       X3DChildNode::initialize();
00158     }
00159 
00161     virtual void render();
00162 
00163 #ifdef USE_HAPTICS
00164 
00165     virtual void traverseSG( TraverseInfo &ti );
00166 #endif
00167 
00174     auto_ptr<    SFAppearanceNode  >  appearance;
00175 
00181     auto_ptr<    SFGeometryNode  >  geometry;
00182 
00189     auto_ptr<    SFHapticGeometry  >  hapticGeometry;
00190 
00191     // if true a route will be set up between the bound field of the
00192     // geometry node in this field and the bound field of the shape. 
00193     bool use_geometry_bound;
00194 
00196     static H3DNodeDatabase database;
00197 
00202     static bool disable_lighting_if_no_app;
00203   };
00204 }
00205 
00206 #endif

Generated on Thu Aug 24 12:38:35 2006 for H3D API by  doxygen 1.4.5