PageRenderTime 197ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llmorphview.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 177 lines | 104 code | 28 blank | 45 comment | 12 complexity | ab294ec55dd4afee9299605bc5ee992f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llmorphview.cpp
  3. * @brief Container for Morph functionality
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llmorphview.h"
  28. #include "lljoint.h"
  29. #include "llagent.h"
  30. #include "llagentcamera.h"
  31. #include "lldrawable.h"
  32. #include "lldrawpoolavatar.h"
  33. #include "llface.h"
  34. //#include "llfirstuse.h"
  35. #include "llfloatertools.h"
  36. #include "llresmgr.h"
  37. #include "lltoolmgr.h"
  38. #include "lltoolmorph.h"
  39. #include "llviewercamera.h"
  40. #include "llvoavatarself.h"
  41. #include "llviewerwindow.h"
  42. #include "pipeline.h"
  43. LLMorphView *gMorphView = NULL;
  44. const F32 EDIT_AVATAR_ORBIT_SPEED = 0.1f;
  45. const F32 EDIT_AVATAR_MAX_CAMERA_PITCH = 0.5f;
  46. const F32 CAMERA_MOVE_TIME = 0.5f;
  47. const F32 MORPH_NEAR_CLIP = 0.1f;
  48. const F32 CAMERA_DIST_MIN = 0.4f;
  49. const F32 CAMERA_DIST_MAX = 4.0f;
  50. const F32 CAMERA_DIST_STEP = 1.5f;
  51. //-----------------------------------------------------------------------------
  52. // LLMorphView()
  53. //-----------------------------------------------------------------------------
  54. LLMorphView::LLMorphView(const LLMorphView::Params& p)
  55. : LLView(p),
  56. mCameraTargetJoint( NULL ),
  57. mCameraOffset(-0.5f, 0.05f, 0.07f ),
  58. mCameraTargetOffset(0.f, 0.f, 0.05f ),
  59. mOldCameraNearClip( 0.f ),
  60. mCameraPitch( 0.f ),
  61. mCameraYaw( 0.f ),
  62. mCameraDrivenByKeys( FALSE )
  63. {}
  64. //-----------------------------------------------------------------------------
  65. // initialize()
  66. //-----------------------------------------------------------------------------
  67. void LLMorphView::initialize()
  68. {
  69. mCameraPitch = 0.f;
  70. mCameraYaw = 0.f;
  71. if (!isAgentAvatarValid() || gAgentAvatarp->isDead())
  72. {
  73. gAgentCamera.changeCameraToDefault();
  74. return;
  75. }
  76. gAgentAvatarp->stopMotion( ANIM_AGENT_BODY_NOISE );
  77. gAgentAvatarp->mSpecialRenderMode = 3;
  78. // set up camera for close look at avatar
  79. mOldCameraNearClip = LLViewerCamera::getInstance()->getNear();
  80. LLViewerCamera::getInstance()->setNear(MORPH_NEAR_CLIP);
  81. }
  82. //-----------------------------------------------------------------------------
  83. // shutdown()
  84. //-----------------------------------------------------------------------------
  85. void LLMorphView::shutdown()
  86. {
  87. LLVOAvatarSelf::onCustomizeEnd();
  88. if (isAgentAvatarValid())
  89. {
  90. gAgentAvatarp->startMotion( ANIM_AGENT_BODY_NOISE );
  91. gAgentAvatarp->mSpecialRenderMode = 0;
  92. // reset camera
  93. LLViewerCamera::getInstance()->setNear(mOldCameraNearClip);
  94. }
  95. }
  96. //-----------------------------------------------------------------------------
  97. // setVisible()
  98. //-----------------------------------------------------------------------------
  99. void LLMorphView::setVisible(BOOL visible)
  100. {
  101. if( visible != getVisible() )
  102. {
  103. LLView::setVisible(visible);
  104. if (visible)
  105. {
  106. // TODO: verify some user action has already opened outfit editor? - Nyx
  107. initialize();
  108. // First run dialog
  109. //LLFirstUse::useAppearance();
  110. }
  111. else
  112. {
  113. // TODO: verify some user action has already closed outfit editor ? - Nyx
  114. shutdown();
  115. }
  116. }
  117. }
  118. void LLMorphView::updateCamera()
  119. {
  120. if (!mCameraTargetJoint)
  121. {
  122. setCameraTargetJoint(gAgentAvatarp->getJoint("mHead"));
  123. }
  124. if (!isAgentAvatarValid()) return;
  125. LLJoint* root_joint = gAgentAvatarp->getRootJoint();
  126. if( !root_joint )
  127. {
  128. return;
  129. }
  130. const LLQuaternion& avatar_rot = root_joint->getWorldRotation();
  131. LLVector3d joint_pos = gAgent.getPosGlobalFromAgent(mCameraTargetJoint->getWorldPosition());
  132. LLVector3d target_pos = joint_pos + mCameraTargetOffset * avatar_rot;
  133. LLQuaternion camera_rot_yaw(mCameraYaw, LLVector3::z_axis);
  134. LLQuaternion camera_rot_pitch(mCameraPitch, LLVector3::y_axis);
  135. LLVector3d camera_pos = joint_pos + mCameraOffset * camera_rot_pitch * camera_rot_yaw * avatar_rot;
  136. gAgentCamera.setCameraPosAndFocusGlobal( camera_pos, target_pos, gAgent.getID() );
  137. }
  138. void LLMorphView::setCameraDrivenByKeys(BOOL b)
  139. {
  140. if( mCameraDrivenByKeys != b )
  141. {
  142. if( b )
  143. {
  144. // Reset to the default camera position specified by mCameraPitch, mCameraYaw, etc.
  145. updateCamera();
  146. }
  147. mCameraDrivenByKeys = b;
  148. }
  149. }