int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { TheLuaManager->init(); // 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); //Setup the Lua Manager BoostPath ModulePath("./Data/"); std::string PackagePath = std::string("?;") + (ModulePath / "?.lua" ).file_string() + ";" + (ModulePath / "?" / "init.lua").file_string(); TheLuaManager->setPackagePath(PackagePath); // Make Torus Node (creates Torus in background of scene) GeometryRefPtr TorusGeometry = makeTorusGeo(.5, 2, 16, 16); setName(TorusGeometry,"Torus Geometry"); //calcVertexTangents(TorusGeometry,0,Geometry::TexCoords7FieldId, Geometry::TexCoords6FieldId); NodeRefPtr TorusGeometryNode = Node::create(); setName(TorusGeometryNode,"Torus Geometry Node"); TorusGeometryNode->setCore(TorusGeometry); //Torus Transformation Node TransformRefPtr TheTorusNodeTransform = Transform::create(); NodeRefPtr TheTorusTransfromNode = Node::create(); TheTorusTransfromNode->setCore(TheTorusNodeTransform); TheTorusTransfromNode->addChild(TorusGeometryNode); setName(TheTorusTransfromNode,"Torus Transform Node"); // Make Main Scene Node and add the Torus NodeRefPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TheTorusTransfromNode); setName(scene,"Scene Node"); //Light Beacon Node TransformRefPtr TheLightBeaconNodeTransform = Transform::create(); NodeRefPtr TheLightBeaconNode = Node::create(); TheLightBeaconNode->setCore(TheLightBeaconNodeTransform); setName(TheLightBeaconNode,"Light Beacon Node"); //Light Node DirectionalLightRefPtr TheLightCore = DirectionalLight::create(); TheLightCore->setDirection(Vec3f(1.0,0.0,0.0)); TheLightCore->setAmbient(Color4f(1.0,1.0,1.0,1.0)); TheLightCore->setDiffuse(Color4f(1.0,1.0,1.0,1.0)); TheLightCore->setSpecular(Color4f(1.0,1.0,1.0,1.0)); TheLightCore->setBeacon(TheLightBeaconNode); NodeRefPtr TheLightNode = Node::create(); TheLightNode->setCore(TheLightCore); TheLightNode->addChild(scene); setName(TheLightNode,"Light Node"); NodeRefPtr RootNode = Node::create(); RootNode->setCore(Group::create()); RootNode->addChild(TheLightNode); RootNode->addChild(TheLightBeaconNode); setName(RootNode,"Root Node"); // Create the Graphics GraphicsRefPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); //Create the Main interface LuaDebuggerInterface TheLuaDebuggerInterface; // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRefPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); BorderLayoutRefPtr MainInternalWindowLayout = BorderLayout::create(); //Split Panel BorderLayoutConstraintsRefPtr SplitPanelConstraints = BorderLayoutConstraints::create(); SplitPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER); TheLuaDebuggerInterface.getMainSplitPanel()->setConstraints(SplitPanelConstraints); BorderLayoutConstraintsRefPtr ButtonPanelConstraints = BorderLayoutConstraints::create(); ButtonPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_NORTH); TheLuaDebuggerInterface.getButtonPanel()->setConstraints(ButtonPanelConstraints); BorderLayoutConstraintsRefPtr CodeAreaInfoPanelConstraints = BorderLayoutConstraints::create(); CodeAreaInfoPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_SOUTH); TheLuaDebuggerInterface.getCodeAreaInfoPanel()->setConstraints(CodeAreaInfoPanelConstraints); InternalWindowRefPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(TheLuaDebuggerInterface.getButtonPanel()); MainInternalWindow->pushToChildren(TheLuaDebuggerInterface.getMainSplitPanel()); MainInternalWindow->pushToChildren(TheLuaDebuggerInterface.getCodeAreaInfoPanel()); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setTitle("Lua Debugger"); setName(MainInternalWindow,"Internal Window"); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); //Scene Background GradientBackgroundRefPtr SceneBackground = GradientBackground::create(); SceneBackground->addLine(Color3f(0.0,0.0,0.0),0.0); setName(SceneBackground,"Scene Background"); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); sceneManager.setRoot(RootNode); //sceneManager.setHeadlight(false); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); TutorialViewport->setBackground(SceneBackground); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &TheLuaDebuggerInterface)); // 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, "03LuaDebugger"); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setPreferredSize(WinSize * 0.85); //Enter main Loop TutorialWindow->mainLoop(); TheLuaManager->uninit(); } 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 TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); TutorialUpdateListener TheTutorialUpdateListener; TutorialWindow->addUpdateListener(&TheTutorialUpdateListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); //Make Main Scene Node NodeRefPtr scene = makeCoredNode<Group>(); setName(scene, "scene"); rootNode = Node::create(); setName(rootNode, "rootNode"); ComponentTransformRefPtr Trans; Trans = ComponentTransform::create(); { rootNode->setCore(Trans); // add the torus as a child rootNode->addChild(scene); } //Make The Physics Characteristics Node PhysicsCharacteristicsDrawableUnrecPtr PhysDrawable = PhysicsCharacteristicsDrawable::create(); PhysDrawable->setRoot(rootNode); PhysDrawableNode = Node::create(); PhysDrawableNode->setCore(PhysDrawable); PhysDrawableNode->setTravMask(TypeTraits<UInt32>::getMin()); rootNode->addChild(PhysDrawableNode); //Light Beacon NodeRefPtr TutorialLightBeacon = makeCoredNode<Transform>(); //Light Node DirectionalLightRefPtr TutorialLight = DirectionalLight::create(); TutorialLight->setDirection(0.0,0.0,-1.0); TutorialLight->setBeacon(TutorialLightBeacon); NodeRefPtr TutorialLightNode = Node::create(); TutorialLightNode->setCore(TutorialLight); scene->addChild(TutorialLightNode); scene->addChild(TutorialLightBeacon); //Setup Physics Scene physicsWorld = PhysicsWorld::create(); physicsWorld->setWorldContactSurfaceLayer(0.01); physicsWorld->setAutoDisableFlag(1); physicsWorld->setAutoDisableTime(0.75); physicsWorld->setWorldContactMaxCorrectingVel(1.0); //physicsWorld->setGravity(Vec3f(0.0, 0.0, -9.81)); //physicsWorld->setCfm(0.001); //physicsWorld->setErp(0.2); hashSpace = PhysicsHashSpace::create(); physHandler = PhysicsHandler::create(); physHandler->setWorld(physicsWorld); physHandler->pushToSpaces(hashSpace); physHandler->setUpdateNode(rootNode); physHandler->attachUpdateProducer(TutorialWindow->editEventProducer()); rootNode->addAttachment(physHandler); rootNode->addAttachment(physicsWorld); rootNode->addAttachment(hashSpace); /************************************************************************/ /* create spaces, geoms and bodys */ /************************************************************************/ //create a group for our space GroupRefPtr spaceGroup; spaceGroupNode = makeCoredNode<Group>(&spaceGroup); //add Attachments to nodes... spaceGroupNode->addAttachment(hashSpace); TutorialLightNode->addChild(spaceGroupNode); //Create Character ShipBody = buildShip(Vec3f(3.0,3.0,10.0), Pnt3f((Real32)(rand()%100)-50.0,(Real32)(rand()%100)-50.0,25.0)); ShipMotor = buildMotor(ShipBody); for(UInt32 i(0) ; i<5 ; ++i) { buildBox(Vec3f(10.0,10.0,10.0), Pnt3f((Real32)(rand()%100)-50.0,(Real32)(rand()%100)-50.0,25.0)); } // tell the manager what to manage mgr->setRoot (rootNode); // show the whole rootNode mgr->showAll(); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "04ZeroGravityShip"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
void ApplicationStartScreen::attachApplication(void) { Inherited::attachApplication(); //Camera Transformation Node Matrix CameraTransformMatrix; CameraTransformMatrix.setTranslate(0.0f,0.0f, 5.0f); TransformRefPtr CameraBeaconTransform = Transform::create(); CameraBeaconTransform->setMatrix(CameraTransformMatrix); NodeRefPtr CameraBeaconNode = Node::create(); CameraBeaconNode->setCore(CameraBeaconTransform); // Make Torus Node (creates Torus in background of scene) NodeRefPtr TorusGeometryNode = NULL; //BoostPath TorusKnotFile(MainApplication::the()->getSettings()->getDataDirectory() / std::string("Models") / std::string("TorusKnot.osb")); //SLOG << "Loading Torus Knot from: " << TorusKnotFile.string() << std::endl; //if(boost::filesystem::exists(TorusKnotFile)) //{ //TorusGeometryNode = SceneFileHandler::the()->read(TorusKnotFile.native_file_string().c_str()); //} //if(TorusGeometryNode == NULL) //{ //SWARNING << "Could not load Torus Knot from: " //<< TorusKnotFile.string() << " because this file doesn't exist." << std::endl; TorusGeometryNode = makeTorus(.5, 2, 64, 64); //} //Scene Transformation TransformRefPtr SceneTransformCore = Transform::create(); NodeRefPtr SceneTransformNode = Node::create(); SceneTransformNode->setCore(SceneTransformCore); SceneTransformNode->addChild(TorusGeometryNode); //Light NodeRefPtr LightBeaconNode = Node::create(); LightBeaconNode->setCore(Transform::create()); DirectionalLightRefPtr SceneLightCore = DirectionalLight::create(); SceneLightCore->setDirection(1.0,0.0,0.0); SceneLightCore->setBeacon(LightBeaconNode); NodeRefPtr SceneLightNode = Node::create(); SceneLightNode->setCore(SceneLightCore); SceneLightNode->addChild(SceneTransformNode); // Make Main Scene Node and add the Torus NodeRefPtr DefaultRootNode = OSG::Node::create(); DefaultRootNode->setCore(OSG::Group::create()); DefaultRootNode->addChild(CameraBeaconNode); DefaultRootNode->addChild(SceneLightNode); DefaultRootNode->addChild(LightBeaconNode); //Camera PerspectiveCameraRefPtr DefaultCamera = PerspectiveCamera::create(); DefaultCamera->setBeacon(CameraBeaconNode); DefaultCamera->setFov (osgDegree2Rad(60.f)); DefaultCamera->setNear (0.1f); DefaultCamera->setFar (10000.f); //Background GradientBackgroundRefPtr DefaultBackground = GradientBackground::create(); DefaultBackground->addLine(Color3f(0.0f,0.0f,0.0f), 0.0f); DefaultBackground->addLine(Color3f(0.0f,0.0f,0.5f), 1.0f); //Animation //KeyFrames KeyframeTransformationSequenceRefPtr TransformationKeyframes = KeyframeTransformationSequenceMatrix4f::create(); OSG::Matrix TempMat; TransformationKeyframes->addKeyframe(TempMat,0.0f); TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*0.5)); TransformationKeyframes->addKeyframe(TempMat,4.0f); TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*1.0)); TransformationKeyframes->addKeyframe(TempMat,8.0f); TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*1.5)); TransformationKeyframes->addKeyframe(TempMat,12.0f); TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 0.0f)); TransformationKeyframes->addKeyframe(TempMat,16.0f); //Animator KeyframeAnimatorRefPtr TorusAnimator = OSG::KeyframeAnimator::create(); TorusAnimator->setKeyframeSequence(TransformationKeyframes); //Animation _TorusAnimation = FieldAnimation::create(); _TorusAnimation->setAnimator(TorusAnimator); _TorusAnimation->setInterpolationType(Animator::LINEAR_INTERPOLATION); _TorusAnimation->setCycling(-1); _TorusAnimation->setAnimatedField(SceneTransformCore, std::string("matrix")); _TorusAnimation->attachUpdateProducer(MainApplication::the()->getMainWindow()->editEventProducer()); _TorusAnimation->start(); //Foreground //ImageForegroundRefPtr LogoForeground = ImageForeground::create(); //BoostPath LogoPath(MainApplication::the()->getSettings()->getDataDirectory() / "Images/Logo.png"); //ImageRefPtr LoadedImage = ImageFileHandler::the().read(LogoPath.string().c_str()); // LogoForeground->addImage( LoadedImage, Pnt2f( 0,0 ) ); ForegroundRefPtr UserInterfaceForeground = createInterface(); _TheUIDrawingSurface->setEventProducer(MainApplication::the()->getMainWindow()); if(MainApplication::the()->getMainWindow() != NULL && MainApplication::the()->getMainWindow()->getMFPort()->size() == 0) { ViewportRefPtr DefaultViewport = Viewport::create(); DefaultViewport->setCamera (DefaultCamera); DefaultViewport->setRoot (DefaultRootNode); DefaultViewport->setSize (0.0f,0.0f, 1.0f,1.0f); DefaultViewport->setBackground (DefaultBackground); DefaultViewport->addForeground (UserInterfaceForeground); MainApplication::the()->getMainWindow()->addPort(DefaultViewport); } MainApplication::the()->getMainWindow()->addKeyListener(&_StartScreenKeyListener); MainApplication::the()->getMainWindow()->addUpdateListener(&_ScreenUpdateListener); }