FF3DLinearForceModel.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of Micole Architecture
00003  *
00004  * Copyright (C) 2007 Micole partners
00005  *
00006  * Micole Architecture is free software: you can redistribute it 
00007  * and/or modify it under the terms of the GNU Lesser General 
00008  * Public License as published by the Free Software Foundation, 
00009  * either version 3 of the License, or (at your option) any 
00010  * later version.
00011  *
00012  * Micole Architecture is distributed in the hope that it will be 
00013  * useful, * but WITHOUT ANY WARRANTY; without even the implied 
00014  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00015  * PURPOSE.  See the GNU Lesser General Public License for more 
00016  * details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Micole Architecture.  If not, see
00020  * <http://www.gnu.org/licenses/>.
00021  */
00022 
00023 #ifndef FF3DLinearForceModel_H
00024 #define FF3DLinearForceModel_H
00025 #include "micolelib.h"
00026 
00027 #include <iostream>
00028 #include "ReachinMicoleApplication.h"
00029 
00030 
00031 #include "FF3DForceModel.h"
00032 using namespace Reachin;
00033 using namespace std;
00034 
00038 struct MICOLELIB_API FF3DLinearForceModel : FF3DForceModel
00039 {
00040         mgFloat _stiffness; 
00041 
00042         Vec3f _pt1;
00043         Vec3f _pt2;
00044         //Vec3f _oldForce;
00045 
00051         FF3DLinearForceModel(const Vec3f &pt1, const Vec3f &pt2, const mgFloat &stiffness = STIFFNESS);
00052         FF3DLinearForceModel (const FF3DLinearForceModel& fm);
00053 
00054         virtual FF3DForceModel * clone() { return new FF3DLinearForceModel(*this); }
00055 
00056         virtual Vec3f evaluate( const Vec3f &pPos, const mgFloat &w )
00057         {
00058                 
00059                 Vec3f pos = pPos; //duplicate original pos
00060                 pos.y = 0; //ignore y pos
00061                 Vec3f diff = Vec3f(0,0,0) - pos; 
00062                 diff.y = 0; //only for linear
00063 
00064                 Vec3f force = _stiffness * diff;
00065 
00066                 //test to avoid unhook of phantom
00067 
00068         
00069 /*                      if ((force - _oldForce).length() > 0.5) {
00070                         
00071                         //_oldForce 
00072                         //s << "force: "<< force.length();
00073                         //s << " difference : " << (force - _oldForce).length();
00074                         //force.normalizeSafe();
00075                         //force=force*10; //max length unit
00076                         //s << " send force : " << force.length();
00077                         //ReachinMicoleApplication * ama = ReachinMicoleApplication::getInstance();
00078                         //ama->sendBusMessage(s.str().data());
00079 
00080                         //while ((force - _oldForce).length() > 0.3) 
00081                         while ((force-_oldForce).length() > 0.5) 
00082                         {
00083                                 force = 0.9*force+_oldForce*0.1  ; //Vec3f(
00084                         }
00085                         
00086                 }
00087 
00088 
00089                 _oldForce = force;
00090                 */              
00091                 
00092                 _oldForce = 0.7*_oldForce + 0.3* force;
00093                 
00094                 return _oldForce; 
00095                 //return Vec3f(100,0,0);
00096         }
00097 };
00098 
00099 #endif

Generated on Tue Oct 16 17:10:42 2007 for Micole by  doxygen 1.4.7