doxygen: intern/iksolver tagged. Leaving out TNT, since we have it in multiple locations.
[blender.git] / intern / iksolver / intern / IK_QTask.h
1 /*
2  * $Id$
3  * ***** BEGIN GPL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  * The Original Code is: all of this file.
23  *
24  * Original author: Laurence
25  * Contributor(s): Brecht
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 /** \file iksolver/intern/IK_QTask.h
31  *  \ingroup iksolver
32  */
33
34
35 #ifndef NAN_INCLUDED_IK_QTask_h
36 #define NAN_INCLUDED_IK_QTask_h
37
38 #include "MT_Vector3.h"
39 #include "MT_Transform.h"
40 #include "MT_Matrix4x4.h"
41 #include "IK_QJacobian.h"
42 #include "IK_QSegment.h"
43
44 class IK_QTask
45 {
46 public:
47         IK_QTask(
48                 int size,
49                 bool primary,
50                 bool active,
51                 const IK_QSegment *segment
52         );
53         virtual ~IK_QTask() {};
54
55         int Id() const
56         { return m_size; }
57
58         void SetId(int id)
59         { m_id = id; }
60
61         int Size() const
62         { return m_size; }
63
64         bool Primary() const
65         { return m_primary; }
66
67         bool Active() const
68         { return m_active; }
69
70         MT_Scalar Weight() const
71         { return m_weight*m_weight; }
72
73         void SetWeight(MT_Scalar weight)
74         { m_weight = sqrt(weight); }
75
76         virtual void ComputeJacobian(IK_QJacobian& jacobian)=0;
77
78         virtual MT_Scalar Distance() const=0;
79
80         virtual bool PositionTask() const { return false; }
81
82         virtual void Scale(float) {}
83
84 protected:
85         int m_id;
86         int m_size;
87         bool m_primary;
88         bool m_active;
89         const IK_QSegment *m_segment;
90         MT_Scalar m_weight;
91 };
92
93 class IK_QPositionTask : public IK_QTask
94 {
95 public:
96         IK_QPositionTask(
97                 bool primary,
98                 const IK_QSegment *segment,
99                 const MT_Vector3& goal
100         );
101
102         void ComputeJacobian(IK_QJacobian& jacobian);
103
104         MT_Scalar Distance() const;
105
106         bool PositionTask() const { return true; }
107         void Scale(float scale) { m_goal *= scale; m_clamp_length *= scale; }
108
109 private:
110         MT_Vector3 m_goal;
111         MT_Scalar m_clamp_length;
112 };
113
114 class IK_QOrientationTask : public IK_QTask
115 {
116 public:
117         IK_QOrientationTask(
118                 bool primary,
119                 const IK_QSegment *segment,
120                 const MT_Matrix3x3& goal
121         );
122
123         MT_Scalar Distance() const { return m_distance; };
124         void ComputeJacobian(IK_QJacobian& jacobian);
125
126 private:
127         MT_Matrix3x3 m_goal;
128         MT_Scalar m_distance;
129 };
130
131
132 class IK_QCenterOfMassTask : public IK_QTask
133 {
134 public:
135         IK_QCenterOfMassTask(
136                 bool primary,
137                 const IK_QSegment *segment,
138                 const MT_Vector3& center
139         );
140
141         void ComputeJacobian(IK_QJacobian& jacobian);
142
143         MT_Scalar Distance() const;
144
145         void Scale(float scale) { m_goal_center *= scale; m_distance *= scale; }
146
147 private:
148         MT_Scalar ComputeTotalMass(const IK_QSegment *segment);
149         MT_Vector3 ComputeCenter(const IK_QSegment *segment);
150         void JacobianSegment(IK_QJacobian& jacobian, MT_Vector3& center, const IK_QSegment *segment);
151
152         MT_Vector3 m_goal_center;
153         MT_Scalar m_total_mass_inv;
154         MT_Scalar m_distance;
155 };
156
157 #endif
158