00001 //=========================================================================== 00002 /* 00003 This file is part of the CHAI 3D visualization and haptics libraries. 00004 Copyright (C) 2003-2009 by CHAI 3D. All rights reserved. 00005 00006 This library is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License("GPL") version 2 00008 as published by the Free Software Foundation. 00009 00010 For using the CHAI 3D libraries with software that can not be combined 00011 with the GNU GPL, and for taking advantage of the additional benefits 00012 of our support services, please contact CHAI 3D about acquiring a 00013 Professional Edition License. 00014 00015 \author <http://www.chai3d.org> 00016 \author Francois Conti 00017 \version 2.0.0 $Rev: 251 $ 00018 */ 00019 //=========================================================================== 00020 00021 //--------------------------------------------------------------------------- 00022 #ifndef CProxyPointForceAlgoH 00023 #define CProxyPointForceAlgoH 00024 //--------------------------------------------------------------------------- 00025 #include "math/CVector3d.h" 00026 #include "math/CMatrix3d.h" 00027 #include "collisions/CGenericCollision.h" 00028 #include "forces/CGenericPointForceAlgo.h" 00029 #include <map> 00030 //--------------------------------------------------------------------------- 00031 class cWorld; 00032 //--------------------------------------------------------------------------- 00033 00034 //=========================================================================== 00042 //=========================================================================== 00043 00044 //=========================================================================== 00053 //=========================================================================== 00054 class cProxyPointForceAlgo : public cGenericPointForceAlgo 00055 { 00056 public: 00057 //----------------------------------------------------------------------- 00058 // CONSTRUCTOR & DESTRUCTOR: 00059 //----------------------------------------------------------------------- 00060 00062 cProxyPointForceAlgo(); 00063 00065 virtual ~cProxyPointForceAlgo() {} 00066 00067 00068 //---------------------------------------------------------------------- 00069 // METHODS - BASIC PROXY: 00070 //---------------------------------------------------------------------- 00071 00073 void initialize(cWorld* a_world, const cVector3d& a_initialGlobalPosition); 00074 00076 void reset(); 00077 00079 virtual cVector3d computeForces(const cVector3d& a_toolPos, const cVector3d& a_toolVel); 00080 00081 00082 //---------------------------------------------------------------------- 00083 // METHODS - GETTER AND SETTER FUNCTIONS: 00084 //---------------------------------------------------------------------- 00085 00087 void setProxyRadius(const double& a_radius) { m_radius = a_radius; m_collisionSettings.m_collisionRadius = m_radius;} 00088 00090 inline double getProxyRadius() const { return (m_radius); } 00091 00093 inline cVector3d getProxyGlobalPosition() const { return (m_proxyGlobalPos); } 00094 00096 inline void setProxyGlobalPosition(const cVector3d& a_position) { m_proxyGlobalPos = a_position; } 00097 00099 inline cVector3d getDeviceGlobalPosition() const { return (m_deviceGlobalPos); } 00100 00102 inline cVector3d getForce() { return (m_lastGlobalForce); } 00103 00105 inline cVector3d getNormalForce() { return (m_normalForce); } 00106 00108 inline cVector3d getTangentialForce() { return (m_tangentialForce); } 00109 00110 00111 //---------------------------------------------------------------------- 00112 // METHODS - COLLISION INFORMATION BETWEEN PROXY AND WORLD 00113 //---------------------------------------------------------------------- 00115 int getNumContacts() { return (m_numContacts); } 00116 00118 cCollisionEvent* m_contactPoint0; 00119 00121 cCollisionEvent* m_contactPoint1; 00122 00124 cCollisionEvent* m_contactPoint2; 00125 00126 00127 //---------------------------------------------------------------------- 00128 // METHODS - FORCE MODELS 00129 //---------------------------------------------------------------------- 00130 00132 bool m_useFriction; 00133 00135 bool m_useDynamicProxy; 00136 00138 bool m_useForceShading; 00139 00146 double m_frictionDynHysteresisMultiplier; 00147 00149 double m_forceShadingAngleThreshold; 00150 00152 cCollisionSettings m_collisionSettings; 00153 00154 //---------------------------------------------------------------------- 00155 // METHODS - RESOLUTION / ERRORS 00156 //---------------------------------------------------------------------- 00157 00159 void setEpsilonBaseValue(double a_value); 00160 00162 double getEpsilonBaseValue() { return (m_epsilonBaseValue); } 00163 00164 00165 protected: 00166 00168 virtual bool goalAchieved(const cVector3d& a_proxy, const cVector3d& a_goal) const; 00169 00171 virtual void computeNextBestProxyPosition(const cVector3d& a_goal); 00172 00174 virtual void testFrictionAndMoveProxy(const cVector3d& a_goal, const cVector3d& a_proxy, cVector3d& a_normal, cGenericObject* a_parent); 00175 00177 virtual void updateForce(); 00178 00179 00180 //---------------------------------------------------------------------- 00181 // MEMBERS - PROXY, DEVICE AND FORCE INFORMATION: 00182 //---------------------------------------------------------------------- 00183 00185 cVector3d m_proxyGlobalPos; 00186 00188 cVector3d m_deviceGlobalPos; 00189 00191 cVector3d m_lastGlobalForce; 00192 00194 cVector3d m_nextBestProxyGlobalPos; 00195 00197 bool m_slipping; 00198 00200 cVector3d m_normalForce; 00201 00203 cVector3d m_tangentialForce; 00204 00206 unsigned int m_numContacts; 00207 00209 double m_radius; 00210 00211 00212 //---------------------------------------------------------------------- 00213 // MEMBERS - TOOLS REQUIRED FOR THE PROXY ALGORITHM 00214 //---------------------------------------------------------------------- 00215 00217 cCollisionRecorder m_collisionRecorderConstraint0; 00218 00220 cCollisionRecorder m_collisionRecorderConstraint1; 00221 00223 cCollisionRecorder m_collisionRecorderConstraint2; 00224 00230 00231 double m_epsilonInitialValue; 00232 00234 double m_epsilon; 00235 00237 double m_epsilonCollisionDetection; 00238 00240 double m_epsilonBaseValue; 00241 00243 double m_epsilonMinimalValue; 00244 00246 unsigned int m_algoCounter; 00247 00249 bool computeNextProxyPositionWithContraints0(const cVector3d& a_goalGlobalPos); 00250 00252 bool computeNextProxyPositionWithContraints1(const cVector3d& a_goalGlobalPos); 00253 00255 bool computeNextProxyPositionWithContraints2(const cVector3d& a_goalGlobalPos); 00256 }; 00257 00258 //--------------------------------------------------------------------------- 00259 #endif 00260 //--------------------------------------------------------------------------- 00261