home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / blix / blixtrackball.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.2 KB  |  88 lines

  1. /*
  2.  * Copyright (C) 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. /*__________________________________________________________________________
  18.  |
  19.  | blixtrackball.h - virtual trackball 
  20.  |
  21.  |  based on the implemantation of Gavin Bell, but adapted to meet blix
  22.  |  high standards :-)
  23.  |
  24.  |    Implementation of a virtual trackball.
  25.  |    Implemented by Gavin Bell, lots of ideas from Thant Tessman and
  26.  |        the August '88 issue of Siggraph's "Computer Graphics," pp. 121-129.
  27.  |
  28. */
  29.  
  30.  
  31. #include "blixvect.h"
  32.  
  33. /* set the size of the trackball, a good value for a general scene is 0.8
  34.  * but you might set it to the eactual size of the oblejt, the mosue is on
  35.  */
  36.  
  37. void set_trackball (const float size, const float ypos);
  38.  
  39. /*
  40.  * Pass the x and y coordinates of the last and current positions of
  41.  * the mouse, scaled so they are from (-1.0 ... 1.0).
  42.  *
  43.  * if ox,oy is the window's center and sizex,sizey is its size, then
  44.  * the proper transformation from screen coordinates (sc) to world
  45.  * coordinates (wc) is:
  46.  * wcx = (2.0 * (scx-ox)) / (float)sizex - 1.0
  47.  * wcy = (2.0 * (scy-oy)) / (float)sizey - 1.0
  48.  *
  49.  * The resulting rotation is returned as a quaternion rotation in the
  50.  * first paramater.
  51.  */
  52. void
  53. trackball(float q[4], const float p1x, const float p1y, const float p2x,
  54.     const float p2y);
  55.  
  56. /*
  57.  * Given two quaternions, add them together to get a third quaternion.
  58.  * Adding quaternions to get a compound rotation is analagous to adding
  59.  * translations to get a compound translation.  When incrementally
  60.  * adding rotations, the first argument here should be the new
  61.  * rotation, the second and third the total rotation (which will be
  62.  * over-written with the resulting new total rotation).
  63.  */
  64. void add_quats(const float q1[4], const float q2[4], float dest[4]);
  65.  
  66. /*
  67.  * A useful function, builds a rotation matrix in Matrix based on
  68.  * given quaternion.
  69.  */
  70. void build_rotmatrix(Matrix, const float q[4]);
  71.  
  72. /*
  73.  * This function computes a quaternion based on an axis (defined by
  74.  * the given vector) and an angle about which to rotate.  The angle is
  75.  * expressed in radians.  The result is put into the third argument.
  76.  */
  77. void axis_to_quat(float a[3], const float angle, float q[4]);
  78.  
  79. /*
  80.  * These are defined for compatibility with an older version of this
  81.  * that referred to quaternions as 'Euler Paramaters'.  The term
  82.  * 'quaternion' is much more widely used in the computer graphics
  83.  * community, and causes less confusion (Euler Paramaters are easily
  84.  * confused with Euler Angles, which are totally different).
  85.  */
  86. #define add_eulers add_quats
  87. #define axis_to_euler axis_to_quat
  88.