Files
Seele/src/Engine/Component/Camera.cpp
T

58 lines
1.4 KiB
C++
Raw Normal View History

#include "Camera.h"
2022-11-17 16:47:42 +01:00
#include "Actor/Actor.h"
#include <algorithm>
2021-01-19 15:30:00 +01:00
#include <iostream>
using namespace Seele;
using namespace Seele::Component;
using namespace Seele::Math;
Camera::Camera()
2023-11-06 14:47:21 +01:00
: viewMatrix(Matrix4())
, bNeedsViewBuild(false)
2023-12-10 22:27:59 +01:00
, cameraPos(Vector())
{
2023-11-30 11:51:53 +01:00
yaw = 3.1415f/2;
pitch = 0;
}
Camera::~Camera()
{
}
void Camera::mouseMove(float deltaYaw, float deltaPitch)
{
2023-11-30 11:51:53 +01:00
yaw += deltaYaw / 500.f;
2022-03-26 12:55:04 +01:00
pitch += deltaPitch / 500.f;
Vector cameraDirection = glm::normalize(Vector(cos(yaw) * cos(pitch), sin(pitch), sin(yaw) * cos(pitch)));
2023-11-30 11:51:53 +01:00
Matrix4 viewMat = glm::lookAt(getTransform().getPosition(), getTransform().getPosition() + cameraDirection, Vector(0, 1, 0));
getTransform().setRotation(viewMat); // quaternion from matrix, janky but im bad at math
2022-03-19 22:45:30 +01:00
bNeedsViewBuild = true;
}
void Camera::mouseScroll(float x)
{
2023-11-30 11:51:53 +01:00
getTransform().translate(getTransform().getForward()*x);
2022-03-19 22:45:30 +01:00
bNeedsViewBuild = true;
}
void Camera::moveX(float amount)
{
2023-11-30 11:51:53 +01:00
getTransform().translate(getTransform().getForward()*amount);
2022-03-19 22:45:30 +01:00
bNeedsViewBuild = true;
}
void Camera::moveY(float amount)
2022-03-19 22:45:30 +01:00
{
2023-11-30 11:51:53 +01:00
getTransform().translate(getTransform().getRight()*amount);
2022-03-19 22:45:30 +01:00
bNeedsViewBuild = true;
}
void Camera::buildViewMatrix()
{
2023-11-30 11:51:53 +01:00
Vector eyePos = getTransform().getPosition();
Vector lookAt = eyePos + getTransform().getForward();
2023-11-13 13:23:16 +01:00
viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0));
2023-11-30 11:51:53 +01:00
cameraPos = eyePos;
2022-03-19 22:45:30 +01:00
bNeedsViewBuild = false;
}