4 #include "OSGGLUTWindow.h"
5 #include "OSGSimpleSceneManager.h"
7 #include "OSGSimpleMaterial.h"
8 #include "OSGTransform.h"
9 #include "OSGSimpleGeometry.h"
10 #include "OSGBaseFunctions.h"
11 #include "OSGSceneFileHandler.h"
12 #include "OSGTypedGeoIntegralProperty.h"
14 #include "OSGManipulatorManager.h"
17 OSG::NodeRefPtr scene
= NULL
;
18 OSG::TransformRefPtr interTC
= NULL
;
19 OSG::NodeRefPtr interN
= NULL
;
20 OSG::NodeRefPtr maniN
= NULL
;
22 OSG::ManipulatorManager
*mama
;
23 OSG::SimpleSceneManagerRefPtr mgr
;
25 int setupGLUT( int *argc
, char *argv
[] );
26 OSG::NodeTransitPtr
makeCoordAxes(void);
28 int main(int argc
, char **argv
)
30 OSG::osgInit(argc
,argv
);
31 int winid
= setupGLUT(&argc
, argv
);
33 OSG::GLUTWindowUnrecPtr gwin
= OSG::GLUTWindow::create();
34 gwin
->setGlutId(winid
);
37 mgr
= OSG::SimpleSceneManager::create();
38 mama
= new OSG::ManipulatorManager
;
40 OSG::GroupUnrecPtr g
= OSG::Group::create();
41 scene
= OSG::Node::create();
43 OSG::TransformUnrecPtr offsetTC
= OSG::Transform::create();
44 OSG::NodeUnrecPtr offsetN
= OSG::Node::create();
48 m
.setTransform( OSG::Vec3f(2,1,0),
49 OSG::Quaternion(OSG::Vec3f(1,0,0), OSG::osgDegree2Rad(0)),
51 offsetTC
->setMatrix(m
);
52 offsetN
->setCore(offsetTC
);
54 interTC
= OSG::Transform::create();
55 interN
= OSG::Node::create();
58 m
.setTransform( OSG::Vec3f(1.0f
, 1.0f
, 1.0f
) );
59 interTC
->setMatrix(m
);
61 interN
->setCore(interTC
);
62 interN
->addChild(OSG::makeBox(1, 0.2f
, 0.2f
, 1, 1, 1));
65 scene
->addChild(makeCoordAxes());
66 scene
->addChild(offsetN
);
67 offsetN
->addChild(interN
);
69 maniN
= mama
->createManipulator(OSG::ManipulatorManager::TRANSLATE
);
71 interN
->addChild(maniN
);
73 mgr
->setWindow(gwin
);
75 mgr
->setClickCenter( false );
78 mama
->setTarget( interN
);
79 mama
->setViewport( mgr
->getWindow()->getPort(0) );
83 glutReshapeWindow(600, 600);
96 void reshape(int w
, int h
)
103 void mouse(int button
, int state
, int x
, int y
)
107 if( mama
->isActive() )
109 mama
->mouseButtonRelease(button
, x
, y
);
112 mgr
->mouseButtonRelease(button
, x
, y
);
118 l
= mgr
->calcViewRay(x
, y
);
120 OSG::IntersectActionRefPtr act
= OSG::IntersectAction::create();
125 if ( (act
->didHit()) && (mama
->activate( act
->getHitObject()) ) )
127 mama
->mouseButtonPress(button
, x
, y
);
132 mgr
->mouseButtonPress(button
, x
, y
);
139 void motion(int x
, int y
)
141 if( mama
->isActive() )
143 mama
->mouseMove(x
, y
);
147 mgr
->mouseMove(x
, y
);
154 void keyboard(unsigned char k
, int x
, int y
)
169 maniN
->setTravMask(OSG::TypeTraits
<OSG::UInt32
>::getZeroElement());
179 maniN
->setTravMask(OSG::TypeTraits
<OSG::UInt32
>::getMax());
182 mama
->changeManipulator(OSG::ManipulatorManager::TRANSLATE
);
186 mama
->changeManipulator(OSG::ManipulatorManager::ROTATE
);
190 mama
->changeManipulator(OSG::ManipulatorManager::SCALE
);
194 mama
->changeManipulator(OSG::ManipulatorManager::PLANE
);
198 mama
->changeEnablePivot(! mama
->getCurrentEnablePivot());
204 OSG::SceneFileHandler::the()->write(scene
, "scene.osb");
210 int setupGLUT(int *argc
, char *argv
[])
212 glutInit(argc
, argv
);
213 glutInitDisplayMode(GLUT_RGB
| GLUT_DEPTH
| GLUT_DOUBLE
);
215 int winid
= glutCreateWindow("Manipulator Demo");
217 glutReshapeFunc(reshape
);
218 glutDisplayFunc(display
);
219 glutMouseFunc(mouse
);
220 glutMotionFunc(motion
);
221 glutKeyboardFunc(keyboard
);
226 OSG::GeometryTransitPtr
makeCoordAxesGeo(void)
228 OSG::GeometryTransitPtr axesG
= OSG::Geometry::create();
230 OSG::GeoUInt8PropertyUnrecPtr type
= OSG::GeoUInt8Property::create();
231 type
->addValue(GL_LINES
);
232 type
->addValue(GL_TRIANGLES
);
234 OSG::GeoUInt32PropertyUnrecPtr lens
= OSG::GeoUInt32Property::create();
238 OSG::GeoPnt3fPropertyUnrecPtr pnts
= OSG::GeoPnt3fProperty::create();
239 // the 6 points of the three Lines
240 pnts
->addValue(OSG::Pnt3f(0, 0, 0));
241 pnts
->addValue(OSG::Pnt3f(1, 0, 0));
243 pnts
->addValue(OSG::Pnt3f(0, 0, 0));
244 pnts
->addValue(OSG::Pnt3f(0, 1, 0));
246 pnts
->addValue(OSG::Pnt3f(0, 0, 0));
247 pnts
->addValue(OSG::Pnt3f(0, 0, 1));
249 // the 9 points of the three Triangles
250 pnts
->addValue(OSG::Pnt3f( 1, 0, 0));
251 pnts
->addValue(OSG::Pnt3f(0.8f
, 0.2f
, 0.2f
));
252 pnts
->addValue(OSG::Pnt3f(0.8f
, -0.2f
, -0.2f
));
254 pnts
->addValue(OSG::Pnt3f( 0, 1, 0));
255 pnts
->addValue(OSG::Pnt3f( 0.2f
, 0.8f
, 0.2f
));
256 pnts
->addValue(OSG::Pnt3f(-0.2f
, 0.8f
, -0.2f
));
258 pnts
->addValue(OSG::Pnt3f( 0, 0, 1));
259 pnts
->addValue(OSG::Pnt3f( 0.2f
, 0.2f
, 0.8f
));
260 pnts
->addValue(OSG::Pnt3f(-0.2f
, -0.2f
, 0.8f
));
262 OSG::GeoColor3fPropertyUnrecPtr colors
= OSG::GeoColor3fProperty::create();
263 colors
->addValue(OSG::Color3f(1, 0, 0));
264 colors
->addValue(OSG::Color3f(1, 0, 0));
266 colors
->addValue(OSG::Color3f(0, 1, 0));
267 colors
->addValue(OSG::Color3f(0, 1, 0));
269 colors
->addValue(OSG::Color3f(0, 0, 1));
270 colors
->addValue(OSG::Color3f(0, 0, 1));
272 colors
->addValue(OSG::Color3f(1, 0, 0));
273 colors
->addValue(OSG::Color3f(1, 0, 0));
274 colors
->addValue(OSG::Color3f(1, 0, 0));
276 colors
->addValue(OSG::Color3f(0, 1, 0));
277 colors
->addValue(OSG::Color3f(0, 1, 0));
278 colors
->addValue(OSG::Color3f(0, 1, 0));
280 colors
->addValue(OSG::Color3f(0, 0, 1));
281 colors
->addValue(OSG::Color3f(0, 0, 1));
282 colors
->addValue(OSG::Color3f(0, 0, 1));
284 axesG
->setTypes (type
);
285 axesG
->setLengths (lens
);
286 axesG
->setPositions(pnts
);
287 axesG
->setColors (colors
);
288 axesG
->setMaterial (OSG::getDefaultUnlitMaterial());
293 OSG::NodeTransitPtr
makeCoordAxes(void)
295 OSG::NodeTransitPtr axesN
= OSG::Node::create();
297 axesN
->setCore(makeCoordAxesGeo());