Blender V2.61 - r43446

IK_QTask.h

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