/indra/llcharacter/llpose.h
C++ Header | 140 lines | 72 code | 21 blank | 47 comment | 0 complexity | 980912d87b4393818abee26df3b37fa6 MD5 | raw file
Possible License(s): LGPL-2.1
1/** 2 * @file llpose.h 3 * @brief Implementation of LLPose 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_LLPOSE_H 28#define LL_LLPOSE_H 29 30//----------------------------------------------------------------------------- 31// Header Files 32//----------------------------------------------------------------------------- 33 34#include "lljointstate.h" 35#include "lljoint.h" 36#include "llmap.h" 37#include "llpointer.h" 38 39#include <map> 40#include <string> 41 42 43//----------------------------------------------------------------------------- 44// class LLPose 45//----------------------------------------------------------------------------- 46class LLPose 47{ 48 friend class LLPoseBlender; 49protected: 50 typedef std::map<std::string, LLPointer<LLJointState> > joint_map; 51 typedef joint_map::iterator joint_map_iterator; 52 typedef joint_map::value_type joint_map_value_type; 53 54 joint_map mJointMap; 55 F32 mWeight; 56 joint_map_iterator mListIter; 57public: 58 // Iterate through jointStates 59 LLJointState* getFirstJointState(); 60 LLJointState* getNextJointState(); 61 LLJointState* findJointState(LLJoint *joint); 62 LLJointState* findJointState(const std::string &name); 63public: 64 // Constructor 65 LLPose() : mWeight(0.f) {} 66 // Destructor 67 ~LLPose(); 68 // add a joint state in this pose 69 BOOL addJointState(const LLPointer<LLJointState>& jointState); 70 // remove a joint state from this pose 71 BOOL removeJointState(const LLPointer<LLJointState>& jointState); 72 // removes all joint states from this pose 73 BOOL removeAllJointStates(); 74 // set weight for all joint states in this pose 75 void setWeight(F32 weight); 76 // get weight for this pose 77 F32 getWeight() const; 78 // returns number of joint states stored in this pose 79 S32 getNumJointStates() const; 80}; 81 82const S32 JSB_NUM_JOINT_STATES = 6; 83 84class LLJointStateBlender 85{ 86protected: 87 LLPointer<LLJointState> mJointStates[JSB_NUM_JOINT_STATES]; 88 S32 mPriorities[JSB_NUM_JOINT_STATES]; 89 BOOL mAdditiveBlends[JSB_NUM_JOINT_STATES]; 90public: 91 LLJointStateBlender(); 92 ~LLJointStateBlender(); 93 void blendJointStates(BOOL apply_now = TRUE); 94 BOOL addJointState(const LLPointer<LLJointState>& joint_state, S32 priority, BOOL additive_blend); 95 void interpolate(F32 u); 96 void clear(); 97 void resetCachedJoint(); 98 99public: 100 LLJoint mJointCache; 101}; 102 103class LLMotion; 104 105class LLPoseBlender 106{ 107protected: 108 typedef std::list<LLJointStateBlender*> blender_list_t; 109 typedef std::map<LLJoint*,LLJointStateBlender*> blender_map_t; 110 blender_map_t mJointStateBlenderPool; 111 blender_list_t mActiveBlenders; 112 113 S32 mNextPoseSlot; 114 LLPose mBlendedPose; 115public: 116 // Constructor 117 LLPoseBlender(); 118 // Destructor 119 ~LLPoseBlender(); 120 121 // request motion joint states to be added to pose blender joint state records 122 BOOL addMotion(LLMotion* motion); 123 124 // blend all joint states and apply to skeleton 125 void blendAndApply(); 126 127 // removes all joint state blenders from last time 128 void clearBlenders(); 129 130 // blend all joint states and cache results 131 void blendAndCache(BOOL reset_cached_joints); 132 133 // interpolate all joints towards cached values 134 void interpolate(F32 u); 135 136 LLPose* getBlendedPose() { return &mBlendedPose; } 137}; 138 139#endif // LL_LLPOSE_H 140