mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
~ | Better camera managment
This commit is contained in:
@ -95,7 +95,41 @@ glm::vec3 Camera::getPosition()
|
||||
return (_position);
|
||||
}
|
||||
|
||||
glm::vec2 Camera::getDirection()
|
||||
{
|
||||
return (glm::vec2(_pitch, _yaw));
|
||||
}
|
||||
|
||||
glm::vec2 Camera::getDOV()
|
||||
{
|
||||
return (glm::vec2(_aperture_size, _focus_distance));
|
||||
}
|
||||
|
||||
GPUCamera Camera::getGPUData()
|
||||
{
|
||||
GPUCamera data;
|
||||
|
||||
data.aperture_size = _aperture_size;
|
||||
data.focus_distance = _focus_distance;
|
||||
data.camera_position = _position;
|
||||
data.view_matrix = getViewMatrix();
|
||||
|
||||
return (data);
|
||||
}
|
||||
|
||||
void Camera::setPosition(glm::vec3 position)
|
||||
{
|
||||
_position = position;
|
||||
}
|
||||
|
||||
void Camera::setDirection(float pitch, float yaw)
|
||||
{
|
||||
_pitch = pitch;
|
||||
_yaw = yaw;
|
||||
}
|
||||
|
||||
void Camera::setDOV(float aperture, float focus)
|
||||
{
|
||||
_aperture_size = aperture;
|
||||
_focus_distance = focus;
|
||||
}
|
@ -91,8 +91,8 @@ void Scene::updateGPUData()
|
||||
else if (obj->getType() == Object::Type::QUAD)
|
||||
{
|
||||
auto quad = static_cast<Quad *>(obj);
|
||||
gpu_obj.vertex1 = quad->getEdge1();
|
||||
gpu_obj.vertex2 = quad->getEdge2();
|
||||
gpu_obj.vertex1 = quad->getUp();
|
||||
gpu_obj.vertex2 = quad->getRight();
|
||||
}
|
||||
else if (obj->getType() == Object::Type::TRIANGLE)
|
||||
{
|
||||
@ -110,8 +110,8 @@ void Scene::updateGPUData()
|
||||
else if (obj->getType() == Object::Type::PORTAL)
|
||||
{
|
||||
auto portal = static_cast<Portal *>(obj);
|
||||
gpu_obj.vertex1 = portal->getEdge1();
|
||||
gpu_obj.vertex2 = portal->getEdge2();
|
||||
gpu_obj.vertex1 = portal->getUp();
|
||||
gpu_obj.vertex2 = portal->getRight();
|
||||
gpu_obj.normal = portal->getNormal();
|
||||
gpu_obj.transform = glm::mat4(portal->getTransform());
|
||||
|
||||
|
@ -85,12 +85,30 @@ void SceneParser::parseMaterial(std::stringstream &line)
|
||||
|
||||
void SceneParser::parseCamera(std::stringstream &line)
|
||||
{
|
||||
float x,y,z;
|
||||
|
||||
float x,y,z;
|
||||
float yaw, pitch;
|
||||
float aperture, focus;
|
||||
|
||||
if (!(line >> x >> y >> z))
|
||||
throw std::runtime_error("Camera: Missing camera properties");
|
||||
|
||||
if (!(line >> yaw >> pitch))
|
||||
{
|
||||
yaw = 0;
|
||||
pitch = -90;
|
||||
}
|
||||
|
||||
if (!(line >> aperture >> focus))
|
||||
{
|
||||
aperture = 0.0;
|
||||
focus = 1.0;
|
||||
}
|
||||
|
||||
_scene->getCamera()->setPosition(glm::vec3(x, y, z));
|
||||
_scene->getCamera()->setDirection(yaw, pitch);
|
||||
_scene->getCamera()->setDOV(aperture, focus);
|
||||
|
||||
_scene->getCamera()->updateCameraVectors();
|
||||
}
|
||||
|
||||
bool SceneParser::parseLine(const std::string &line)
|
||||
|
@ -110,6 +110,18 @@ void Window::keyCallback(GLFWwindow *window, int key, int scancode, int action,
|
||||
{
|
||||
Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window));
|
||||
(void) win; (void) key; (void) scancode; (void) action; (void) mods;
|
||||
|
||||
if (key == 67 && action == GLFW_PRESS)
|
||||
{
|
||||
glm::vec3 pos = win->_scene->getCamera()->getPosition();
|
||||
glm::vec2 dir = win->_scene->getCamera()->getDirection();
|
||||
glm::vec2 dov = win->_scene->getCamera()->getDOV();
|
||||
|
||||
std::cout << "\nCAM\t" << pos.x << " " << pos.y << " " << pos.z << "\t"
|
||||
<< dir.x << " " << dir.y << " " << "\t"
|
||||
<< dov.x << " " << dov.y << " " << "\t"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Window::display()
|
||||
|
Reference in New Issue
Block a user