Mogre学习笔记(二)

Section 2: Terrain, Sky, Fog, and the Root object

还是先给出代码:

using System;
using System.Windows.Forms;
using MogreFramework;
using Mogre;

namespace Tutorial03
{
static class Program
{
[STAThread]
static void Main()
{
try
{
MyOgreWindow win = new MyOgreWindow();
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 MyOgreWindow : OgreWindow
{
protected override void CreateSceneManager()
{
SceneManager = Root.CreateSceneManager(SceneType.ST_EXTERIOR_CLOSE);
}

protected override void CreateCamera()
{
Camera = this.SceneManager.CreateCamera("PlayerCam");
Camera.Position = new Vector3(0, 10, 500);
Camera.LookAt(Vector3.ZERO);
Camera.NearClipDistance = 5;

}

protected override void CreateViewport()
{
Viewport = this.RenderWindow.AddViewport(Camera);
Camera.AspectRatio = Viewport.ActualWidth / Viewport.ActualHeight;

}

}

class SceneCreator
{
public SceneCreator(OgreWindow win)
{
win.SceneCreating += new OgreWindow.SceneEventHandler(SceneCreating);
}

void SceneCreating(OgreWindow win)
{
ColourValue fadeColour = new ColourValue(0.1f, 0.1f, 0.1f);
win.Viewport.BackgroundColour = fadeColour;
win.SceneManager.SetFog(FogMode.FOG_LINEAR, fadeColour, 0, 10, 150);
win.SceneManager.SetWorldGeometry("terrain.cfg");

Plane plane;
plane.d = 10;
plane.normal = Vector3.NEGATIVE_UNIT_Y;

win.SceneManager.SetSkyPlane(true, plane, "Examples/SpaceSkyPlane", 100, 45, true, 0.5f, 150, 150);

}
}
}

运行结果截图如下:

接下来,我们就对其做相应的解释:

Root

Root对象是OGRE的核心对象,在我的OGRE学习笔记中可以看到Root和其他对象的UML关系图。在本例中,我们需要用Root新建一个SceneManager,代码如下:

protected override void CreateSceneManager()
{
    SceneManager = Root.CreateSceneManager(SceneType.ST_EXTERIOR_CLOSE);
}

Terrain

在本例中,我们要改变MogreFramework原来提供的Terrain,SceneManager提供了SetWorldGeometry:

win.SceneManager.SetWorldGeometry("terrain.cfg");

Sky

  1. SkyBox: 一个巨大的立方体形的天空,它环绕在场景中所有的对象周围;
  2. SkyDome:类似于SkyBox,但是它是圆屋顶形,不会盖住地面;
  3. SkyPlane:它与SkyBox和SkyDome有很大的不同,是一个平面的天空。

本例中使用了SkyPlane,代码如下:

Plane plane;
plane.d = 10;
plane.normal = Vector3.NEGATIVE_UNIT_Y;

win.SceneManager.SetSkyPlane(true, plane, "Examples/SpaceSkyPlane", 100, 45, true, 0.5f, 150, 150);

Fog

Ogre中,Fog的使用非常简单, 主要有两种基本类型的Fog:

  1. linear:雾线性的变浓,
  2. exponential:雾指数级的变浓。

在本例中,使用了linear的Fog,代码如下:

ColourValue fadeColour = new ColourValue(0.1f, 0.1f, 0.1f);
win.Viewport.BackgroundColour = fadeColour;
win.SceneManager.SetFog(FogMode.FOG_LINEAR, fadeColour, 0, 10, 150);

按F5运行,可以看到以上结果了。

你可能感兴趣的:(JavaScript,windows,Blog,Go,UML)