libpsys

diff src/rndval.c @ 3:133094e2f5a5

reorganizing
author John Tsiombikas <nuclear@mutantstargoat.com>
date Mon, 26 Sep 2011 18:20:11 +0300
parents
children 613d2bf3ea1f
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/rndval.c	Mon Sep 26 18:20:11 2011 +0300
     1.3 @@ -0,0 +1,74 @@
     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(anm_init_track(&r->value) == -1) {
    1.10 +		return -1;
    1.11 +	}
    1.12 +	if(anm_init_track(&r->range) == -1) {
    1.13 +		anm_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 +	anm_destroy_track(&r->value);
    1.22 +	anm_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(anm_init_track3(&r->value) == -1) {
    1.28 +		return -1;
    1.29 +	}
    1.30 +	if(anm_init_track3(&r->range) == -1) {
    1.31 +		anm_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 +	anm_destroy_track3(&r->value);
    1.40 +	anm_destroy_track3(&r->range);
    1.41 +}
    1.42 +
    1.43 +
    1.44 +float psys_eval_rnd(struct psys_rnd *r)
    1.45 +{
    1.46 +	return r->value + r->range * (float)rand() / (float)RAND_MAX - 0.5 * r->range;
    1.47 +}
    1.48 +
    1.49 +vec3_t psys_eval_rnd3(struct psys_rnd3 *r)
    1.50 +{
    1.51 +	vec3_t res;
    1.52 +	res.x = r->value.x + r->range.x * (float)rand() / (float)RAND_MAX - 0.5 * r->range.x;
    1.53 +	res.y = r->value.y + r->range.y * (float)rand() / (float)RAND_MAX - 0.5 * r->range.y;
    1.54 +	res.z = r->value.z + r->range.z * (float)rand() / (float)RAND_MAX - 0.5 * r->range.z;
    1.55 +	return res;
    1.56 +}
    1.57 +
    1.58 +
    1.59 +float psys_eval_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm)
    1.60 +{
    1.61 +	if(r->cur_tm != tm) {
    1.62 +		r->cur.value = anm_get_value(&r->value, tm);
    1.63 +		r->cur.range = anm_get_value(&r->range, tm);
    1.64 +		r->cur_tm = tm;
    1.65 +	}
    1.66 +	return psys_eval_rnd(&r->cur);
    1.67 +}
    1.68 +
    1.69 +vec3_t psys_eval_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm)
    1.70 +{
    1.71 +	if(r->cur_tm != tm) {
    1.72 +		r->cur.value = anm_get_value3(&r->value, tm);
    1.73 +		r->cur.range = anm_get_value3(&r->range, tm);
    1.74 +		r->cur_tm = tm;
    1.75 +	}
    1.76 +	return psys_eval_rnd3(&r->cur);
    1.77 +}