dungeon_crawler

diff prototype/psys/rndval.c @ 67:2560a7ab0243

internalized libanim, libimago2, and libpsys
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 07 Oct 2012 02:04:00 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/prototype/psys/rndval.c	Sun Oct 07 02:04:00 2012 +0300
     1.3 @@ -0,0 +1,105 @@
     1.4 +#include <stdlib.h>
     1.5 +#include "rndval.h"
     1.6 +
     1.7 +int psys_init_anm_rnd(struct psys_anm_rnd *r)
     1.8 +{
     1.9 +	if(psys_init_track(&r->value) == -1) {
    1.10 +		return -1;
    1.11 +	}
    1.12 +	if(psys_init_track(&r->range) == -1) {
    1.13 +		psys_destroy_track(&r->value);
    1.14 +		return -1;
    1.15 +	}
    1.16 +	return 0;
    1.17 +}
    1.18 +
    1.19 +void psys_destroy_anm_rnd(struct psys_anm_rnd *r)
    1.20 +{
    1.21 +	psys_destroy_track(&r->value);
    1.22 +	psys_destroy_track(&r->range);
    1.23 +}
    1.24 +
    1.25 +int psys_init_anm_rnd3(struct psys_anm_rnd3 *r)
    1.26 +{
    1.27 +	if(psys_init_track3(&r->value) == -1) {
    1.28 +		return -1;
    1.29 +	}
    1.30 +	if(psys_init_track3(&r->range) == -1) {
    1.31 +		psys_destroy_track3(&r->value);
    1.32 +		return -1;
    1.33 +	}
    1.34 +	return 0;
    1.35 +}
    1.36 +
    1.37 +void psys_destroy_anm_rnd3(struct psys_anm_rnd3 *r)
    1.38 +{
    1.39 +	psys_destroy_track3(&r->value);
    1.40 +	psys_destroy_track3(&r->range);
    1.41 +}
    1.42 +
    1.43 +
    1.44 +void psys_set_rnd(struct psys_rnd *r, float val, float range)
    1.45 +{
    1.46 +	r->value = val;
    1.47 +	r->range = range;
    1.48 +}
    1.49 +
    1.50 +void psys_set_rnd3(struct psys_rnd3 *r, vec3_t val, vec3_t range)
    1.51 +{
    1.52 +	r->value = val;
    1.53 +	r->range = range;
    1.54 +}
    1.55 +
    1.56 +void psys_set_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm, float val, float range)
    1.57 +{
    1.58 +	psys_set_value(&r->value, tm, val);
    1.59 +	psys_set_value(&r->range, tm, range);
    1.60 +}
    1.61 +
    1.62 +void psys_set_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm, vec3_t val, vec3_t range)
    1.63 +{
    1.64 +	psys_set_value3(&r->value, tm, val);
    1.65 +	psys_set_value3(&r->range, tm, range);
    1.66 +}
    1.67 +
    1.68 +
    1.69 +float psys_eval_rnd(struct psys_rnd *r)
    1.70 +{
    1.71 +	return r->value + r->range * (float)rand() / (float)RAND_MAX - 0.5 * r->range;
    1.72 +}
    1.73 +
    1.74 +vec3_t psys_eval_rnd3(struct psys_rnd3 *r)
    1.75 +{
    1.76 +	vec3_t res;
    1.77 +	res.x = r->value.x + r->range.x * (float)rand() / (float)RAND_MAX - 0.5 * r->range.x;
    1.78 +	res.y = r->value.y + r->range.y * (float)rand() / (float)RAND_MAX - 0.5 * r->range.y;
    1.79 +	res.z = r->value.z + r->range.z * (float)rand() / (float)RAND_MAX - 0.5 * r->range.z;
    1.80 +	return res;
    1.81 +}
    1.82 +
    1.83 +
    1.84 +float psys_eval_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm)
    1.85 +{
    1.86 +	struct psys_rnd tmp;
    1.87 +	if(tm == ANM_TIME_INVAL) {
    1.88 +		tmp.value = psys_get_cur_value(&r->value);
    1.89 +		tmp.range = psys_get_cur_value(&r->range);
    1.90 +	} else {
    1.91 +		tmp.value = psys_get_value(&r->value, tm);
    1.92 +		tmp.range = psys_get_value(&r->range, tm);
    1.93 +	}
    1.94 +	return psys_eval_rnd(&tmp);
    1.95 +}
    1.96 +
    1.97 +vec3_t psys_eval_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm)
    1.98 +{
    1.99 +	struct psys_rnd3 tmp;
   1.100 +	if(tm == ANM_TIME_INVAL) {
   1.101 +		tmp.value = psys_get_cur_value3(&r->value);
   1.102 +		tmp.range = psys_get_cur_value3(&r->range);
   1.103 +	} else {
   1.104 +		tmp.value = psys_get_value3(&r->value, tm);
   1.105 +		tmp.range = psys_get_value3(&r->range, tm);
   1.106 +	}
   1.107 +	return psys_eval_rnd3(&tmp);
   1.108 +}