libpsys
view src/rndval.c @ 4:0fe624ffcb4f
reorg
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Mon, 26 Sep 2011 18:25:18 +0300 |
parents | |
children | 613d2bf3ea1f |
line source
1 #include <stdlib.h>
2 #include "rndval.h"
4 int psys_init_anm_rnd(struct psys_anm_rnd *r)
5 {
6 if(anm_init_track(&r->value) == -1) {
7 return -1;
8 }
9 if(anm_init_track(&r->range) == -1) {
10 anm_destroy_track(&r->value);
11 return -1;
12 }
13 return 0;
14 }
16 void psys_destroy_anm_rnd(struct psys_anm_rnd *r)
17 {
18 anm_destroy_track(&r->value);
19 anm_destroy_track(&r->range);
20 }
22 int psys_init_anm_rnd3(struct psys_anm_rnd3 *r)
23 {
24 if(anm_init_track3(&r->value) == -1) {
25 return -1;
26 }
27 if(anm_init_track3(&r->range) == -1) {
28 anm_destroy_track3(&r->value);
29 return -1;
30 }
31 return 0;
32 }
34 void psys_destroy_anm_rnd3(struct psys_anm_rnd3 *r)
35 {
36 anm_destroy_track3(&r->value);
37 anm_destroy_track3(&r->range);
38 }
41 float psys_eval_rnd(struct psys_rnd *r)
42 {
43 return r->value + r->range * (float)rand() / (float)RAND_MAX - 0.5 * r->range;
44 }
46 vec3_t psys_eval_rnd3(struct psys_rnd3 *r)
47 {
48 vec3_t res;
49 res.x = r->value.x + r->range.x * (float)rand() / (float)RAND_MAX - 0.5 * r->range.x;
50 res.y = r->value.y + r->range.y * (float)rand() / (float)RAND_MAX - 0.5 * r->range.y;
51 res.z = r->value.z + r->range.z * (float)rand() / (float)RAND_MAX - 0.5 * r->range.z;
52 return res;
53 }
56 float psys_eval_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm)
57 {
58 if(r->cur_tm != tm) {
59 r->cur.value = anm_get_value(&r->value, tm);
60 r->cur.range = anm_get_value(&r->range, tm);
61 r->cur_tm = tm;
62 }
63 return psys_eval_rnd(&r->cur);
64 }
66 vec3_t psys_eval_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm)
67 {
68 if(r->cur_tm != tm) {
69 r->cur.value = anm_get_value3(&r->value, tm);
70 r->cur.range = anm_get_value3(&r->range, tm);
71 r->cur_tm = tm;
72 }
73 return psys_eval_rnd3(&r->cur);
74 }