libpsys

annotate 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
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@5 6 if(psys_init_track(&r->value) == -1) {
nuclear@3 7 return -1;
nuclear@3 8 }
nuclear@5 9 if(psys_init_track(&r->range) == -1) {
nuclear@5 10 psys_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@5 18 psys_destroy_track(&r->value);
nuclear@5 19 psys_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@5 24 if(psys_init_track3(&r->value) == -1) {
nuclear@3 25 return -1;
nuclear@3 26 }
nuclear@5 27 if(psys_init_track3(&r->range) == -1) {
nuclear@5 28 psys_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@5 36 psys_destroy_track3(&r->value);
nuclear@5 37 psys_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@5 58 struct psys_rnd tmp;
nuclear@5 59 if(tm == ANM_TIME_INVAL) {
nuclear@5 60 tmp.value = psys_get_cur_value(&r->value);
nuclear@5 61 tmp.range = psys_get_cur_value(&r->range);
nuclear@5 62 } else {
nuclear@5 63 tmp.value = psys_get_value(&r->value, tm);
nuclear@5 64 tmp.range = psys_get_value(&r->range, tm);
nuclear@3 65 }
nuclear@5 66 return psys_eval_rnd(&tmp);
nuclear@3 67 }
nuclear@3 68
nuclear@3 69 vec3_t psys_eval_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm)
nuclear@3 70 {
nuclear@5 71 struct psys_rnd3 tmp;
nuclear@5 72 if(tm == ANM_TIME_INVAL) {
nuclear@5 73 tmp.value = psys_get_cur_value3(&r->value);
nuclear@5 74 tmp.range = psys_get_cur_value3(&r->range);
nuclear@5 75 } else {
nuclear@5 76 tmp.value = psys_get_value3(&r->value, tm);
nuclear@5 77 tmp.range = psys_get_value3(&r->range, tm);
nuclear@3 78 }
nuclear@5 79 return psys_eval_rnd3(&tmp);
nuclear@3 80 }