mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Starting camera handling
This commit is contained in:
31
includes/Camera.hpp
Normal file
31
includes/Camera.hpp
Normal 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
|
@ -39,6 +39,8 @@ class Window
|
|||||||
private:
|
private:
|
||||||
GLFWwindow *_window;
|
GLFWwindow *_window;
|
||||||
RT::Vec2i _mousePos;
|
RT::Vec2i _mousePos;
|
||||||
|
RT::Vec2i _prevMousePos;
|
||||||
|
RT::Vec2i _mouseDelta;
|
||||||
|
|
||||||
float _fps;
|
float _fps;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ void main()
|
|||||||
uv.x *= u_resolution.x / u_resolution.y;
|
uv.x *= u_resolution.x / u_resolution.y;
|
||||||
|
|
||||||
vec3 rayOrigin = vec3(0.0, 0.0, 0.0);
|
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);
|
Ray ray = Ray(rayOrigin, rayDirection);
|
||||||
|
|
||||||
|
34
srcs/Camera.cpp
Normal file
34
srcs/Camera.cpp
Normal 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);
|
||||||
|
}
|
@ -29,7 +29,7 @@ int main(void)
|
|||||||
size_t size = sizeof(vertices) / sizeof(RT::Vec2f) / 3;
|
size_t size = sizeof(vertices) / sizeof(RT::Vec2f) / 3;
|
||||||
|
|
||||||
shader.setupVertexBuffer(vertices, size);
|
shader.setupVertexBuffer(vertices, size);
|
||||||
|
|
||||||
while (!window.shouldClose())
|
while (!window.shouldClose())
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
@ -72,7 +72,10 @@ void Window::mouseMoveCallback(GLFWwindow* window, double xpos, double ypos)
|
|||||||
Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window));
|
Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window));
|
||||||
(void) win; (void) xpos; (void) ypos;
|
(void) win; (void) xpos; (void) ypos;
|
||||||
|
|
||||||
|
win->_prevMousePos = win->_mousePos;
|
||||||
win->_mousePos = RT::Vec2i(xpos, ypos);
|
win->_mousePos = RT::Vec2i(xpos, ypos);
|
||||||
|
|
||||||
|
win->_mouseDelta = win->_mousePos - win->_prevMousePos;
|
||||||
}
|
}
|
||||||
void Window::mouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
void Window::mouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user