This time, we are going to use another model besides Sinbad: the ninja.
createScene()
function.Ogre::Entity* ent = mSceneMgr->createEntity("MyEntity","Sinbad.mesh"); Ogre::SceneNode* node = mSceneMgr->createSceneNode("Node1"); node->setPosition(10,10,0); mSceneMgr->getRootSceneNode()->addChild(node); node->attachObject(ent);
Ogre::Entity* ent2 = mSceneMgr->createEntity("MyEntitysNinja","ninja.mesh"); Ogre::SceneNode* node2 = node->createChildSceneNode("node2"); node2->setPosition(10,0,0); node2->setScale(0.02f,0.02f,0.02f); node2->attachObject(ent2);
node->setPosition(40,10,0);
node->yaw(Ogre::Degree(180.0f));
We created a sneaky ninja who follows each step of Sinbad. We made this possible because we added the node the ninja model is attached to as a child to the scene node Sinbad is attached to. When we moved Sinbad, we used his scene node, so each transform we did is also done to the ninja, because this scene node is the child of the node we modify, and as said before, the transformation of a parent is passed to all its children. This fact about scene nodes is extremely helpful to create the following models or complex scenes. Say, if we wanted to create a truck which carries a complete house, we could create the house using a lot of different models and scene nodes. At the end, we would have a scene node where the whole house and its interior are added as children too. Now when we want to move the house, we simply attach the house node to the truck or anything else, and if the truck moves, the complete house moves with it.
The arrows show the direction the transformations are propagated along the scene graph.
18.216.231.189