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/>.
20 int psys_init_track(struct psys_track *track)
22 track->cache_tm = ANM_TIME_INVAL;
24 if(anm_init_track(&track->trk) == -1) {
30 void psys_destroy_track(struct psys_track *track)
32 anm_destroy_track(&track->trk);
35 int psys_init_track3(struct psys_track3 *track)
37 track->cache_tm = ANM_TIME_INVAL;
39 if(anm_init_track(&track->x) == -1) {
42 if(anm_init_track(&track->y) == -1) {
43 anm_destroy_track(&track->x);
46 if(anm_init_track(&track->z) == -1) {
47 anm_destroy_track(&track->x);
48 anm_destroy_track(&track->z);
54 void psys_destroy_track3(struct psys_track3 *track)
56 anm_destroy_track(&track->x);
57 anm_destroy_track(&track->y);
58 anm_destroy_track(&track->z);
61 void psys_copy_track(struct psys_track *dest, const struct psys_track *src)
63 anm_copy_track(&dest->trk, &src->trk);
64 dest->cache_tm = ANM_TIME_INVAL;
67 void psys_copy_track3(struct psys_track3 *dest, const struct psys_track3 *src)
69 anm_copy_track(&dest->x, &src->x);
70 anm_copy_track(&dest->y, &src->y);
71 anm_copy_track(&dest->z, &src->z);
73 dest->cache_tm = ANM_TIME_INVAL;
76 void psys_eval_track(struct psys_track *track, anm_time_t tm)
78 if(track->cache_tm != tm) {
80 track->cache_val = anm_get_value(&track->trk, tm);
84 void psys_set_value(struct psys_track *track, anm_time_t tm, float v)
86 anm_set_value(&track->trk, tm, v);
87 track->cache_tm = ANM_TIME_INVAL;
90 float psys_get_value(struct psys_track *track, anm_time_t tm)
92 psys_eval_track(track, tm);
93 return track->cache_val;
96 float psys_get_cur_value(struct psys_track *track)
98 return track->cache_val;
102 void psys_eval_track3(struct psys_track3 *track, anm_time_t tm)
104 if(track->cache_tm != tm) {
105 track->cache_tm = tm;
106 track->cache_vec[0] = anm_get_value(&track->x, tm);
107 track->cache_vec[1] = anm_get_value(&track->y, tm);
108 track->cache_vec[2] = anm_get_value(&track->z, tm);
112 void psys_set_value3(struct psys_track3 *track, anm_time_t tm, float x, float y, float z)
114 anm_set_value(&track->x, tm, x);
115 anm_set_value(&track->y, tm, y);
116 anm_set_value(&track->z, tm, z);
117 track->cache_tm = ANM_TIME_INVAL;
120 float *psys_get_value3(struct psys_track3 *track, anm_time_t tm, float *vec)
122 psys_eval_track3(track, tm);
124 vec[0] = track->cache_vec[0];
125 vec[1] = track->cache_vec[1];
126 vec[2] = track->cache_vec[2];
128 return track->cache_vec;
131 float *psys_get_cur_value3(struct psys_track3 *track, float *vec)
134 vec[0] = track->cache_vec[0];
135 vec[1] = track->cache_vec[1];
136 vec[2] = track->cache_vec[2];
138 return track->cache_vec;