dsys2
changeset 8:4ad7a01c4ff5
ha
author | John Tsiombikas <nuclear@siggraph.org> |
---|---|
date | Fri, 02 Sep 2011 10:48:24 +0300 |
parents | 3258d163cfbc |
children | 61cc1a525023 |
files | src/dsys.c test.c testscript.dsys |
diffstat | 3 files changed, 58 insertions(+), 2 deletions(-) [+] |
line diff
1.1 --- a/src/dsys.c Fri Sep 02 08:14:40 2011 +0300 1.2 +++ b/src/dsys.c Fri Sep 02 10:48:24 2011 +0300 1.3 @@ -297,6 +297,8 @@ 1.4 /* seek without continuity */ 1.5 void dsys_seek(struct dsys_demo *demo, demotime_t tm) 1.6 { 1.7 + struct dsys_event *ev; 1.8 + 1.9 if(tm < 0) { 1.10 tm = 0; 1.11 } 1.12 @@ -306,6 +308,15 @@ 1.13 1.14 demo->start_tm = demo->src_tm - tm; 1.15 demo->stoppage_tm = 0; 1.16 + 1.17 + demo->nextev = demo->active = demo->evlist; 1.18 + 1.19 + /* recalculate events */ 1.20 + ev = demo->evlist; 1.21 + while(ev) { 1.22 + proc_event(ev, tm); 1.23 + ev = ev->next; 1.24 + } 1.25 } 1.26 1.27 void dsys_seek_norm(struct dsys_demo *demo, float t)
2.1 --- a/test.c Fri Sep 02 08:14:40 2011 +0300 2.2 +++ b/test.c Fri Sep 02 10:48:24 2011 +0300 2.3 @@ -1,5 +1,6 @@ 2.4 #include <stdio.h> 2.5 #include <stdlib.h> 2.6 +#include <math.h> 2.7 #include <time.h> 2.8 #include <sys/time.h> 2.9 2.10 @@ -14,6 +15,7 @@ 2.11 void disp(void); 2.12 void draw_progress(float p); 2.13 void draw_teapot(float sec); 2.14 +void flash_callback(struct dsys_event *ev, void *cls); 2.15 void reshape(int x, int y); 2.16 void keyb(unsigned char key, int x, int y); 2.17 void skeyb(int key, int x, int y); 2.18 @@ -21,6 +23,13 @@ 2.19 2.20 struct dsys_demo *demo; 2.21 2.22 +struct dsys_event *evfoo, *evfoolong, *evfooshort; 2.23 + 2.24 +float teapot_color[][4] = { 2.25 + {0.9, 0.5, 0.3, 1.0}, 2.26 + {0.3, 0.4, 0.8, 1.0} 2.27 +}; 2.28 + 2.29 int main(int argc, char **argv) 2.30 { 2.31 float lpos[] = {-100, 100, 100, 1}; 2.32 @@ -47,6 +56,12 @@ 2.33 return 1; 2.34 } 2.35 2.36 + evfoo = dsys_event(demo, "foo"); 2.37 + evfoolong = dsys_event(demo, "foolong"); 2.38 + evfooshort = dsys_event(demo, "fooshort"); 2.39 + 2.40 + dsys_event_callback(evfooshort, flash_callback, 0); 2.41 + 2.42 glutMainLoop(); 2.43 return 0; 2.44 } 2.45 @@ -54,7 +69,9 @@ 2.46 2.47 void disp(void) 2.48 { 2.49 + int i; 2.50 float sec; 2.51 + static const float trans[][2] = {{-3, 0}, {3, 0}, {0, -3}, {0, 3}}; 2.52 2.53 dsys_update(demo, dsys_msec_to_dtime(get_ticks())); 2.54 sec = dsys_dtime_to_sec(dsys_time(demo)); 2.55 @@ -68,6 +85,19 @@ 2.56 2.57 draw_teapot(sec); 2.58 2.59 + glEnable(GL_BLEND); 2.60 + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2.61 + 2.62 + for(i=0; i<4; i++) { 2.63 + glPushMatrix(); 2.64 + glRotatef(-sec * 100.0, 0, 1, 0); 2.65 + glTranslatef(trans[i][0], 0, trans[i][1]); 2.66 + glScalef(0.7, 0.7, 0.7); 2.67 + draw_teapot(sec); 2.68 + glPopMatrix(); 2.69 + } 2.70 + glDisable(GL_BLEND); 2.71 + 2.72 draw_progress(dsys_progress(demo)); 2.73 2.74 glutSwapBuffers(); 2.75 @@ -113,10 +143,18 @@ 2.76 glPopMatrix(); 2.77 } 2.78 2.79 +#define LERP(a, b, t) ((a) + ((b) - (a)) * (t)) 2.80 + 2.81 void draw_teapot(float sec) 2.82 { 2.83 - float dcol[] = {0.2, 0.4, 0.8, 1.0}; 2.84 + float dcol[4]; 2.85 float scol[] = {0.8, 0.8, 0.8, 1.0}; 2.86 + float t = dsys_event_value(evfoo); 2.87 + 2.88 + dcol[0] = LERP(teapot_color[0][0], teapot_color[1][0], t); 2.89 + dcol[1] = LERP(teapot_color[0][1], teapot_color[1][1], t); 2.90 + dcol[2] = LERP(teapot_color[0][2], teapot_color[1][2], t); 2.91 + dcol[3] = dsys_event_value(evfoolong); 2.92 2.93 glPushMatrix(); 2.94 glRotatef(sec * 100.0, 0, 1, 0); 2.95 @@ -132,6 +170,13 @@ 2.96 glPopMatrix(); 2.97 } 2.98 2.99 +void flash_callback(struct dsys_event *ev, void *cls) 2.100 +{ 2.101 + float t = sin(dsys_event_value(ev) * M_PI); 2.102 + 2.103 + glClearColor(t, t, t, 1.0); 2.104 +} 2.105 + 2.106 void reshape(int x, int y) 2.107 { 2.108 glViewport(0, 0, x, y);