void PlaneMoveManipulator::onCreate(const PlaneMoveManipulator* source) { // Skip direct parent, don't want the default geometry creation Transform::onCreate(source); SimpleMaterialUnrecPtr pMat = SimpleMaterial::create(); pMat->setDiffuse(Color3f(.5, .5, .5)); pMat->setLit (false ); setMaterialX(pMat); pMat = SimpleMaterial::create(); pMat->setDiffuse(Color3f(0, 1, 0)); pMat->setLit (false ); LineChunkUnrecPtr lc = LineChunk::create(); lc->setWidth(3); pMat->addChunk(lc); setMaterialY(pMat); pMat = SimpleMaterial::create(); pMat->setDiffuse(Color3f(0., 0., 1.)); pMat->setLit (true ); setMaterialZ(pMat); // SimpleMaterial *simpleMat; // Geometry *geo; setExternalUpdateHandler(NULL); // add a name attachment NameUnrecPtr nameN = Name::create(); nameN->editFieldPtr()->setValue("XYManipulator"); addAttachment(nameN); // make the axis line. Not really a handle, but easier to manage this way. GeoBuilder b; b.vertex(Pnt3f(0,0,0)); b.vertex(Pnt3f(0,getLength()[1],0)); b.line(0, 1); GeometryUnrecPtr g = b.getGeometry(); g->setMaterial(getMaterialY()); NodeUnrecPtr pNode = makeNodeFor(g); setTransYNode(pNode); // make the plane handle pNode = Node::create(); setTransXNode(pNode); g = makePlaneGeo(getLength()[0] / 2.f, getLength()[2] / 2.f, 1, 1); g->setMaterial(getMaterialX()); pNode = makeNodeFor(g); OSG::ComponentTransformUnrecPtr transHandleXC = ComponentTransform::create(); setHandleXNode(pNode); getTransXNode()->setCore (transHandleXC ); getTransXNode()->addChild(getHandleXNode()); transHandleXC->setTranslation(Vec3f(0, getLength()[1], 0)); transHandleXC->setRotation (Quaternion(Vec3f(1, 0, 0), osgDegree2Rad(90))); // // make the rotate handle pNode = Node::create(); setTransZNode(pNode); g = makeCylinderGeo(0.05f, 0.1f, 16, true, true, true); g->setMaterial(getMaterialZ()); pNode = makeNodeFor(g); OSG::ComponentTransformUnrecPtr transHandleZC = ComponentTransform::create(); setHandleZNode(pNode); getTransZNode()->setCore (transHandleZC ); getTransZNode()->addChild(getHandleZNode()); transHandleZC->setTranslation(Vec3f(0, getLength()[1], 0)); commitChanges(); }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // GLUT init int winid = setupGLUT(&argc, argv); // the connection between GLUT and OpenSG GLUTWindowPtr gwin= GLUTWindow::create(); gwin->setId(winid); gwin->init(); // create the scene /* Transformation accumulate through the graph, i.e. all nodes below a Transformation are influenced by it, even other Transformations. This can be used to create models of objects that move together and in relation to each other, the prime examples being a robot arm and a planetary system. This example does something not quite unlike a robot arm. */ // create the scene /* This time the graph is not wide, but deep, i.e. every Transformation only has two children, a Geometry and another transformation. The end resulting motion of the geometry is the accumulation of all the Transformations above it. */ // use a cylinder this time GeometryPtr cyl = makeCylinderGeo( 1, .3, 8, true, true, true ); // the single transformation Core used trans = Transform::create(); // setup an intial transformation Matrix m; m.setTransform(Vec3f(0, .9, 0)); beginEditCP(trans, Transform::MatrixFieldMask); { trans->setMatrix(m); } endEditCP (trans, Transform::MatrixFieldMask); /* NullFC is the generic NULL value for FieldContainer pointer. */ NodePtr last = NullFC; // create the copied transformations and their geometry nodes for(UInt16 i = 1; i < ncopies; ++i) { // create the shared Geometry NodePtr geonode = Node::create(); beginEditCP(geonode, Node::CoreFieldMask ); { geonode->setCore(cyl); } endEditCP (geonode, Node::CoreFieldMask ); // add a transformation to the Geometry NodePtr transnode = Node::create(); beginEditCP(transnode, Node::CoreFieldMask | Node::ChildrenFieldMask); { transnode->setCore (trans); transnode->addChild(geonode ); if(last != NullFC) transnode->addChild(last); } endEditCP (transnode, Node::CoreFieldMask | Node::ChildrenFieldMask); last = transnode; } NodePtr scene = last; // create the SimpleSceneManager helper mgr = new SimpleSceneManager; // tell the manager what to manage mgr->setWindow(gwin ); mgr->setRoot (scene); // show the whole scene mgr->showAll(); // GLUT main loop glutMainLoop(); return 0; }