llmorphview.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llmorphview.h"
00035 
00036 #include "lljoint.h"
00037 
00038 #include "llagent.h"
00039 #include "lldrawable.h"
00040 #include "lldrawpoolavatar.h"
00041 #include "llface.h"
00042 #include "llfirstuse.h"
00043 #include "llfloatercustomize.h"
00044 #include "llfloatertools.h"
00045 #include "llresmgr.h"
00046 #include "lltoolmgr.h"
00047 #include "lltoolmorph.h"
00048 #include "llviewercamera.h"
00049 #include "llvoavatar.h"
00050 #include "llviewerwindow.h"
00051 #include "pipeline.h"
00052 #include "viewer.h"
00053 
00054 LLMorphView *gMorphView = NULL;
00055 
00056 
00057 const F32 EDIT_AVATAR_ORBIT_SPEED = 0.1f;
00058 const F32 EDIT_AVATAR_MAX_CAMERA_PITCH = 0.5f;
00059 
00060 const F32 CAMERA_MOVE_TIME = 0.5f;
00061 const F32 MORPH_NEAR_CLIP = 0.1f;
00062 
00063 const F32 CAMERA_DIST_MIN  = 0.4f;
00064 const F32 CAMERA_DIST_MAX  = 4.0f;
00065 const F32 CAMERA_DIST_STEP = 1.5f;
00066 
00067 //-----------------------------------------------------------------------------
00068 // LLMorphView()
00069 //-----------------------------------------------------------------------------
00070 LLMorphView::LLMorphView(const std::string& name, const LLRect& rect)
00071         : 
00072         LLView(name, rect, FALSE, FOLLOWS_ALL),
00073         mCameraTargetJoint( NULL ),
00074         mCameraOffset(-0.5f, 0.05f, 0.07f ),
00075         mCameraTargetOffset(0.f, 0.f, 0.05f ),
00076         mOldCameraNearClip( 0.f ),
00077         mCameraPitch( 0.f ),
00078         mCameraYaw( 0.f ),
00079         mCameraDist( -1.f ),
00080         mCameraDrivenByKeys( FALSE )
00081 {
00082 }
00083 
00084 EWidgetType LLMorphView::getWidgetType() const
00085 {
00086         return WIDGET_TYPE_MORPH_VIEW;
00087 }
00088 
00089 LLString LLMorphView::getWidgetTag() const
00090 {
00091         return LL_MORPH_VIEW_TAG;
00092 }
00093 
00094 //-----------------------------------------------------------------------------
00095 // initialize()
00096 //-----------------------------------------------------------------------------
00097 void    LLMorphView::initialize()
00098 {
00099         mCameraPitch = 0.f;
00100         mCameraYaw = 0.f;
00101         mCameraDist = -1.f;
00102 
00103         LLVOAvatar *avatarp = gAgent.getAvatarObject();
00104         if (!avatarp || avatarp->isDead())
00105         {
00106                 gAgent.changeCameraToDefault();
00107                 return;
00108         }
00109 
00110         avatarp->stopMotion( ANIM_AGENT_BODY_NOISE );
00111         avatarp->mSpecialRenderMode = 3;
00112         
00113         // set up camera for close look at avatar
00114         mOldCameraNearClip = gCamera->getNear();
00115         gCamera->setNear(MORPH_NEAR_CLIP);      
00116 }
00117 
00118 //-----------------------------------------------------------------------------
00119 // shutdown()
00120 //-----------------------------------------------------------------------------
00121 void    LLMorphView::shutdown()
00122 {
00123         LLVOAvatar::onCustomizeEnd();
00124 
00125         LLVOAvatar *avatarp = gAgent.getAvatarObject();
00126         if(avatarp && !avatarp->isDead())
00127         {
00128                 avatarp->startMotion( ANIM_AGENT_BODY_NOISE );
00129                 avatarp->mSpecialRenderMode = 0;
00130                 // reset camera
00131                 gCamera->setNear(mOldCameraNearClip);
00132         }
00133 }
00134 
00135 
00136 //-----------------------------------------------------------------------------
00137 // setVisible()
00138 //-----------------------------------------------------------------------------
00139 void LLMorphView::setVisible(BOOL visible)
00140 {
00141         if( visible != getVisible() )
00142         {
00143                 LLView::setVisible(visible);
00144 
00145                 if (visible)
00146                 {
00147                         llassert( !gFloaterCustomize );
00148                         gFloaterCustomize = new LLFloaterCustomize();
00149                         gFloaterCustomize->fetchInventory();
00150                         gFloaterCustomize->open();      /*Flawfinder: ignore*/
00151 
00152                         // Must do this _after_ gFloaterView is initialized.
00153                         gFloaterCustomize->switchToDefaultSubpart();
00154 
00155                         initialize();
00156 
00157                         // First run dialog
00158                         LLFirstUse::useAppearance();
00159                 }
00160                 else
00161                 {
00162                         if( gFloaterCustomize )
00163                         {
00164                                 gFloaterView->removeChild( gFloaterCustomize );
00165                                 delete gFloaterCustomize;
00166                                 gFloaterCustomize = NULL;
00167                         }
00168 
00169                         shutdown();
00170                 }
00171         }
00172 }
00173 
00174 void LLMorphView::updateCamera()
00175 {
00176         if (!mCameraTargetJoint)
00177         {
00178                 setCameraTargetJoint(gAgent.getAvatarObject()->getJoint("mHead"));
00179         }
00180         
00181         LLVOAvatar* avatar = gAgent.getAvatarObject();
00182         if( !avatar )
00183         {
00184                 return;
00185         }
00186         LLJoint* root_joint = avatar->getRootJoint();
00187         if( !root_joint )
00188         {
00189                 return;
00190         }
00191 
00192         const LLQuaternion& avatar_rot = root_joint->getWorldRotation();
00193 
00194         LLVector3d joint_pos = gAgent.getPosGlobalFromAgent(mCameraTargetJoint->getWorldPosition());
00195         LLVector3d target_pos = joint_pos + mCameraTargetOffset * avatar_rot;
00196 
00197         LLQuaternion camera_rot_yaw(mCameraYaw, LLVector3::z_axis);
00198         LLQuaternion camera_rot_pitch(mCameraPitch, LLVector3::y_axis);
00199 
00200         LLVector3d camera_pos = joint_pos + mCameraOffset * camera_rot_pitch * camera_rot_yaw * avatar_rot;
00201 
00202         gAgent.setCameraPosAndFocusGlobal( camera_pos, target_pos, gAgent.getID() );
00203 }
00204 
00205 void LLMorphView::setCameraDrivenByKeys(BOOL b)
00206 {
00207         if( mCameraDrivenByKeys != b )
00208         {
00209                 if( b )
00210                 {
00211                         // Reset to the default camera position specified by mCameraPitch, mCameraYaw, etc.
00212                         updateCamera();
00213                 }
00214                 mCameraDrivenByKeys = b;
00215         }
00216 }

Generated on Thu Jul 1 06:08:54 2010 for Second Life Viewer by  doxygen 1.4.7