vrshoot

annotate libs/psys/rndval.c @ 3:c179c72369be

rename candy->vr
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 03 Feb 2014 08:52:13 +0200
parents
children
rev   line source
nuclear@0 1 #include <stdlib.h>
nuclear@0 2 #include "rndval.h"
nuclear@0 3
nuclear@0 4 int psys_init_anm_rnd(struct psys_anm_rnd *r)
nuclear@0 5 {
nuclear@0 6 if(psys_init_track(&r->value) == -1) {
nuclear@0 7 return -1;
nuclear@0 8 }
nuclear@0 9 if(psys_init_track(&r->range) == -1) {
nuclear@0 10 psys_destroy_track(&r->value);
nuclear@0 11 return -1;
nuclear@0 12 }
nuclear@0 13 return 0;
nuclear@0 14 }
nuclear@0 15
nuclear@0 16 void psys_destroy_anm_rnd(struct psys_anm_rnd *r)
nuclear@0 17 {
nuclear@0 18 psys_destroy_track(&r->value);
nuclear@0 19 psys_destroy_track(&r->range);
nuclear@0 20 }
nuclear@0 21
nuclear@0 22 int psys_init_anm_rnd3(struct psys_anm_rnd3 *r)
nuclear@0 23 {
nuclear@0 24 if(psys_init_track3(&r->value) == -1) {
nuclear@0 25 return -1;
nuclear@0 26 }
nuclear@0 27 if(psys_init_track3(&r->range) == -1) {
nuclear@0 28 psys_destroy_track3(&r->value);
nuclear@0 29 return -1;
nuclear@0 30 }
nuclear@0 31 return 0;
nuclear@0 32 }
nuclear@0 33
nuclear@0 34 void psys_destroy_anm_rnd3(struct psys_anm_rnd3 *r)
nuclear@0 35 {
nuclear@0 36 psys_destroy_track3(&r->value);
nuclear@0 37 psys_destroy_track3(&r->range);
nuclear@0 38 }
nuclear@0 39
nuclear@0 40 void psys_copy_anm_rnd(struct psys_anm_rnd *dest, const struct psys_anm_rnd *src)
nuclear@0 41 {
nuclear@0 42 psys_copy_track(&dest->value, &src->value);
nuclear@0 43 psys_copy_track(&dest->range, &src->range);
nuclear@0 44 }
nuclear@0 45
nuclear@0 46 void psys_copy_anm_rnd3(struct psys_anm_rnd3 *dest, const struct psys_anm_rnd3 *src)
nuclear@0 47 {
nuclear@0 48 psys_copy_track3(&dest->value, &src->value);
nuclear@0 49 psys_copy_track3(&dest->range, &src->range);
nuclear@0 50 }
nuclear@0 51
nuclear@0 52 void psys_set_rnd(struct psys_rnd *r, float val, float range)
nuclear@0 53 {
nuclear@0 54 r->value = val;
nuclear@0 55 r->range = range;
nuclear@0 56 }
nuclear@0 57
nuclear@0 58 void psys_set_rnd3(struct psys_rnd3 *r, vec3_t val, vec3_t range)
nuclear@0 59 {
nuclear@0 60 r->value = val;
nuclear@0 61 r->range = range;
nuclear@0 62 }
nuclear@0 63
nuclear@0 64 void psys_set_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm, float val, float range)
nuclear@0 65 {
nuclear@0 66 psys_set_value(&r->value, tm, val);
nuclear@0 67 psys_set_value(&r->range, tm, range);
nuclear@0 68 }
nuclear@0 69
nuclear@0 70 void psys_set_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm, vec3_t val, vec3_t range)
nuclear@0 71 {
nuclear@0 72 psys_set_value3(&r->value, tm, val);
nuclear@0 73 psys_set_value3(&r->range, tm, range);
nuclear@0 74 }
nuclear@0 75
nuclear@0 76
nuclear@0 77 float psys_eval_rnd(struct psys_rnd *r)
nuclear@0 78 {
nuclear@0 79 return r->value + r->range * (float)rand() / (float)RAND_MAX - 0.5 * r->range;
nuclear@0 80 }
nuclear@0 81
nuclear@0 82 vec3_t psys_eval_rnd3(struct psys_rnd3 *r)
nuclear@0 83 {
nuclear@0 84 vec3_t res;
nuclear@0 85 res.x = r->value.x + r->range.x * (float)rand() / (float)RAND_MAX - 0.5 * r->range.x;
nuclear@0 86 res.y = r->value.y + r->range.y * (float)rand() / (float)RAND_MAX - 0.5 * r->range.y;
nuclear@0 87 res.z = r->value.z + r->range.z * (float)rand() / (float)RAND_MAX - 0.5 * r->range.z;
nuclear@0 88 return res;
nuclear@0 89 }
nuclear@0 90
nuclear@0 91
nuclear@0 92 float psys_eval_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm)
nuclear@0 93 {
nuclear@0 94 struct psys_rnd tmp;
nuclear@0 95 if(tm == ANM_TIME_INVAL) {
nuclear@0 96 tmp.value = psys_get_cur_value(&r->value);
nuclear@0 97 tmp.range = psys_get_cur_value(&r->range);
nuclear@0 98 } else {
nuclear@0 99 tmp.value = psys_get_value(&r->value, tm);
nuclear@0 100 tmp.range = psys_get_value(&r->range, tm);
nuclear@0 101 }
nuclear@0 102 return psys_eval_rnd(&tmp);
nuclear@0 103 }
nuclear@0 104
nuclear@0 105 vec3_t psys_eval_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm)
nuclear@0 106 {
nuclear@0 107 struct psys_rnd3 tmp;
nuclear@0 108 if(tm == ANM_TIME_INVAL) {
nuclear@0 109 tmp.value = psys_get_cur_value3(&r->value);
nuclear@0 110 tmp.range = psys_get_cur_value3(&r->range);
nuclear@0 111 } else {
nuclear@0 112 tmp.value = psys_get_value3(&r->value, tm);
nuclear@0 113 tmp.range = psys_get_value3(&r->range, tm);
nuclear@0 114 }
nuclear@0 115 return psys_eval_rnd3(&tmp);
nuclear@0 116 }