Camera.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "Frustum.h"
  25. #include "Component.h"
  26. #include "Node.h"
  27. #include "Ray.h"
  28. static const unsigned VOF_NONE = 0x0;
  29. static const unsigned VOF_LOW_MATERIAL_QUALITY = 0x1;
  30. static const unsigned VOF_DISABLE_SHADOWS = 0x2;
  31. static const unsigned VOF_DISABLE_OCCLUSION = 0x4;
  32. /// Camera component
  33. class Camera : public Component
  34. {
  35. OBJECT(Camera);
  36. public:
  37. /// Construct
  38. Camera(Context* context);
  39. /// Destruct
  40. virtual ~Camera();
  41. /// Register object factory
  42. static void RegisterObject(Context* context);
  43. /// Set near clip distance
  44. void SetNearClip(float nearClip);
  45. /// Set far clip distance
  46. void SetFarClip(float farClip);
  47. /// Set field of view
  48. void SetFov(float fov);
  49. /// Set orthographic mode view uniform size
  50. void SetOrthoSize(float orthoSize);
  51. /// Set orthographic mode view size
  52. void SetOrthoSize(const Vector2& orthoSize);
  53. /// Set aspect ratio
  54. void SetAspectRatio(float aspectRatio);
  55. /// Set zoom
  56. void SetZoom(float zoom);
  57. /// Set LOD bias
  58. void SetLodBias(float bias);
  59. /// Set view mask. Will be and'ed with object's view mask to see if the object should be rendered
  60. void SetViewMask(unsigned mask);
  61. /// Set view override flags
  62. void SetViewOverrideFlags(unsigned flags);
  63. /// Set orthographic mode enabled/disabled
  64. void SetOrthographic(bool enable);
  65. /// Set automatic aspect ratio based on viewport dimensions
  66. void SetAutoAspectRatio(bool enable);
  67. /// Set projection jitter offset. It needs to be calculated as (offset in pixels) / (viewport dimensions)
  68. void SetProjectionOffset(const Vector2& offset);
  69. /// Return far clip distance
  70. float GetFarClip() const { return farClip_; }
  71. /// Return near clip distance
  72. float GetNearClip() const;
  73. /// Return field of view
  74. float GetFov() const { return fov_; }
  75. /// Return orthographic mode size
  76. float GetOrthoSize() const { return orthoSize_; }
  77. /// Return aspect ratio
  78. float GetAspectRatio() const { return aspectRatio_; }
  79. /// Return zoom
  80. float GetZoom() const { return zoom_; }
  81. /// Return LOD bias
  82. float GetLodBias() const { return lodBias_; }
  83. /// Return view mask
  84. unsigned GetViewMask() const { return viewMask_; }
  85. /// Return view override flags
  86. unsigned GetViewOverrideFlags() const { return viewOverrideFlags_; }
  87. /// Return orthographic flag
  88. bool IsOrthographic() const { return orthographic_; }
  89. /// Return auto aspect ratio flag
  90. bool GetAutoAspectRatio() const { return autoAspectRatio_; }
  91. /// Return frustum in world space
  92. Frustum GetFrustum() const;
  93. /// Return projection matrix
  94. Matrix4 GetProjection(bool enableOffset = true) const;
  95. /// Return frustum near and far sizes
  96. void GetFrustumSize(Vector3& near, Vector3& far) const;
  97. /// Return half view size
  98. float GetHalfViewSize() const;
  99. /// Return frustum transformed to view space
  100. Frustum GetViewSpaceFrustum() const;
  101. /// Return frustum split by custom near and far clip distances
  102. Frustum GetSplitFrustum(float nearClip, float farClip);
  103. /// Return ray corresponding to screen coordinates (0.0 to 1.0)
  104. Ray GetScreenRay(float x, float y);
  105. /// Return forward vector
  106. Vector3 GetForwardVector();
  107. /// Return right vector
  108. Vector3 GetRightVector();
  109. /// Return up vector
  110. Vector3 GetUpVector();
  111. /// Return projection jitter offset
  112. const Vector2& GetProjectionOffset() const { return projectionOffset_; }
  113. /// Return distance to position. In orthographic mode uses only Z coordinate
  114. float GetDistance(const Vector3& worldPos);
  115. /// Return squared distance to position. In orthographic mode uses only Z coordinate
  116. float GetDistanceSquared(const Vector3& worldPos);
  117. /// Return a scene node's LOD scaled distance
  118. float GetLodDistance(float distance, float scale, float bias) const;
  119. /// Return inverse world transform (view matrix)
  120. Matrix3x4 GetInverseWorldTransform() const { return GetWorldTransform().Inverse(); }
  121. private:
  122. /// Near clip distance
  123. float nearClip_;
  124. /// Far clip distance
  125. float farClip_;
  126. /// Field of view
  127. float fov_;
  128. /// Orthographic view size
  129. float orthoSize_;
  130. /// Aspect ratio
  131. float aspectRatio_;
  132. /// Zoom
  133. float zoom_;
  134. /// LOD bias
  135. float lodBias_;
  136. /// View mask
  137. unsigned viewMask_;
  138. /// View override flags
  139. unsigned viewOverrideFlags_;
  140. /// Orthographic mode flag
  141. bool orthographic_;
  142. /// Auto aspect ratio flag
  143. bool autoAspectRatio_;
  144. /// Projection jitter offset
  145. Vector2 projectionOffset_;
  146. };