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.
- */
- /*
- *
- * control.c
- *
- * Part of the "Curve Demo"
- * by Howard Look for Silicon Graphics
- *
- * June, 1989
- *
- * This file contains the routines used for the program's display and
- * environment options, as defaults and as selected by the user. Most
- * of these routines are called by menu selection. See the file menu.c
- * for menu derfinitions.
- *
- */
-
-
- #include <stdio.h>
- #include <gl.h>
- #include <device.h>
- #include <math.h>
- #include "curve.h"
- #include "event.h"
-
-
- /* Prototypes */
- void set_initial_conditions(void);
- void set_defaults(void);
- void change_display(int);
- void toggle_markers(void);
- void toggle_hulls(void);
- void toggle_motion(void);
- void toggle_smear(void);
- void change_basis(int);
- void change_precision(int);
- void change_speed(int);
- void change_style(int);
- void change_whizbang(int);
- void set_two_d_view(void);
- void set_three_d_view(void);
-
- extern void clear_window(void);
- extern void remake_curve_menu(void);
- extern void remake_basis_menu(void);
- extern void remake_display_menu(void);
- extern void remake_precision_menu(void);
- extern void remake_speed_menu(void);
- extern void remake_style_menu(void);
- extern void remake_whizbang_menu(void);
- extern void remake_options_menu(void);
- extern void remake_all_menus(void);
- extern void create_whizbang(int);
-
-
- /* Environment variables */
- extern
- int curve_basis,
- display_mode,
- curve_precision,
- speed,
- line_style,
- whizbang;
- extern
- Boolean markers,
- hulls,
- motion,
- smear,
- rotating;
-
- extern
- int hardware;
-
-
- /* About the window... */
- extern int origin_x, origin_y, size_x, size_y;
- extern float aspect;
-
- extern Boolean draw_active;
-
-
- /*
- * Sets default values for the environment variables. Change these to
- * your heart's content.
- */
- void set_initial_conditions(void)
- {
- curve_basis = BSPLINE;
- curvebasis(curve_basis);
-
- display_mode = TWO_D;
- ortho(-1.0, 1.0, -1.0, 1.0, -2.0, 2.0);
-
- markers = ON;
- hulls = OFF;
- motion = OFF;
- rotating = FALSE;
-
- curve_precision = MAX_PRECISION;
- curveprecision(curve_precision);
-
- speed = DEFAULT_SPEED;
- smear = OFF;
- frontbuffer(FALSE);
-
- line_style = SOLID;
- setlinestyle(line_style);
- }
-
-
- void set_defaults(void)
- {
- set_initial_conditions();
- remake_all_menus();
- draw_display();
- }
-
-
-
- /*
- * Toggles the display mode between two and three dimensional
- */
- void change_display(int new_mode)
- {
- display_mode = new_mode;
-
- if (smear)
- {
- cpack(0); clear(); zclear();
- }
-
- draw_display();
-
- remake_display_menu();
- remake_curve_menu();
- }
-
-
- /*
- * Toggles the mode of the control point markers between on and off.
- */
- void toggle_markers(void)
- {
- if (markers == ON)
- markers = OFF;
- else
- markers = ON;
-
- draw_display();
-
- remake_options_menu();
- remake_curve_menu();
- }
-
-
- /*
- * Toggles the mode of the convex hulls between on and off.
- */
- void toggle_hulls(void)
- {
- if (hulls == ON)
- hulls = OFF;
- else
- hulls = ON;
-
- draw_display();
-
- remake_options_menu();
- remake_curve_menu();
- }
-
-
- /*
- * Toggles motion between on and off.
- */
- void toggle_motion(void)
- {
- if (motion == ON)
- {
- motion = OFF;
- draw_active = FALSE;
- }
- else
- {
- motion = ON;
- draw_active = TRUE;
- }
-
- remake_options_menu();
- remake_curve_menu();
- }
-
-
- /*
- * Toggles 'smearing' between on and off. Smearing is only visible
- * when motion is also turned on.
- */
- void toggle_smear(void)
- {
- if (smear == ON)
- {
- smear = OFF;
- frontbuffer(FALSE);
- }
- else
- {
- smear = ON;
- frontbuffer(TRUE);
- }
-
- draw_display();
-
- remake_options_menu();
- remake_curve_menu();
- }
-
-
- /*
- * Changes the curve basis matrix to that selected by the user.
- */
- void change_basis(int new_basis)
- {
- curve_basis = new_basis;
-
- curvebasis(curve_basis);
-
- draw_display();
-
- remake_basis_menu();
- remake_curve_menu();
- }
-
-
- /*
- * Changes the curve precision (in segments per spline) to that
- * selected by the user.
- */
- void change_precision(int new_precision)
- {
- curve_precision = new_precision;
-
- curveprecision(curve_precision);
-
- draw_display();
-
- remake_precision_menu();
- remake_options_menu();
- remake_curve_menu();
- }
-
-
- /*
- * Changes the motion speed to that selected by the user.
- */
- void change_speed(int new_speed)
- {
- speed = new_speed;
-
- remake_speed_menu();
- remake_options_menu();
- remake_curve_menu();
- }
-
-
- /*
- * Changes the line style used to draw the curves to that selected by
- * the user.
- */
- void change_style(int new_style)
- {
- line_style = new_style;
-
- draw_display();
-
- remake_style_menu();
- remake_options_menu();
- remake_curve_menu();
- }
-
-
-
- void change_whizbang(int new_whizbang)
- {
- whizbang = new_whizbang;
-
- create_whizbang(whizbang);
-
- draw_active = TRUE;
- draw_display();
-
- remake_whizbang_menu();
- remake_options_menu();
- remake_curve_menu();
- }
-
-
-
- /*
- * Sets the three dimensional viewing transformation and sets up depth
- * cuing. DOES NOT PRESERVE THE CURRENT MATRX. BE SURE TO PUSHMATRIX
- * IF YOU NEED TO SAVE IT.
- */
- void set_three_d_view(void)
- {
- /* Perspecive, 3D view:
- 40 degree field of view,
- aspect maintained,
- clip around -1 to +1 cube, allow for rotation,
- move eye back */
- perspective(400, aspect, 4.0 - fsqrt(3), 5.0 + fsqrt(3));
- translate(0.0, 0.0, -5.0);
- if (hardware != ECLIPSE8)
- {
- depthcue(TRUE);
- }
- }
-
-
- /*
- * Sets the two dimensional viewing transformation.
- * DOES NOT PRESERVE THE CURRENT MATRX. BE SURE TO PUSHMATRIX
- * IF YOU NEED TO SAVE IT.
- */
- void set_two_d_view(void)
- {
- display_mode = TWO_D;
- /* Orthographic, 2D view. Ignores z values */
- ortho(-1.0, 1.0, -1.0, 1.0, -2.0, 2.0);
- depthcue(FALSE);
- }
-