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