forked from TheCherno/Hazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SceneCamera + camera resizing support
- Loading branch information
Showing
8 changed files
with
112 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "hzpch.h" | ||
#include "SceneCamera.h" | ||
|
||
#include <glm/gtc/matrix_transform.hpp> | ||
|
||
namespace Hazel { | ||
|
||
SceneCamera::SceneCamera() | ||
{ | ||
RecalculateProjection(); | ||
} | ||
|
||
void SceneCamera::SetOrthographic(float size, float nearClip, float farClip) | ||
{ | ||
m_OrthographicSize = size; | ||
m_OrthographicNear = nearClip; | ||
m_OrthographicFar = farClip; | ||
RecalculateProjection(); | ||
} | ||
|
||
void SceneCamera::SetViewportSize(uint32_t width, uint32_t height) | ||
{ | ||
m_AspectRatio = (float)width / (float)height; | ||
RecalculateProjection(); | ||
} | ||
|
||
void SceneCamera::RecalculateProjection() | ||
{ | ||
float orthoLeft = -m_OrthographicSize * m_AspectRatio * 0.5f; | ||
float orthoRight = m_OrthographicSize * m_AspectRatio * 0.5f; | ||
float orthoBottom = -m_OrthographicSize * 0.5f; | ||
float orthoTop = m_OrthographicSize * 0.5f; | ||
|
||
m_Projection = glm::ortho(orthoLeft, orthoRight, | ||
orthoBottom, orthoTop, m_OrthographicNear, m_OrthographicFar); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include "Hazel/Renderer/Camera.h" | ||
|
||
namespace Hazel { | ||
|
||
class SceneCamera : public Camera | ||
{ | ||
public: | ||
SceneCamera(); | ||
virtual ~SceneCamera() = default; | ||
|
||
void SetOrthographic(float size, float nearClip, float farClip); | ||
|
||
void SetViewportSize(uint32_t width, uint32_t height); | ||
|
||
float GetOrthographicSize() const { return m_OrthographicSize; } | ||
void SetOrthographicSize(float size) { m_OrthographicSize = size; RecalculateProjection(); } | ||
private: | ||
void RecalculateProjection(); | ||
private: | ||
float m_OrthographicSize = 10.0f; | ||
float m_OrthographicNear = -1.0f, m_OrthographicFar = 1.0f; | ||
|
||
float m_AspectRatio = 0.0f; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters