lltoolmorph.cpp

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

Generated on Fri May 16 08:34:07 2008 for SecondLife by  doxygen 1.5.5