summaryrefslogtreecommitdiff
path: root/themes/LeafParticleRender.h
blob: 713d9f6499e63295d71785028e74d78e070a5a38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "Renderer2d.h"
#include "mathlib.h"
#include "types.h"

struct TreeShapeLoadResult;

struct LeafParticleLoadData {
    Vector2 initPosition;
    Vector4 initColor;
    int numLeaves = 48;
};

enum LeafParticleState {
    OnTree,
    Falling,
    OnGround,
    Remerging
};

struct LeafParticleUpdateData {
    LeafParticleState state = LeafParticleState::Remerging;

    Vertex2D* vertexToFollow = NULL;
    Vector4 color = Vector4(1.f, 0.f, 0.f, 0.f);
    f32 scale = 1.f;

    f32 timeElapsedSeconds = 0.f;
    i32 fallChance = -1;
    Vector2 fallPosition;
    f32 fallVerticalVelocity;
    f32 fallHorizontalFrequency;
    
    f32 resetTime = 0.f;

    Vertex2D* vertexPtr = NULL;
};

struct LeafParticleRender {
    f32 elapsedTimeSeconds = 0.5;
    f32 fallIntervalSeconds = 1.f;

    // Update data
    i32 numLeaves = 0;

    LeafParticleUpdateData* updateData = NULL;
    Vertex2D* vertices = NULL;

    // Render data
	u32 vao;
	u32 vbo;
	u32 numVertices = 0;
	Mat4x4 model;

    void load(Renderer2d* renderer, TreeShapeLoadResult* lr);
	void update(f32 dtSeconds);
	void render(Renderer2d* renderer);
	void unload();
};