FF3DDiscForceModel.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 FF3DDiscForceModel_H
00024 #define FF3DDiscForceModel_H
00025 #include "micolelib.h"
00026 
00027 #include "FF3DForceModel.h"
00028 #include <LinearAlgebra.h>
00029 using namespace Reachin;
00030 
00034 struct MICOLELIB_API FF3DDiscForceModel : FF3DForceModel
00035 {
00036         mgFloat _stiffness; 
00037 
00038         Vec3f _pt1;
00039         Vec3f _pt2;
00040         Vec3f _pt3;
00041 
00042         mgFloat _range;
00043 
00049         FF3DDiscForceModel(const Vec3f &pt1, const Vec3f &pt2, const mgFloat &pRange, const mgFloat &stiffness = 800);
00050         FF3DDiscForceModel (const FF3DDiscForceModel& fm);
00051 
00052         virtual FF3DForceModel * clone() {return new FF3DDiscForceModel(*this); }
00053 
00054         virtual Vec3f evaluate( const Vec3f &pPos, const mgFloat &w )
00055         {
00056                         //planar evaluation
00057                         Vec3f pos = pPos; //duplicate original pos
00058                         pos.x = 0; //ignore y pos
00059                         pos.z = 0; //ignore y pos
00060                     Vec3f diff = Vec3f(0,0,0) - pos; 
00061                         diff.x = 0; //only for linear
00062                         diff.z = 0; //only for planar
00063                         //return diff; 
00064 
00065                         //sphere evaluation
00066                     Vec3f diff2 = Vec3f(0,0,0) - pPos; 
00067                         //diff.x = 0; //only for linear
00068                         //diff.z = 0; //only for planar
00069                         if (diff2.length()< _range)  
00070                                 diff2 = Vec3f(0,0,0);
00071                         else
00072                         {
00073                                 Vec3f normaldiff = diff2;
00074                                 normaldiff.normalizeSafe();
00075                                 
00076                                 diff2 = (diff2-(_range * normaldiff)); 
00077                         }
00078 
00079                         //combination of two effects
00080                         diff2.y = diff.y;
00081 
00082                         return (_stiffness * diff2);
00083         }
00084 };
00085 
00086 #endif

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