Axiom3D程序的基本渲染流程

 #region Namespace Declarations

 using System;
using System.Linq;
using Axiom.Core;
using Axiom.Framework.Configuration;
using Axiom.Graphics;
using Vector3 = Axiom.Math.Vector3; #endregion Namespace Declarations namespace Axiom.Framework
{
public abstract class Game : IDisposable, IWindowEventListener
{
protected Root Engine;
protected IConfigurationManager ConfigurationManager;
protected ResourceGroupManager Content;
protected SceneManager SceneManager;
protected Camera Camera;
protected Viewport Viewport;
protected RenderWindow Window;
protected Axiom.Graphics.RenderSystem RenderSystem;
protected SharpInputSystem.InputManager InputManager;
protected SharpInputSystem.Mouse mouse;
protected SharpInputSystem.Keyboard keyboard; public virtual void Run()
{
PreInitialize();
LoadConfiguration();
Initialize();
CreateRenderSystem();
CreateRenderWindow();
LoadContent();
CreateSceneManager();
CreateCamera();
CreateViewports();
CreateInput();
CreateScene();
this.Engine.StartRendering();
} private void PreInitialize()
{
this.ConfigurationManager = new DefaultConfigurationManager(); // instantiate the Root singleton
this.Engine = new Root( this.ConfigurationManager.LogFilename ); // add event handlers for frame events
this.Engine.FrameStarted += Engine_FrameRenderingQueued;
} public virtual void LoadConfiguration()
{
this.ConfigurationManager.RestoreConfiguration( this.Engine );
} private void Engine_FrameRenderingQueued( object source, FrameEventArgs e )
{
Update( e.TimeSinceLastFrame );
} public virtual void Initialize()
{
} public virtual void CreateRenderSystem()
{
if ( this.Engine.RenderSystem == null )
{
this.RenderSystem = this.Engine.RenderSystem = this.Engine.RenderSystems.First().Value;
}
else
{
this.RenderSystem = this.Engine.RenderSystem;
}
} public virtual void CreateRenderWindow()
{
this.Window = Root.Instance.Initialize( true, "Axiom Framework Window" ); WindowEventMonitor.Instance.RegisterListener( this.Window, this );
} public virtual void LoadContent()
{
ResourceGroupManager.Instance.InitializeAllResourceGroups();
} public virtual void CreateSceneManager()
{
// Get the SceneManager, a generic one by default
this.SceneManager = this.Engine.CreateSceneManager( "DefaultSceneManager", "GameSMInstance" );
this.SceneManager.ClearScene();
} public virtual void CreateCamera()
{
// create a camera and initialize its position
this.Camera = this.SceneManager.CreateCamera( "MainCamera" );
this.Camera.Position = new Vector3( , , );
this.Camera.LookAt( new Vector3( , , - ) ); // set the near clipping plane to be very close
this.Camera.Near = ; this.Camera.AutoAspectRatio = true;
} public virtual void CreateViewports()
{
// create a new viewport and set it's background color
this.Viewport = this.Window.AddViewport( this.Camera, , , 1.0f, 1.0f, );
this.Viewport.BackgroundColor = ColorEx.SteelBlue;
} public virtual void CreateInput()
{
var pl = new SharpInputSystem.ParameterList();
pl.Add( new SharpInputSystem.Parameter( "WINDOW", this.Window[ "WINDOW" ] ) ); if ( this.RenderSystem.Name.Contains( "DirectX" ) )
{
//Default mode is foreground exclusive..but, we want to show mouse - so nonexclusive
pl.Add( new SharpInputSystem.Parameter( "w32_mouse", "CLF_BACKGROUND" ) );
pl.Add( new SharpInputSystem.Parameter( "w32_mouse", "CLF_NONEXCLUSIVE" ) );
} //This never returns null.. it will raise an exception on errors
this.InputManager = SharpInputSystem.InputManager.CreateInputSystem( pl );
//mouse = InputManager.CreateInputObject<SharpInputSystem.Mouse>( true, "" );
//keyboard = InputManager.CreateInputObject<SharpInputSystem.Keyboard>( true, "" );
} public abstract void CreateScene(); public virtual void Update( float timeSinceLastFrame )
{
} #region IDisposable Implementation #region IsDisposed Property /// <summary>
/// Determines if this instance has been disposed of already.
/// </summary>
public bool IsDisposed { get; set; } #endregion IsDisposed Property /// <summary>
/// Class level dispose method
/// </summary>
/// <remarks>
/// When implementing this method in an inherited class the following template should be used;
/// protected override void dispose( bool disposeManagedResources )
/// {
/// if ( !IsDisposed )
/// {
/// if ( disposeManagedResources )
/// {
/// // Dispose managed resources.
/// }
///
/// // If there are unmanaged resources to release,
/// // they need to be released here.
/// }
///
/// // If it is available, make the call to the
/// // base class's Dispose(Boolean) method
/// base.dispose( disposeManagedResources );
/// }
/// </remarks>
/// <param name="disposeManagedResources">True if Unmanaged resources should be released.</param>
protected virtual void dispose( bool disposeManagedResources )
{
if ( !IsDisposed )
{
if ( disposeManagedResources )
{
if ( this.Engine != null )
{
// remove event handlers
this.Engine.FrameStarted -= Engine_FrameRenderingQueued;
}
if ( this.SceneManager != null )
{
this.SceneManager.RemoveAllCameras();
}
this.Camera = null;
if ( Root.Instance != null )
{
Root.Instance.RenderSystem.DetachRenderTarget( this.Window );
}
if ( this.Window != null )
{
WindowEventMonitor.Instance.UnregisterWindow( this.Window );
this.Window.Dispose();
}
if ( this.Engine != null )
{
this.Engine.Dispose();
}
} // There are no unmanaged resources to release, but
// if we add them, they need to be released here.
}
IsDisposed = true;
} /// <summary>
/// Call to when class is no longer needed
/// </summary>
public void Dispose()
{
dispose( true );
GC.SuppressFinalize( this );
} ~Game()
{
dispose( false );
} #endregion IDisposable Implementation #region IWindowEventListener Implementation /// <summary>
/// Window has moved position
/// </summary>
/// <param name="rw">The RenderWindow which created this event</param>
public void WindowMoved( RenderWindow rw )
{
} /// <summary>
/// Window has resized
/// </summary>
/// <param name="rw">The RenderWindow which created this event</param>
public void WindowResized( RenderWindow rw )
{
} /// <summary>
/// Window has closed
/// </summary>
/// <param name="rw">The RenderWindow which created this event</param>
public void WindowClosed( RenderWindow rw )
{
// Only do this for the Main Window
if ( rw == this.Window )
{
Root.Instance.QueueEndRendering();
}
} /// <summary>
/// Window lost/regained the focus
/// </summary>
/// <param name="rw">The RenderWindow which created this event</param>
public void WindowFocusChange( RenderWindow rw )
{
} #endregion
}
}

查看Run()方法。

public virtual void Run()
{
  PreInitialize();
  LoadConfiguration();//加载配置
  Initialize();
  CreateRenderSystem();//创建渲染系统
  CreateRenderWindow();//创建渲染窗体
  LoadContent();
  CreateSceneManager();//创建场景管理器
  CreateCamera();//设置相机
  CreateViewports();//设置视口
  CreateInput();
  CreateScene();//构建场景
  this.Engine.StartRendering();//开始渲染
}

基本流程:实例化Root,加载配置文件,创建渲染系统,创建渲染窗体,创建场景管理器,设置相机,设置视口,构建场景,开始渲染流程。

新建C#项目,命名为AppAxiom,添加引用Axiom.Engine。

新建类MyGame,继承自Game,编写代码如下:

  public class myGame : Game
{
public override void CreateScene()
{ SceneManager.SetSkyDome(true, "Examples/CloudySky", , );
SceneManager.AmbientLight = new ColorEx(0.3f, 0.3f, 0.3f);
SceneManager.CreateLight("ParticleSampleLight").Position = new Vector3(, , ); Entity ogreHead = SceneManager.CreateEntity("OgreHead", "ogrehead.mesh");
// Load muiltiple heads for box select and demonstrating single select with stacked objects
// create a scene node for each entity and attach the entity
SceneNode ogreHead1Node;
ogreHead1Node = SceneManager.RootSceneNode.CreateChildSceneNode("OgreHeadNode", Vector3.Zero, Quaternion.Identity);
ogreHead1Node.AttachObject(ogreHead); SceneNode ogreHead2Node;
Entity ogreHead2 = SceneManager.CreateEntity("OgreHead2", "ogrehead.mesh");
ogreHead2Node = SceneManager.RootSceneNode.CreateChildSceneNode("OgreHead2Node", new Vector3(-, , ),
Quaternion.Identity);
ogreHead2Node.AttachObject(ogreHead2); SceneNode ogreHead3Node;
Entity ogreHead3 = SceneManager.CreateEntity("OgreHead3", "ogrehead.mesh");
ogreHead3Node = SceneManager.RootSceneNode.CreateChildSceneNode("OgreHead3Node", new Vector3(+, , ),
Quaternion.Identity);
ogreHead3Node.AttachObject(ogreHead3); }
public override void CreateCamera()
{
// create a camera and initialize its position
this.Camera = this.SceneManager.CreateCamera("MainCamera");
this.Camera.Position = new Vector3(, , );
this.Camera.LookAt(new Vector3(, , )); // set the near clipping plane to be very close
this.Camera.Near = ;
this.Camera.AutoAspectRatio = true;
}
}

添加项目配置文件App.Config,内容如下:

 <?xml version="1.0"?>

 <configuration>
<configSections>
<section name="axiom" type="Axiom.Framework.Configuration.AxiomConfigurationSection, Axiom.Framework" />
</configSections>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
<axiom xmlns="http://www.axiom3d.net/schemas/configuration/v1.0">
<resourceLocations>
<!-- Resource Group : Essential -->
<resourceLocation type="ZipFile" group="Essential" path="../../media/archives/SdkTrays.zip" recurse="false" />
<resourceLocation type="Folder" group="Essential" path="../../media/thumbnails" recurse="false" />
<resourceLocation type="Folder" group="Essential" path="../../media/icons" recurse="false" /> <!-- Resource Group : Popular -->
<resourceLocation type="ZipFile" group="Popular" path="../../media/archives/cubemap.zip" recurse="false" />
<resourceLocation type="ZipFile" group="Popular" path="../../media/archives/cubemapsjs.zip" recurse="false" />
<!-- resourceLocation type="ZipFile" group="Popular" path="../../media/archives/dragon.zip" recurse="false" /-->
<!-- resourceLocation type="ZipFile" group="Popular" path="../../media/archives/fresneldemo.zip" recurse="false" /-->
<!-- resourceLocation type="ZipFile" group="Popular" path="../../media/archives/ogretestmap.zip" recurse="false" /-->
<resourceLocation type="ZipFile" group="Popular" path="../../media/archives/skybox.zip" recurse="false" />
<resourceLocation type="ZipFile" group="Popular" path="../../media/archives/sinbad.zip" recurse="false" />
<resourceLocation type="Folder" group="Popular" path="../../media/fonts" recurse="false" />
<resourceLocation type="Folder" group="Popular" path="../../media/programs" recurse="false" />
<resourceLocation type="Folder" group="Popular" path="../../media/materials" recurse="false" />
<resourceLocation type="Folder" group="Popular" path="../../media/particles" recurse="false" />
<resourceLocation type="Folder" group="Popular" path="../../media/textures" recurse="false" />
<resourceLocation type="Folder" group="Popular" path="../../media/meshes" recurse="false" />
<!-- resourceLocation type="Folder" group="Popular" path="../../media/deferredshadingmedia" recurse="false" / -->
<!-- resourceLocation type="Folder" group="Popular" path="../../media/pczappmedia" recurse="false" / -->
</resourceLocations>
<renderSystems>
<renderSystem name="Xna">
<options>
<option name="Video Mode" value="1280 x 720 @ 32-bit color" />
<option name="Full Screen" value="Yes" />
<option name="VSync" value="No" />
<option name="Anti aliasing" value="None" />
<option name="Floating-point mode" value="Fastest" />
<option name="Allow NVPerfHUD" value="No" />
<option name="Save Generated Shaders" value="No" />
<option name="Use Content Pipeline" value="No" />
</options>
</renderSystem>
<renderSystem name="DirectX9">
<options>
<option name="Video Mode" value="800 x 600 @ 32-bit colour" />
<option name="Full Screen" value="No" />
<option name="VSync" value="No" />
<option name="Anti aliasing" value="None" />
<option name="Floating-point mode" value="Fastest" />
<option name="Allow NVPerfHUD" value="No" />
</options>
</renderSystem>
<renderSystem name="OpenGL">
<options>
<option name="Video Mode" value="1280 x 720" />
<option name="Color Depth" value="" />
<option name="Display Frequency" value="N/A" />
<option name="Full Screen" value="Yes" />
<option name="FSAA" value="" />
<option name="VSync" value="No" />
<option name="RTT Preferred Mode" value="FBO" />
</options>
</renderSystem>
</renderSystems>
</axiom>
</configuration>

在Main方法下添加代码:

  static void Main()
{
myGame my = new myGame();
my.Run();
}

将材质文件Material放在debug同一级目录下,将dll放在Debug目录下,运行效果如下。

奇怪的是同样的D3D、Vs配置在XP系统中无法运行!

[Axiom3D]第一个Axiom3D程序的更多相关文章

  1. DirectX游戏编程(一):创建一个Direct3D程序

    一.环境 Visual Studio 2012,DirectX SDK (June 2010) 二.准备 1.环境变量(如没有配置请添加) 变量名:DXSDK_DIR 变量值:D:\Software\ ...

  2. 第一个python程序

    一个python程序的两种执行方式: 1.第一种方式是通过python解释器: cmd->python->进入python解释器->编写python代码->回车. 2.第二种方 ...

  3. 编写第一个MapReduce程序—— 统计气温

    摘要:hadoop安装完成后,像学习其他语言一样,要开始写一个“hello world!” ,看了一些学习资料,模仿写了个程序.对于一个C#程序员来说,写个java程序,并调用hadoop的包,并跑在 ...

  4. 1.3 第一个C#程序

    几乎没一门编程语言的第一个程序都叫“你好,世界”,所以先在visual studio 中创建一个Helloworld程序. 各部分的详细内容: Main方法是程序运行的起点,最重要的代码就写在Main ...

  5. 一个.net程序员的安卓之旅-Eclipse设置代码智能提示功能

    一个.net程序员的安卓之旅-代码智能提示功能 过完年回来就决心开始学安卓开发,就网上买了个内存条加在笔记本上(因为笔记本原来2G内存太卡了,装了vs2010.SQL Server 2008.orac ...

  6. MFC-01-Chapter01:Hello,MFC---1.3 第一个MFC程序(02)

    1.3.1 应用程序对象 MFC应用程序的核心就是基于CWinApp类的应用程序对象,CWinApp提供了消息循环来检索消息并将消息调度给应用程序的窗口.当包含头文件<afxwin.h>, ...

  7. Go! new Hello World, 我的第一个Go程序

    以下语句摘自百度百科: Go语言是谷歌2009发布的第二款开源编程语言. Go语言专门针对多处理器系统应用程序的编程进行了优化,使用Go编译的程序可以媲美C或C++代码的速度,而且更加安全.支持并行进 ...

  8. 搭建java开发环境、使用eclipse编写第一个java程序

    搭建java开发环境.使用eclipse编写第一个java程序 一.Java 开发环境的搭建 1.首先安装java SDK(简称JDK). 点击可执行文件 jdk-6u24-windows-i586. ...

  9. 第一个ruby程序

    老实说不是很喜欢去讨论ruby和python的对比,似乎总是把两个语言放在对立的位置上,我觉得没有必要,同样是动态语言,同样是解释型脚本语言,很多特性都是互相影响的,语言本身也在不断进化,我们更应该关 ...

随机推荐

  1. Windows网络编程Internet Gopher了解下

    Gopher:中文译“地鼠”,是迪士尼卡通人物之一(谷佛). 英文原义:The Internet Gopher Protocol 中文释义:(RFC-1436)网际Gopher协议 该系统是在明尼苏达 ...

  2. 【观点】“马云:金融是要为外行人服务",这个观点其实并不新鲜

    不久前,马云在外滩国际金融峰会演讲,称金融行业需要“搅局者”.他说:“今天的金融,确实做得不错,没有今天这样的金融机构,中国的经济30年来不可能发展到今天,但是靠今天银行的机制,我不相信能支撑30年以 ...

  3. TFS2010 分支问题

    最近在使用TFS2010分支的时候,对项目怎么分支都无法分支. 原因:TFS只支持对文件夹分支不针对项目分支 解决:项目建一个文件夹 把项目移动进去,再进行分支即可. 提示:Nuget会出现意外的路径 ...

  4. Linux,unix,cygwin,centeros下的tar压缩解压缩命令具体解释

    tar Examples:   tar -cf archive.tar foo bar  # Create archive.tar from files foo and bar.   tar -tvf ...

  5. 用命令行执行ROBOT FRAMEWORK用例

    转自:http://www.51testing.com/html/86/n-1430786.html 除了在ride中执行用例,我们也可以通过命令行的形式执行用例. 1.执行一整个项目 pybot+项 ...

  6. ios学习--TableView详细解释

    -.建立 UITableView DataTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)]; [DataTa ...

  7. poj_3283 trie树

    题目大意 将一副牌进行编号,四种花色分别标记为'C'.'D'.'H'.'S',数值标记为'A'.'1'.'2'.'3'.'4'.'5'.'6'.'7'.'8'.'9'.'10'.'J'.'Q'.'K' ...

  8. Vscode 修改为中文语言

    1 官网下载最新版的vscode : https://code.visualstudio.com/Download 2 安装之后, 按键 F1  搜索框 输入 language   选择 config ...

  9. 国内linux 镜像

    北京理工大学开源软件镜像服务mirrors.ustc.edu.cn 开源中国社区软件镜像下载资源库mirrors.oss.org.cn 阿里云开源镜像站mirrors.aliyun.com<ig ...

  10. LeetCode——Integer to Roman

    Description: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the r ...