libpsys
view src/rndval.c @ 6:d774738f50f6
almost finished with the reorg (2)
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Tue, 27 Sep 2011 07:42:54 +0300 |
parents | 133094e2f5a5 |
children | a10f19674147 |
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 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 struct psys_rnd tmp;
59 if(tm == ANM_TIME_INVAL) {
60 tmp.value = psys_get_cur_value(&r->value);
61 tmp.range = psys_get_cur_value(&r->range);
62 } else {
63 tmp.value = psys_get_value(&r->value, tm);
64 tmp.range = psys_get_value(&r->range, tm);
65 }
66 return psys_eval_rnd(&tmp);
67 }
69 vec3_t psys_eval_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm)
70 {
71 struct psys_rnd3 tmp;
72 if(tm == ANM_TIME_INVAL) {
73 tmp.value = psys_get_cur_value3(&r->value);
74 tmp.range = psys_get_cur_value3(&r->range);
75 } else {
76 tmp.value = psys_get_value3(&r->value, tm);
77 tmp.range = psys_get_value3(&r->range, tm);
78 }
79 return psys_eval_rnd3(&tmp);
80 }