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