changed: gcc8 base update
[opensg.git] / Source / Contrib / Manipulators / OSGRotateManipulator.cpp
bloba1713db80c5f3587d6112e5c38575008d516127c
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <stdlib.h>
44 #include <stdio.h>
46 #define OSG_COMPILEMANIPULATORSLIB
48 #include "OSGConfig.h"
49 #include "OSGRenderAction.h"
50 #include "OSGIntersectAction.h"
52 #include "OSGRotateManipulator.h"
54 OSG_USING_NAMESPACE
56 /***************************************************************************\
57 * Description *
58 \***************************************************************************/
60 /*! \class OSG::RotateManipulator
61 * The MoveHandle is used for moving objects. It consist of three axis which
62 * can be picked and translated and one center box to translate freely in 3D.
65 /***************************************************************************\
66 * Class variables *
67 \***************************************************************************/
69 /***************************************************************************\
70 * Class methods *
71 \***************************************************************************/
73 void RotateManipulator::initMethod(InitPhase ePhase)
75 Inherited::initMethod(ePhase);
77 if(ePhase == TypeObject::SystemPost)
79 IntersectAction::registerEnterDefault(
80 getClassType(),
81 reinterpret_cast<Action::Callback>(
82 &RotateManipulator::intersectEnter));
84 IntersectAction::registerLeaveDefault(
85 getClassType(),
86 reinterpret_cast<Action::Callback>(
87 &RotateManipulator::intersectLeave));
89 RenderAction::registerEnterDefault(
90 getClassType(),
91 reinterpret_cast<Action::Callback>(
92 &RotateManipulator::renderEnter));
94 RenderAction::registerLeaveDefault(
95 getClassType(),
96 reinterpret_cast<Action::Callback>(
97 &RotateManipulator::renderLeave));
101 /***************************************************************************\
102 * Instance methods *
103 \***************************************************************************/
105 /*-------------------------------------------------------------------------*\
106 - private -
107 \*-------------------------------------------------------------------------*/
109 /*----------------------- constructors & destructors ----------------------*/
111 RotateManipulator::RotateManipulator(void) :
112 Inherited()
116 RotateManipulator::RotateManipulator(const RotateManipulator &source) :
117 Inherited(source)
121 RotateManipulator::~RotateManipulator(void)
125 /*----------------------------- class specific ----------------------------*/
127 void RotateManipulator::changed(ConstFieldMaskArg whichField,
128 UInt32 origin,
129 BitVector details)
131 Inherited::changed(whichField, origin, details);
134 void RotateManipulator::dump( UInt32 uiIndent,
135 const BitVector bvFlags ) const
137 Inherited::dump(uiIndent, bvFlags);
140 NodeTransitPtr RotateManipulator::makeHandleGeo()
142 return makeSphere(2, 0.2f);
145 void RotateManipulator::doMovement( Transform *t,
146 const Int32 coord,
147 const Real32 value,
148 const Vec3f &translation,
149 const Quaternion &rotation,
150 const Vec3f &scaleFactor,
151 const Quaternion &scaleOrientation)
153 Vec3f axis(0.0f, 0.0f, 0.0f);
154 axis[coord] = 1.0;
155 const Quaternion rot(axis, value);
157 Matrix ma, mb, mc, md, me, mf, mg;
159 Vec3f sp( getPivot()[0] * scaleFactor[0],
160 getPivot()[1] * scaleFactor[1],
161 getPivot()[2] * scaleFactor[2]);
163 ma.setTranslate( - translation );
164 mb.setRotate ( rotation.inverse() );
165 mc.setTranslate( - sp );
166 md.setRotate ( rot );
167 me.setTranslate( sp );
168 mf.setRotate ( rotation );
169 mg.setTranslate( translation );
172 t->editMatrix().multLeft(ma);
173 t->editMatrix().multLeft(mb);
174 t->editMatrix().multLeft(mc);
175 t->editMatrix().multLeft(md);
176 t->editMatrix().multLeft(me);
177 t->editMatrix().multLeft(mf);
178 t->editMatrix().multLeft(mg);