libpsys

annotate src/rndval.c @ 17:7fbed016e739

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