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 __HLCUSTOMOBJECT_H__
00030 #define __HLCUSTOMOBJECT_H__
00031
00032 #include "H3DTypes.h"
00033 #include "HLShape.h"
00034
00035 namespace H3D {
00036
00037
00041 class H3DAPI_API HLCustomObject: public HLShape {
00042 public:
00043 #ifdef HAVE_OPENHAPTICS
00057 virtual bool intersectSurface( const Vec3f &start_point,
00058 const Vec3f &end_point,
00059 Vec3f &intersection_point,
00060 Vec3f &intersection_normal,
00061 HLenum &face ) = 0;
00062
00072 virtual bool closestFeature( const Vec3f &query_point,
00073 const Vec3f &target_point,
00074 HLgeom *geom,
00075 Vec3f &closest_point ) = 0;
00076 #endif
00082 virtual void hlRender( HLHapticsDevice *hd );
00083
00084 #ifdef HAVE_OPENHAPTICS
00085 protected:
00089 static HLboolean HLCALLBACK intersectCallback(
00090 const HLdouble *start_point,
00091 const HLdouble *end_point,
00092 HLdouble *intersection_point,
00093 HLdouble *intersection_normal,
00094 HLenum* face,
00095 void *user_data ) {
00096 HLCustomObject* object = static_cast<HLCustomObject*>( user_data );
00097 Vec3f ip, in;
00098 HLboolean b = object->intersectSurface( Vec3f((H3DFloat)start_point[0],
00099 (H3DFloat)start_point[1],
00100 (H3DFloat)start_point[2] ),
00101 Vec3f((H3DFloat)end_point[0],
00102 (H3DFloat)end_point[1],
00103 (H3DFloat)end_point[2] ),
00104 ip,
00105 in,
00106 *face );
00107 intersection_point[0] = ip.x;
00108 intersection_point[1] = ip.y;
00109 intersection_point[2] = ip.z;
00110
00111 intersection_normal[0] = in.x;
00112 intersection_normal[1] = in.y;
00113 intersection_normal[2] = in.z;
00114
00115 return b;
00116 }
00117
00121 static HLboolean HLCALLBACK closestFeaturesCallback(
00122 const HLdouble *query_point,
00123 const HLdouble *target_point,
00124 HLgeom *geom,
00125 HLdouble *closest_point,
00126 void* user_data ) {
00127 HLCustomObject* object = static_cast<HLCustomObject*>( user_data );
00128
00129 Vec3f cp, cn;
00130 HLboolean b = object->closestFeature( Vec3f( (H3DFloat)query_point[0],
00131 (H3DFloat)query_point[1],
00132 (H3DFloat)query_point[2] ),
00133 Vec3f( (H3DFloat)target_point[0],
00134 (H3DFloat)target_point[1],
00135 (H3DFloat)target_point[2]),
00136 geom,
00137 cp );
00138 closest_point[0] = cp.x;
00139 closest_point[1] = cp.y;
00140 closest_point[2] = cp.z;
00141
00142 return b;
00143 }
00144 #endif
00145 };
00146 }
00147
00148 #endif