1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #define OSG_COMPILEMANIPULATORSLIB
48 #include "OSGConfig.h"
49 #include "OSGRenderAction.h"
50 #include "OSGIntersectAction.h"
52 #include "OSGScaleManipulator.h"
56 /***************************************************************************\
58 \***************************************************************************/
60 /*! \class OSG::ScaleManipulator
61 * The ScaleHandle is used for scaleing objects. It consist of three axis
62 * which can be picked and scaled and one center box to scale freely in 3D.
65 /***************************************************************************\
67 \***************************************************************************/
69 /***************************************************************************\
71 \***************************************************************************/
73 void ScaleManipulator::initMethod(InitPhase ePhase
)
75 Inherited::initMethod(ePhase
);
77 if(ePhase
== TypeObject::SystemPost
)
79 IntersectAction::registerEnterDefault(
81 reinterpret_cast<Action::Callback
>(
82 &ScaleManipulator::intersectEnter
));
84 IntersectAction::registerLeaveDefault(
86 reinterpret_cast<Action::Callback
>(
87 &ScaleManipulator::intersectLeave
));
89 RenderAction::registerEnterDefault(
91 reinterpret_cast<Action::Callback
>(&ScaleManipulator::renderEnter
));
93 RenderAction::registerLeaveDefault(
95 reinterpret_cast<Action::Callback
>(&ScaleManipulator::renderLeave
));
100 /***************************************************************************\
102 \***************************************************************************/
104 /*-------------------------------------------------------------------------*\
106 \*-------------------------------------------------------------------------*/
108 /*----------------------- constructors & destructors ----------------------*/
110 ScaleManipulator::ScaleManipulator(void) :
115 ScaleManipulator::ScaleManipulator(const ScaleManipulator
&source
) :
120 ScaleManipulator::~ScaleManipulator(void)
124 /*----------------------------- class specific ----------------------------*/
126 void ScaleManipulator::changed(ConstFieldMaskArg whichField
,
130 Inherited::changed(whichField
, origin
, details
);
133 void ScaleManipulator::dump( UInt32 uiIndent
,
134 const BitVector bvFlags
) const
136 Inherited::dump(uiIndent
, bvFlags
);
139 NodeTransitPtr
ScaleManipulator::makeHandleGeo()
141 return makeCylinder(0.75f
, 0.1f
, 12, true, true, true);
144 void ScaleManipulator::doMovement( Transform
*t
,
147 const Vec3f
&translation
,
148 const Quaternion
&rotation
,
149 const Vec3f
&scaleFactor
,
150 const Quaternion
&scaleOrientation
)
152 Vec3f
scale(1.0f
, 1.0f
, 1.0f
);
154 if(getUniform() == true)
156 scale
+= Vec3f(value
, value
, value
);
160 scale
[coord
] += value
;
163 Matrix ma
, mb
, mc
, md
, me
, mf
, mg
;
165 Vec3f
sp( getPivot()[0] * scaleFactor
[0],
166 getPivot()[1] * scaleFactor
[1],
167 getPivot()[2] * scaleFactor
[2]);
169 ma
.setTranslate(-translation
);
170 mb
.setRotate ( rotation
.inverse());
171 mc
.setTranslate( - sp
);
172 md
.setScale ( scale
);
173 me
.setTranslate( sp
);
174 mf
.setRotate ( rotation
);
175 mg
.setTranslate( translation
);
177 t
->editMatrix().multLeft(ma
);
178 t
->editMatrix().multLeft(mb
);
179 t
->editMatrix().multLeft(mc
);
180 t
->editMatrix().multLeft(md
);
181 t
->editMatrix().multLeft(me
);
182 t
->editMatrix().multLeft(mf
);
183 t
->editMatrix().multLeft(mg
);