2 libpsys - reusable particle system library.
3 Copyright (C) 2011-2018 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <anim/anim.h>
28 typedef int (*psys_spawn_func_t)(struct psys_emitter*, struct psys_particle*, void*);
29 typedef void (*psys_update_func_t)(struct psys_emitter*, struct psys_particle*, long, float, void*);
31 typedef void (*psys_draw_func_t)(const struct psys_emitter*, const struct psys_particle*, void*);
32 typedef void (*psys_draw_start_func_t)(const struct psys_emitter*, void*);
33 typedef void (*psys_draw_end_func_t)(const struct psys_emitter*, void*);
39 struct psys_plane *next;
47 struct psys_attributes attr;
49 /* list of active particles */
50 struct psys_particle *plist;
51 int pcount; /* number of active particles */
53 /* list of collision planes */
54 struct psys_plane *planes;
56 /* custom spawn closure */
58 psys_spawn_func_t spawn;
60 /* custom particle update closure */
62 psys_update_func_t update;
64 /* custom draw closure */
66 psys_draw_func_t draw;
67 psys_draw_start_func_t draw_start;
68 psys_draw_end_func_t draw_end;
70 long spawn_acc; /* partial spawn accumulator */
71 long last_update; /* last update time (to calc dt) */
75 struct psys_particle {
81 struct psys_particle_attributes *pattr;
83 /* current particle attr values calculated during update */
87 struct psys_particle *next;
94 struct psys_emitter *psys_create(void);
95 void psys_free(struct psys_emitter *em);
97 int psys_init(struct psys_emitter *em);
98 void psys_destroy(struct psys_emitter *em);
102 /* set emitter position. pos should point to 3 floats (xyz) */
103 void psys_set_pos(struct psys_emitter *em, const float *pos, long tm);
104 void psys_set_pos3f(struct psys_emitter *em, float x, float y, float z, long tm);
105 /* set emitter rotation quaternion. qrot should point to 4 floats (xyzw) */
106 void psys_set_rot(struct psys_emitter *em, const float *qrot, long tm);
107 void psys_set_rot4f(struct psys_emitter *em, float x, float y, float z, float w, long tm);
108 /* set emitter rotation by defining a rotation axis, and an angle */
109 void psys_set_rot_axis(struct psys_emitter *em, float angle, float x, float y, float z, long tm);
110 /* set rotation pivot point. pos should point to 3 floats (xyz) */
111 void psys_set_pivot(struct psys_emitter *em, const float *pivot);
112 void psys_set_pivot3f(struct psys_emitter *em, float x, float y, float z);
114 /* pos should be a pointer to 3 floats (xyz) */
115 void psys_get_pos(struct psys_emitter *em, float *pos, long tm);
116 /* qrot should be a pointer to 4 floats (xyzw) */
117 void psys_get_rot(struct psys_emitter *em, float *qrot, long tm);
118 /* pivot should be a pointer to 3 floats (xyz) */
119 void psys_get_pivot(struct psys_emitter *em, float *pivot);
121 void psys_clear_collision_planes(struct psys_emitter *em);
122 int psys_add_collision_plane(struct psys_emitter *em, const float *plane, float elast);
124 void psys_add_particle(struct psys_emitter *em, struct psys_particle *p);
126 void psys_spawn_func(struct psys_emitter *em, psys_spawn_func_t func, void *cls);
127 void psys_update_func(struct psys_emitter *em, psys_update_func_t func, void *cls);
128 void psys_draw_func(struct psys_emitter *em, psys_draw_func_t draw,
129 psys_draw_start_func_t start, psys_draw_end_func_t end, void *cls);
131 /* update and render */
133 void psys_update(struct psys_emitter *em, long tm);
134 void psys_draw(const struct psys_emitter *em);
140 #endif /* LIBPSYS_H_ */