~ | Variable refactoring

This commit is contained in:
TheRedShip
2025-01-05 14:50:29 +01:00
parent 846efdd5c6
commit b9b7084a4f
6 changed files with 36 additions and 17 deletions

View File

@ -16,14 +16,14 @@ Camera::Camera(glm::vec3 start_pos, glm::vec3 start_up, float start_yaw, float s
: _position(start_pos), _forward(glm::vec3(0.0f, 0.0f, -1.0f)), _up(start_up), _pitch(start_pitch), _yaw(start_yaw),
_velocity(0.0f), _acceleration(0.0f)
{
update_camera_vectors();
updateCameraVectors();
}
Camera::~Camera(void)
{
}
void Camera::update_camera_vectors()
void Camera::updateCameraVectors()
{
glm::vec3 frontTemp;
@ -54,7 +54,7 @@ void Camera::update(float delta_time)
}
void Camera::process_mouse(float xoffset, float yoffset, bool constraint_pitch = true)
void Camera::processMouse(float xoffset, float yoffset, bool constraint_pitch = true)
{
_yaw += xoffset * _sensitivity;
_pitch += yoffset * _sensitivity;
@ -65,10 +65,10 @@ void Camera::process_mouse(float xoffset, float yoffset, bool constraint_pitch
if (_pitch < -89.0f) _pitch = -89.0f;
}
update_camera_vectors();
updateCameraVectors();
}
void Camera::process_keyboard(bool forward, bool backward, bool left, bool right, bool up, bool down)
void Camera::processKeyboard(bool forward, bool backward, bool left, bool right, bool up, bool down)
{
glm::vec3 acceleration(0.0f);
@ -85,12 +85,17 @@ void Camera::process_keyboard(bool forward, bool backward, bool left, bool righ
_acceleration = acceleration;
}
glm::mat4 Camera::get_view_matrix()
glm::mat4 Camera::getViewMatrix()
{
return (glm::lookAt(_position, _position + _forward, _up));
}
glm::vec3 Camera::get_position()
glm::vec3 Camera::getPosition()
{
return (_position);
}
void Camera::setPosition(glm::vec3 position)
{
_position = position;
}

View File

@ -54,6 +54,16 @@ void SceneParser::parseMaterial(std::stringstream &line)
_scene->addMaterial(mat);
}
void SceneParser::parseCamera(std::stringstream &line)
{
float x,y,z;
if (!(line >> x >> y >> z))
throw std::runtime_error("Camera: Missing camera properties");
_scene->getCamera()->setPosition(glm::vec3(x, y, z));
}
bool SceneParser::parseLine(const std::string &line)
{
if (line.empty() || line[0] == '#')
@ -77,6 +87,8 @@ bool SceneParser::parseLine(const std::string &line)
if (identifier == "MAT")
this->parseMaterial(ss);
else if (identifier == "CAM")
this->parseCamera(ss);
}
catch (const std::exception& e)
{

View File

@ -67,7 +67,7 @@ void Window::process_input()
if (forward || backward || left || right || up || down)
_frameCount = 0;
_scene->getCamera()->process_keyboard(forward, backward, left, right, up, down);
_scene->getCamera()->processKeyboard(forward, backward, left, right, up, down);
}
void Window::mouseMoveCallback(GLFWwindow* window, double xpos, double ypos)
@ -89,7 +89,7 @@ void Window::mouseMoveCallback(GLFWwindow* window, double xpos, double ypos)
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS)
{
win->_scene->getCamera()->process_mouse(xoffset, yoffset, true);
win->_scene->getCamera()->processMouse(xoffset, yoffset, true);
win->_frameCount = 0;
}