+ | Starting camera handling

This commit is contained in:
TheRedShip
2024-10-15 14:11:49 +02:00
parent 1c25a29c38
commit a006174ce5
6 changed files with 72 additions and 2 deletions

31
includes/Camera.hpp Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Camera.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: TheRed <TheRed@students.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/15 13:59:57 by TheRed #+# #+# */
/* Updated: 2024/10/15 13:59:57 by TheRed ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef RT_CAMERA__HPP
# define RT_CAMERA__HPP
class Camera
{
public:
Camera(void);
Camera(Camera const &src);
~Camera(void);
Camera &operator=(Camera const &rhs);
private:
};
#endif

View File

@ -39,6 +39,8 @@ class Window
private:
GLFWwindow *_window;
RT::Vec2i _mousePos;
RT::Vec2i _prevMousePos;
RT::Vec2i _mouseDelta;
float _fps;

View File

@ -56,7 +56,7 @@ void main()
uv.x *= u_resolution.x / u_resolution.y;
vec3 rayOrigin = vec3(0.0, 0.0, 0.0);
vec3 rayDirection = normalize(vec3(uv, -1.0));
vec3 rayDirection = normalize(vec3(uv, -1.0));
Ray ray = Ray(rayOrigin, rayDirection);

34
srcs/Camera.cpp Normal file
View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Camera.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: TheRed <TheRed@students.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/15 14:00:38 by TheRed #+# #+# */
/* Updated: 2024/10/15 14:00:38 by TheRed ### ########.fr */
/* */
/* ************************************************************************** */
#include "Camera.hpp"
Camera::Camera(void)
{
}
Camera::Camera(Camera const &src)
{
*this = src;
}
Camera::~Camera(void)
{
}
Camera &Camera::operator=(Camera const &rhs)
{
if (this != &rhs)
{
}
return (*this);
}

View File

@ -29,7 +29,7 @@ int main(void)
size_t size = sizeof(vertices) / sizeof(RT::Vec2f) / 3;
shader.setupVertexBuffer(vertices, size);
while (!window.shouldClose())
{
glClear(GL_COLOR_BUFFER_BIT);

View File

@ -72,7 +72,10 @@ void Window::mouseMoveCallback(GLFWwindow* window, double xpos, double ypos)
Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window));
(void) win; (void) xpos; (void) ypos;
win->_prevMousePos = win->_mousePos;
win->_mousePos = RT::Vec2i(xpos, ypos);
win->_mouseDelta = win->_mousePos - win->_prevMousePos;
}
void Window::mouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
{