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

Generated on Fri May 16 08:33:48 2008 for SecondLife by  doxygen 1.5.5