|
Blender
V2.59
|
00001 /* 00002 * $Id: IK_QTask.h 35154 2011-02-25 11:43:19Z jesterking $ 00003 * ***** BEGIN GPL LICENSE BLOCK ***** 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software Foundation, 00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 * 00019 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00020 * All rights reserved. 00021 * 00022 * The Original Code is: all of this file. 00023 * 00024 * Original author: Laurence 00025 * Contributor(s): Brecht 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00035 #ifndef NAN_INCLUDED_IK_QTask_h 00036 #define NAN_INCLUDED_IK_QTask_h 00037 00038 #include "MT_Vector3.h" 00039 #include "MT_Transform.h" 00040 #include "MT_Matrix4x4.h" 00041 #include "IK_QJacobian.h" 00042 #include "IK_QSegment.h" 00043 00044 class IK_QTask 00045 { 00046 public: 00047 IK_QTask( 00048 int size, 00049 bool primary, 00050 bool active, 00051 const IK_QSegment *segment 00052 ); 00053 virtual ~IK_QTask() {}; 00054 00055 int Id() const 00056 { return m_size; } 00057 00058 void SetId(int id) 00059 { m_id = id; } 00060 00061 int Size() const 00062 { return m_size; } 00063 00064 bool Primary() const 00065 { return m_primary; } 00066 00067 bool Active() const 00068 { return m_active; } 00069 00070 MT_Scalar Weight() const 00071 { return m_weight*m_weight; } 00072 00073 void SetWeight(MT_Scalar weight) 00074 { m_weight = sqrt(weight); } 00075 00076 virtual void ComputeJacobian(IK_QJacobian& jacobian)=0; 00077 00078 virtual MT_Scalar Distance() const=0; 00079 00080 virtual bool PositionTask() const { return false; } 00081 00082 virtual void Scale(float) {} 00083 00084 protected: 00085 int m_id; 00086 int m_size; 00087 bool m_primary; 00088 bool m_active; 00089 const IK_QSegment *m_segment; 00090 MT_Scalar m_weight; 00091 }; 00092 00093 class IK_QPositionTask : public IK_QTask 00094 { 00095 public: 00096 IK_QPositionTask( 00097 bool primary, 00098 const IK_QSegment *segment, 00099 const MT_Vector3& goal 00100 ); 00101 00102 void ComputeJacobian(IK_QJacobian& jacobian); 00103 00104 MT_Scalar Distance() const; 00105 00106 bool PositionTask() const { return true; } 00107 void Scale(float scale) { m_goal *= scale; m_clamp_length *= scale; } 00108 00109 private: 00110 MT_Vector3 m_goal; 00111 MT_Scalar m_clamp_length; 00112 }; 00113 00114 class IK_QOrientationTask : public IK_QTask 00115 { 00116 public: 00117 IK_QOrientationTask( 00118 bool primary, 00119 const IK_QSegment *segment, 00120 const MT_Matrix3x3& goal 00121 ); 00122 00123 MT_Scalar Distance() const { return m_distance; }; 00124 void ComputeJacobian(IK_QJacobian& jacobian); 00125 00126 private: 00127 MT_Matrix3x3 m_goal; 00128 MT_Scalar m_distance; 00129 }; 00130 00131 00132 class IK_QCenterOfMassTask : public IK_QTask 00133 { 00134 public: 00135 IK_QCenterOfMassTask( 00136 bool primary, 00137 const IK_QSegment *segment, 00138 const MT_Vector3& center 00139 ); 00140 00141 void ComputeJacobian(IK_QJacobian& jacobian); 00142 00143 MT_Scalar Distance() const; 00144 00145 void Scale(float scale) { m_goal_center *= scale; m_distance *= scale; } 00146 00147 private: 00148 MT_Scalar ComputeTotalMass(const IK_QSegment *segment); 00149 MT_Vector3 ComputeCenter(const IK_QSegment *segment); 00150 void JacobianSegment(IK_QJacobian& jacobian, MT_Vector3& center, const IK_QSegment *segment); 00151 00152 MT_Vector3 m_goal_center; 00153 MT_Scalar m_total_mass_inv; 00154 MT_Scalar m_distance; 00155 }; 00156 00157 #endif 00158