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 FF3DSPHERICALFORCEMODEL_H 00024 #define FF3DSPHERICALFORCEMODEL_H 00025 #include "micolelib.h" 00026 00027 #include "define.h" 00028 00029 #include "FF3DForceModel.h" 00030 #include <LinearAlgebra.h> 00031 using namespace Reachin; 00032 00036 struct MICOLELIB_API FF3DSphericalForceModel : FF3DForceModel 00037 { 00038 mgFloat _stiffness; 00039 00040 Vec3f _pt1; 00041 Vec3f _pt2; 00042 Vec3f _pt3; 00043 00044 mgFloat _range; 00045 00046 00052 FF3DSphericalForceModel(const Vec3f &pt, const mgFloat &pRange, const mgFloat &stiffness = STIFFNESS); 00053 FF3DSphericalForceModel (const FF3DSphericalForceModel &fm); 00054 00055 virtual FF3DForceModel * clone() {return new FF3DSphericalForceModel(*this); } 00056 00057 virtual Vec3f evaluate( const Vec3f &pos, const mgFloat &w ) 00058 { 00059 Vec3f diff = Vec3f(0,0,0) - pos; 00060 //diff.x = 0; //only for linear 00061 //diff.z = 0; //only for planar 00062 if (diff.length()< _range) 00063 return Vec3f(0,0,0); 00064 00065 Vec3f normaldiff = diff; 00066 normaldiff.normalizeSafe(); 00067 00068 return (_stiffness * (diff-(_range * normaldiff))); 00069 } 00070 }; 00071 00072 #endif