Blender V2.61 - r43446

IK_QJacobianSolver.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_QJacobianSolver_h
00035 
00036 #define NAN_INCLUDED_IK_QJacobianSolver_h
00037 
00043 #include <vector>
00044 #include <list>
00045 
00046 #include "MT_Vector3.h"
00047 #include "MT_Transform.h"
00048 #include "IK_QJacobian.h"
00049 #include "IK_QSegment.h"
00050 #include "IK_QTask.h"
00051 
00052 class IK_QJacobianSolver
00053 {
00054 public:
00055     IK_QJacobianSolver();
00056     ~IK_QJacobianSolver() {};
00057 
00058     // setup pole vector constraint
00059     void SetPoleVectorConstraint(IK_QSegment *tip, MT_Vector3& goal,
00060         MT_Vector3& polegoal, float poleangle, bool getangle);
00061     float GetPoleAngle() { return m_poleangle; };
00062 
00063     // call setup once before solving, if it fails don't solve
00064     bool Setup(IK_QSegment *root, std::list<IK_QTask*>& tasks);
00065 
00066     // returns true if converged, false if max number of iterations was used
00067     bool Solve(
00068         IK_QSegment *root,
00069         std::list<IK_QTask*> tasks,
00070         const MT_Scalar tolerance,
00071         const int max_iterations
00072     );
00073 
00074 private:
00075     void AddSegmentList(IK_QSegment *seg);
00076     bool UpdateAngles(MT_Scalar& norm);
00077     void ConstrainPoleVector(IK_QSegment *root, std::list<IK_QTask*>& tasks);
00078 
00079     MT_Scalar ComputeScale();
00080     void Scale(float scale, std::list<IK_QTask*>& tasks);
00081 
00082 private:
00083 
00084     IK_QJacobian m_jacobian;
00085     IK_QJacobian m_jacobian_sub;
00086 
00087     bool m_secondary_enabled;
00088 
00089     std::vector<IK_QSegment*> m_segments;
00090 
00091     MT_Transform m_rootmatrix;
00092 
00093     bool m_poleconstraint;
00094     bool m_getpoleangle;
00095     MT_Vector3 m_goal;
00096     MT_Vector3 m_polegoal;
00097     float m_poleangle;
00098     IK_QSegment *m_poletip;
00099 };
00100 
00101 #endif
00102