PageRenderTime 858ms CodeModel.GetById 684ms app.highlight 12ms RepoModel.GetById 159ms app.codeStats 1ms

/indra/llcharacter/lljoint.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 199 lines | 103 code | 42 blank | 54 comment | 0 complexity | 6f1161e867cecf08d861757d34c3694b MD5 | raw file
  1/** 
  2 * @file lljoint.h
  3 * @brief Implementation of LLJoint 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_LLJOINT_H
 28#define LL_LLJOINT_H
 29
 30//-----------------------------------------------------------------------------
 31// Header Files
 32//-----------------------------------------------------------------------------
 33#include <string>
 34
 35#include "linked_lists.h"
 36#include "v3math.h"
 37#include "v4math.h"
 38#include "m4math.h"
 39#include "llquaternion.h"
 40#include "xform.h"
 41#include "lldarray.h"
 42
 43const S32 LL_CHARACTER_MAX_JOINTS_PER_MESH = 15;
 44const U32 LL_CHARACTER_MAX_JOINTS = 32; // must be divisible by 4!
 45const U32 LL_HAND_JOINT_NUM = 31;
 46const U32 LL_FACE_JOINT_NUM = 30;
 47const S32 LL_CHARACTER_MAX_PRIORITY = 7;
 48const F32 LL_MAX_PELVIS_OFFSET = 5.f;
 49
 50//-----------------------------------------------------------------------------
 51// class LLJoint
 52//-----------------------------------------------------------------------------
 53class LLJoint
 54{
 55public:
 56	// priority levels, from highest to lowest
 57	enum JointPriority
 58	{
 59		USE_MOTION_PRIORITY = -1,
 60		LOW_PRIORITY = 0,
 61		MEDIUM_PRIORITY,
 62		HIGH_PRIORITY,
 63		HIGHER_PRIORITY,
 64		HIGHEST_PRIORITY,
 65		ADDITIVE_PRIORITY = LL_CHARACTER_MAX_PRIORITY
 66	};
 67
 68	enum DirtyFlags
 69	{
 70		MATRIX_DIRTY = 0x1 << 0,
 71		ROTATION_DIRTY = 0x1 << 1,
 72		POSITION_DIRTY = 0x1 << 2,
 73		ALL_DIRTY = 0x7
 74	};
 75protected:
 76	std::string	mName;
 77
 78	// parent joint
 79	LLJoint	*mParent;
 80
 81	// explicit transformation members
 82	LLXformMatrix		mXform;
 83	LLXformMatrix		mOldXform;
 84	LLXformMatrix		mDefaultXform;
 85
 86	LLUUID				mId;
 87public:
 88	U32				mDirtyFlags;
 89	BOOL			mUpdateXform;
 90
 91	BOOL			mResetAfterRestoreOldXform;
 92
 93	// describes the skin binding pose
 94	LLVector3		mSkinOffset;
 95
 96	S32				mJointNum;
 97
 98	// child joints
 99	typedef std::list<LLJoint*> child_list_t;
100	child_list_t mChildren;
101
102	// debug statics
103	static S32		sNumTouches;
104	static S32		sNumUpdates;
105
106public:
107	LLJoint();
108	LLJoint( const std::string &name, LLJoint *parent=NULL );
109
110	virtual ~LLJoint();
111
112	// set name and parent
113	void setup( const std::string &name, LLJoint *parent=NULL );
114
115	void touch(U32 flags = ALL_DIRTY);
116
117	// get/set name
118	const std::string& getName() const { return mName; }
119	void setName( const std::string &name ) { mName = name; }
120
121	// getParent
122	LLJoint *getParent() { return mParent; }
123
124	// getRoot
125	LLJoint *getRoot();
126
127	// search for child joints by name
128	LLJoint *findJoint( const std::string &name );
129
130	// add/remove children
131	void addChild( LLJoint *joint );
132	void removeChild( LLJoint *joint );
133	void removeAllChildren();
134
135	// get/set local position
136	const LLVector3& getPosition();
137	void setPosition( const LLVector3& pos );
138	
139	void setDefaultPosition( const LLVector3& pos );
140	
141	// get/set world position
142	LLVector3 getWorldPosition();
143	LLVector3 getLastWorldPosition();
144	void setWorldPosition( const LLVector3& pos );
145
146	// get/set local rotation
147	const LLQuaternion& getRotation();
148	void setRotation( const LLQuaternion& rot );
149
150	// get/set world rotation
151	LLQuaternion getWorldRotation();
152	LLQuaternion getLastWorldRotation();
153	void setWorldRotation( const LLQuaternion& rot );
154
155	// get/set local scale
156	const LLVector3& getScale();
157	void setScale( const LLVector3& scale );
158
159	// get/set world matrix
160	const LLMatrix4 &getWorldMatrix();
161	void setWorldMatrix( const LLMatrix4& mat );
162
163	void updateWorldMatrixChildren();
164	void updateWorldMatrixParent();
165
166	void updateWorldPRSParent();
167
168	void updateWorldMatrix();
169
170	// get/set skin offset
171	const LLVector3 &getSkinOffset();
172	void setSkinOffset( const LLVector3 &offset);
173
174	LLXformMatrix	*getXform() { return &mXform; }
175
176	void clampRotation(LLQuaternion old_rot, LLQuaternion new_rot);
177
178	virtual BOOL isAnimatable() const { return TRUE; }
179
180	S32 getJointNum() const { return mJointNum; }
181	void setJointNum(S32 joint_num) { mJointNum = joint_num; }
182	
183	void restoreOldXform( void );
184	void restoreToDefaultXform( void );
185	void setDefaultFromCurrentXform( void );
186	void storeCurrentXform( const LLVector3& pos );
187
188	//Accessor for the joint id
189	LLUUID getId( void ) { return mId; }
190	//Setter for the joints id
191	void setId( const LLUUID& id ) { mId = id;}
192
193	//If the old transform flag has been set, then the reset logic in avatar needs to be aware(test) of it
194	const BOOL doesJointNeedToBeReset( void ) const { return mResetAfterRestoreOldXform; }
195	//Setter for joint reset flag
196	void setJointToBeReset( BOOL val ) { mResetAfterRestoreOldXform = val; }
197};
198#endif // LL_LLJOINT_H
199