dsys2

annotate src/dsys_impl.h @ 0:34d90cd9ef9b

starting a new demosystem
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 20 Aug 2011 07:48:16 +0300
parents
children 1705e550bd91
rev   line source
nuclear@0 1 #ifndef DSYS_IMPL_H_
nuclear@0 2 #define DSYS_IMPL_H_
nuclear@0 3
nuclear@0 4 #include "dsys2.h"
nuclear@0 5
nuclear@0 6 static float eval_step(struct dsys_event *ev, demotime_t t);
nuclear@0 7 static float eval_lerp(struct dsys_event *ev, demotime_t t);
nuclear@0 8 static float eval_sigmoid(struct dsys_event *ev, demotime_t t);
nuclear@0 9
nuclear@0 10
nuclear@0 11 struct dsys_demo {
nuclear@0 12 demotime_t srctime;
nuclear@0 13
nuclear@0 14 struct dsys_event *ev;
nuclear@0 15 int num_ev;
nuclear@0 16 };
nuclear@0 17
nuclear@0 18 struct callback {
nuclear@0 19 void (*func)(struct dsys_event*, void*);
nuclear@0 20 void *cls;
nuclear@0 21
nuclear@0 22 struct callback *next;
nuclear@0 23 };
nuclear@0 24
nuclear@0 25
nuclear@0 26 struct dsys_event {
nuclear@0 27 enum dsys_evtype type;
nuclear@0 28
nuclear@0 29 demotime_t t0, t1;
nuclear@0 30 float val;
nuclear@0 31
nuclear@0 32 float (*eval_func)(struct dsys_event*);
nuclear@0 33
nuclear@0 34 struct callback *cblist;
nuclear@0 35 };
nuclear@0 36
nuclear@0 37
nuclear@0 38 static float eval_step(struct dsys_event *ev, demotime_t t)
nuclear@0 39 {
nuclear@0 40 return t >= ev->t1 ? 1.0 : 0.0;
nuclear@0 41 }
nuclear@0 42
nuclear@0 43 static float eval_lerp(struct dsys_event *ev, demotime_t t)
nuclear@0 44 {
nuclear@0 45 return (t - ev->t0) / (ev->t1 - ev->t0);
nuclear@0 46 }
nuclear@0 47
nuclear@0 48 static float eval_sigmoid(struct dsys_event *ev, demotime_t t)
nuclear@0 49 {
nuclear@0 50 t = eval_lerp(ev, t);
nuclear@0 51 return 1.0 - (cos(t * M_PI) * 0.5 + 0.5);
nuclear@0 52 }
nuclear@0 53
nuclear@0 54 #endif /* DSYS_IMPL_H_ */