本文整理汇总了C++中WindowEventProducerUnrecPtr::mainLoop方法的典型用法代码示例。如果您正苦于以下问题:C++ WindowEventProducerUnrecPtr::mainLoop方法的具体用法?C++ WindowEventProducerUnrecPtr::mainLoop怎么用?C++ WindowEventProducerUnrecPtr::mainLoop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WindowEventProducerUnrecPtr
的用法示例。
在下文中一共展示了WindowEventProducerUnrecPtr::mainLoop方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
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);
//Print key command info
std::cout << "\n\nKEY COMMANDS:" << std::endl;
std::cout << "CTRL-Q Exit\n\n" << std::endl;
//SkeletonDrawer System Material
LineChunkUnrecPtr ExampleLineChunk = LineChunk::create();
ExampleLineChunk->setWidth(2.0f);
ExampleLineChunk->setSmooth(true);
BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create();
ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f));
ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f));
ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
ExampleMaterial->addChunk(ExampleLineChunk);
ExampleMaterial->addChunk(ExampleMaterialChunk);
ExampleMaterial->addChunk(ExampleBlendChunk);
//Joint Node Hierarchy
NodeRecPtr ExampleJointNode;
//Create a new skeleton
SkeletonBlendedGeometryRecPtr ExampleSkeleton;
//Load skeleton from an XML file
FCFileType::FCPtrStore NewContainers;
NewContainers = FCFileHandler::the()->read(BoostPath("./Data/14Skeleton.xml"));
FCFileType::FCPtrStore::iterator Itor;
for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
{
//We only want the skeleton; ignore anything else saved in the XML file
if( (*Itor)->getType() == (SkeletonBlendedGeometry::getClassType()))
{
ExampleSkeleton = (dynamic_pointer_cast<SkeletonBlendedGeometry>(*Itor));
}
if( (*Itor)->getType() == (Node::getClassType()) &&
(dynamic_pointer_cast<Node>(*Itor)->getParent() == NULL))
{
ExampleJointNode = (dynamic_pointer_cast<Node>(*Itor));
}
}
//SkeletonDrawer
SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
ExampleSkeletonDrawable->setMaterial(ExampleMaterial);
//Skeleton Node
NodeUnrecPtr SkeletonNode = Node::create();
SkeletonNode->setCore(ExampleSkeletonDrawable);
// Make Main Scene Node and add the Torus
NodeUnrecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(SkeletonNode);
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,
"14SkeletonLoader");
//Main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例2: main
// Initialize WIN32 & OpenSG and set up the scene
int main(int argc, char **argv)
{
std::cout << "\n\nKEY COMMANDS:" << std::endl
<< "1-9 Play Sounds 1-9" << std::endl
<< "p Pause Sounds" << std::endl
<< "u Unpause Sounds" << std::endl
<< "- Decrease Sound Group Volume" << std::endl
<< "= Increase Sound Group Volume" << std::endl
<< "CTRL-Q Exit\n\n" << std::endl;
// OSG init
osgInit(argc,argv);
TheWindowEventProducer = createNativeWindow();
TheWindowEventProducer->initWindow();
TheWindowEventProducer->setDisplayCallback(display);
TheWindowEventProducer->setReshapeCallback(reshape);
//Attach Mouse Listener
TutorialMouseListener TheTutorialMouseListener;
MouseEventConnection = TheWindowEventProducer->addMouseListener(&TheTutorialMouseListener);
//Attach Key Listener
TutorialKeyListener TheTutorialKeyListener;
TheWindowEventProducer->addKeyListener(&TheTutorialKeyListener);
//Attach MouseMotion Listener
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TheWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener);
// create the scene
NodeUnrecPtr scene = makeTorus(1.0, 2.0, 16, 16);
// create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// tell the manager what to manage
mgr->setWindow(TheWindowEventProducer );
mgr->setRoot (scene);
// show the whole scene
mgr->showAll();
//Load Sound Definitions
FCFileType::FCPtrStore NewContainers;
NewContainers = FCFileHandler::the()->read(BoostPath("Data/04SoundData.xml"));
FCFileType::FCPtrStore::iterator Itor;
TutorialSoundListener TheSoundListerner;
for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
{
//Get Sounds
if( (*Itor)->getType().isDerivedFrom(Sound::getClassType()))
{
Sounds.push_back(dynamic_pointer_cast<Sound>(*Itor));
dynamic_pointer_cast<Sound>(*Itor)->addSoundListener(&TheSoundListerner);
}
//Get Sound Groups
if( (*Itor)->getType().isDerivedFrom(SoundGroup::getClassType()))
{
SoundGroups.push_back(dynamic_pointer_cast<SoundGroup>(*Itor));
}
}
//Initialize the Sound Manager
SoundManager::the()->attachUpdateProducer(TheWindowEventProducer);
SoundManager::the()->setCamera(mgr->getCamera());
Vec2f WinSize(TheWindowEventProducer->getDesktopSize() * 0.85f);
Pnt2f WinPos((TheWindowEventProducer->getDesktopSize() - WinSize) *0.5);
TheWindowEventProducer->openWindow(WinPos,
WinSize,
"04 XML Sound Loading Window");
//Enter main loop
TheWindowEventProducer->mainLoop();
osgExit();
return 0;
}
示例3: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
//Add Window Listener
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);
//Shader Material
BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
//Material Chunk
MaterialChunkUnrecPtr ShaderMaterialChunk = MaterialChunk::create();
ShaderMaterialChunk->setAmbient(Color4f(0.4f,0.4f,0.4f,1.0f));
ShaderMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
ShaderMaterialChunk->setSpecular(Color4f(1.0f,1.0f,1.0f,1.0f));
//Shader Chunk
SimpleSHLChunkUnrecPtr TheSHLChunk = SimpleSHLChunk::create();
TheSHLChunk->setVertexProgram(createSHLVertexProg());
TheSHLChunk->setFragmentProgram(createSHLFragProg());
//Color Parameter
ShaderVariableVec4fUnrecPtr Color1Parameter = ShaderVariableVec4f::create();
Color1Parameter->setName("Color1");
Color1Parameter->setValue(Vec4f(0.0f,1.0f,0.0f,1.0f));
ShaderVariableVec4fUnrecPtr Color2Parameter = ShaderVariableVec4f::create();
Color2Parameter->setName("Color2");
Color2Parameter->setValue(Vec4f(1.0f,1.0f,1.0f,1.0f));
//Shader Parameter Chunk
SHLParameterChunkUnrecPtr SHLParameters = SHLParameterChunk::create();
SHLParameters->getParameters().push_back(Color1Parameter);
SHLParameters->getParameters().push_back(Color2Parameter);
SHLParameters->setSHLChunk(TheSHLChunk);
ChunkMaterialUnrecPtr ShaderMaterial = ChunkMaterial::create();
ShaderMaterial->addChunk(ShaderMaterialChunk);
ShaderMaterial->addChunk(TheSHLChunk);
ShaderMaterial->addChunk(SHLParameters);
//Torus Node
GeometryUnrecPtr TorusGeometry = makeTorusGeo(5.0f,20.0f, 32,32);
TorusGeometry->setMaterial(ShaderMaterial);
NodeUnrecPtr TorusNode = Node::create();
TorusNode->setCore(TorusGeometry);
// Make Main Scene Node
NodeUnrecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(TorusNode);
mgr->setRoot(scene);
// Show the whole Scene
mgr->showAll();
//Create the Animations
initAnimations(Color1Parameter, "value");
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"04ShaderAnimation");
//Main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例4: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
//Initialize Window
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
//Add Window Listener
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);
//Setup the Animation
setupAnimation();
//Box Geometry
GeometryUnrecPtr BoxGeometry = makeBoxGeo(1.0,1.0,1.0,1,1,1);
BoxGeometry->setMaterial(TheBoxMaterial);
NodeUnrecPtr BoxGeometryNode = Node::create();
BoxGeometryNode->setCore(BoxGeometry);
//Make Box Node
NodeUnrecPtr BoxNode = Node::create();
TransformUnrecPtr BoxNodeTrans;
BoxNodeTrans = Transform::create();
BoxNode->setCore(BoxNodeTrans);
BoxNode->addChild(BoxGeometryNode);
//Make Main Scene Node
NodeUnrecPtr scene = Node::create();
ComponentTransformUnrecPtr Trans;
Trans = ComponentTransform::create();
scene->setCore(Trans);
// add the torus as a child
scene->addChild(BoxNode);
// tell the manager what to manage
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,
"05TextureAnimation");
//Main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例5: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
//Add Window Listener
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
//Initialize Window
TutorialWindow->initWindow();
//Torus Material
TheTorusMaterial = SimpleMaterial::create();
dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setAmbient(Color3f(0.2,0.2,0.2));
dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setDiffuse(Color3f(0.7,0.7,0.7));
dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setSpecular(Color3f(0.7,0.7,0.7));
dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setShininess(100.0f);
//Torus Geometry
GeometryRefPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32);
TorusGeometry->setMaterial(TheTorusMaterial);
NodeRefPtr TorusGeometryNode = Node::create();
TorusGeometryNode->setCore(TorusGeometry);
//Make Torus Node
NodeRefPtr TorusNode = Node::create();
TorusNodeTrans = Transform::create();
setName(TorusNodeTrans, std::string("TorusNodeTransformationCore"));
TorusNode->setCore(TorusNodeTrans);
TorusNode->addChild(TorusGeometryNode);
//Make Main Scene Node
NodeRefPtr scene = Node::create();
Trans = ComponentTransform::create();
setName(Trans, std::string("MainTransformationCore"));
scene->setCore(Trans);
scene->addChild(TorusNode);
setupAnimation();
commitChanges();
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
// tell the manager what to manage
mgr->setRoot (scene);
// show the whole scene
mgr->showAll();
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"OpenSG 02TransformAnimation Window");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例6: main
//.........这里部分代码省略.........
ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
ExampleMaterial->addChunk(ExampleLineChunk);
ExampleMaterial->addChunk(ExampleMaterialChunk);
ExampleMaterial->addChunk(ExampleBlendChunk);
GeometryRefPtr SphereGeometry = makeSphereGeo(2, 0.25f);
GeometryRefPtr BoxGeometry = makeBoxGeo(0.5f,0.5f,0.5f,1,1,1);
//Skeleton
SkeletonBlendedGeometryUnrecPtr ExampleSkeleton = SkeletonBlendedGeometry::create();
//Joint
TransformRecPtr ExampleRootJoint = Transform::create();
NodeRecPtr ExampleRootJointNode = makeNodeFor(ExampleRootJoint);
//Add this joint to the skeleton
ExampleSkeleton->pushToJoints(ExampleRootJointNode, Matrix());
NodeRecPtr TempRootJointNode = ExampleRootJointNode;
NodeRefPtr GeoNode = makeNodeFor(BoxGeometry);
TempRootJointNode->addChild(GeoNode);
Matrix TempMat;
//Create a set of randomly placed child joints
for (Real32 i = 0.0f; i < 5.0f; ++i)
{
TransformRecPtr ExampleChildJoint = Transform::create();
NodeRecPtr ExampleChildJointNode = makeNodeFor(ExampleChildJoint);
GeoNode = makeNodeFor(SphereGeometry);
ExampleChildJointNode->addChild(GeoNode);
//TempMat.setTranslate(RandomPoolManager::getRandomReal32(0.0, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f));
switch((static_cast<UInt32>(i) % 3))
{
case 0:
TempMat.setTranslate(2.0f,0.0f,0.0f);
break;
case 1:
TempMat.setTranslate(0.0f,2.0f,0.0f);
break;
case 2:
TempMat.setTranslate(0.0f,0.0f,2.0f);
break;
}
//Set bind and current transformations to TempMat (calculated above)
ExampleChildJoint->setMatrix(TempMat);
//Add ExampleChildJoint as a child to the previous joint
TempRootJointNode->addChild(ExampleChildJointNode);//add a Child to the root joint
//ExampleChildJoint will be the next parent joint
TempRootJointNode = ExampleChildJointNode;
//Add this joint to the skeleton
Matrix InvBind(TempRootJointNode->getToWorld());
InvBind.invert();
ExampleSkeleton->pushToJoints(ExampleChildJointNode, InvBind);
}
//SkeletonDrawer
SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
ExampleSkeletonDrawable->setMaterial(ExampleMaterial);
//Skeleton Particle System Node
NodeUnrecPtr SkeletonNode = Node::create();
SkeletonNode->setCore(ExampleSkeletonDrawable);
// Make Main Scene Node and add the Torus
NodeUnrecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(SkeletonNode);
scene->addChild(ExampleRootJointNode);
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,
"10SkeletonDrawer");
//Main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例7: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
//Add Window Listener
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);
//SkeletonDrawer System Material
LineChunkUnrecPtr ExampleLineChunk = LineChunk::create();
ExampleLineChunk->setWidth(2.0f);
ExampleLineChunk->setSmooth(true);
BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create();
ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f));
ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f));
ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
ExampleMaterial->addChunk(ExampleLineChunk);
//Read skeleton from XML file
FCFileType::FCPtrStore NewContainers;
NewContainers = FCFileHandler::the()->read(BoostPath("./Data/16Skeleton.xml"));
SkeletonUnrecPtr ExampleSkeleton;
FCFileType::FCPtrStore::iterator Itor;
for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
{
//Only import skeleton data; we ignore anything else saved in the XML file
if( (*Itor)->getType() == (Skeleton::getClassType()))
{
//Set the Skeleton to the one we just read in
ExampleSkeleton = (dynamic_pointer_cast<Skeleton>(*Itor));
}
}
//SkeletonDrawer
SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
ExampleSkeletonDrawable->setMaterial(ExampleMaterial);
//Skeleton Particle System Node
NodeUnrecPtr SkeletonNode = Node::create();
SkeletonNode->setCore(ExampleSkeletonDrawable);
//Torus Node
NodeUnrecPtr TorusNode = makeTorus(.5, 2, 32, 32);
// Make Main Scene Node and add the Torus
NodeUnrecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(SkeletonNode);
//scene->addChild(TorusNode);
scene->addChild(makeCoordAxis(10.0));
mgr->setRoot(scene);
mgr->turnHeadlightOff();
// Show the whole Scene
mgr->showAll();
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"16LoadXMLSkeleton");
//Enter main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
//.........这里部分代码省略.........
示例8: main
//.........这里部分代码省略.........
SkeletonBlendedGeometryUnrecPtr ExampleSkeleton = SkeletonBlendedGeometry::create();
//Joint
JointRecPtr ExampleRootJoint = Joint::create();
//Add this joint to the skeleton
ExampleSkeleton->pushToJoints(ExampleRootJoint, Matrix());
NodeRecPtr ExampleRootJointNode = makeNodeFor(ExampleRootJoint);
NodeRecPtr TempRootJointNode = ExampleRootJointNode;
NodeRefPtr GeoNode = makeNodeFor(BoxGeometry);
TempRootJointNode->addChild(GeoNode);
Matrix TempMat;
//Create a set of randomly placed child joints
for (Real32 i = 0.0f; i < 5.0f; ++i)
{
JointRecPtr ExampleChildJoint = Joint::create();
NodeRecPtr ExampleChildJointNode = makeNodeFor(ExampleChildJoint);
GeoNode = makeNodeFor(SphereGeometry);
ExampleChildJointNode->addChild(GeoNode);
//TempMat.setTranslate(RandomPoolManager::getRandomReal32(0.0, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f));
switch((static_cast<UInt32>(i) % 3))
{
case 0:
TempMat.setTranslate(2.0f,0.0f,0.0f);
break;
case 1:
TempMat.setTranslate(0.0f,2.0f,0.0f);
break;
case 2:
TempMat.setTranslate(0.0f,0.0f,2.0f);
break;
}
//Set bind and current transformations to TempMat (calculated above)
ExampleChildJoint->setJointTransformation(TempMat);
//Add ExampleChildJoint as a child to the previous joint
TempRootJointNode->addChild(ExampleChildJointNode);//add a Child to the root joint
//ExampleChildJoint will be the next parent joint
TempRootJointNode = ExampleChildJointNode;
//Add this joint to the skeleton
Matrix InvBind(TempRootJointNode->getToWorld());
InvBind.invert();
ExampleSkeleton->pushToJoints(ExampleChildJoint, InvBind);
}
//SkeletonDrawer
SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
ExampleSkeletonDrawable->setMaterial(ExampleMaterial);
ExampleSkeletonDrawable->setDrawBindPose(false); //By default, we won't draw the skeleton's bind pose
ExampleSkeletonDrawable->setBindPoseColor(Color4f(0.0, 1.0, 0.0, 1.0)); //When the skeleton's bind pose is rendered, it will be green
ExampleSkeletonDrawable->setDrawPose(true); //By default, we do draw the skeleton's current pose
ExampleSkeletonDrawable->setPoseColor(Color4f(0.0, 0.0, 1.0, 1.0)); //The skeleton's current pose is rendered in blue
//Skeleton Node
SkeletonNode = Node::create();
SkeletonNode->setCore(ExampleSkeletonDrawable);
//Create scene
NodeUnrecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(SkeletonNode);
scene->addChild(ExampleRootJointNode);
mgr->setRoot(scene);
//Setup the Animation
setupAnimation(ExampleRootJoint,
dynamic_cast<Joint*>(ExampleRootJointNode->getChild(1)->getCore()));
//Set the currently playing animation to TheJointAnimation (can be switched at runtime via a key command)
TheCurrentAnimation = TheJointAnimation;
// 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,
"11BoneAnimation");
//Main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例9: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
//Add Window Listener
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);
//Torus Node
NodeUnrecPtr TorusGeometryNode = makeTorus(.5, 2, 32, 32);
//Make Torus Node
NodeUnrecPtr TorusNode = Node::create();
TransformUnrecPtr TorusNodeTrans;
TorusNodeTrans = Transform::create();
TorusNode->setCore(TorusNodeTrans);
TorusNode->addChild(TorusGeometryNode);
//Make Main Scene Node
NodeUnrecPtr scene = Node::create();
ComponentTransformUnrecPtr Trans;
Trans = ComponentTransform::create();
scene->setCore(Trans);
// add the torus as a child
scene->addChild(TorusNode);
//Make a gradient Background
TutorialBackground = GradientBackground::create();
TutorialBackground->addLine(Color3f(1.0,0.0,0.0),0.0);
TutorialBackground->addLine(Color3f(0.0,1.0,0.0),0.5);
TutorialBackground->addLine(Color3f(0.0,0.0,1.0),1.0);
setName(TutorialBackground, std::string("TutorialGradientBackground"));
setupAnimation();
// tell the manager what to manage
mgr->setRoot (scene);
mgr->getWindow()->getPort(0)->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,
"03MFieldAnimation");
//Main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例10: main
//.........这里部分代码省略.........
std::cout << "2 Play second example animation" << std::endl;
std::cout << "CTRL-Q Exit\n\n" << std::endl;
//SkeletonDrawer System Material
LineChunkUnrecPtr ExampleLineChunk = LineChunk::create();
ExampleLineChunk->setWidth(2.0f);
ExampleLineChunk->setSmooth(true);
BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create();
ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f));
ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f));
ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
ExampleMaterial->addChunk(ExampleLineChunk);
ExampleMaterial->addChunk(ExampleMaterialChunk);
ExampleMaterial->addChunk(ExampleBlendChunk);
//Joint
JointUnrecPtr ExampleRootJoint = Joint::create();
JointUnrecPtr TempRootJoint;
TempRootJoint = ExampleRootJoint;
Matrix TempMat;
//Create a set of randomly placed joints
for (Real32 i = 1.0f; i < 9.0f; i++)
{
JointUnrecPtr ExampleChildJoint;
TempMat.setTranslate(RandomPoolManager::getRandomReal32(0.0, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f));
ExampleChildJoint = Joint::create(); //create a joint called ExampleChildJoint
//Set ExampleChildJoint's current and bind transformations to TempMat (calculated above)
ExampleChildJoint->setRelativeTransformation(TempMat);
ExampleChildJoint->setBindRelativeTransformation(TempMat);
ExampleChildJoint->setUseParentTranslation(true);
//Add ExampleChildJoint as a child to the previously created joint
TempRootJoint->pushToChildJoints(ExampleChildJoint);//add a Child to the previous joint
//ExampleChildJoint will be the next parent joint
TempRootJoint = TempRootJoint->getChildJoints(0);
}
//Skeleton
SkeletonUnrecPtr ExampleSkeleton = Skeleton::create();
ExampleSkeleton->pushToRootJoints(ExampleRootJoint);
//SkeletonDrawer
SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
ExampleSkeletonDrawable->setMaterial(ExampleMaterial);
ExampleSkeletonDrawable->setDrawBindPose(false); //By default, we won't draw the skeleton's bind pose
ExampleSkeletonDrawable->setBindPoseColor(Color4f(0.0, 1.0, 0.0, 1.0)); //When the skeleton's bind pose is rendered, it will be green
ExampleSkeletonDrawable->setDrawPose(true); //By default, we do draw the skeleton's current pose
ExampleSkeletonDrawable->setPoseColor(Color4f(0.0, 0.0, 1.0, 1.0)); //The skeleton's current pose is rendered in blue
//Skeleton Node
SkeletonNode = Node::create();
SkeletonNode->setCore(ExampleSkeletonDrawable);
//Create scene
NodeUnrecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(SkeletonNode);
mgr->setRoot(scene);
//Setup the Animation
setupAnimation(ExampleRootJoint, ExampleRootJoint->getChildJoints(0));
//Set the currently playing animation to TheJointAnimation (can be switched at runtime via a key command)
TheCurrentAnimation = TheJointAnimation;
// 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,
"11BoneAnimation");
//Main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例11: main
//.........这里部分代码省略.........
ExampleSkeleton->addJointBlending(36,RightHand,1.0f);
ExampleSkeleton->addJointBlending(37,RightHand,1.0f);
ExampleSkeleton->addJointBlending(38,RightFingers,1.0f);
ExampleSkeleton->addJointBlending(39,RightFingers,1.0f);
//Left Hip
ExampleSkeleton->addJointBlending(40,Pelvis,1.0f);
ExampleSkeleton->addJointBlending(41,Pelvis,1.0f);
ExampleSkeleton->addJointBlending(42,LeftHip,1.0f);
ExampleSkeleton->addJointBlending(43,LeftHip,1.0f);
//Left Femur
ExampleSkeleton->addJointBlending(44,LeftHip,1.0f);
ExampleSkeleton->addJointBlending(45,LeftHip,1.0f);
ExampleSkeleton->addJointBlending(46,LeftKnee,1.0f);
ExampleSkeleton->addJointBlending(47,LeftKnee,1.0f);
//Left Tibia
ExampleSkeleton->addJointBlending(48,LeftKnee,1.0f);
ExampleSkeleton->addJointBlending(49,LeftKnee,1.0f);
ExampleSkeleton->addJointBlending(50,LeftFoot,1.0f);
ExampleSkeleton->addJointBlending(51,LeftFoot,1.0f);
//Left Foot
ExampleSkeleton->addJointBlending(52,LeftFoot,1.0f);
ExampleSkeleton->addJointBlending(53,LeftFoot,1.0f);
ExampleSkeleton->addJointBlending(54,LeftToes,1.0f);
ExampleSkeleton->addJointBlending(55,LeftToes,1.0f);
//Right Hip
ExampleSkeleton->addJointBlending(56,Pelvis,1.0f);
ExampleSkeleton->addJointBlending(57,Pelvis,1.0f);
ExampleSkeleton->addJointBlending(58,RightHip,1.0f);
ExampleSkeleton->addJointBlending(59,RightHip,1.0f);
//Right Femur
ExampleSkeleton->addJointBlending(60,RightHip,1.0f);
ExampleSkeleton->addJointBlending(61,RightHip,1.0f);
ExampleSkeleton->addJointBlending(62,RightKnee,1.0f);
ExampleSkeleton->addJointBlending(63,RightKnee,1.0f);
//Right Tibia
ExampleSkeleton->addJointBlending(64,RightKnee,1.0f);
ExampleSkeleton->addJointBlending(65,RightKnee,1.0f);
ExampleSkeleton->addJointBlending(66,RightFoot,1.0f);
ExampleSkeleton->addJointBlending(67,RightFoot,1.0f);
//Right Foot
ExampleSkeleton->addJointBlending(68,RightFoot,1.0f);
ExampleSkeleton->addJointBlending(69,RightFoot,1.0f);
ExampleSkeleton->addJointBlending(70,RightToes,1.0f);
ExampleSkeleton->addJointBlending(71,RightToes,1.0f);
MeshNode = Node::create();
MeshNode->setCore(ExampleSkeleton);
//Create scene node
NodeUnrecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(UnboundGeometry);
scene->addChild(SkeletonNode);
scene->addChild(MeshNode);
mgr->setRoot(scene);
//Setup the Animation
setupAnimation();
//Save to an xml file
FCFileType::FCPtrStore Containers;
Containers.insert(ExampleSkeleton);
Containers.insert(PelvisNode);
Containers.insert(TheSkeletonAnimation);
//Use an empty Ignore types vector
FCFileType::FCTypeVector IgnoreTypes;
//IgnoreTypes.push_back(Node::getClassType().getId());
//Write the Field Containers to a xml file
FCFileHandler::the()->write(Containers,BoostPath("./13Output.xml"),IgnoreTypes);
// 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,
"13MeshBlending");
//Main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例12: main
//.........这里部分代码省略.........
physicsSpace = PhysicsSweepAndPruneSpace::create();
CollisionContactParametersUnrecPtr DefaultCollisionParams = CollisionContactParameters::createEmpty();
DefaultCollisionParams->setMode(dContactApprox1 | dContactBounce);
DefaultCollisionParams->setMu(0.3);
DefaultCollisionParams->setMu2(0.0);
DefaultCollisionParams->setBounce(0.2);
DefaultCollisionParams->setBounceSpeedThreshold(0.1);
DefaultCollisionParams->setSoftCFM(0.1);
DefaultCollisionParams->setSoftERP(0.2);
DefaultCollisionParams->setMotion1(0.0);
DefaultCollisionParams->setMotion2(0.0);
DefaultCollisionParams->setMotionN(0.0);
DefaultCollisionParams->setSlip1(0.0);
DefaultCollisionParams->setSlip2(0.0);
physicsSpace->setDefaultCollisionParameters(DefaultCollisionParams);
physHandler = PhysicsHandler::create();
physHandler->setWorld(physicsWorld);
physHandler->pushToSpaces(physicsSpace);
physHandler->setUpdateNode(rootNode);
physHandler->attachUpdateProducer(TutorialWindow->editEventProducer());
rootNode->addAttachment(physHandler);
rootNode->addAttachment(physicsWorld);
rootNode->addAttachment(physicsSpace);
/************************************************************************/
/* create spaces, geoms and bodys */
/************************************************************************/
//create a group for our space
GroupUnrecPtr spaceGroup;
spaceGroupNode = makeCoredNode<Group>(&spaceGroup);
//create the ground plane
GeometryUnrecPtr plane;
NodeUnrecPtr planeNode = makeBox(30.0, 30.0, 1.0, 1, 1, 1);
plane = dynamic_cast<Geometry*>(planeNode->getCore());
//and its Material
SimpleMaterialUnrecPtr plane_mat = SimpleMaterial::create();
plane_mat->setAmbient(Color3f(0.7,0.7,0.7));
plane_mat->setDiffuse(Color3f(0.9,0.6,1.0));
plane->setMaterial(plane_mat);
//create Physical Attachments
PhysicsBoxGeomUnrecPtr planeGeom = PhysicsBoxGeom::create();
planeGeom->setLengths(Vec3f(30.0, 30.0, 1.0));
//add geoms to space for collision
planeGeom->setSpace(physicsSpace);
//add Attachments to nodes...
spaceGroupNode->addAttachment(physicsSpace);
spaceGroupNode->addChild(planeNode);
planeNode->addAttachment(planeGeom);
scene->addChild(spaceGroupNode);
//Create Statistics Foreground
SimpleStatisticsForegroundUnrecPtr PhysicsStatForeground = SimpleStatisticsForeground::create();
PhysicsStatForeground->setSize(25);
PhysicsStatForeground->setColor(Color4f(0,1,0,0.7));
PhysicsStatForeground->addElement(PhysicsHandler::statPhysicsTime,
"Physics time: %.3f s");
PhysicsStatForeground->addElement(PhysicsHandler::statCollisionTime,
"Collision time: %.3f s");
PhysicsStatForeground->addElement(PhysicsHandler::statSimulationTime,
"Simulation time: %.3f s");
PhysicsStatForeground->addElement(PhysicsHandler::statNCollisions,
"%d collisions");
PhysicsStatForeground->addElement(PhysicsHandler::statNCollisionTests,
"%d collision tests");
PhysicsStatForeground->addElement(PhysicsHandler::statNPhysicsSteps,
"%d simulation steps per frame");
// tell the manager what to manage
mgr->setRoot (rootNode);
mgr->getWindow()->getPort(0)->addForeground(PhysicsStatForeground);
physHandler->setStatistics(PhysicsStatForeground->getCollector());
// show the whole rootNode
mgr->showAll();
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"05Explosion");
//Enter main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例13: main
//.........这里部分代码省略.........
LeftFoot->pushToChildJoints(LeftToes);
/*================================================================================================*/
/* Right Foot */
RightFoot = Joint::create(); //create a joint called RightFoot
TempMat.setTranslate(0.0,-3.0,0.0);
RightFoot->setRelativeTransformation(TempMat);
RightFoot->setBindRelativeTransformation(TempMat);
RightFoot->pushToChildJoints(RightToes);
/*================================================================================================*/
/* Left Knee */
LeftKnee = Joint::create(); //create a joint called LeftKnee
TempMat.setTranslate(0.0,-3.0,0.0);
LeftKnee->setRelativeTransformation(TempMat);
LeftKnee->setBindRelativeTransformation(TempMat);
LeftKnee->pushToChildJoints(LeftFoot);
/*================================================================================================*/
/* Right Knee */
RightKnee = Joint::create(); //create a joint called RightKnee
TempMat.setTranslate(0.0,-3.0,0.0);
RightKnee->setRelativeTransformation(TempMat);
RightKnee->setBindRelativeTransformation(TempMat);
RightKnee->pushToChildJoints(RightFoot);
/*================================================================================================*/
/* Left Hip */
LeftHip = Joint::create(); //create a joint called LeftHip
TempMat.setTranslate(1.0,-1.0,0.0);
LeftHip->setRelativeTransformation(TempMat);
LeftHip->setBindRelativeTransformation(TempMat);
LeftHip->pushToChildJoints(LeftKnee);
/*================================================================================================*/
/* Right Hip */
RightHip = Joint::create(); //create a joint called RightHip
TempMat.setTranslate(-1.0,-1.0,0.0);
RightHip->setRelativeTransformation(TempMat);
RightHip->setBindRelativeTransformation(TempMat);
RightHip->pushToChildJoints(RightKnee);
/*================================================================================================*/
/* Pelvis */
Pelvis = Joint::create(); //create a joint called Pelvis
TempMat.setTranslate(0.0,7.0,0.0);
Pelvis->setRelativeTransformation(TempMat);
Pelvis->setBindRelativeTransformation(TempMat);
Pelvis->pushToChildJoints(LeftHip);
Pelvis->pushToChildJoints(RightHip);
Pelvis->pushToChildJoints(Clavicle);
//Skeleton
ExampleSkeleton = Skeleton::create();
ExampleSkeleton->pushToRootJoints(Pelvis); //Set Pelvis as root joint of skeleton
//SkeletonDrawer
SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
ExampleSkeletonDrawable->setMaterial(ExampleMaterial);
ExampleSkeletonDrawable->setDrawBindPose(false); //Be default, we won't draw the skeleton's bind pose
ExampleSkeletonDrawable->setBindPoseColor(Color4f(0.0, 1.0, 0.0, 1.0)); //When drawn, the skeleton's bind pose renders green
ExampleSkeletonDrawable->setDrawPose(true); //Be default, we do draw the skeleton's current pose
ExampleSkeletonDrawable->setPoseColor(Color4f(0.0, 0.0, 1.0, 1.0)); //The skeleton's current pose renders blue
//Skeleton Node
SkeletonNode = Node::create();
SkeletonNode->setCore(ExampleSkeletonDrawable);
//Create scene
NodeUnrecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(SkeletonNode);
mgr->setRoot(scene);
//Setup the Animation
setupAnimation();
// 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,
"12SkeletonAnimation");
//Main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例14: main
// Initialize OpenSG and set up the scene
int main(int argc, char **argv)
{
//Print key command info
std::cout << "\n\nKEY COMMANDS:" << std::endl;
std::cout << "space Play/Pause the animation" << std::endl;
std::cout << "CTRL-Q Exit\n\n" << std::endl;
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
//Add Window Listener
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);
//Torus Geometry
TorusGeometry = makeTorusGeo(.5, 2, 16, 16);
NodeUnrecPtr TorusGeometryNode = Node::create();
TorusGeometryNode->setCore(TorusGeometry);
//Make Torus Node
NodeUnrecPtr TorusNode = Node::create();
TransformUnrecPtr TorusNodeTrans;
TorusNodeTrans = Transform::create();
setName(TorusNodeTrans, std::string("TorusNodeTransformationCore"));
TorusNode->setCore(TorusNodeTrans);
TorusNode->addChild(TorusGeometryNode);
//Make Main Scene Node
NodeUnrecPtr scene = Node::create();
//ComponentTransformUnrecPtr Trans;
//Trans = ComponentTransform::create();
//setName(Trans, std::string("MainTransformationCore"));
scene->setCore(Group::create());
// add the torus as a child
scene->addChild(TorusNode);
setupAnimation();
mgr->setRoot (scene);
// show the whole scene
mgr->showAll();
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"15LoadXMLAnimation");
//Enter main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}