+ | Optimization + reflection

This commit is contained in:
TheRedShip
2025-01-02 16:33:21 +01:00
parent 21f2e84b61
commit 5d92a82b66
14 changed files with 204 additions and 101 deletions

View File

@ -38,22 +38,18 @@ void Camera::update_camera_vectors()
void Camera::update(float delta_time)
{
delta_time = 0.016;
_velocity += _acceleration * delta_time;
// std::cout << _acceleration.x << " " << _acceleration.y << " " << _acceleration.z << " " << std::endl;
// Apply deceleration when no acceleration
if (glm::length(_acceleration) < 0.1f)
_velocity *= (1.0f - _deceleration_rate * delta_time);
// Clamp velocity to maximum speed
float speed = glm::length(_velocity);
if (speed > _maxSpeed)
_velocity = (_velocity / speed) * _maxSpeed;
// Update position
_position += _velocity * delta_time;
// Reset acceleration
_acceleration = glm::vec3(0.0f);
}

View File

@ -72,17 +72,24 @@ void Scene::updateGPUData()
mat = getMaterial(obj->getMaterialIndex());
gpu_obj.position = obj->getPosition();
gpu_obj.color = mat->color;
gpu_obj.emission = mat->emission;
gpu_obj.roughness = mat->roughness;
gpu_obj.specular = mat->specular;
gpu_obj.type = static_cast<int>(obj->getType());
if (obj->getType() == Object::Type::SPHERE)
{
auto sphere = static_cast<const Sphere*>(obj);
auto sphere = static_cast<const Sphere *>(obj);
gpu_obj.radius = sphere->getRadius();
}
else if (obj->getType() == Object::Type::PLANE)
{
auto plane = static_cast<const Plane *>(obj);
gpu_obj.normal = plane->getNormal();
}
_gpu_objects.push_back(gpu_obj);
}

View File

@ -14,10 +14,16 @@
SceneParser::SceneParser(Scene *scene) : _scene(scene)
{
object_parsers["sp"] = [](std::stringstream& ss) -> Object*
object_parsers["sp"] = [](std::stringstream &ss) -> Object *
{
try { return (new Sphere(ss)); }
catch (const std::exception& e) { throw; }
catch (const std::exception &e) { throw; }
};
object_parsers["pl"] = [](std::stringstream &ss) -> Object *
{
try { return (new Plane(ss)); }
catch (const std::exception &e) { throw; }
};
}

View File

@ -66,6 +66,7 @@ void Window::process_input()
if (forward || backward || left || right || up || down)
_frameCount = 0;
_scene->getCamera()->process_keyboard(forward, backward, left, right, up, down);
}
@ -89,7 +90,6 @@ 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->_frameCount = 0;
}
@ -116,10 +116,11 @@ void Window::display()
{
static double lastTime = glfwGetTime();
double currentTime = glfwGetTime();
double delta = currentTime - lastTime;
_delta = currentTime - lastTime;
lastTime = currentTime;
_fps = 1.0f / delta;
_fps = 1.0f / _delta;
_frameCount++;
@ -128,7 +129,7 @@ void Window::display()
void Window::pollEvents()
{
this->process_input();
_scene->getCamera()->update(1.0f / _fps);
_scene->getCamera()->update(_delta);
glfwPollEvents();
}