00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00027
00029 #ifndef __X3DGEOMETRYNODE_H__
00030 #define __X3DGEOMETRYNODE_H__
00031
00032 #include "X3DChildNode.h"
00033 #include "H3DBoundedObject.h"
00034 #include "H3DDisplayListObject.h"
00035 #include "MFBool.h"
00036 #include "MFVec3f.h"
00037 #include "AutoPtrVector.h"
00038 #include "H3DOptionNode.h"
00039 #include "MFNode.h"
00040 #ifdef HAVE_OPENHAPTICS
00041 #include <HL/hl.h>
00042 #endif
00043
00044 namespace H3D {
00045
00046 class HLHapticsDevice;
00047
00053 class H3DAPI_API X3DGeometryNode :
00054 public X3DChildNode,
00055 public H3DBoundedObject,
00056 public H3DDisplayListObject {
00057 public:
00058 typedef TypedMFNode< H3DOptionNode > MFOptionsNode;
00059
00065 class H3DAPI_API BugWorkaroundDisplayList:
00066 public H3DDisplayListObject::DisplayList {
00067 };
00068
00071 class H3DAPI_API DisplayList: public BugWorkaroundDisplayList {
00072 public:
00074 virtual void callList( bool build_list = true );
00075 };
00076
00078 X3DGeometryNode( Inst< SFNode > _metadata = 0,
00079 Inst< SFBound > _bound = 0,
00080 Inst< DisplayList > _displayList = 0,
00081 Inst< MFBool > _isTouched = 0,
00082 Inst< MFVec3f > _force = 0,
00083 Inst< MFVec3f > _contactPoint = 0,
00084 Inst< MFVec3f > _contactNormal = 0);
00085
00091 virtual void hlRender( HLHapticsDevice *hd, Matrix4f &transform ) {
00092 displayList->callList( false );
00093 }
00094
00098 inline void useBackFaceCulling( bool enabled ) {
00099 use_back_face_culling = enabled;
00100 }
00101
00103 inline bool usingBackFaceCulling() {
00104 return use_back_face_culling;
00105 }
00106
00110 inline void allowBackFaceCulling( bool allow ) {
00111 allow_back_face_culling = allow;
00112 }
00113
00115 inline bool allowingBackFaceCulling() {
00116 return allow_back_face_culling;
00117 }
00118
00123 template< class OptionNodeType >
00124 void getOptionNode( OptionNodeType * &option ) {
00125 for( MFOptionsNode::const_iterator i = options->begin();
00126 i != options->end(); i++ ) {
00127 OptionNodeType *options = dynamic_cast< OptionNodeType * >( *i );
00128 if( options ) {
00129 option = options;
00130 return;
00131 }
00132 }
00133 option = NULL;
00134 }
00135
00136 #ifdef HAVE_OPENHAPTICS
00138 virtual ~X3DGeometryNode();
00139
00145 HLuint getHLShapeId( HLHapticsDevice *hd,
00146 unsigned int index );
00147
00152 HapticShape *getOpenGLHapticShape( H3DSurfaceNode *_surface,
00153 const Matrix4f &_transform,
00154 HLint _nr_vertices = -1 );
00155 #endif
00159 virtual string defaultXMLContainerField() {
00160 return "geometry";
00161 }
00162
00170 auto_ptr< MFBool > isTouched;
00171
00176 auto_ptr< MFVec3f > force;
00177
00184 auto_ptr< MFVec3f > contactPoint;
00185
00192 auto_ptr< MFVec3f > contactNormal;
00193
00197 auto_ptr< MFOptionsNode > options;
00198
00200 static H3DNodeDatabase database;
00201
00202 protected:
00203
00204 #ifdef HAVE_OPENHAPTICS
00205
00206 static void HLCALLBACK touchCallback( HLenum event,
00207 HLuint object,
00208 HLenum thread,
00209 HLcache *cache,
00210 void *userdata );
00211
00214 static void HLCALLBACK untouchCallback( HLenum event,
00215 HLuint object,
00216 HLenum thread,
00217 HLcache *cache,
00218 void *userdata );
00219
00222 static void HLCALLBACK motionCallback( HLenum event,
00223 HLuint object,
00224 HLenum thread,
00225 HLcache *cache,
00226 void *userdata );
00227
00228 typedef map< HLHapticsDevice *, vector< HLuint > > ShapeIdMap;
00229
00231 ShapeIdMap hl_shape_ids;
00232
00233 struct CallbackData {
00234 CallbackData( X3DGeometryNode *g, int i ): geometry( g ), device_index( i ) {}
00235 X3DGeometryNode *geometry;
00236 int device_index;
00237 };
00238
00239 AutoPtrVector< CallbackData > callback_data;
00240
00241 bool use_back_face_culling, allow_back_face_culling;
00242
00243 #endif
00244 };
00245 }
00246
00247 #endif