Mogre学习系列(2)基本概念The SceneNode, Entity, and SceneManager constructs

来源:互联网 发布:上海连尚网络 怎么样 编辑:程序博客网 时间:2024/06/05 11:03
  •  ScenceManager相当于一个显示控制器,所有在屏幕上显示的对象都通过它来管理。具体来说,ScenceManager保存了对象的track。关于ScenceManager的种类可以查看http://www.ogre3d.org/wiki/index.php/SceneManagersFAQ

 

  • Entity可以理解为Mogre世界里面的基本对象,所有的可视对象都是Entity,但是Entity只包含了对象本身的属性信息,并不包含方位信息,例如方位和朝向。

 

  • ScenceNode包含Entity的方位和朝向信息。为什么需要单独设置这个类来存放这些信息,而不是放在Entity中?初步猜测是因为对象的方位和朝向信息是Entity对象中经常发生变化的属性,可以通过单独的封装来隔离这种变换。当然了,由于不同的Entity可以使用同一个ScenceNode的信息,也可以达到共享的目的。需要注意的是,ScneceNode的位置信息都是相对于其parent ScenceNode而言的。

 参考代码:

 

 using System; using System.Collections.Generic; using System.Windows.Forms; using MogreFramework; using Mogre;  namespace Tutorial01 {     static class Program     {         [STAThread]         static void Main()         {             try             {                 OgreWindow win = new OgreWindow();                 new SceneCreator(win);                 win.Go();             }             catch (System.Runtime.InteropServices.SEHException)             {                 if (OgreException.IsThrown)                     MessageBox.Show(OgreException.LastException.FullDescription, "An Ogre exception has occurred!");                 else                     throw;             }         }     }      class SceneCreator     {         public SceneCreator(OgreWindow win)         {             win.SceneCreating += new OgreWindow.SceneEventHandler(SceneCreating);         }          void SceneCreating(OgreWindow win)         {             // Setting the ambient light             SceneManager mgr = win.SceneManager;             mgr.AmbientLight = new ColourValue(1, 1, 1);              // Adding Objects             Entity ent = mgr.CreateEntity("Robot", "robot.mesh");             SceneNode node = mgr.RootSceneNode.CreateChildSceneNode("RobotNode");             node.AttachObject(ent);              Entity ent2 = mgr.CreateEntity("Robot2", "robot.mesh");             SceneNode node2 = mgr.RootSceneNode.CreateChildSceneNode("RobotNode2", new Vector3(50, 0, 0));             node2.AttachObject(ent2);              // Translating Objects             node2.Position += new Vector3(10, 0, 10);             node.Position += new Vector3(25, 0, 0);              // Scaling Objects             node.Scale(.5f, 1, 2);             node2.Scale(1, 2, 1);              // Rotating Objects             Entity ent3 = mgr.CreateEntity("Robot3", "robot.mesh");             SceneNode node3 = mgr.RootSceneNode.CreateChildSceneNode("RobotNode3", new Vector3(100, 0, 0));             node3.AttachObject(ent3);              node.Pitch(new Degree(90));             node2.Yaw(new Degree(90));             node3.Roll(new Degree(90));         }     } }

原创粉丝点击