Annotation of /trunk/indra/llcharacter/llmotion.h
Parent Directory
|
Revision Log
Revision 135 - (view) (download)
| 1 : | mjm | 135 | /** |
| 2 : | * @file llmotion.h | ||
| 3 : | * @brief Implementation of LLMotion class. | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2001&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | * Copyright (c) 2001-2009, Linden Research, Inc. | ||
| 8 : | * | ||
| 9 : | * Second Life Viewer Source Code | ||
| 10 : | * The source code in this file ("Source Code") is provided by Linden Lab | ||
| 11 : | * to you under the terms of the GNU General Public License, version 2.0 | ||
| 12 : | * ("GPL"), unless you have obtained a separate licensing agreement | ||
| 13 : | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
| 14 : | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
| 15 : | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
| 16 : | * | ||
| 17 : | * There are special exceptions to the terms and conditions of the GPL as | ||
| 18 : | * it is applied to this Source Code. View the full text of the exception | ||
| 19 : | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
| 20 : | * online at | ||
| 21 : | * http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 22 : | * | ||
| 23 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 24 : | * that you have read and understood your obligations described above, | ||
| 25 : | * and agree to abide by those obligations. | ||
| 26 : | * | ||
| 27 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 28 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 29 : | * COMPLETENESS OR PERFORMANCE. | ||
| 30 : | * $/LicenseInfo$ | ||
| 31 : | */ | ||
| 32 : | |||
| 33 : | #ifndef LL_LLMOTION_H | ||
| 34 : | #define LL_LLMOTION_H | ||
| 35 : | |||
| 36 : | //----------------------------------------------------------------------------- | ||
| 37 : | // Header files | ||
| 38 : | //----------------------------------------------------------------------------- | ||
| 39 : | #include <string> | ||
| 40 : | |||
| 41 : | #include "llerror.h" | ||
| 42 : | #include "llpose.h" | ||
| 43 : | #include "lluuid.h" | ||
| 44 : | |||
| 45 : | class LLCharacter; | ||
| 46 : | |||
| 47 : | //----------------------------------------------------------------------------- | ||
| 48 : | // class LLMotion | ||
| 49 : | //----------------------------------------------------------------------------- | ||
| 50 : | class LLMotion | ||
| 51 : | { | ||
| 52 : | friend class LLMotionController; | ||
| 53 : | |||
| 54 : | public: | ||
| 55 : | enum LLMotionBlendType | ||
| 56 : | { | ||
| 57 : | NORMAL_BLEND, | ||
| 58 : | ADDITIVE_BLEND | ||
| 59 : | }; | ||
| 60 : | |||
| 61 : | enum LLMotionInitStatus | ||
| 62 : | { | ||
| 63 : | STATUS_FAILURE, | ||
| 64 : | STATUS_SUCCESS, | ||
| 65 : | STATUS_HOLD | ||
| 66 : | }; | ||
| 67 : | |||
| 68 : | // Constructor | ||
| 69 : | LLMotion(const LLUUID &id); | ||
| 70 : | |||
| 71 : | // Destructor | ||
| 72 : | virtual ~LLMotion(); | ||
| 73 : | |||
| 74 : | public: | ||
| 75 : | //------------------------------------------------------------------------- | ||
| 76 : | // functions to support MotionController and MotionRegistry | ||
| 77 : | //------------------------------------------------------------------------- | ||
| 78 : | |||
| 79 : | // get the name of this instance | ||
| 80 : | const std::string &getName() const { return mName; } | ||
| 81 : | |||
| 82 : | // set the name of this instance | ||
| 83 : | void setName(const std::string &name) { mName = name; } | ||
| 84 : | |||
| 85 : | const LLUUID& getID() const { return mID; } | ||
| 86 : | |||
| 87 : | // returns the pose associated with the current state of this motion | ||
| 88 : | virtual LLPose* getPose() { return &mPose;} | ||
| 89 : | |||
| 90 : | void fadeOut(); | ||
| 91 : | |||
| 92 : | void fadeIn(); | ||
| 93 : | |||
| 94 : | F32 getFadeWeight() const { return mFadeWeight; } | ||
| 95 : | |||
| 96 : | F32 getStopTime() const { return mStopTimestamp; } | ||
| 97 : | |||
| 98 : | virtual void setStopTime(F32 time); | ||
| 99 : | |||
| 100 : | BOOL isStopped() const { return mStopped; } | ||
| 101 : | |||
| 102 : | void setStopped(BOOL stopped) { mStopped = stopped; } | ||
| 103 : | |||
| 104 : | BOOL isBlending(); | ||
| 105 : | |||
| 106 : | // Activation functions. | ||
| 107 : | // It is OK for other classes to activate a motion, | ||
| 108 : | // but only the controller can deactivate it. | ||
| 109 : | // Thus, if mActive == TRUE, the motion *may* be on the controllers active list, | ||
| 110 : | // but if mActive == FALSE, the motion is gauranteed not to be on the active list. | ||
| 111 : | protected: | ||
| 112 : | // Used by LLMotionController only | ||
| 113 : | void deactivate(); | ||
| 114 : | BOOL isActive() { return mActive; } | ||
| 115 : | public: | ||
| 116 : | void activate(F32 time); | ||
| 117 : | |||
| 118 : | public: | ||
| 119 : | //------------------------------------------------------------------------- | ||
| 120 : | // animation callbacks to be implemented by subclasses | ||
| 121 : | //------------------------------------------------------------------------- | ||
| 122 : | |||
| 123 : | // motions must specify whether or not they loop | ||
| 124 : | virtual BOOL getLoop() = 0; | ||
| 125 : | |||
| 126 : | // motions must report their total duration | ||
| 127 : | virtual F32 getDuration() = 0; | ||
| 128 : | |||
| 129 : | // motions must report their "ease in" duration | ||
| 130 : | virtual F32 getEaseInDuration() = 0; | ||
| 131 : | |||
| 132 : | // motions must report their "ease out" duration. | ||
| 133 : | virtual F32 getEaseOutDuration() = 0; | ||
| 134 : | |||
| 135 : | // motions must report their priority level | ||
| 136 : | virtual LLJoint::JointPriority getPriority() = 0; | ||
| 137 : | |||
| 138 : | // motions must report their blend type | ||
| 139 : | virtual LLMotionBlendType getBlendType() = 0; | ||
| 140 : | |||
| 141 : | // called to determine when a motion should be activated/deactivated based on avatar pixel coverage | ||
| 142 : | virtual F32 getMinPixelArea() = 0; | ||
| 143 : | |||
| 144 : | // run-time (post constructor) initialization, | ||
| 145 : | // called after parameters have been set | ||
| 146 : | // must return true to indicate success and be available for activation | ||
| 147 : | virtual LLMotionInitStatus onInitialize(LLCharacter *character) = 0; | ||
| 148 : | |||
| 149 : | // called per time step | ||
| 150 : | // must return TRUE while it is active, and | ||
| 151 : | // must return FALSE when the motion is completed. | ||
| 152 : | virtual BOOL onUpdate(F32 activeTime, U8* joint_mask) = 0; | ||
| 153 : | |||
| 154 : | // called when a motion is deactivated | ||
| 155 : | virtual void onDeactivate() = 0; | ||
| 156 : | |||
| 157 : | // can we crossfade this motion with a new instance when restarted? | ||
| 158 : | // should ultimately always be TRUE, but lack of emote blending, etc | ||
| 159 : | // requires this | ||
| 160 : | virtual BOOL canDeprecate(); | ||
| 161 : | |||
| 162 : | // optional callback routine called when animation deactivated. | ||
| 163 : | void setDeactivateCallback( void (*cb)(void *), void* userdata ); | ||
| 164 : | |||
| 165 : | protected: | ||
| 166 : | // called when a motion is activated | ||
| 167 : | // must return TRUE to indicate success, or else | ||
| 168 : | // it will be deactivated | ||
| 169 : | virtual BOOL onActivate() = 0; | ||
| 170 : | |||
| 171 : | void addJointState(const LLPointer<LLJointState>& jointState); | ||
| 172 : | |||
| 173 : | protected: | ||
| 174 : | LLPose mPose; | ||
| 175 : | BOOL mStopped; // motion has been stopped; | ||
| 176 : | BOOL mActive; // motion is on active list (can be stopped or not stopped) | ||
| 177 : | |||
| 178 : | //------------------------------------------------------------------------- | ||
| 179 : | // these are set implicitly by the motion controller and | ||
| 180 : | // may be referenced (read only) in the above handlers. | ||
| 181 : | //------------------------------------------------------------------------- | ||
| 182 : | std::string mName; // instance name assigned by motion controller | ||
| 183 : | LLUUID mID; | ||
| 184 : | |||
| 185 : | F32 mActivationTimestamp; // time when motion was activated | ||
| 186 : | F32 mStopTimestamp; // time when motion was told to stop | ||
| 187 : | F32 mSendStopTimestamp; // time when simulator should be told to stop this motion | ||
| 188 : | F32 mResidualWeight; // blend weight at beginning of stop motion phase | ||
| 189 : | F32 mFadeWeight; // for fading in and out based on LOD | ||
| 190 : | U8 mJointSignature[3][LL_CHARACTER_MAX_JOINTS]; // signature of which joints are animated at what priority | ||
| 191 : | void (*mDeactivateCallback)(void* data); | ||
| 192 : | void* mDeactivateCallbackUserData; | ||
| 193 : | }; | ||
| 194 : | |||
| 195 : | |||
| 196 : | //----------------------------------------------------------------------------- | ||
| 197 : | // LLTestMotion | ||
| 198 : | //----------------------------------------------------------------------------- | ||
| 199 : | class LLTestMotion : public LLMotion | ||
| 200 : | { | ||
| 201 : | public: | ||
| 202 : | LLTestMotion(const LLUUID &id) : LLMotion(id){} | ||
| 203 : | ~LLTestMotion() {} | ||
| 204 : | static LLMotion *create(const LLUUID& id) { return new LLTestMotion(id); } | ||
| 205 : | BOOL getLoop() { return FALSE; } | ||
| 206 : | F32 getDuration() { return 0.0f; } | ||
| 207 : | F32 getEaseInDuration() { return 0.0f; } | ||
| 208 : | F32 getEaseOutDuration() { return 0.0f; } | ||
| 209 : | LLJoint::JointPriority getPriority() { return LLJoint::HIGH_PRIORITY; } | ||
| 210 : | LLMotionBlendType getBlendType() { return NORMAL_BLEND; } | ||
| 211 : | F32 getMinPixelArea() { return 0.f; } | ||
| 212 : | |||
| 213 : | LLMotionInitStatus onInitialize(LLCharacter*) { llinfos << "LLTestMotion::onInitialize()" << llendl; return STATUS_SUCCESS; } | ||
| 214 : | BOOL onActivate() { llinfos << "LLTestMotion::onActivate()" << llendl; return TRUE; } | ||
| 215 : | BOOL onUpdate(F32 time, U8* joint_mask) { llinfos << "LLTestMotion::onUpdate(" << time << ")" << llendl; return TRUE; } | ||
| 216 : | void onDeactivate() { llinfos << "LLTestMotion::onDeactivate()" << llendl; } | ||
| 217 : | }; | ||
| 218 : | |||
| 219 : | |||
| 220 : | //----------------------------------------------------------------------------- | ||
| 221 : | // LLNullMotion | ||
| 222 : | //----------------------------------------------------------------------------- | ||
| 223 : | class LLNullMotion : public LLMotion | ||
| 224 : | { | ||
| 225 : | public: | ||
| 226 : | LLNullMotion(const LLUUID &id) : LLMotion(id) {} | ||
| 227 : | ~LLNullMotion() {} | ||
| 228 : | static LLMotion *create(const LLUUID &id) { return new LLNullMotion(id); } | ||
| 229 : | |||
| 230 : | // motions must specify whether or not they loop | ||
| 231 : | /*virtual*/ BOOL getLoop() { return TRUE; } | ||
| 232 : | |||
| 233 : | // motions must report their total duration | ||
| 234 : | /*virtual*/ F32 getDuration() { return 1.f; } | ||
| 235 : | |||
| 236 : | // motions must report their "ease in" duration | ||
| 237 : | /*virtual*/ F32 getEaseInDuration() { return 0.f; } | ||
| 238 : | |||
| 239 : | // motions must report their "ease out" duration. | ||
| 240 : | /*virtual*/ F32 getEaseOutDuration() { return 0.f; } | ||
| 241 : | |||
| 242 : | // motions must report their priority level | ||
| 243 : | /*virtual*/ LLJoint::JointPriority getPriority() { return LLJoint::HIGH_PRIORITY; } | ||
| 244 : | |||
| 245 : | // motions must report their blend type | ||
| 246 : | /*virtual*/ LLMotionBlendType getBlendType() { return NORMAL_BLEND; } | ||
| 247 : | |||
| 248 : | // called to determine when a motion should be activated/deactivated based on avatar pixel coverage | ||
| 249 : | /*virtual*/ F32 getMinPixelArea() { return 0.f; } | ||
| 250 : | |||
| 251 : | // run-time (post constructor) initialization, | ||
| 252 : | // called after parameters have been set | ||
| 253 : | // must return true to indicate success and be available for activation | ||
| 254 : | /*virtual*/ LLMotionInitStatus onInitialize(LLCharacter *character) { return STATUS_SUCCESS; } | ||
| 255 : | |||
| 256 : | // called when a motion is activated | ||
| 257 : | // must return TRUE to indicate success, or else | ||
| 258 : | // it will be deactivated | ||
| 259 : | /*virtual*/ BOOL onActivate() { return TRUE; } | ||
| 260 : | |||
| 261 : | // called per time step | ||
| 262 : | // must return TRUE while it is active, and | ||
| 263 : | // must return FALSE when the motion is completed. | ||
| 264 : | /*virtual*/ BOOL onUpdate(F32 activeTime, U8* joint_mask) { return TRUE; } | ||
| 265 : | |||
| 266 : | // called when a motion is deactivated | ||
| 267 : | /*virtual*/ void onDeactivate() {} | ||
| 268 : | }; | ||
| 269 : | #endif // LL_LLMOTION_H | ||
| 270 : |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

