dungeon_crawler

annotate prototype/psys/rndval.c @ 75:b05ab29cd17d

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