OSGRotateManipulator.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *               Copyright (C) 2000-2002 by the OpenSG Forum                 *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038
00039 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #define OSG_COMPILEMANIPULATORSLIB
00047 
00048 #include "OSGConfig.h"
00049 #include "OSGRenderAction.h"
00050 #include "OSGIntersectAction.h"
00051
00052 #include "OSGRotateManipulator.h"
00053
00054 OSG_USING_NAMESPACE
00055
00056 /***************************************************************************\
00057  *                            Description                                  *
00058 \***************************************************************************/
00059
00065 /***************************************************************************\
00066  *                           Class variables                               *
00067 \***************************************************************************/
00068
00069 /***************************************************************************\
00070  *                           Class methods                                 *
00071 \***************************************************************************/
00072
00073 void RotateManipulator::initMethod(InitPhase ePhase)
00074 {
00075     Inherited::initMethod(ePhase);
00076
00077     if(ePhase == TypeObject::SystemPost)
00078     {
00079         IntersectAction::registerEnterDefault(
00080             getClassType(),
00081             reinterpret_cast<Action::Callback>(
00082                 &RotateManipulator::intersectEnter));
00083
00084         IntersectAction::registerLeaveDefault(
00085             getClassType(),
00086             reinterpret_cast<Action::Callback>(
00087                 &RotateManipulator::intersectLeave));
00088
00089         RenderAction::registerEnterDefault(
00090             getClassType(),
00091             reinterpret_cast<Action::Callback>(
00092                 &RotateManipulator::renderEnter));
00093
00094         RenderAction::registerLeaveDefault(
00095             getClassType(),
00096             reinterpret_cast<Action::Callback>(
00097                 &RotateManipulator::renderLeave));
00098     }
00099 }
00100
00101 /***************************************************************************\
00102  *                           Instance methods                              *
00103 \***************************************************************************/
00104
00105 /*-------------------------------------------------------------------------*\
00106  -  private                                                                 -
00107 \*-------------------------------------------------------------------------*/
00108
00109 /*----------------------- constructors & destructors ----------------------*/
00110
00111 RotateManipulator::RotateManipulator(void) :
00112     Inherited()
00113 {
00114 }
00115
00116 RotateManipulator::RotateManipulator(const RotateManipulator &source) :
00117     Inherited(source)
00118 {
00119 }
00120
00121 RotateManipulator::~RotateManipulator(void)
00122 {
00123 }
00124
00125 /*----------------------------- class specific ----------------------------*/
00126
00127 void RotateManipulator::changed(ConstFieldMaskArg whichField,
00128                                 UInt32            origin,
00129                                 BitVector         details)
00130 {
00131     Inherited::changed(whichField, origin, details);
00132 }
00133
00134 void RotateManipulator::dump(      UInt32    uiIndent,
00135                              const BitVector bvFlags ) const
00136 {
00137     Inherited::dump(uiIndent, bvFlags);
00138 }
00139
00140 NodeTransitPtr RotateManipulator::makeHandleGeo()
00141 {
00142     return makeSphere(2, 0.2f);
00143 }
00144
00145 void RotateManipulator::doMovement(      Transform    *t,
00146                                    const Int32         coord,
00147                                    const Real32        value,
00148                                    const Vec3f        &translation,
00149                                    const Quaternion   &rotation,
00150                                    const Vec3f        &scaleFactor,
00151                                    const Quaternion   &scaleOrientation)
00152 {
00153     Vec3f axis(0.0f, 0.0f, 0.0f);
00154     axis[coord] = 1.0;
00155     const Quaternion rot(axis, value);
00156
00157     Matrix ma, mb, mc, md, me;
00158
00159     ma.setTranslate(-translation        );
00160     mb.setRotate   ( rotation.inverse() );
00161     mc.setRotate   ( rot                );
00162     md.setRotate   ( rotation           );
00163     me.setTranslate( translation        );
00164     t->editMatrix().multLeft(ma);
00165     t->editMatrix().multLeft(mb);
00166     t->editMatrix().multLeft(mc);
00167     t->editMatrix().multLeft(md);
00168     t->editMatrix().multLeft(me);
00169
00170     commitChanges();
00171 }