vrshoot

annotate libs/psys/psys.h @ 1:e7ca128b8713

looks nice :)
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 02 Feb 2014 00:35:22 +0200
parents
children
rev   line source
nuclear@0 1 #ifndef LIBPSYS_H_
nuclear@0 2 #define LIBPSYS_H_
nuclear@0 3
nuclear@0 4 #include <vmath/vmath.h>
nuclear@0 5 #include <anim/anim.h>
nuclear@0 6 #include "rndval.h"
nuclear@0 7 #include "pattr.h"
nuclear@0 8
nuclear@0 9 struct psys_particle;
nuclear@0 10 struct psys_emitter;
nuclear@0 11
nuclear@0 12 typedef int (*psys_spawn_func_t)(struct psys_emitter*, struct psys_particle*, void*);
nuclear@0 13 typedef void (*psys_update_func_t)(struct psys_emitter*, struct psys_particle*, float, float, void*);
nuclear@0 14
nuclear@0 15 typedef void (*psys_draw_func_t)(const struct psys_emitter*, const struct psys_particle*, void*);
nuclear@0 16 typedef void (*psys_draw_start_func_t)(const struct psys_emitter*, void*);
nuclear@0 17 typedef void (*psys_draw_end_func_t)(const struct psys_emitter*, void*);
nuclear@0 18
nuclear@0 19
nuclear@0 20 struct psys_plane {
nuclear@0 21 plane_t p;
nuclear@0 22 float elasticity;
nuclear@0 23 struct psys_plane *next;
nuclear@0 24 };
nuclear@0 25
nuclear@0 26
nuclear@0 27 struct psys_emitter {
nuclear@0 28 struct anm_node prs;
nuclear@0 29 vec3_t cur_pos;
nuclear@0 30
nuclear@0 31 struct psys_attributes attr;
nuclear@0 32
nuclear@0 33 /* list of active particles */
nuclear@0 34 struct psys_particle *plist;
nuclear@0 35 int pcount; /* number of active particles */
nuclear@0 36
nuclear@0 37 /* list of collision planes */
nuclear@0 38 struct psys_plane *planes;
nuclear@0 39
nuclear@0 40 /* custom spawn closure */
nuclear@0 41 void *spawn_cls;
nuclear@0 42 psys_spawn_func_t spawn;
nuclear@0 43
nuclear@0 44 /* custom particle update closure */
nuclear@0 45 void *upd_cls;
nuclear@0 46 psys_update_func_t update;
nuclear@0 47
nuclear@0 48 /* custom draw closure */
nuclear@0 49 void *draw_cls;
nuclear@0 50 psys_draw_func_t draw;
nuclear@0 51 psys_draw_start_func_t draw_start;
nuclear@0 52 psys_draw_end_func_t draw_end;
nuclear@0 53
nuclear@0 54 float spawn_acc; /* partial spawn accumulator */
nuclear@0 55 float last_update; /* last update time (to calc dt) */
nuclear@0 56 };
nuclear@0 57
nuclear@0 58
nuclear@0 59 struct psys_particle {
nuclear@0 60 vec3_t pos, vel;
nuclear@0 61 float life, max_life;
nuclear@0 62 float base_size;
nuclear@0 63
nuclear@0 64 struct psys_particle_attributes *pattr;
nuclear@0 65
nuclear@0 66 /* current particle attr values calculated during update */
nuclear@0 67 vec3_t color;
nuclear@0 68 float alpha, size;
nuclear@0 69
nuclear@0 70 struct psys_particle *next;
nuclear@0 71 };
nuclear@0 72
nuclear@0 73 #ifdef __cplusplus
nuclear@0 74 extern "C" {
nuclear@0 75 #endif
nuclear@0 76
nuclear@0 77 struct psys_emitter *psys_create(void);
nuclear@0 78 void psys_free(struct psys_emitter *em);
nuclear@0 79
nuclear@0 80 int psys_init(struct psys_emitter *em);
nuclear@0 81 void psys_destroy(struct psys_emitter *em);
nuclear@0 82
nuclear@0 83 /* set properties */
nuclear@0 84 void psys_set_pos(struct psys_emitter *em, vec3_t pos, float tm);
nuclear@0 85 void psys_set_rot(struct psys_emitter *em, quat_t rot, float tm);
nuclear@0 86 void psys_set_pivot(struct psys_emitter *em, vec3_t pivot);
nuclear@0 87
nuclear@0 88 vec3_t psys_get_pos(struct psys_emitter *em, float tm);
nuclear@0 89 quat_t psys_get_rot(struct psys_emitter *em, float tm);
nuclear@0 90 vec3_t psys_get_pivot(struct psys_emitter *em);
nuclear@0 91
nuclear@0 92 void psys_clear_collision_planes(struct psys_emitter *em);
nuclear@0 93 int psys_add_collision_plane(struct psys_emitter *em, plane_t plane, float elast);
nuclear@0 94
nuclear@0 95 void psys_add_particle(struct psys_emitter *em, struct psys_particle *p);
nuclear@0 96
nuclear@0 97 void psys_spawn_func(struct psys_emitter *em, psys_spawn_func_t func, void *cls);
nuclear@0 98 void psys_update_func(struct psys_emitter *em, psys_update_func_t func, void *cls);
nuclear@0 99 void psys_draw_func(struct psys_emitter *em, psys_draw_func_t draw,
nuclear@0 100 psys_draw_start_func_t start, psys_draw_end_func_t end, void *cls);
nuclear@0 101
nuclear@0 102 /* update and render */
nuclear@0 103
nuclear@0 104 void psys_update(struct psys_emitter *em, float tm);
nuclear@0 105 void psys_draw(const struct psys_emitter *em);
nuclear@0 106
nuclear@0 107 #ifdef __cplusplus
nuclear@0 108 }
nuclear@0 109 #endif
nuclear@0 110
nuclear@0 111 #endif /* LIBPSYS_H_ */