OSGScaleManipulator.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 "OSGScaleManipulator.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 ScaleManipulator::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                 &ScaleManipulator::intersectEnter));
00083
00084         IntersectAction::registerLeaveDefault(
00085             getClassType(),
00086             reinterpret_cast<Action::Callback>(
00087                 &ScaleManipulator::intersectLeave));
00088
00089         RenderAction::registerEnterDefault(
00090             getClassType(),
00091             reinterpret_cast<Action::Callback>(&ScaleManipulator::renderEnter));
00092
00093         RenderAction::registerLeaveDefault(
00094             getClassType(),
00095             reinterpret_cast<Action::Callback>(&ScaleManipulator::renderLeave));
00096     }
00097 }
00098
00099
00100 /***************************************************************************\
00101  *                           Instance methods                              *
00102 \***************************************************************************/
00103
00104 /*-------------------------------------------------------------------------*\
00105  -  private                                                                 -
00106 \*-------------------------------------------------------------------------*/
00107
00108 /*----------------------- constructors & destructors ----------------------*/
00109
00110 ScaleManipulator::ScaleManipulator(void) :
00111     Inherited()
00112 {
00113 }
00114
00115 ScaleManipulator::ScaleManipulator(const ScaleManipulator &source) :
00116     Inherited(source)
00117 {
00118 }
00119
00120 ScaleManipulator::~ScaleManipulator(void)
00121 {
00122 }
00123
00124 /*----------------------------- class specific ----------------------------*/
00125
00126 void ScaleManipulator::changed(ConstFieldMaskArg whichField,
00127                                UInt32            origin,
00128                                BitVector         details   )
00129 {
00130     Inherited::changed(whichField, origin, details);
00131 }
00132
00133 void ScaleManipulator::dump(      UInt32    uiIndent,
00134                             const BitVector bvFlags) const
00135 {
00136     Inherited::dump(uiIndent, bvFlags);
00137 }
00138
00139 NodeTransitPtr ScaleManipulator::makeHandleGeo()
00140 {
00141     return makeCylinder(0.75f, 0.1f, 12, true, true, true);
00142 }
00143
00144 void ScaleManipulator::doMovement(      Transform    *t,
00145                                   const Int32         coord,
00146                                   const Real32        value,
00147                                   const Vec3f        &translation,
00148                                   const Quaternion   &rotation,
00149                                   const Vec3f        &scaleFactor,
00150                                   const Quaternion   &scaleOrientation)
00151 {
00152     Vec3f scale(1.0f, 1.0f, 1.0f);
00153     scale[coord] += value;
00154
00155     Matrix ma, mb, mc, md, me;
00156
00157     ma.setTranslate(-translation       );
00158     mb.setRotate   ( rotation.inverse());
00159     mc.setScale    ( scale             );
00160     md.setRotate   ( rotation          );
00161     me.setTranslate( translation       );
00162
00163     t->editMatrix().multLeft(ma);
00164     t->editMatrix().multLeft(mb);
00165     t->editMatrix().multLeft(mc);
00166     t->editMatrix().multLeft(md);
00167     t->editMatrix().multLeft(me);
00168
00169     commitChanges();
00170 }