/indra/newview/llviewercamera.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 142 lines · 86 code · 26 blank · 30 comment · 0 complexity · 0e05bcdf73c166ffb09476ea0771f411 MD5 · raw file

  1. /**
  2. * @file llviewercamera.h
  3. * @brief LLViewerCamera class header file
  4. *
  5. * $LicenseInfo:firstyear=2002&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_LLVIEWERCAMERA_H
  27. #define LL_LLVIEWERCAMERA_H
  28. #include "llcamera.h"
  29. #include "llsingleton.h"
  30. #include "llstat.h"
  31. #include "lltimer.h"
  32. #include "m4math.h"
  33. class LLCoordGL;
  34. class LLViewerObject;
  35. // This rotation matrix moves the default OpenGL reference frame
  36. // (-Z at, Y up) to Cory's favorite reference frame (X at, Z up)
  37. const F32 OGL_TO_CFR_ROTATION[16] = { 0.f, 0.f, -1.f, 0.f, // -Z becomes X
  38. -1.f, 0.f, 0.f, 0.f, // -X becomes Y
  39. 0.f, 1.f, 0.f, 0.f, // Y becomes Z
  40. 0.f, 0.f, 0.f, 1.f };
  41. const BOOL FOR_SELECTION = TRUE;
  42. const BOOL NOT_FOR_SELECTION = FALSE;
  43. // Build time optimization, generate this once in .cpp file
  44. #ifndef LLVIEWERCAMERA_CPP
  45. extern template class LLViewerCamera* LLSingleton<class LLViewerCamera>::getInstance();
  46. #endif
  47. class LLViewerCamera : public LLCamera, public LLSingleton<LLViewerCamera>
  48. {
  49. public:
  50. typedef enum
  51. {
  52. CAMERA_WORLD = 0,
  53. CAMERA_SHADOW0,
  54. CAMERA_SHADOW1,
  55. CAMERA_SHADOW2,
  56. CAMERA_SHADOW3,
  57. CAMERA_SHADOW4,
  58. CAMERA_SHADOW5,
  59. CAMERA_WATER0,
  60. CAMERA_WATER1,
  61. CAMERA_GI_SOURCE,
  62. NUM_CAMERAS
  63. } eCameraID;
  64. static U32 sCurCameraID;
  65. LLViewerCamera();
  66. void updateCameraLocation(const LLVector3 &center,
  67. const LLVector3 &up_direction,
  68. const LLVector3 &point_of_interest);
  69. static void updateFrustumPlanes(LLCamera& camera, BOOL ortho = FALSE, BOOL zflip = FALSE, BOOL no_hacks = FALSE);
  70. static void updateCameraAngle(void* user_data, const LLSD& value);
  71. void setPerspective(BOOL for_selection, S32 x, S32 y_from_bot, S32 width, S32 height, BOOL limit_select_distance, F32 z_near = 0, F32 z_far = 0);
  72. const LLMatrix4 &getProjection() const;
  73. const LLMatrix4 &getModelview() const;
  74. // Warning! These assume the current global matrices are correct
  75. void projectScreenToPosAgent(const S32 screen_x, const S32 screen_y, LLVector3* pos_agent ) const;
  76. BOOL projectPosAgentToScreen(const LLVector3 &pos_agent, LLCoordGL &out_point, const BOOL clamp = TRUE) const;
  77. BOOL projectPosAgentToScreenEdge(const LLVector3 &pos_agent, LLCoordGL &out_point) const;
  78. const LLVector3* getVelocityDir() const {return &mVelocityDir;}
  79. LLStat *getVelocityStat() { return &mVelocityStat; }
  80. LLStat *getAngularVelocityStat() { return &mAngularVelocityStat; }
  81. F32 getCosHalfFov() {return mCosHalfCameraFOV;}
  82. F32 getAverageSpeed() {return mAverageSpeed ;}
  83. F32 getAverageAngularSpeed() {return mAverageAngularSpeed;}
  84. void getPixelVectors(const LLVector3 &pos_agent, LLVector3 &up, LLVector3 &right);
  85. LLVector3 roundToPixel(const LLVector3 &pos_agent);
  86. // Sets the current matrix
  87. /* virtual */ void setView(F32 vertical_fov_rads);
  88. void setDefaultFOV(F32 fov) ;
  89. F32 getDefaultFOV() { return mCameraFOVDefault; }
  90. BOOL cameraUnderWater() const;
  91. const LLVector3 &getPointOfInterest() { return mLastPointOfInterest; }
  92. BOOL areVertsVisible(LLViewerObject* volumep, BOOL all_verts);
  93. F32 getPixelMeterRatio() const { return mPixelMeterRatio; }
  94. S32 getScreenPixelArea() const { return mScreenPixelArea; }
  95. void setZoomParameters(F32 factor, S16 subregion) { mZoomFactor = factor; mZoomSubregion = subregion; }
  96. F32 getZoomFactor() { return mZoomFactor; }
  97. S16 getZoomSubRegion() { return mZoomSubregion; }
  98. protected:
  99. void calcProjection(const F32 far_distance) const;
  100. LLStat mVelocityStat;
  101. LLStat mAngularVelocityStat;
  102. LLVector3 mVelocityDir ;
  103. F32 mAverageSpeed ;
  104. F32 mAverageAngularSpeed ;
  105. mutable LLMatrix4 mProjectionMatrix; // Cache of perspective matrix
  106. mutable LLMatrix4 mModelviewMatrix;
  107. F32 mCameraFOVDefault;
  108. F32 mCosHalfCameraFOV;
  109. LLVector3 mLastPointOfInterest;
  110. F32 mPixelMeterRatio; // Divide by distance from camera to get pixels per meter at that distance.
  111. S32 mScreenPixelArea; // Pixel area of entire window
  112. F32 mZoomFactor;
  113. S16 mZoomSubregion;
  114. public:
  115. };
  116. #endif // LL_LLVIEWERCAMERA_H