vrshoot
view libs/psys/rndval.c @ 2:334d17aed7de
visual studio project files
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 02 Feb 2014 18:36:38 +0200 |
parents | |
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 }
40 void psys_copy_anm_rnd(struct psys_anm_rnd *dest, const struct psys_anm_rnd *src)
41 {
42 psys_copy_track(&dest->value, &src->value);
43 psys_copy_track(&dest->range, &src->range);
44 }
46 void psys_copy_anm_rnd3(struct psys_anm_rnd3 *dest, const struct psys_anm_rnd3 *src)
47 {
48 psys_copy_track3(&dest->value, &src->value);
49 psys_copy_track3(&dest->range, &src->range);
50 }
52 void psys_set_rnd(struct psys_rnd *r, float val, float range)
53 {
54 r->value = val;
55 r->range = range;
56 }
58 void psys_set_rnd3(struct psys_rnd3 *r, vec3_t val, vec3_t range)
59 {
60 r->value = val;
61 r->range = range;
62 }
64 void psys_set_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm, float val, float range)
65 {
66 psys_set_value(&r->value, tm, val);
67 psys_set_value(&r->range, tm, range);
68 }
70 void psys_set_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm, vec3_t val, vec3_t range)
71 {
72 psys_set_value3(&r->value, tm, val);
73 psys_set_value3(&r->range, tm, range);
74 }
77 float psys_eval_rnd(struct psys_rnd *r)
78 {
79 return r->value + r->range * (float)rand() / (float)RAND_MAX - 0.5 * r->range;
80 }
82 vec3_t psys_eval_rnd3(struct psys_rnd3 *r)
83 {
84 vec3_t res;
85 res.x = r->value.x + r->range.x * (float)rand() / (float)RAND_MAX - 0.5 * r->range.x;
86 res.y = r->value.y + r->range.y * (float)rand() / (float)RAND_MAX - 0.5 * r->range.y;
87 res.z = r->value.z + r->range.z * (float)rand() / (float)RAND_MAX - 0.5 * r->range.z;
88 return res;
89 }
92 float psys_eval_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm)
93 {
94 struct psys_rnd tmp;
95 if(tm == ANM_TIME_INVAL) {
96 tmp.value = psys_get_cur_value(&r->value);
97 tmp.range = psys_get_cur_value(&r->range);
98 } else {
99 tmp.value = psys_get_value(&r->value, tm);
100 tmp.range = psys_get_value(&r->range, tm);
101 }
102 return psys_eval_rnd(&tmp);
103 }
105 vec3_t psys_eval_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm)
106 {
107 struct psys_rnd3 tmp;
108 if(tm == ANM_TIME_INVAL) {
109 tmp.value = psys_get_cur_value3(&r->value);
110 tmp.range = psys_get_cur_value3(&r->range);
111 } else {
112 tmp.value = psys_get_value3(&r->value, tm);
113 tmp.range = psys_get_value3(&r->range, tm);
114 }
115 return psys_eval_rnd3(&tmp);
116 }