void AddLightToSceneCommand::execute(void) { //Make the Light Beacon node _CreatedLightBeaconNode = makeCoredNode<Transform>(); setName(_CreatedLightBeaconNode, _LightType.getName() + "_Beacon_Node"); //Make the Light node LightRecPtr NewLight = dynamic_pointer_cast<Light>(_LightType.createContainer()); NewLight->setBeacon(_CreatedLightBeaconNode); setName(NewLight, _LightType.getName() + "_NodeCore"); _CreatedLightNode = Node::create(); setName(_CreatedLightNode, _LightType.getName() + "_Node"); _CreatedLightNode->setCore(NewLight); //Get the Root node NodeRecPtr RootNode = _RootScene->getPrimaryViewport()->getRoot(); //Move all of the child nodes on the root onto children of the light node while(RootNode->getNChildren() != 0) { _CreatedLightNode->addChild(RootNode->getChild(0)); } _CreatedLightNode->addChild(_CreatedLightBeaconNode); //Add the Light node to the root RootNode->addChild(_CreatedLightNode); dynamic_cast<ApplicationBuilder*>(MainApplication::the()->getBuilderMode())->getMainWindow()->getSceneComponentTree()->getTreeModel()->lightAdded(dynamic_cast<Light*>(_CreatedLightNode->getCore())); _HasBeenDone = true; }
NodeTransitPtr OctreeVisualization::createNodeGeo(OctreePtr, const Octree::OTNodePtr node, Material* GeoMaterial, const Node* BaseGeo) { //Make the Geoemtry NodeRecPtr box = deepCloneTree(BaseGeo); dynamic_cast<Geometry*>(box->getCore())->setMaterial(GeoMaterial); Matrix m; TransformRecPtr box_trans; NodeRecPtr trans_node = makeCoredNode<Transform>(&box_trans); Pnt3f Center; node->getVolume().getCenter(Center); m.setTranslate( Center.x(), Center.y(), Center.z()); const Real32 Offset(0.0f); Vec3f Size; node->getVolume().getSize(Size); m.setScale(Size.x()-(Size.x()*Offset), Size.y()-(Size.y()*Offset), Size.z()-(Size.z()*Offset)); box_trans->setMatrix(m); trans_node->addChild(box); return NodeTransitPtr(trans_node); }
Vec2f VRIntersect_computeTexel(VRIntersection& ins, NodeRecPtr node) { if (!ins.hit) return Vec2f(0,0); if (node == 0) return Vec2f(0,0); GeometryRefPtr geo = dynamic_cast<Geometry*>( node->getCore() ); if (geo == 0) return Vec2f(0,0); auto texcoords = geo->getTexCoords(); if (texcoords == 0) return Vec2f(0,0); TriangleIterator iter = geo->beginTriangles(); iter.seek( ins.triangle ); Matrix m = node->getToWorld(); m.invert(); Pnt3f local_pnt; m.mult(ins.point, local_pnt); Pnt3f p0 = iter.getPosition(0); Pnt3f p1 = iter.getPosition(1); Pnt3f p2 = iter.getPosition(2); Vec3f cr = (p1 - p0).cross(p2 - p0); Vec3f n = cr; n.normalize(); float areaABC = n.dot(cr); float areaPBC = n.dot((p1 - local_pnt).cross(p2 - local_pnt)); float areaPCA = n.dot((p2 - local_pnt).cross(p0 - local_pnt)); float a = areaPBC / areaABC; float b = areaPCA / areaABC; float c = 1.0f - a - b; return iter.getTexCoords(0) * a + iter.getTexCoords(1) * b + iter.getTexCoords(2) * c; }
void AddLightToSceneCommand::undo(void) { Inherited::undo(); dynamic_cast<ApplicationBuilder*>(MainApplication::the()->getBuilderMode())->getMainWindow()->getSceneComponentTree()->getTreeModel()->lightWillBeRemoved(dynamic_cast<Light*>(_CreatedLightNode->getCore())); //Get the Root node NodeRecPtr RootNode = _RootScene->getPrimaryViewport()->getRoot(); //Move all of the child nodes on the root onto children of the light node while(_CreatedLightNode->getNChildren() != 0) { RootNode->addChild(_CreatedLightNode->getChild(0)); } //Add the Light node to the root RootNode->subChild(_CreatedLightBeaconNode); dynamic_cast<ApplicationBuilder*>(MainApplication::the()->getBuilderMode())->getMainWindow()->getSceneComponentTree()->getTreeModel()->lightRemoved(dynamic_cast<Light*>(_CreatedLightNode->getCore())); }
NodeTransitPtr createTorus(void) { // Make Object Nodes NodeRecPtr ExampleTorusGeo = makeTorus(90, 270, 16, 16); // Preform transformations on them Matrix mat; // On Torus mat.setTranslate(0.0,100.0,-200.0); TransformRecPtr TorusTranCore = Transform::create(); TorusTranCore->setMatrix(mat); NodeRecPtr ExampleTorus = Node::create(); ExampleTorus->setCore(TorusTranCore); ExampleTorus->addChild(ExampleTorusGeo); ExampleTorus->setTravMask(0); return NodeTransitPtr(ExampleTorus); }
void ColladaNode::handleInstanceLight(domInstance_light *instLight) { ColladaInstanceLightRefPtr colInstLight = getUserDataAs<ColladaInstanceLight>(instLight); if(colInstLight == NULL) { colInstLight = dynamic_pointer_cast<ColladaInstanceLight>( ColladaElementFactory::the()->create(instLight, getGlobal())); colInstLight->read(); } //push the Light onto the root LightUnrecPtr light = colInstLight->process(this); if(light != NULL) { //Append the lights beacon node GroupUnrecPtr lightBeacon = Group::create(); NodeRecPtr lightBeaconN = Node::create(); lightBeaconN->setCore(lightBeacon); /*std::string BeaconNodeName(instLight->getName()); BeaconNodeName += "_beacon"; setName(lightBeaconN, BeaconNodeName);*/ //TODO: set beacon name appendChild(lightBeaconN); light->setBeacon(lightBeaconN); NodeRecPtr lightN = Node::create(); lightN->setCore(light); //setName(lightN,instLight->getName()); //TODO: set light name _visualScene->pushNodeToRoot(lightN); } }
VRCamera::VRCamera(string name) : VRTransform(name) { parallaxD = 2; nearClipPlaneCoeff = 0.1; //farClipPlaneCoeff = 250000; farClipPlaneCoeff = 250; cam_invert_z = true; cam = PerspectiveCamera::create(); cam->setBeacon(getNode()); cam->setFov(osgDegree2Rad(60)); cam->setNear(parallaxD* nearClipPlaneCoeff); cam->setFar(parallaxD* farClipPlaneCoeff); type = "Camera"; doAcceptRoot = true; camGeo = 0; TransformRecPtr trans = Transform::create(); NodeRecPtr t = makeNodeFor(trans); trans->editMatrix().setTranslate(Vec3f(0,0,0.25)); GeometryRecPtr camGeo_ = makeBoxGeo(0.2, 0.2, 0.25, 1, 1, 1); GeometryRecPtr camGeo2_ = makeCylinderGeo(0.2, 0.07, 16, 1, 1, 1); camGeo = makeNodeFor(camGeo_); NodeRecPtr camGeo2 = makeNodeFor(camGeo2_); camGeo->setTravMask(0); camGeo_->setMaterial(getCamGeoMat()->getMaterial()); camGeo2_->setMaterial(getCamGeoMat()->getMaterial()); addChild(t); t->addChild(camGeo); TransformRecPtr trans2 = Transform::create(); NodeRecPtr t2 = makeNodeFor(trans2); trans2->editMatrix().setTranslate(Vec3f(0,0,-0.15)); trans2->editMatrix().setRotate(Quaternion(Vec3f(1,0,0), Pi*0.5)); camGeo->addChild(t2); t2->addChild(camGeo2); getAll().push_back(this); VRGuiManager::broadcast("camera_added"); }
NodeTransitPtr OctreeVisualization::createNodeDistanceLOD(OctreePtr, const Octree::OTNodePtr node, Material* GeoMaterial, const Node* BaseGeo, Real32 Range ) { NodeRecPtr box = deepCloneTree(BaseGeo); dynamic_cast<Geometry*>(box->getCore())->setMaterial(GeoMaterial); //DistanceLOD node DistanceLODRecPtr LOD = DistanceLOD::create(); LOD->editMFRange()->push_back(10.0); NodeRecPtr LODNode = makeNodeFor(LOD); LODNode->addChild(box); LODNode->addChild(makeCoredNode<Group>()); Matrix m; TransformRecPtr box_trans; NodeRecPtr trans_node = makeCoredNode<Transform>(&box_trans); Pnt3f Center; node->getVolume().getCenter(Center); m.setTranslate(Center.x(), Center.y(), Center.z()); const Real32 Offset(0.0f); Vec3f Size; node->getVolume().getSize(Size); m.setScale(Size.x()-(Size.x()*Offset), Size.y()-(Size.y()*Offset), Size.z()-(Size.z()*Offset)); box_trans->setMatrix(m); trans_node->addChild(LODNode); return NodeTransitPtr(trans_node); }
OpenSGEnvironmentSceneGraphAttachment::~OpenSGEnvironmentSceneGraphAttachment() { if (envGroupeNode->getNChildren() > 0) { printd(ERROR, "OpenSGEnvironmentSceneGraphAttachment::destructor(): Environment Group-Node still has children attached! FORCING REMOVE!\n"); for (int i=envGroupeNode->getNChildren()-1; i >= 0 ; i--) { #if OSG_MAJOR_VERSION >= 2 envGroupeNode->subChild(i); #else //OpenSG1: beginEditCP(envGroupeNode); envGroupeNode->subChild(i); endEditCP(envGroupeNode); #endif } // for } // if #if OSG_MAJOR_VERSION >= 2 if (envTransNode->getParent() != NULL) { printd(ERROR, "OpenSGEnvironmentSceneGraphAttachment::destructor(): Environment Transformation Node still in SceneGraph! FORCING REMOVE!\n"); NodeRecPtr parentNode = envTransNode->getParent(); parentNode->subChild(envTransNode); } // if #else //OpenSG1: if (envTransNode->getParent() != NullFC) { printd(ERROR, "OpenSGEnvironmentSceneGraphAttachment::destructor(): Environment Transformation Node still in SceneGraph! FORCING REMOVE!\n"); NodePtr parentNode = envTransNode->getParent(); beginEditCP(parentNode); parentNode->subChild(envTransNode); endEditCP(parentNode); } // if subRefCP(envTransNode); #endif } // ~OpenSGEnvironmentSceneGraphAttachment
////////////////////////////////////////////////////////////////////////// //! build a box ////////////////////////////////////////////////////////////////////////// void buildBox(Node* const spaceGroupNode, PhysicsWorld* const physicsWorld, PhysicsHashSpace* const physicsSpace) { Vec3f Lengths((Real32)(rand()%2)+1.0, (Real32)(rand()%2)+1.0, (Real32)(rand()%2)+1.0); Matrix m; //create OpenSG mesh GeometryRecPtr box; NodeRecPtr boxNode = makeBox(Lengths.x(), Lengths.y(), Lengths.z(), 1, 1, 1); box = dynamic_cast<Geometry*>(boxNode->getCore()); SimpleMaterialRecPtr box_mat = SimpleMaterial::create(); box_mat->setAmbient(Color3f(0.0,0.0,0.0)); box_mat->setDiffuse(Color3f(0.0,1.0 ,0.0)); box->setMaterial(box_mat); TransformRecPtr boxTrans; NodeRecPtr boxTransNode = makeCoredNode<Transform>(&boxTrans); m.setIdentity(); Real32 randX = (Real32)(rand()%10)-5.0; Real32 randY = (Real32)(rand()%10)-5.0; m.setTranslate(randX, randY, 10.0); boxTrans->setMatrix(m); //create ODE data PhysicsBodyRecPtr boxBody = PhysicsBody::create(physicsWorld); boxBody->setPosition(Vec3f(randX, randY, 10.0)); boxBody->setBoxMass(1.0, Lengths.x(), Lengths.y(), Lengths.z()); //std::cout << "mass: " << boxBody->getMass() << std::endl //<< "massCenterOfGravity: " << boxBody->getMassCenterOfGravity().x() << ", " << boxBody->getMassCenterOfGravity().y() << ", " << boxBody->getMassCenterOfGravity().z() << std::endl //<< "massInertiaTensor: " << std::endl //<< boxBody->getMassInertiaTensor()[0][0] << " "<< boxBody->getMassInertiaTensor()[0][1] << " "<< boxBody->getMassInertiaTensor()[0][2] << " " << boxBody->getMassInertiaTensor()[0][3] << std::endl //<< boxBody->getMassInertiaTensor()[1][0] << " "<< boxBody->getMassInertiaTensor()[1][1] << " "<< boxBody->getMassInertiaTensor()[1][2] << " " << boxBody->getMassInertiaTensor()[1][3] << std::endl //<< boxBody->getMassInertiaTensor()[2][0] << " "<< boxBody->getMassInertiaTensor()[2][1] << " "<< boxBody->getMassInertiaTensor()[2][2] << " " << boxBody->getMassInertiaTensor()[2][3] << std::endl //<< boxBody->getMassInertiaTensor()[3][0] << " "<< boxBody->getMassInertiaTensor()[3][1] << " "<< boxBody->getMassInertiaTensor()[3][2] << " " << boxBody->getMassInertiaTensor()[3][3] << std::endl //<< std::endl; PhysicsBoxGeomRecPtr boxGeom = PhysicsBoxGeom::create(); boxGeom->setBody(boxBody); boxGeom->setSpace(physicsSpace); boxGeom->setLengths(Lengths); //add attachments boxNode->addAttachment(boxGeom); boxTransNode->addAttachment(boxBody); boxTransNode->addChild(boxNode); //add to SceneGraph spaceGroupNode->addChild(boxTransNode); commitChanges(); }
////////////////////////////////////////////////////////////////////////// //! trimesh defined by filenode will be loaded ////////////////////////////////////////////////////////////////////////// void buildTriMesh(Node* const TriGeometryBase, Node* const spaceGroupNode, PhysicsWorld* const physicsWorld, PhysicsHashSpace* const physicsSpace) { NodeRecPtr tri = cloneTree(TriGeometryBase); if(tri!=NULL) { GeometryRecPtr triGeo = dynamic_cast<Geometry*>(tri->getCore()); Matrix m; SimpleMaterialRecPtr tri_mat = SimpleMaterial::create(); tri_mat->setAmbient(Color3f(0.1,0.1,0.2)); tri_mat->setDiffuse(Color3f(1.0,0.1,0.7)); triGeo->setMaterial(tri_mat); TransformRecPtr triTrans; NodeRecPtr triTransNode = makeCoredNode<Transform>(&triTrans); m.setIdentity(); Real32 randX = (Real32)(rand()%10)-5.0; Real32 randY = (Real32)(rand()%10)-5.0; m.setTranslate(randX, randY, 18.0); triTrans->setMatrix(m); //create ODE data Vec3f GeometryBounds(calcMinGeometryBounds(triGeo)); PhysicsBodyRecPtr triBody = PhysicsBody::create(physicsWorld); triBody->setPosition(Vec3f(randX, randY, 18.0)); triBody->setLinearDamping(0.0001); triBody->setAngularDamping(0.0001); triBody->setBoxMass(1.0,GeometryBounds.x(), GeometryBounds.y(), GeometryBounds.z()); PhysicsGeomRecPtr triGeom; if(true) { triGeom = PhysicsTriMeshGeom::create(); triGeom->setBody(triBody); //add geom to space for collision triGeom->setSpace(physicsSpace); //set the geometryNode to fill the ode-triMesh NodeRecPtr TorusGeometryNode(makeTorus(0.55, 1.05, 6, 6)); dynamic_pointer_cast<PhysicsTriMeshGeom>(triGeom)->setGeometryNode(TorusGeometryNode); } //add attachments tri->addAttachment(triGeom); triTransNode->addAttachment(triBody); //add to SceneGraph triTransNode->addChild(tri); spaceGroupNode->addChild(triTransNode); } else { SLOG << "Could not read MeshData!" << endLog; } commitChanges(); }
////////////////////////////////////////////////////////////////////////// //! build a sphere ////////////////////////////////////////////////////////////////////////// void buildSphere(Node* const spaceGroupNode, PhysicsWorld* const physicsWorld, PhysicsHashSpace* const physicsSpace) { Real32 Radius((Real32)(rand()%2)*0.5+0.5); Matrix m; //create OpenSG mesh GeometryRecPtr sphere; NodeRecPtr sphereNode = makeSphere(2, Radius); sphere = dynamic_cast<Geometry*>(sphereNode->getCore()); SimpleMaterialRecPtr sphere_mat = SimpleMaterial::create(); sphere_mat->setAmbient(Color3f(0.0,0.0,0.0)); sphere_mat->setDiffuse(Color3f(0.0,0.0,1.0)); sphere->setMaterial(sphere_mat); TransformRecPtr sphereTrans; NodeRecPtr sphereTransNode = makeCoredNode<Transform>(&sphereTrans); m.setIdentity(); Real32 randX = (Real32)(rand()%10)-5.0; Real32 randY = (Real32)(rand()%10)-5.0; m.setTranslate(randX, randY, 10.0); sphereTrans->setMatrix(m); //create ODE data PhysicsBodyRecPtr sphereBody = PhysicsBody::create(physicsWorld); sphereBody->setPosition(Vec3f(randX, randY, 10.0)); sphereBody->setAngularDamping(0.0001); sphereBody->setSphereMass(1.0,Radius); PhysicsSphereGeomRecPtr sphereGeom = PhysicsSphereGeom::create(); sphereGeom->setBody(sphereBody); sphereGeom->setSpace(physicsSpace); sphereGeom->setRadius(Radius); //add attachments sphereNode->addAttachment(sphereGeom); sphereTransNode->addAttachment(sphereBody); sphereTransNode->addChild(sphereNode); //add to SceneGraph spaceGroupNode->addChild(sphereTransNode); commitChanges(); }
NodeTransitPtr createBox(void) { // Make Object Nodes NodeRecPtr ExampleBoxGeo = makeBox(100, 100, 100, 1, 1, 1); MaterialRecPtr GreenMaterial = createMaterial(Color4f(0.0f,1.0f,0.0f,1.0f)); dynamic_cast<Geometry*>(ExampleBoxGeo->getCore())->setMaterial(GreenMaterial); Matrix mat; mat.setTranslate(250.0,250.0,0.0); TransformRecPtr ExampleBoxTranCore = Transform::create(); ExampleBoxTranCore->setMatrix(mat); NodeRecPtr ExampleBox = Node::create(); ExampleBox->setCore(ExampleBoxTranCore); ExampleBox->addChild(ExampleBoxGeo); ExampleBox->setTravMask(0); return NodeTransitPtr(ExampleBox); }
NodeTransitPtr createSphere(void) { // Make Object Nodes NodeRecPtr ExampleSphereGeo = makeSphere(4, 100); MaterialRecPtr RedMaterial = createMaterial(Color4f(1.0f,0.0f,0.0f,1.0f)); dynamic_cast<Geometry*>(ExampleSphereGeo->getCore())->setMaterial(RedMaterial); Matrix mat; mat.setTranslate(250.0,0.0,0.0); TransformRecPtr SphereTranCore = Transform::create(); SphereTranCore->setMatrix(mat); NodeRecPtr ExampleSphere = Node::create(); ExampleSphere->setCore(SphereTranCore); ExampleSphere->addChild(ExampleSphereGeo); ExampleSphere->setTravMask(0); return NodeTransitPtr(ExampleSphere); }
NodeTransitPtr createCone(void) { // Make Object Nodes NodeRecPtr ExampleConeGeo = makeCone(150, 50, 16, true, true); MaterialRecPtr BlueMaterial = createMaterial(Color4f(0.0f,0.0f,1.0f,1.0f)); dynamic_cast<Geometry*>(ExampleConeGeo->getCore())->setMaterial(BlueMaterial); // Preform transformations on them Matrix mat; // On Cone mat.setTranslate(0.0,0.0,-250.0); TransformRecPtr ConeTranCore = Transform::create(); ConeTranCore->setMatrix(mat); NodeRecPtr ExampleCone = Node::create(); ExampleCone->setCore(ConeTranCore); ExampleCone->addChild(ExampleConeGeo); ExampleCone->setTravMask(0); return NodeTransitPtr(ExampleCone); }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create a Spinner Model. This dictates how the Spinner functions. -setMaximum(int): Determine the Maximum value the Spinner can have. -setMinimum(int): Determine the Minimum value the Spinner can have. -setStepSize(int): Determine the incremental step size. -setValue(SharedFieldRecPtr(new SFInt32(int)): Determine initial starting value of the Spinner. Note: the StepSize can be changed dynamically as done in this Tutorial with ButtonSelectedListeners. ******************************************************/ //Int32SpinnerModelPtr TheModel(new Int32SpinnerModel()); Int32SpinnerModelPtr TheModel(new Int32SpinnerModel()); TheModel->setMaximum(100); TheModel->setMinimum(-100); TheModel->setStepSize(1); TheModel->setValue(boost::any(Int32(0))); /****************************************************** Create a Spinner and and assign it a Model. ******************************************************/ SpinnerRecPtr ExampleSpinner = Spinner::create(); ExampleSpinner->setModel(TheModel); /****************************************************** Create a RadioButtonPanel to allow for certain characteristics of the Spinner to be changed dynamically. See 14RadioButton for more information about RadioButtons. ******************************************************/ RadioButtonRecPtr SingleIncrementButton = RadioButton::create(); RadioButtonRecPtr DoubleIncrementButton = RadioButton::create(); SingleIncrementButton->setText("Increment by 1"); SingleIncrementButton->setPreferredSize(Vec2f(100, 50)); SingleIncrementButton->connectButtonSelected(boost::bind(handleSingleIncbuttonSelected, _1, TheModel)); DoubleIncrementButton->setText("Increment by 2"); DoubleIncrementButton->setPreferredSize(Vec2f(100, 50)); DoubleIncrementButton->connectButtonSelected(boost::bind(handleDoubleIncbuttonSelected, _1, TheModel)); RadioButtonGroupRecPtr SelectionRadioButtonGroup = RadioButtonGroup::create(); SelectionRadioButtonGroup->addButton(SingleIncrementButton); SelectionRadioButtonGroup->addButton(DoubleIncrementButton); SingleIncrementButton->setSelected(true); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(SingleIncrementButton); MainInternalWindow->pushToChildren(DoubleIncrementButton); MainInternalWindow->pushToChildren(ExampleSpinner); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "29Spinner"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create BorderLayout and some BorderLayoutConstraints to be used to set up CardLayout. ******************************************************/ BorderLayoutRecPtr MainInternalWindowLayout = BorderLayout::create(); BorderLayoutConstraintsRecPtr ExampleButton1Constraints = BorderLayoutConstraints::create(); BorderLayoutConstraintsRecPtr ExampleButton2Constraints = BorderLayoutConstraints::create(); BorderLayoutConstraintsRecPtr ExampleButton7Constraints = BorderLayoutConstraints::create(); BorderLayoutConstraintsRecPtr ExampleButton8Constraints = BorderLayoutConstraints::create(); BorderLayoutConstraintsRecPtr ExampleCardPanelConstraints = BorderLayoutConstraints::create(); ExampleButton1Constraints->setRegion(BorderLayoutConstraints::BORDER_EAST); ExampleButton2Constraints->setRegion(BorderLayoutConstraints::BORDER_WEST); ExampleButton7Constraints->setRegion(BorderLayoutConstraints::BORDER_NORTH); ExampleButton8Constraints->setRegion(BorderLayoutConstraints::BORDER_SOUTH); ExampleCardPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER); /****************************************************** Create CardLayout. CardLayout shows a single Component at a time, meaning it is not exactly practical to use it alone for a Layout. This tutorial uses the BorderLayout to include a Panel in the Center Region, and within that Panel using a CardLayout. A single card is displayed at one time within a ComponentContainer using CardLayout. CardLayout has four functions: next, previous, first, and last. ->next(CardContainerName): Causes CardLayout to display the next card. ->previous(CardContainerName): Causes CardLayout to display the previous card. ->first(CardContainerName): Causes CardLayout to display the first card. ->last(CardContainerName): Causes CardLayout to display the last card. These are most useful when combined with Action, as shown at the top of this Tutorial, to assign actions to the Buttons or Components to allow the user to cycle through the Card Layout and view different ExampleCards. Note that CardContainerName is the name of the ComponentContainer which is using the CardLayout, while the begin/endEditCP is performed on the CardLayout itself. ******************************************************/ CardLayoutRecPtr ExampleCardLayout = CardLayout::create(); PanelRecPtr ExampleCardPanel = Panel::create(); /****************************************************** Create Button Components to be used with CardLayout to allow for interactivity. ******************************************************/ ButtonRecPtr ExampleButton1 = Button::create(); ButtonRecPtr ExampleButton2 = Button::create(); ButtonRecPtr ExampleButton3 = Button::create(); ButtonRecPtr ExampleButton4 = Button::create(); ButtonRecPtr ExampleButton5 = Button::create(); ButtonRecPtr ExampleButton6 = Button::create(); ButtonRecPtr ExampleButton7 = Button::create(); ButtonRecPtr ExampleButton8 = Button::create(); ExampleButton1->setText("Next Card"); ExampleButton1->setConstraints(ExampleButton1Constraints); // Add Action ExampleButton1->connectActionPerformed(boost::bind(handleNextCardAction, _1, ExampleCardLayout.get(), ExampleCardPanel.get())); ExampleButton2->setText("Previous Card"); ExampleButton2->setConstraints(ExampleButton2Constraints); // Add Action ExampleButton2->connectActionPerformed(boost::bind(handleBackCardAction, _1, ExampleCardLayout.get(), ExampleCardPanel.get())); ExampleButton3->setText("This"); ExampleButton4->setText("is"); ExampleButton5->setText("Card"); ExampleButton6->setText("Layout"); ExampleButton7->setText("First Card"); ExampleButton7->setConstraints(ExampleButton7Constraints); // Add Action ExampleButton7->connectActionPerformed(boost::bind(handleFirstCardAction, _1, ExampleCardLayout.get(), ExampleCardPanel.get())); ExampleButton8->setText("Last Card"); ExampleButton8->setConstraints(ExampleButton8Constraints); // Add Action ExampleButton8->connectActionPerformed(boost::bind(handleLastCardAction, _1, ExampleCardLayout.get(), ExampleCardPanel.get())); ExampleCardPanel->setLayout(ExampleCardLayout); ExampleCardPanel->pushToChildren(ExampleButton3); ExampleCardPanel->pushToChildren(ExampleButton4); ExampleCardPanel->pushToChildren(ExampleButton5); ExampleCardPanel->pushToChildren(ExampleButton6); ExampleCardPanel->setConstraints(ExampleCardPanelConstraints); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleButton1); MainInternalWindow->pushToChildren(ExampleButton2); MainInternalWindow->pushToChildren(ExampleButton7); MainInternalWindow->pushToChildren(ExampleButton8); MainInternalWindow->pushToChildren(ExampleCardPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "11CardLayout"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); // Create a simple Font to be used with the PasswordField UIFontRecPtr ExampleFont = UIFont::create(); ExampleFont->setSize(16); /****************************************************** Create and edit a PasswordField. A PasswordField is a TextField which allows for text to be entered secretly. -setEchoCar("char"): Determine which character replaces text in the PasswordField. See 16TextField for more information. ******************************************************/ TextFieldRecPtr ExampleTextField = TextField::create(); ExampleTextField->setText(""); ExampleTextField->setEmptyDescText("username"); ExampleTextField->setPreferredSize(Vec2f(130.0f,ExampleTextField->getPreferredSize().y())); PasswordFieldRecPtr ExamplePasswordField = PasswordField::create(); ExamplePasswordField->setPreferredSize(Vec2f(130, ExamplePasswordField->getPreferredSize().y())); ExamplePasswordField->setTextColor(Color4f(0.0, 0.0, 0.0, 1.0)); ExamplePasswordField->setSelectionBoxColor(Color4f(0.0, 0.0, 1.0, 1.0)); ExamplePasswordField->setSelectionTextColor(Color4f(1.0, 1.0, 1.0, 1.0)); //ExamplePasswordField->setText("Text"); // "Text" will be replaced by "####" in the PasswordField ExamplePasswordField->setEchoChar("#"); ExamplePasswordField->setEditable(true); ExamplePasswordField->setFont(ExampleFont); ExamplePasswordField->setSelectionStart(2); ExamplePasswordField->setSelectionEnd(3); ExamplePasswordField->setAlignment(Vec2f(0.0,0.5)); ExamplePasswordField->setEmptyDescText("password"); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); FlowLayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); MainInternalWindowLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleTextField); MainInternalWindow->pushToChildren(ExamplePasswordField); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "24PasswordField"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create an Button Component and a simple Font. See 17Label_Font for more information about Fonts. ******************************************************/ ButtonRecPtr ExampleButton = Button::create(); UIFontRecPtr ExampleFont = UIFont::create(); ExampleFont->setSize(16); ExampleButton->setMinSize(Vec2f(50, 25)); ExampleButton->setMaxSize(Vec2f(200, 100)); ExampleButton->setPreferredSize(Vec2f(100, 50)); ExampleButton->setToolTipText("Button 1 ToolTip"); ExampleButton->setText("Button 1"); ExampleButton->setFont(ExampleFont); ExampleButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0)); ExampleButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setAlignment(Vec2f(1.0,0.0)); /****************************************************** Create a ToggleButton and determine its characteristics. ToggleButton inherits off of Button, so all characteristsics used above can be used with ToggleButtons as well. The only difference is that when pressed, ToggleButton remains pressed until pressed again. -setSelected(bool): Determine whether the ToggleButton is Selected (true) or deselected (false). ******************************************************/ ToggleButtonRecPtr ExampleToggleButton = ToggleButton::create(); ExampleToggleButton->setSelected(false); ExampleToggleButton->setText("ToggleMe"); ExampleToggleButton->setToolTipText("Toggle Button ToolTip"); // Create Background to be used with the MainInternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); // Create The Internal Window InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); // Assign the Button to the MainInternalWindow so it will be displayed // when the view is rendered. MainInternalWindow->pushToChildren(ExampleButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setPosition(Pnt2f(50,50)); MainInternalWindow->setPreferredSize(Vec2f(300,300)); MainInternalWindow->setTitle(std::string("Internal Window 1")); // Create The Internal Window InternalWindowRecPtr MainInternalWindow2 = InternalWindow::create(); LayoutRecPtr MainInternalWindowLayout2 = FlowLayout::create(); // Assign the Button to the MainInternalWindow so it will be displayed // when the view is rendered. MainInternalWindow2->pushToChildren(ExampleToggleButton); MainInternalWindow2->setLayout(MainInternalWindowLayout2); MainInternalWindow2->setBackgrounds(MainInternalWindowBackground); MainInternalWindow2->setPosition(Pnt2f(150,150)); MainInternalWindow2->setPreferredSize(Vec2f(300,300)); MainInternalWindow2->setTitle(std::string("Allways on top window")); MainInternalWindow2->setIconable(false); MainInternalWindow2->setAllwaysOnTop(true); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); TutorialDrawingSurface->openWindow(MainInternalWindow2); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "37InternalWindow"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManagerRefPtr sceneManager = SimpleSceneManager::create(); TutorialWindow->setDisplayCallback(boost::bind(display, sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, sceneManager)); // Tell the Manager what to manage sceneManager->setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create Components to add to MenuBar Menus. Each MenuBar has multiple Menus which contain multiple MenuItems. -setAcceleratorKey(KeyEventDetails::KEY_*): This links the key "*" as a shortcut to selecting the item it is attached to. An example of this would be Q with Control+Q causing programs to quit. -setAcceleratorModifiers(KeyEventDetails::KEY_MODIFIER_*): This adds the "*" key as another requirement to cause the item to be selected. Things such as "CONTROL" are likely to be used here (as mentioned above, both Control and Q are specified). Note: These shortcuts will be shown in the list with the MenuItem they are attached to. -setMnemonicKey(KeyEventDetails::KEY_****): sets the key "****" to be underlined within the Menu itself ******************************************************/ // Creates MenuItems as in 25PopupMenu MenuItemRecPtr NewMenuItem = MenuItem::create(); MenuItemRecPtr OpenMenuItem = MenuItem::create(); MenuItemRecPtr CloseMenuItem = MenuItem::create(); MenuItemRecPtr ExitMenuItem = MenuItem::create(); MenuItemRecPtr UndoMenuItem = MenuItem::create(); MenuItemRecPtr RedoMenuItem = MenuItem::create(); //Edits MenuItems NewMenuItem->setText("New ..."); NewMenuItem->setAcceleratorKey(KeyEventDetails::KEY_N); NewMenuItem->setAcceleratorModifiers(KeyEventDetails::KEY_MODIFIER_COMMAND); NewMenuItem->setMnemonicKey(KeyEventDetails::KEY_N); OpenMenuItem->setText("Open ..."); OpenMenuItem->setAcceleratorKey(KeyEventDetails::KEY_P); OpenMenuItem->setAcceleratorModifiers(KeyEventDetails::KEY_MODIFIER_COMMAND); OpenMenuItem->setMnemonicKey(KeyEventDetails::KEY_P); CloseMenuItem->setText("Close ..."); CloseMenuItem->setAcceleratorKey(KeyEventDetails::KEY_W); CloseMenuItem->setAcceleratorModifiers(KeyEventDetails::KEY_MODIFIER_COMMAND); CloseMenuItem->setMnemonicKey(KeyEventDetails::KEY_C); ExitMenuItem->setText("Quit"); ExitMenuItem->setAcceleratorKey(KeyEventDetails::KEY_Q); ExitMenuItem->setAcceleratorModifiers(KeyEventDetails::KEY_MODIFIER_COMMAND); ExitMenuItem->setMnemonicKey(KeyEventDetails::KEY_Q); UndoMenuItem->setText("Undo"); UndoMenuItem->setAcceleratorKey(KeyEventDetails::KEY_Z); UndoMenuItem->setAcceleratorModifiers(KeyEventDetails::KEY_MODIFIER_COMMAND); UndoMenuItem->setMnemonicKey(KeyEventDetails::KEY_U); RedoMenuItem->setText("Redo"); RedoMenuItem->setEnabled(false); RedoMenuItem->setMnemonicKey(KeyEventDetails::KEY_R); // Create a function connection to ExitMenuItem // This is defined above, and will cause the program to quit // when that MenuItem is selected or Control + Q hit ExitMenuItem->connectActionPerformed(boost::bind(handleQuitAction, _1, TutorialWindow.get())); /****************************************************** Create Menu Components to add to MenuBar and adds above Components to them. Note: setAcceleratorKey, setAcceleratorModifiers, and setMnemnoicKey all apply to Menus in addition to MenuItems. ******************************************************/ // Create a File menu and adds its MenuItems MenuRecPtr FileMenu = Menu::create(); FileMenu->addItem(NewMenuItem); FileMenu->addItem(OpenMenuItem); FileMenu->addItem(CloseMenuItem); FileMenu->addSeparator(); FileMenu->addItem(ExitMenuItem); // Labels the File Menu FileMenu->setText("File"); FileMenu->setMnemonicKey(KeyEventDetails::KEY_F); // Creates an Edit menu and adds its MenuItems MenuRecPtr EditMenu = Menu::create(); EditMenu->addItem(UndoMenuItem); EditMenu->addItem(RedoMenuItem); // Labels the Edit Menu EditMenu->setText("Edit"); EditMenu->setMnemonicKey(KeyEventDetails::KEY_E); /****************************************************** Create MainMenuBar and adds the Menus created above to it. Also creates several Backgrounds to improve MenuBar overall look. Both the MenuBar and Menu can have Backgrounds; the set up currently is to have EmptyBackgrounds in each Menu allowing a single overall MenuBar Background which is given to the MenuBar itself. This can be easily changed by adding different Backgrounds to the File and Edit Menus. Note: The MenuBar is added to the MainFrame below. ******************************************************/ // Creates two Backgrounds MenuBarRecPtr MainMenuBar = MenuBar::create(); // Adds the two Menus to the MainMenuBar MainMenuBar->addMenu(FileMenu); MainMenuBar->addMenu(EditMenu); // Create two Labels LabelRecPtr ExampleLabel1 = Label::create(); LabelRecPtr ExampleLabel2 = Label::create(); ExampleLabel1->setText("Look up in the corner!"); ExampleLabel1->setPreferredSize(Vec2f(150, 25)); ExampleLabel2->setText("Hit Control + Z"); ExampleLabel2->setPreferredSize(Vec2f(150, 25)); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow EmptyLayerRecPtr MainInternalWindowBackground = EmptyLayer::create(); EmptyBorderRecPtr MainInternalWindowBorder = EmptyBorder::create(); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleLabel1); MainInternalWindow->pushToChildren(ExampleLabel2); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setMenuBar(MainMenuBar); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setBorders(MainInternalWindowBorder); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(1.0f,1.0f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager->getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(sceneManager, TutorialWindow); // Show the whole Scene sceneManager->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "26MenuBar"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// Initialize OpenSG and set up the scene int main(int argc, char **argv) { //Set the number of aspects ThreadManager::setNumAspects(2); ChangeList::setReadWriteDefault(true); // OSG init osgInit(argc,argv); { // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->setUseCallbackForDraw(true); TutorialWindow->setUseCallbackForReshape(true); //Initialize Window TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); //Attach to events TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); //Torus Material MaterialRecPtr TheTorusMaterial = SimpleMaterial::create(); dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setAmbient(Color3f(0.2,0.2,0.2)); dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setDiffuse(Color3f(0.7,0.7,0.7)); dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setSpecular(Color3f(0.7,0.7,0.7)); dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setShininess(100.0f); //Torus Geometry GeometryRecPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32); TorusGeometry->setMaterial(TheTorusMaterial); NodeRecPtr TorusGeometryNode = Node::create(); TorusGeometryNode->setCore(TorusGeometry); //Make Torus Node NodeRecPtr TorusNode = Node::create(); TransformRecPtr TorusNodeTrans = Transform::create(); setName(TorusNodeTrans, std::string("TorusNodeTransformationCore")); TorusNode->setCore(TorusNodeTrans); TorusNode->addChild(TorusGeometryNode); //Make Main Scene Node NodeRecPtr scene = Node::create(); ComponentTransformRecPtr Trans = ComponentTransform::create(); setName(Trans, std::string("MainTransformationCore")); scene->setCore(Trans); scene->addChild(TorusNode); AnimationRecPtr TheAnimation = setupAnimation(TorusNodeTrans, TutorialWindow); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TheAnimation.get(), TutorialWindow.get())); TheAnimation->connectAnimationStarted(boost::bind(animationStarted, _1)); TheAnimation->connectAnimationStopped(boost::bind(animationStopped, _1)); TheAnimation->connectAnimationPaused(boost::bind(animationPaused, _1)); TheAnimation->connectAnimationUnpaused(boost::bind(animationUnpaused, _1)); TheAnimation->connectAnimationEnded(boost::bind(animationEnded, _1)); TheAnimation->connectAnimationCycled(boost::bind(animationCycled, _1)); commitChanges(); // tell the manager what to manage sceneManager.setRoot (scene); // show the whole scene sceneManager.showAll(); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "OpenSG 01Animation Window"); // store a pointer to the application thread ApplicationThread = dynamic_cast<OSG::Thread *>(OSG::ThreadManager::getAppThread()); //create the thread that will run generation of new matrices RenderThread = OSG::dynamic_pointer_cast<OSG::Thread>( OSG::ThreadManager::the()->getThread("render", true)); //Start the render thread on aspect 1 RenderThread->runFunction(draw, 1, static_cast<void *>(&sceneManager)); //Enter main Loop TutorialWindow->mainLoop(); //Stop the render thread RenderThread->terminate(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); // Create a simple Font to be used with the TextField UIFontRecPtr sampleFont = UIFont::create(); sampleFont->setSize(16); /****************************************************** Create and edit the TextField. A TextField is a Component which allows a single line of text to be displayed. Text can be entered via the keyboard, and selected with arrow keys or the Mouse. -setTextColor(Color4f): Determine the Text Color. setSelectionBoxColor(Color4f): Determine the Color of highlighting around selected Text. -setSelectionTextColor(Color4f): Determine the Color of selected Text. -setText("TextToBeDisplayed"): Determine initial Text within TextField. -setFont(FontName): Determine the Font used within TextField. -setSelectionStart(StartCharacterNumber): Determine the character with which the selection will initially start. -setSelectionEnd(EndCharacterNumber): Determine the character which the selection ends before. -setAlignment(float): Determine the alignment of the text. The float is a percentage is from the top of the text [0.0-1.0]. Note: be sure to visually verify this, as due to font size and line size this does not always place it exactly at the percentage point. ******************************************************/ // Create a TextField component TextFieldRecPtr ExampleTextField = TextField::create(); ExampleTextField->setPreferredSize(Vec2f(100, 50)); ExampleTextField->setTextColor(Color4f(0.0, 0.0, 0.0, 1.0)); ExampleTextField->setSelectionBoxColor(Color4f(0.0, 0.0, 1.0, 1.0)); ExampleTextField->setSelectionTextColor(Color4f(1.0, 1.0, 1.0, 1.0)); ExampleTextField->setText("What"); ExampleTextField->setFont(sampleFont); // The next two functions will select the "a" from above ExampleTextField->setSelectionStart(2); ExampleTextField->setSelectionEnd(3); ExampleTextField->setAlignment(Vec2f(0.0,0.5)); // Create another TextField Component TextFieldRecPtr ExampleTextField2 = TextField::create(); ExampleTextField2->setText(""); ExampleTextField2->setEmptyDescText("Write in me, please"); ExampleTextField2->setPreferredSize(Vec2f(200.0f,ExampleTextField2->getPreferredSize().y())); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleTextField); MainInternalWindow->pushToChildren(ExampleTextField2); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "16TextField"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManagerRefPtr sceneManager = SimpleSceneManager::create(); TutorialWindow->setDisplayCallback(boost::bind(display, sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, sceneManager)); // Tell the Manager what to manage sceneManager->setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Creates RadioButton components and edit them. The RadioButton class inherits from the Button class. Radio Buttons are special ToggleButtons. When they are selected, any RadioButton in the same group is deselected, so there can only be one option selected. Advanced options for RadioButton can be found in the DefaultLookAndFeel.cpp file found in OSGUserInterface/Source Files/ LookAndFeel (options for changing the RadioButton style, etc). ******************************************************/ RadioButtonRecPtr ExampleRadioButton1 = RadioButton::create(); RadioButtonRecPtr ExampleRadioButton2 = RadioButton::create(); RadioButtonRecPtr ExampleRadioButton3 = RadioButton::create(); ExampleRadioButton1->setAlignment(Vec2f(0.0,0.5)); ExampleRadioButton1->setPreferredSize(Vec2f(100, 50)); ExampleRadioButton1->setText("Option 1"); ExampleRadioButton2->setAlignment(Vec2f(0.0,0.5)); ExampleRadioButton2->setPreferredSize(Vec2f(100, 50)); ExampleRadioButton2->setText("Option 2"); ExampleRadioButton3->setAlignment(Vec2f(0.0,0.5)); ExampleRadioButton3->setPreferredSize(Vec2f(100, 50)); ExampleRadioButton3->setText("Option 3"); /*************************************************** Create and populate a group of RadioButtons. Defining the group allows you to pick which RadioButtons are tied together so that only one can be selected. Each RadioButtonGroup can only have ONE RadioButton selected at a time, and by selecting this RadioButton, will deselect all other RadioButtons in the RadioButtonGroup. ******************************************************/ RadioButtonGroupRecPtr ExampleRadioButtonGroup = RadioButtonGroup::create(); ExampleRadioButtonGroup->addButton(ExampleRadioButton1); ExampleRadioButtonGroup->addButton(ExampleRadioButton2); ExampleRadioButtonGroup->addButton(ExampleRadioButton3); ExampleRadioButtonGroup->setSelectedButton(ExampleRadioButton2); FlowLayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); MainInternalWindowLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION); MainInternalWindowLayout->setMajorAxisAlignment(0.5f); MainInternalWindowLayout->setMinorAxisAlignment(0.5f); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleRadioButton1); MainInternalWindow->pushToChildren(ExampleRadioButton2); MainInternalWindow->pushToChildren(ExampleRadioButton3); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager->getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(sceneManager, TutorialWindow); // Show the whole Scene sceneManager->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "14RadioButton"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
OSG_USING_NAMESPACE void renderSceneToTexture(Scene* const TheScene, TextureObjChunk* const ColorTexture, Window* const TheWindow, RenderAction* TheRenderAction) { //Create an FBO to render the Scene's Viewport(s) into FrameBufferObjectRecPtr SceneFBO = FrameBufferObject::create(); TextureBufferRecPtr FBOTextureBuffer = TextureBuffer ::create(); RenderBufferRecPtr FBODepthBuffer = RenderBuffer ::create(); //Attache the Texture to the TexureBuffer FBOTextureBuffer->setTexture(ColorTexture); // add a depth attachment, otherwise there is no depth buffer when // rendering to the FBO FBODepthBuffer->setInternalFormat(GL_DEPTH_COMPONENT24); // make the fbo render to the texture SceneFBO->setColorAttachment(FBOTextureBuffer, 0); SceneFBO->setDepthAttachment(FBODepthBuffer ); SceneFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT); SceneFBO->setWidth (FBOTextureBuffer->getTexture()->getImage()->getWidth() ); SceneFBO->setHeight(FBOTextureBuffer->getTexture()->getImage()->getHeight()); /* Next we set up a Stage, which renders the subtree below it to its render target (the FBO from above). */ SimpleStageRefPtr SceneStage = SimpleStage::create(); NodeRefPtr SceneStageNode = makeNodeFor(SceneStage); ViewportRecPtr SceneViewport(TheScene->getPrimaryViewport()); SceneStage->setRenderTarget(SceneFBO); SceneStage->setLeft(SceneViewport->getLeft()); SceneStage->setRight(SceneViewport->getRight()); SceneStage->setTop(SceneViewport->getTop()); SceneStage->setBottom(SceneViewport->getBottom()); SceneStage->setCamera(SceneViewport->getCamera()); SceneStage->setBackground(SceneViewport->getBackground()); for(UInt32 i(0) ; i<SceneViewport->getMFForegrounds()->size() ; ++i) { SceneStage->pushToForegrounds(SceneViewport->getForegrounds(i)); } SceneStageNode->addChild(SceneViewport->getRoot()); NodeRecPtr ThumbRootNode = makeCoredNode<Group>(); ThumbRootNode->addChild(SceneStageNode); CameraRecPtr ThumbCamera = MatrixCamera::create(); ThumbCamera->setBeacon(ThumbRootNode); BackgroundRecPtr ThumbBackground = PassiveBackground::create(); //Create a dummy Viewport for attaching to the window ViewportRecPtr ThumbViewport = Viewport::create(); ThumbViewport->setBackground(ThumbBackground); ThumbViewport->setRoot(ThumbRootNode); ThumbViewport->setCamera(ThumbCamera); //Get all of the original TravMasks of the Viewports on the window //Set all of the TravMasks of the Viewports on the window to 0 std::vector<UInt32> OrigTravMasks; OrigTravMasks.reserve(TheWindow->getMFPort()->size()); for(UInt32 i(0) ; i<TheWindow->getMFPort()->size() ; ++i) { OrigTravMasks.push_back(TheWindow->getPort(i)->getTravMask()); TheWindow->getPort(i)->setTravMask(0); } //Attach the Viewport to the Window TheWindow->addPort(ThumbViewport); //Draw the window TheWindow->render(TheRenderAction); //Detach the Viewport from the Window TheWindow->subPortByObj(ThumbViewport); //Reset all of the original TravMasks of the Viewports on the window for(UInt32 i(0) ; i<TheWindow->getMFPort()->size() ; ++i) { TheWindow->getPort(i)->setTravMask(OrigTravMasks[i]); } }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create and edit a CheckboxButton. Note: the only function call shown specific to CheckboxButton is setSelected. In DefaultLookAndFeel, the options for changing the style of the CheckBox are shown. CheckboxButton also inherits off Button so all features of Button may be used. -setSelected(bool): Determines if the CheckboxButton is checked(true) or not checked(false). ******************************************************/ CheckboxButtonRecPtr ExampleCheckboxButton = CheckboxButton::create(); ExampleCheckboxButton->setMinSize(Vec2f(50, 25)); ExampleCheckboxButton->setMaxSize(Vec2f(300, 100)); ExampleCheckboxButton->setPreferredSize(Vec2f(200, 50)); ExampleCheckboxButton->setEnabled(true); ExampleCheckboxButton->setText("Checkbox Button"); ExampleCheckboxButton->setAlignment(Vec2f(0.5,0.5)); ExampleCheckboxButton->setSelected(true); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleCheckboxButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "13CheckboxButton"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the rootNode int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); //Attach to events TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); TutorialWindow->connectKeyReleased(boost::bind(keyReleased, _1)); //Make Main Scene Node NodeRefPtr scene = makeCoredNode<Group>(); setName(scene, "scene"); NodeRecPtr rootNode = Node::create(); setName(rootNode, "rootNode"); ComponentTransformRefPtr Trans = ComponentTransform::create(); rootNode->setCore(Trans); rootNode->addChild(scene); //Light Beacon Matrix LightTransformMat; LightTransformMat.setTranslate(Vec3f(50.0,0.0,100.0)); TransformRefPtr LightTransform = Transform::create(); LightTransform->setMatrix(LightTransformMat); NodeRefPtr TutorialLightBeacon = Node::create(); TutorialLightBeacon->setCore(LightTransform); //Light Node PointLightRefPtr TutorialLight = PointLight::create(); TutorialLight->setBeacon(TutorialLightBeacon); NodeRefPtr TutorialLightNode = Node::create(); TutorialLightNode->setCore(TutorialLight); scene->addChild(TutorialLightNode); scene->addChild(TutorialLightBeacon); //Setup Physics Scene PhysicsWorldRecPtr physicsWorld = PhysicsWorld::create(); physicsWorld->setWorldContactSurfaceLayer(0.005); physicsWorld->setAutoDisableFlag(1); physicsWorld->setAutoDisableTime(0.75); physicsWorld->setWorldContactMaxCorrectingVel(100.0); physicsWorld->setGravity(Vec3f(0.0, 0.0, -9.81)); PhysicsHashSpaceRecPtr physicsSpace = PhysicsHashSpace::create(); //Setup the default collision parameters CollisionContactParametersRefPtr DefaultCollisionParams = CollisionContactParameters::createEmpty(); DefaultCollisionParams->setMode(dContactApprox1); DefaultCollisionParams->setMu(1.0); DefaultCollisionParams->setMu2(0.0); DefaultCollisionParams->setBounce(0.0); DefaultCollisionParams->setBounceSpeedThreshold(0.0); DefaultCollisionParams->setSoftCFM(0.1); DefaultCollisionParams->setSoftERP(0.2); DefaultCollisionParams->setMotion1(0.0); DefaultCollisionParams->setMotion2(0.0); DefaultCollisionParams->setMotionN(0.0); DefaultCollisionParams->setSlip1(0.0); DefaultCollisionParams->setSlip2(0.0); physicsSpace->setDefaultCollisionParameters(DefaultCollisionParams); PhysicsHandlerRecPtr physHandler = PhysicsHandler::create(); physHandler->setWorld(physicsWorld); physHandler->pushToSpaces(physicsSpace); physHandler->setUpdateNode(rootNode); physHandler->attachUpdateProducer(TutorialWindow); rootNode->addAttachment(physHandler); rootNode->addAttachment(physicsWorld); rootNode->addAttachment(physicsSpace); /************************************************************************/ /* create spaces, geoms and bodys */ /************************************************************************/ //create a group for our space GroupRefPtr spaceGroup; NodeRecPtr spaceGroupNode = makeCoredNode<Group>(&spaceGroup); //create the ground terrain GeometryRefPtr TerrainGeo = buildTerrain(Vec2f(400.0,400.0),25,25); //and its Material SimpleMaterialRefPtr TerrainMat = SimpleMaterial::create(); TerrainMat->setAmbient(Color3f(0.3,0.5,0.3)); TerrainMat->setDiffuse(Color3f(0.5,0.9,0.5)); TerrainGeo->setMaterial(TerrainMat); NodeRefPtr TerrainNode = Node::create(); TerrainNode->setCore(TerrainGeo); //create ODE data PhysicsGeomRefPtr TerrainODEGeom = PhysicsTriMeshGeom::create(); //add geom to space for collision TerrainODEGeom->setSpace(physicsSpace); //set the geometryNode to fill the ode-triMesh dynamic_pointer_cast<PhysicsTriMeshGeom>(TerrainODEGeom)->setGeometryNode(TerrainNode); //add attachments //add Attachments to nodes... spaceGroupNode->addAttachment(physicsSpace); spaceGroupNode->addChild(TerrainNode); TerrainNode->addAttachment(TerrainODEGeom); TutorialLightNode->addChild(spaceGroupNode); //Create Character PhysicsBodyRefPtr CharacterPhysicsBody = buildCharacter(Vec3f(5.0,5.0,10.0), Pnt3f((Real32)(rand()%100)-50.0,(Real32)(rand()%100)-50.0,25.0), spaceGroupNode, physicsWorld, physicsSpace); PhysicsLMotorJointRefPtr CharacterMover = buildMover(CharacterPhysicsBody); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, spaceGroupNode.get(), physicsWorld.get(), physicsSpace.get())); TutorialWindow->connectUpdate(boost::bind(handleUpdate, _1, CharacterPhysicsBody.get(), CharacterMover.get())); // tell the manager what to manage sceneManager.setRoot (rootNode); // show the whole rootNode sceneManager.showAll(); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "03CharacterTerrain"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Creates some Button components and edit their Text. ******************************************************/ ButtonRecPtr ExampleButton1 = Button::create(); ButtonRecPtr ExampleButton2 = Button::create(); ButtonRecPtr ExampleButton3 = Button::create(); ButtonRecPtr ExampleButton4 = Button::create(); ButtonRecPtr ExampleButton5 = Button::create(); ButtonRecPtr ExampleButton6 = Button::create(); ExampleButton1->setText("This"); ExampleButton2->setText("is a"); ExampleButton3->setText("sample"); ExampleButton4->setText("two"); ExampleButton5->setText("ExamplePanel"); ExampleButton6->setText("layout"); /****************************************************** Create some Flow and BoxLayouts to be used with the Main Frame and two Panels. ******************************************************/ FlowLayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); FlowLayoutRecPtr ExamplePanel1Layout = FlowLayout::create(); FlowLayoutRecPtr ExamplePanel2Layout = FlowLayout::create(); ExamplePanel1Layout->setOrientation(FlowLayout::VERTICAL_ORIENTATION); /****************************************************** Create two Backgrounds to be used with Panels and MainInternalWindow. ******************************************************/ ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); ColorLayerRecPtr ExamplePanelBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); ExamplePanelBackground->setColor(Color4f(0.0,0.0,0.0,1.0)); /****************************************************** Create a Border to be used with the two Panels. ******************************************************/ LineBorderRecPtr ExamplePanelBorder = LineBorder::create(); ExamplePanelBorder->setColor(Color4f(0.9, 0.9, 0.9, 1.0)); ExamplePanelBorder->setWidth(3); /****************************************************** Create MainInternalWindow and two Panel Components and edit their characteristics. -setPreferredSize(Vec2f): Determine the size of the Panel. -pushToChildren(ComponentName): Adds a Component to the ComponentContainer as a Child (meaning it will be displayed within it). -setLayout(LayoutName): Determines the Layout of the ComponentContainer. ******************************************************/ InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); PanelRecPtr ExamplePanel1 = Panel::create(); PanelRecPtr ExamplePanel2 = Panel::create(); // Edit Panel1, Panel2 ExamplePanel1->setPreferredSize(Vec2f(200, 200)); ExamplePanel1->pushToChildren(ExampleButton1); ExamplePanel1->pushToChildren(ExampleButton2); ExamplePanel1->pushToChildren(ExampleButton3); ExamplePanel1->setLayout(ExamplePanel1Layout); ExamplePanel1->setBackgrounds(ExamplePanelBackground); ExamplePanel1->setBorders(ExamplePanelBorder); ExamplePanel2->setPreferredSize(Vec2f(200, 200)); ExamplePanel2->pushToChildren(ExampleButton4); ExamplePanel2->pushToChildren(ExampleButton5); ExamplePanel2->pushToChildren(ExampleButton6); ExamplePanel2->setLayout(ExamplePanel2Layout); ExamplePanel2->setBackgrounds(ExamplePanelBackground); ExamplePanel2->setBorders(ExamplePanelBorder); // Create The Main InternalWindow MainInternalWindow->pushToChildren(ExamplePanel1); MainInternalWindow->pushToChildren(ExamplePanel2); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); MainInternalWindow->setAllInsets(5); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "10Container"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
OSG_BEGIN_NAMESPACE NodeTransitPtr OctreeVisualization::createOctreeVisualization(OctreePtr tree, Int32 MaxDepth, bool filledGeometry, bool onlyLeaf) { OTNodeGeometryCreateFunc GeoCreateFunc; OTNodeMaterialCreateFunc MatCreateFunc; OTNodeIsVisibleFunc IsVisibleFunc; IsVisibleFunc = boost::bind(&OctreeVisualization::isNodeLeaf,_1, _2, false); NodeRecPtr VisRootNode = makeCoredNode<Group>(); if(filledGeometry) { NodeRecPtr BaseBox = makeBox(1.0f,1.0f,1.0f, 1, 1, 1); GeoCreateFunc = boost::bind(&OctreeVisualization::createNodeDistanceLOD,_1, _2, _3, BaseBox.get(), 10.0f); BlendChunkRecPtr DefaultBlendChunk = BlendChunk::create(); DefaultBlendChunk->setSrcFactor(GL_SRC_ALPHA); DefaultBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); PolygonChunkRecPtr DefaultPolygonChunk = PolygonChunk::create(); DefaultPolygonChunk->setCullFace(GL_BACK); MatCreateFunc = boost::bind(&OctreeVisualization::createMatFilled,_1, _2, Color3f(0.0f,1.0f,0.0f), Color3f(1.0f,0.0f,0.0f), 0.15f, DefaultBlendChunk.get(), DefaultPolygonChunk.get()); createOctreeVisualizationRec(tree, tree->getRoot(), VisRootNode, osgMin<UInt32>(tree->getDepth(),MaxDepth), GeoCreateFunc, MatCreateFunc, IsVisibleFunc); } else { //*******************Create the Geometry for the box GeoUInt8PropertyRecPtr type = GeoUInt8Property::create(); //Volume bound box type->push_back(GL_LINE_STRIP); type->push_back(GL_LINES); GeoUInt32PropertyRefPtr lens = GeoUInt32Property::create(); //Volume bound box lens->push_back(10); lens->push_back(6); GeoUInt32PropertyRefPtr index = GeoUInt32Property::create(); //Volume bound box index->push_back(0); index->push_back(1); index->push_back(3); index->push_back(2); index->push_back(0); index->push_back(4); index->push_back(5); index->push_back(7); index->push_back(6); index->push_back(4); index->push_back(1); index->push_back(5); index->push_back(2); index->push_back(6); index->push_back(3); index->push_back(7); GeoPnt3fPropertyRefPtr highlightPoints = GeoPnt3fProperty::create(); //Volume bound box highlightPoints->push_back(Pnt3f(-1, -1, -1)); highlightPoints->push_back(Pnt3f( 1, -1, -1)); highlightPoints->push_back(Pnt3f(-1, 1, -1)); highlightPoints->push_back(Pnt3f( 1, 1, -1)); highlightPoints->push_back(Pnt3f(-1, -1, 1)); highlightPoints->push_back(Pnt3f( 1, -1, 1)); highlightPoints->push_back(Pnt3f(-1, 1, 1)); highlightPoints->push_back(Pnt3f( 1, 1, 1)); //Colors Color4f BoundBoxColor(1.0f,1.0f,1.0,1.00f); GeoVec4fPropertyRefPtr highlightColors = GeoVec4fProperty::create(); //Volume bound box highlightColors->push_back(BoundBoxColor); highlightColors->push_back(BoundBoxColor); highlightColors->push_back(BoundBoxColor); highlightColors->push_back(BoundBoxColor); highlightColors->push_back(BoundBoxColor); highlightColors->push_back(BoundBoxColor); highlightColors->push_back(BoundBoxColor); highlightColors->push_back(BoundBoxColor); GeometryRecPtr BoxGeo =Geometry::create(); BoxGeo->setTypes (type); BoxGeo->setLengths (lens); BoxGeo->setIndices (index); BoxGeo->setPositions (highlightPoints); BoxGeo->setColors (highlightColors); //Highlight Bound Box Node NodeRecPtr BaseBox = makeNodeFor(BoxGeo); GeoCreateFunc = boost::bind(&OctreeVisualization::createNodeDistanceLOD,_1, _2, _3, BaseBox.get(), 10.0f); //*******************Create the Geometry for the highlight BlendChunkRecPtr DefaultBlendChunk = BlendChunk::create(); DefaultBlendChunk->setSrcFactor(GL_SRC_ALPHA); DefaultBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); LineChunkRecPtr DefaultLineChunk = LineChunk::create(); DefaultLineChunk->setSmooth(true); MatCreateFunc = boost::bind(&OctreeVisualization::createMatLine,_1, _2, Color3f(1.0f,0.0f,0.0f), Color3f(0.0f,0.0f,1.0f), 0.55f, DefaultBlendChunk.get(), DefaultLineChunk.get()); createOctreeVisualizationRec(tree, tree->getRoot(), VisRootNode, osgMin<UInt32>(tree->getDepth(),MaxDepth), GeoCreateFunc, MatCreateFunc, IsVisibleFunc); } return NodeTransitPtr(VisRootNode); }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create a RotatedComponent. -setAngle(Angle, in radians): Determine the angle the Component initially is rotated. -setInternalComponent(Component): Determine what Component will be rotated. -setResizePolicy(RotatedComponent::ENUM): Takes NO_RESIZING, RESIZE_TO_MIN, or RESIZE_TO_MAX arguments. ******************************************************/ RotatedComponentRecPtr TheRotatedComponent = RotatedComponent::create(); // Define PI Real32 PI(3.14159); TheRotatedComponent->setAngle(PI/4); ComponentRecPtr InnerPanel = createPanel(); TheRotatedComponent->setInternalComponent(InnerPanel); TheRotatedComponent->setResizePolicy(RotatedComponent::RESIZE_TO_MIN); /****************************************************** Create a ToggleButton which can be used to start and stop the Button from rotating. Note: due to the way FlowLayout works you will notice that this ToggleButton will move as well. In cases where a Rotating Component is used, an alternate Layout may be preferred to prevent other Components from moving as well. This is intentionally left this way to illustrate why this might be the case. A SplitPanel with fixed divider for example would prevent the ToggleButton from moving, while still allowing the Panel to move freely. ******************************************************/ ToggleButtonRecPtr RotateControlButton = ToggleButton::create(); RotateControlButton->setText("Start Rotating"); RotateControlButton->setPreferredSize(Vec2f(100.0f, 29.0f)); RotateControlButton->connectButtonSelected(boost::bind(handleButtonSelected, _1, TutorialWindow.get(), TheRotatedComponent.get())); RotateControlButton->connectButtonDeselected(boost::bind(handleButtonDeselected, _1, TutorialWindow.get(), TheRotatedComponent.get())); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(TheRotatedComponent); MainInternalWindow->pushToChildren(RotateControlButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.8f,0.8f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "30RotatedComponent"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); //Create the nessicary parts for a viewport Matrix TransformMatrix; TransformMatrix.setTranslate(0.0f,0.0f, 0.0f); TransformRecPtr CameraBeaconTransform = Transform::create(); CameraBeaconTransform->setMatrix(TransformMatrix); NodeRecPtr CameraBeaconNode = Node::create(); CameraBeaconNode->setCore(CameraBeaconTransform); // Make Torus Node (creates Torus in background of scene) NodeRecPtr GeometryNode = makeTorus(.5, 2, 32, 32); //Make a light Node NodeRecPtr LightBeaconNode = makeCoredNode<Transform>(); DirectionalLightRecPtr SceneLight = DirectionalLight::create(); SceneLight->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f)); SceneLight->setDiffuse(Color4f(0.8f,0.8f,0.8f,1.0f)); SceneLight->setSpecular(Color4f(1.0f,1.0f,1.0f,1.0f)); SceneLight->setOn(true); SceneLight->setBeacon(LightBeaconNode); NodeRecPtr LightNode = makeNodeFor(SceneLight); LightNode->addChild(GeometryNode); // Make Main Scene Node and add the Torus NodeRecPtr DefaultRootNode = Node::create(); DefaultRootNode->setCore(Group::create()); DefaultRootNode->addChild(LightNode); DefaultRootNode->addChild(LightBeaconNode); DefaultRootNode->addChild(CameraBeaconNode); //Camera PerspectiveCameraRecPtr DefaultCamera = PerspectiveCamera::create(); DefaultCamera->setBeacon(CameraBeaconNode); DefaultCamera->setFov (osgDegree2Rad(60.f)); DefaultCamera->setNear (0.1f); DefaultCamera->setFar (100.f); //Background GradientBackgroundRecPtr DefaultBackground = GradientBackground::create(); DefaultBackground->addLine(Color3f(0.0f,0.0f,0.0f), 0.0f); DefaultBackground->addLine(Color3f(0.0f,0.0f,1.0f), 1.0f); //Viewport ViewportRecPtr DefaultViewport = Viewport::create(); DefaultViewport->setCamera (DefaultCamera); DefaultViewport->setRoot (DefaultRootNode); DefaultViewport->setSize (0.0f,0.0f, 1.0f,1.0f); DefaultViewport->setBackground (DefaultBackground); //GL Viewport Component LineBorderRecPtr TheGLViewportBorder = LineBorder::create(); TheGLViewportBorder->setColor(Color4f(1.0,0.0,0.0,1.0)); TheGLViewportBorder->setWidth(3.0); GLViewportRecPtr TheGLViewport = GLViewport::create(); TheGLViewport->setPort(DefaultViewport); TheGLViewport->setPreferredSize(Vec2f(400.0f,400.0f)); TheGLViewport->setBorders(TheGLViewportBorder); TheGLViewport->lookAt(Pnt3f(0.0f,0.0f,10.0f), //From Pnt3f(0.0f,0.0f,0.0f), //At Vec3f(0.0f,1.0f,0.0f)); //Up ButtonRecPtr ExampleButton = Button::create(); ExampleButton->setText("Example"); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); MainInternalWindow->pushToChildren(TheGLViewport); MainInternalWindow->pushToChildren(ExampleButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.95f,0.95f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "41GLViewportComponent"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }