本文整理汇总了C++中WindowEventProducerRecPtr::mainLoop方法的典型用法代码示例。如果您正苦于以下问题:C++ WindowEventProducerRecPtr::mainLoop方法的具体用法?C++ WindowEventProducerRecPtr::mainLoop怎么用?C++ WindowEventProducerRecPtr::mainLoop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WindowEventProducerRecPtr
的用法示例。
在下文中一共展示了WindowEventProducerRecPtr::mainLoop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
ExamplePatternLayerButton->setTextColor(Color4f(0.0,1.0,0.0,1.0));
ExamplePatternLayerButton->setRolloverTextColor(Color4f(0.0,1.0,0.0,1.0));
ExamplePatternLayerButton->setActiveTextColor(Color4f(0.0,1.0,0.0,1.0));
ExampleGlassLayerButton->setText("Glass Layer");
ExampleGlassLayerButton->setBackground(ExampleGlassLayer);
ExampleGlassLayerButton->setActiveBackground(ExampleGlassLayer);
ExampleGlassLayerButton->setRolloverBackground(ExampleGlassLayer);
ExampleGlassLayerButton->setPreferredSize(Vec2f(150,50));
ExampleGlassLayerButton->setTextColor(Color4f(0.0,0.0,0.0,1.0));
ExampleGlassLayerButton->setRolloverTextColor(Color4f(0.0,0.0,0.0,1.0));
ExampleGlassLayerButton->setActiveTextColor(Color4f(0.0,0.0,0.0,1.0));
ExampleGlassCompoundLayerButton->setText("GlassCompound Layer");
ExampleGlassCompoundLayerButton->setBackground(ExampleGlassCompoundLayer);
ExampleGlassCompoundLayerButton->setActiveBackground(ExampleGlassCompoundLayer);
ExampleGlassCompoundLayerButton->setRolloverBackground(ExampleGlassCompoundLayer);
ExampleGlassCompoundLayerButton->setPreferredSize(Vec2f(150,50));
ExampleGlassCompoundLayerButton->setTextColor(Color4f(0.0,0.0,0.0,1.0));
ExampleGlassCompoundLayerButton->setRolloverTextColor(Color4f(0.0,0.0,0.0,1.0));
ExampleGlassCompoundLayerButton->setActiveTextColor(Color4f(0.0,0.0,0.0,1.0));
/******************************************************
Create a MainFrameBackground. For almost
all Tutorials, this is simply a
ColorLayer with a semi-transparent
white Background.
******************************************************/
// 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));
//InternalWindow Layout
LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();
InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create();
MainInternalWindow->pushToChildren(ExampleColorLayerButton);
MainInternalWindow->pushToChildren(ExampleCompoundLayerButton);
MainInternalWindow->pushToChildren(ExampleEmptyLayerButton);
MainInternalWindow->pushToChildren(ExampleGradientLayerButton);
MainInternalWindow->pushToChildren(ExampleMaterialLayerButton);
MainInternalWindow->pushToChildren(ExampleTextureLayerButton);
MainInternalWindow->pushToChildren(ExamplePatternLayerButton);
MainInternalWindow->pushToChildren(ExampleGlassLayerButton);
MainInternalWindow->pushToChildren(ExampleGlassCompoundLayerButton);
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
sceneManager->setRoot(scene);
// Add the UI Foreground Object to the Scene
ViewportRefPtr 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,
"04Background");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例2: main
//.........这里部分代码省略.........
-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;
}
示例3: main
// Initialize WIN32 & OpenSG and set up the scene
int main(int argc, char **argv)
{
preloadSharedObject("OSGTBFileIO");
// 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->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1));
// create the scene
NodeUnrecPtr scene = makeTorus(1.0, 2.0, 16, 16);
sceneManager.setRoot (scene);
//Create the Documentation
SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
// show the whole scene
sceneManager.showAll();
//Load Sound Definitions
FCFileType::FCPtrStore NewContainers;
NewContainers = FCFileHandler::the()->read(BoostPath("Data/04SoundData.xml"));
FCFileType::FCPtrStore::iterator Itor;
for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
{
//Get Sounds
if( (*Itor)->getType().isDerivedFrom(Sound::getClassType()))
{
Sounds.push_back(dynamic_pointer_cast<Sound>(*Itor));
Sounds.back()->connectSoundPlayed (boost::bind(handleSoundPlayed, _1));
Sounds.back()->connectSoundStopped (boost::bind(handleSoundStopped, _1));
Sounds.back()->connectSoundPaused (boost::bind(handleSoundPaused, _1));
Sounds.back()->connectSoundUnpaused(boost::bind(handleSoundUnpaused, _1));
Sounds.back()->connectSoundLooped (boost::bind(handleSoundLooped, _1));
}
//Get Sound Groups
if( (*Itor)->getType().isDerivedFrom(SoundGroup::getClassType()))
{
SoundGroups.push_back(dynamic_pointer_cast<SoundGroup>(*Itor));
}
}
//Initialize the Sound Manager
SoundManager::the()->attachUpdateProducer(TutorialWindow);
SoundManager::the()->setCamera(sceneManager.getCamera());
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"04 XML Sound Loading Window");
//Enter main loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例4: main
//.........这里部分代码省略.........
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->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager));
//Particle System 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 PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSPointChunk);
PSMaterial->addChunk(PSMaterialChunkChunk);
PSMaterial->addChunk(PSBlendChunk);
Distribution3DRefPtr PositionDistribution = createPositionDistribution();
Pnt3f PositionReturnValue;
//Particle System
ParticleSystemRefPtr ExampleParticleSystem = ParticleSystem::create();
for(UInt32 i(0) ; i<500 ; ++i)//controls how many particles are created
{
if(PositionDistribution != NULL)
{
PositionReturnValue = Pnt3f(PositionDistribution->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),
-1,
Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f) //acceleration
);
}
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
//Particle System Drawer
PointParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = PointParticleSystemDrawer::create();
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = Node::create();
ParticleNode->setCore(ParticleNodeCore);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(ParticleNode);
sceneManager.setRoot(scene);
// Show the whole Scene
sceneManager.showAll();
//Create an DistanceKill
DistanceKillParticleAffectorRefPtr ExampleDistanceKillParticleAffector = DistanceKillParticleAffector::create();
ExampleDistanceKillParticleAffector->setKillDistance(1000.0f);
ExampleDistanceKillParticleAffector->setParticleSystemNode(ParticleNode);
ExampleDistanceKillParticleAffector->setDistanceFromSource(DistanceKillParticleAffector::DISTANCE_FROM_CAMERA);
ExampleDistanceKillParticleAffector->setDistanceFromCamera(sceneManager.getCamera());
ExampleParticleSystem->pushToAffectors(ExampleDistanceKillParticleAffector);
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"09DistanceKillParticleAffector");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例5: main
//.........这里部分代码省略.........
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;
}
示例6: main
//.........这里部分代码省略.........
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;
}
示例7: main
//.........这里部分代码省略.........
// 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;
}
示例8: main
//.........这里部分代码省略.........
// Create an Action and assign it to ExampleButton
// This Class is defined above, and will cause the output
// window to display "Button 1 Action" when pressed
ExampleButton->connectActionPerformed(boost::bind(actionPerformed, _1));
/******************************************************
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).
******************************************************/
ToggleButtonRefPtr ExampleToggleButton = OSG::ToggleButton::create();
ExampleToggleButton->setSelected(false);
ExampleToggleButton->setText("ToggleMe");
ExampleToggleButton->setToolTipText("Toggle Button ToolTip");
//Button with Image
ButtonRefPtr ExampleDrawObjectButton = OSG::Button::create();
ExampleDrawObjectButton->setDrawObjectToTextAlignment(Button::ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT);
ExampleDrawObjectButton->setText("Icon");
ExampleDrawObjectButton->setImage(std::string("./Data/Icon.png"));
ExampleDrawObjectButton->setActiveImage(std::string("./Data/Icon.png"));
ExampleDrawObjectButton->setFocusedImage(std::string("./Data/Icon.png"));
ExampleDrawObjectButton->setRolloverImage(std::string("./Data/Icon.png"));
ExampleDrawObjectButton->setDisabledImage(std::string("./Data/Icon.png"));
// 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(ExampleButton);
MainInternalWindow->pushToChildren(ExampleToggleButton);
MainInternalWindow->pushToChildren(ExampleDrawObjectButton);
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);
sceneManager.setRoot(scene);
// Add the UI Foreground Object to the Scene
ViewportRefPtr 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();
//Attach key controls
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"01Button");
commitChanges();
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例9: main
//.........这里部分代码省略.........
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;
}
示例10: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
//Initialize Window
TutorialWindow->initWindow();
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->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
//Torus Material
SimpleMaterialUnrecPtr TheTorusMaterial = SimpleMaterial::create();
TheTorusMaterial->setAmbient(Color3f(0.3,0.3,0.3));
TheTorusMaterial->setDiffuse(Color3f(0.7,0.7,0.7));
TheTorusMaterial->setSpecular(Color3f(1.0,1.0,1.0));
TheTorusMaterial->setShininess(20.0);
//Torus Geometry
GeometryUnrecPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32);
TorusGeometry->setMaterial(TheTorusMaterial);
NodeUnrecPtr TorusGeometryNode = Node::create();
TorusGeometryNode->setCore(TorusGeometry);
//Make Torus Node
NodeUnrecPtr TorusNode = Node::create();
TransformUnrecPtr TorusNodeTrans = Transform::create();
setName(TorusNodeTrans, std::string("TorusNodeTransformationCore"));
TorusNode->setCore(TorusNodeTrans);
TorusNode->addChild(TorusGeometryNode);
//Make Main Scene Node
NodeUnrecPtr scene = Node::create();
ComponentTransformUnrecPtr Trans = ComponentTransform::create();
setName(Trans, std::string("MainTransformationCore"));
scene->setCore(Trans);
// add the torus as a child
scene->addChild(TorusNode);
AnimationGroupUnrecPtr TheAnimation = setupAnimation(TheTorusMaterial, TorusNodeTrans);
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1,
TheAnimation.get(),
TutorialWindow.get()));
TheAnimation->attachUpdateProducer(TutorialWindow);
TheAnimation->start();
// tell the manager what to manage
sceneManager.setRoot (scene);
//Create the Documentation
SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
// show the whole scene
sceneManager.showAll();
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"07AnimationGroup");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例11: main
//.........这里部分代码省略.........
use the same Model), using each
will cause them to move at different
speeds due to these settings being
different.
******************************************************/
// Create a DefaultBoundedRangeModel
DefaultBoundedRangeModelRecPtr TheBoundedRangeModel = DefaultBoundedRangeModel::create();
TheBoundedRangeModel->setMinimum(10);
TheBoundedRangeModel->setMaximum(100);
TheBoundedRangeModel->setValue(10);
TheBoundedRangeModel->setExtent(20);
ScrollBarRecPtr ExampleVerticalScrollBar = ScrollBar::create();
//ExampleScrollPanel->getHorizontalScrollBar()
ExampleVerticalScrollBar->setOrientation(ScrollBar::VERTICAL_ORIENTATION);
ExampleVerticalScrollBar->setPreferredSize(Vec2f(20,200));
ExampleVerticalScrollBar->setEnabled(false);
ExampleVerticalScrollBar->setUnitIncrement(10);
ExampleVerticalScrollBar->setBlockIncrement(100);
ExampleVerticalScrollBar->setRangeModel(TheBoundedRangeModel);
ScrollBarRecPtr ExampleHorizontalScrollBar = ScrollBar::create();
ExampleHorizontalScrollBar->setOrientation(ScrollBar::HORIZONTAL_ORIENTATION);
ExampleHorizontalScrollBar->setPreferredSize(Vec2f(400,20));
ExampleHorizontalScrollBar->setRangeModel(TheBoundedRangeModel);
// Creates another DefaultBoundedRangeModel to use
// for separating the two ScrollBars from each other.
// Make sure to comment out the addition of the
// previous setModel above.
/*
DefaultBoundedRangeModel TheBoundedRangeModel2;
TheBoundedRangeModel2.setMinimum(0);
TheBoundedRangeModel2.setMaximum(100);
TheBoundedRangeModel2.setValue(10);
TheBoundedRangeModel2.setExtent(20);
ExampleHorizontalScrollBar->setModel(&TheBoundedRangeModel2);
*/
// 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(ExampleHorizontalScrollBar);
MainInternalWindow->pushToChildren(ExampleVerticalScrollBar);
MainInternalWindow->pushToChildren(ExampleScrollPanel);
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,
"27ScrollPanel");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例12: main
//.........这里部分代码省略.........
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
//Particle System Material
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(PSMaterialChunkChunk);
Distribution3DRefPtr PositionDistribution = createPositionDistribution();
Pnt3f PositionReturnValue;
//Particle System
ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create();
for(UInt32 i(0) ; i<500 ; ++i)//controls how many particles are created
{
if(PositionDistribution != NULL)
{
PositionReturnValue = Pnt3f(PositionDistribution->generate());
}
ExampleParticleSystem->addParticle(
PositionReturnValue,
PositionReturnValue,
Vec3f(0.0f,0.0f,1.0f),
Color4f(1.0,0.0,0.0,1.0),
Vec3f(1.0,1.0,1.0),
-1, 0,
Vec3f(0.0,0.0,0.0), Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f), //acceleration
StringToUInt32Map() );
}
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
RandomMovementParticleAffectorRecPtr ExampleRMA = RandomMovementParticleAffector::create();
ExampleRMA->setAmplitude(100.0f);
AttributeAttractRepelParticleAffectorRecPtr ExampleAttributeAttractRepelParticleAffector = AttributeAttractRepelParticleAffector::create();
ExampleAttributeAttractRepelParticleAffector->setAttributeAffected(RandomMovementParticleAffector::POSITION_ATTRIBUTE);
ExampleAttributeAttractRepelParticleAffector->setMinDistance(0.0);
ExampleAttributeAttractRepelParticleAffector->setMaxDistance(10000000000000.0);
ExampleAttributeAttractRepelParticleAffector->setQuadratic(0.01);
ExampleAttributeAttractRepelParticleAffector->setLinear(0.01);
ExampleAttributeAttractRepelParticleAffector->setConstant(0.0);
ExampleParticleSystem->pushToAffectors(ExampleRMA);
ExampleParticleSystem->pushToAffectors(ExampleAttributeAttractRepelParticleAffector);
ExampleParticleSystem->setUpdateSecAttribs(false);
//Particle System Drawer
QuadParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = QuadParticleSystemDrawer::create();
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = Node::create();
ParticleNode->setCore(ParticleNodeCore);
// Make Main Scene Node
NodeRefPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(ParticleNode);
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
&sceneManager,
ExampleParticleSystem.get(),
ExampleRMA.get(),
ExampleAttributeAttractRepelParticleAffector.get()));
sceneManager.setRoot(scene);
// 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,
"17RandomMovement");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例13: main
//.........这里部分代码省略.........
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.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(QuadTextureChunk);
PSMaterial->addChunk(QuadTextureEnvChunk);
PSMaterial->addChunk(PSMaterialChunk);
PSMaterial->addChunk(PSBlendChunk);
//Particle System
ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create();
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
//Particle System Drawer
QuadParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = QuadParticleSystemDrawer::create();
BurstParticleGeneratorRecPtr ExampleBurstGenerator = BurstParticleGenerator::create();
//Attach the function objects to the Generator
ExampleBurstGenerator->setPositionDistribution(createPositionDistribution());
ExampleBurstGenerator->setLifespanDistribution(createLifespanDistribution());
ExampleBurstGenerator->setBurstAmount(50.0);
ExampleBurstGenerator->setVelocityDistribution(createVelocityDistribution());
ExampleBurstGenerator->setAccelerationDistribution(createAccelerationDistribution());
ExampleBurstGenerator->setSizeDistribution(createSizeDistribution());
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = Node::create();
ParticleNode->setCore(ParticleNodeCore);
//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 = Node::create();
scene->setCore(Group::create());
scene->addChild(ParticleNode);
scene->addChild(GroundTransformNode);
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
&sceneManager,
ExampleParticleSystem.get(),
ExampleBurstGenerator.get(),
ExampleParticleSystemDrawer.get()));
sceneManager.setRoot(scene);
//Create the Documentation
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,
"05QuadParticleDrawer");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例14: main
// Initialize WIN32 & OpenSG and set up the scene
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->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
//Sound Emitter Node
SoundEmitterRecPtr TheEmitter = SoundEmitter::create();
TheEmitter->attachUpdateProducer(TutorialWindow);
NodeUnrecPtr TheEmitterNode = Node::create();
TheEmitterNode->setCore(TheEmitter);
//Sphere Transformation Node
Matrix Translate;
Translate.setTranslate(0.0,0.0,-5.0);
Matrix Rotation;
Rotation.setRotate(Quaternion(Vec3f(0.0,1.0,0.0), 0.0));
Matrix Total(Translate);
Total.mult(Rotation);
TransformRecPtr TheSphereTransform = Transform::create();
TheSphereTransform->setMatrix(Total);
NodeUnrecPtr SphereTransformNode = Node::create();
SphereTransformNode->setCore(TheSphereTransform);
SphereTransformNode->addChild(makeSphere(2, 1.0));
SphereTransformNode->addChild(TheEmitterNode);
// create the scene
NodeUnrecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(SphereTransformNode);
// tell the manager what to manage
sceneManager.setRoot (scene);
CameraUnrecPtr TheCamera = sceneManager.getCamera();
TheCamera->setNear(0.1);
TheCamera->setFar(100.0);
//Initialize the Sound Manager
SoundManager::the()->attachUpdateProducer(TutorialWindow);
SoundManager::the()->setCamera(sceneManager.getCamera());
SoundRecPtr PopSound = SoundManager::the()->createSound();
PopSound->setFile(BoostPath("./Data/pop.wav"));
PopSound->setVolume(1.0);
PopSound->setStreaming(false);
PopSound->setLooping(-1);
PopSound->setEnable3D(true);
PopSound->connectSoundPlayed (boost::bind(handleSoundPlayed, _1));
PopSound->connectSoundStopped (boost::bind(handleSoundStopped, _1));
PopSound->connectSoundPaused (boost::bind(handleSoundPaused, _1));
PopSound->connectSoundUnpaused(boost::bind(handleSoundUnpaused, _1));
PopSound->connectSoundLooped (boost::bind(handleSoundLooped, _1));
//Attach this sound to the emitter node
TheEmitter->setSound(PopSound);
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
TheEmitter.get()));
TutorialWindow->connectUpdate(boost::bind(handleUpdate, _1,
TheSphereTransform.get()));
//Create the Documentation
SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"02 Sound3D Window");
//Enter main loop
TutorialWindow->mainLoop();
}
//.........这里部分代码省略.........
示例15: main
//.........这里部分代码省略.........
//Particle System
ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create();
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
//Age Particle Function. Controls which image is shown when, based on the age of a particle.
AgeParticleFunctionRecPtr AgeFunc = 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 -
QuadSequenceParticleSystemDrawerRecPtr ExampleParticleSystemDrawer = QuadSequenceParticleSystemDrawer::create();
// image dimensions (in pixels) are required if there is a border on the images.
ExampleParticleSystemDrawer->setImageDimensions(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(Vec2b(3,2));
// width of the border on each side of the image, in pixels.
ExampleParticleSystemDrawer->setBorderOffsets(Vec2b(0,0));
// this is the age function we just created above.
ExampleParticleSystemDrawer->setSequenceFunction(AgeFunc);
RateParticleGeneratorRecPtr ExampleParticleGenerator = 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(40.0f);
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
ParticleNodeCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT);
NodeRefPtr ParticleNode = 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 = makeCoredNode<Group>();
scene->addChild(ParticleNode);
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
&sceneManager,
AgeFunc.get()));
sceneManager.setRoot(scene);
// 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,
"05a - QuadSequenceParticleDrawer");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}