nuclear@0: #include nuclear@0: #include "rndval.h" nuclear@0: nuclear@0: int psys_init_anm_rnd(struct psys_anm_rnd *r) nuclear@0: { nuclear@0: if(psys_init_track(&r->value) == -1) { nuclear@0: return -1; nuclear@0: } nuclear@0: if(psys_init_track(&r->range) == -1) { nuclear@0: psys_destroy_track(&r->value); nuclear@0: return -1; nuclear@0: } nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: void psys_destroy_anm_rnd(struct psys_anm_rnd *r) nuclear@0: { nuclear@0: psys_destroy_track(&r->value); nuclear@0: psys_destroy_track(&r->range); nuclear@0: } nuclear@0: nuclear@0: int psys_init_anm_rnd3(struct psys_anm_rnd3 *r) nuclear@0: { nuclear@0: if(psys_init_track3(&r->value) == -1) { nuclear@0: return -1; nuclear@0: } nuclear@0: if(psys_init_track3(&r->range) == -1) { nuclear@0: psys_destroy_track3(&r->value); nuclear@0: return -1; nuclear@0: } nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: void psys_destroy_anm_rnd3(struct psys_anm_rnd3 *r) nuclear@0: { nuclear@0: psys_destroy_track3(&r->value); nuclear@0: psys_destroy_track3(&r->range); nuclear@0: } nuclear@0: nuclear@0: void psys_copy_anm_rnd(struct psys_anm_rnd *dest, const struct psys_anm_rnd *src) nuclear@0: { nuclear@0: psys_copy_track(&dest->value, &src->value); nuclear@0: psys_copy_track(&dest->range, &src->range); nuclear@0: } nuclear@0: nuclear@0: void psys_copy_anm_rnd3(struct psys_anm_rnd3 *dest, const struct psys_anm_rnd3 *src) nuclear@0: { nuclear@0: psys_copy_track3(&dest->value, &src->value); nuclear@0: psys_copy_track3(&dest->range, &src->range); nuclear@0: } nuclear@0: nuclear@0: void psys_set_rnd(struct psys_rnd *r, float val, float range) nuclear@0: { nuclear@0: r->value = val; nuclear@0: r->range = range; nuclear@0: } nuclear@0: nuclear@0: void psys_set_rnd3(struct psys_rnd3 *r, vec3_t val, vec3_t range) nuclear@0: { nuclear@0: r->value = val; nuclear@0: r->range = range; nuclear@0: } nuclear@0: nuclear@0: void psys_set_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm, float val, float range) nuclear@0: { nuclear@0: psys_set_value(&r->value, tm, val); nuclear@0: psys_set_value(&r->range, tm, range); nuclear@0: } nuclear@0: nuclear@0: void psys_set_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm, vec3_t val, vec3_t range) nuclear@0: { nuclear@0: psys_set_value3(&r->value, tm, val); nuclear@0: psys_set_value3(&r->range, tm, range); nuclear@0: } nuclear@0: nuclear@0: nuclear@0: float psys_eval_rnd(struct psys_rnd *r) nuclear@0: { nuclear@0: return r->value + r->range * (float)rand() / (float)RAND_MAX - 0.5 * r->range; nuclear@0: } nuclear@0: nuclear@0: vec3_t psys_eval_rnd3(struct psys_rnd3 *r) nuclear@0: { nuclear@0: vec3_t res; nuclear@0: res.x = r->value.x + r->range.x * (float)rand() / (float)RAND_MAX - 0.5 * r->range.x; nuclear@0: res.y = r->value.y + r->range.y * (float)rand() / (float)RAND_MAX - 0.5 * r->range.y; nuclear@0: res.z = r->value.z + r->range.z * (float)rand() / (float)RAND_MAX - 0.5 * r->range.z; nuclear@0: return res; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: float psys_eval_anm_rnd(struct psys_anm_rnd *r, anm_time_t tm) nuclear@0: { nuclear@0: struct psys_rnd tmp; nuclear@0: if(tm == ANM_TIME_INVAL) { nuclear@0: tmp.value = psys_get_cur_value(&r->value); nuclear@0: tmp.range = psys_get_cur_value(&r->range); nuclear@0: } else { nuclear@0: tmp.value = psys_get_value(&r->value, tm); nuclear@0: tmp.range = psys_get_value(&r->range, tm); nuclear@0: } nuclear@0: return psys_eval_rnd(&tmp); nuclear@0: } nuclear@0: nuclear@0: vec3_t psys_eval_anm_rnd3(struct psys_anm_rnd3 *r, anm_time_t tm) nuclear@0: { nuclear@0: struct psys_rnd3 tmp; nuclear@0: if(tm == ANM_TIME_INVAL) { nuclear@0: tmp.value = psys_get_cur_value3(&r->value); nuclear@0: tmp.range = psys_get_cur_value3(&r->range); nuclear@0: } else { nuclear@0: tmp.value = psys_get_value3(&r->value, tm); nuclear@0: tmp.range = psys_get_value3(&r->range, tm); nuclear@0: } nuclear@0: return psys_eval_rnd3(&tmp); nuclear@0: }