Camera.pkg 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. $#include "Camera.h"
  2. /// %Camera component.
  3. class Camera : public Component
  4. {
  5. public:
  6. /// Set near clip distance.
  7. void SetNearClip(float nearClip);
  8. /// Set far clip distance.
  9. void SetFarClip(float farClip);
  10. /// Set field of view.
  11. void SetFov(float fov);
  12. /// Set orthographic mode view uniform size.
  13. void SetOrthoSize(float orthoSize);
  14. /// Set orthographic mode view size.
  15. void SetOrthoSize(const Vector2& orthoSize);
  16. /// Set aspect ratio.
  17. void SetAspectRatio(float aspectRatio);
  18. /// Set polygon fill mode to use when rendering a scene.
  19. void SetFillMode(FillMode mode);
  20. /// Set zoom.
  21. void SetZoom(float zoom);
  22. /// Set LOD bias.
  23. void SetLodBias(float bias);
  24. /// Set view mask. Will be and'ed with object's view mask to see if the object should be rendered.
  25. void SetViewMask(unsigned mask);
  26. /// Set view override flags.
  27. void SetViewOverrideFlags(unsigned flags);
  28. /// Set orthographic mode enabled/disabled.
  29. void SetOrthographic(bool enable);
  30. /// Set automatic aspect ratio based on viewport dimensions.
  31. void SetAutoAspectRatio(bool enable);
  32. /// Set projection offset. It needs to be calculated as (offset in pixels) / (viewport dimensions.)
  33. void SetProjectionOffset(const Vector2& offset);
  34. /// Set vertical flipping mode.
  35. void SetFlipVertical(bool enable);
  36. /// Return far clip distance.
  37. float GetFarClip() const { return farClip_; }
  38. /// Return near clip distance.
  39. float GetNearClip() const;
  40. /// Return field of view.
  41. float GetFov() const { return fov_; }
  42. /// Return orthographic mode size.
  43. float GetOrthoSize() const { return orthoSize_; }
  44. /// Return aspect ratio.
  45. float GetAspectRatio() const { return aspectRatio_; }
  46. /// Return zoom.
  47. float GetZoom() const { return zoom_; }
  48. /// Return LOD bias.
  49. float GetLodBias() const { return lodBias_; }
  50. /// Return view mask.
  51. unsigned GetViewMask() const { return viewMask_; }
  52. /// Return view override flags.
  53. unsigned GetViewOverrideFlags() const { return viewOverrideFlags_; }
  54. /// Return fill mode.
  55. FillMode GetFillMode() const { return fillMode_; }
  56. /// Return orthographic flag.
  57. bool IsOrthographic() const { return orthographic_; }
  58. /// Return auto aspect ratio flag.
  59. bool GetAutoAspectRatio() const { return autoAspectRatio_; }
  60. /// Return frustum in world space.
  61. const Frustum& GetFrustum() const;
  62. /// Return API-specific projection matrix.
  63. const Matrix4& GetProjection() const;
  64. /// Return either API-specific or API-independent (D3D convention) projection matrix.
  65. Matrix4 GetProjection(bool apiSpecific) const;
  66. /// Return view matrix.
  67. const Matrix3x4& GetView() const;
  68. /// Return frustum near and far sizes.
  69. void GetFrustumSize(Vector3& near, Vector3& far) const;
  70. /// Return half view size.
  71. float GetHalfViewSize() const;
  72. /// Return frustum split by custom near and far clip distances.
  73. Frustum GetSplitFrustum(float nearClip, float farClip) const;
  74. /// Return frustum in view space.
  75. Frustum GetViewSpaceFrustum() const;
  76. /// Return split frustum in view space.
  77. Frustum GetViewSpaceSplitFrustum(float nearClip, float farClip) const;
  78. /// Return ray corresponding to normalized screen coordinates (0.0 to 1.0.)
  79. Ray GetScreenRay(float x, float y) const;
  80. // Convert a world space point to normalized screen coordinates (0.0 - 1.0).
  81. Vector2 WorldToScreenPoint(const Vector3& worldPos) const;
  82. // Convert normalized screen coordinates (0.0 - 1.0) and depth to a world space point.
  83. Vector3 ScreenToWorldPoint(const Vector3& screenPos) const;
  84. /// Return forward vector.
  85. Vector3 GetForwardVector() const;
  86. /// Return right vector.
  87. Vector3 GetRightVector() const;
  88. /// Return up vector.
  89. Vector3 GetUpVector() const;
  90. /// Return projection offset.
  91. const Vector2& GetProjectionOffset() const { return projectionOffset_; }
  92. /// Return vertical flipping mode.
  93. bool GetFlipVertical() const { return flipVertical_; }
  94. /// Return distance to position. In orthographic mode uses only Z coordinate.
  95. float GetDistance(const Vector3& worldPos) const;
  96. /// Return squared distance to position. In orthographic mode uses only Z coordinate.
  97. float GetDistanceSquared(const Vector3& worldPos) const;
  98. /// Return a scene node's LOD scaled distance.
  99. float GetLodDistance(float distance, float scale, float bias) const;
  100. /// Return if projection parameters are valid for rendering and raycasting.
  101. bool IsProjectionValid() const;
  102. };