core/vgui/internals/trackball.h
Go to the documentation of this file.
00001 #ifndef vgui_internals_trackball_h_
00002 #define vgui_internals_trackball_h_
00003 
00004 #ifdef __cplusplus
00005 extern "C" {
00006 #endif
00007 /*
00008  * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
00009  * ALL RIGHTS RESERVED
00010  * Permission to use, copy, modify, and distribute this software for
00011  * any purpose and without fee is hereby granted, provided that the above
00012  * copyright notice appear in all copies and that both the copyright notice
00013  * and this permission notice appear in supporting documentation, and that
00014  * the name of Silicon Graphics, Inc. not be used in advertising
00015  * or publicity pertaining to distribution of the software without specific,
00016  * written prior permission.
00017  *
00018  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
00019  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
00020  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
00021  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
00022  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
00023  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
00024  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
00025  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
00026  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
00027  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
00028  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
00029  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
00030  *
00031  * US Government Users Restricted Rights
00032  * Use, duplication, or disclosure by the Government is subject to
00033  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
00034  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
00035  * clause at DFARS 252.227-7013 and/or in similar or successor
00036  * clauses in the FAR or the DOD or NASA FAR Supplement.
00037  * Unpublished-- rights reserved under the copyright laws of the
00038  * United States.  Contractor/manufacturer is Silicon Graphics,
00039  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
00040  *
00041  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
00042  */
00043 /*
00044  * trackball.h
00045  * A virtual trackball implementation
00046  * Written by Gavin Bell for Silicon Graphics, November 1988.
00047  */
00048 
00049 /*
00050  * Pass the x and y coordinates of the last and current positions of
00051  * the mouse, scaled so they are from (-1.0 ... 1.0).
00052  *
00053  * The resulting rotation is returned as a quaternion rotation in the
00054  * first parameter.
00055  */
00056 void
00057 trackball(float q[4], float p1x, float p1y, float p2x, float p2y);
00058 
00059 /*
00060  * Given two quaternions, add them together to get a third quaternion.
00061  * Adding quaternions to get a compound rotation is analagous to adding
00062  * translations to get a compound translation.  When incrementally
00063  * adding rotations, the first argument here should be the new
00064  * rotation, the second and third the total rotation (which will be
00065  * over-written with the resulting new total rotation).
00066  */
00067 void
00068 add_quats(const float *q1, const float *q2, float *dest);
00069 
00070 /*
00071  * A useful function, builds a rotation matrix in Matrix based on
00072  * given quaternion.
00073  */
00074 void
00075 build_rotmatrix(float m[4][4], float q[4]);
00076 
00077 /*
00078  * This function computes a quaternion based on an axis (defined by
00079  * the given vcl_vector) and an angle about which to rotate.  The angle is
00080  * expressed in radians.  The result is put into the third argument.
00081  */
00082 void
00083 axis_to_quat(float a[3], float phi, float q[4]);
00084 
00085 #ifdef __cplusplus
00086 }
00087 #endif
00088 
00089 #endif /* vgui_internals_trackball_h_ */