In process of creating the orthographic camera and camera component
In process of Implementing world rendering and the world view panel in the editormaster
parent
ed6fdbdb5b
commit
5beb9b2789
@ -1,20 +0,0 @@
|
||||
/******************************************************************************
|
||||
* File - camera.h
|
||||
* Author - Joey Pollack
|
||||
* Date - 2022/01/25 (y/m/d)
|
||||
* Mod Date - 2022/01/25 (y/m/d)
|
||||
* Description - A 2D camera to be used with the World
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef CAMERA_H_
|
||||
#define CAMERA_H_
|
||||
|
||||
namespace lunarium
|
||||
{
|
||||
class Camera
|
||||
{
|
||||
// TODO: class Camera
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CAMERA_H_
|
||||
@ -0,0 +1,72 @@
|
||||
/******************************************************************************
|
||||
* File - orthographic_camera.cpp
|
||||
* Author - Joey Pollack
|
||||
* Date - 2022/01/25 (y/m/d)
|
||||
* Mod Date - 2022/01/25 (y/m/d)
|
||||
* Description - A 2D camera to be used with the World
|
||||
******************************************************************************/
|
||||
|
||||
#include "orthographic_camera.h"
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
namespace lunarium
|
||||
{
|
||||
OrthographicCamera::OrthographicCamera(Vec2f position, Sizef viewport_size)
|
||||
: mPosition(position), mRotation(0.0f), mViewportSize(viewport_size), mView(1.0f)
|
||||
{
|
||||
RecalculateView();
|
||||
}
|
||||
|
||||
void OrthographicCamera::MoveLeft(float amt)
|
||||
{
|
||||
mPosition.X += amt;
|
||||
RecalculateView();
|
||||
}
|
||||
|
||||
void OrthographicCamera::MoveUp(float amt)
|
||||
{
|
||||
mPosition.Y += amt;
|
||||
RecalculateView();
|
||||
}
|
||||
|
||||
void OrthographicCamera::Rotate(float amt)
|
||||
{
|
||||
mRotation += amt;
|
||||
RecalculateView();
|
||||
}
|
||||
|
||||
void OrthographicCamera::SetPosition(Vec2f position)
|
||||
{
|
||||
mPosition = position;
|
||||
RecalculateView();
|
||||
}
|
||||
|
||||
void OrthographicCamera::SetRotation(float rot)
|
||||
{
|
||||
mRotation = rot;
|
||||
RecalculateView();
|
||||
}
|
||||
|
||||
glm::mat4 OrthographicCamera::GetViewProjection()
|
||||
{
|
||||
return mViewProj;
|
||||
}
|
||||
|
||||
void OrthographicCamera::SetViewportSize(Sizef size)
|
||||
{
|
||||
mViewportSize = size;
|
||||
RecalculateView();
|
||||
}
|
||||
|
||||
void OrthographicCamera::RecalculateView()
|
||||
{
|
||||
mProjection = glm::ortho(0.0f, mViewportSize.Width, mViewportSize.Height, 0.0f, -1.0f, 1.0f);
|
||||
|
||||
glm::mat4 transform = glm::translate(glm::mat4(1.0f), (glm::vec3)mPosition);
|
||||
transform *= glm::rotate(glm::mat4(1.0f), glm::radians(mRotation), glm::vec3(0, 0, 1));
|
||||
|
||||
mView = glm::inverse(transform);
|
||||
mViewProj = mProjection * mView;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
/******************************************************************************
|
||||
* File - orthographic_camera.h
|
||||
* Author - Joey Pollack
|
||||
* Date - 2022/01/25 (y/m/d)
|
||||
* Mod Date - 2022/01/25 (y/m/d)
|
||||
* Description - A 2D camera to be used with the World
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef CAMERA_H_
|
||||
#define CAMERA_H_
|
||||
|
||||
#include <core/types.h>
|
||||
|
||||
namespace lunarium
|
||||
{
|
||||
class OrthographicCamera
|
||||
{
|
||||
public:
|
||||
OrthographicCamera(Vec2f position = { 0.0f, 0.0f }, Sizef viewport_size = {0.0f, 0.0f });
|
||||
|
||||
void MoveLeft(float amt);
|
||||
void MoveUp(float amt);
|
||||
void Rotate(float amt);
|
||||
|
||||
void SetPosition(Vec2f position);
|
||||
void SetRotation(float rot);
|
||||
|
||||
void SetViewportSize(Sizef size);
|
||||
|
||||
glm::mat4 GetViewProjection();
|
||||
|
||||
private:
|
||||
void RecalculateView();
|
||||
|
||||
private:
|
||||
|
||||
Vec2f mPosition;
|
||||
float mRotation;
|
||||
Sizef mViewportSize;
|
||||
|
||||
glm::mat4 mProjection;
|
||||
glm::mat4 mView;
|
||||
glm::mat4 mViewProj;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CAMERA_H_
|
||||
Loading…
Reference in New Issue