home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / GL / snurb / scaleobj.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.2 KB  |  82 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 <stdio.h>
  18. #include <gl.h>
  19. #include <device.h>
  20. #include <math.h>
  21. #include "defines.h"
  22. #include "event.h"
  23. #include "trackball.h"
  24. #include "scaleobj.h"
  25. #include "rotobj.h"
  26.  
  27. extern Matrix view_matrix;
  28. extern Matrix R_view_matrix;
  29. extern Matrix identity_matrix;
  30.  
  31. /* About the window... */ 
  32. extern long origin_x, origin_y, size_x, size_y;
  33.  
  34. /* Mouse values in screen coords */
  35. static Scoord mx;
  36.     
  37. /* Scaled mouse values (-1.0 to 1.0) */
  38. static Coord last_x, new_x;
  39.  
  40. static Coord scale_center[3];
  41.  
  42. void scale_object()
  43. {
  44.     mx = getvaluator(MOUSEX) - origin_x;
  45. /*    my = getvaluator(MOUSEY) - origin_y;*/
  46.  
  47.     /* Scale mouse values to square around -1.0 to 1.0  */
  48.     last_x = 2.0*((Coord)mx/size_x - 0.5);
  49. /*    last_y = 2.0*((Coord)my/size_y - 0.5); */
  50.  
  51.     compute_center(scale_center);
  52. }
  53.  
  54.  
  55. void update_object_scale(Matrix object_matrix)
  56. {
  57.     float scale_factor;
  58.     
  59.     mx = getvaluator(MOUSEX) - origin_x;
  60. /*    my = getvaluator(MOUSEY) - origin_y;*/
  61.     
  62.     /* Scale mouse values to square around -1.0 to 1.0  */
  63.     new_x = 2.0*((Coord)mx/size_x - 0.5);
  64. /*    new_y = 2.0*((Coord)my/size_y - 0.5); */
  65.  
  66.     scale_factor = 1.0 + new_x - last_x;
  67.  
  68.     last_x = new_x;
  69. /*    last_y = new_y; */
  70.     
  71.     loadmatrix(identity_matrix);
  72.         
  73.     translate(scale_center[0],scale_center[1],scale_center[2]); 
  74.     multmatrix(R_view_matrix);
  75.     scale(scale_factor, scale_factor, scale_factor);
  76.     multmatrix(view_matrix);
  77.     translate(-scale_center[0],-scale_center[1],-scale_center[2]); 
  78.  
  79.     getmatrix(object_matrix);
  80. }
  81.  
  82.