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.
- */
- #include <gl.h>
- #include <device.h>
- #include <math.h>
- #include "event.h"
- #include "trackball.h"
- #include "rotate.h"
-
- extern Matrix identity_matrix;
-
- /*
- * This matrix get successively updated as the user rotates the view
- * volume. It represents the transformation to rotate the view volume
- * (and the curve within it) from whatever the current transformation
- * is to the appropriate rotated view.
- */
- Matrix view_matrix =
- { {1.0,0.0,0.0,0.0},
- {0.0,1.0,0.0,0.0},
- {0.0,0.0,1.0,0.0},
- {0.0,0.0,0.0,1.0}
- };
- Matrix R_view_matrix =
- { {1.0,0.0,0.0,0.0},
- {0.0,1.0,0.0,0.0},
- {0.0,0.0,1.0,0.0},
- {0.0,0.0,0.0,1.0}
- };
-
- /* About the window... */
- extern long origin_x, origin_y, size_x, size_y;
-
- /* Mouse values in screen coords */
- static Scoord mx, my;
-
- /* Scaled mouse values (-1.0 to 1.0) */
- static Coord last_x, last_y, new_x, new_y;
-
- static Coord euler[4];
- Boolean euler_initialized = FALSE;
- static Coord x_axis[3] = {1.0, 0.0, 0.0};
-
-
-
- void rotate_view_volume(void)
- {
- mx = getvaluator(MOUSEX) - origin_x;
- my = getvaluator(MOUSEY) - origin_y;
-
- /* Scale mouse values to square around -1.0 to 1.0 */
- last_x = 2.0*((Coord)mx/size_x - 0.5);
- last_y = 2.0*((Coord)my/size_y - 0.5);
-
- if (! euler_initialized)
- {
- axis_to_euler(x_axis, 0.0, euler);
- euler_initialized = TRUE;
- }
- }
-
-
- void update_view_rotation(void)
- {
- Coord new_euler[4];
- Coord R_euler[4]; /* reversed */
-
- mx = getvaluator(MOUSEX) - origin_x;
- my = getvaluator(MOUSEY) - origin_y;
-
- /* Scale mouse values to square around -1.0 to 1.0 */
- new_x = 2.0*((Coord)mx/size_x - 0.5);
- new_y = 2.0*((Coord)my/size_y - 0.5);
-
- axis_to_euler(x_axis, 0.0, new_euler);
- trackball(new_euler, last_x, last_y, new_x, new_y);
-
- last_x = new_x;
- last_y = new_y;
-
- add_eulers(new_euler, euler, euler);
- build_rotmatrix(view_matrix, euler);
-
- R_euler[0] = euler[0];
- R_euler[1] = euler[1];
- R_euler[2] = euler[2];
- R_euler[3] = -euler[3];
-
- build_rotmatrix(R_view_matrix, R_euler);
- }
-
-