void get_position (rotator *rot, double *x_ret, double *y_ret, double *z_ret, int update_p) { double x = 0.5, y = 0.5, z = 0.5; if (rot->wander_speed != 0) { if (update_p) rot->wander_frame++; # define SINOID(F) ((1 + sin((rot->wander_frame * (F)) / 2 * M_PI)) / 2.0) x = SINOID (0.71 * rot->wander_speed); y = SINOID (0.53 * rot->wander_speed); z = SINOID (0.37 * rot->wander_speed); # undef SINOID } if (x_ret) *x_ret = x; if (y_ret) *y_ret = y; if (z_ret) *z_ret = z; }
static void draw(ModeInfo *mi) { Bool wireframe_p = MI_IS_WIREFRAME(mi); gasketstruct *gp = &gasket[MI_SCREEN(mi)]; static int tick = 0; static GLfloat pos[4] = {1.0, 1.0, 1.0, 0.0}; static float white[] = {1.0, 1.0, 1.0, 1.0}; static float color[] = {0.0, 0.0, 0.0, 1.0}; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (!wireframe_p) { glColor4fv (white); glLightfv(GL_LIGHT0, GL_POSITION, pos); color[0] = gp->colors[gp->ccolor].red * intens_factor; color[1] = gp->colors[gp->ccolor].green * intens_factor; color[2] = gp->colors[gp->ccolor].blue * intens_factor; gp->ccolor++; if (gp->ccolor >= gp->ncolors) gp->ccolor = 0; glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color); glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); glPushMatrix(); { static int frame = 0; GLfloat x, y, z; # define SINOID(SCALE,SIZE) \ ((((1 + sin((frame * (SCALE)) / 2 * M_PI)) / 2.0) * (SIZE)) - (SIZE)/2) x = SINOID(0.0071, 8.0); y = SINOID(0.0053, 6.0); z = SINOID(0.0037, 15.0); frame++; glTranslatef(x, y, z); x = gp->rotx; y = gp->roty; z = gp->rotz; if (x < 0) x = 1 - (x + 1); if (y < 0) y = 1 - (y + 1); if (z < 0) z = 1 - (z + 1); glRotatef(x * 360, 1.0, 0.0, 0.0); glRotatef(y * 360, 0.0, 1.0, 0.0); glRotatef(z * 360, 0.0, 0.0, 1.0); } glScalef( 8.0, 8.0, 8.0 ); glCallList(gp->gasket1); glPopMatrix(); if (tick++ >= speed) { tick = 0; if (gp->current_depth >= max_depth) gp->current_depth = -max_depth; gp->current_depth++; glDeleteLists (gp->gasket1, 1); glNewList (gp->gasket1, GL_COMPILE); compile_gasket (mi); glEndList(); } }
static void DrawFire(ModeInfo * mi) { int j; firestruct *fs = &fire[MI_SCREEN(mi)]; Bool wire = MI_IS_WIREFRAME(mi); if (do_trackmouse && !MI_IS_ICONIC(mi)) trackmouse(mi); if (do_wander) { GLfloat x, y, z; # define SINOID(SCALE,SIZE) \ ((((1 + sin((frame * (SCALE)) / 2 * M_PI)) / 2.0) * (SIZE)) - (SIZE)/2) x = SINOID(0.031, 0.85); y = SINOID(0.017, 0.25); z = SINOID(0.023, 0.85); frame++; fs->obs[0] = x + DEF_OBS[0]; fs->obs[1] = y + DEF_OBS[1]; fs->obs[2] = z + DEF_OBS[2]; fs->dir[1] = y; fs->dir[2] = z; } glEnable(GL_DEPTH_TEST); if (fs->fog) glEnable(GL_FOG); else glDisable(GL_FOG); glDepthMask(GL_TRUE); glClearColor(0.5, 0.5, 0.8, 1.0); /* sky in the distance */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); calcposobs(fs); gluLookAt(fs->obs[0], fs->obs[1], fs->obs[2], fs->obs[0] + fs->dir[0], fs->obs[1] + fs->dir[1], fs->obs[2] + fs->dir[2], 0.0, 1.0, 0.0); glEnable(GL_TEXTURE_2D); /* draw ground using the computed texture */ #ifdef HAVE_GLBINDTEXTURE if (do_texture) { glColor4f(1.0,1.0,1.0,1.0); /* white to get texture in it's true color */ glBindTexture(GL_TEXTURE_2D, fs->groundid); } else #endif /* HAVE_GLBINDTEXTURE */ glColor4f(0.54, 0.27, 0.07, 1.0); /* untextured ground color */ glBegin(GL_QUADS); glTexCoord2fv(qt[0]); glVertex3fv(q[0]); glTexCoord2fv(qt[1]); glVertex3fv(q[1]); glTexCoord2fv(qt[2]); glVertex3fv(q[2]); glTexCoord2fv(qt[3]); glVertex3fv(q[3]); glEnd(); glAlphaFunc(GL_GEQUAL, 0.9); #ifdef HAVE_GLBINDTEXTURE if (fs->num_trees) { /* here do_texture IS True - and color used is white */ glEnable(GL_ALPHA_TEST); glBindTexture(GL_TEXTURE_2D,fs->treeid); for(j=0;j<fs->num_trees;j++) drawtree(fs->treepos[j].x ,fs->treepos[j].y ,fs->treepos[j].z ); glDisable(GL_ALPHA_TEST); } #endif /* HAVE_GLBINDTEXTURE */ glDisable(GL_TEXTURE_2D); glDepthMask(GL_FALSE); if (fs->shadows) { /* draw shadows with black color */ glBegin(wire ? GL_LINE_STRIP : GL_TRIANGLES); for (j = 0; j < fs->np; j++) { glColor4f(black[0], black[1], black[2], fs->p[j].c[0][3]); glVertex3f(fs->p[j].p[0][0], 0.1, fs->p[j].p[0][2]); glColor4f(black[0], black[1], black[2], fs->p[j].c[1][3]); glVertex3f(fs->p[j].p[1][0], 0.1, fs->p[j].p[1][2]); glColor4f(black[0], black[1], black[2], fs->p[j].c[2][3]); glVertex3f(fs->p[j].p[2][0], 0.1, fs->p[j].p[2][2]); } glEnd(); } glBegin(wire ? GL_LINE_STRIP : GL_TRIANGLES); for (j = 0; j < fs->np; j++) { /* draw particles: colors are computed in setpart */ glColor4fv(fs->p[j].c[0]); glVertex3fv(fs->p[j].p[0]); glColor4fv(fs->p[j].c[1]); glVertex3fv(fs->p[j].p[1]); glColor4fv(fs->p[j].c[2]); glVertex3fv(fs->p[j].p[2]); setpart(fs, &fs->p[j]); } glEnd(); /* draw rain particles if no fire particles */ if (!fs->np) { float timeused = gettimerain(); glDisable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); glBegin(GL_LINES); for (j = 0; j < NUMPART; j++) { glColor4f(0.7f,0.95f,1.0f,0.0f); glVertex3fv(fs->r[j].oldpos); glColor4f(0.3f,0.7f,1.0f,1.0f); glVertex3fv(fs->r[j].pos); setpartrain(fs, &fs->r[j],timeused); } glEnd(); glShadeModel(GL_FLAT); } glDisable(GL_TEXTURE_2D); glDisable(GL_ALPHA_TEST); glDisable(GL_DEPTH_TEST); glDisable(GL_FOG); /* manage framerate display */ if (MI_IS_FPS(mi)) do_fps (mi); glPopMatrix(); }
ENTRYPOINT void draw_unicrud (ModeInfo *mi) { unicrud_configuration *bp = &bps[MI_SCREEN(mi)]; Display *dpy = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); if (!bp->glx_context) return; glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *bp->glx_context); glShadeModel (GL_FLAT); glEnable (GL_NORMALIZE); glDisable (GL_CULL_FACE); glDisable (GL_LIGHTING); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (! bp->button_down_p) switch (bp->state) { case IN: bp->ratio += speed * 0.05; break; case OUT: bp->ratio += speed * 0.05; break; case LINGER: bp->ratio += speed * 0.005; break; default: abort(); } if (bp->ratio > 1.0) { bp->ratio = 0; switch (bp->state) { case IN: bp->state = LINGER; break; case LINGER: bp->state = OUT; bp->spin_direction = (random() & 1) ? 1 : -1; break; case OUT: bp->state = IN; pick_unichar(mi); break; default: abort(); } } glPushMatrix (); { double x, y, z; get_position (bp->rot, &x, &y, &z, !bp->button_down_p); glTranslatef((x - 0.5) * 6, (y - 0.5) * 6, (z - 0.5) * 6); gltrackball_rotate (bp->trackball); get_rotation (bp->rot, &x, &y, &z, !bp->button_down_p); x = y = 0; glRotatef (x * 360, 1.0, 0.0, 0.0); glRotatef (y * 360, 0.0, 1.0, 0.0); glRotatef (z * 360, 0.0, 0.0, 1.0); } # define SINOID(N) (sin(M_PI - (N) / 2 * M_PI)) { GLfloat s; switch (bp->state) { case IN: s = SINOID (bp->ratio); break; case OUT: s = SINOID (1-bp->ratio); break; default: s = 1; break; } glScalef (s, s, s); glRotatef (360 * s * bp->spin_direction * (bp->state == IN ? -1 : 1), 0, 0, 1); } draw_unichar (mi); glPopMatrix (); if (mi->fps_p) do_fps (mi); glFinish(); glXSwapBuffers(dpy, window); }
void draw_molecule (ModeInfo *mi) { /* static time_t last = 0; */ time_t now = time ((time_t *) 0); molecule_configuration *mc; Display *dpy = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); if (mcs == NULL) return; mc = &mcs[MI_SCREEN(mi)]; if (!mc->glx_context) return; MI_IS_DRAWN(mi) = True; if (last + timeout <= now) /* randomize molecules every -timeout seconds */ { if (mc->nmolecules == 1) { if (last != 0) goto SKIP; mc->which = 0; } else if (last == 0) { mc->which = NRAND(mc->nmolecules); } else { int n = mc->which; while (n == mc->which) n = NRAND(mc->nmolecules); mc->which = n; } last = now; glNewList (mc->molecule_dlist, GL_COMPILE); ensure_bounding_box_visible (mi); if (MI_IS_ICONIC(mi)) {do_labels = False; do_bonds = True; do_titles = False; } else { do_labels = orig_do_labels; do_bonds = orig_do_bonds; do_titles = orig_do_titles; } cur_wire = orig_wire; if (mc->molecule_size > mc->no_label_threshold) do_labels = 0; if (mc->molecule_size > mc->wireframe_threshold) cur_wire = 1; if (cur_wire) do_bonds = 1; build_molecule (mi); glEndList(); } SKIP: glPushMatrix (); glScalef(1.1, 1.1, 1.1); { GLfloat x, y, z; if (do_wander) { static int frame = 0; # define SINOID(SCALE,SIZE) \ ((((1 + sin((frame * (SCALE)) / 2 * M_PI)) / 2.0) * (SIZE)) - (SIZE)/2) x = SINOID(0.031, 9.0); y = SINOID(0.023, 9.0); z = SINOID(0.017, 9.0); frame++; glTranslatef(x, y, z); } if (mc->spin_x || mc->spin_y || mc->spin_z) { x = mc->rotx; y = mc->roty; z = mc->rotz; if (x < 0) x = 1 - (x + 1); if (y < 0) y = 1 - (y + 1); if (z < 0) z = 1 - (z + 1); if (mc->spin_x) glRotatef(x * 360, 1.0, 0.0, 0.0); if (mc->spin_y) glRotatef(y * 360, 0.0, 1.0, 0.0); if (mc->spin_z) glRotatef(z * 360, 0.0, 0.0, 1.0); rotate(&mc->rotx, &mc->dx, &mc->ddx, mc->d_max, MI_IS_VERBOSE(mi)); rotate(&mc->roty, &mc->dy, &mc->ddy, mc->d_max, MI_IS_VERBOSE(mi)); rotate(&mc->rotz, &mc->dz, &mc->ddz, mc->d_max, MI_IS_VERBOSE(mi)); } } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glCallList (mc->molecule_dlist); glPopMatrix (); if (MI_IS_FPS(mi)) do_fps (mi); glFinish(); glXSwapBuffers(dpy, window); }