HLCustomObject.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 __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

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