llviewercamera.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /**
  2. * @file llviewercamera.h
  3. * @brief LLViewerCamera class header file
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLVIEWERCAMERA_H
  33. #define LL_LLVIEWERCAMERA_H
  34. #include "llcamera.h"
  35. #include "lltimer.h"
  36. #include "llstat.h"
  37. #include "llmatrix4.h"
  38. class LLCoordGL;
  39. class LLViewerObject;
  40. constexpr bool FOR_SELECTION = true;
  41. constexpr bool NOT_FOR_SELECTION = false;
  42. class alignas(16) LLViewerCamera final : public LLCamera
  43. {
  44. protected:
  45. LOG_CLASS(LLViewerCamera);
  46. public:
  47. LL_ALIGNED16_NEW_DELETE
  48. enum eCameraID
  49. {
  50. CAMERA_WORLD = 0,
  51. CAMERA_SUN_SHADOW0,
  52. CAMERA_SUN_SHADOW1,
  53. CAMERA_SUN_SHADOW2,
  54. CAMERA_SUN_SHADOW3,
  55. CAMERA_SPOT_SHADOW0,
  56. CAMERA_SPOT_SHADOW2,
  57. CAMERA_WATER0,
  58. CAMERA_WATER1,
  59. NUM_CAMERAS
  60. };
  61. LLViewerCamera();
  62. static void initClass(); // Called from LLAgent::init()
  63. void updateCameraLocation(const LLVector3& center,
  64. const LLVector3& up_direction,
  65. const LLVector3& point_of_interest);
  66. static void updateFrustumPlanes(LLCamera& camera, bool ortho = false,
  67. bool zflip = false, bool no_hacks = false);
  68. void setPerspective(bool for_selection, S32 x, S32 y_from_bot, S32 width,
  69. S32 height, bool limit_select_distance,
  70. F32 z_near = 0, F32 z_far = 0);
  71. const LLMatrix4& getProjection() const;
  72. const LLMatrix4& getModelview() const;
  73. // Warning! These assume the current global matrices are correct
  74. void projectScreenToPosAgent(S32 screen_x, S32 screen_y,
  75. LLVector3* pos_agent) const;
  76. bool projectPosAgentToScreen(const LLVector3& pos_agent,
  77. LLCoordGL& out_point,
  78. bool clamp = true) const;
  79. bool projectPosAgentToScreenEdge(const LLVector3& pos_agent,
  80. LLCoordGL& out_point) const;
  81. LL_INLINE const LLVector3* getVelocityDir() const { return &mVelocityDir; }
  82. LL_INLINE F32 getCosHalfFov() { return mCosHalfCameraFOV; }
  83. LL_INLINE F32 getAverageSpeed() { return mAverageSpeed; }
  84. LL_INLINE F32 getAverageAngularSpeed() { return mAverageAngularSpeed; }
  85. void getPixelVectors(const LLVector3& pos_agent, LLVector3& up,
  86. LLVector3& right);
  87. LLVector3 roundToPixel(const LLVector3& pos_agent);
  88. // Sets the current matrix
  89. void setView(F32 vertical_fov_rads) override;
  90. // Sets FOV without broadcasting to simulator (for temporary local cameras)
  91. LL_INLINE void setViewNoBroadcast(F32 vertical_fov_rads)
  92. {
  93. LLCamera::setView(vertical_fov_rads);
  94. }
  95. void setDefaultFOV(F32 fov);
  96. LL_INLINE F32 getDefaultFOV() { return mCameraFOVDefault; }
  97. bool isDefaultFOVChanged();
  98. bool cameraUnderWater() const;
  99. LL_INLINE const LLVector3& getPointOfInterest() { return mLastPointOfInterest; }
  100. bool areVertsVisible(LLViewerObject* volumep, bool all_verts);
  101. LL_INLINE F32 getPixelMeterRatio() const { return mPixelMeterRatio; }
  102. LL_INLINE S32 getScreenPixelArea() const { return mScreenPixelArea; }
  103. LL_INLINE void setZoomParameters(F32 factor, S16 subregion)
  104. {
  105. mZoomFactor = factor;
  106. mZoomSubregion = subregion;
  107. }
  108. LL_INLINE F32 getZoomFactor() { return mZoomFactor; }
  109. LL_INLINE S16 getZoomSubRegion() { return mZoomSubregion; }
  110. LL_INLINE static const LLStat& getVelocityStat() { return sVelocityStat; }
  111. LL_INLINE static const LLStat& getAngularVelocityStat()
  112. {
  113. return sAngularVelocityStat;
  114. }
  115. protected:
  116. void calcProjection(F32 far_distance) const;
  117. private:
  118. static void updateCameraAngle(const LLSD& value);
  119. protected:
  120. // Cache of perspective matrix
  121. mutable LLMatrix4 mProjectionMatrix;
  122. mutable LLMatrix4 mModelviewMatrix;
  123. LLVector3 mVelocityDir;
  124. F32 mAverageSpeed;
  125. F32 mAverageAngularSpeed;
  126. F32 mCameraFOVDefault;
  127. F32 mPrevCameraFOVDefault;
  128. F32 mCosHalfCameraFOV;
  129. LLVector3 mLastPointOfInterest;
  130. // Divide by distance from camera to get pixels per meter at that distance.
  131. F32 mPixelMeterRatio;
  132. // Pixel area of entire window
  133. S32 mScreenPixelArea;
  134. F32 mZoomFactor;
  135. S16 mZoomSubregion;
  136. public:
  137. static LLStat sVelocityStat;
  138. static LLStat sAngularVelocityStat;
  139. static S32 sCurCameraID;
  140. };
  141. extern LLViewerCamera gViewerCamera;
  142. #endif // LL_LLVIEWERCAMERA_H