本文整理汇总了C++中NodeUnrecPtr::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeUnrecPtr::addChild方法的具体用法?C++ NodeUnrecPtr::addChild怎么用?C++ NodeUnrecPtr::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeUnrecPtr
的用法示例。
在下文中一共展示了NodeUnrecPtr::addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doMain
//
// setup scene
//
static int doMain(int argc, char *argv[])
{
preloadSharedObject("OSGFileIO");
preloadSharedObject("OSGImageFileIO");
osgInit(argc,argv);
int winid = setupGLUT(&argc, argv);
win = GLUTWindow::create();
win->setGlutId(winid);
win->init();
if(argc < 2)
{
FWARNING(("No file given!\n"));
FWARNING(("Supported file formats:\n"));
std::list<const char*> suffixes;
SceneFileHandler::the()->getSuffixList(suffixes);
for(std::list<const char*>::iterator it = suffixes.begin();
it != suffixes.end();
++it)
{
FWARNING(("%s\n", *it));
}
staticScene = createStaticScene();
}
else
{
staticScene = SceneFileHandler::the()->read(argv[1]);
}
dynamicScene = createDynamicScene();
commitChanges();
mgr = SimpleSceneManager::create();
NodeUnrecPtr root = makeCoredNode<Group>();
root->addChild(staticScene);
mgr->setWindow(win);
mgr->setRoot (root);
GradientBackgroundUnrecPtr background = GradientBackground::create();
background->addLine(Color3f(0,0,0), 0);
background->addLine(Color3f(1,1,1), 1);
staticVp = win->getPort(0);
staticVp->setBackground(background);
camera = staticVp->getCamera();
mgr->showAll();
return 0;
}
示例2: getGlobal
void
ColladaLight::createAmbientLight(ColladaLightAmbientInstInfo *colInstInfo)
{
OSG_COLLADA_LOG(("ColladaLight::createAmbientLight\n"));
LightLoaderState *state =
getGlobal()->getLoaderStateAs<LightLoaderState>(_loaderStateName);
OSG_ASSERT(state != NULL);
ChunkOverrideGroupUnrecPtr coGroup = ChunkOverrideGroup::create();
NodeUnrecPtr coGroupN = makeNodeFor(coGroup);
coGroup->addChunk(state->getLightModelChunk());
Node *rootN = getGlobal()->getRoot();
while(rootN->getNChildren() > 0)
{
coGroupN->addChild(rootN->getChild(0));
}
if(getGlobal()->getOptions()->getCreateNameAttachments() == true)
{
setName(coGroupN, "OpenSG_AmbientLight");
}
rootN->addChild(coGroupN);
}
示例3: createStaticScene
//
// create an arbitrarly complex render scene
//
static NodeTransitPtr createStaticScene()
{
NodeUnrecPtr root = makeCoredNode<Group>();
typedef boost::mt19937 base_generator_type;
static base_generator_type generator(0);
static boost::uniform_01<float> value;
static boost::variate_generator< base_generator_type, boost::uniform_01<float> > die(generator, value);
for (int i = 0; i < max_tori; ++i) {
NodeUnrecPtr scene = makeTorus(.5, 2, 32, 32);
TransformUnrecPtr transformCore = Transform::create();
Matrix mat;
mat.setIdentity();
float x = 500.f * die();
float y = 500.f * die();
float z = 500.f * die();
float e1 = die();
float e2 = die();
float e3 = die();
Vec3f v(e1,e2,e3);
v.normalize();
float a = TwoPi * die();
Quaternion q(v, a);
mat.setTranslate(x,y,z);
mat.setRotate(q);
transformCore->setMatrix(mat);
NodeUnrecPtr trafo = makeNodeFor(transformCore);
trafo->addChild(scene);
root->addChild(trafo);
}
return NodeTransitPtr(root);
}
示例4: buildScene
NodeTransitPtr buildScene(void)
{
NodeUnrecPtr geoN = makeBox(1.f, 1.f, 1.f, 1, 1, 1);
ComponentTransformUnrecPtr xform = ComponentTransform::create();
NodeUnrecPtr xformN = makeNodeFor(xform);
setTargetId(xform, "xform0");
gXForm = xform;
NodeUnrecPtr groupN = makeCoredNode<Group>();
xformN->addChild(geoN );
groupN->addChild(xformN);
return NodeTransitPtr(groupN);
}
示例5: buildSphere
//////////////////////////////////////////////////////////////////////////
//! build a sphere
//////////////////////////////////////////////////////////////////////////
PhysicsBodyUnrecPtr buildSphere(void)
{
Real32 Radius((Real32)(rand()%2)*0.5+0.5);
Matrix m;
//create OpenSG mesh
GeometryUnrecPtr sphere;
NodeUnrecPtr sphereNode = makeSphere(2, Radius);
sphere = dynamic_cast<Geometry*>(sphereNode->getCore());
SimpleMaterialUnrecPtr sphere_mat = SimpleMaterial::create();
sphere_mat->setAmbient(Color3f(0.0,0.0,0.0));
sphere_mat->setDiffuse(Color3f(0.0,0.0,1.0));
sphere->setMaterial(sphere_mat);
TransformUnrecPtr sphereTrans;
NodeUnrecPtr sphereTransNode = makeCoredNode<Transform>(&sphereTrans);
m.setIdentity();
Real32 randX = (Real32)(rand()%10)-5.0;
Real32 randY = (Real32)(rand()%10)-5.0;
m.setTranslate(randX, randY, 10.0);
sphereTrans->setMatrix(m);
//create ODE data
PhysicsBodyUnrecPtr sphereBody = PhysicsBody::create(physicsWorld);
sphereBody->setPosition(Vec3f(randX, randY, 10.0));
sphereBody->setLinearDamping(0.0001);
sphereBody->setAngularDamping(0.0001);
sphereBody->setSphereMass(1.0,Radius);
PhysicsSphereGeomUnrecPtr sphereGeom = PhysicsSphereGeom::create();
sphereGeom->setBody(sphereBody);
sphereGeom->setSpace(physicsSpace);
sphereGeom->setRadius(Radius);
//add attachments
sphereNode->addAttachment(sphereGeom);
sphereTransNode->addAttachment(sphereBody);
sphereTransNode->addChild(sphereNode);
//add to SceneGraph
spaceGroupNode->addChild(sphereTransNode);
commitChanges();
return sphereBody;
}
示例6: buildBox
//////////////////////////////////////////////////////////////////////////
//! build a box
//////////////////////////////////////////////////////////////////////////
PhysicsBodyUnrecPtr buildBox(void)
{
Vec3f Lengths((Real32)(rand()%2)+1.0, (Real32)(rand()%2)+1.0, (Real32)(rand()%2)+1.0);
Matrix m;
//create OpenSG mesh
GeometryUnrecPtr box;
NodeUnrecPtr boxNode = makeBox(Lengths.x(), Lengths.y(), Lengths.z(), 1, 1, 1);
box = dynamic_cast<Geometry*>(boxNode->getCore());
SimpleMaterialUnrecPtr box_mat = SimpleMaterial::create();
box_mat->setAmbient(Color3f(0.0,0.0,0.0));
box_mat->setDiffuse(Color3f(0.0,1.0 ,0.0));
box->setMaterial(box_mat);
TransformUnrecPtr boxTrans;
NodeUnrecPtr boxTransNode = makeCoredNode<Transform>(&boxTrans);
m.setIdentity();
Real32 randX = (Real32)(rand()%10)-5.0;
Real32 randY = (Real32)(rand()%10)-5.0;
m.setTranslate(randX, randY, 10.0);
boxTrans->setMatrix(m);
//create ODE data
PhysicsBodyUnrecPtr boxBody = PhysicsBody::create(physicsWorld);
boxBody->setPosition(Vec3f(randX, randY, 10.0));
boxBody->setBoxMass(1.0, Lengths.x(), Lengths.y(), Lengths.z());
PhysicsBoxGeomUnrecPtr boxGeom = PhysicsBoxGeom::create();
boxGeom->setBody(boxBody);
boxGeom->setSpace(physicsSpace);
boxGeom->setLengths(Lengths);
//add attachments
boxNode->addAttachment(boxGeom);
boxTransNode->addAttachment(boxBody);
boxTransNode->addChild(boxNode);
//add to SceneGraph
spaceGroupNode->addChild(boxTransNode);
commitChanges();
return boxBody;
}
示例7: enableStaticScene
static void enableStaticScene()
{
win->subPortByObj(dynamicVp);
dynamicVp = nullptr;
NodeUnrecPtr root = makeCoredNode<Group>();
root->addChild(staticScene);
mgr->setRoot(root);
mgr->getNavigator()->setViewport(staticVp);
staticVp->setCamera(camera);
win->addPort(staticVp);
}
示例8: buildBox
PhysicsBodyUnrecPtr buildBox(const Pnt3f& Position,
const Vec3f& Dimensions,
const Color3f& Color,
Node* const spaceGroupNode,
PhysicsWorld* const physicsWorld,
PhysicsHashSpace* const physicsSpace)
{
Matrix m;
//create OpenSG mesh
GeometryUnrecPtr box;
NodeUnrecPtr boxNode = makeBox(Dimensions.x(), Dimensions.y(), Dimensions.z(), 1, 1, 1);
box = dynamic_cast<Geometry*>(boxNode->getCore());
SimpleMaterialUnrecPtr box_mat = SimpleMaterial::create();
box_mat->setAmbient(Color3f(0.0,0.0,0.0));
box_mat->setDiffuse(Color);
box->setMaterial(box_mat);
TransformUnrecPtr boxTrans;
NodeUnrecPtr boxTransNode = makeCoredNode<Transform>(&boxTrans);
m.setIdentity();
m.setTranslate(Position);
boxTrans->setMatrix(m);
//create ODE data
PhysicsBodyUnrecPtr boxBody = PhysicsBody::create(physicsWorld);
boxBody->setPosition(Vec3f(Position));
boxBody->setBoxMass(1.0,Dimensions.x(), Dimensions.y(), Dimensions.z());
boxBody->setLinearDamping(0.0001);
boxBody->setAngularDamping(0.0001);
PhysicsBoxGeomUnrecPtr boxGeom = PhysicsBoxGeom::create();
boxGeom->setBody(boxBody);
boxGeom->setSpace(physicsSpace);
boxGeom->setLengths(Dimensions);
//add attachments
boxNode->addAttachment(boxGeom);
boxTransNode->addAttachment(boxBody);
boxTransNode->addChild(boxNode);
//add to SceneGraph
spaceGroupNode->addChild(boxTransNode);
return boxBody;
}
示例9: createDynamicViewport
static void createDynamicViewport()
{
win->subPortByObj(staticVp);
FBOBackgroundUnrecPtr fboBckgnd = FBOBackground::create();
fboBckgnd->setFrameBufferObject(spSimpleFBO->fbo());
NodeUnrecPtr root = makeCoredNode<Group>();
root->addChild(dynamicScene);
mgr->setRoot(root);
dynamicVp = Viewport::create();
dynamicVp->setRoot (rootNode(root));
dynamicVp->setBackground(fboBckgnd);
dynamicVp->setCamera (camera);
dynamicVp->setSize (0,0, 1,1);
mgr->getNavigator()->setViewport(dynamicVp);
win->addPort(dynamicVp);
mgr->update();
}
示例10: main
int main (int argc, char **argv)
{
osgInit(argc,argv);
// GLUT init
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize (uiSize, uiSize);
glutInitWindowPosition(100,100);
int winid = glutCreateWindow("OpenSG");
glutKeyboardFunc(key);
glutVisibilityFunc(vis);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutIdleFunc(display);
// OSG
SceneFileHandler::the()->print();
// create the graph
// beacon for camera and light
NodeUnrecPtr b1n = Node::create();
GroupUnrecPtr b1 = Group::create();
b1n->setCore( b1 );
// transformation
NodeUnrecPtr t1n = Node::create();
TransformUnrecPtr t1 = Transform::create();
t1n->setCore (t1 );
t1n->addChild(b1n);
cam_trans = t1;
// light
NodeUnrecPtr dlight = Node::create();
DirectionalLightUnrecPtr dl = DirectionalLight::create();
{
dlight->setCore(dl);
dl->setAmbient( .0, .0, .0, 1 );
dl->setDiffuse( .8, .8, .8, .8 );
dl->setDirection(0,0,1);
dl->setBeacon( b1n);
}
// root
root = Node:: create();
GroupUnrecPtr gr1 = Group::create();
root->setCore (gr1 );
root->addChild(t1n );
root->addChild(dlight);
// Load the file
NodeUnrecPtr file = NULL;
if(argc > 1)
{
file = SceneFileHandler::the()->read(argv[1], NULL);
}
if(file == NULL)
{
std::cerr << "Couldn't load file, ignoring" << std::endl;
file = makeSphere(4, 20.0);
}
Thread::getCurrentChangeList()->commitChanges();
file->updateVolume();
Vec3f min,max;
file->getVolume().getBounds(min, max);
std::cout << "Volume: from " << min << " to " << max << std::endl;
scene_trans = Transform::create();
NodeUnrecPtr sceneTrN = Node::create();
sceneTrN->setCore (scene_trans);
sceneTrN->addChild(file );
ref_trans = Transform::create();
//.........这里部分代码省略.........
示例11: 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;
}
示例12: main
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));
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get()));
//Shader Chunk
SimpleSHLChunkUnrecPtr TheSHLChunk = SimpleSHLChunk::create();
TheSHLChunk->setVertexProgram(createSHLVertexProg());
TheSHLChunk->setFragmentProgram(createSHLFragProg());
//TheSHLChunk->addUniformVariable("Color1",Vec4f(0.0f,1.0f,0.0f,1.0f));
//TheSHLChunk->addUniformVariable("Color2",Vec4f(1.0f,1.0f,1.0f,1.0f));
//Shader Parameter Chunk
SimpleSHLVariableChunkUnrecPtr SHLParameters = SimpleSHLVariableChunk::create();
//Color Parameter
SHLParameters->addUniformVariable("Color1",Vec4f(0.0f,1.0f,0.0f,1.0f));
SHLParameters->addUniformVariable("Color2",Vec4f(1.0f,1.0f,1.0f,1.0f));
ChunkMaterialUnrecPtr ShaderMaterial = ChunkMaterial::create();
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);
sceneManager.setRoot(scene);
// Show the whole Scene
sceneManager.showAll();
//Create the Animations
ShaderVariableVec4fUnrecPtr Color1Parameter;
ShaderVariableVec4fUnrecPtr Color2Parameter;
Color1Parameter = dynamic_cast<ShaderVariableVec4f*>(const_cast<ShaderVariable*>(SHLParameters->getVariables()->getVariable("Color1")));
Color2Parameter = dynamic_cast<ShaderVariableVec4f*>(const_cast<ShaderVariable*>(SHLParameters->getVariables()->getVariable("Color2")));
commitChanges();
AnimationUnrecPtr TheAnimation = setupAnimation(Color1Parameter, "value");
TheAnimation->attachUpdateProducer(TutorialWindow);
TheAnimation->start();
//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;
}
示例13: createAcquisitionStage
//
// setup of the image generation stage
//
static void createAcquisitionStage()
{
size_t num_ports = win->getMFPort()->size();
if (num_ports == 0)
return;
UInt32 width = win->getWidth();
UInt32 height = win->getHeight();
Real32 a = Real32(width) / Real32(height);
width = UInt32(a*height);
Viewport* vp = staticVp;
Node* internalRoot = rootNode(mgr->getRoot());
//
// Setup the FBO
//
spSimpleFBO.reset(new SimpleFBO(width, height, true, true, true, false));
//spSimpleFBO->fbo()->setPostProcessOnDeactivate(true);
//spSimpleFBO->colorBuffer(0)->setReadBack(true);
//
// We would like to render the scene but won't detach it from its parent.
// The VisitSubTree allows just that.
//
VisitSubTreeUnrecPtr visitor = VisitSubTree::create();
visitor->setSubTreeRoot(internalRoot);
NodeUnrecPtr visit_node = makeNodeFor(visitor);
//
// The stage object does provide a render target for the frame buffer attachment.
// SimpleStage has a camera, a background and the left, right, top, bottom
// fields to let you restrict rendering to a sub-rectangle of your FBO, i.e.
// they give you a viewport.
//
SimpleStageUnrecPtr stage = SimpleStage::create();
stage->setRenderTarget(spSimpleFBO->fbo());
stage->setCamera (vp->getCamera());
stage->setBackground (vp->getBackground());
//
// Give the stage core a place to live
//
NodeUnrecPtr stage_node = makeNodeFor(stage);
stage_node->addChild(visit_node);
//
// root
// |
// +- SimpleStage
// |
// +- VisitSubTree -> ApplicationScene
//
NodeUnrecPtr root = makeCoredNode<Group>();
root->addChild(stage_node);
//
// Give the root node a place to live, i.e. create a passive
// viewport and add it to the window.
//
ViewportUnrecPtr stage_viewport = PassiveViewport::create();
stage_viewport->setRoot (stage_node);
stage_viewport->setBackground(vp->getBackground());
stage_viewport->setCamera (vp->getCamera());
win->addPort(stage_viewport);
mgr->update();
win->renderNoFinish(mgr->getRenderAction());
win->frameExit();
win->deactivate ();
//ImageUnrecPtr col_image = Image::create();
//col_image->set(Image::OSG_RGBA_PF, width, height);
//TextureObjChunk* texObj = spSimpleFBO->colorTexObj(0);
//texObj->getImage()->subImage(0, 0, 0, width, height, 1, col_image);
//col_image->write("d:/my_Test_opensg.png");
win->subPortByObj(stage_viewport);
}
示例14: 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;
}
示例15: endEntity
/* Insert one or more shallow copies of a block (created by DXFBlock as
* Transform Group) into a layer (created by DXFLayer as MaterialGroup) or
* another block.
* \todo
* Could there be a INSERT inside a block referring to another block which has
* not been read yet? We then have to find a solution to enable deferred
* instantiation of INSERT entities :-(
*/
DXFResult DXFInsert::endEntity(void)
{
NodeUnrecPtr ctrafoNodeP = NULL;
// ComponentTransformUnrecPtr ctrafoCoreP = NULL;
TransformUnrecPtr ctrafoCoreP = NULL;
NodeUnrecPtr blockNodeP = NULL;
Node *parentNodeP = getParentNode();
StringToNodePtrMap::iterator itr = _blocksMapP->find(_blockName);
if (itr != _blocksMapP->end() && parentNodeP != NULL)
{
blockNodeP = itr->second;
// TODO: check fetched INSERT Data for consistency!
// Insert multiple times in a grid...
Vec3f offset(0.0, 0.0, 0.0);
for(Int16 column = 0; column < _columnCount; ++ column)
{
offset[0] = column * _columnSpacing;
for(Int16 row = 0; row < _rowCount; ++ row)
{
offset[1] = row * _rowSpacing;
// TODO: find out about DXF insert semantics!
ctrafoNodeP = Node::create();
ctrafoCoreP = Transform::create();
#if 0
beginEditCP(ctrafoCoreP);
#endif
{
if(_blockName == std::string("Rectangular Mullion - 64 x 128 rectangular-V1-Level 1"))
{
std::cout << blockNodeP->getNChildren() << std::endl;
}
OSG::TransformationMatrix<Real32> transMat;
transMat.setIdentity();
transMat.setTranslate(_insertionPoint + offset);
OSG::TransformationMatrix<Real32> rotMat;
rotMat.setIdentity();
OSG::Quaternion rot(OSG::Vec3f(0,0,1),osgDegree2Rad(_rotationAngle));
rotMat.setRotate(rot);
OSG::TransformationMatrix<Real32> scaleMat;
scaleMat.setIdentity();
scaleMat.setScale(_scaleFactor);
OSG::Vec3f vin(-40, 65, 0);
OSG::Vec3f vout;
transMat.mult(rotMat);
transMat.mult(scaleMat);
if(_extrusionDirection[2]<0)
{
transMat[0][0] *= -1.0;
transMat[1][0] *= -1.0;
transMat[2][0] *= -1.0;
transMat[3][0] *= -1.0;
}
ctrafoCoreP->setMatrix(transMat);
}
#if 0
endEditCP(ctrafoCoreP);
#endif
#if 0
beginEditCP(ctrafoNodeP);
#endif
{
ctrafoNodeP->setCore(ctrafoCoreP);
#if 0
ctrafoNodeP->addChild(blockNodeP->clone());
#endif
NodeUnrecPtr pClone = cloneTree(blockNodeP);
ctrafoNodeP->addChild(pClone);
}
#if 0
endEditCP(ctrafoNodeP);
#endif
#if 0
beginEditCP(parentNodeP);
#endif
{
parentNodeP->addChild(ctrafoNodeP);
}
#if 0
endEditCP(parentNodeP);
#endif
}
}
// Warn for details not implemented or assured yet! TODO: better
//.........这里部分代码省略.........