Changes to player, and mesh renderer INCOMPLETE
This commit is contained in:
114
camera.h
114
camera.h
@@ -2,17 +2,17 @@
|
||||
#ifndef CAMERA_H
|
||||
#define CAMERA_H
|
||||
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
enum Camera_Movement
|
||||
{
|
||||
_FORWARD,
|
||||
_BACKWARD,
|
||||
_LEFT,
|
||||
_RIGHT
|
||||
};
|
||||
#include <GameObject.h>
|
||||
#include <MeshRenderer.h>
|
||||
#include <LevelMap.h>
|
||||
|
||||
const float YAW = -90.0f;
|
||||
const float PITCH = 0.0f;
|
||||
@@ -20,97 +20,35 @@ const float SPEED = 5.0f;
|
||||
const float MOUSE_SENSITIVITY = 0.1f;
|
||||
const float ZOOM = 45.0f;
|
||||
|
||||
class Camera
|
||||
class Camera : public GameObject
|
||||
{
|
||||
public:
|
||||
glm::vec3 Position;
|
||||
glm::vec3 Front;
|
||||
glm::vec3 Up;
|
||||
glm::vec3 Right;
|
||||
glm::vec3 WorldUp;
|
||||
glm::vec3 CameraOffset;
|
||||
glm::vec3 Offset;
|
||||
|
||||
float Yaw;
|
||||
float Pitch;
|
||||
|
||||
|
||||
float MovementSpeed;
|
||||
float MouseSensitivity;
|
||||
float Zoom;
|
||||
|
||||
Camera(
|
||||
glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f),
|
||||
glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f),
|
||||
glm::vec3 offset = glm::vec3(0.0f, 1.0f, 0.0f),
|
||||
float yaw = YAW,
|
||||
float pitch = PITCH)
|
||||
:
|
||||
Front(glm::vec3(0.0f, 0.0f, -1.0f)),
|
||||
MovementSpeed(SPEED),
|
||||
MouseSensitivity(MOUSE_SENSITIVITY),
|
||||
Zoom(ZOOM)
|
||||
{
|
||||
Position = position;
|
||||
CameraOffset = offset;
|
||||
WorldUp = up;
|
||||
Yaw = yaw;
|
||||
Pitch = pitch;
|
||||
updateCameraVectors();
|
||||
}
|
||||
GLFWwindow* Window;
|
||||
|
||||
glm::mat4 GetViewMatrix()
|
||||
{
|
||||
return glm::lookAt(Position, Position + Front, Up);
|
||||
}
|
||||
public:
|
||||
Camera(GLFWwindow* Window);
|
||||
~Camera() = default;
|
||||
|
||||
void ProcessKeyboard(Camera_Movement direction, float deltaTime)
|
||||
{
|
||||
float velocity = MovementSpeed * deltaTime;
|
||||
if (direction == _FORWARD)
|
||||
Position += Front * velocity;
|
||||
if (direction == _BACKWARD)
|
||||
Position -= Front * velocity;
|
||||
if (direction == _LEFT)
|
||||
Position -= Right * velocity;
|
||||
if (direction == _RIGHT)
|
||||
Position += Right * velocity;
|
||||
}
|
||||
|
||||
void ProcessMouseMovement(float XOffset, float YOffset, GLboolean bConstrainPitch = true)
|
||||
{
|
||||
//Yaw += XOffset;
|
||||
Pitch += YOffset;
|
||||
|
||||
if (bConstrainPitch)
|
||||
{
|
||||
if (Pitch > 89.0f)
|
||||
Pitch = 89.0f;
|
||||
if (Pitch < -89.0f)
|
||||
Pitch = -89.0f;
|
||||
}
|
||||
|
||||
updateCameraVectors();
|
||||
}
|
||||
|
||||
void ProcessMouseScroll(float yoffset)
|
||||
{
|
||||
Zoom -= (float)yoffset;
|
||||
if (Zoom < 1.0f)
|
||||
Zoom = 1.0f;
|
||||
if (Zoom > 45.0f)
|
||||
Zoom = 45.0f;
|
||||
}
|
||||
private:
|
||||
|
||||
void updateCameraVectors()
|
||||
{
|
||||
glm::vec3 front;
|
||||
front.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
|
||||
front.y = sin(glm::radians(Pitch));
|
||||
front.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));
|
||||
Front = glm::normalize(front);
|
||||
Right = glm::normalize(glm::cross(Front, WorldUp));
|
||||
Up = glm::normalize(glm::cross(Right, Front));
|
||||
}
|
||||
glm::mat4 GetViewMatrix();
|
||||
void SetOffset(glm::vec3 Offset);
|
||||
void MoveCamera(glm::vec3 Position);
|
||||
void RotateCamera(float Yaw, float Pitch, GLboolean bConstrainPitch = true);
|
||||
void ZoomCamera(float ZoomAmount);
|
||||
void RenderScene(
|
||||
LevelMap& LevelMap,
|
||||
const std::vector<PointLight>& Lights,
|
||||
int ScreenWidth,
|
||||
int ScreenHeight
|
||||
);
|
||||
glm::mat4 GetProjectionMatrix(int ScreenWidth, int ScreenHeight);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user