summaryrefslogtreecommitdiff
path: root/indra/llcharacter
diff options
context:
space:
mode:
authorSteven Bennetts <steve@lindenlab.com>2007-12-07 20:27:13 +0000
committerSteven Bennetts <steve@lindenlab.com>2007-12-07 20:27:13 +0000
commitb01d567a5d9e2b5dd28bcc7b3f474fabd93e7a2f (patch)
treec45377783f53f033d43a4d06d36bbeb2a7f7e79b /indra/llcharacter
parenta64f283477ea4db09c8b515ab94709e1fb5c82af (diff)
EFFECTIVE MERGE: merge release@73232 maint-viewer-2@75100 -> maint-viewer-2-merge
EFFECTIVE MERGE: merge -r 74370 library-update -> maint-viewer-2-merge ACTUAL MERGE: release@75267 maint-viewer-2-merge@75293 -> release
Diffstat (limited to 'indra/llcharacter')
-rw-r--r--indra/llcharacter/lleditingmotion.cpp84
-rw-r--r--indra/llcharacter/lleditingmotion.h10
-rw-r--r--indra/llcharacter/llheadrotmotion.cpp69
-rw-r--r--indra/llcharacter/llheadrotmotion.h10
-rw-r--r--indra/llcharacter/lljoint.h4
-rw-r--r--indra/llcharacter/lljointstate.h36
-rw-r--r--indra/llcharacter/llkeyframefallmotion.cpp15
-rw-r--r--indra/llcharacter/llkeyframefallmotion.h2
-rw-r--r--indra/llcharacter/llkeyframemotion.cpp232
-rw-r--r--indra/llcharacter/llkeyframemotion.h14
-rw-r--r--indra/llcharacter/llkeyframemotionparam.cpp1
-rw-r--r--indra/llcharacter/llkeyframemotionparam.h1
-rw-r--r--indra/llcharacter/llkeyframestandmotion.h14
-rw-r--r--indra/llcharacter/llkeyframewalkmotion.cpp43
-rw-r--r--indra/llcharacter/llkeyframewalkmotion.h6
-rw-r--r--indra/llcharacter/llmotion.cpp2
-rw-r--r--indra/llcharacter/llmotion.h2
-rw-r--r--indra/llcharacter/llpose.cpp16
-rw-r--r--indra/llcharacter/llpose.h18
-rw-r--r--indra/llcharacter/lltargetingmotion.cpp14
-rw-r--r--indra/llcharacter/lltargetingmotion.h2
21 files changed, 329 insertions, 266 deletions
diff --git a/indra/llcharacter/lleditingmotion.cpp b/indra/llcharacter/lleditingmotion.cpp
index 6e878429fa..34fb6c423a 100644
--- a/indra/llcharacter/lleditingmotion.cpp
+++ b/indra/llcharacter/lleditingmotion.cpp
@@ -64,6 +64,12 @@ LLEditingMotion::LLEditingMotion( const LLUUID &id) : LLMotion(id)
mElbowJoint.addChild( &mWristJoint );
mName = "editing";
+
+ mParentState = new LLJointState;
+ mShoulderState = new LLJointState;
+ mElbowState = new LLJointState;
+ mWristState = new LLJointState;
+ mTorsoState = new LLJointState;
}
@@ -93,13 +99,13 @@ LLMotion::LLMotionInitStatus LLEditingMotion::onInitialize(LLCharacter *characte
}
// get the shoulder, elbow, wrist joints from the character
- mParentState.setJoint( mCharacter->getJoint("mShoulderLeft")->getParent() );
- mShoulderState.setJoint( mCharacter->getJoint("mShoulderLeft") );
- mElbowState.setJoint( mCharacter->getJoint("mElbowLeft") );
- mWristState.setJoint( mCharacter->getJoint("mWristLeft") );
- mTorsoState.setJoint( mCharacter->getJoint("mTorso"));
+ mParentState->setJoint( mCharacter->getJoint("mShoulderLeft")->getParent() );
+ mShoulderState->setJoint( mCharacter->getJoint("mShoulderLeft") );
+ mElbowState->setJoint( mCharacter->getJoint("mElbowLeft") );
+ mWristState->setJoint( mCharacter->getJoint("mWristLeft") );
+ mTorsoState->setJoint( mCharacter->getJoint("mTorso"));
- if ( ! mParentState.getJoint() )
+ if ( ! mParentState->getJoint() )
{
llinfos << getName() << ": Can't get parent joint." << llendl;
return STATUS_FAILURE;
@@ -108,25 +114,25 @@ LLMotion::LLMotionInitStatus LLEditingMotion::onInitialize(LLCharacter *characte
mWristOffset = LLVector3(0.0f, 0.2f, 0.0f);
// add joint states to the pose
- mShoulderState.setUsage(LLJointState::ROT);
- mElbowState.setUsage(LLJointState::ROT);
- mTorsoState.setUsage(LLJointState::ROT);
- mWristState.setUsage(LLJointState::ROT);
- addJointState( &mShoulderState );
- addJointState( &mElbowState );
- addJointState( &mTorsoState );
- addJointState( &mWristState );
+ mShoulderState->setUsage(LLJointState::ROT);
+ mElbowState->setUsage(LLJointState::ROT);
+ mTorsoState->setUsage(LLJointState::ROT);
+ mWristState->setUsage(LLJointState::ROT);
+ addJointState( mShoulderState );
+ addJointState( mElbowState );
+ addJointState( mTorsoState );
+ addJointState( mWristState );
// propagate joint positions to kinematic chain
- mParentJoint.setPosition( mParentState.getJoint()->getWorldPosition() );
- mShoulderJoint.setPosition( mShoulderState.getJoint()->getPosition() );
- mElbowJoint.setPosition( mElbowState.getJoint()->getPosition() );
- mWristJoint.setPosition( mWristState.getJoint()->getPosition() + mWristOffset );
+ mParentJoint.setPosition( mParentState->getJoint()->getWorldPosition() );
+ mShoulderJoint.setPosition( mShoulderState->getJoint()->getPosition() );
+ mElbowJoint.setPosition( mElbowState->getJoint()->getPosition() );
+ mWristJoint.setPosition( mWristState->getJoint()->getPosition() + mWristOffset );
// propagate current joint rotations to kinematic chain
- mParentJoint.setRotation( mParentState.getJoint()->getWorldRotation() );
- mShoulderJoint.setRotation( mShoulderState.getJoint()->getRotation() );
- mElbowJoint.setRotation( mElbowState.getJoint()->getRotation() );
+ mParentJoint.setRotation( mParentState->getJoint()->getWorldRotation() );
+ mShoulderJoint.setRotation( mShoulderState->getJoint()->getRotation() );
+ mElbowJoint.setRotation( mElbowState->getJoint()->getRotation() );
// connect the ikSolver to the chain
mIKSolver.setPoleVector( LLVector3( -1.0f, 1.0f, 0.0f ) );
@@ -144,15 +150,15 @@ LLMotion::LLMotionInitStatus LLEditingMotion::onInitialize(LLCharacter *characte
BOOL LLEditingMotion::onActivate()
{
// propagate joint positions to kinematic chain
- mParentJoint.setPosition( mParentState.getJoint()->getWorldPosition() );
- mShoulderJoint.setPosition( mShoulderState.getJoint()->getPosition() );
- mElbowJoint.setPosition( mElbowState.getJoint()->getPosition() );
- mWristJoint.setPosition( mWristState.getJoint()->getPosition() + mWristOffset );
+ mParentJoint.setPosition( mParentState->getJoint()->getWorldPosition() );
+ mShoulderJoint.setPosition( mShoulderState->getJoint()->getPosition() );
+ mElbowJoint.setPosition( mElbowState->getJoint()->getPosition() );
+ mWristJoint.setPosition( mWristState->getJoint()->getPosition() + mWristOffset );
// propagate current joint rotations to kinematic chain
- mParentJoint.setRotation( mParentState.getJoint()->getWorldRotation() );
- mShoulderJoint.setRotation( mShoulderState.getJoint()->getRotation() );
- mElbowJoint.setRotation( mElbowState.getJoint()->getRotation() );
+ mParentJoint.setRotation( mParentState->getJoint()->getWorldRotation() );
+ mShoulderJoint.setRotation( mShoulderState->getJoint()->getRotation() );
+ mElbowJoint.setRotation( mElbowState->getJoint()->getRotation() );
return TRUE;
}
@@ -182,15 +188,15 @@ BOOL LLEditingMotion::onUpdate(F32 time, U8* joint_mask)
focus_pt += mCharacter->getCharacterPosition();
// propagate joint positions to kinematic chain
- mParentJoint.setPosition( mParentState.getJoint()->getWorldPosition() );
- mShoulderJoint.setPosition( mShoulderState.getJoint()->getPosition() );
- mElbowJoint.setPosition( mElbowState.getJoint()->getPosition() );
- mWristJoint.setPosition( mWristState.getJoint()->getPosition() + mWristOffset );
+ mParentJoint.setPosition( mParentState->getJoint()->getWorldPosition() );
+ mShoulderJoint.setPosition( mShoulderState->getJoint()->getPosition() );
+ mElbowJoint.setPosition( mElbowState->getJoint()->getPosition() );
+ mWristJoint.setPosition( mWristState->getJoint()->getPosition() + mWristOffset );
// propagate current joint rotations to kinematic chain
- mParentJoint.setRotation( mParentState.getJoint()->getWorldRotation() );
- mShoulderJoint.setRotation( mShoulderState.getJoint()->getRotation() );
- mElbowJoint.setRotation( mElbowState.getJoint()->getRotation() );
+ mParentJoint.setRotation( mParentState->getJoint()->getWorldRotation() );
+ mShoulderJoint.setRotation( mShoulderState->getJoint()->getRotation() );
+ mElbowJoint.setRotation( mElbowState->getJoint()->getRotation() );
// update target position from character
LLVector3 target = focus_pt - mParentJoint.getPosition();
@@ -199,7 +205,7 @@ BOOL LLEditingMotion::onUpdate(F32 time, U8* joint_mask)
LLVector3 edit_plane_normal(1.f / F_SQRT2, 1.f / F_SQRT2, 0.f);
edit_plane_normal.normVec();
- edit_plane_normal.rotVec(mTorsoState.getJoint()->getWorldRotation());
+ edit_plane_normal.rotVec(mTorsoState->getJoint()->getWorldRotation());
F32 dot = edit_plane_normal * target;
@@ -236,9 +242,9 @@ BOOL LLEditingMotion::onUpdate(F32 time, U8* joint_mask)
// now put blended values back into joints
llassert(shoulderRot.isFinite());
llassert(elbowRot.isFinite());
- mShoulderState.setRotation(shoulderRot);
- mElbowState.setRotation(elbowRot);
- mWristState.setRotation(LLQuaternion::DEFAULT);
+ mShoulderState->setRotation(shoulderRot);
+ mElbowState->setRotation(elbowRot);
+ mWristState->setRotation(LLQuaternion::DEFAULT);
}
mCharacter->setAnimationData("Hand Pose", &sHandPose);
diff --git a/indra/llcharacter/lleditingmotion.h b/indra/llcharacter/lleditingmotion.h
index 18bfd7f88a..60ec4a34d9 100644
--- a/indra/llcharacter/lleditingmotion.h
+++ b/indra/llcharacter/lleditingmotion.h
@@ -116,11 +116,11 @@ public:
LLCharacter *mCharacter;
LLVector3 mWristOffset;
- LLJointState mParentState;
- LLJointState mShoulderState;
- LLJointState mElbowState;
- LLJointState mWristState;
- LLJointState mTorsoState;
+ LLPointer<LLJointState> mParentState;
+ LLPointer<LLJointState> mShoulderState;
+ LLPointer<LLJointState> mElbowState;
+ LLPointer<LLJointState> mWristState;
+ LLPointer<LLJointState> mTorsoState;
LLJoint mParentJoint;
LLJoint mShoulderJoint;
diff --git a/indra/llcharacter/llheadrotmotion.cpp b/indra/llcharacter/llheadrotmotion.cpp
index 55af269376..7e25cc457e 100644
--- a/indra/llcharacter/llheadrotmotion.cpp
+++ b/indra/llcharacter/llheadrotmotion.cpp
@@ -82,6 +82,10 @@ LLHeadRotMotion::LLHeadRotMotion(const LLUUID &id) :
mHeadJoint(NULL)
{
mName = "head_rot";
+
+ mTorsoState = new LLJointState;
+ mNeckState = new LLJointState;
+ mHeadState = new LLJointState;
}
@@ -130,34 +134,34 @@ LLMotion::LLMotionInitStatus LLHeadRotMotion::onInitialize(LLCharacter *characte
return STATUS_FAILURE;
}
- mTorsoState.setJoint( character->getJoint("mTorso") );
- if ( ! mTorsoState.getJoint() )
+ mTorsoState->setJoint( character->getJoint("mTorso") );
+ if ( ! mTorsoState->getJoint() )
{
llinfos << getName() << ": Can't get torso joint." << llendl;
return STATUS_FAILURE;
}
- mNeckState.setJoint( character->getJoint("mNeck") );
- if ( ! mNeckState.getJoint() )
+ mNeckState->setJoint( character->getJoint("mNeck") );
+ if ( ! mNeckState->getJoint() )
{
llinfos << getName() << ": Can't get neck joint." << llendl;
return STATUS_FAILURE;
}
- mHeadState.setJoint( character->getJoint("mHead") );
- if ( ! mHeadState.getJoint() )
+ mHeadState->setJoint( character->getJoint("mHead") );
+ if ( ! mHeadState->getJoint() )
{
llinfos << getName() << ": Can't get head joint." << llendl;
return STATUS_FAILURE;
}
- mTorsoState.setUsage(LLJointState::ROT);
- mNeckState.setUsage(LLJointState::ROT);
- mHeadState.setUsage(LLJointState::ROT);
+ mTorsoState->setUsage(LLJointState::ROT);
+ mNeckState->setUsage(LLJointState::ROT);
+ mHeadState->setUsage(LLJointState::ROT);
- addJointState( &mTorsoState );
- addJointState( &mNeckState );
- addJointState( &mHeadState );
+ addJointState( mTorsoState );
+ addJointState( mNeckState );
+ addJointState( mHeadState );
mLastHeadRot.loadIdentity();
@@ -240,16 +244,16 @@ BOOL LLHeadRotMotion::onUpdate(F32 time, U8* joint_mask)
// Set torso target rotation such that it lags behind the head rotation
// by a fixed amount.
LLQuaternion torso_rot_local = nlerp(TORSO_LAG, LLQuaternion::DEFAULT, head_rot_local );
- mTorsoState.setRotation( nlerp(torso_slerp_amt, mTorsoState.getRotation(), torso_rot_local) );
+ mTorsoState->setRotation( nlerp(torso_slerp_amt, mTorsoState->getRotation(), torso_rot_local) );
head_rot_local = nlerp(head_slerp_amt, mLastHeadRot, head_rot_local);
mLastHeadRot = head_rot_local;
// Set the head rotation.
- LLQuaternion torsoRotLocal = mNeckState.getJoint()->getParent()->getWorldRotation() * currentInvRootRotWorld;
+ LLQuaternion torsoRotLocal = mNeckState->getJoint()->getParent()->getWorldRotation() * currentInvRootRotWorld;
head_rot_local = head_rot_local * ~torsoRotLocal;
- mNeckState.setRotation( nlerp(NECK_LAG, LLQuaternion::DEFAULT, head_rot_local) );
- mHeadState.setRotation( nlerp(1.f - NECK_LAG, LLQuaternion::DEFAULT, head_rot_local));
+ mNeckState->setRotation( nlerp(NECK_LAG, LLQuaternion::DEFAULT, head_rot_local) );
+ mHeadState->setRotation( nlerp(1.f - NECK_LAG, LLQuaternion::DEFAULT, head_rot_local));
return TRUE;
}
@@ -284,6 +288,9 @@ LLEyeMotion::LLEyeMotion(const LLUUID &id) : LLMotion(id)
mHeadJoint = NULL;
mName = "eye_rot";
+
+ mLeftEyeState = new LLJointState;
+ mRightEyeState = new LLJointState;
}
@@ -309,25 +316,25 @@ LLMotion::LLMotionInitStatus LLEyeMotion::onInitialize(LLCharacter *character)
return STATUS_FAILURE;
}
- mLeftEyeState.setJoint( character->getJoint("mEyeLeft") );
- if ( ! mLeftEyeState.getJoint() )
+ mLeftEyeState->setJoint( character->getJoint("mEyeLeft") );
+ if ( ! mLeftEyeState->getJoint() )
{
llinfos << getName() << ": Can't get left eyeball joint." << llendl;
return STATUS_FAILURE;
}
- mRightEyeState.setJoint( character->getJoint("mEyeRight") );
- if ( ! mRightEyeState.getJoint() )
+ mRightEyeState->setJoint( character->getJoint("mEyeRight") );
+ if ( ! mRightEyeState->getJoint() )
{
llinfos << getName() << ": Can't get Right eyeball joint." << llendl;
return STATUS_FAILURE;
}
- mLeftEyeState.setUsage(LLJointState::ROT);
- mRightEyeState.setUsage(LLJointState::ROT);
+ mLeftEyeState->setUsage(LLJointState::ROT);
+ mRightEyeState->setUsage(LLJointState::ROT);
- addJointState( &mLeftEyeState );
- addJointState( &mRightEyeState );
+ addJointState( mLeftEyeState );
+ addJointState( mRightEyeState );
return STATUS_SUCCESS;
}
@@ -443,11 +450,15 @@ BOOL LLEyeMotion::onUpdate(F32 time, U8* joint_mask)
target_eye_rot = LLQuaternion(eye_look_at, left, up);
// convert target rotation to head-local coordinates
target_eye_rot *= ~mHeadJoint->getWorldRotation();
+ // eliminate any Euler roll - we're lucky that roll is applied last.
+ F32 roll, pitch, yaw;
+ target_eye_rot.getEulerAngles(&roll, &pitch, &yaw);
+ target_eye_rot.setQuat(0.0f, pitch, yaw);
// constrain target orientation to be in front of avatar's face
target_eye_rot.constrain(EYE_ROT_LIMIT_ANGLE);
// calculate vergence
- F32 interocular_dist = (mLeftEyeState.getJoint()->getWorldPosition() - mRightEyeState.getJoint()->getWorldPosition()).magVec();
+ F32 interocular_dist = (mLeftEyeState->getJoint()->getWorldPosition() - mRightEyeState->getJoint()->getWorldPosition()).magVec();
vergence = -atan2((interocular_dist / 2.f), lookAtDistance);
llclamp(vergence, -F_PI_BY_TWO, 0.f);
}
@@ -495,8 +506,8 @@ BOOL LLEyeMotion::onUpdate(F32 time, U8* joint_mask)
vergence_quat.transQuat();
right_eye_rot = vergence_quat * eye_jitter_rot * right_eye_rot;
- mLeftEyeState.setRotation( left_eye_rot );
- mRightEyeState.setRotation( right_eye_rot );
+ mLeftEyeState->setRotation( left_eye_rot );
+ mRightEyeState->setRotation( right_eye_rot );
return TRUE;
}
@@ -507,13 +518,13 @@ BOOL LLEyeMotion::onUpdate(F32 time, U8* joint_mask)
//-----------------------------------------------------------------------------
void LLEyeMotion::onDeactivate()
{
- LLJoint* joint = mLeftEyeState.getJoint();
+ LLJoint* joint = mLeftEyeState->getJoint();
if (joint)
{
joint->setRotation(LLQuaternion::DEFAULT);
}
- joint = mRightEyeState.getJoint();
+ joint = mRightEyeState->getJoint();
if (joint)
{
joint->setRotation(LLQuaternion::DEFAULT);
diff --git a/indra/llcharacter/llheadrotmotion.h b/indra/llcharacter/llheadrotmotion.h
index efb9c3e0be..57c4db5dad 100644
--- a/indra/llcharacter/llheadrotmotion.h
+++ b/indra/llcharacter/llheadrotmotion.h
@@ -117,9 +117,9 @@ public:
LLJoint *mRootJoint;
LLJoint *mPelvisJoint;
- LLJointState mTorsoState;
- LLJointState mNeckState;
- LLJointState mHeadState;
+ LLPointer<LLJointState> mTorsoState;
+ LLPointer<LLJointState> mNeckState;
+ LLPointer<LLJointState> mHeadState;
LLQuaternion mLastHeadRot;
};
@@ -196,8 +196,8 @@ public:
LLCharacter *mCharacter;
LLJoint *mHeadJoint;
- LLJointState mLeftEyeState;
- LLJointState mRightEyeState;
+ LLPointer<LLJointState> mLeftEyeState;
+ LLPointer<LLJointState> mRightEyeState;
LLFrameTimer mEyeJitterTimer;
F32 mEyeJitterTime;
diff --git a/indra/llcharacter/lljoint.h b/indra/llcharacter/lljoint.h
index 167598fc70..8ca8118e4c 100644
--- a/indra/llcharacter/lljoint.h
+++ b/indra/llcharacter/lljoint.h
@@ -115,7 +115,7 @@ public:
void touch(U32 flags = ALL_DIRTY);
// get/set name
- const std::string &getName() { return mName; }
+ const std::string& getName() const { return mName; }
void setName( const std::string &name ) { mName = name; }
// getParent
@@ -175,7 +175,7 @@ public:
virtual BOOL isAnimatable() { return TRUE; }
- S32 getJointNum() { return mJointNum; }
+ S32 getJointNum() const { return mJointNum; }
void setJointNum(S32 joint_num) { mJointNum = joint_num; }
};
#endif // LL_LLJOINT_H
diff --git a/indra/llcharacter/lljointstate.h b/indra/llcharacter/lljointstate.h
index 202232243b..a1723b6dd9 100644
--- a/indra/llcharacter/lljointstate.h
+++ b/indra/llcharacter/lljointstate.h
@@ -36,11 +36,12 @@
// Header Files
//-----------------------------------------------------------------------------
#include "lljoint.h"
+#include "llmemory.h"
//-----------------------------------------------------------------------------
// class LLJointState
//-----------------------------------------------------------------------------
-class LLJointState
+class LLJointState : public LLRefCount
{
public:
enum BlendPhase
@@ -85,13 +86,9 @@ public:
mPriority = LLJoint::USE_MOTION_PRIORITY;
}
- // Destructor
- virtual ~LLJointState()
- {
- }
-
// joint that this state is applied to
- LLJoint *getJoint() { return mJoint; }
+ LLJoint* getJoint() { return mJoint; }
+ const LLJoint* getJoint() const { return mJoint; }
BOOL setJoint( LLJoint *joint ) { mJoint = joint; return mJoint != NULL; }
// transform type (bitwise flags can be combined)
@@ -103,26 +100,33 @@ public:
ROT = 2,
SCALE = 4,
};
- U32 getUsage() { return mUsage; }
- void setUsage( U32 usage ) { mUsage = usage; }
- F32 getWeight() { return mWeight; }
+ U32 getUsage() const { return mUsage; }
+ void setUsage( U32 usage ) { mUsage = usage; }
+ F32 getWeight() const { return mWeight; }
void setWeight( F32 weight ) { mWeight = weight; }
// get/set position
- const LLVector3& getPosition() { return mPosition; }
+ const LLVector3& getPosition() const { return mPosition; }
void setPosition( const LLVector3& pos ) { llassert(mUsage & POS); mPosition = pos; }
// get/set rotation
- const LLQuaternion& getRotation() { return mRotation; }
+ const LLQuaternion& getRotation() const { return mRotation; }
void setRotation( const LLQuaternion& rot ) { llassert(mUsage & ROT); mRotation = rot; }
// get/set scale
- const LLVector3& getScale() { return mScale; }
- void setScale( const LLVector3& scale ) { llassert(mUsage & SCALE); mScale = scale; }
+ const LLVector3& getScale() const { return mScale; }
+ void setScale( const LLVector3& scale ) { llassert(mUsage & SCALE); mScale = scale; }
// get/set priority
- LLJoint::JointPriority getPriority() { return mPriority; }
- void setPriority( const LLJoint::JointPriority priority ) { mPriority = priority; }
+ LLJoint::JointPriority getPriority() const { return mPriority; }
+ void setPriority( LLJoint::JointPriority priority ) { mPriority = priority; }
+
+private:
+ // Destructor
+ virtual ~LLJointState()
+ {
+ }
+
};
#endif // LL_LLJOINTSTATE_H
diff --git a/indra/llcharacter/llkeyframefallmotion.cpp b/indra/llcharacter/llkeyframefallmotion.cpp
index bcef7a3fda..13308f4e4a 100644
--- a/indra/llcharacter/llkeyframefallmotion.cpp
+++ b/indra/llcharacter/llkeyframefallmotion.cpp
@@ -75,13 +75,13 @@ LLMotion::LLMotionInitStatus LLKeyframeFallMotion::onInitialize(LLCharacter *cha
// load keyframe data, setup pose and joint states
LLMotion::LLMotionInitStatus result = LLKeyframeMotion::onInitialize(character);
- for (U32 jm=0; jm<mJointMotionList->mNumJointMotions; jm++)
+ for (U32 jm=0; jm<mJointMotionList->getNumJointMotions(); jm++)
{
- if (!mJointStates[jm].getJoint())
+ if (!mJointStates[jm]->getJoint())
continue;
- if (mJointStates[jm].getJoint()->getName() == std::string("mPelvis"))
+ if (mJointStates[jm]->getJoint()->getName() == std::string("mPelvis"))
{
- mPelvisStatep = &mJointStates[jm];
+ mPelvisState = mJointStates[jm];
}
}
@@ -124,8 +124,11 @@ BOOL LLKeyframeFallMotion::onUpdate(F32 activeTime, U8* joint_mask)
BOOL result = LLKeyframeMotion::onUpdate(activeTime, joint_mask);
F32 slerp_amt = clamp_rescale(activeTime / getDuration(), 0.5f, 0.75f, 0.f, 1.f);
- mPelvisStatep->setRotation(mPelvisStatep->getRotation() * slerp(slerp_amt, mRotationToGroundNormal, LLQuaternion()));
-
+ if (mPelvisState.notNull())
+ {
+ mPelvisState->setRotation(mPelvisState->getRotation() * slerp(slerp_amt, mRotationToGroundNormal, LLQuaternion()));
+ }
+
return result;
}
diff --git a/indra/llcharacter/llkeyframefallmotion.h b/indra/llcharacter/llkeyframefallmotion.h
index 4307c51130..618a169324 100644
--- a/indra/llcharacter/llkeyframefallmotion.h
+++ b/indra/llcharacter/llkeyframefallmotion.h
@@ -75,7 +75,7 @@ protected:
//-------------------------------------------------------------------------
LLCharacter* mCharacter;
F32 mVelocityZ;
- LLJointState* mPelvisStatep;
+ LLPointer<LLJointState> mPelvisState;
LLQuaternion mRotationToGroundNormal;
};
diff --git a/indra/llcharacter/llkeyframemotion.cpp b/indra/llcharacter/llkeyframemotion.cpp
index 6efe243a8f..44a2425b1b 100644
--- a/indra/llcharacter/llkeyframemotion.cpp
+++ b/indra/llcharacter/llkeyframemotion.cpp
@@ -71,24 +71,22 @@ static F32 MAX_CONSTRAINTS = 10;
// JointMotionList
//-----------------------------------------------------------------------------
LLKeyframeMotion::JointMotionList::JointMotionList()
- : mNumJointMotions(0),
- mJointMotionArray(NULL)
{
}
LLKeyframeMotion::JointMotionList::~JointMotionList()
{
for_each(mConstraints.begin(), mConstraints.end(), DeletePointer());
- delete [] mJointMotionArray;
+ for_each(mJointMotionArray.begin(), mJointMotionArray.end(), DeletePointer());
}
U32 LLKeyframeMotion::JointMotionList::dumpDiagInfo()
{
S32 total_size = sizeof(JointMotionList);
- for (U32 i = 0; i < mNumJointMotions; i++)
+ for (U32 i = 0; i < getNumJointMotions(); i++)
{
- LLKeyframeMotion::JointMotion* joint_motion_p = &mJointMotionArray[i];
+ LLKeyframeMotion::JointMotion* joint_motion_p = mJointMotionArray[i];
llinfos << "\tJoint " << joint_motion_p->mJointName << llendl;
if (joint_motion_p->mUsage & LLJointState::SCALE)
@@ -385,10 +383,10 @@ void LLKeyframeMotion::JointMotion::update(LLJointState* joint_state, F32 time,
{
// this value being 0 is the cause of https://jira.lindenlab.com/browse/SL-22678 but I haven't
// managed to get a stack to see how it got here. Testing for 0 here will stop the crash.
- if ( joint_state == 0 )
+ if ( joint_state == NULL )
{
return;
- };
+ }
U32 usage = joint_state->getUsage();
@@ -431,7 +429,6 @@ void LLKeyframeMotion::JointMotion::update(LLJointState* joint_state, F32 time,
LLKeyframeMotion::LLKeyframeMotion(const LLUUID &id)
: LLMotion(id),
mJointMotionList(NULL),
- mJointStates(NULL),
mPelvisp(NULL),
mLastSkeletonSerialNum(0),
mLastUpdateTime(0.f),
@@ -448,10 +445,6 @@ LLKeyframeMotion::LLKeyframeMotion(const LLUUID &id)
//-----------------------------------------------------------------------------
LLKeyframeMotion::~LLKeyframeMotion()
{
- if (mJointStates)
- {
- delete [] mJointStates;
- }
for_each(mConstraints.begin(), mConstraints.end(), DeletePointer());
}
@@ -464,6 +457,26 @@ LLMotion *LLKeyframeMotion::create(const LLUUID &id)
}
//-----------------------------------------------------------------------------
+// getJointState()
+//-----------------------------------------------------------------------------
+LLPointer<LLJointState>& LLKeyframeMotion::getJointState(U32 index)
+{
+ llassert_always (index < (S32)mJointStates.size());
+ return mJointStates[index];
+}
+
+//-----------------------------------------------------------------------------
+// getJoin()
+//-----------------------------------------------------------------------------
+LLJoint* LLKeyframeMotion::getJoint(U32 index)
+{
+ llassert_always (index < (S32)mJointStates.size());
+ LLJoint* joint = mJointStates[index]->getJoint();
+ llassert_always (joint);
+ return joint;
+}
+
+//-----------------------------------------------------------------------------
// LLKeyframeMotion::onInitialize(LLCharacter *character)
//-----------------------------------------------------------------------------
LLMotion::LLMotionInitStatus LLKeyframeMotion::onInitialize(LLCharacter *character)
@@ -506,17 +519,20 @@ LLMotion::LLMotionInitStatus LLKeyframeMotion::onInitialize(LLCharacter *charact
// motion already existed in cache, so grab it
mJointMotionList = joint_motion_list;
+ mJointStates.reserve(mJointMotionList->getNumJointMotions());
+
// don't forget to allocate joint states
- mJointStates = new LLJointState[mJointMotionList->mNumJointMotions];
-
// set up joint states to point to character joints
- for(U32 i = 0; i < mJointMotionList->mNumJointMotions; i++)
+ for(U32 i = 0; i < mJointMotionList->getNumJointMotions(); i++)
{
- if (LLJoint *jointp = mCharacter->getJoint(mJointMotionList->mJointMotionArray[i].mJointName))
+ JointMotion* joint_motion = mJointMotionList->getJointMotion(i);
+ if (LLJoint *joint = mCharacter->getJoint(joint_motion->mJointName))
{
- mJointStates[i].setJoint(jointp);
- mJointStates[i].setUsage(mJointMotionList->mJointMotionArray[i].mUsage);
- mJointStates[i].setPriority(joint_motion_list->mJointMotionArray[i].mPriority);
+ LLPointer<LLJointState> joint_state = new LLJointState;
+ mJointStates.push_back(joint_state);
+ joint_state->setJoint(joint);
+ joint_state->setUsage(joint_motion->mUsage);
+ joint_state->setPriority(joint_motion->mPriority);
}
}
mAssetStatus = ASSET_LOADED;
@@ -587,11 +603,12 @@ LLMotion::LLMotionInitStatus LLKeyframeMotion::onInitialize(LLCharacter *charact
BOOL LLKeyframeMotion::setupPose()
{
// add all valid joint states to the pose
- for (U32 jm=0; jm<mJointMotionList->mNumJointMotions; jm++)
+ for (U32 jm=0; jm<mJointMotionList->getNumJointMotions(); jm++)
{
- if ( mJointStates[jm].getJoint() )
+ LLPointer<LLJointState> joint_state = getJointState(jm);
+ if ( joint_state->getJoint() )
{
- addJointState( &mJointStates[jm] );
+ addJointState( joint_state );
}
}
@@ -692,13 +709,12 @@ BOOL LLKeyframeMotion::onUpdate(F32 time, U8* joint_mask)
//-----------------------------------------------------------------------------
void LLKeyframeMotion::applyKeyframes(F32 time)
{
- U32 i;
- for (i=0; i<mJointMotionList->mNumJointMotions; i++)
+ llassert_always (mJointMotionList->getNumJointMotions() <= mJointStates.size());
+ for (U32 i=0; i<mJointMotionList->getNumJointMotions(); i++)
{
- mJointMotionList->mJointMotionArray[i].update(
- &mJointStates[i],
- time,
- mJointMotionList->mDuration );
+ mJointMotionList->getJointMotion(i)->update(mJointStates[i],
+ time,
+ mJointMotionList->mDuration );
}
LLJoint::JointPriority* pose_priority = (LLJoint::JointPriority* )mCharacter->getAnimationData("Hand Pose Priority");
@@ -793,7 +809,7 @@ void LLKeyframeMotion::initializeConstraint(JointConstraint* constraint)
S32 joint_num;
LLVector3 source_pos = mCharacter->getVolumePos(shared_data->mSourceConstraintVolume, shared_data->mSourceConstraintOffset);
- LLJoint* cur_joint = mJointStates[shared_data->mJointStateIndices[0]].getJoint();
+ LLJoint* cur_joint = getJoint(shared_data->mJointStateIndices[0]);
F32 source_pos_offset = dist_vec(source_pos, cur_joint->getWorldPosition());
@@ -802,7 +818,7 @@ void LLKeyframeMotion::initializeConstraint(JointConstraint* constraint)
// grab joint lengths
for (joint_num = 1; joint_num < shared_data->mChainLength; joint_num++)
{
- cur_joint = mJointStates[shared_data->mJointStateIndices[joint_num]].getJoint();
+ cur_joint = getJointState(shared_data->mJointStateIndices[joint_num])->getJoint();
if (!cur_joint)
{
return;
@@ -844,7 +860,7 @@ void LLKeyframeMotion::activateConstraint(JointConstraint* constraint)
for (joint_num = 1; joint_num < shared_data->mChainLength; joint_num++)
{
- LLJoint* cur_joint = mJointStates[shared_data->mJointStateIndices[joint_num]].getJoint();
+ LLJoint* cur_joint = getJoint(shared_data->mJointStateIndices[joint_num]);
constraint->mPositions[joint_num] = (cur_joint->getWorldPosition() - mPelvisp->getWorldPosition()) * ~mPelvisp->getWorldRotation();
}
@@ -884,7 +900,6 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8
LLVector3 velocities[MAX_CHAIN_LENGTH - 1];
LLQuaternion old_rots[MAX_CHAIN_LENGTH];
S32 joint_num;
- LLJoint* cur_joint;
if (time < shared_data->mEaseInStartTime)
{
@@ -905,7 +920,7 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8
activateConstraint(constraint);
}
- LLJoint* root_joint = mJointStates[shared_data->mJointStateIndices[shared_data->mChainLength]].getJoint();
+ LLJoint* root_joint = getJoint(shared_data->mJointStateIndices[shared_data->mChainLength]);
LLVector3 root_pos = root_joint->getWorldPosition();
// LLQuaternion root_rot =
root_joint->getParent()->getWorldRotation();
@@ -916,14 +931,14 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8
//apply underlying keyframe animation to get nominal "kinematic" joint positions
for (joint_num = 0; joint_num <= shared_data->mChainLength; joint_num++)
{
- cur_joint = mJointStates[shared_data->mJointStateIndices[joint_num]].getJoint();
+ LLJoint* cur_joint = getJoint(shared_data->mJointStateIndices[joint_num]);
if (joint_mask[cur_joint->getJointNum()] >= (0xff >> (7 - getPriority())))
{
// skip constraint
return;
}
old_rots[joint_num] = cur_joint->getRotation();
- cur_joint->setRotation(mJointStates[shared_data->mJointStateIndices[joint_num]].getRotation());
+ cur_joint->setRotation(getJointState(shared_data->mJointStateIndices[joint_num])->getRotation());
}
@@ -1007,7 +1022,7 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8
if (shared_data->mChainLength)
{
- LLQuaternion end_rot = mJointStates[shared_data->mJointStateIndices[0]].getJoint()->getWorldRotation();
+ LLQuaternion end_rot = getJoint(shared_data->mJointStateIndices[0])->getWorldRotation();
// slam start and end of chain to the proper positions (rest of chain stays put)
positions[0] = lerp(keyframe_source_pos, target_pos, weight);
@@ -1016,7 +1031,7 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8
// grab keyframe-specified positions of joints
for (joint_num = 1; joint_num < shared_data->mChainLength; joint_num++)
{
- LLVector3 kinematic_position = mJointStates[shared_data->mJointStateIndices[joint_num]].getJoint()->getWorldPosition() +
+ LLVector3 kinematic_position = getJoint(shared_data->mJointStateIndices[joint_num])->getWorldPosition() +
(source_to_target * constraint->mJointLengthFractions[joint_num]);
// convert intermediate joint positions to world coordinates
@@ -1061,9 +1076,9 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8
for (joint_num = shared_data->mChainLength; joint_num > 0; joint_num--)
{
- LLQuaternion parent_rot = mJointStates[shared_data->mJointStateIndices[joint_num]].getJoint()->getParent()->getWorldRotation();
- cur_joint = mJointStates[shared_data->mJointStateIndices[joint_num]].getJoint();
- LLJoint* child_joint = mJointStates[shared_data->mJointStateIndices[joint_num - 1]].getJoint();
+ LLJoint* cur_joint = getJoint(shared_data->mJointStateIndices[joint_num]);
+ LLJoint* child_joint = getJoint(shared_data->mJointStateIndices[joint_num - 1]);
+ LLQuaternion parent_rot = cur_joint->getParent()->getWorldRotation();
LLQuaternion cur_rot = cur_joint->getWorldRotation();
LLQuaternion fixup_rot;
@@ -1088,25 +1103,25 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8
if (weight != 1.f)
{
- LLQuaternion cur_rot = mJointStates[shared_data->mJointStateIndices[joint_num]].getRotation();
+ LLQuaternion cur_rot = getJointState(shared_data->mJointStateIndices[joint_num])->getRotation();
target_rot = nlerp(weight, cur_rot, target_rot);
}
- mJointStates[shared_data->mJointStateIndices[joint_num]].setRotation(target_rot);
+ getJointState(shared_data->mJointStateIndices[joint_num])->setRotation(target_rot);
cur_joint->setRotation(target_rot);
}
- LLJoint* end_joint = mJointStates[shared_data->mJointStateIndices[0]].getJoint();
+ LLJoint* end_joint = getJoint(shared_data->mJointStateIndices[0]);
LLQuaternion end_local_rot = end_rot * ~end_joint->getParent()->getWorldRotation();
if (weight == 1.f)
{
- mJointStates[shared_data->mJointStateIndices[0]].setRotation(end_local_rot);
+ getJointState(shared_data->mJointStateIndices[0])->setRotation(end_local_rot);
}
else
{
- LLQuaternion cur_rot = mJointStates[shared_data->mJointStateIndices[0]].getRotation();
- mJointStates[shared_data->mJointStateIndices[0]].setRotation(nlerp(weight, cur_rot, end_local_rot));
+ LLQuaternion cur_rot = getJointState(shared_data->mJointStateIndices[0])->getRotation();
+ getJointState(shared_data->mJointStateIndices[0])->setRotation(nlerp(weight, cur_rot, end_local_rot));
}
// save simulated positions in pelvis-space and calculate total fixup distance
@@ -1124,17 +1139,17 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8
//reset old joint rots
for (joint_num = 0; joint_num <= shared_data->mChainLength; joint_num++)
{
- mJointStates[shared_data->mJointStateIndices[joint_num]].getJoint()->setRotation(old_rots[joint_num]);
+ getJoint(shared_data->mJointStateIndices[joint_num])->setRotation(old_rots[joint_num]);
}
}
// simple positional constraint (pelvis only)
- else if (mJointStates[shared_data->mJointStateIndices[0]].getUsage() & LLJointState::POS)
+ else if (getJointState(shared_data->mJointStateIndices[0])->getUsage() & LLJointState::POS)
{
LLVector3 delta = source_to_target * weight;
- LLJointState* current_joint_statep = &mJointStates[shared_data->mJointStateIndices[0]];
- LLQuaternion parent_rot = current_joint_statep->getJoint()->getParent()->getWorldRotation();
+ LLPointer<LLJointState> current_joint_state = getJointState(shared_data->mJointStateIndices[0]);
+ LLQuaternion parent_rot = current_joint_state->getJoint()->getParent()->getWorldRotation();
delta = delta * ~parent_rot;
- current_joint_statep->setPosition(current_joint_statep->getJoint()->getPosition() + delta);
+ current_joint_state->setPosition(current_joint_state->getJoint()->getPosition() + delta);
}
}
@@ -1145,7 +1160,6 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp)
{
BOOL old_version = FALSE;
mJointMotionList = new LLKeyframeMotion::JointMotionList;
- mJointMotionList->mNumJointMotions = 0;
//-------------------------------------------------------------------------
// get base priority
@@ -1261,40 +1275,38 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp)
//-------------------------------------------------------------------------
// get number of joint motions
//-------------------------------------------------------------------------
- if (!dp.unpackU32(mJointMotionList->mNumJointMotions, "num_joints"))
+ U32 num_motions = 0;
+ if (!dp.unpackU32(num_motions, "num_joints"))
{
llwarns << "can't read number of joints" << llendl;
return FALSE;
}
- if (mJointMotionList->mNumJointMotions == 0)
+ if (num_motions == 0)
{
llwarns << "no joints in animation" << llendl;
return FALSE;
}
- else if (mJointMotionList->mNumJointMotions > LL_CHARACTER_MAX_JOINTS)
+ else if (num_motions > LL_CHARACTER_MAX_JOINTS)
{
llwarns << "too many joints in animation" << llendl;
return FALSE;
}
- mJointMotionList->mJointMotionArray = new JointMotion[mJointMotionList->mNumJointMotions];
- mJointStates = new LLJointState[mJointMotionList->mNumJointMotions];
-
- if (!mJointMotionList->mJointMotionArray)
- {
- mJointMotionList->mDuration = 0.0f;
- mJointMotionList->mEaseInDuration = 0.0f;
- mJointMotionList->mEaseOutDuration = 0.0f;
- return FALSE;
- }
+ mJointMotionList->mJointMotionArray.clear();
+ mJointMotionList->mJointMotionArray.reserve(num_motions);
+ mJointStates.clear();
+ mJointStates.reserve(num_motions);
//-------------------------------------------------------------------------
// initialize joint motions
//-------------------------------------------------------------------------
- S32 k;
- for(U32 i=0; i<mJointMotionList->mNumJointMotions; ++i)
+
+ for(U32 i=0; i<num_motions; ++i)
{
+ JointMotion* joint_motion = new JointMotion;
+ mJointMotionList->mJointMotionArray.push_back(joint_motion);
+
std::string joint_name;
if (!dp.unpackString(joint_name, "joint_name"))
{
@@ -1316,9 +1328,12 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp)
//return FALSE;
}
- mJointMotionList->mJointMotionArray[i].mJointName = joint_name;
- mJointStates[i].setJoint( joint );
- mJointStates[i].setUsage( 0 );
+ joint_motion->mJointName = joint_name;
+
+ LLPointer<LLJointState> joint_state = new LLJointState;
+ mJointStates.push_back(joint_state);
+ joint_state->setJoint( joint );
+ joint_state->setUsage( 0 );
//---------------------------------------------------------------------
// get joint priority
@@ -1330,36 +1345,36 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp)
return FALSE;
}
- mJointMotionList->mJointMotionArray[i].mPriority = (LLJoint::JointPriority)joint_priority;
+ joint_motion->mPriority = (LLJoint::JointPriority)joint_priority;
if (joint_priority != LLJoint::USE_MOTION_PRIORITY &&
joint_priority > mJointMotionList->mMaxPriority)
{
mJointMotionList->mMaxPriority = (LLJoint::JointPriority)joint_priority;
}
- mJointStates[i].setPriority((LLJoint::JointPriority)joint_priority);
+ joint_state->setPriority((LLJoint::JointPriority)joint_priority);
//---------------------------------------------------------------------
// scan rotation curve header
//---------------------------------------------------------------------
- if (!dp.unpackS32(mJointMotionList->mJointMotionArray[i].mRotationCurve.mNumKeys, "num_rot_keys"))
+ if (!dp.unpackS32(joint_motion->mRotationCurve.mNumKeys, "num_rot_keys"))
{
llwarns << "can't read number of rotation keys" << llendl;
return FALSE;
}
- mJointMotionList->mJointMotionArray[i].mRotationCurve.mInterpolationType = IT_LINEAR;
- if (mJointMotionList->mJointMotionArray[i].mRotationCurve.mNumKeys != 0)
+ joint_motion->mRotationCurve.mInterpolationType = IT_LINEAR;
+ if (joint_motion->mRotationCurve.mNumKeys != 0)
{
- mJointStates[i].setUsage(mJointStates[i].getUsage() | LLJointState::ROT );
+ joint_state->setUsage(joint_state->getUsage() | LLJointState::ROT );
}
//---------------------------------------------------------------------
// scan rotation curve keys
//---------------------------------------------------------------------
- RotationCurve *rCurve = &mJointMotionList->mJointMotionArray[i].mRotationCurve;
+ RotationCurve *rCurve = &joint_motion->mRotationCurve;
- for (k = 0; k < mJointMotionList->mJointMotionArray[i].mRotationCurve.mNumKeys; k++)
+ for (S32 k = 0; k < joint_motion->mRotationCurve.mNumKeys; k++)
{
F32 time;
U16 time_short;
@@ -1424,24 +1439,24 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp)
//---------------------------------------------------------------------
// scan position curve header
//---------------------------------------------------------------------
- if (!dp.unpackS32(mJointMotionList->mJointMotionArray[i].mPositionCurve.mNumKeys, "num_pos_keys"))
+ if (!dp.unpackS32(joint_motion->mPositionCurve.mNumKeys, "num_pos_keys"))
{
llwarns << "can't read number of position keys" << llendl;
return FALSE;
}
- mJointMotionList->mJointMotionArray[i].mPositionCurve.mInterpolationType = IT_LINEAR;
- if (mJointMotionList->mJointMotionArray[i].mPositionCurve.mNumKeys != 0)
+ joint_motion->mPositionCurve.mInterpolationType = IT_LINEAR;
+ if (joint_motion->mPositionCurve.mNumKeys != 0)
{
- mJointStates[i].setUsage(mJointStates[i].getUsage() | LLJointState::POS );
+ joint_state->setUsage(joint_state->getUsage() | LLJointState::POS );
}
//---------------------------------------------------------------------
// scan position curve keys
//---------------------------------------------------------------------
- PositionCurve *pCurve = &mJointMotionList->mJointMotionArray[i].mPositionCurve;
- BOOL is_pelvis = mJointMotionList->mJointMotionArray[i].mJointName == "mPelvis";
- for (k = 0; k < mJointMotionList->mJointMotionArray[i].mPositionCurve.mNumKeys; k++)
+ PositionCurve *pCurve = &joint_motion->mPositionCurve;
+ BOOL is_pelvis = joint_motion->mJointName == "mPelvis";
+ for (S32 k = 0; k < joint_motion->mPositionCurve.mNumKeys; k++)
{
U16 time_short;
PositionKey* pos_key = new PositionKey;
@@ -1501,7 +1516,7 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp)
}
}
- mJointMotionList->mJointMotionArray[i].mUsage = mJointStates[i].getUsage();
+ joint_motion->mUsage = joint_state->getUsage();
}
//-------------------------------------------------------------------------
@@ -1655,9 +1670,9 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp)
}
joint = parent;
constraintp->mJointStateIndices[i] = -1;
- for (U32 j = 0; j < mJointMotionList->mNumJointMotions; j++)
+ for (U32 j = 0; j < mJointMotionList->getNumJointMotions(); j++)
{
- if(mJointStates[j].getJoint() == joint)
+ if(getJoint(j) == joint)
{
constraintp->mJointStateIndices[i] = (S32)j;
break;
@@ -1695,11 +1710,11 @@ BOOL LLKeyframeMotion::serialize(LLDataPacker& dp) const
success &= dp.packF32(mJointMotionList->mEaseInDuration, "ease_in_duration");
success &= dp.packF32(mJointMotionList->mEaseOutDuration, "ease_out_duration");
success &= dp.packU32(mJointMotionList->mHandPose, "hand_pose");
- success &= dp.packU32(mJointMotionList->mNumJointMotions, "num_joints");
+ success &= dp.packU32(mJointMotionList->getNumJointMotions(), "num_joints");
- for (U32 i = 0; i < mJointMotionList->mNumJointMotions; i++)
+ for (U32 i = 0; i < mJointMotionList->getNumJointMotions(); i++)
{
- JointMotion* joint_motionp = &mJointMotionList->mJointMotionArray[i];
+ JointMotion* joint_motionp = mJointMotionList->getJointMotion(i);
success &= dp.packString(joint_motionp->mJointName.c_str(), "joint_name");
success &= dp.packS32(joint_motionp->mPriority, "joint_priority");
success &= dp.packS32(joint_motionp->mRotationCurve.mNumKeys, "num_rot_keys");
@@ -1806,13 +1821,14 @@ void LLKeyframeMotion::setPriority(S32 priority)
mJointMotionList->mBasePriority = (LLJoint::JointPriority)priority;
mJointMotionList->mMaxPriority = mJointMotionList->mBasePriority;
- for (U32 i = 0; i < mJointMotionList->mNumJointMotions; i++)
+ for (U32 i = 0; i < mJointMotionList->getNumJointMotions(); i++)
{
- mJointMotionList->mJointMotionArray[i].mPriority = (LLJoint::JointPriority)llclamp(
- (S32)mJointMotionList->mJointMotionArray[i].mPriority + priority_delta,
+ JointMotion* joint_motion = mJointMotionList->getJointMotion(i);
+ joint_motion->mPriority = (LLJoint::JointPriority)llclamp(
+ (S32)joint_motion->mPriority + priority_delta,
(S32)LLJoint::LOW_PRIORITY,
(S32)LLJoint::HIGHEST_PRIORITY);
- mJointStates[i].setPriority(mJointMotionList->mJointMotionArray[i].mPriority);
+ getJointState(i)->setPriority(joint_motion->mPriority);
}
}
}
@@ -1888,11 +1904,13 @@ void LLKeyframeMotion::setLoopIn(F32 in_point)
mJointMotionList->mLoopInPoint = in_point;
// set up loop keys
- for (U32 i = 0; i < mJointMotionList->mNumJointMotions; i++)
+ for (U32 i = 0; i < mJointMotionList->getNumJointMotions(); i++)
{
- PositionCurve* pos_curve = &mJointMotionList->mJointMotionArray[i].mPositionCurve;
- RotationCurve* rot_curve = &mJointMotionList->mJointMotionArray[i].mRotationCurve;
- ScaleCurve* scale_curve = &mJointMotionList->mJointMotionArray[i].mScaleCurve;
+ JointMotion* joint_motion = mJointMotionList->getJointMotion(i);
+
+ PositionCurve* pos_curve = &joint_motion->mPositionCurve;
+ RotationCurve* rot_curve = &joint_motion->mRotationCurve;
+ ScaleCurve* scale_curve = &joint_motion->mScaleCurve;
pos_curve->mLoopInKey.mTime = mJointMotionList->mLoopInPoint;
rot_curve->mLoopInKey.mTime = mJointMotionList->mLoopInPoint;
@@ -1915,11 +1933,13 @@ void LLKeyframeMotion::setLoopOut(F32 out_point)
mJointMotionList->mLoopOutPoint = out_point;
// set up loop keys
- for (U32 i = 0; i < mJointMotionList->mNumJointMotions; i++)
+ for (U32 i = 0; i < mJointMotionList->getNumJointMotions(); i++)
{
- PositionCurve* pos_curve = &mJointMotionList->mJointMotionArray[i].mPositionCurve;
- RotationCurve* rot_curve = &mJointMotionList->mJointMotionArray[i].mRotationCurve;
- ScaleCurve* scale_curve = &mJointMotionList->mJointMotionArray[i].mScaleCurve;
+ JointMotion* joint_motion = mJointMotionList->getJointMotion(i);
+
+ PositionCurve* pos_curve = &joint_motion->mPositionCurve;
+ RotationCurve* rot_curve = &joint_motion->mRotationCurve;
+ ScaleCurve* scale_curve = &joint_motion->mScaleCurve;
pos_curve->mLoopOutKey.mTime = mJointMotionList->mLoopOutPoint;
rot_curve->mLoopOutKey.mTime = mJointMotionList->mLoopOutPoint;
@@ -2020,10 +2040,10 @@ void LLKeyframeMotion::writeCAL3D(apr_file_t* fp)
// </TRACK>
// </ANIMATION>
- apr_file_printf(fp, "<ANIMATION VERSION=\"1000\" DURATION=\"%.5f\" NUMTRACKS=\"%d\">\n", getDuration(), mJointMotionList->mNumJointMotions);
- for (U32 joint_index = 0; joint_index < mJointMotionList->mNumJointMotions; joint_index++)
+ apr_file_printf(fp, "<ANIMATION VERSION=\"1000\" DURATION=\"%.5f\" NUMTRACKS=\"%d\">\n", getDuration(), mJointMotionList->getNumJointMotions());
+ for (U32 joint_index = 0; joint_index < mJointMotionList->getNumJointMotions(); joint_index++)
{
- JointMotion* joint_motionp = &mJointMotionList->mJointMotionArray[joint_index];
+ JointMotion* joint_motionp = mJointMotionList->getJointMotion(joint_index);
LLJoint* animated_joint = mCharacter->getJoint(joint_motionp->mJointName);
S32 joint_num = animated_joint->mJointNum + 1;
diff --git a/indra/llcharacter/llkeyframemotion.h b/indra/llcharacter/llkeyframemotion.h
index 57123fadea..9cea7f3a59 100644
--- a/indra/llcharacter/llkeyframemotion.h
+++ b/indra/llcharacter/llkeyframemotion.h
@@ -73,6 +73,11 @@ public:
// Destructor
virtual ~LLKeyframeMotion();
+private:
+ // private helper functions to wrap some asserts
+ LLPointer<LLJointState>& getJointState(U32 index);
+ LLJoint* getJoint(U32 index);
+
public:
//-------------------------------------------------------------------------
// functions to support MotionController and MotionRegistry
@@ -388,7 +393,7 @@ public:
U32 mUsage;
LLJoint::JointPriority mPriority;
- void update(LLJointState *joint_state, F32 time, F32 duration);
+ void update(LLJointState* joint_state, F32 time, F32 duration);
};
//-------------------------------------------------------------------------
@@ -397,8 +402,7 @@ public:
class JointMotionList
{
public:
- U32 mNumJointMotions;
- JointMotion* mJointMotionArray;
+ std::vector<JointMotion*> mJointMotionArray;
F32 mDuration;
BOOL mLoop;
F32 mLoopInPoint;
@@ -415,6 +419,8 @@ public:
JointMotionList();
~JointMotionList();
U32 dumpDiagInfo();
+ JointMotion* getJointMotion(U32 index) const { llassert(index < mJointMotionArray.size()); return mJointMotionArray[index]; }
+ U32 getNumJointMotions() const { return mJointMotionArray.size(); }
};
@@ -425,7 +431,7 @@ protected:
// Member Data
//-------------------------------------------------------------------------
JointMotionList* mJointMotionList;
- LLJointState* mJointStates;
+ std::vector<LLPointer<LLJointState> > mJointStates;
LLJoint* mPelvisp;
LLCharacter* mCharacter;
std::string mEmoteName;
diff --git a/indra/llcharacter/llkeyframemotionparam.cpp b/indra/llcharacter/llkeyframemotionparam.cpp
index dd64ef2135..f54d1f4a83 100644
--- a/indra/llcharacter/llkeyframemotionparam.cpp
+++ b/indra/llcharacter/llkeyframemotionparam.cpp
@@ -61,7 +61,6 @@ BOOL LLKeyframeMotionParam::sortFunc(ParameterizedMotion *new_motion, Parameteri
//-----------------------------------------------------------------------------
LLKeyframeMotionParam::LLKeyframeMotionParam( const LLUUID &id) : LLMotion(id)
{
- mJointStates = NULL;
mDefaultKeyframeMotion = NULL;
mCharacter = NULL;
diff --git a/indra/llcharacter/llkeyframemotionparam.h b/indra/llcharacter/llkeyframemotionparam.h
index 204a475dd3..39a02aea25 100644
--- a/indra/llcharacter/llkeyframemotionparam.h
+++ b/indra/llcharacter/llkeyframemotionparam.h
@@ -145,7 +145,6 @@ protected:
typedef LLLinkedList < ParameterizedMotion > motion_list_t;
LLAssocList <std::string, motion_list_t* > mParameterizedMotions;
- LLJointState* mJointStates;
LLMotion* mDefaultKeyframeMotion;
LLCharacter* mCharacter;
LLPoseBlender mPoseBlender;
diff --git a/indra/llcharacter/llkeyframestandmotion.h b/indra/llcharacter/llkeyframestandmotion.h
index 48496af917..f98a7e6a84 100644
--- a/indra/llcharacter/llkeyframestandmotion.h
+++ b/indra/llcharacter/llkeyframestandmotion.h
@@ -78,15 +78,15 @@ public:
BOOL mFlipFeet;
- LLJointState *mPelvisState;
+ LLPointer<LLJointState> mPelvisState;
- LLJointState *mHipLeftState;
- LLJointState *mKneeLeftState;
- LLJointState *mAnkleLeftState;
+ LLPointer<LLJointState> mHipLeftState;
+ LLPointer<LLJointState> mKneeLeftState;
+ LLPointer<LLJointState> mAnkleLeftState;
- LLJointState *mHipRightState;
- LLJointState *mKneeRightState;
- LLJointState *mAnkleRightState;
+ LLPointer<LLJointState> mHipRightState;
+ LLPointer<LLJointState> mKneeRightState;
+ LLPointer<LLJointState> mAnkleRightState;
LLJoint mPelvisJoint;
diff --git a/indra/llcharacter/llkeyframewalkmotion.cpp b/indra/llcharacter/llkeyframewalkmotion.cpp
index 9a49996ebd..0d7e34bb4f 100644
--- a/indra/llcharacter/llkeyframewalkmotion.cpp
+++ b/indra/llcharacter/llkeyframewalkmotion.cpp
@@ -143,6 +143,8 @@ LLWalkAdjustMotion::LLWalkAdjustMotion(const LLUUID &id) : LLMotion(id)
{
mLastTime = 0.f;
mName = "walk_adjust";
+
+ mPelvisState = new LLJointState;
}
//-----------------------------------------------------------------------------
@@ -155,15 +157,15 @@ LLMotion::LLMotionInitStatus LLWalkAdjustMotion::onInitialize(LLCharacter *chara
mRightAnkleJoint = mCharacter->getJoint("mAnkleRight");
mPelvisJoint = mCharacter->getJoint("mPelvis");
- mPelvisState.setJoint( mPelvisJoint );
+ mPelvisState->setJoint( mPelvisJoint );
if ( !mPelvisJoint )
{
llwarns << getName() << ": Can't get pelvis joint." << llendl;
return STATUS_FAILURE;
}
- mPelvisState.setUsage(LLJointState::POS);
- addJointState( &mPelvisState );
+ mPelvisState->setUsage(LLJointState::POS);
+ addJointState( mPelvisState );
return STATUS_SUCCESS;
}
@@ -178,7 +180,7 @@ BOOL LLWalkAdjustMotion::onActivate()
mAnimSpeed = 0.f;
mAvgSpeed = 0.f;
mRelativeDir = 1.f;
- mPelvisState.setPosition(LLVector3::zero);
+ mPelvisState->setPosition(LLVector3::zero);
// store ankle positions for next frame
mLastLeftAnklePos = mCharacter->getPosGlobalFromAgent(mLeftAnkleJoint->getWorldPosition());
mLastRightAnklePos = mCharacter->getPosGlobalFromAgent(mRightAnkleJoint->getWorldPosition());
@@ -271,7 +273,7 @@ BOOL LLWalkAdjustMotion::onUpdate(F32 time, U8* joint_mask)
// calculate ideal pelvis offset so that foot is glued to ground and damp towards it
// the amount of foot slippage this frame + the offset applied last frame
- mPelvisOffset = mPelvisState.getPosition() + lerp(LLVector3::zero, footCorrection, LLCriticalDamp::getInterpolant(0.2f));
+ mPelvisOffset = mPelvisState->getPosition() + lerp(LLVector3::zero, footCorrection, LLCriticalDamp::getInterpolant(0.2f));
// pelvis drift (along walk direction)
mAvgCorrection = lerp(mAvgCorrection, footCorrection.mV[VX] * mRelativeDir, LLCriticalDamp::getInterpolant(0.1f));
@@ -319,7 +321,7 @@ BOOL LLWalkAdjustMotion::onUpdate(F32 time, U8* joint_mask)
F32 drift_comp_max = llclamp(speed, 0.f, DRIFT_COMP_MAX_SPEED) / DRIFT_COMP_MAX_SPEED;
drift_comp_max *= DRIFT_COMP_MAX_TOTAL;
- LLVector3 currentPelvisPos = mPelvisState.getJoint()->getPosition();
+ LLVector3 currentPelvisPos = mPelvisState->getJoint()->getPosition();
// NB: this is an ADDITIVE amount that is accumulated every frame, so clamping it alone won't do the trick
// must clamp with absolute position of pelvis in mind
@@ -328,7 +330,7 @@ BOOL LLWalkAdjustMotion::onUpdate(F32 time, U8* joint_mask)
mPelvisOffset.mV[VZ] = 0.f;
// set position
- mPelvisState.setPosition(mPelvisOffset);
+ mPelvisState->setPosition(mPelvisOffset);
mCharacter->setAnimationData("Pelvis Offset", &mPelvisOffset);
@@ -344,6 +346,17 @@ void LLWalkAdjustMotion::onDeactivate()
}
//-----------------------------------------------------------------------------
+// LLFlyAdjustMotion::LLFlyAdjustMotion()
+//-----------------------------------------------------------------------------
+LLFlyAdjustMotion::LLFlyAdjustMotion(const LLUUID &id)
+ : LLMotion(id)
+{
+ mName = "fly_adjust";
+
+ mPelvisState = new LLJointState;
+}
+
+//-----------------------------------------------------------------------------
// LLFlyAdjustMotion::onInitialize()
//-----------------------------------------------------------------------------
LLMotion::LLMotionInitStatus LLFlyAdjustMotion::onInitialize(LLCharacter *character)
@@ -351,15 +364,15 @@ LLMotion::LLMotionInitStatus LLFlyAdjustMotion::onInitialize(LLCharacter *charac
mCharacter = character;
LLJoint* pelvisJoint = mCharacter->getJoint("mPelvis");
- mPelvisState.setJoint( pelvisJoint );
+ mPelvisState->setJoint( pelvisJoint );
if ( !pelvisJoint )
{
llwarns << getName() << ": Can't get pelvis joint." << llendl;
return STATUS_FAILURE;
}
- mPelvisState.setUsage(LLJointState::POS | LLJointState::ROT);
- addJointState( &mPelvisState );
+ mPelvisState->setUsage(LLJointState::POS | LLJointState::ROT);
+ addJointState( mPelvisState );
return STATUS_SUCCESS;
}
@@ -369,8 +382,8 @@ LLMotion::LLMotionInitStatus LLFlyAdjustMotion::onInitialize(LLCharacter *charac
//-----------------------------------------------------------------------------
BOOL LLFlyAdjustMotion::onActivate()
{
- mPelvisState.setPosition(LLVector3::zero);
- mPelvisState.setRotation(LLQuaternion::DEFAULT);
+ mPelvisState->setPosition(LLVector3::zero);
+ mPelvisState->setRotation(LLQuaternion::DEFAULT);
mRoll = 0.f;
return TRUE;
}
@@ -392,11 +405,11 @@ BOOL LLFlyAdjustMotion::onUpdate(F32 time, U8* joint_mask)
// llinfos << mRoll << llendl;
LLQuaternion roll(mRoll, LLVector3(0.f, 0.f, 1.f));
- mPelvisState.setRotation(roll);
+ mPelvisState->setRotation(roll);
// F32 lerp_amt = LLCriticalDamp::getInterpolant(0.2f);
//
-// LLVector3 pelvis_correction = mPelvisState.getPosition() - lerp(LLVector3::zero, mPelvisState.getJoint()->getPosition() + mPelvisState.getPosition(), lerp_amt);
-// mPelvisState.setPosition(pelvis_correction);
+// LLVector3 pelvis_correction = mPelvisState->getPosition() - lerp(LLVector3::zero, mPelvisState->getJoint()->getPosition() + mPelvisState->getPosition(), lerp_amt);
+// mPelvisState->setPosition(pelvis_correction);
return TRUE;
}
diff --git a/indra/llcharacter/llkeyframewalkmotion.h b/indra/llcharacter/llkeyframewalkmotion.h
index f52a8d6e33..bd30b5d11d 100644
--- a/indra/llcharacter/llkeyframewalkmotion.h
+++ b/indra/llcharacter/llkeyframewalkmotion.h
@@ -123,7 +123,7 @@ public:
LLCharacter *mCharacter;
LLJoint* mLeftAnkleJoint;
LLJoint* mRightAnkleJoint;
- LLJointState mPelvisState;
+ LLPointer<LLJointState> mPelvisState;
LLJoint* mPelvisJoint;
LLVector3d mLastLeftAnklePos;
LLVector3d mLastRightAnklePos;
@@ -141,7 +141,7 @@ class LLFlyAdjustMotion : public LLMotion
{
public:
// Constructor
- LLFlyAdjustMotion(const LLUUID &id) : LLMotion(id) {mName = "fly_adjust";}
+ LLFlyAdjustMotion(const LLUUID &id);
public:
//-------------------------------------------------------------------------
@@ -173,7 +173,7 @@ protected:
// Member Data
//-------------------------------------------------------------------------
LLCharacter *mCharacter;
- LLJointState mPelvisState;
+ LLPointer<LLJointState> mPelvisState;
F32 mRoll;
};
diff --git a/indra/llcharacter/llmotion.cpp b/indra/llcharacter/llmotion.cpp
index e674620d42..bf332ed838 100644
--- a/indra/llcharacter/llmotion.cpp
+++ b/indra/llcharacter/llmotion.cpp
@@ -106,7 +106,7 @@ void LLMotion::fadeIn()
//-----------------------------------------------------------------------------
// addJointState()
//-----------------------------------------------------------------------------
-void LLMotion::addJointState(LLJointState* jointState)
+void LLMotion::addJointState(const LLPointer<LLJointState>& jointState)
{
mPose.addJointState(jointState);
S32 priority = jointState->getPriority();
diff --git a/indra/llcharacter/llmotion.h b/indra/llcharacter/llmotion.h
index 2b5c5aad5e..7669920339 100644
--- a/indra/llcharacter/llmotion.h
+++ b/indra/llcharacter/llmotion.h
@@ -163,7 +163,7 @@ protected:
// it will be deactivated
virtual BOOL onActivate() = 0;
- void addJointState(LLJointState* jointState);
+ void addJointState(const LLPointer<LLJointState>& jointState);
protected:
LLPose mPose;
diff --git a/indra/llcharacter/llpose.cpp b/indra/llcharacter/llpose.cpp
index 1e637d7e33..557bbd2d56 100644
--- a/indra/llcharacter/llpose.cpp
+++ b/indra/llcharacter/llpose.cpp
@@ -54,7 +54,7 @@ LLPose::~LLPose()
//-----------------------------------------------------------------------------
// getFirstJointState()
//-----------------------------------------------------------------------------
-LLJointState *LLPose::getFirstJointState()
+LLJointState* LLPose::getFirstJointState()
{
mListIter = mJointMap.begin();
if (mListIter == mJointMap.end())
@@ -86,7 +86,7 @@ LLJointState *LLPose::getNextJointState()
//-----------------------------------------------------------------------------
// addJointState()
//-----------------------------------------------------------------------------
-BOOL LLPose::addJointState(LLJointState *jointState)
+BOOL LLPose::addJointState(const LLPointer<LLJointState>& jointState)
{
if (mJointMap.find(jointState->getJoint()->getName()) == mJointMap.end())
{
@@ -98,7 +98,7 @@ BOOL LLPose::addJointState(LLJointState *jointState)
//-----------------------------------------------------------------------------
// removeJointState()
//-----------------------------------------------------------------------------
-BOOL LLPose::removeJointState(LLJointState *jointState)
+BOOL LLPose::removeJointState(const LLPointer<LLJointState>& jointState)
{
mJointMap.erase(jointState->getJoint()->getName());
return TRUE;
@@ -199,7 +199,7 @@ LLJointStateBlender::~LLJointStateBlender()
//-----------------------------------------------------------------------------
// addJointState()
//-----------------------------------------------------------------------------
-BOOL LLJointStateBlender::addJointState(LLJointState *joint_state, S32 priority, BOOL additive_blend)
+BOOL LLJointStateBlender::addJointState(const LLPointer<LLJointState>& joint_state, S32 priority, BOOL additive_blend)
{
llassert(joint_state);
@@ -209,7 +209,7 @@ BOOL LLJointStateBlender::addJointState(LLJointState *joint_state, S32 priority,
for(S32 i = 0; i < JSB_NUM_JOINT_STATES; i++)
{
- if (NULL == mJointStates[i])
+ if (mJointStates[i].isNull())
{
mJointStates[i] = joint_state;
mPriorities[i] = priority;
@@ -246,7 +246,7 @@ void LLJointStateBlender::blendJointStates(BOOL apply_now)
// we need at least one joint to blend
// if there is one, it will be in slot zero according to insertion logic
// instead of resetting joint state to default, just leave it unchanged from last frame
- if (NULL == mJointStates[0])
+ if (mJointStates[0].isNull())
{
return;
}
@@ -275,7 +275,7 @@ void LLJointStateBlender::blendJointStates(BOOL apply_now)
sum_weights[SCALE_WEIGHT] = 0.f;
for(S32 joint_state_index = 0;
- joint_state_index < JSB_NUM_JOINT_STATES && mJointStates[joint_state_index] != NULL;
+ joint_state_index < JSB_NUM_JOINT_STATES && mJointStates[joint_state_index].notNull();
joint_state_index++)
{
LLJointState* jsp = mJointStates[joint_state_index];
@@ -468,7 +468,7 @@ BOOL LLPoseBlender::addMotion(LLMotion* motion)
{
LLPose* pose = motion->getPose();
- for(LLJointState *jsp = pose->getFirstJointState(); jsp; jsp = pose->getNextJointState())
+ for(LLJointState* jsp = pose->getFirstJointState(); jsp; jsp = pose->getNextJointState())
{
LLJoint *jointp = jsp->getJoint();
LLJointStateBlender* joint_blender;
diff --git a/indra/llcharacter/llpose.h b/indra/llcharacter/llpose.h
index fe0a23887d..5ba579a167 100644
--- a/indra/llcharacter/llpose.h
+++ b/indra/llcharacter/llpose.h
@@ -52,7 +52,7 @@ class LLPose
{
friend class LLPoseBlender;
protected:
- typedef std::map<std::string, LLJointState*> joint_map;
+ typedef std::map<std::string, LLPointer<LLJointState> > joint_map;
typedef joint_map::iterator joint_map_iterator;
typedef joint_map::value_type joint_map_value_type;
@@ -61,19 +61,19 @@ protected:
joint_map_iterator mListIter;
public:
// Iterate through jointStates
- LLJointState *getFirstJointState();
- LLJointState *getNextJointState();
- LLJointState *findJointState(LLJoint *joint);
- LLJointState *findJointState(const std::string &name);
+ LLJointState* getFirstJointState();
+ LLJointState* getNextJointState();
+ LLJointState* findJointState(LLJoint *joint);
+ LLJointState* findJointState(const std::string &name);
public:
// Constructor
LLPose() : mWeight(0.f) {}
// Destructor
~LLPose();
// add a joint state in this pose
- BOOL addJointState(LLJointState *jointState);
+ BOOL addJointState(const LLPointer<LLJointState>& jointState);
// remove a joint state from this pose
- BOOL removeJointState(LLJointState *jointState);
+ BOOL removeJointState(const LLPointer<LLJointState>& jointState);
// removes all joint states from this pose
BOOL removeAllJointStates();
// set weight for all joint states in this pose
@@ -89,14 +89,14 @@ const S32 JSB_NUM_JOINT_STATES = 6;
class LLJointStateBlender
{
protected:
- LLJointState* mJointStates[JSB_NUM_JOINT_STATES];
+ LLPointer<LLJointState> mJointStates[JSB_NUM_JOINT_STATES];
S32 mPriorities[JSB_NUM_JOINT_STATES];
BOOL mAdditiveBlends[JSB_NUM_JOINT_STATES];
public:
LLJointStateBlender();
~LLJointStateBlender();
void blendJointStates(BOOL apply_now = TRUE);
- BOOL addJointState(LLJointState *joint_state, S32 priority, BOOL additive_blend);
+ BOOL addJointState(const LLPointer<LLJointState>& joint_state, S32 priority, BOOL additive_blend);
void interpolate(F32 u);
void clear();
void resetCachedJoint();
diff --git a/indra/llcharacter/lltargetingmotion.cpp b/indra/llcharacter/lltargetingmotion.cpp
index d5fe65461b..c0ce11cb85 100644
--- a/indra/llcharacter/lltargetingmotion.cpp
+++ b/indra/llcharacter/lltargetingmotion.cpp
@@ -55,6 +55,8 @@ LLTargetingMotion::LLTargetingMotion(const LLUUID &id) : LLMotion(id)
{
mCharacter = NULL;
mName = "targeting";
+
+ mTorsoState = new LLJointState;
}
@@ -87,11 +89,11 @@ LLMotion::LLMotionInitStatus LLTargetingMotion::onInitialize(LLCharacter *charac
return STATUS_FAILURE;
}
- mTorsoState.setJoint( mTorsoJoint );
+ mTorsoState->setJoint( mTorsoJoint );
// add joint states to the pose
- mTorsoState.setUsage(LLJointState::ROT);
- addJointState( &mTorsoState );
+ mTorsoState->setUsage(LLJointState::ROT);
+ addJointState( mTorsoState );
return STATUS_SUCCESS;
}
@@ -127,7 +129,7 @@ BOOL LLTargetingMotion::onUpdate(F32 time, U8* joint_mask)
}
//LLVector3 target_plane_normal = LLVector3(1.f, 0.f, 0.f) * mPelvisJoint->getWorldRotation();
- //LLVector3 torso_dir = LLVector3(1.f, 0.f, 0.f) * (mTorsoJoint->getWorldRotation() * mTorsoState.getRotation());
+ //LLVector3 torso_dir = LLVector3(1.f, 0.f, 0.f) * (mTorsoJoint->getWorldRotation() * mTorsoState->getRotation());
LLVector3 skyward(0.f, 0.f, 1.f);
LLVector3 left(skyward % target);
@@ -151,14 +153,14 @@ BOOL LLTargetingMotion::onUpdate(F32 time, U8* joint_mask)
new_torso_rot = new_torso_rot * ~cur_torso_rot;
// slerp from current additive rotation to ideal additive rotation
- new_torso_rot = nlerp(slerp_amt, mTorsoState.getRotation(), new_torso_rot);
+ new_torso_rot = nlerp(slerp_amt, mTorsoState->getRotation(), new_torso_rot);
// constraint overall torso rotation
LLQuaternion total_rot = new_torso_rot * mTorsoJoint->getRotation();
total_rot.constrain(F_PI_BY_TWO * 0.8f);
new_torso_rot = total_rot * ~mTorsoJoint->getRotation();
- mTorsoState.setRotation(new_torso_rot);
+ mTorsoState->setRotation(new_torso_rot);
return result;
}
diff --git a/indra/llcharacter/lltargetingmotion.h b/indra/llcharacter/lltargetingmotion.h
index 9877467e48..d72a8b11ec 100644
--- a/indra/llcharacter/lltargetingmotion.h
+++ b/indra/llcharacter/lltargetingmotion.h
@@ -111,7 +111,7 @@ public:
public:
LLCharacter *mCharacter;
- LLJointState mTorsoState;
+ LLPointer<LLJointState> mTorsoState;
LLJoint* mPelvisJoint;
LLJoint* mTorsoJoint;
LLJoint* mRightHandJoint;