static Bool Init(ModeInfo * mi) { int i; firestruct *fs = &fire[MI_SCREEN(mi)]; /* default settings */ fs->eject_r = 0.1 + NRAND(10) * 0.03; fs->dt = 0.015; fs->eject_vy = 4; fs->eject_vl = 1; fs->ridtri = 0.1 + NRAND(10) * 0.005; fs->maxage = 1.0 / fs->dt; vinit(fs->obs, DEF_OBS[0], DEF_OBS[1], DEF_OBS[2]); fs->v = 0.0; fs->alpha = DEF_ALPHA; fs->beta = DEF_BETA; /* initialise texture stuff */ if (do_texture) inittextures(mi); else { fs->ttexture = (XImage*) NULL; fs->gtexture = (XImage*) NULL; } if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tnum_part=%d\n\ttrees=%d\n\tfog=%s\n\tshadows=%s\n\teject_r=%.3f\n\tridtri=%.3f\n", MI_NAME(mi), fs->np, fs->num_trees, fs->fog ? "on" : "off", fs->shadows ? "on" : "off", fs->eject_r, fs->ridtri); } /* initialise particles and trees */ for (i = 0; i < fs->np; i++) { setnewpart(fs, &(fs->p[i])); } if (fs->num_trees) if (!inittree(mi)) { return False; } /* if no fire particles then initialise rain particles */ if (!fs->np) { vinit(fs->min,-7.0f,-0.2f,-7.0f); vinit(fs->max,7.0f,8.0f,7.0f); for (i = 0; i < NUMPART; i++) { setnewrain(fs, &(fs->r[i])); } } return True; }
static void setpart(part * p) { float fact; if (p->p[0][1] < 0.1) { setnewpart(p); return; } p->v[1] += AGRAV * dt; vadds(p->p[0], dt, p->v); vadds(p->p[1], dt, p->v); vadds(p->p[2], dt, p->v); p->age++; if ((p->age) > maxage) { vequ(p->c[0], blu2); vequ(p->c[1], blu2); vequ(p->c[2], blu2); } else { fact = 1.0 / maxage; vadds(p->c[0], fact, blu2); vclamp(p->c[0]); p->c[0][3] = fact * (maxage - p->age); vadds(p->c[1], fact, blu2); vclamp(p->c[1]); p->c[1][3] = fact * (maxage - p->age); vadds(p->c[2], fact, blu2); vclamp(p->c[2]); p->c[2][3] = fact * (maxage - p->age); } }
/* set fire particle values */ static void setpart(firestruct * fs, part * p) { float fact; if (p->p[0][1] < 0.1) { setnewpart(fs, p); return; } p->v[1] += AGRAV * fs->dt; vadds(p->p[0], fs->dt, p->v); vadds(p->p[1], fs->dt, p->v); vadds(p->p[2], fs->dt, p->v); p->age++; if ((p->age) > fs->maxage) { vequ(p->c[0], partcol2); vequ(p->c[1], partcol2); vequ(p->c[2], partcol2); } else { fact = 1.0 / fs->maxage; vadds(p->c[0], fact, partcol2); vclamp(p->c[0]); p->c[0][3] = fact * (fs->maxage - p->age); vadds(p->c[1], fact, partcol2); vclamp(p->c[1]); p->c[1][3] = fact * (fs->maxage - p->age); vadds(p->c[2], fact, partcol2); vclamp(p->c[2]); p->c[2][3] = fact * (fs->maxage - p->age); } }
static Bool Init(ModeInfo * mi) { int i; firestruct *fs = &fire[MI_SCREEN(mi)]; /* default settings */ fs->eject_r = 0.1 + NRAND(10) * 0.03; fs->dt = 0.015; fs->eject_vy = 4; fs->eject_vl = 1; fs->ridtri = 0.1 + NRAND(10) * 0.005; fs->maxage = 1.0 / fs->dt; vinit(fs->obs, DEF_OBS[0], DEF_OBS[1], DEF_OBS[2]); fs->v = 0.0; fs->alpha = DEF_ALPHA; fs->beta = DEF_BETA; /* initialise texture stuff */ if (do_texture) inittextures(mi); else { fs->ttexture = (XImage*) NULL; fs->gtexture = (XImage*) NULL; } if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tnum_part=%d\n\ttrees=%d\n\tfog=%s\n\tshadows=%s\n\teject_r=%.3f\n\tridtri=%.3f\n", MI_NAME(mi), fs->np, fs->num_trees, fs->fog ? "on" : "off", fs->shadows ? "on" : "off", fs->eject_r, fs->ridtri); } glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); /* makes particles blend with background */ if (!MI_IS_WIREFRAME(mi)||(!fs->np)) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } /* fog stuff */ glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_EXP); glFogfv(GL_FOG_COLOR, fogcolor); glFogf(GL_FOG_DENSITY, 0.03); glHint(GL_FOG_HINT, GL_NICEST); /* initialise particles and trees */ for (i = 0; i < fs->np; i++) { setnewpart(fs, &(fs->p[i])); } if (fs->num_trees) if (!inittree(mi)) { return False; } /* if no fire particles then initialise rain particles */ if (!fs->np) { vinit(fs->min,-7.0f,-0.2f,-7.0f); vinit(fs->max,7.0f,8.0f,7.0f); for (i = 0; i < NUMPART; i++) { setnewrain(fs, &(fs->r[i])); } } return True; }
int main(int ac,char **av) { int i; fprintf(stderr,"Fire V1.5\nWritten by David Bucciarelli ([email protected])\n"); /* Default settings */ WIDTH=640; HEIGHT=480; np=800; eject_r=0.1; dt=0.015; eject_vy=4; eject_vl=1; shadows=1; ridtri=0.1; maxage=1.0/dt; if(ac==2) np=atoi(av[1]); if(ac==4) { WIDTH=atoi(av[2]); HEIGHT=atoi(av[3]); } glutInitWindowPosition(0,0); glutInitWindowSize(WIDTH,HEIGHT); glutInit(&ac,av); glutInitDisplayMode(GLUT_RGB|GLUT_DEPTH|GLUT_DOUBLE); glutCreateWindow("Fire"); reshape(WIDTH,HEIGHT); inittextures(); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_FOG); glFogi(GL_FOG_MODE,GL_EXP); glFogfv(GL_FOG_COLOR,fogcolor); glFogf(GL_FOG_DENSITY,0.1); #ifdef FX glHint(GL_FOG_HINT,GL_NICEST); #endif p=malloc(sizeof(part)*np); for(i=0;i<np;i++) setnewpart(&p[i]); inittree(); glutKeyboardFunc(key); glutSpecialFunc(special); glutDisplayFunc(drawfire); glutIdleFunc(drawfire); glutReshapeFunc(reshape); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
int main(int ac, char **av) { int i; fprintf(stderr, "Fire V1.5\nWritten by David Bucciarelli ([email protected])\n"); /* Default settings */ np = 800; eject_r = -0.65; dt = 0.015; eject_vy = 4; eject_vl = 1; shadows = 1; ridtri = 0.25; maxage = 1.0 / dt; if (ac == 2) { np = atoi(av[1]); if (np <= 0 || np > 1000000) { fprintf(stderr, "Invalid input.\n"); exit(-1); } } if (ac == 4) { WIDTH = atoi(av[2]); HEIGHT = atoi(av[3]); } glutInitWindowSize(WIDTH, HEIGHT); glutInit(&ac, av); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); if (!(win = glutCreateWindow("Fire"))) { fprintf(stderr, "Error opening a window.\n"); exit(-1); } reshape(WIDTH, HEIGHT); inittextures(); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_EXP); glFogfv(GL_FOG_COLOR, fogcolor); glFogf(GL_FOG_DENSITY, 0.1); assert(np > 0); p = (part *) malloc(sizeof(part) * np); assert(p); for (i = 0; i < np; i++) setnewpart(&p[i]); inittree(); glutKeyboardFunc(key); glutSpecialFunc(special); glutDisplayFunc(drawfire); glutIdleFunc(idle); glutReshapeFunc(reshape); glutMainLoop(); return (0); }