mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
~ | Camera system working
This commit is contained in:
@ -31,10 +31,8 @@ void Camera::update_camera_vectors()
|
||||
frontTemp.z = sin(glm::radians(_yaw)) * cos(glm::radians(_pitch));
|
||||
_forward = glm::normalize(frontTemp);
|
||||
|
||||
_right = glm::normalize(glm::cross(_forward, _up));
|
||||
_right = glm::normalize(glm::cross(_forward, glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||
_up = glm::normalize(glm::cross(_right, _forward));
|
||||
|
||||
std::cout << _right.x << " " << _right.y << " " << _right.z << std::endl;
|
||||
}
|
||||
|
||||
glm::mat4 Camera::get_view_matrix()
|
||||
@ -59,20 +57,18 @@ void Camera::process_mouse(float xoffset, float yoffset, bool constraint_pitch
|
||||
}
|
||||
|
||||
update_camera_vectors();
|
||||
|
||||
std::cout << _yaw << " " << _pitch << std::endl;
|
||||
}
|
||||
|
||||
void Camera::process_keyboard(bool forward, bool backward, bool left, bool right, bool up, bool down)
|
||||
{
|
||||
float speed;
|
||||
|
||||
speed = 1.0f;
|
||||
speed = .1f;
|
||||
|
||||
if (forward) _position += _forward * speed;
|
||||
if (backward) _position -= _forward * speed;
|
||||
if (left) _position -= _right * speed;
|
||||
if (right) _position += _right * speed;
|
||||
if (up) _position += up * speed;
|
||||
if (down) _position -= up * speed;
|
||||
if (up) _position += _up * speed;
|
||||
if (down) _position -= _up * speed;
|
||||
}
|
10
srcs/RT.cpp
10
srcs/RT.cpp
@ -19,10 +19,6 @@ int main(void)
|
||||
|
||||
shader.attach();
|
||||
|
||||
// glm::vec2 vertices[6] = {
|
||||
// { -1.0f, -1.0f }, { 1.0f, -1.0f }, { -1.0f, 1.0f },
|
||||
// { 1.0f, -1.0f }, { 1.0f, 1.0f }, { -1.0f, 1.0f }
|
||||
// };
|
||||
glm::vec2 vertices[3] = {
|
||||
{-1.0f, -1.0f}, {3.0f, -1.0f}, {-1.0f, 3.0f}
|
||||
};
|
||||
@ -34,13 +30,9 @@ int main(void)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glm::mat4 view = window.get_camera()->get_view_matrix();
|
||||
glm::mat4 projection = glm::perspective(glm::radians(45.0f), (float)WIDTH / HEIGHT, 0.1f, 100.0f);
|
||||
|
||||
shader.set_vec2("u_resolution", glm::vec2(WIDTH, HEIGHT));
|
||||
shader.set_vec3("u_cameraPosition", window.get_camera()->get_position());
|
||||
shader.set_mat4("u_viewMatrix", view);
|
||||
shader.set_mat4("u_projectionMatrix", projection);
|
||||
shader.set_mat4("u_viewMatrix", window.get_camera()->get_view_matrix());
|
||||
|
||||
glUseProgram(shader.getProgram());
|
||||
shader.drawTriangles(size);
|
||||
|
@ -55,18 +55,17 @@ Window::~Window(void)
|
||||
|
||||
void Window::keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window));
|
||||
(void) win; (void) key; (void) scancode; (void) mods;
|
||||
Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window));
|
||||
(void) win; (void) key; (void) scancode; (void) mods;
|
||||
|
||||
bool forward = glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS;
|
||||
bool backward = glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS;
|
||||
bool left = glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS;
|
||||
bool right = glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS;
|
||||
bool up = glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS;
|
||||
bool down = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS;
|
||||
|
||||
// Update the camera position based on keyboard input
|
||||
win->_camera->process_keyboard(forward, backward, left, right, up, down);
|
||||
bool backward = glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS;
|
||||
bool left = glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS;
|
||||
bool right = glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS;
|
||||
bool up = glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS;
|
||||
bool down = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS;
|
||||
|
||||
win->_camera->process_keyboard(forward, backward, left, right, up, down);
|
||||
}
|
||||
void Window::mouseMoveCallback(GLFWwindow* window, double xpos, double ypos)
|
||||
{
|
||||
@ -82,8 +81,8 @@ void Window::mouseMoveCallback(GLFWwindow* window, double xpos, double ypos)
|
||||
lastY = ypos;
|
||||
}
|
||||
|
||||
double xoffset = lastX - xpos;
|
||||
double yoffset = ypos - lastY;
|
||||
double xoffset = xpos - lastX;
|
||||
double yoffset = lastY - ypos;
|
||||
|
||||
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS)
|
||||
{
|
||||
|
Reference in New Issue
Block a user