PageRenderTime 31ms CodeModel.GetById 26ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcharacter/lljointsolverrp3.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 176 lines | 36 code | 19 blank | 121 comment | 0 complexity | 3acd179ed36e8b4c031b5d6f62523aff MD5 | raw file
  1/** 
  2 * @file lljointsolverrp3.h
  3 * @brief Implementation of LLJointSolverRP3 class
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLJOINTSOLVERRP3_H
 28#define LL_LLJOINTSOLVERRP3_H
 29
 30//-----------------------------------------------------------------------------
 31// Header Files
 32//-----------------------------------------------------------------------------
 33#include "lljoint.h"
 34
 35/* -some compilers don't like line continuation chars-
 36//-----------------------------------------------------------------------------
 37// class LLJointSolverRP3
 38//
 39// This class is a "poor man's" IK for simple 3 joint kinematic chains.
 40// It is modeled after the 'ikRPSolver' in Maya.
 41// This class takes 4 LLJoints:
 42//   jointA
 43//   jointB
 44//   jointC
 45//   jointGoal
 46//
 47// Such that jointA is the parent of jointB, jointB is the parent of jointC.
 48// When invoked, this class modifies the rotations of jointA and jointB such
 49// that the position of the jointC attempts to reach the position of jointGoal.
 50//
 51// At object initialization time, the distances between jointA - jointB and
 52// jointB - jointC are cached.  During evaluation these bone lengths are
 53// preserved.
 54//
 55//  A          A 
 56//  |          |
 57//  |          |
 58//  B          B---CG     A---B---C...G
 59//   \
 60//    \
 61//     CG
 62//
 63//
 64// In addition a "poleVector" is specified that does two things:
 65//
 66// a) defines the plane in which the solution occurs, thus
 67//    reducing an infinite number of solutions, down to 2.
 68//
 69// b) disambiguates the resulting two solutions as follows:
 70//
 71//  A             A            A--->poleVector
 72//  |              \            \
 73//  |               \            \
 74//  B       vs.      B   ==>      B
 75//   \               |            |
 76//    \              |            |
 77//     CG            CG           CG
 78//
 79// A "twist" setting allows the solution plane to be rotated about the
 80// line between A and C.  A handy animation feature.
 81//
 82// For "smarter" results for non-coplanar limbs, specify the joints axis
 83// of bend in the B's local frame (see setBAxis())
 84//-----------------------------------------------------------------------------
 85*/
 86
 87class LLJointSolverRP3
 88{
 89protected:
 90	LLJoint		*mJointA;
 91	LLJoint		*mJointB;
 92	LLJoint		*mJointC;
 93	LLJoint		*mJointGoal;
 94
 95	F32			mLengthAB;
 96	F32			mLengthBC;
 97
 98	LLVector3	mPoleVector;
 99	LLVector3	mBAxis;
100	BOOL		mbUseBAxis;
101
102	F32			mTwist;
103
104	BOOL		mFirstTime;
105	LLMatrix4	mSavedJointAMat;
106	LLMatrix4	mSavedInvPlaneMat;
107
108	LLQuaternion	mJointABaseRotation;
109	LLQuaternion	mJointBBaseRotation;
110
111public:
112	//-------------------------------------------------------------------------
113	// Constructor/Destructor
114	//-------------------------------------------------------------------------
115	LLJointSolverRP3();
116	virtual ~LLJointSolverRP3();
117
118	//-------------------------------------------------------------------------
119	// setupJoints()
120	// This must be called one time to setup the solver.
121	// This must be called AFTER the skeleton has been created, all parent/child
122	// relationships are established, and after the joints are placed in
123	// a valid configuration (as distances between them will be cached).
124	//-------------------------------------------------------------------------
125	void setupJoints(	LLJoint* jointA,
126						LLJoint* jointB,
127						LLJoint* jointC,
128						LLJoint* jointGoal );
129
130	//-------------------------------------------------------------------------
131	// getPoleVector()
132	// Returns the current pole vector.
133	//-------------------------------------------------------------------------
134	const LLVector3& getPoleVector();
135
136	//-------------------------------------------------------------------------
137	// setPoleVector()
138	// Sets the pole vector.
139	// The pole vector is defined relative to (in the space of) jointA's parent.
140	// The default pole vector is (1,0,0), and this is used if this function
141	// is never called.
142	// This vector is normalized when set.
143	//-------------------------------------------------------------------------
144	void setPoleVector( const LLVector3& poleVector );
145
146	//-------------------------------------------------------------------------
147	// setBAxis()
148	// Sets the joint's axis in B's local frame, and enable "smarter" solve(). 
149	// This allows for smarter IK when for twisted limbs.
150	//-------------------------------------------------------------------------
151	void setBAxis( const LLVector3& bAxis );
152
153	//-------------------------------------------------------------------------
154	// getTwist()
155	// Returns the current twist in radians.
156	//-------------------------------------------------------------------------
157	F32 getTwist();
158
159	//-------------------------------------------------------------------------
160	// setTwist()
161	// Sets the twist value.
162	// The default is 0.0.
163	//-------------------------------------------------------------------------
164	void setTwist( F32 twist );
165
166	//-------------------------------------------------------------------------
167	// solve()
168	// This is the "work" function.
169	// When called, the rotations of jointA and jointB will be modified
170	// such that jointC attempts to reach jointGoal.
171	//-------------------------------------------------------------------------
172	void solve();
173};
174
175#endif // LL_LLJOINTSOLVERRP3_H
176