libpsys

view src/psys.h @ 7:3c0a306c5f01

revamped the makefile a bit and changed all <vmath.h> to <vmath/vmath.h> to avoid relying on pkg-config
author John Tsiombikas <nuclear@mutantstargoat.com>
date Tue, 27 Sep 2011 07:52:01 +0300
parents 613d2bf3ea1f
children 9c24273f211b
line source
1 #ifndef LIBPSYS_H_
2 #define LIBPSYS_H_
4 #include <vmath/vmath.h>
5 #include <anim/anim.h>
6 #include "rndval.h"
7 #include "pattr.h"
9 struct psys_particle;
10 struct psys_emitter;
12 typedef int (*psys_spawn_func_t)(struct psys_emitter*, struct psys_particle*, void*);
13 typedef void (*psys_update_func_t)(struct psys_emitter*, struct psys_particle*, float, float, void*);
15 typedef void (*psys_draw_func_t)(struct psys_emitter*, struct psys_particle*, void*);
16 typedef void (*psys_draw_start_func_t)(struct psys_emitter*, void*);
17 typedef void (*psys_draw_end_func_t)(struct psys_emitter*, void*);
20 struct psys_plane {
21 plane_t p;
22 float elasticity;
23 struct psys_plane *next;
24 };
27 struct psys_emitter {
28 struct anm_node prs;
29 vec3_t cur_pos;
31 struct psys_attributes attr;
33 /* list of active particles */
34 struct psys_particle *plist;
35 int pcount; /* number of active particles */
37 /* list of collision planes */
38 struct psys_plane *planes;
40 /* custom spawn closure */
41 void *spawn_cls;
42 psys_spawn_func_t spawn;
44 /* custom particle update closure */
45 void *upd_cls;
46 psys_update_func_t update;
48 /* custom draw closure */
49 void *draw_cls;
50 psys_draw_func_t draw;
51 psys_draw_start_func_t draw_start;
52 psys_draw_end_func_t draw_end;
54 float spawn_acc; /* partial spawn accumulator */
55 float last_update; /* last update time (to calc dt) */
56 };
59 struct psys_particle {
60 vec3_t pos, vel;
61 float life, size;
63 struct psys_particle *next;
64 };
68 struct psys_emitter *psys_create(void);
69 void psys_free(struct psys_emitter *em);
71 int psys_init(struct psys_emitter *em);
72 void psys_destroy(struct psys_emitter *em);
74 /* set properties */
75 void psys_set_pos(struct psys_emitter *em, vec3_t pos, float tm);
76 void psys_set_rot(struct psys_emitter *em, quat_t rot, float tm);
77 void psys_set_pivot(struct psys_emitter *em, vec3_t pivot);
79 void psys_clear_collision_planes(struct psys_emitter *em);
80 int psys_add_collision_plane(struct psys_emitter *em, plane_t plane, float elast);
82 void psys_add_particle(struct psys_emitter *em, struct psys_particle *p);
84 void psys_spawn_func(struct psys_emitter *em, psys_spawn_func_t func, void *cls);
85 void psys_update_func(struct psys_emitter *em, psys_update_func_t func, void *cls);
86 void psys_draw_func(struct psys_emitter *em, psys_draw_func_t draw,
87 psys_draw_start_func_t start, psys_draw_end_func_t end, void *cls);
89 /* update and render */
91 void psys_update(struct psys_emitter *em, float tm);
92 void psys_draw(struct psys_emitter *em);
94 #endif /* LIBPSYS_H_ */