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