Trackball.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                              SOFA :: Framework                              *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00027 /*
00028  * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
00029  * ALL RIGHTS RESERVED
00030  * Permission to use, copy, modify, and distribute this software for
00031  * any purpose and without fee is hereby granted, provided that the above
00032  * copyright notice appear in all copies and that both the copyright notice
00033  * and this permission notice appear in supporting documentation, and that
00034  * the name of Silicon Graphics, Inc. not be used in advertising
00035  * or publicity pertaining to distribution of the software without specific,
00036  * written prior permission.
00037  *
00038  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
00039  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
00040  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
00041  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
00042  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
00043  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
00044  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
00045  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
00046  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
00047  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
00048  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
00049  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
00050  *
00051  * US Government Users Restricted Rights
00052  * Use, duplication, or disclosure by the Government is subject to
00053  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
00054  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
00055  * clause at DFARS 252.227-7013 and/or in similar or successor
00056  * clauses in the FAR or the DOD or NASA FAR Supplement.
00057  * Unpublished-- rights reserved under the copyright laws of the
00058  * United States.  Contractor/manufacturer is Silicon Graphics,
00059  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
00060  *
00061  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
00062  */
00063 /*
00064  * trackball.h
00065  * A virtual trackball implementation
00066  * Written by Gavin Bell for Silicon Graphics, November 1988.
00067  */
00068 
00069 /*
00070  * Pass the x and y coordinates of the last and current positions of
00071  * the mouse, scaled so they are from (-1.0 ... 1.0).
00072  *
00073  * The resulting rotation is returned as a quaternion rotation in the
00074  * first paramater.
00075  */
00076 
00077 #ifndef SOFA_HELPER_GL_TRACKBALL_H
00078 #define SOFA_HELPER_GL_TRACKBALL_H
00079 
00080 #include <sofa/defaulttype/Quat.h>
00081 
00082 namespace sofa
00083 {
00084 
00085 namespace helper
00086 {
00087 
00088 namespace gl
00089 {
00090 
00091 class   Trackball
00092 {
00093   public:
00094 //  typedef Quater<double> Quaternion;
00095 
00096     Trackball();
00097     ~Trackball();
00098 
00099     // Accessors
00100     void SetQuaternion(sofa::defaulttype::Quaternion Q);
00101     sofa::defaulttype::Quaternion GetQuaternion(void);
00102 
00103     // Pass the x and y coordinates of the last and current positions of
00104     // the mouse, scaled so they are from (-1.0 ... 1.0).
00105     // The resulting rotation is returned as a quaternion rotation 
00106     void ComputeQuaternion(double p1x, double p1y, double p2x,
00107                                   double p2y);
00108 
00109     // This function computes a quaternion based on an axis (defined by
00110     // the given vector) and an angle about which to rotate.  The angle is
00111     // expressed in radians.  The result is put into the third argument.
00112     void AxisToQuat(double a[3], double phi, double q[4]);
00113 
00114   private:
00115     sofa::defaulttype::Quaternion   _quat;
00116 };
00117 
00118 } // namespace gl
00119 
00120 } // namespace helper
00121 
00122 } // namespace sofa
00123 
00124 #endif

Generated on Sun Nov 23 02:29:30 2008 for Sofa by  doxygen 1.5.7.1