PageRenderTime 47ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llagentcamera.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 394 lines | 247 code | 45 blank | 102 comment | 10 complexity | f9ed6c21b333c1e245778706e46f5337 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llagent.h
  3. * @brief LLAgent class header file
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLAGENTCAMERA_H
  27. #define LL_LLAGENTCAMERA_H
  28. #include "llfollowcam.h" // Ventrella
  29. #include "llhudeffectlookat.h" // EPointAtType
  30. #include "llhudeffectpointat.h" // ELookAtType
  31. class LLPickInfo;
  32. class LLVOAvatarSelf;
  33. class LLControlVariable;
  34. //--------------------------------------------------------------------
  35. // Types
  36. //--------------------------------------------------------------------
  37. enum ECameraMode
  38. {
  39. CAMERA_MODE_THIRD_PERSON,
  40. CAMERA_MODE_MOUSELOOK,
  41. CAMERA_MODE_CUSTOMIZE_AVATAR,
  42. CAMERA_MODE_FOLLOW
  43. };
  44. /** Camera Presets for CAMERA_MODE_THIRD_PERSON */
  45. enum ECameraPreset
  46. {
  47. /** Default preset, what the Third Person Mode actually was */
  48. CAMERA_PRESET_REAR_VIEW,
  49. /** "Looking at the Avatar from the front" */
  50. CAMERA_PRESET_FRONT_VIEW,
  51. /** "Above and to the left, over the shoulder, pulled back a little on the zoom" */
  52. CAMERA_PRESET_GROUP_VIEW
  53. };
  54. //------------------------------------------------------------------------
  55. // LLAgentCamera
  56. //------------------------------------------------------------------------
  57. class LLAgentCamera
  58. {
  59. LOG_CLASS(LLAgentCamera);
  60. public:
  61. //--------------------------------------------------------------------
  62. // Constructors / Destructors
  63. //--------------------------------------------------------------------
  64. public:
  65. LLAgentCamera();
  66. virtual ~LLAgentCamera();
  67. void init();
  68. void cleanup();
  69. void setAvatarObject(LLVOAvatarSelf* avatar);
  70. bool isInitialized() { return mInitialized; }
  71. private:
  72. bool mInitialized;
  73. //--------------------------------------------------------------------
  74. // Mode
  75. //--------------------------------------------------------------------
  76. public:
  77. void changeCameraToDefault();
  78. void changeCameraToMouselook(BOOL animate = TRUE);
  79. void changeCameraToThirdPerson(BOOL animate = TRUE);
  80. void changeCameraToCustomizeAvatar(); // Trigger transition animation
  81. void changeCameraToFollow(BOOL animate = TRUE); // Ventrella
  82. BOOL cameraThirdPerson() const { return (mCameraMode == CAMERA_MODE_THIRD_PERSON && mLastCameraMode == CAMERA_MODE_THIRD_PERSON); }
  83. BOOL cameraMouselook() const { return (mCameraMode == CAMERA_MODE_MOUSELOOK && mLastCameraMode == CAMERA_MODE_MOUSELOOK); }
  84. BOOL cameraCustomizeAvatar() const { return (mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR /*&& !mCameraAnimating*/); }
  85. BOOL cameraFollow() const { return (mCameraMode == CAMERA_MODE_FOLLOW && mLastCameraMode == CAMERA_MODE_FOLLOW); }
  86. ECameraMode getCameraMode() const { return mCameraMode; }
  87. ECameraMode getLastCameraMode() const { return mLastCameraMode; }
  88. void updateCamera(); // Call once per frame to update camera location/orientation
  89. void resetCamera(); // Slam camera into its default position
  90. void updateLastCamera(); // Set last camera to current camera
  91. private:
  92. ECameraMode mCameraMode; // Target mode after transition animation is done
  93. ECameraMode mLastCameraMode;
  94. //--------------------------------------------------------------------
  95. // Preset
  96. //--------------------------------------------------------------------
  97. public:
  98. void switchCameraPreset(ECameraPreset preset);
  99. private:
  100. /** Determines default camera offset depending on the current camera preset */
  101. LLVector3 getCameraOffsetInitial();
  102. /** Camera preset in Third Person Mode */
  103. ECameraPreset mCameraPreset;
  104. /** Initial camera offsets */
  105. std::map<ECameraPreset, LLPointer<LLControlVariable> > mCameraOffsetInitial;
  106. /** Initial focus offsets */
  107. std::map<ECameraPreset, LLPointer<LLControlVariable> > mFocusOffsetInitial;
  108. //--------------------------------------------------------------------
  109. // Position
  110. //--------------------------------------------------------------------
  111. public:
  112. LLVector3d getCameraPositionGlobal() const;
  113. const LLVector3 &getCameraPositionAgent() const;
  114. LLVector3d calcCameraPositionTargetGlobal(BOOL *hit_limit = NULL); // Calculate the camera position target
  115. F32 getCameraMinOffGround(); // Minimum height off ground for this mode, meters
  116. void setCameraCollidePlane(const LLVector4 &plane) { mCameraCollidePlane = plane; }
  117. BOOL calcCameraMinDistance(F32 &obj_min_distance);
  118. F32 getCurrentCameraBuildOffset() { return (F32)mCameraFocusOffset.length(); }
  119. void clearCameraLag() { mCameraLag.clearVec(); }
  120. private:
  121. F32 mCurrentCameraDistance; // Current camera offset from avatar
  122. F32 mTargetCameraDistance; // Target camera offset from avatar
  123. F32 mCameraFOVZoomFactor; // Amount of fov zoom applied to camera when zeroing in on an object
  124. F32 mCameraCurrentFOVZoomFactor; // Interpolated fov zoom
  125. F32 mCameraFOVDefault; // Default field of view that is basis for FOV zoom effect
  126. LLVector4 mCameraCollidePlane; // Colliding plane for camera
  127. F32 mCameraZoomFraction; // Mousewheel driven fraction of zoom
  128. LLVector3 mCameraPositionAgent; // Camera position in agent coordinates
  129. LLVector3 mCameraVirtualPositionAgent; // Camera virtual position (target) before performing FOV zoom
  130. LLVector3d mCameraSmoothingLastPositionGlobal;
  131. LLVector3d mCameraSmoothingLastPositionAgent;
  132. bool mCameraSmoothingStop;
  133. LLVector3 mCameraLag; // Third person camera lag
  134. LLVector3 mCameraUpVector; // Camera's up direction in world coordinates (determines the 'roll' of the view)
  135. //--------------------------------------------------------------------
  136. // Follow
  137. //--------------------------------------------------------------------
  138. public:
  139. void setUsingFollowCam(bool using_follow_cam);
  140. private:
  141. LLFollowCam mFollowCam; // Ventrella
  142. //--------------------------------------------------------------------
  143. // Sit
  144. //--------------------------------------------------------------------
  145. public:
  146. void setupSitCamera();
  147. BOOL sitCameraEnabled() { return mSitCameraEnabled; }
  148. void setSitCamera(const LLUUID &object_id,
  149. const LLVector3 &camera_pos = LLVector3::zero, const LLVector3 &camera_focus = LLVector3::zero);
  150. private:
  151. LLPointer<LLViewerObject> mSitCameraReferenceObject; // Object to which camera is related when sitting
  152. BOOL mSitCameraEnabled; // Use provided camera information when sitting?
  153. LLVector3 mSitCameraPos; // Root relative camera pos when sitting
  154. LLVector3 mSitCameraFocus; // Root relative camera target when sitting
  155. //--------------------------------------------------------------------
  156. // Animation
  157. //--------------------------------------------------------------------
  158. public:
  159. void setCameraAnimating(BOOL b) { mCameraAnimating = b; }
  160. BOOL getCameraAnimating() { return mCameraAnimating; }
  161. void setAnimationDuration(F32 seconds);
  162. void startCameraAnimation();
  163. void stopCameraAnimation();
  164. private:
  165. LLFrameTimer mAnimationTimer; // Seconds that transition animation has been active
  166. F32 mAnimationDuration; // In seconds
  167. BOOL mCameraAnimating; // Camera is transitioning from one mode to another
  168. LLVector3d mAnimationCameraStartGlobal; // Camera start position, global coords
  169. LLVector3d mAnimationFocusStartGlobal; // Camera focus point, global coords
  170. //--------------------------------------------------------------------
  171. // Focus
  172. //--------------------------------------------------------------------
  173. public:
  174. LLVector3d calcFocusPositionTargetGlobal();
  175. LLVector3 calcFocusOffset(LLViewerObject *object, LLVector3 pos_agent, S32 x, S32 y);
  176. BOOL getFocusOnAvatar() const { return mFocusOnAvatar; }
  177. LLPointer<LLViewerObject>& getFocusObject() { return mFocusObject; }
  178. F32 getFocusObjectDist() const { return mFocusObjectDist; }
  179. void updateFocusOffset();
  180. void validateFocusObject();
  181. void setFocusGlobal(const LLPickInfo& pick);
  182. void setFocusGlobal(const LLVector3d &focus, const LLUUID &object_id = LLUUID::null);
  183. void setFocusOnAvatar(BOOL focus, BOOL animate);
  184. void setCameraPosAndFocusGlobal(const LLVector3d& pos, const LLVector3d& focus, const LLUUID &object_id);
  185. void clearFocusObject();
  186. void setFocusObject(LLViewerObject* object);
  187. void setObjectTracking(BOOL track) { mTrackFocusObject = track; }
  188. const LLVector3d &getFocusGlobal() const { return mFocusGlobal; }
  189. const LLVector3d &getFocusTargetGlobal() const { return mFocusTargetGlobal; }
  190. private:
  191. LLVector3d mCameraFocusOffset; // Offset from focus point in build mode
  192. LLVector3d mCameraFocusOffsetTarget; // Target towards which we are lerping the camera's focus offset
  193. BOOL mFocusOnAvatar;
  194. LLVector3d mFocusGlobal;
  195. LLVector3d mFocusTargetGlobal;
  196. LLPointer<LLViewerObject> mFocusObject;
  197. F32 mFocusObjectDist;
  198. LLVector3 mFocusObjectOffset;
  199. F32 mFocusDotRadius; // Meters
  200. BOOL mTrackFocusObject;
  201. //--------------------------------------------------------------------
  202. // Lookat / Pointat
  203. //--------------------------------------------------------------------
  204. public:
  205. void updateLookAt(const S32 mouse_x, const S32 mouse_y);
  206. BOOL setLookAt(ELookAtType target_type, LLViewerObject *object = NULL, LLVector3 position = LLVector3::zero);
  207. ELookAtType getLookAtType();
  208. void lookAtLastChat();
  209. void slamLookAt(const LLVector3 &look_at); // Set the physics data
  210. BOOL setPointAt(EPointAtType target_type, LLViewerObject *object = NULL, LLVector3 position = LLVector3::zero);
  211. EPointAtType getPointAtType();
  212. public:
  213. LLPointer<LLHUDEffectLookAt> mLookAt;
  214. LLPointer<LLHUDEffectPointAt> mPointAt;
  215. //--------------------------------------------------------------------
  216. // Third person
  217. //--------------------------------------------------------------------
  218. public:
  219. LLVector3d calcThirdPersonFocusOffset();
  220. void setThirdPersonHeadOffset(LLVector3 offset) { mThirdPersonHeadOffset = offset; }
  221. private:
  222. LLVector3 mThirdPersonHeadOffset; // Head offset for third person camera position
  223. //--------------------------------------------------------------------
  224. // Orbit
  225. //--------------------------------------------------------------------
  226. public:
  227. void cameraOrbitAround(const F32 radians); // Rotate camera CCW radians about build focus point
  228. void cameraOrbitOver(const F32 radians); // Rotate camera forward radians over build focus point
  229. void cameraOrbitIn(const F32 meters); // Move camera in toward build focus point
  230. //--------------------------------------------------------------------
  231. // Zoom
  232. //--------------------------------------------------------------------
  233. public:
  234. void handleScrollWheel(S32 clicks); // Mousewheel driven zoom
  235. void cameraZoomIn(const F32 factor); // Zoom in by fraction of current distance
  236. F32 getCameraZoomFraction(); // Get camera zoom as fraction of minimum and maximum zoom
  237. void setCameraZoomFraction(F32 fraction); // Set camera zoom as fraction of minimum and maximum zoom
  238. F32 calcCameraFOVZoomFactor();
  239. //--------------------------------------------------------------------
  240. // Pan
  241. //--------------------------------------------------------------------
  242. public:
  243. void cameraPanIn(const F32 meters);
  244. void cameraPanLeft(const F32 meters);
  245. void cameraPanUp(const F32 meters);
  246. //--------------------------------------------------------------------
  247. // View
  248. //--------------------------------------------------------------------
  249. public:
  250. // Called whenever the agent moves. Puts camera back in default position, deselects items, etc.
  251. void resetView(BOOL reset_camera = TRUE, BOOL change_camera = FALSE);
  252. // Called on camera movement. Unlocks camera from the default position behind the avatar.
  253. void unlockView();
  254. public:
  255. F32 mDrawDistance;
  256. //--------------------------------------------------------------------
  257. // Mouselook
  258. //--------------------------------------------------------------------
  259. public:
  260. BOOL getForceMouselook() const { return mForceMouselook; }
  261. void setForceMouselook(BOOL mouselook) { mForceMouselook = mouselook; }
  262. private:
  263. BOOL mForceMouselook;
  264. //--------------------------------------------------------------------
  265. // HUD
  266. //--------------------------------------------------------------------
  267. public:
  268. F32 mHUDTargetZoom; // Target zoom level for HUD objects (used when editing)
  269. F32 mHUDCurZoom; // Current animated zoom level for HUD objects
  270. /********************************************************************************
  271. ** **
  272. ** KEYS
  273. **/
  274. public:
  275. S32 getAtKey() const { return mAtKey; }
  276. S32 getWalkKey() const { return mWalkKey; }
  277. S32 getLeftKey() const { return mLeftKey; }
  278. S32 getUpKey() const { return mUpKey; }
  279. F32 getYawKey() const { return mYawKey; }
  280. F32 getPitchKey() const { return mPitchKey; }
  281. void setAtKey(S32 mag) { mAtKey = mag; }
  282. void setWalkKey(S32 mag) { mWalkKey = mag; }
  283. void setLeftKey(S32 mag) { mLeftKey = mag; }
  284. void setUpKey(S32 mag) { mUpKey = mag; }
  285. void setYawKey(F32 mag) { mYawKey = mag; }
  286. void setPitchKey(F32 mag) { mPitchKey = mag; }
  287. void clearGeneralKeys();
  288. static S32 directionToKey(S32 direction); // Changes direction to -1/0/1
  289. private:
  290. S32 mAtKey; // Either 1, 0, or -1. Indicates that movement key is pressed
  291. S32 mWalkKey; // Like AtKey, but causes less forward thrust
  292. S32 mLeftKey;
  293. S32 mUpKey;
  294. F32 mYawKey;
  295. F32 mPitchKey;
  296. //--------------------------------------------------------------------
  297. // Orbit
  298. //--------------------------------------------------------------------
  299. public:
  300. F32 getOrbitLeftKey() const { return mOrbitLeftKey; }
  301. F32 getOrbitRightKey() const { return mOrbitRightKey; }
  302. F32 getOrbitUpKey() const { return mOrbitUpKey; }
  303. F32 getOrbitDownKey() const { return mOrbitDownKey; }
  304. F32 getOrbitInKey() const { return mOrbitInKey; }
  305. F32 getOrbitOutKey() const { return mOrbitOutKey; }
  306. void setOrbitLeftKey(F32 mag) { mOrbitLeftKey = mag; }
  307. void setOrbitRightKey(F32 mag) { mOrbitRightKey = mag; }
  308. void setOrbitUpKey(F32 mag) { mOrbitUpKey = mag; }
  309. void setOrbitDownKey(F32 mag) { mOrbitDownKey = mag; }
  310. void setOrbitInKey(F32 mag) { mOrbitInKey = mag; }
  311. void setOrbitOutKey(F32 mag) { mOrbitOutKey = mag; }
  312. void clearOrbitKeys();
  313. private:
  314. F32 mOrbitLeftKey;
  315. F32 mOrbitRightKey;
  316. F32 mOrbitUpKey;
  317. F32 mOrbitDownKey;
  318. F32 mOrbitInKey;
  319. F32 mOrbitOutKey;
  320. //--------------------------------------------------------------------
  321. // Pan
  322. //--------------------------------------------------------------------
  323. public:
  324. F32 getPanLeftKey() const { return mPanLeftKey; }
  325. F32 getPanRightKey() const { return mPanRightKey; }
  326. F32 getPanUpKey() const { return mPanUpKey; }
  327. F32 getPanDownKey() const { return mPanDownKey; }
  328. F32 getPanInKey() const { return mPanInKey; }
  329. F32 getPanOutKey() const { return mPanOutKey; }
  330. void setPanLeftKey(F32 mag) { mPanLeftKey = mag; }
  331. void setPanRightKey(F32 mag) { mPanRightKey = mag; }
  332. void setPanUpKey(F32 mag) { mPanUpKey = mag; }
  333. void setPanDownKey(F32 mag) { mPanDownKey = mag; }
  334. void setPanInKey(F32 mag) { mPanInKey = mag; }
  335. void setPanOutKey(F32 mag) { mPanOutKey = mag; }
  336. void clearPanKeys();
  337. private:
  338. F32 mPanUpKey;
  339. F32 mPanDownKey;
  340. F32 mPanLeftKey;
  341. F32 mPanRightKey;
  342. F32 mPanInKey;
  343. F32 mPanOutKey;
  344. /** Keys
  345. ** **
  346. *******************************************************************************/
  347. };
  348. extern LLAgentCamera gAgentCamera;
  349. #endif