Time for action — translating in local and parent space

  1. Clear the createScene() function once again.
  2. Insert a reference model; this time we will move it nearer to our camera so we don't have to move the camera so much:
    Ogre::Entity* ent = mSceneMgr->createEntity("MyEntity","Sinbad.mesh");
    Ogre::SceneNode* node = mSceneMgr->createSceneNode("Node1");
    node->setPosition(0,0,400);
    node->yaw(Ogre::Degree(180.0f));
    mSceneMgr->getRootSceneNode()->addChild(node);
    node->attachObject(ent);
    
  3. Add a second model and rotate it by 45 degrees around the y-axis and translate it (0,0,20) units in parent space:
    Ogre::Entity* ent2 = mSceneMgr->createEntity("MyEntity2","Sinbad.mesh");
    Ogre::SceneNode* node2 = node->createChildSceneNode("node2");
    node2->yaw(Ogre::Degree(45));
    node2->translate(0,0,20);
    node2->attachObject(ent2);
    
  4. Add a third model and also rotate it 45 degrees around the y-axis and translate it (0,0,20) units in local space:
    Ogre::Entity* ent3 = mSceneMgr->createEntity("MyEntity3","Sinbad.mesh");
    Ogre::SceneNode* node3 = node->createChildSceneNode("node3");
    node3->yaw(Ogre::Degree(45));
    node3->translate(0,0,20,Ogre::Node::TS_LOCAL);
    node3->attachObject(ent3);
    
  5. Compile and run the application. Then navigate the camera again so that you see the model from above.
    Time for action — translating in local and parent space

What just happened?

We created our reference model and then added two models which were rotated 45 degrees around the y-axis. Then we translated both with (0,0,20), one model in parent space, the default setting, and the other model in local space. The model we translated in parent space moved in a straight line on the z-axis. But because we rotated the models around the y-axis, the model we translated in local space moved with this rotation and ended up moving up and left in the image. Let's repeat this. When we translate, the default setting is parent space, meaning that all rotations, except the rotation of the scene node we translate, are used while translating. When using world space, no rotation is taken into consideration. When translating, the world coordination system is used. When translating in local space, every rotation, even the rotation from the node we translate, is used for the translation.

Pop quiz — Ogre 3D and spaces

Name three different spaces that Ogre 3D knows.

Have a go hero — adding symmetry

Change the rotation and translation of the MyEntity2 to make the image symmetric. Make sure you use the right space; otherwise, it's difficult to create a symmetric image. Here is how it should look afterwards:

Have a go hero — adding symmetry
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.143.65