00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034
00035 #include "lltoolmorph.h"
00036
00037
00038 #include "audioengine.h"
00039 #include "llviewercontrol.h"
00040 #include "llfontgl.h"
00041 #include "sound_ids.h"
00042 #include "v3math.h"
00043 #include "v3color.h"
00044
00045
00046 #include "llagent.h"
00047 #include "lldrawable.h"
00048 #include "lldrawpoolavatar.h"
00049 #include "llface.h"
00050 #include "llfloatercustomize.h"
00051 #include "llmorphview.h"
00052 #include "llresmgr.h"
00053 #include "llselectmgr.h"
00054 #include "llsky.h"
00055 #include "lltexlayer.h"
00056 #include "lltoolmgr.h"
00057 #include "lltoolview.h"
00058 #include "llui.h"
00059 #include "llviewercamera.h"
00060 #include "llviewerimagelist.h"
00061 #include "llviewerobject.h"
00062 #include "llviewerwindow.h"
00063 #include "llvoavatar.h"
00064 #include "pipeline.h"
00065 #include "viewer.h"
00066
00067
00068
00069
00070 LLLinkedList<LLVisualParamHint> LLVisualParamHint::sInstances;
00071 BOOL LLVisualParamReset::sDirty = FALSE;
00072
00073
00074
00075
00076
00077
00078 LLVisualParamHint::LLVisualParamHint(
00079 S32 pos_x, S32 pos_y,
00080 S32 width, S32 height,
00081 LLViewerJointMesh *mesh,
00082 LLViewerVisualParam *param,
00083 F32 param_weight)
00084 :
00085 LLDynamicTexture(width, height, 3, LLDynamicTexture::ORDER_MIDDLE, TRUE ),
00086 mNeedsUpdate( TRUE ),
00087 mIsVisible( FALSE ),
00088 mJointMesh( mesh ),
00089 mVisualParam( param ),
00090 mVisualParamWeight( param_weight ),
00091 mAllowsUpdates( TRUE ),
00092 mDelayFrames( 0 ),
00093 mRect( pos_x, pos_y + height, pos_x + width, pos_y ),
00094 mLastParamWeight(0.f)
00095 {
00096 LLVisualParamHint::sInstances.addData( this );
00097 LLUUID id;
00098 id.set( gViewerArt.getString("avatar_thumb_bkgrnd.tga") );
00099 mBackgroundp = gImageList.getImage(id, FALSE, TRUE);
00100
00101
00102 llassert(width != 0);
00103 llassert(height != 0);
00104 }
00105
00106
00107
00108
00109 LLVisualParamHint::~LLVisualParamHint()
00110 {
00111 LLVisualParamHint::sInstances.removeData( this );
00112 }
00113
00114
00115
00116
00117
00118
00119 void LLVisualParamHint::requestHintUpdates( LLVisualParamHint* exception1, LLVisualParamHint* exception2 )
00120 {
00121 S32 delay_frames = 0;
00122 for(LLVisualParamHint* instance = sInstances.getFirstData();
00123 instance;
00124 instance = sInstances.getNextData())
00125 {
00126 if( (instance != exception1) && (instance != exception2) )
00127 {
00128 if( instance->mAllowsUpdates )
00129 {
00130 instance->mNeedsUpdate = TRUE;
00131 instance->mDelayFrames = delay_frames;
00132 delay_frames++;
00133 }
00134 else
00135 {
00136 instance->mNeedsUpdate = TRUE;
00137 instance->mDelayFrames = 0;
00138 }
00139 }
00140 }
00141 }
00142
00143 BOOL LLVisualParamHint::needsRender()
00144 {
00145 return mNeedsUpdate && mDelayFrames-- <= 0 && !gAgent.getAvatarObject()->mAppearanceAnimating && mAllowsUpdates;
00146 }
00147
00148 void LLVisualParamHint::preRender(BOOL clear_depth)
00149 {
00150 LLVOAvatar* avatarp = gAgent.getAvatarObject();
00151
00152 mLastParamWeight = avatarp->getVisualParamWeight(mVisualParam);
00153 avatarp->setVisualParamWeight(mVisualParam, mVisualParamWeight);
00154 avatarp->setVisualParamWeight("Blink_Left", 0.f);
00155 avatarp->setVisualParamWeight("Blink_Right", 0.f);
00156 avatarp->updateComposites();
00157 avatarp->updateVisualParams();
00158 avatarp->updateGeometry(avatarp->mDrawable);
00159 avatarp->updateLOD();
00160
00161 LLDynamicTexture::preRender(clear_depth);
00162 }
00163
00164
00165
00166
00167 BOOL LLVisualParamHint::render()
00168 {
00169 LLVisualParamReset::sDirty = TRUE;
00170 LLVOAvatar* avatarp = gAgent.getAvatarObject();
00171
00172 glMatrixMode(GL_PROJECTION);
00173 glPushMatrix();
00174 glLoadIdentity();
00175 glOrtho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f);
00176
00177 glMatrixMode(GL_MODELVIEW);
00178 glPushMatrix();
00179 glLoadIdentity();
00180
00181 LLGLSUIDefault gls_ui;
00182
00183 LLViewerImage::bindTexture(mBackgroundp);
00184 glColor4f(1.f, 1.f, 1.f, 1.f);
00185 gl_rect_2d_simple_tex( mWidth, mHeight );
00186 mBackgroundp->unbindTexture(0, GL_TEXTURE_2D);
00187
00188 glMatrixMode(GL_PROJECTION);
00189 glPopMatrix();
00190
00191 glMatrixMode(GL_MODELVIEW);
00192 glPopMatrix();
00193
00194 mNeedsUpdate = FALSE;
00195 mIsVisible = TRUE;
00196
00197 LLViewerJointMesh* cam_target_joint = NULL;
00198 const std::string& cam_target_mesh_name = mVisualParam->getCameraTargetName();
00199 if( !cam_target_mesh_name.empty() )
00200 {
00201 cam_target_joint = (LLViewerJointMesh*)avatarp->getJoint( cam_target_mesh_name );
00202 }
00203 if( !cam_target_joint )
00204 {
00205 cam_target_joint = (LLViewerJointMesh*)gMorphView->getCameraTargetJoint();
00206 }
00207 if( !cam_target_joint )
00208 {
00209 cam_target_joint = (LLViewerJointMesh*)avatarp->getJoint("mHead");
00210 }
00211
00212 LLQuaternion avatar_rotation;
00213 LLJoint* root_joint = avatarp->getRootJoint();
00214 if( root_joint )
00215 {
00216 avatar_rotation = root_joint->getWorldRotation();
00217 }
00218
00219 LLVector3 target_joint_pos = cam_target_joint->getWorldPosition();
00220
00221 LLVector3 target_offset( 0, 0, mVisualParam->getCameraElevation() );
00222 LLVector3 target_pos = target_joint_pos + (target_offset * avatar_rotation);
00223
00224 F32 cam_angle_radians = mVisualParam->getCameraAngle() * DEG_TO_RAD;
00225 LLVector3 camera_snapshot_offset(
00226 mVisualParam->getCameraDistance() * cosf( cam_angle_radians ),
00227 mVisualParam->getCameraDistance() * sinf( cam_angle_radians ),
00228 mVisualParam->getCameraElevation() );
00229 LLVector3 camera_pos = target_joint_pos + (camera_snapshot_offset * avatar_rotation);
00230
00231 gCamera->setAspect((F32)mWidth / (F32)mHeight);
00232 gCamera->setOriginAndLookAt(
00233 camera_pos,
00234 LLVector3(0.f, 0.f, 1.f),
00235 target_pos );
00236
00237 gCamera->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, mWidth, mHeight, FALSE);
00238
00239 if (avatarp->mDrawable.notNull())
00240 {
00241 LLDrawPoolAvatar *avatarPoolp = (LLDrawPoolAvatar *)avatarp->mDrawable->getFace(0)->getPool();
00242 LLGLDepthTest gls_depth(GL_TRUE, GL_TRUE);
00243 avatarPoolp->renderAvatars(avatarp);
00244 }
00245 avatarp->setVisualParamWeight(mVisualParam, mLastParamWeight);
00246
00247 return TRUE;
00248 }
00249
00250
00251
00252
00253
00254 void LLVisualParamHint::draw()
00255 {
00256 if (!mIsVisible) return;
00257
00258 bindTexture();
00259
00260 glColor4f(1.f, 1.f, 1.f, 1.f);
00261
00262 LLGLSUIDefault gls_ui;
00263 glBegin(GL_QUADS);
00264 {
00265 glTexCoord2i(0, 1);
00266 glVertex2i(0, mHeight);
00267 glTexCoord2i(0, 0);
00268 glVertex2i(0, 0);
00269 glTexCoord2i(1, 0);
00270 glVertex2i(mWidth, 0);
00271 glTexCoord2i(1, 1);
00272 glVertex2i(mWidth, mHeight);
00273 }
00274 glEnd();
00275
00276 LLImageGL::unbindTexture(0, GL_TEXTURE_2D);
00277 }
00278
00279
00280
00281
00282 LLVisualParamReset::LLVisualParamReset() : LLDynamicTexture(1, 1, 1, ORDER_RESET, FALSE)
00283 {
00284 }
00285
00286
00287
00288
00289 BOOL LLVisualParamReset::render()
00290 {
00291 if (sDirty)
00292 {
00293 LLVOAvatar* avatarp = gAgent.getAvatarObject();
00294 avatarp->updateComposites();
00295 avatarp->updateVisualParams();
00296 avatarp->updateGeometry(avatarp->mDrawable);
00297 sDirty = FALSE;
00298 }
00299
00300 return FALSE;
00301 }