Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
ParticleStretch.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
23
24inline glm::vec2 velocityOnScreen(const glm::vec3& velocity, const glm::vec3& towardViewer) {
25 const f32 reach = glm::length(towardViewer);
26 if (reach <= 1e-6f) return {velocity.x, velocity.y};
27 const glm::vec3 fwd = towardViewer / reach;
28 const glm::vec3 refUp = std::abs(fwd.y) > 0.999f ? glm::vec3(0.0f, 0.0f, 1.0f) : glm::vec3(0.0f, 1.0f, 0.0f);
29 const glm::vec3 right = glm::normalize(glm::cross(refUp, fwd));
30 const glm::vec3 up = glm::cross(fwd, right);
31 return {glm::dot(velocity, right), glm::dot(velocity, up)};
32}
33
34inline StretchedQuad stretchedQuad(glm::vec2 velocity, f32 rotation, f32 size, f32 lengthScale, f32 velocityScale) {
35 const f32 speed = glm::length(velocity);
36 if (speed <= 1e-4f) return {rotation, size};
37 constexpr f32 kHalfPi = 1.57079632679f;
38 return {std::atan2(velocity.y, velocity.x) - kHalfPi, size * lengthScale + speed * velocityScale};
39}
40
41} // namespace esengine::particle
Core type definitions and utilities for ESEngine.
StretchedQuad stretchedQuad(glm::vec2 velocity, f32 rotation, f32 size, f32 lengthScale, f32 velocityScale)
glm::vec2 velocityOnScreen(const glm::vec3 &velocity, const glm::vec3 &towardViewer)
glm::vec3 towardViewer(const glm::vec3 &worldPos, const CameraView &camera)
Decomposes transform and returns its world position shifted toward the camera by (1 - parallax); fact...
float f32
32-bit floating point
Definition Types.hpp:59
How a stretched particle's quad is laid along its velocity.
f32 rotation
Radians, counter-clockwise, turning the quad's +Y onto the velocity.
f32 length
The quad's extent along its Y.