home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / GL / snurb / rotate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.7 KB  |  106 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <gl.h>
  18. #include <device.h>
  19. #include <math.h>
  20. #include "event.h"
  21. #include "trackball.h"
  22. #include "rotate.h"
  23.  
  24. extern Matrix identity_matrix;
  25.  
  26. /* 
  27.  * This matrix get successively updated as the user rotates the view
  28.  * volume. It represents the transformation to rotate the view volume
  29.  * (and the curve within it) from whatever the current transformation
  30.  * is to the appropriate rotated view.
  31.  */
  32. Matrix view_matrix = 
  33.     {    {1.0,0.0,0.0,0.0}, 
  34.         {0.0,1.0,0.0,0.0},
  35.         {0.0,0.0,1.0,0.0},
  36.         {0.0,0.0,0.0,1.0}
  37.     };
  38. Matrix R_view_matrix =
  39.     {    {1.0,0.0,0.0,0.0}, 
  40.         {0.0,1.0,0.0,0.0},
  41.         {0.0,0.0,1.0,0.0},
  42.         {0.0,0.0,0.0,1.0}
  43.     };
  44.  
  45. /* About the window... */ 
  46. extern long origin_x, origin_y, size_x, size_y;
  47.  
  48. /* Mouse values in screen coords */
  49. static Scoord mx, my;
  50.     
  51. /* Scaled mouse values (-1.0 to 1.0) */
  52. static Coord last_x, last_y, new_x, new_y;
  53.  
  54. static Coord euler[4];
  55. Boolean euler_initialized = FALSE;
  56. static Coord x_axis[3] = {1.0, 0.0, 0.0};
  57.  
  58.  
  59.  
  60. void rotate_view_volume(void)
  61. {
  62.     mx = getvaluator(MOUSEX) - origin_x;
  63.     my = getvaluator(MOUSEY) - origin_y;
  64.  
  65.     /* Scale mouse values to square around -1.0 to 1.0  */
  66.     last_x = 2.0*((Coord)mx/size_x - 0.5);
  67.     last_y = 2.0*((Coord)my/size_y - 0.5);
  68.  
  69.     if (! euler_initialized)
  70.     {
  71.         axis_to_euler(x_axis, 0.0, euler);
  72.         euler_initialized = TRUE;
  73.     }
  74. }
  75.  
  76.  
  77. void update_view_rotation(void)
  78. {
  79.     Coord new_euler[4];
  80.     Coord R_euler[4]; /* reversed */
  81.     
  82.     mx = getvaluator(MOUSEX) - origin_x;
  83.     my = getvaluator(MOUSEY) - origin_y;
  84.     
  85.     /* Scale mouse values to square around -1.0 to 1.0  */
  86.     new_x = 2.0*((Coord)mx/size_x - 0.5);
  87.     new_y = 2.0*((Coord)my/size_y - 0.5);
  88.  
  89.     axis_to_euler(x_axis, 0.0, new_euler);
  90.     trackball(new_euler, last_x, last_y, new_x, new_y);
  91.  
  92.     last_x = new_x;
  93.     last_y = new_y;
  94.     
  95.     add_eulers(new_euler, euler, euler); 
  96.     build_rotmatrix(view_matrix, euler);
  97.  
  98.     R_euler[0] = euler[0];
  99.     R_euler[1] = euler[1];
  100.     R_euler[2] = euler[2];
  101.     R_euler[3] = -euler[3];
  102.         
  103.     build_rotmatrix(R_view_matrix, R_euler);
  104. }
  105.  
  106.