Added sparks

This commit is contained in:
Vladislav Khorev committed 2026-04-24 19:53:18 +03:00
1 parent 2bb7da2e37
commit 393ebcd831
6 files changed
+202 -27

No files matched your search

+24 -2
View File
@@ -51,9 +51,18 @@ namespace ZL {
std::string shaderProgramName;
bool configured;
void prepareDrawData(bool withRotation);
// Rebuilds the CPU-side quad/UV arrays. If cameraViewMatrix is identity,
// particles are rendered as axis-aligned quads in world XY and sorted by
// world Z (legacy behavior). Otherwise quads are billboarded toward the
// camera using its world-space right/up axes, and particles are sorted
// back-to-front in eye space for correct alpha blending.
void prepareDrawData(const Eigen::Matrix4f& cameraViewMatrix);
bool useWorldSpace;
// When non-zero, velocities spray in a cone around this direction
// instead of the default planar XY + Z spread used by JSON emitters.
Vector3f emissionDirection = Vector3f{ 0.f, 0.f, 0.f };
public:
SparkEmitter();
SparkEmitter(const SparkEmitter& copyFrom);
@@ -74,11 +83,24 @@ namespace ZL {
void setUseWorldSpace(bool use) { useWorldSpace = use; }
bool loadFromJsonFile(const std::string& path, Renderer& renderer, const std::string& zipFile = "");
// Programmatic configuration (alternative to loadFromJsonFile).
// Ranges follow the same semantics as the JSON fields.
void setSpeedRange(float minVal, float maxVal) { speedRange.min = minVal; speedRange.max = maxVal; }
void setZSpeedRange(float minVal, float maxVal) { zSpeedRange.min = minVal; zSpeedRange.max = maxVal; }
void setScaleRange(float minVal, float maxVal) { scaleRange.min = minVal; scaleRange.max = maxVal; }
void setLifeTimeRange(float minVal, float maxVal) { lifeTimeRange.min = minVal; lifeTimeRange.max = maxVal; }
void setEmissionDirection(const Vector3f& dir) { emissionDirection = dir; }
void markConfigured() { configured = true; }
bool isConfigured() const { return configured; }
void update(float deltaTimeMs);
void emit(float ageMs = 0.0f, float lerpT = 0.0f);
// Вызывать ДО draw() в начале кадра: готовит данные и загружает в VBO.
void prepareForDraw(bool withRotation = true);
// Pass the current camera view matrix (world → eye) to billboard sparks
// toward the camera and sort them back-to-front. Identity (default)
// keeps the legacy non-billboarded behavior.
void prepareForDraw(const Eigen::Matrix4f& cameraViewMatrix = Eigen::Matrix4f::Identity());
void draw(Renderer& renderer, float zoom, int screenWidth, int screenHeight);
void draw(Renderer& renderer, float zoom, int screenWidth, int screenHeight, bool withRotation);