libpsys
view src/rndval.c @ 15:5678915dc2c7
probably done with the psys loader
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Mon, 10 Sep 2012 21:57:49 +0300 |
parents | 613d2bf3ea1f |
children |
line source
1 #include <stdlib.h>
2 #include "rndval.h"
4 int psys_init_anm_rnd(struct psys_anm_rnd *r)
5 {
6 if(psys_init_track(&r->value) == -1) {
7 return -1;
8 }
9 if(psys_init_track(&r->range) == -1) {
10 psys_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 psys_destroy_track(&r->value);
19 psys_destroy_track(&r->range);
20 }
22 int psys_init_anm_rnd3(struct psys_anm_rnd3 *r)
23 {
24 if(psys_init_track3(&r->value) == -1) {
25 return -1;
26 }
27 if(psys_init_track3(&r->range) == -1) {
28 psys_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 psys_destroy_track3(&r->value);
37 psys_destroy_track3(&r->range);
38 }
41 void psys_set_rnd(struct psys_rnd *r, float val, float range)
42 {
43 r->value = val;
44 r->range = range;
45 }
47 void psys_set_rnd3(struct psys_rnd3 *r, vec3_t val, vec3_t range)
48 {
49 r->value = val;
50 r->range = range;
51 }
53 void psys_set_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm, float val, float range)
54 {
55 psys_set_value(&r->value, tm, val);
56 psys_set_value(&r->range, tm, range);
57 }
59 void psys_set_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm, vec3_t val, vec3_t range)
60 {
61 psys_set_value3(&r->value, tm, val);
62 psys_set_value3(&r->range, tm, range);
63 }
66 float psys_eval_rnd(struct psys_rnd *r)
67 {
68 return r->value + r->range * (float)rand() / (float)RAND_MAX - 0.5 * r->range;
69 }
71 vec3_t psys_eval_rnd3(struct psys_rnd3 *r)
72 {
73 vec3_t res;
74 res.x = r->value.x + r->range.x * (float)rand() / (float)RAND_MAX - 0.5 * r->range.x;
75 res.y = r->value.y + r->range.y * (float)rand() / (float)RAND_MAX - 0.5 * r->range.y;
76 res.z = r->value.z + r->range.z * (float)rand() / (float)RAND_MAX - 0.5 * r->range.z;
77 return res;
78 }
81 float psys_eval_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm)
82 {
83 struct psys_rnd tmp;
84 if(tm == ANM_TIME_INVAL) {
85 tmp.value = psys_get_cur_value(&r->value);
86 tmp.range = psys_get_cur_value(&r->range);
87 } else {
88 tmp.value = psys_get_value(&r->value, tm);
89 tmp.range = psys_get_value(&r->range, tm);
90 }
91 return psys_eval_rnd(&tmp);
92 }
94 vec3_t psys_eval_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm)
95 {
96 struct psys_rnd3 tmp;
97 if(tm == ANM_TIME_INVAL) {
98 tmp.value = psys_get_cur_value3(&r->value);
99 tmp.range = psys_get_cur_value3(&r->range);
100 } else {
101 tmp.value = psys_get_value3(&r->value, tm);
102 tmp.range = psys_get_value3(&r->range, tm);
103 }
104 return psys_eval_rnd3(&tmp);
105 }