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

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llmorphview.cpp
  3.  * @brief Container for Morph functionality
  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. #include "llviewerprecompiledheaders.h"
  33. #include "llmorphview.h"
  34. #include "lljoint.h"
  35. #include "llagent.h"
  36. #include "lldrawable.h"
  37. #include "lldrawpoolavatar.h"
  38. #include "llface.h"
  39. //#include "llfirstuse.h"
  40. #include "llfloatercustomize.h"
  41. #include "llfloatertools.h"
  42. #include "llresmgr.h"
  43. #include "lltoolmgr.h"
  44. #include "lltoolmorph.h"
  45. #include "llviewercamera.h"
  46. #include "llvoavatarself.h"
  47. #include "llviewerwindow.h"
  48. #include "pipeline.h"
  49. LLMorphView *gMorphView = NULL;
  50. const F32 EDIT_AVATAR_ORBIT_SPEED = 0.1f;
  51. const F32 EDIT_AVATAR_MAX_CAMERA_PITCH = 0.5f;
  52. const F32 CAMERA_MOVE_TIME = 0.5f;
  53. const F32 MORPH_NEAR_CLIP = 0.1f;
  54. const F32 CAMERA_DIST_MIN  = 0.4f;
  55. const F32 CAMERA_DIST_MAX  = 4.0f;
  56. const F32 CAMERA_DIST_STEP = 1.5f;
  57. //-----------------------------------------------------------------------------
  58. // LLMorphView()
  59. //-----------------------------------------------------------------------------
  60. LLMorphView::LLMorphView(const LLMorphView::Params& p)
  61. :  LLView(p),
  62. mCameraTargetJoint( NULL ),
  63. mCameraOffset(-0.5f, 0.05f, 0.07f ),
  64. mCameraTargetOffset(0.f, 0.f, 0.05f ),
  65. mOldCameraNearClip( 0.f ),
  66. mCameraPitch( 0.f ),
  67. mCameraYaw( 0.f ),
  68. mCameraDist( -1.f ),
  69. mCameraDrivenByKeys( FALSE )
  70. {}
  71. //-----------------------------------------------------------------------------
  72. // initialize()
  73. //-----------------------------------------------------------------------------
  74. void LLMorphView::initialize()
  75. {
  76. mCameraPitch = 0.f;
  77. mCameraYaw = 0.f;
  78. mCameraDist = -1.f;
  79. LLVOAvatar *avatarp = gAgent.getAvatarObject();
  80. if (!avatarp || avatarp->isDead())
  81. {
  82. gAgent.changeCameraToDefault();
  83. return;
  84. }
  85. avatarp->stopMotion( ANIM_AGENT_BODY_NOISE );
  86. avatarp->mSpecialRenderMode = 3;
  87. // set up camera for close look at avatar
  88. mOldCameraNearClip = LLViewerCamera::getInstance()->getNear();
  89. LLViewerCamera::getInstance()->setNear(MORPH_NEAR_CLIP);
  90. }
  91. //-----------------------------------------------------------------------------
  92. // shutdown()
  93. //-----------------------------------------------------------------------------
  94. void LLMorphView::shutdown()
  95. {
  96. LLVOAvatarSelf::onCustomizeEnd();
  97. LLVOAvatar *avatarp = gAgent.getAvatarObject();
  98. if(avatarp && !avatarp->isDead())
  99. {
  100. avatarp->startMotion( ANIM_AGENT_BODY_NOISE );
  101. avatarp->mSpecialRenderMode = 0;
  102. // reset camera
  103. LLViewerCamera::getInstance()->setNear(mOldCameraNearClip);
  104. }
  105. }
  106. //-----------------------------------------------------------------------------
  107. // setVisible()
  108. //-----------------------------------------------------------------------------
  109. void LLMorphView::setVisible(BOOL visible)
  110. {
  111. if( visible != getVisible() )
  112. {
  113. LLView::setVisible(visible);
  114. if (visible)
  115. {
  116. llassert( !gFloaterCustomize );
  117. gFloaterCustomize = new LLFloaterCustomize();
  118. gFloaterCustomize->fetchInventory();
  119. gFloaterCustomize->openFloater();
  120. // Must do this _after_ gFloaterView is initialized.
  121. gFloaterCustomize->switchToDefaultSubpart();
  122. initialize();
  123. // First run dialog
  124. //LLFirstUse::useAppearance();
  125. }
  126. else
  127. {
  128. if( gFloaterCustomize )
  129. {
  130. gFloaterView->removeChild( gFloaterCustomize );
  131. delete gFloaterCustomize;
  132. gFloaterCustomize = NULL;
  133. }
  134. shutdown();
  135. }
  136. }
  137. }
  138. void LLMorphView::updateCamera()
  139. {
  140. if (!mCameraTargetJoint)
  141. {
  142. setCameraTargetJoint(gAgent.getAvatarObject()->getJoint("mHead"));
  143. }
  144. LLVOAvatar* avatar = gAgent.getAvatarObject();
  145. if( !avatar )
  146. {
  147. return;
  148. }
  149. LLJoint* root_joint = avatar->getRootJoint();
  150. if( !root_joint )
  151. {
  152. return;
  153. }
  154. const LLQuaternion& avatar_rot = root_joint->getWorldRotation();
  155. LLVector3d joint_pos = gAgent.getPosGlobalFromAgent(mCameraTargetJoint->getWorldPosition());
  156. LLVector3d target_pos = joint_pos + mCameraTargetOffset * avatar_rot;
  157. LLQuaternion camera_rot_yaw(mCameraYaw, LLVector3::z_axis);
  158. LLQuaternion camera_rot_pitch(mCameraPitch, LLVector3::y_axis);
  159. LLVector3d camera_pos = joint_pos + mCameraOffset * camera_rot_pitch * camera_rot_yaw * avatar_rot;
  160. gAgent.setCameraPosAndFocusGlobal( camera_pos, target_pos, gAgent.getID() );
  161. }
  162. void LLMorphView::setCameraDrivenByKeys(BOOL b)
  163. {
  164. if( mCameraDrivenByKeys != b )
  165. {
  166. if( b )
  167. {
  168. // Reset to the default camera position specified by mCameraPitch, mCameraYaw, etc.
  169. updateCamera();
  170. }
  171. mCameraDrivenByKeys = b;
  172. }
  173. }