Minor Camera class tweaks

This commit is contained in:
Wojtek Figat
2023-05-28 22:57:52 +02:00
parent 44036a26d0
commit 2149995116
2 changed files with 39 additions and 27 deletions

View File

@@ -46,6 +46,11 @@ Camera::Camera(const SpawnParams& params)
#endif
}
bool Camera::GetUsePerspective() const
{
return _usePerspective;
}
void Camera::SetUsePerspective(bool value)
{
if (_usePerspective != value)
@@ -55,6 +60,11 @@ void Camera::SetUsePerspective(bool value)
}
}
float Camera::GetFieldOfView() const
{
return _fov;
}
void Camera::SetFieldOfView(float value)
{
value = Math::Clamp(value, 1.0f, 179.9f);
@@ -65,16 +75,26 @@ void Camera::SetFieldOfView(float value)
}
}
float Camera::GetCustomAspectRatio() const
{
return _customAspectRatio;
}
void Camera::SetCustomAspectRatio(float value)
{
value = Math::Clamp(value, 0.0f, 100.0f);
if (_customAspectRatio != value)
if (Math::NotNearEqual(_customAspectRatio, value))
{
_customAspectRatio = value;
UpdateCache();
}
}
float Camera::GetNearPlane() const
{
return _near;
}
void Camera::SetNearPlane(float value)
{
value = Math::Clamp(value, 0.001f, _far - 1.0f);
@@ -85,6 +105,11 @@ void Camera::SetNearPlane(float value)
}
}
float Camera::GetFarPlane() const
{
return _far;
}
void Camera::SetFarPlane(float value)
{
value = Math::Max(value, _near + 1.0f);
@@ -95,6 +120,11 @@ void Camera::SetFarPlane(float value)
}
}
float Camera::GetOrthographicScale() const
{
return _orthoScale;
}
void Camera::SetOrthographicScale(float value)
{
value = Math::Clamp(value, 0.0001f, 1000000.0f);
@@ -191,7 +221,7 @@ Viewport Camera::GetViewport() const
if (Editor::Managed)
result.Size = Editor::Managed->GetGameWindowSize();
#else
// game
// Game
auto mainWin = Engine::MainWindow;
if (mainWin)
{
@@ -201,7 +231,7 @@ Viewport Camera::GetViewport() const
#endif
// Fallback to the default value
if (result.Width <= ZeroTolerance)
if (result.Size.MinValue() <= ZeroTolerance)
result.Size = Float2(1280, 720);
return result;

View File

@@ -66,10 +66,7 @@ public:
/// Gets the value indicating if camera should use perspective rendering mode, otherwise it will use orthographic projection.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(20), DefaultValue(true), EditorDisplay(\"Camera\"), Tooltip(\"Enables perspective projection mode, otherwise uses orthographic.\")")
FORCE_INLINE bool GetUsePerspective() const
{
return _usePerspective;
}
bool GetUsePerspective() const;
/// <summary>
/// Sets the value indicating if camera should use perspective rendering mode, otherwise it will use orthographic projection.
@@ -80,10 +77,7 @@ public:
/// Gets the camera's field of view (in degrees).
/// </summary>
API_PROPERTY(Attributes="EditorOrder(10), DefaultValue(60.0f), Limit(0, 179), EditorDisplay(\"Camera\", \"Field Of View\"), Tooltip(\"Field of view angle in degrees.\")")
FORCE_INLINE float GetFieldOfView() const
{
return _fov;
}
float GetFieldOfView() const;
/// <summary>
/// Sets camera's field of view (in degrees).
@@ -94,10 +88,7 @@ public:
/// Gets the custom aspect ratio. 0 if not use custom value.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(50), DefaultValue(0.0f), Limit(0, 10, 0.01f), EditorDisplay(\"Camera\"), Tooltip(\"Custom aspect ratio to use. Set to 0 to disable.\")")
FORCE_INLINE float GetCustomAspectRatio() const
{
return _customAspectRatio;
}
float GetCustomAspectRatio() const;
/// <summary>
/// Sets the custom aspect ratio. 0 if not use custom value.
@@ -108,10 +99,7 @@ public:
/// Gets camera's near plane distance.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(30), DefaultValue(10.0f), Limit(0, 1000, 0.05f), EditorDisplay(\"Camera\"), Tooltip(\"Near clipping plane distance\")")
FORCE_INLINE float GetNearPlane() const
{
return _near;
}
float GetNearPlane() const;
/// <summary>
/// Sets camera's near plane distance.
@@ -122,10 +110,7 @@ public:
/// Gets camera's far plane distance.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(40), DefaultValue(40000.0f), Limit(0, float.MaxValue, 5), EditorDisplay(\"Camera\"), Tooltip(\"Far clipping plane distance\")")
FORCE_INLINE float GetFarPlane() const
{
return _far;
}
float GetFarPlane() const;
/// <summary>
/// Sets camera's far plane distance.
@@ -136,10 +121,7 @@ public:
/// Gets the orthographic projection scale.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(60), DefaultValue(1.0f), Limit(0.0001f, 1000, 0.01f), EditorDisplay(\"Camera\"), Tooltip(\"Orthographic projection scale\")")
FORCE_INLINE float GetOrthographicScale() const
{
return _orthoScale;
}
float GetOrthographicScale() const;
/// <summary>
/// Sets the orthographic projection scale.