libpsys

view src/psys.h @ 9:9c24273f211b

first test is done
author John Tsiombikas <nuclear@mutantstargoat.com>
date Wed, 28 Sep 2011 03:42:01 +0300
parents 3c0a306c5f01
children 23d4c50616ff
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, max_life;
62 float base_size;
64 struct psys_particle_attributes *pattr;
66 /* current particle attr values calculated during update */
67 vec3_t color;
68 float alpha, size;
70 struct psys_particle *next;
71 };
75 struct psys_emitter *psys_create(void);
76 void psys_free(struct psys_emitter *em);
78 int psys_init(struct psys_emitter *em);
79 void psys_destroy(struct psys_emitter *em);
81 /* set properties */
82 void psys_set_pos(struct psys_emitter *em, vec3_t pos, float tm);
83 void psys_set_rot(struct psys_emitter *em, quat_t rot, float tm);
84 void psys_set_pivot(struct psys_emitter *em, vec3_t pivot);
86 void psys_clear_collision_planes(struct psys_emitter *em);
87 int psys_add_collision_plane(struct psys_emitter *em, plane_t plane, float elast);
89 void psys_add_particle(struct psys_emitter *em, struct psys_particle *p);
91 void psys_spawn_func(struct psys_emitter *em, psys_spawn_func_t func, void *cls);
92 void psys_update_func(struct psys_emitter *em, psys_update_func_t func, void *cls);
93 void psys_draw_func(struct psys_emitter *em, psys_draw_func_t draw,
94 psys_draw_start_func_t start, psys_draw_end_func_t end, void *cls);
96 /* update and render */
98 void psys_update(struct psys_emitter *em, float tm);
99 void psys_draw(struct psys_emitter *em);
101 #endif /* LIBPSYS_H_ */