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/>.
21 int psys_init_anm_rnd(struct psys_anm_rnd *r)
23 if(psys_init_track(&r->value) == -1) {
26 if(psys_init_track(&r->range) == -1) {
27 psys_destroy_track(&r->value);
33 void psys_destroy_anm_rnd(struct psys_anm_rnd *r)
35 psys_destroy_track(&r->value);
36 psys_destroy_track(&r->range);
39 int psys_init_anm_rnd3(struct psys_anm_rnd3 *r)
41 if(psys_init_track3(&r->value) == -1) {
44 if(psys_init_track3(&r->range) == -1) {
45 psys_destroy_track3(&r->value);
51 void psys_destroy_anm_rnd3(struct psys_anm_rnd3 *r)
53 psys_destroy_track3(&r->value);
54 psys_destroy_track3(&r->range);
57 void psys_copy_anm_rnd(struct psys_anm_rnd *dest, const struct psys_anm_rnd *src)
59 psys_copy_track(&dest->value, &src->value);
60 psys_copy_track(&dest->range, &src->range);
63 void psys_copy_anm_rnd3(struct psys_anm_rnd3 *dest, const struct psys_anm_rnd3 *src)
65 psys_copy_track3(&dest->value, &src->value);
66 psys_copy_track3(&dest->range, &src->range);
69 void psys_set_rnd(struct psys_rnd *r, float val, float range)
75 void psys_set_rnd3(struct psys_rnd3 *r, const float *val, const float *range)
80 r->range[i] = range[i];
84 void psys_set_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm, float val, float range)
86 psys_set_value(&r->value, tm, val);
87 psys_set_value(&r->range, tm, range);
90 void psys_set_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm, const float *val, const float *range)
92 psys_set_value3(&r->value, tm, val[0], val[1], val[2]);
93 psys_set_value3(&r->range, tm, range[0], range[1], range[2]);
97 float psys_eval_rnd(struct psys_rnd *r)
99 return r->value + r->range * (float)rand() / (float)RAND_MAX - 0.5 * r->range;
102 void psys_eval_rnd3(struct psys_rnd3 *r, float *val)
104 val[0] = r->value[0] + r->range[0] * (float)rand() / (float)RAND_MAX - 0.5 * r->range[0];
105 val[1] = r->value[1] + r->range[1] * (float)rand() / (float)RAND_MAX - 0.5 * r->range[1];
106 val[2] = r->value[2] + r->range[2] * (float)rand() / (float)RAND_MAX - 0.5 * r->range[2];
110 float psys_eval_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm)
113 if(tm == ANM_TIME_INVAL) {
114 tmp.value = psys_get_cur_value(&r->value);
115 tmp.range = psys_get_cur_value(&r->range);
117 tmp.value = psys_get_value(&r->value, tm);
118 tmp.range = psys_get_value(&r->range, tm);
120 return psys_eval_rnd(&tmp);
123 void psys_eval_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm, float *val)
125 struct psys_rnd3 tmp;
126 if(tm == ANM_TIME_INVAL) {
127 psys_get_cur_value3(&r->value, tmp.value);
128 psys_get_cur_value3(&r->range, tmp.range);
130 psys_get_value3(&r->value, tm, tmp.value);
131 psys_get_value3(&r->range, tm, tmp.range);
133 psys_eval_rnd3(&tmp, val);