Annotation of /trunk/linden/indra/newview/llviewerjointattachment.cpp
Parent Directory
|
Revision Log
Revision 57 -
(view)
(download)
Original Path: linden_release/linden/indra/newview/llviewerjointattachment.cpp
| 1 : | mjm | 57 | /** |
| 2 : | * @file llviewerjointattachment.cpp | ||
| 3 : | * @brief Implementation of LLViewerJointAttachment class | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2002&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | * Copyright (c) 2002-2008, 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 http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 21 : | * | ||
| 22 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 23 : | * that you have read and understood your obligations described above, | ||
| 24 : | * and agree to abide by those obligations. | ||
| 25 : | * | ||
| 26 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 27 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 28 : | * COMPLETENESS OR PERFORMANCE. | ||
| 29 : | * $/LicenseInfo$ | ||
| 30 : | */ | ||
| 31 : | |||
| 32 : | #include "llviewerprecompiledheaders.h" | ||
| 33 : | |||
| 34 : | #include "llviewerjointattachment.h" | ||
| 35 : | |||
| 36 : | #include "llagentconstants.h" | ||
| 37 : | |||
| 38 : | #include "llviewercontrol.h" | ||
| 39 : | #include "lldrawable.h" | ||
| 40 : | #include "llgl.h" | ||
| 41 : | #include "llrender.h" | ||
| 42 : | #include "llvoavatar.h" | ||
| 43 : | #include "llvolume.h" | ||
| 44 : | #include "pipeline.h" | ||
| 45 : | #include "llspatialpartition.h" | ||
| 46 : | #include "llinventorymodel.h" | ||
| 47 : | #include "llviewerobjectlist.h" | ||
| 48 : | #include "llface.h" | ||
| 49 : | #include "llvoavatar.h" | ||
| 50 : | |||
| 51 : | #include "llglheaders.h" | ||
| 52 : | |||
| 53 : | extern LLPipeline gPipeline; | ||
| 54 : | |||
| 55 : | //----------------------------------------------------------------------------- | ||
| 56 : | // LLViewerJointAttachment() | ||
| 57 : | //----------------------------------------------------------------------------- | ||
| 58 : | LLViewerJointAttachment::LLViewerJointAttachment() : | ||
| 59 : | mAttachedObject(NULL), | ||
| 60 : | mVisibleInFirst(FALSE), | ||
| 61 : | mGroup(0), | ||
| 62 : | mIsHUDAttachment(FALSE), | ||
| 63 : | mPieSlice(-1) | ||
| 64 : | { | ||
| 65 : | mValid = FALSE; | ||
| 66 : | mUpdateXform = FALSE; | ||
| 67 : | } | ||
| 68 : | |||
| 69 : | //----------------------------------------------------------------------------- | ||
| 70 : | // ~LLViewerJointAttachment() | ||
| 71 : | //----------------------------------------------------------------------------- | ||
| 72 : | LLViewerJointAttachment::~LLViewerJointAttachment() | ||
| 73 : | { | ||
| 74 : | } | ||
| 75 : | |||
| 76 : | //----------------------------------------------------------------------------- | ||
| 77 : | // isTransparent() | ||
| 78 : | //----------------------------------------------------------------------------- | ||
| 79 : | BOOL LLViewerJointAttachment::isTransparent() | ||
| 80 : | { | ||
| 81 : | return FALSE; | ||
| 82 : | } | ||
| 83 : | |||
| 84 : | //----------------------------------------------------------------------------- | ||
| 85 : | // drawShape() | ||
| 86 : | //----------------------------------------------------------------------------- | ||
| 87 : | U32 LLViewerJointAttachment::drawShape( F32 pixelArea, BOOL first_pass ) | ||
| 88 : | { | ||
| 89 : | if (LLVOAvatar::sShowAttachmentPoints) | ||
| 90 : | { | ||
| 91 : | LLGLDisable cull_face(GL_CULL_FACE); | ||
| 92 : | |||
| 93 : | gGL.color4f(1.f, 1.f, 1.f, 1.f); | ||
| 94 : | gGL.begin(LLVertexBuffer::QUADS); | ||
| 95 : | { | ||
| 96 : | gGL.vertex3f(-0.1f, 0.1f, 0.f); | ||
| 97 : | gGL.vertex3f(-0.1f, -0.1f, 0.f); | ||
| 98 : | gGL.vertex3f(0.1f, -0.1f, 0.f); | ||
| 99 : | gGL.vertex3f(0.1f, 0.1f, 0.f); | ||
| 100 : | }gGL.end(); | ||
| 101 : | } | ||
| 102 : | return 0; | ||
| 103 : | } | ||
| 104 : | |||
| 105 : | void LLViewerJointAttachment::setupDrawable(LLDrawable* drawablep) | ||
| 106 : | { | ||
| 107 : | drawablep->mXform.setParent(&mXform); // LLViewerJointAttachment::lazyAttach | ||
| 108 : | drawablep->makeActive(); | ||
| 109 : | LLVector3 current_pos = mAttachedObject->getRenderPosition(); | ||
| 110 : | LLQuaternion current_rot = mAttachedObject->getRenderRotation(); | ||
| 111 : | LLQuaternion attachment_pt_inv_rot = ~getWorldRotation(); | ||
| 112 : | |||
| 113 : | current_pos -= getWorldPosition(); | ||
| 114 : | current_pos.rotVec(attachment_pt_inv_rot); | ||
| 115 : | |||
| 116 : | current_rot = current_rot * attachment_pt_inv_rot; | ||
| 117 : | |||
| 118 : | drawablep->mXform.setPosition(current_pos); | ||
| 119 : | drawablep->mXform.setRotation(current_rot); | ||
| 120 : | gPipeline.markMoved(drawablep); | ||
| 121 : | gPipeline.markTextured(drawablep); // face may need to change draw pool to/from POOL_HUD | ||
| 122 : | drawablep->setState(LLDrawable::USE_BACKLIGHT); | ||
| 123 : | |||
| 124 : | if(mIsHUDAttachment) | ||
| 125 : | { | ||
| 126 : | for (S32 face_num = 0; face_num < drawablep->getNumFaces(); face_num++) | ||
| 127 : | { | ||
| 128 : | drawablep->getFace(face_num)->setState(LLFace::HUD_RENDER); | ||
| 129 : | } | ||
| 130 : | } | ||
| 131 : | |||
| 132 : | LLViewerObject::const_child_list_t& child_list = mAttachedObject->getChildren(); | ||
| 133 : | for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin(); | ||
| 134 : | iter != child_list.end(); iter++) | ||
| 135 : | { | ||
| 136 : | LLViewerObject* childp = *iter; | ||
| 137 : | if (childp && childp->mDrawable.notNull()) | ||
| 138 : | { | ||
| 139 : | childp->mDrawable->setState(LLDrawable::USE_BACKLIGHT); | ||
| 140 : | gPipeline.markTextured(childp->mDrawable); // face may need to change draw pool to/from POOL_HUD | ||
| 141 : | if(mIsHUDAttachment) | ||
| 142 : | { | ||
| 143 : | for (S32 face_num = 0; face_num < childp->mDrawable->getNumFaces(); face_num++) | ||
| 144 : | { | ||
| 145 : | childp->mDrawable->getFace(face_num)->setState(LLFace::HUD_RENDER); | ||
| 146 : | } | ||
| 147 : | } | ||
| 148 : | } | ||
| 149 : | } | ||
| 150 : | } | ||
| 151 : | |||
| 152 : | //----------------------------------------------------------------------------- | ||
| 153 : | // addObject() | ||
| 154 : | //----------------------------------------------------------------------------- | ||
| 155 : | BOOL LLViewerJointAttachment::addObject(LLViewerObject* object) | ||
| 156 : | { | ||
| 157 : | if (mAttachedObject) | ||
| 158 : | { | ||
| 159 : | llwarns << "Attempted to attach object where an attachment already exists!" << llendl; | ||
| 160 : | |||
| 161 : | if (mAttachedObject == object) { | ||
| 162 : | llinfos << "(same object re-attached)" << llendl; | ||
| 163 : | removeObject(mAttachedObject); | ||
| 164 : | // Pass through anyway to let setupDrawable() | ||
| 165 : | // re-connect object to the joint correctly | ||
| 166 : | } | ||
| 167 : | else { | ||
| 168 : | llinfos << "(objects differ, removing existing object)" << llendl; | ||
| 169 : | // Rather hacky, but no-one can think of something | ||
| 170 : | // better to do for this case. | ||
| 171 : | gObjectList.killObject(mAttachedObject); | ||
| 172 : | // Proceed with new object attachment | ||
| 173 : | } | ||
| 174 : | } | ||
| 175 : | mAttachedObject = object; | ||
| 176 : | |||
| 177 : | LLUUID item_id; | ||
| 178 : | |||
| 179 : | // Find the inventory item ID of the attached object | ||
| 180 : | LLNameValue* item_id_nv = object->getNVPair("AttachItemID"); | ||
| 181 : | if( item_id_nv ) | ||
| 182 : | { | ||
| 183 : | const char* s = item_id_nv->getString(); | ||
| 184 : | if( s ) | ||
| 185 : | { | ||
| 186 : | item_id.set( s ); | ||
| 187 : | lldebugs << "getNVPair( AttachItemID ) = " << item_id << llendl; | ||
| 188 : | } | ||
| 189 : | } | ||
| 190 : | |||
| 191 : | mItemID = item_id; | ||
| 192 : | |||
| 193 : | LLDrawable* drawablep = object->mDrawable; | ||
| 194 : | |||
| 195 : | if (drawablep) | ||
| 196 : | { | ||
| 197 : | //if object is active, make it static | ||
| 198 : | if(drawablep->isActive()) | ||
| 199 : | { | ||
| 200 : | drawablep->makeStatic(FALSE) ; | ||
| 201 : | } | ||
| 202 : | |||
| 203 : | setupDrawable(drawablep); | ||
| 204 : | } | ||
| 205 : | |||
| 206 : | if (mIsHUDAttachment) | ||
| 207 : | { | ||
| 208 : | if (object->mText.notNull()) | ||
| 209 : | { | ||
| 210 : | object->mText->setOnHUDAttachment(TRUE); | ||
| 211 : | } | ||
| 212 : | LLViewerObject::const_child_list_t& child_list = object->getChildren(); | ||
| 213 : | for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin(); | ||
| 214 : | iter != child_list.end(); iter++) | ||
| 215 : | { | ||
| 216 : | LLViewerObject* childp = *iter; | ||
| 217 : | if (childp && childp->mText.notNull()) | ||
| 218 : | { | ||
| 219 : | childp->mText->setOnHUDAttachment(TRUE); | ||
| 220 : | } | ||
| 221 : | } | ||
| 222 : | } | ||
| 223 : | calcLOD(); | ||
| 224 : | mUpdateXform = TRUE; | ||
| 225 : | |||
| 226 : | return TRUE; | ||
| 227 : | } | ||
| 228 : | |||
| 229 : | //----------------------------------------------------------------------------- | ||
| 230 : | // removeObject() | ||
| 231 : | //----------------------------------------------------------------------------- | ||
| 232 : | void LLViewerJointAttachment::removeObject(LLViewerObject *object) | ||
| 233 : | { | ||
| 234 : | // force object visibile | ||
| 235 : | setAttachmentVisibility(TRUE); | ||
| 236 : | |||
| 237 : | if (object->mDrawable.notNull()) | ||
| 238 : | { | ||
| 239 : | //if object is active, make it static | ||
| 240 : | if(object->mDrawable->isActive()) | ||
| 241 : | { | ||
| 242 : | object->mDrawable->makeStatic(FALSE) ; | ||
| 243 : | } | ||
| 244 : | |||
| 245 : | LLVector3 cur_position = object->getRenderPosition(); | ||
| 246 : | LLQuaternion cur_rotation = object->getRenderRotation(); | ||
| 247 : | |||
| 248 : | object->mDrawable->mXform.setPosition(cur_position); | ||
| 249 : | object->mDrawable->mXform.setRotation(cur_rotation); | ||
| 250 : | gPipeline.markMoved(object->mDrawable, TRUE); | ||
| 251 : | gPipeline.markTextured(object->mDrawable); // face may need to change draw pool to/from POOL_HUD | ||
| 252 : | object->mDrawable->clearState(LLDrawable::USE_BACKLIGHT); | ||
| 253 : | |||
| 254 : | if (mIsHUDAttachment) | ||
| 255 : | { | ||
| 256 : | for (S32 face_num = 0; face_num < object->mDrawable->getNumFaces(); face_num++) | ||
| 257 : | { | ||
| 258 : | object->mDrawable->getFace(face_num)->clearState(LLFace::HUD_RENDER); | ||
| 259 : | } | ||
| 260 : | } | ||
| 261 : | } | ||
| 262 : | |||
| 263 : | LLViewerObject::const_child_list_t& child_list = object->getChildren(); | ||
| 264 : | for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin(); | ||
| 265 : | iter != child_list.end(); iter++) | ||
| 266 : | { | ||
| 267 : | LLViewerObject* childp = *iter; | ||
| 268 : | if (childp && childp->mDrawable.notNull()) | ||
| 269 : | { | ||
| 270 : | childp->mDrawable->clearState(LLDrawable::USE_BACKLIGHT); | ||
| 271 : | gPipeline.markTextured(childp->mDrawable); // face may need to change draw pool to/from POOL_HUD | ||
| 272 : | if (mIsHUDAttachment) | ||
| 273 : | { | ||
| 274 : | for (S32 face_num = 0; face_num < childp->mDrawable->getNumFaces(); face_num++) | ||
| 275 : | { | ||
| 276 : | childp->mDrawable->getFace(face_num)->clearState(LLFace::HUD_RENDER); | ||
| 277 : | } | ||
| 278 : | } | ||
| 279 : | } | ||
| 280 : | } | ||
| 281 : | |||
| 282 : | if (mIsHUDAttachment) | ||
| 283 : | { | ||
| 284 : | if (object->mText.notNull()) | ||
| 285 : | { | ||
| 286 : | object->mText->setOnHUDAttachment(FALSE); | ||
| 287 : | } | ||
| 288 : | LLViewerObject::const_child_list_t& child_list = object->getChildren(); | ||
| 289 : | for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin(); | ||
| 290 : | iter != child_list.end(); iter++) | ||
| 291 : | { | ||
| 292 : | LLViewerObject* childp = *iter; | ||
| 293 : | if (childp->mText.notNull()) | ||
| 294 : | { | ||
| 295 : | childp->mText->setOnHUDAttachment(FALSE); | ||
| 296 : | } | ||
| 297 : | } | ||
| 298 : | } | ||
| 299 : | |||
| 300 : | mAttachedObject = NULL; | ||
| 301 : | mUpdateXform = FALSE; | ||
| 302 : | mItemID.setNull(); | ||
| 303 : | } | ||
| 304 : | |||
| 305 : | //----------------------------------------------------------------------------- | ||
| 306 : | // setAttachmentVisibility() | ||
| 307 : | //----------------------------------------------------------------------------- | ||
| 308 : | void LLViewerJointAttachment::setAttachmentVisibility(BOOL visible) | ||
| 309 : | { | ||
| 310 : | if (!mAttachedObject || mAttachedObject->mDrawable.isNull() || | ||
| 311 : | !(mAttachedObject->mDrawable->getSpatialBridge())) | ||
| 312 : | return; | ||
| 313 : | |||
| 314 : | if (visible) | ||
| 315 : | { | ||
| 316 : | // Hack to make attachments not visible by disabling their type mask! | ||
| 317 : | // This will break if you can ever attach non-volumes! - djs 02/14/03 | ||
| 318 : | mAttachedObject->mDrawable->getSpatialBridge()->mDrawableType = | ||
| 319 : | mAttachedObject->isHUDAttachment() ? LLPipeline::RENDER_TYPE_HUD : LLPipeline::RENDER_TYPE_VOLUME; | ||
| 320 : | } | ||
| 321 : | else | ||
| 322 : | { | ||
| 323 : | mAttachedObject->mDrawable->getSpatialBridge()->mDrawableType = 0; | ||
| 324 : | } | ||
| 325 : | } | ||
| 326 : | |||
| 327 : | //----------------------------------------------------------------------------- | ||
| 328 : | // setOriginalPosition() | ||
| 329 : | //----------------------------------------------------------------------------- | ||
| 330 : | void LLViewerJointAttachment::setOriginalPosition(LLVector3& position) | ||
| 331 : | { | ||
| 332 : | mOriginalPos = position; | ||
| 333 : | setPosition(position); | ||
| 334 : | } | ||
| 335 : | |||
| 336 : | //----------------------------------------------------------------------------- | ||
| 337 : | // clampObjectPosition() | ||
| 338 : | //----------------------------------------------------------------------------- | ||
| 339 : | void LLViewerJointAttachment::clampObjectPosition() | ||
| 340 : | { | ||
| 341 : | if (mAttachedObject) | ||
| 342 : | { | ||
| 343 : | // *NOTE: object can drift when hitting maximum radius | ||
| 344 : | LLVector3 attachmentPos = mAttachedObject->getPosition(); | ||
| 345 : | F32 dist = attachmentPos.normVec(); | ||
| 346 : | dist = llmin(dist, MAX_ATTACHMENT_DIST); | ||
| 347 : | attachmentPos *= dist; | ||
| 348 : | mAttachedObject->setPosition(attachmentPos); | ||
| 349 : | } | ||
| 350 : | } | ||
| 351 : | |||
| 352 : | //----------------------------------------------------------------------------- | ||
| 353 : | // calcLOD() | ||
| 354 : | //----------------------------------------------------------------------------- | ||
| 355 : | void LLViewerJointAttachment::calcLOD() | ||
| 356 : | { | ||
| 357 : | F32 maxarea = mAttachedObject->getMaxScale() * mAttachedObject->getMidScale(); | ||
| 358 : | LLViewerObject::const_child_list_t& child_list = mAttachedObject->getChildren(); | ||
| 359 : | for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin(); | ||
| 360 : | iter != child_list.end(); iter++) | ||
| 361 : | { | ||
| 362 : | LLViewerObject* childp = *iter; | ||
| 363 : | F32 area = childp->getMaxScale() * childp->getMidScale(); | ||
| 364 : | maxarea = llmax(maxarea, area); | ||
| 365 : | } | ||
| 366 : | maxarea = llclamp(maxarea, .01f*.01f, 1.f); | ||
| 367 : | F32 avatar_area = (4.f * 4.f); // pixels for an avatar sized attachment | ||
| 368 : | F32 min_pixel_area = avatar_area / maxarea; | ||
| 369 : | setLOD(min_pixel_area); | ||
| 370 : | } | ||
| 371 : | |||
| 372 : | //----------------------------------------------------------------------------- | ||
| 373 : | // updateLOD() | ||
| 374 : | //----------------------------------------------------------------------------- | ||
| 375 : | BOOL LLViewerJointAttachment::updateLOD(F32 pixel_area, BOOL activate) | ||
| 376 : | { | ||
| 377 : | BOOL res = FALSE; | ||
| 378 : | if (!mValid) | ||
| 379 : | { | ||
| 380 : | setValid(TRUE, TRUE); | ||
| 381 : | res = TRUE; | ||
| 382 : | } | ||
| 383 : | return res; | ||
| 384 : | } | ||
| 385 : |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

