home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- *
- * whiz.c
- *
- * Part of the "Curve Demo"
- * by Howard Look for Silicon Graphics
- *
- * June, 1989
- *
- * This file contains routines for "whizbangs" added to the curve
- * demo. A whizbang (genus "widgets") is a neat shape defined using
- * only cubic splines.
- *
- */
-
- #include <stdio.h>
- #include <gl.h>
- #include <device.h>
- #include <math.h>
- #include "event.h"
- #include "curve.h"
-
-
- void create_whizbang(int);
- void create_coil(void);
- void create_bedspring(void);
- void create_doughnut(void);
- extern float generate_random_float(float);
- extern void remake_all_menus(void);
-
- extern Coord geometry[MAX_MARKERS][3];
- extern Coord offset[MAX_MARKERS][3];
- extern int current_markers;
- extern int origin_x, origin_y, size_x, size_y;
-
-
- /* Environment variables */
- extern
- int curve_basis,
- display_mode,
- curve_precision,
- speed,
- line_style,
- whizbang;
- extern
- Boolean markers,
- hulls,
- motion,
- smear;
- extern
- Boolean draw_active;
-
- extern
- int hardware;
-
- /*
- * Dispatches a call from the whizbang menu to a routine that replaces
- * the current curve geometry with a whizbang geometry.
- */
- void create_whizbang(int which_whiz)
- {
- switch(which_whiz)
- {
- case COIL:
- create_coil();
- break;
- case BEDSPRING:
- create_bedspring();
- break;
- case DOUGHNUT:
- create_doughnut();
- break;
- }
- }
-
-
- /*
- * Replaces the current curve geometry with a constant radius coil.
- * All offsets are the same, so the coil retains its shape when set in
- * motion.
- * Sets environment variables and rebuilds menus.
- */
- void create_coil(void)
- {
- float i, ox, oy, oz;
-
- current_markers = 0;
-
- ox = (generate_random_float(2.0) - 1.0)/(float)size_y;
- oy = (generate_random_float(2.0) - 1.0)/(float)size_y;
- oz = (generate_random_float(2.0) - 1.0)/(float)size_y;
-
- for(i = -0.75; i < 0.75; i += 0.02)
- {
- geometry[current_markers][0] = 0.5*fcos(20.0*i);
- geometry[current_markers][1] = i;
- geometry[current_markers][2] = 0.5*fsin(20.0*i);
-
- offset[current_markers][0] = ox;
- offset[current_markers][1] = oy;
- offset[current_markers][2] = oz;
-
- current_markers++;
- }
-
- curve_basis = BSPLINE;
- display_mode = THREE_D;
- curve_precision = MIN_PRECISION;
- if (hardware == GT)
- speed = MIN_SPEED;
- else
- speed = MAX_SPEED;
- line_style = SOLID;
- markers = OFF;
- motion = ON;
- hulls = OFF;
- smear = OFF;
- frontbuffer(FALSE);
- draw_active = TRUE;
-
- remake_all_menus();
- }
-
-
- /*
- * Replaces the current geometry with a varying radius spiral that
- * resembles a standard Sealy bedspring.
- * Sets environment variables and rebuilds menus.
- */
- void create_bedspring(void)
- {
- float i, ox, oy, oz;
-
- current_markers = 0;
-
- ox = (generate_random_float(2.0) - 1.0)/(float)size_y;
- oy = (generate_random_float(2.0) - 1.0)/(float)size_y;
- oz = (generate_random_float(2.0) - 1.0)/(float)size_y;
-
- for(i = -0.75; i < 0.75; i += 0.02)
- {
- geometry[current_markers][0] = i*fcos(40.0*i);
- geometry[current_markers][1] = i;
- geometry[current_markers][2] = i*fsin(40.0*i);
-
- offset[current_markers][0] = ox;
- offset[current_markers][1] = oy;
- offset[current_markers][2] = oz;
-
- current_markers++;
- }
-
- curve_basis = BSPLINE;
- display_mode = THREE_D;
- curve_precision = MIN_PRECISION;
- if (hardware == GT)
- speed = MIN_SPEED;
- else
- speed = MAX_SPEED;
- line_style = SOLID;
- markers = OFF;
- motion = ON;
- hulls = OFF;
- smear = OFF;
- frontbuffer(FALSE);
- draw_active = TRUE;
-
- remake_all_menus();
- }
-
-
- /*
- * Replaces the current curve geometry with a doughnut (toroid).
- * Sets environment variables and rebuilds menus.
- */
- void create_doughnut(void)
- {
- float theta = 0.0, x, y, z, ox, oy, oz;
-
- ox = (generate_random_float(2.0) - 1.0)/(float)size_y;
- oy = (generate_random_float(2.0) - 1.0)/(float)size_y;
- oz = (generate_random_float(2.0) - 1.0)/(float)size_y;
-
- current_markers = 0;
-
- while (theta <= 2.0*PI + 6.0*PI/300.0)
- {
- x = 0.6*fcos(theta) + 0.3*fsin(50.0*theta)*fcos(theta);
- y = 0.3*fcos(50.0*theta);
- z = 0.6*fsin(theta) + 0.3*fsin(50.0*theta)*fsin(theta);
-
- geometry[current_markers][0] = x;
- geometry[current_markers][1] = y;
- geometry[current_markers][2] = z;
-
- offset[current_markers][0] = ox;
- offset[current_markers][1] = oy;
- offset[current_markers][2] = oz;
-
- theta += 2.0*PI/300.0;
- current_markers++;
- }
-
- curve_basis = BSPLINE;
- display_mode = THREE_D;
- curve_precision = MIN_PRECISION;
- if (hardware == GT)
- speed = MIN_SPEED;
- else
- speed = MAX_SPEED;
- line_style = SOLID;
- markers = OFF;
- motion = ON;
- hulls = OFF;
- smear = OFF;
- frontbuffer(FALSE);
- draw_active = TRUE;
-
- remake_all_menus();
- }
-