aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llviewerjointattachment.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llviewerjointattachment.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llviewerjointattachment.cpp')
-rw-r--r--linden/indra/newview/llviewerjointattachment.cpp400
1 files changed, 400 insertions, 0 deletions
diff --git a/linden/indra/newview/llviewerjointattachment.cpp b/linden/indra/newview/llviewerjointattachment.cpp
new file mode 100644
index 0000000..89db44d
--- /dev/null
+++ b/linden/indra/newview/llviewerjointattachment.cpp
@@ -0,0 +1,400 @@
1/**
2 * @file llviewerjointattachment.cpp
3 * @brief Implementation of LLViewerJointAttachment class
4 *
5 * Copyright (c) 2002-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 "llviewerjointattachment.h"
31
32#include "llagentconstants.h"
33
34#include "llviewercontrol.h"
35#include "lldrawable.h"
36#include "llgl.h"
37#include "llvoavatar.h"
38#include "llvolume.h"
39#include "pipeline.h"
40#include "llinventorymodel.h"
41#include "llviewerobjectlist.h"
42#include "llface.h"
43#include "llvoavatar.h"
44
45#include "llglheaders.h"
46
47extern LLPipeline gPipeline;
48
49//-----------------------------------------------------------------------------
50// LLViewerJointAttachment()
51//-----------------------------------------------------------------------------
52LLViewerJointAttachment::LLViewerJointAttachment()
53{
54 mJoint = NULL;
55 mAttachedObject = NULL;
56 mAttachmentDirty = FALSE;
57 mGroup = 0;
58 mUpdateXform = FALSE;
59 mIsHUDAttachment = FALSE;
60 mValid = FALSE;
61 mPieSlice = -1;
62}
63
64//-----------------------------------------------------------------------------
65// ~LLViewerJointAttachment()
66//-----------------------------------------------------------------------------
67LLViewerJointAttachment::~LLViewerJointAttachment()
68{
69}
70
71//-----------------------------------------------------------------------------
72// isTransparent()
73//-----------------------------------------------------------------------------
74BOOL LLViewerJointAttachment::isTransparent()
75{
76 return FALSE;
77}
78
79//-----------------------------------------------------------------------------
80// drawShape()
81//-----------------------------------------------------------------------------
82U32 LLViewerJointAttachment::drawShape( F32 pixelArea )
83{
84 if (LLVOAvatar::sShowAttachmentPoints)
85 {
86 LLGLDisable cull_face(GL_CULL_FACE);
87
88 glColor4f(1.f, 1.f, 1.f, 1.f);
89 glBegin(GL_QUADS);
90 {
91 glVertex3f(-0.1f, 0.1f, 0.f);
92 glVertex3f(-0.1f, -0.1f, 0.f);
93 glVertex3f(0.1f, -0.1f, 0.f);
94 glVertex3f(0.1f, 0.1f, 0.f);
95 }glEnd();
96 }
97 return 0;
98}
99
100//-----------------------------------------------------------------------------
101// lazyAttach()
102//-----------------------------------------------------------------------------
103void LLViewerJointAttachment::lazyAttach()
104{
105 if (!mAttachedObject)
106 {
107 return;
108 }
109 LLDrawable *drawablep = mAttachedObject->mDrawable;
110
111 if (mAttachmentDirty && drawablep)
112 {
113 setupDrawable(drawablep);
114 mAttachmentDirty = FALSE;
115 }
116}
117
118void LLViewerJointAttachment::setupDrawable(LLDrawable* drawablep)
119{
120 drawablep->mXform.setParent(&mXform); // LLViewerJointAttachment::lazyAttach
121 drawablep->makeActive();
122 LLVector3 current_pos = mAttachedObject->getRenderPosition();
123 LLQuaternion current_rot = mAttachedObject->getRenderRotation();
124 LLQuaternion attachment_pt_inv_rot = ~getWorldRotation();
125
126 current_pos -= getWorldPosition();
127 current_pos.rotVec(attachment_pt_inv_rot);
128
129 current_rot = current_rot * attachment_pt_inv_rot;
130
131 drawablep->mXform.setPosition(current_pos);
132 drawablep->mXform.setRotation(current_rot);
133 gPipeline.markMoved(drawablep);
134 gPipeline.markTextured(drawablep); // face may need to change draw pool to/from POOL_HUD
135 drawablep->setState(LLDrawable::USE_BACKLIGHT);
136
137 if(mIsHUDAttachment)
138 {
139 for (S32 face_num = 0; face_num < drawablep->getNumFaces(); face_num++)
140 {
141 drawablep->getFace(face_num)->setState(LLFace::HUD_RENDER);
142 }
143 }
144
145 for (LLViewerObject::child_list_t::iterator iter = mAttachedObject->mChildList.begin();
146 iter != mAttachedObject->mChildList.end(); ++iter)
147 {
148 LLViewerObject* childp = *iter;
149 if (childp && childp->mDrawable.notNull())
150 {
151 childp->mDrawable->setState(LLDrawable::USE_BACKLIGHT);
152 gPipeline.markTextured(childp->mDrawable); // face may need to change draw pool to/from POOL_HUD
153 if(mIsHUDAttachment)
154 {
155 for (S32 face_num = 0; face_num < childp->mDrawable->getNumFaces(); face_num++)
156 {
157 childp->mDrawable->getFace(face_num)->setState(LLFace::HUD_RENDER);
158 }
159 }
160 }
161 }
162}
163
164//-----------------------------------------------------------------------------
165// addObject()
166//-----------------------------------------------------------------------------
167BOOL LLViewerJointAttachment::addObject(LLViewerObject* object)
168{
169 if (mAttachedObject)
170 {
171 llwarns << "Attempted to attach object where an attachment already exists!" << llendl;
172 return FALSE;
173 }
174 mAttachedObject = object;
175
176 LLUUID item_id;
177
178 // Find the inventory item ID of the attached object
179 LLNameValue* item_id_nv = object->getNVPair("AttachItemID");
180 if( item_id_nv )
181 {
182 const char* s = item_id_nv->getString();
183 if( s )
184 {
185 item_id.set( s );
186 lldebugs << "getNVPair( AttachItemID ) = " << item_id << llendl;
187 }
188 }
189
190 mItemID = item_id;
191
192 LLDrawable* drawablep = object->mDrawable;
193
194 if (drawablep)
195 {
196 setupDrawable(drawablep);
197 }
198 else
199 {
200 // do lazy update once we have a drawable for this object
201 mAttachmentDirty = TRUE;
202 }
203
204 if (mIsHUDAttachment)
205 {
206 if (object->mText.notNull())
207 {
208 object->mText->setOnHUDAttachment(TRUE);
209 }
210 for (LLViewerObject::child_list_t::iterator iter = object->mChildList.begin();
211 iter != object->mChildList.end(); ++iter)
212 {
213 LLViewerObject* childp = *iter;
214 if (childp && childp->mText.notNull())
215 {
216 childp->mText->setOnHUDAttachment(TRUE);
217 }
218 }
219 }
220 calcLOD();
221 mUpdateXform = TRUE;
222
223 return TRUE;
224}
225
226//-----------------------------------------------------------------------------
227// removeObject()
228//-----------------------------------------------------------------------------
229void LLViewerJointAttachment::removeObject(LLViewerObject *object)
230{
231 // force object visibile
232 setAttachmentVisibility(TRUE);
233
234 if (object->mDrawable.notNull())
235 {
236 LLVector3 cur_position = object->getRenderPosition();
237 LLQuaternion cur_rotation = object->getRenderRotation();
238
239 object->mDrawable->mXform.setPosition(cur_position);
240 object->mDrawable->mXform.setRotation(cur_rotation);
241 gPipeline.markMoved(object->mDrawable, TRUE);
242 gPipeline.markTextured(object->mDrawable); // face may need to change draw pool to/from POOL_HUD
243 object->mDrawable->clearState(LLDrawable::USE_BACKLIGHT);
244
245 if (mIsHUDAttachment)
246 {
247 for (S32 face_num = 0; face_num < object->mDrawable->getNumFaces(); face_num++)
248 {
249 object->mDrawable->getFace(face_num)->clearState(LLFace::HUD_RENDER);
250 }
251 }
252 }
253
254 for (LLViewerObject::child_list_t::iterator iter = object->mChildList.begin();
255 iter != object->mChildList.end(); ++iter)
256 {
257 LLViewerObject* childp = *iter;
258 if (childp && childp->mDrawable.notNull())
259 {
260 childp->mDrawable->clearState(LLDrawable::USE_BACKLIGHT);
261 gPipeline.markTextured(childp->mDrawable); // face may need to change draw pool to/from POOL_HUD
262 if (mIsHUDAttachment)
263 {
264 for (S32 face_num = 0; face_num < childp->mDrawable->getNumFaces(); face_num++)
265 {
266 childp->mDrawable->getFace(face_num)->clearState(LLFace::HUD_RENDER);
267 }
268 }
269 }
270 }
271
272 if (mIsHUDAttachment)
273 {
274 if (object->mText.notNull())
275 {
276 object->mText->setOnHUDAttachment(FALSE);
277 }
278 for (LLViewerObject::child_list_t::iterator iter = object->mChildList.begin();
279 iter != object->mChildList.end(); ++iter)
280 {
281 LLViewerObject* childp = *iter;
282 if (childp->mText.notNull())
283 {
284 childp->mText->setOnHUDAttachment(FALSE);
285 }
286 }
287 }
288
289 mAttachedObject = NULL;
290 mUpdateXform = FALSE;
291 mItemID.setNull();
292}
293
294//-----------------------------------------------------------------------------
295// setAttachmentVisibility()
296//-----------------------------------------------------------------------------
297void LLViewerJointAttachment::setAttachmentVisibility(BOOL visible)
298{
299 if (!mAttachedObject || mAttachedObject->mDrawable.isNull())
300 return;
301
302 if (visible)
303 {
304 // Hack to make attachments not visible by disabling their type mask!
305 // This will break if you can ever attach non-volumes! - djs 02/14/03
306 mAttachedObject->mDrawable->setRenderType(LLPipeline::RENDER_TYPE_VOLUME);
307 for (LLViewerObject::child_list_t::iterator iter = mAttachedObject->mChildList.begin();
308 iter != mAttachedObject->mChildList.end(); ++iter)
309 {
310 LLViewerObject* childp = *iter;
311 if (childp && childp->mDrawable.notNull())
312 {
313 childp->mDrawable->setRenderType(LLPipeline::RENDER_TYPE_VOLUME);
314 }
315 }
316 }
317 else
318 {
319 //RN: sometimes we call this on objects that are already invisible, so check for that case
320 if (!mAttachedObject->mDrawable->isRenderType(LLPipeline::RENDER_TYPE_VOLUME) &&
321 !mAttachedObject->mDrawable->isRenderType(0))
322 {
323 llerrs << "Tried to attach non-volume to a joint, visibility hack dangerous!" << llendl;
324 }
325 mAttachedObject->mDrawable->setRenderType(0);
326 for (LLViewerObject::child_list_t::iterator iter = mAttachedObject->mChildList.begin();
327 iter != mAttachedObject->mChildList.end(); ++iter)
328 {
329 LLViewerObject* childp = *iter;
330 if (childp && childp->mDrawable.notNull())
331 {
332 if (!childp->mDrawable->isRenderType(LLPipeline::RENDER_TYPE_VOLUME) &&
333 !mAttachedObject->mDrawable->isRenderType(0))
334 {
335 llerrs << "Tried to attach non-volume to a joint, visibility hack dangerous!" << llendl;
336 }
337 childp->mDrawable->setRenderType(0);
338 }
339 }
340 }
341}
342
343//-----------------------------------------------------------------------------
344// setOriginalPosition()
345//-----------------------------------------------------------------------------
346void LLViewerJointAttachment::setOriginalPosition(LLVector3& position)
347{
348 mOriginalPos = position;
349 setPosition(position);
350}
351
352//-----------------------------------------------------------------------------
353// clampObjectPosition()
354//-----------------------------------------------------------------------------
355void LLViewerJointAttachment::clampObjectPosition()
356{
357 if (mAttachedObject)
358 {
359 // *NOTE: object can drift when hitting maximum radius
360 LLVector3 attachmentPos = mAttachedObject->getPosition();
361 F32 dist = attachmentPos.normVec();
362 dist = llmin(dist, MAX_ATTACHMENT_DIST);
363 attachmentPos *= dist;
364 mAttachedObject->setPosition(attachmentPos);
365 }
366}
367
368//-----------------------------------------------------------------------------
369// calcLOD()
370//-----------------------------------------------------------------------------
371void LLViewerJointAttachment::calcLOD()
372{
373 F32 maxarea = mAttachedObject->getMaxScale() * mAttachedObject->getMidScale();
374 for (LLViewerObject::child_list_t::iterator iter = mAttachedObject->mChildList.begin();
375 iter != mAttachedObject->mChildList.end(); ++iter)
376 {
377 LLViewerObject* childp = *iter;
378 F32 area = childp->getMaxScale() * childp->getMidScale();
379 maxarea = llmax(maxarea, area);
380 }
381 maxarea = llclamp(maxarea, .01f*.01f, 1.f);
382 F32 avatar_area = (4.f * 4.f); // pixels for an avatar sized attachment
383 F32 min_pixel_area = avatar_area / maxarea;
384 setLOD(min_pixel_area);
385}
386
387//-----------------------------------------------------------------------------
388// updateLOD()
389//-----------------------------------------------------------------------------
390BOOL LLViewerJointAttachment::updateLOD(F32 pixel_area, BOOL activate)
391{
392 BOOL res = FALSE;
393 if (!mValid)
394 {
395 setValid(TRUE, TRUE);
396 res = TRUE;
397 }
398 return res;
399}
400