dsys2

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/dsys_impl.h	Sat Aug 20 07:48:16 2011 +0300
     1.3 @@ -0,0 +1,54 @@
     1.4 +#ifndef DSYS_IMPL_H_
     1.5 +#define DSYS_IMPL_H_
     1.6 +
     1.7 +#include "dsys2.h"
     1.8 +
     1.9 +static float eval_step(struct dsys_event *ev, demotime_t t);
    1.10 +static float eval_lerp(struct dsys_event *ev, demotime_t t);
    1.11 +static float eval_sigmoid(struct dsys_event *ev, demotime_t t);
    1.12 +
    1.13 +
    1.14 +struct dsys_demo {
    1.15 +	demotime_t srctime;
    1.16 +
    1.17 +	struct dsys_event *ev;
    1.18 +	int num_ev;
    1.19 +};
    1.20 +
    1.21 +struct callback {
    1.22 +	void (*func)(struct dsys_event*, void*);
    1.23 +	void *cls;
    1.24 +
    1.25 +	struct callback *next;
    1.26 +};
    1.27 +
    1.28 +
    1.29 +struct dsys_event {
    1.30 +	enum dsys_evtype type;
    1.31 +
    1.32 +	demotime_t t0, t1;
    1.33 +	float val;
    1.34 +
    1.35 +	float (*eval_func)(struct dsys_event*);
    1.36 +
    1.37 +	struct callback *cblist;
    1.38 +};
    1.39 +
    1.40 +
    1.41 +static float eval_step(struct dsys_event *ev, demotime_t t)
    1.42 +{
    1.43 +	return t >= ev->t1 ? 1.0 : 0.0;
    1.44 +}
    1.45 +
    1.46 +static float eval_lerp(struct dsys_event *ev, demotime_t t)
    1.47 +{
    1.48 +	return (t - ev->t0) / (ev->t1 - ev->t0);
    1.49 +}
    1.50 +
    1.51 +static float eval_sigmoid(struct dsys_event *ev, demotime_t t)
    1.52 +{
    1.53 +	t = eval_lerp(ev, t);
    1.54 +	return 1.0 - (cos(t * M_PI) * 0.5 + 0.5);
    1.55 +}
    1.56 +
    1.57 +#endif	/* DSYS_IMPL_H_ */