added cgmath, libanim, and libpsys
[andemo] / libs / psys / pattr.h
1 /*
2 libpsys - reusable particle system library.
3 Copyright (C) 2011-2018  John Tsiombikas <nuclear@member.fsf.org>
4
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.
9
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.
14
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/>.
17 */
18 #ifndef PATTR_H_
19 #define PATTR_H_
20
21 #include <stdio.h>
22 #include "pstrack.h"
23 #include "rndval.h"
24
25 /* the particle attributes vary from 0 to 1 during its lifetime */
26 struct psys_particle_attributes {
27         struct psys_track3 color;
28         struct psys_track alpha;
29         struct psys_track size;
30 };
31
32 enum psys_blending { PSYS_ADD, PSYS_ALPHA };
33
34 struct psys_attributes {
35         unsigned int tex;       /* OpenGL texture to use for the billboard */
36
37         struct psys_track3 spawn_range; /* radius of emmiter */
38         struct psys_track rate;                 /* spawn rate particles per sec */
39         struct psys_anm_rnd life;               /* particle life in seconds */
40         struct psys_anm_rnd size;               /* base particle size */
41         struct psys_anm_rnd3 dir;               /* particle shoot direction */
42
43         struct psys_track3 grav;                /* external force (usually gravity) */
44         float drag;     /* I don't think this needs to animate */
45
46         enum psys_blending blending;
47
48         /* particle attributes */
49         struct psys_particle_attributes part_attr;
50
51         /* limits */
52         int max_particles;
53 };
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 void psys_texture_loader(unsigned int (*load)(const char*, void*), void (*unload)(unsigned int, void*), void *cls);
60
61 struct psys_attributes *psys_create_attr(void);
62 void psys_free_attr(struct psys_attributes *attr);
63
64 int psys_init_attr(struct psys_attributes *attr);
65 void psys_destroy_attr(struct psys_attributes *attr);
66
67 /* copies particle system attributes src to dest
68  * XXX: dest must have been initialized first
69  */
70 void psys_copy_attr(struct psys_attributes *dest, const struct psys_attributes *src);
71
72 void psys_eval_attr(struct psys_attributes *attr, anm_time_t tm);
73
74 int psys_load_attr(struct psys_attributes *attr, const char *fname);
75 int psys_load_attr_stream(struct psys_attributes *attr, FILE *fp);
76
77 int psys_save_attr(const struct psys_attributes *attr, const char *fname);
78 int psys_save_attr_stream(const struct psys_attributes *attr, FILE *fp);
79
80 #ifdef __cplusplus
81 }
82 #endif
83
84 #endif  /* PATTR_H_ */