132001f49Smrg/*
232001f49Smrg * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
332001f49Smrg * ALL RIGHTS RESERVED
432001f49Smrg * Permission to use, copy, modify, and distribute this software for
532001f49Smrg * any purpose and without fee is hereby granted, provided that the above
632001f49Smrg * copyright notice appear in all copies and that both the copyright notice
732001f49Smrg * and this permission notice appear in supporting documentation, and that
832001f49Smrg * the name of Silicon Graphics, Inc. not be used in advertising
932001f49Smrg * or publicity pertaining to distribution of the software without specific,
1032001f49Smrg * written prior permission.
1132001f49Smrg *
1232001f49Smrg * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
1332001f49Smrg * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
1432001f49Smrg * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
1532001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
1632001f49Smrg * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
1732001f49Smrg * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
1832001f49Smrg * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
1932001f49Smrg * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
2032001f49Smrg * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
2132001f49Smrg * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
2232001f49Smrg * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
2332001f49Smrg * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
2432001f49Smrg *
2532001f49Smrg * US Government Users Restricted Rights
2632001f49Smrg * Use, duplication, or disclosure by the Government is subject to
2732001f49Smrg * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
2832001f49Smrg * (c)(1)(ii) of the Rights in Technical Data and Computer Software
2932001f49Smrg * clause at DFARS 252.227-7013 and/or in similar or successor
3032001f49Smrg * clauses in the FAR or the DOD or NASA FAR Supplement.
3132001f49Smrg * Unpublished-- rights reserved under the copyright laws of the
3232001f49Smrg * United States.  Contractor/manufacturer is Silicon Graphics,
3332001f49Smrg * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
3432001f49Smrg *
3532001f49Smrg * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
3632001f49Smrg */
3732001f49Smrg/*
3832001f49Smrg * trackball.h
3932001f49Smrg * A virtual trackball implementation
4032001f49Smrg * Written by Gavin Bell for Silicon Graphics, November 1988.
4132001f49Smrg */
4232001f49Smrg
4332001f49Smrg#ifndef TRACKBALL_H
4432001f49Smrg#define TRACKBALL_H
4532001f49Smrg
4632001f49Smrg
4732001f49Smrg/*
4832001f49Smrg * Pass the x and y coordinates of the last and current positions of
4932001f49Smrg * the mouse, scaled so they are from (-1.0 ... 1.0).
5032001f49Smrg *
5132001f49Smrg * The resulting rotation is returned as a quaternion rotation in the
5232001f49Smrg * first paramater.
5332001f49Smrg */
5432001f49Smrgvoid
5532001f49Smrgtrackball(float q[4], float p1x, float p1y, float p2x, float p2y);
5632001f49Smrg
5732001f49Smrg/*
5832001f49Smrg * Given two quaternions, add them together to get a third quaternion.
5932001f49Smrg * Adding quaternions to get a compound rotation is analagous to adding
6032001f49Smrg * translations to get a compound translation.  When incrementally
6132001f49Smrg * adding rotations, the first argument here should be the new
6232001f49Smrg * rotation, the second and third the total rotation (which will be
6332001f49Smrg * over-written with the resulting new total rotation).
6432001f49Smrg */
6532001f49Smrgvoid
6632001f49Smrgadd_quats(const float q1[4], const float q2[4], float dest[4]);
6732001f49Smrg
6832001f49Smrg/*
6932001f49Smrg * A useful function, builds a rotation matrix in Matrix based on
7032001f49Smrg * given quaternion.
7132001f49Smrg */
7232001f49Smrgvoid
7332001f49Smrgbuild_rotmatrix(float m[4][4], const float q[4]);
7432001f49Smrg
7532001f49Smrg/*
7632001f49Smrg * This function computes a quaternion based on an axis (defined by
7732001f49Smrg * the given vector) and an angle about which to rotate.  The angle is
7832001f49Smrg * expressed in radians.  The result is put into the third argument.
7932001f49Smrg */
8032001f49Smrgvoid
8132001f49Smrgaxis_to_quat(const float a[3], float phi, float q[4]);
8232001f49Smrg
8332001f49Smrg
8432001f49Smrg#endif /* TRACKBALL_H */
85