llhandmotion.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:7k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llhandmotion.cpp
  3.  * @brief Implementation of LLHandMotion class.
  4.  *
  5.  * $LicenseInfo:firstyear=2001&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2001-2010, 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. // Header Files
  34. //-----------------------------------------------------------------------------
  35. #include "linden_common.h"
  36. #include "llhandmotion.h"
  37. #include "llcharacter.h"
  38. #include "m3math.h"
  39. //-----------------------------------------------------------------------------
  40. // Constants
  41. //-----------------------------------------------------------------------------
  42. const char *gHandPoseNames[LLHandMotion::NUM_HAND_POSES] =  /* Flawfinder: ignore */
  43. {
  44. "",
  45. "Hands_Relaxed",
  46. "Hands_Point",
  47. "Hands_Fist",
  48. "Hands_Relaxed_L",
  49. "Hands_Point_L",
  50. "Hands_Fist_L",
  51. "Hands_Relaxed_R",
  52. "Hands_Point_R",
  53. "Hands_Fist_R",
  54. "Hands_Salute_R",
  55. "Hands_Typing",
  56. "Hands_Peace_R",
  57. "Hands_Spread_R"
  58. };
  59. const F32 HAND_MORPH_BLEND_TIME = 0.2f;
  60. //-----------------------------------------------------------------------------
  61. // LLHandMotion()
  62. // Class Constructor
  63. //-----------------------------------------------------------------------------
  64. LLHandMotion::LLHandMotion(const LLUUID &id) : LLMotion(id)
  65. {
  66. mCharacter = NULL;
  67. mLastTime = 0.f;
  68. mCurrentPose = HAND_POSE_RELAXED;
  69. mNewPose = HAND_POSE_RELAXED;
  70. mName = "hand_motion";
  71. //RN: flag hand joint as highest priority for now, until we implement a proper animation track
  72. mJointSignature[0][LL_HAND_JOINT_NUM] = 0xff;
  73. mJointSignature[1][LL_HAND_JOINT_NUM] = 0xff;
  74. mJointSignature[2][LL_HAND_JOINT_NUM] = 0xff;
  75. }
  76. //-----------------------------------------------------------------------------
  77. // ~LLHandMotion()
  78. // Class Destructor
  79. //-----------------------------------------------------------------------------
  80. LLHandMotion::~LLHandMotion()
  81. {
  82. }
  83. //-----------------------------------------------------------------------------
  84. // LLHandMotion::onInitialize(LLCharacter *character)
  85. //-----------------------------------------------------------------------------
  86. LLMotion::LLMotionInitStatus LLHandMotion::onInitialize(LLCharacter *character)
  87. {
  88. mCharacter = character;
  89. return STATUS_SUCCESS;
  90. }
  91. //-----------------------------------------------------------------------------
  92. // LLHandMotion::onActivate()
  93. //-----------------------------------------------------------------------------
  94. BOOL LLHandMotion::onActivate()
  95. {
  96. LLPolyMesh *upperBodyMesh = mCharacter->getUpperBodyMesh();
  97. if (upperBodyMesh)
  98. {
  99. // Note: 0 is the default
  100. for (S32 i = 1; i < LLHandMotion::NUM_HAND_POSES; i++)
  101. {
  102. mCharacter->setVisualParamWeight(gHandPoseNames[i], 0.f);
  103. }
  104. mCharacter->setVisualParamWeight(gHandPoseNames[mCurrentPose], 1.f);
  105. mCharacter->updateVisualParams();
  106. }
  107. return TRUE;
  108. }
  109. //-----------------------------------------------------------------------------
  110. // LLHandMotion::onUpdate()
  111. //-----------------------------------------------------------------------------
  112. BOOL LLHandMotion::onUpdate(F32 time, U8* joint_mask)
  113. {
  114. eHandPose *requestedHandPose;
  115. F32 timeDelta = time - mLastTime;
  116. mLastTime = time;
  117. requestedHandPose = (eHandPose *)mCharacter->getAnimationData("Hand Pose");
  118. // check to see if requested pose has changed
  119. if (!requestedHandPose)
  120. {
  121. if (mNewPose != HAND_POSE_RELAXED && mNewPose != mCurrentPose)
  122. {
  123. mCharacter->setVisualParamWeight(gHandPoseNames[mNewPose], 0.f);
  124. }
  125. mNewPose = HAND_POSE_RELAXED;
  126. }
  127. else
  128. {
  129. // this is a new morph we didn't know about before
  130. if (*requestedHandPose != mNewPose && mNewPose != mCurrentPose && mNewPose != HAND_POSE_SPREAD)
  131. {
  132. mCharacter->setVisualParamWeight(gHandPoseNames[mNewPose], 0.f);
  133. }
  134. mNewPose = *requestedHandPose;
  135. }
  136. mCharacter->removeAnimationData("Hand Pose");
  137. mCharacter->removeAnimationData("Hand Pose Priority");
  138. // if (requestedHandPose)
  139. // llinfos << "Hand Pose " << *requestedHandPose << llendl;
  140. // if we are still blending...
  141. if (mCurrentPose != mNewPose)
  142. {
  143. F32 incomingWeight = 1.f;
  144. F32 outgoingWeight = 0.f;
  145. if (mNewPose != HAND_POSE_SPREAD)
  146. {
  147. incomingWeight = mCharacter->getVisualParamWeight(gHandPoseNames[mNewPose]);
  148. incomingWeight += (timeDelta / HAND_MORPH_BLEND_TIME);
  149. incomingWeight = llclamp(incomingWeight, 0.f, 1.f);
  150. mCharacter->setVisualParamWeight(gHandPoseNames[mNewPose], incomingWeight);
  151. }
  152. if (mCurrentPose != HAND_POSE_SPREAD)
  153. {
  154. outgoingWeight = mCharacter->getVisualParamWeight(gHandPoseNames[mCurrentPose]);
  155. outgoingWeight -= (timeDelta / HAND_MORPH_BLEND_TIME);
  156. outgoingWeight = llclamp(outgoingWeight, 0.f, 1.f);
  157. mCharacter->setVisualParamWeight(gHandPoseNames[mCurrentPose], outgoingWeight);
  158. }
  159. mCharacter->updateVisualParams();
  160. if (incomingWeight == 1.f && outgoingWeight == 0.f)
  161. {
  162. mCurrentPose = mNewPose;
  163. }
  164. }
  165. return TRUE;
  166. }
  167. //-----------------------------------------------------------------------------
  168. // LLHandMotion::onDeactivate()
  169. //-----------------------------------------------------------------------------
  170. void LLHandMotion::onDeactivate()
  171. {
  172. }
  173. //-----------------------------------------------------------------------------
  174. // LLHandMotion::getHandPoseName()
  175. //-----------------------------------------------------------------------------
  176. std::string LLHandMotion::getHandPoseName(eHandPose pose)
  177. {
  178. if ((S32)pose < LLHandMotion::NUM_HAND_POSES && (S32)pose >= 0)
  179. {
  180. return std::string(gHandPoseNames[pose]);
  181. }
  182. return LLStringUtil::null;
  183. }
  184. LLHandMotion::eHandPose LLHandMotion::getHandPose(std::string posename)
  185. {
  186. for (S32 pose = 0; pose < LLHandMotion::NUM_HAND_POSES; ++pose)
  187. {
  188. if (gHandPoseNames[pose] == posename)
  189. {
  190. return (eHandPose)pose;
  191. }
  192. }
  193. return (eHandPose)0;
  194. }
  195. // End