Пример #1
0
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);

    // Make Torus Node (creates Torus in background of scene)
    NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

    // Make Main Scene Node and add the Torus
    NodeRefPtr scene = OSG::Node::create();
        scene->setCore(OSG::Group::create());
        scene->addChild(TorusGeometryNode);

    // Create the Graphics
    GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create();

    // Initialize the LookAndFeelManager to enable default settings
    LookAndFeelManager::the()->getLookAndFeel()->init();

    // Create a simple Font to be used with the TextField
    UIFontRefPtr sampleFont = OSG::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
    TextFieldRefPtr ExampleTextField = OSG::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
    TextFieldRefPtr ExampleTextField2 = OSG::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
    ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create();
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));

    LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();

    InternalWindowRefPtr MainInternalWindow = OSG::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
    UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create();
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindow);
	
	TutorialDrawingSurface->openWindow(MainInternalWindow);

    // Create the UI Foreground Object
    UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create();

        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);
    mgr->setRoot(scene);

    // Add the UI Foreground Object to the Scene
    ViewportRefPtr TutorialViewport = mgr->getWindow()->getPort(0);
        TutorialViewport->addForeground(TutorialUIForeground);

    // Show the whole Scene
    mgr->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
    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);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);

    //Particle System Material
    //point material
    PointChunkRefPtr PSPointChunk = PointChunk::create();
    PSPointChunk->setSize(5.0f);
    PSPointChunk->setSmooth(true);
    BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
    PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

    MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
    PSMaterialChunkChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
    PSMaterialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
    PSMaterialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
    PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);

    ChunkMaterialRefPtr PSPointMaterial = ChunkMaterial::create();
    PSPointMaterial->addChunk(PSPointChunk);
    PSPointMaterial->addChunk(PSMaterialChunkChunk);
    PSPointMaterial->addChunk(PSBlendChunk);

    //smoke material
    TextureObjChunkRefPtr QuadTextureObjChunk = TextureObjChunk::create();
    ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Checker.jpg");    
    QuadTextureObjChunk->setImage(LoadedImage);

    TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create();
    QuadTextureEnvChunk->setEnvMode(GL_MODULATE);

    MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
    PSMaterialChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
    PSMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
    PSMaterialChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
    PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);

    ChunkMaterialRefPtr PSSmokeMaterial = ChunkMaterial::create();
    PSSmokeMaterial->addChunk(QuadTextureObjChunk);
    PSSmokeMaterial->addChunk(PSMaterialChunk);
    PSSmokeMaterial->addChunk(PSMaterialChunk);
    PSSmokeMaterial->addChunk(QuadTextureEnvChunk);


    //Particle System
    //Rocket
    RocketParticleSystem = OSG::ParticleSystem::create();
    RocketParticleSystem->attachUpdateListener(TutorialWindow);

    TutorialRocketParticleSystemListener TheRocketListener;
    RocketParticleSystem->addParticleSystemListener(&TheRocketListener);

    //smoke
    SmokeParticleSystem = OSG::ParticleSystem::create();
    SmokeParticleSystem->attachUpdateListener(TutorialWindow);
    //Shrapnel
    ShrapnelParticleSystem = OSG::ParticleSystem::create();
    ShrapnelParticleSystem->attachUpdateListener(TutorialWindow);
    //Fireball
    FireballParticleSystem = OSG::ParticleSystem::create();
    FireballParticleSystem->attachUpdateListener(TutorialWindow);



    //Particle System Drawer
    //Rocket does not have a drawer because it is being attached to a special node core
    //Smoke
    SmokeParticleSystemDrawer = OSG::QuadParticleSystemDrawer::create();
    //SmokeParticleSystemDrawer->setQuadSizeScaling(Vec2f(0.5f,0.5f));
    //Shrapnel
    ExampleShrapnelParticleSystemDrawer = OSG::PointParticleSystemDrawer::create();
    ExampleShrapnelParticleSystemDrawer->setForcePerParticleSizing(true);
    //Fireball
    ExampleFireballParticleSystemDrawer = OSG::PointParticleSystemDrawer::create();
    ExampleFireballParticleSystemDrawer->setForcePerParticleSizing(true);



    //Particle System Node
    //collision node
    //NodeRefPtr EnvironmentNode = makeSphere(2,4.0f);

    Matrix EnvironmentTransformation;
    EnvironmentTransformation.setScale(0.1f);

    TransformRefPtr EnvironmentTransformCore = Transform::create();
    EnvironmentTransformCore->setMatrix(EnvironmentTransformation);

    NodeRefPtr EnvironmentNode = Node::create();
    EnvironmentNode->setCore(EnvironmentTransformCore);
    //EnvironmentNode->addChild(SceneFileHandler::the()->read("Data/Chloroplast.osb"));
    EnvironmentNode->addChild(SceneFileHandler::the()->read("Data/house.obj"));

    //NodeRefPtr ParticlePrototypeNode = makeTorus(1.0,4.0,16,16);
    NodeRefPtr RocketParticlePrototypeNode = SceneFileHandler::the()->read("Data/rocket.obj");
    if(RocketParticlePrototypeNode == NULL)
    {
        RocketParticlePrototypeNode = makeTorus(.5, 2, 16, 16);
    }

    NodeParticleSystemCoreRefPtr RocketParticleNodeCore = OSG::NodeParticleSystemCore::create();
    RocketParticleNodeCore->setSystem(RocketParticleSystem);
    RocketParticleNodeCore->setPrototypeNode(RocketParticlePrototypeNode);
    RocketParticleNodeCore->setNormalSource(NodeParticleSystemCore::NORMAL_VELOCITY);
    RocketParticleNodeCore->setUpSource(NodeParticleSystemCore::UP_PARTICLE_NORMAL);
    RocketParticleNodeCore->setUp(Vec3f(0.0f,1.0f,0.0f));

    //Geometry Collision Affector
    GeometryCollisionParticleSystemAffectorRefPtr ExampleGeometryCollisionParticleSystemAffector = GeometryCollisionParticleSystemAffector::create();
    ExampleGeometryCollisionParticleSystemAffector->setCollisionNode(EnvironmentNode);

    TutorialParticleCollisionListener TheCollisionListener;
    ExampleGeometryCollisionParticleSystemAffector->addParticleGeometryCollisionListener(&TheCollisionListener);


    NodeRefPtr RocketParticleNode = OSG::Node::create();
    RocketParticleNode->setCore(RocketParticleNodeCore);

    //Attach the Affector to the Rocket Particle System
    //RocketParticleSystem->pushToAffectors();
    RocketParticleSystem->pushToSystemAffectors(ExampleGeometryCollisionParticleSystemAffector);


    //Smoke
    SmokeGenerator = OSG::RateParticleGenerator::create();
    //Attach the function objects to the Generator
    SmokePositionDistribution = createSmokePositionDistribution();
    SmokeGenerator->setPositionDistribution(SmokePositionDistribution);
    SmokeGenerator->setLifespanDistribution(createSmokeLifespanDistribution());
    SmokeGenerator->setGenerationRate(50.0);
    SmokeGenerator->setVelocityDistribution(createSmokeVelocityDistribution());
    //Attach the function objects the Affectors
    SmokeAgeFadeParticleAffector = OSG::AgeFadeParticleAffector::create();
    SmokeAgeFadeParticleAffector->setFadeInTime(2.0f);
    SmokeAgeFadeParticleAffector->setFadeOutTime(5.0f);
    SmokeAgeFadeParticleAffector->setStartAlpha(0.0f);
    SmokeAgeFadeParticleAffector->setFadeToAlpha(0.2f);
    SmokeAgeFadeParticleAffector->setEndAlpha(0.0f);	

    SmokeAgeSizeParticleAffector = OSG::AgeSizeParticleAffector::create();
    //ages
    SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.1);
    SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.2);
    SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.3);
    SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.5);
    SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.7);
    SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.8);
    SmokeAgeSizeParticleAffector->editMFAges()->push_back(1.0);

    //sizes
    SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(0.5,0.5,0.5));
    SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(1.0,1.0,1.0));
    SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.0,2.0,2.0));
    SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(3.0,3.0,3.0));
    SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(4.0,4.0,4.0));
    SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(5.0,5.0,5.0));
    SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(6.5,6.5,6.5));

    ParticleSystemCoreRefPtr SmokeParticleNodeCore = OSG::ParticleSystemCore::create();
    SmokeParticleNodeCore->setSystem(SmokeParticleSystem);
    SmokeParticleNodeCore->setDrawer(SmokeParticleSystemDrawer);
    SmokeParticleNodeCore->setMaterial(PSSmokeMaterial);

    NodeRefPtr SmokeParticleNode = OSG::Node::create();
    SmokeParticleNode->setCore(SmokeParticleNodeCore);
    //end/////////////////////

    //Shrapnel
    ShrapnelBurstGenerator = OSG::BurstParticleGenerator::create();
    NodeRefPtr ShrapnelParticlePrototypeNode = SceneFileHandler::the()->read("Data/Shrapnel.obj");

    NodeParticleSystemCoreRefPtr ShrapnelParticleNodeCore = OSG::NodeParticleSystemCore::create();
    ShrapnelParticleNodeCore->setSystem(ShrapnelParticleSystem);
    ShrapnelParticleNodeCore->setPrototypeNode(ShrapnelParticlePrototypeNode);

    //Attach the function objects to the Generator
    ShrapnelPositionDistribution = createShrapnelPositionDistribution();
    ShrapnelBurstGenerator->setPositionDistribution(ShrapnelPositionDistribution);
    ShrapnelBurstGenerator->setLifespanDistribution(createLifespanDistribution());
    ShrapnelBurstGenerator->setBurstAmount(50.0);
    ShrapnelBurstGenerator->setVelocityDistribution(createShrapnelVelocityDistribution());
    ShrapnelBurstGenerator->setAccelerationDistribution(createShrapnelAccelerationDistribution());

    NodeRefPtr ShrapnelParticleNode = OSG::Node::create();
    ShrapnelParticleNode->setCore(ShrapnelParticleNodeCore);
    //end/////////////////////

    //fireball
    FireballGenerator = OSG::BurstParticleGenerator::create();
    NodeRefPtr FireballParticlePrototypeNode = SceneFileHandler::the()->read("Data/bubble.obj");

    NodeParticleSystemCoreRefPtr FireballParticleNodeCore = OSG::NodeParticleSystemCore::create();
    FireballParticleNodeCore->setSystem(FireballParticleSystem);
    FireballParticleNodeCore->setPrototypeNode(FireballParticlePrototypeNode);
    //Attach the function objects to the Generator
    FireballPositionDistribution = createFireballPositionDistribution();
    FireballGenerator->setPositionDistribution(FireballPositionDistribution);
    FireballGenerator->setLifespanDistribution(createFireballLifespanDistribution());
    FireballGenerator->setBurstAmount(100.0);
    FireballGenerator->setVelocityDistribution(createFireballVelocityDistribution());
    FireballGenerator->setAccelerationDistribution(createFireballAccelerationDistribution());
    //Attach the function objects the Affectors
    FireballAgeSizeParticleAffector = OSG::AgeSizeParticleAffector::create();
    //ages
    FireballAgeSizeParticleAffector->editMFAges()->push_back(0.1);
    FireballAgeSizeParticleAffector->editMFAges()->push_back(0.2);
    FireballAgeSizeParticleAffector->editMFAges()->push_back(0.3);
    FireballAgeSizeParticleAffector->editMFAges()->push_back(0.5);
    FireballAgeSizeParticleAffector->editMFAges()->push_back(0.7);
    FireballAgeSizeParticleAffector->editMFAges()->push_back(0.8);
    FireballAgeSizeParticleAffector->editMFAges()->push_back(1.0);

    //sizes
    FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.0,2.0,2.0));
    FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.3,2.3,2.3));
    FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.5,2.5,2.5));
    FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(3.0,3.0,3.0));
    FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(4.0,4.0,4.0));
    FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(5.0,5.0,5.0));
    FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(6.5,6.5,6.5));

    NodeRefPtr FireballParticleNode = OSG::Node::create();
    FireballParticleNode->setCore(FireballParticleNodeCore);
    //end/////////////////////


    // Make Main Scene Node 
    NodeRefPtr scene = OSG::Node::create();
    scene->setCore(OSG::Group::create());
    scene->addChild(RocketParticleNode);
    scene->addChild(SmokeParticleNode);
    scene->addChild(ShrapnelParticleNode);
    scene->addChild(FireballParticleNode);
    scene->addChild(EnvironmentNode);

    mgr->setRoot(scene);

    mgr->getNavigator()->set(Pnt3f(0.0,0.0,0.0), Pnt3f(0.0,0.0,-1.0), Vec3f(0.0,1.0,0.0));
    mgr->getNavigator()->setMotionFactor(1.0f);
    mgr->getCamera()->setNear(0.1f);
    mgr->getCamera()->setFar(1000.0f);


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
                               WinSize,
                               "10RocketLauncher");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
Пример #3
0
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);

    // Make Torus Node (creates Torus in background of scene)
    NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

    // Make Main Scene Node and add the Torus
    NodeRefPtr scene = OSG::Node::create();
        scene->setCore(OSG::Group::create());
        scene->addChild(TorusGeometryNode);

    // Create the Graphics
    GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create();

    // Initialize the LookAndFeelManager to enable default settings
    LookAndFeelManager::the()->getLookAndFeel()->init();

    /******************************************************
            
            Create and edit a few Button Components. 

    ******************************************************/
    ButtonRefPtr ExampleButton1 = OSG::Button::create();
    ButtonRefPtr ExampleButton2 = OSG::Button::create();
    ButtonRefPtr ExampleButton3 = OSG::Button::create();
    ButtonRefPtr ExampleButton4 = OSG::Button::create();
    ButtonRefPtr ExampleButton5 = OSG::Button::create();
    ButtonRefPtr ExampleButton6 = OSG::Button::create();

        ExampleButton1->setPreferredSize(Vec2f(200, 50));

        ExampleButton4->setPreferredSize(Vec2f(50, 50));

    /******************************************************

        Create Flow Layout.  Flow Layout arranges objects
        automatically within the Frame, so that depending 
        on Frame size, the objects may appear in a vertical
        line, horizontal line, or multiple lines.  Objects 
        fill from the upper left hand corner of the Frame
        across, then down (when the line becomes full) while
        arranged Horizontally, or from the upper left hand
        corner across when arranged Vertically, starting a 
        new column when necessary.

        You can experiment with this by changing the window 
        size, changing the orientation, changing the 
        PreferredSize of the Buttons, or adding more 
		Buttons to the view.

        Note that if the Frame is too small or resized
		too much, the FlowLayout will become slightly
		distorted.  For Layouts which will often
		be dynamically changed, FlowLayout is not
		the best choice.
	
		-setHorizontalGap(int): Determine the Horizontal
			gap in pixels between Components in 
			FlowLayout.
		-setVerticalGap(int): Determine the Vertical
			gap in pixels between Components in 
			FlowLayout.
		-setOrientation(ENUM): Determine whether the
			Layout is arranged Vertically or
			Horizontally.  Takes HORIZONTAL_ORIENTATION
			or VERTICAL_ORIENTATION arguments.
		-setMajorAxisAlignment(ENUM): Determines
			the alignment of the entire Layout 
			within its ComponentContainer.  See below.
		-setMinorAxistAlignment(ENUM): Determines
			the alignment of Components within
			the Layout.  See below.

		Both of the last two functions take the
		following arguments: AXIS_MAX_ALIGNMENT, 
		AXIS_CENTER_ALIGNMENT, and AXIS_MIN_ALIGNMENT.
		MAX puts it to the bottom/right, CENTER
		centers it, and MIN puts it to the
		top/left (for Vertical/Horizontal as
		set above, respectively).

    ******************************************************/
    FlowLayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();
        MainInternalWindowLayout->setHorizontalGap(3.0f);
        MainInternalWindowLayout->setVerticalGap(3.0f);
		MainInternalWindowLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION);
        MainInternalWindowLayout->setMajorAxisAlignment(0.5f);
        MainInternalWindowLayout->setMinorAxisAlignment(1.0f);
    
    // Create The Main InternalWindow
    // Create Background to be used with the Main InternalWindow
    ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create();
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));

    InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create();
       MainInternalWindow->pushToChildren(ExampleButton1);
       MainInternalWindow->pushToChildren(ExampleButton2);
       MainInternalWindow->pushToChildren(ExampleButton3);
       MainInternalWindow->pushToChildren(ExampleButton4);
       MainInternalWindow->pushToChildren(ExampleButton5);
       MainInternalWindow->pushToChildren(ExampleButton6);
       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);
	   // Add a 10 pixel "padding" inside the MainFrame
       MainInternalWindow->setAllInsets(10);

    //Create the Drawing Surface
    UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create();
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindow);
    
	TutorialDrawingSurface->openWindow(MainInternalWindow);

    // Create the UI Foreground Object
    UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create();

        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);


    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);
    mgr->setRoot(scene);

    // Add the UI Foreground Object to the Scene
    ViewportRefPtr TutorialViewport = mgr->getWindow()->getPort(0);
        TutorialViewport->addForeground(TutorialUIForeground);

    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
            WinSize,
            "05FlowLayout");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
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);

    // Make Torus Node (creates Torus in background of scene)
    NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

    // Make Main Scene Node and add the Torus
    NodeRefPtr scene = OSG::Node::create();
    scene->setCore(OSG::Group::create());
    scene->addChild(TorusGeometryNode);

    // Create the Graphics
    GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create();

    // Initialize the LookAndFeelManager to enable default settings
    LookAndFeelManager::the()->getLookAndFeel()->init();

    //Background
    SolidBackgroundRefPtr TutorialBackground = SolidBackground::create();
    TutorialBackground->setColor(Color3f(1.0,0.0,0.0));

	TheUndoManager = UndoManager::create();
	UndoManagerChangeListener TheUndoManagerChangeListener;
	TheUndoManager->addChangeListener(&TheUndoManagerChangeListener);
    TheCommandManager = CommandManager::create(TheUndoManager);
	
    //UndoList
	UndoRedoListModel = DefaultListModel::create();
    UndoRedoListModel->pushBack(boost::any(std::string("Top")));
	ListSelectionModelPtr UndoRedoListSelectionModel(new DefaultListSelectionModel());

	UndoRedoList = List::create();
    UndoRedoList->setPreferredSize(Vec2f(200, 300));
    UndoRedoList->setOrientation(List::VERTICAL_ORIENTATION);
	UndoRedoList->setModel(UndoRedoListModel);

    UndoRedoList->setSelectionModel(UndoRedoListSelectionModel);

    UndoRedoListListener TheUndoRedoListListener;
    UndoRedoList->getSelectionModel()->addListSelectionListener(&TheUndoRedoListListener);

    UndoButton = OSG::Button::create();
    UndoButton->setText("Undo");
	UndoButton->setEnabled(TheUndoManager->numberOfUndos() != 0);
    UndoButtonActionListener TheUndoButtonActionListener;
    UndoButton->addActionListener(&TheUndoButtonActionListener);
	

    RedoButton = OSG::Button::create();
    RedoButton->setText("Redo");
	RedoButton->setEnabled(TheUndoManager->numberOfRedos() != 0);
    RedoButtonActionListener TheRedoButtonActionListener;
    RedoButton->addActionListener(&TheRedoButtonActionListener);

    // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel)
    ScrollPanelRefPtr UndoRedoScrollPanel = ScrollPanel::create();
    UndoRedoScrollPanel->setPreferredSize(Vec2f(200,200));
    UndoRedoScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW);
    UndoRedoScrollPanel->setViewComponent(UndoRedoList);

    //Background Editor Field
    //FieldEditorComponentRefPtr TheEditor = FieldEditorFactory::the()->createDefaultEditor(TutorialBackground, SolidBackground::ColorFieldId, TheCommandManager);
    FieldEditorComponentRefPtr TheEditor = FieldEditorFactory::the()->createDefaultEditor(RedoButton, Button::TextFieldId, TheCommandManager);
    TheEditor->setPreferredSize(Vec2f(100.0f, 20.0f));

    // Create The Main InternalWindow
    // Create Background to be used with the Main InternalWindow
    ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create();
    MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
    InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create();
    LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();
    MainInternalWindow->pushToChildren(TheEditor);
    MainInternalWindow->pushToChildren(UndoRedoScrollPanel);
    MainInternalWindow->pushToChildren(UndoButton);
    MainInternalWindow->pushToChildren(RedoButton);
    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
    UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create();
    TutorialDrawingSurface->setGraphics(TutorialGraphics);
    TutorialDrawingSurface->setEventProducer(TutorialWindow);
    
	TutorialDrawingSurface->openWindow(MainInternalWindow);
	
	// Create the UI Foreground Object
    UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create();

    TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);
    mgr->setRoot(scene);

    // Add the UI Foreground Object to the Scene
    ViewportRefPtr TutorialViewport = mgr->getWindow()->getPort(0);
    TutorialViewport->addForeground(TutorialUIForeground);
    TutorialViewport->setBackground(TutorialBackground);

    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
                                WinSize,
                                "02GenericFieldEditor");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
Пример #5
0
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);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);


    BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
    PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

    //Particle System Material
    TextureObjChunkRefPtr QuadTextureObjChunk = TextureObjChunk::create();
    ImageRefPtr LoadedImage = ImageFileHandler::the()->read("./Data/Cloud.png");    
    QuadTextureObjChunk->setImage(LoadedImage);

    MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
    PSMaterialChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
    PSMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
    PSMaterialChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
    PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);

    ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
    PSMaterial->addChunk(QuadTextureObjChunk);
    PSMaterial->addChunk(PSMaterialChunk);
    PSMaterial->addChunk(PSBlendChunk);

    //Particle System Material 2
    TextureObjChunkRefPtr QuadTextureObjChunk2 = TextureObjChunk::create();
    ImageRefPtr LoadedImage2 = ImageFileHandler::the()->read("./Data/Cloud.png");    
    QuadTextureObjChunk2->setImage(LoadedImage2);

    MaterialChunkRefPtr PSMaterialChunk2 = MaterialChunk::create();
    PSMaterialChunk2->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
    PSMaterialChunk2->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
    PSMaterialChunk2->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
    PSMaterialChunk2->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);

    ChunkMaterialRefPtr PSMaterial2 = ChunkMaterial::create();
    PSMaterial2->addChunk(QuadTextureObjChunk2);
    PSMaterial2->addChunk(PSMaterialChunk2);
    PSMaterial2->addChunk(PSBlendChunk);


    //Particle System

    Example1ParticleSystem = OSG::ParticleSystem::create();
    Example1ParticleSystem->attachUpdateListener(TutorialWindow);

    Example2ParticleSystem = OSG::ParticleSystem::create();
    Example2ParticleSystem->attachUpdateListener(TutorialWindow);

    //Particle System Drawer
    Example1ParticleSystemDrawer = OSG::QuadParticleSystemDrawer::create();
    Example2ParticleSystemDrawer = OSG::QuadParticleSystemDrawer::create();




    //Attach the function objects to the Generator
    //Generator 1 
    ExampleBurstGenerator = OSG::BurstParticleGenerator::create();
    ExampleBurstGenerator->setPositionDistribution(createPositionDistribution());
    ExampleBurstGenerator->setLifespanDistribution(createLifespanDistribution());
    ExampleBurstGenerator->setBurstAmount(50.0);
    ExampleBurstGenerator->setVelocityDistribution(createVelocityDistribution());
    ExampleBurstGenerator->setAccelerationDistribution(createAccelerationDistribution());
    ExampleBurstGenerator->setSizeDistribution(createSizeDistribution());

    //Generator 2
    Example2BurstGenerator = OSG::BurstParticleGenerator::create();
    Example2BurstGenerator->setPositionDistribution(createPositionDistribution());
    Example2BurstGenerator->setLifespanDistribution(createLifespanDistribution());
    Example2BurstGenerator->setBurstAmount(50.0);
    Example2BurstGenerator->setVelocityDistribution(createVelocityDistribution2());
    Example2BurstGenerator->setAccelerationDistribution(createAccelerationDistribution());
    Example2BurstGenerator->setSizeDistribution(createSizeDistribution());



    //Particle System Node
    ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create();
    ParticleNodeCore->setSystem(Example1ParticleSystem);
    ParticleNodeCore->setDrawer(Example1ParticleSystemDrawer);
    ParticleNodeCore->setMaterial(PSMaterial);

    NodeRefPtr ParticleNode = OSG::Node::create();
    ParticleNode->setCore(ParticleNodeCore);

    //Particle System Node2
    ParticleSystemCoreRefPtr ParticleNodeCore2 = OSG::ParticleSystemCore::create();
    ParticleNodeCore2->setSystem(Example2ParticleSystem);
    ParticleNodeCore2->setDrawer(Example2ParticleSystemDrawer);
    ParticleNodeCore2->setMaterial(PSMaterial2);

    NodeRefPtr ParticleNode2 = OSG::Node::create();
    ParticleNode2->setCore(ParticleNodeCore2);

    //Ground Node
    NodeRefPtr GoundNode = makePlane(30.0,30.0,10,10);

    Matrix GroundTransformation;
    GroundTransformation.setRotate(Quaternion(Vec3f(1.0f,0.0,0.0), -3.14195f));
    TransformRefPtr GroundTransformCore = Transform::create();
    GroundTransformCore->setMatrix(GroundTransformation);

    NodeRefPtr GroundTransformNode = Node::create();
    GroundTransformNode->setCore(GroundTransformCore);
    GroundTransformNode->addChild(GoundNode);


    // Make Main Scene Node and add the Torus
    NodeRefPtr scene = OSG::Node::create();
    scene->setCore(OSG::Group::create());
    scene->addChild(ParticleNode);
    scene->addChild(ParticleNode2);
    scene->addChild(GroundTransformNode);

    mgr->setRoot(scene);

    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
                               WinSize,
                               "06Explosion");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
Пример #6
0
// Initialize WIN32 & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    {
        // create the scene
        NodeRecPtr scene = makeTorus(.5, 2, 16, 16);

        //Create a Window object
        WindowEventProducerRefPtr TheWindow = createNativeWindow();

        //Apply window settings
        TheWindow->setUseCallbackForDraw(true);
        TheWindow->setUseCallbackForReshape(true);
        //TheWindow->setFullscreen(true);
        
        
        
        //Initialize Window
        TheWindow->initWindow();

        commitChanges();
        
        // create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TheWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TheWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // tell the manager what to manage
        sceneManager.setWindow(TheWindow);
        sceneManager.setRoot  (scene);

        //Attach to the Mouse Events
        TheWindow->connectMouseClicked(boost::bind(mouseClicked, _1));
        TheWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TheWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TheWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager));
        TheWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TheWindow->connectMouseEntered(boost::bind(mouseEntered, _1));
        TheWindow->connectMouseExited(boost::bind(mouseExited, _1));
        
        TheWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));

        //Attach to the Key Events
        TheWindow->connectKeyPressed(boost::bind(keyPressed, _1));
        TheWindow->connectKeyReleased(boost::bind(keyReleased, _1));
        TheWindow->connectKeyTyped(boost::bind(keyTyped, _1));

        //Attach to the Window Events
        TheWindow->connectWindowOpened(boost::bind(windowOpened, _1));
        TheWindow->connectWindowClosing(boost::bind(windowClosing, _1));
        TheWindow->connectWindowClosed(boost::bind(windowClosed, _1));
        TheWindow->connectWindowIconified(boost::bind(windowIconified, _1));
        TheWindow->connectWindowDeiconified(boost::bind(windowDeiconified, _1));
        TheWindow->connectWindowActivated(boost::bind(windowActivated, _1));
        TheWindow->connectWindowDeactivated(boost::bind(windowDeactivated, _1));
        TheWindow->connectWindowEntered(boost::bind(windowEntered, _1));
        TheWindow->connectWindowExited(boost::bind(windowExited, _1));

        //Create the Documentation Foreground and add it to the viewport
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TheWindow);

        // show the whole scene
        sceneManager.showAll();

        // show statistics
        sceneManager.setStatistics(true);


        //Open Window
        Vec2f WinSize(TheWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TheWindow->getDesktopSize() - WinSize) *0.5);
        TheWindow->openWindow(WinPos,
                            WinSize,
                            "01 Native Window");

        //Enter main loop
        TheWindow->mainLoop();
    }

    osgExit();
    return 0;
}
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);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);

    //Particle System Material
    PointChunkRefPtr PSPointChunk = PointChunk::create();
    PSPointChunk->setSize(20.0f);
    PSPointChunk->setSmooth(true);
    BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
    PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

    MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
    PSMaterialChunkChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
    PSMaterialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
    PSMaterialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
    PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);

    ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
    PSMaterial->addChunk(PSPointChunk);
    PSMaterial->addChunk(PSMaterialChunkChunk);
    PSMaterial->addChunk(PSBlendChunk);

    Distribution3DRefPtr PositionDistribution = createPositionDistribution();
    Distribution1DRefPtr LifespanDistribution = createLifespanDistribution();

    Pnt3f PositionReturnValue;
    Time LifespanReturnValue = -1;

    //Particle System
    ParticleSystemRefPtr ExampleParticleSystem = OSG::ParticleSystem::create();
    for(UInt32 i(0) ; i<200 ; ++i)//controls how many particles are created
    {
        if(PositionDistribution != NULL)
        {
            PositionReturnValue = Pnt3f(PositionDistribution->generate());
        }
        if(LifespanDistribution != NULL)
        {
            LifespanReturnValue = LifespanDistribution->generate();
        }

        ExampleParticleSystem->addParticle(
                                           PositionReturnValue,
                                           Vec3f(0.0f,0.0f,1.0f),
                                           Color4f(1.0,0.0,0.0,1.0), 
                                           Vec3f(1.0,1.0,1.0), 
                                           LifespanReturnValue, 
                                           Vec3f(0.0f,0.0f,0.0f), //Velocity
                                           Vec3f(0.0f,0.0f,0.0f)	//acceleration
                                          );
    }
    ExampleParticleSystem->attachUpdateListener(TutorialWindow);

    //Particle System Drawer
    PointParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = OSG::PointParticleSystemDrawer::create();


    //Create an CollectiveGravityParticleSystemAffector
    CollectiveGravityParticleSystemAffectorRefPtr ExampleCollectiveGravityParticleSystemAffector = OSG::CollectiveGravityParticleSystemAffector::create();
    ExampleCollectiveGravityParticleSystemAffector->setParticleMass(10000000000.0f);

    ExampleParticleSystem->pushToSystemAffectors(ExampleCollectiveGravityParticleSystemAffector);


    //Particle System Node
    ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create();
    ParticleNodeCore->setSystem(ExampleParticleSystem);
    ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
    ParticleNodeCore->setMaterial(PSMaterial);

    NodeRefPtr ParticleNode = OSG::Node::create();
    ParticleNode->setCore(ParticleNodeCore);


    // Make Main Scene Node and add the Torus
    NodeRefPtr scene = OSG::Node::create();
    scene->setCore(OSG::Group::create());
    scene->addChild(ParticleNode);

    mgr->setRoot(scene);

    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
                               WinSize,
                               "10GravityParticleSystemAffector");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
Пример #8
0
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);

    // Make Torus Node (creates Torus in background of scene)
    NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

    // Make Main Scene Node and add the Torus
    NodeRefPtr scene = OSG::Node::create();
    scene->setCore(OSG::Group::create());
    scene->addChild(TorusGeometryNode);

    // Create the Graphics
    GraphicsRefPtr TutorialGraphics = OSG::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(KeyEvent::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(KeyEvent::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(KeyEvent::KEY_****): sets the key
"****" to be underlined within the Menu
itself


     ******************************************************/

    // Creates MenuItems as in 25PopupMenu
    MenuItemRefPtr NewMenuItem = MenuItem::create();
    MenuItemRefPtr OpenMenuItem = MenuItem::create();
    MenuItemRefPtr CloseMenuItem = MenuItem::create();
    MenuItemRefPtr ExitMenuItem = MenuItem::create();
    MenuItemRefPtr UndoMenuItem = MenuItem::create();
    MenuItemRefPtr RedoMenuItem = MenuItem::create();

    //Edits MenuItems
    NewMenuItem->setText("New ...");
    NewMenuItem->setAcceleratorKey(KeyEvent::KEY_N);
    NewMenuItem->setAcceleratorModifiers(KeyEvent::KEY_MODIFIER_COMMAND);
    NewMenuItem->setMnemonicKey(KeyEvent::KEY_N);

    OpenMenuItem->setText("Open ...");
    OpenMenuItem->setAcceleratorKey(KeyEvent::KEY_P);
    OpenMenuItem->setAcceleratorModifiers(KeyEvent::KEY_MODIFIER_COMMAND);
    OpenMenuItem->setMnemonicKey(KeyEvent::KEY_P);

    CloseMenuItem->setText("Close ...");
    CloseMenuItem->setAcceleratorKey(KeyEvent::KEY_W);
    CloseMenuItem->setAcceleratorModifiers(KeyEvent::KEY_MODIFIER_COMMAND);
    CloseMenuItem->setMnemonicKey(KeyEvent::KEY_C);

    ExitMenuItem->setText("Quit");
    ExitMenuItem->setAcceleratorKey(KeyEvent::KEY_Q);
    ExitMenuItem->setAcceleratorModifiers(KeyEvent::KEY_MODIFIER_COMMAND);
    ExitMenuItem->setMnemonicKey(KeyEvent::KEY_Q);

    UndoMenuItem->setText("Undo");
    UndoMenuItem->setAcceleratorKey(KeyEvent::KEY_Z);
    UndoMenuItem->setAcceleratorModifiers(KeyEvent::KEY_MODIFIER_COMMAND);
    UndoMenuItem->setMnemonicKey(KeyEvent::KEY_U);
    RedoMenuItem->setText("Redo");
    RedoMenuItem->setEnabled(false);
    RedoMenuItem->setMnemonicKey(KeyEvent::KEY_R);

    // Create an ActionListener and assign it to ExitMenuItem
    // This is defined above, and will cause the program to quit
    // when that MenuItem is selected or Control + Q hit 
    QuitActionListener TheQuitActionListener;
    ExitMenuItem->addActionListener( &TheQuitActionListener);

    /******************************************************

      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
    MenuRefPtr 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(KeyEvent::KEY_F);

    // Creates an Edit menu and adds its MenuItems
    MenuRefPtr EditMenu = Menu::create();
    EditMenu->addItem(UndoMenuItem);
    EditMenu->addItem(RedoMenuItem);

    // Labels the Edit Menu
    EditMenu->setText("Edit");
    EditMenu->setMnemonicKey(KeyEvent::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

    MenuBarRefPtr MainMenuBar = MenuBar::create();
    // Adds the two Menus to the MainMenuBar
    MainMenuBar->addMenu(FileMenu);
    MainMenuBar->addMenu(EditMenu);

    // Create two Labels
    LabelRefPtr ExampleLabel1 = OSG::Label::create();
    LabelRefPtr ExampleLabel2 = OSG::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
    EmptyLayerRefPtr MainInternalWindowBackground = OSG::EmptyLayer::create();
    EmptyBorderRefPtr MainInternalWindowBorder = OSG::EmptyBorder::create();

    LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();

    InternalWindowRefPtr MainInternalWindow = OSG::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
    UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create();
    TutorialDrawingSurface->setGraphics(TutorialGraphics);
    TutorialDrawingSurface->setEventProducer(TutorialWindow);

    TutorialDrawingSurface->openWindow(MainInternalWindow);

    // Create the UI Foreground Object
    UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create();

    TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);


    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);
    mgr->setRoot(scene);

    // Add the UI Foreground Object to the Scene
    ViewportRefPtr TutorialViewport = mgr->getWindow()->getPort(0);
    TutorialViewport->addForeground(TutorialUIForeground);

    // Show the whole Scene
    mgr->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;
}
Пример #9
0
 virtual void actionPerformed(const ActionEventUnrecPtr e)
 {
     TutorialWindow->closeWindow();
 }
int main(int argc, char **argv)
{
    OSG::preloadSharedObject("OSGImageFileIO");
    // 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);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);

    // Creating the Particle System Material
	// Here, the image is loaded.  The entire image sequence is conatined in one image,
	// which reduces texture memory overhead and runs faster.
    TextureObjChunkRefPtr QuadTextureChunk = TextureObjChunk::create();
    ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/SpriteExplode.png");    
    QuadTextureChunk->setImage(LoadedImage);

    TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create();
    QuadTextureEnvChunk->setEnvMode(GL_MODULATE);

    BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
    PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

    MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
    PSMaterialChunk->setAmbient(Color4f(0.3f,0.0f,0.0f,1.0f));
    PSMaterialChunk->setDiffuse(Color4f(0.7f,0.0f,0.0f,1.0f));
    PSMaterialChunk->setSpecular(Color4f(0.9f,0.0f,0.0f,1.0f));
    PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);

    ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
    PSMaterial->addChunk(QuadTextureChunk);
    PSMaterial->addChunk(QuadTextureEnvChunk);
    PSMaterial->addChunk(PSMaterialChunk);
    PSMaterial->addChunk(PSBlendChunk);

    //Particle System
    ExampleParticleSystem = OSG::ParticleSystem::create();
    ExampleParticleSystem->attachUpdateListener(TutorialWindow);

	//Age Particle Function.  Controls which image is shown when, based on the age of a particle.
	AgeFunc = OSG::AgeParticleFunction::create();
	AgeFunc->setSequenceTime(0.1f); // image changes every 0.1 seconds.
	AgeFunc->setSequenceOrder(AgeParticleFunction::CUSTOM); // using the custom sequence below.
	/*
		Here, a custom sequence for the image ordering is assembled.  The image sequence will be shown in 
		the order specified here.  Once the end of the sequence is reached, the sequence repeats.
	*/
	AgeFunc->editMFCustomSequence()->push_back(0);
	AgeFunc->editMFCustomSequence()->push_back(1);
	AgeFunc->editMFCustomSequence()->push_back(2);
	AgeFunc->editMFCustomSequence()->push_back(3);
	AgeFunc->editMFCustomSequence()->push_back(4);
	AgeFunc->editMFCustomSequence()->push_back(5);
	AgeFunc->editMFCustomSequence()->push_back(4);
	AgeFunc->editMFCustomSequence()->push_back(3);
	AgeFunc->editMFCustomSequence()->push_back(2);
	AgeFunc->editMFCustomSequence()->push_back(1);

	//Particle System Drawer - 
    ExampleParticleSystemDrawer = OSG::QuadSequenceParticleSystemDrawer::create();
	// image dimensions (in pixels) are required if there is a border on the images.
	ExampleParticleSystemDrawer->setImageDimensions(OSG::Vec2us(780,520));
	// The "dimensions" of the sequence contained in the image.  For this image,
	// there are 3 images in the "x" direction, and two in the "y" direction, for a 
	// total of 6.
	ExampleParticleSystemDrawer->setSequenceDimensions(OSG::Vec2b(3,2));
	// width of the border on each side of the image, in pixels.
	ExampleParticleSystemDrawer->setBorderOffsets(OSG::Vec2b(0,0));
	// this is the age function we just created above.
	ExampleParticleSystemDrawer->setSequenceFunction(AgeFunc);

    ExampleParticleGenerator = OSG::RateParticleGenerator::create();
    //Attach the function objects to the Generator
    ExampleParticleGenerator->setPositionDistribution(createPositionDistribution());
    ExampleParticleGenerator->setLifespanDistribution(createLifespanDistribution());
    ExampleParticleGenerator->setVelocityDistribution(createVelocityDistribution());
    ExampleParticleGenerator->setAccelerationDistribution(createAccelerationDistribution());
    ExampleParticleGenerator->setSizeDistribution(createSizeDistribution());
	ExampleParticleGenerator->setGenerationRate(2.0f);

    //Particle System Node
    ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create();
    ParticleNodeCore->setSystem(ExampleParticleSystem);
    ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
    ParticleNodeCore->setMaterial(PSMaterial);
	ParticleNodeCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT);
	
    NodeRefPtr ParticleNode = OSG::Node::create();
    ParticleNode->setCore(ParticleNodeCore);

	ExampleParticleSystem->addParticle(Pnt3f(10.0,0.0,0.0),
                                   Vec3f(0.0,1.0,0.0),
                                   Color4f(1.0,1.0,1.0,1.0),
                                   Vec3f(1.0,1.0,1.0),
                                   0.01,
                                   Vec3f(0.0,0.0,0.0),
                                   Vec3f(0.0,0.0,0.0));

	ExampleParticleSystem->addParticle(Pnt3f(-10.0,0.0,0.0),
                                   Vec3f(0.0,1.0,0.0),
                                   Color4f(1.0,1.0,1.0,1.0),
                                   Vec3f(1.0,1.0,1.0),
                                   0.01,
                                   Vec3f(0.0,0.0,0.0),
                                   Vec3f(0.0,0.0,0.0));

	ExampleParticleSystem->pushToGenerators(ExampleParticleGenerator);
    // Make Main Scene Node and add the Torus
    NodeRefPtr scene = OSG::Node::create();
    scene->setCore(OSG::Group::create());
    scene->addChild(ParticleNode);

    mgr->setRoot(scene);

    // Show the whole Scene
    mgr->showAll();

    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
                               WinSize,
                               "05a - QuadSequenceParticleDrawer");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}