diff options
Diffstat (limited to 'linden/indra/newview/llmorphview.cpp')
-rw-r--r-- | linden/indra/newview/llmorphview.cpp | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/linden/indra/newview/llmorphview.cpp b/linden/indra/newview/llmorphview.cpp new file mode 100644 index 0000000..9c56ab3 --- /dev/null +++ b/linden/indra/newview/llmorphview.cpp | |||
@@ -0,0 +1,212 @@ | |||
1 | /** | ||
2 | * @file llmorphview.cpp | ||
3 | * @brief Container for Morph functionality | ||
4 | * | ||
5 | * Copyright (c) 2001-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "llviewerprecompiledheaders.h" | ||
29 | |||
30 | #include "llmorphview.h" | ||
31 | |||
32 | #include "lljoint.h" | ||
33 | |||
34 | #include "llagent.h" | ||
35 | #include "lldrawable.h" | ||
36 | #include "lldrawpoolavatar.h" | ||
37 | #include "llface.h" | ||
38 | #include "llfirstuse.h" | ||
39 | #include "llfloatercustomize.h" | ||
40 | #include "llfloatertools.h" | ||
41 | #include "llresmgr.h" | ||
42 | #include "lltoolmgr.h" | ||
43 | #include "lltoolmorph.h" | ||
44 | #include "llviewercamera.h" | ||
45 | #include "llvoavatar.h" | ||
46 | #include "llviewerwindow.h" | ||
47 | #include "pipeline.h" | ||
48 | #include "viewer.h" | ||
49 | |||
50 | LLMorphView *gMorphView = NULL; | ||
51 | |||
52 | |||
53 | const F32 EDIT_AVATAR_ORBIT_SPEED = 0.1f; | ||
54 | const F32 EDIT_AVATAR_MAX_CAMERA_PITCH = 0.5f; | ||
55 | |||
56 | const F32 CAMERA_MOVE_TIME = 0.5f; | ||
57 | const F32 MORPH_NEAR_CLIP = 0.1f; | ||
58 | |||
59 | const F32 CAMERA_DIST_MIN = 0.4f; | ||
60 | const F32 CAMERA_DIST_MAX = 4.0f; | ||
61 | const F32 CAMERA_DIST_STEP = 1.5f; | ||
62 | |||
63 | //----------------------------------------------------------------------------- | ||
64 | // LLMorphView() | ||
65 | //----------------------------------------------------------------------------- | ||
66 | LLMorphView::LLMorphView(const std::string& name, const LLRect& rect) | ||
67 | : | ||
68 | LLView(name, rect, FALSE, FOLLOWS_ALL), | ||
69 | mCameraTargetJoint( NULL ), | ||
70 | mCameraOffset(-0.5f, 0.05f, 0.07f ), | ||
71 | mCameraTargetOffset(0.f, 0.f, 0.05f ), | ||
72 | mOldCameraNearClip( 0.f ), | ||
73 | mCameraPitch( 0.f ), | ||
74 | mCameraYaw( 0.f ), | ||
75 | mCameraDist( -1.f ), | ||
76 | mCameraDrivenByKeys( FALSE ) | ||
77 | { | ||
78 | } | ||
79 | |||
80 | EWidgetType LLMorphView::getWidgetType() const | ||
81 | { | ||
82 | return WIDGET_TYPE_MORPH_VIEW; | ||
83 | } | ||
84 | |||
85 | LLString LLMorphView::getWidgetTag() const | ||
86 | { | ||
87 | return LL_MORPH_VIEW_TAG; | ||
88 | } | ||
89 | |||
90 | //----------------------------------------------------------------------------- | ||
91 | // initialize() | ||
92 | //----------------------------------------------------------------------------- | ||
93 | void LLMorphView::initialize() | ||
94 | { | ||
95 | mCameraPitch = 0.f; | ||
96 | mCameraYaw = 0.f; | ||
97 | mCameraDist = -1.f; | ||
98 | |||
99 | LLVOAvatar *avatarp = gAgent.getAvatarObject(); | ||
100 | if (!avatarp || avatarp->isDead()) | ||
101 | { | ||
102 | gAgent.changeCameraToDefault(); | ||
103 | return; | ||
104 | } | ||
105 | |||
106 | avatarp->stopMotion( ANIM_AGENT_BODY_NOISE ); | ||
107 | avatarp->mSpecialRenderMode = 3; | ||
108 | |||
109 | // set up camera for close look at avatar | ||
110 | mOldCameraNearClip = gCamera->getNear(); | ||
111 | gCamera->setNear(MORPH_NEAR_CLIP); | ||
112 | } | ||
113 | |||
114 | //----------------------------------------------------------------------------- | ||
115 | // shutdown() | ||
116 | //----------------------------------------------------------------------------- | ||
117 | void LLMorphView::shutdown() | ||
118 | { | ||
119 | LLVOAvatar::onCustomizeEnd(); | ||
120 | |||
121 | LLVOAvatar *avatarp = gAgent.getAvatarObject(); | ||
122 | if(avatarp && !avatarp->isDead()) | ||
123 | { | ||
124 | avatarp->startMotion( ANIM_AGENT_BODY_NOISE ); | ||
125 | avatarp->mSpecialRenderMode = 0; | ||
126 | // reset camera | ||
127 | gCamera->setNear(mOldCameraNearClip); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | |||
132 | //----------------------------------------------------------------------------- | ||
133 | // setVisible() | ||
134 | //----------------------------------------------------------------------------- | ||
135 | void LLMorphView::setVisible(BOOL visible) | ||
136 | { | ||
137 | if( visible != getVisible() ) | ||
138 | { | ||
139 | LLView::setVisible(visible); | ||
140 | |||
141 | if (visible) | ||
142 | { | ||
143 | llassert( !gFloaterCustomize ); | ||
144 | gFloaterCustomize = new LLFloaterCustomize(); | ||
145 | gFloaterCustomize->fetchInventory(); | ||
146 | gFloaterCustomize->open(); | ||
147 | |||
148 | // Must do this _after_ gFloaterView is initialized. | ||
149 | gFloaterCustomize->switchToDefaultSubpart(); | ||
150 | |||
151 | initialize(); | ||
152 | |||
153 | // First run dialog | ||
154 | LLFirstUse::useAppearance(); | ||
155 | } | ||
156 | else | ||
157 | { | ||
158 | if( gFloaterCustomize ) | ||
159 | { | ||
160 | gFloaterView->removeChild( gFloaterCustomize ); | ||
161 | delete gFloaterCustomize; | ||
162 | gFloaterCustomize = NULL; | ||
163 | } | ||
164 | |||
165 | shutdown(); | ||
166 | } | ||
167 | } | ||
168 | } | ||
169 | |||
170 | void LLMorphView::updateCamera() | ||
171 | { | ||
172 | if (!mCameraTargetJoint) | ||
173 | { | ||
174 | setCameraTargetJoint(gAgent.getAvatarObject()->getJoint("mHead")); | ||
175 | } | ||
176 | |||
177 | LLVOAvatar* avatar = gAgent.getAvatarObject(); | ||
178 | if( !avatar ) | ||
179 | { | ||
180 | return; | ||
181 | } | ||
182 | LLJoint* root_joint = avatar->getRootJoint(); | ||
183 | if( !root_joint ) | ||
184 | { | ||
185 | return; | ||
186 | } | ||
187 | |||
188 | const LLQuaternion& avatar_rot = root_joint->getWorldRotation(); | ||
189 | |||
190 | LLVector3d joint_pos = gAgent.getPosGlobalFromAgent(mCameraTargetJoint->getWorldPosition()); | ||
191 | LLVector3d target_pos = joint_pos + mCameraTargetOffset * avatar_rot; | ||
192 | |||
193 | LLQuaternion camera_rot_yaw(mCameraYaw, LLVector3::z_axis); | ||
194 | LLQuaternion camera_rot_pitch(mCameraPitch, LLVector3::y_axis); | ||
195 | |||
196 | LLVector3d camera_pos = joint_pos + mCameraOffset * camera_rot_pitch * camera_rot_yaw * avatar_rot; | ||
197 | |||
198 | gAgent.setCameraPosAndFocusGlobal( camera_pos, target_pos, gAgent.getID() ); | ||
199 | } | ||
200 | |||
201 | void LLMorphView::setCameraDrivenByKeys(BOOL b) | ||
202 | { | ||
203 | if( mCameraDrivenByKeys != b ) | ||
204 | { | ||
205 | if( b ) | ||
206 | { | ||
207 | // Reset to the default camera position specified by mCameraPitch, mCameraYaw, etc. | ||
208 | updateCamera(); | ||
209 | } | ||
210 | mCameraDrivenByKeys = b; | ||
211 | } | ||
212 | } | ||