Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
ParticleSpeedLimit.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
3#pragma once
4
5#include "../core/Types.hpp"
6
7#include <glm/glm.hpp>
8
9#include <cmath>
10
11namespace esengine::particle {
12
20inline glm::vec3 limitedVelocity(glm::vec3 velocity, f32 limit, f32 dampen, f32 dt) {
21 const f32 speed = glm::length(velocity);
22 if (limit <= 0.0f || speed <= limit) return velocity;
23 const f32 keep = std::pow(1.0f - glm::clamp(dampen, 0.0f, 1.0f), dt * 60.0f); // the part of the excess left after dt
24 const f32 target = limit + (speed - limit) * keep;
25 return velocity * (target / speed);
26}
27
28} // namespace esengine::particle
Core type definitions and utilities for ESEngine.
glm::vec3 limitedVelocity(glm::vec3 velocity, f32 limit, f32 dampen, f32 dt)
A particle's velocity after its speed limit has pulled it back.
float f32
32-bit floating point
Definition Types.hpp:59