Ported CameraTrack Demo


24-07-2007 21:51:48

Dont know if it is usefull for anyone or could be used in the Demos of MOGRE, but i played around with porting Ogre C++ code to MOGRE C# and came up with this.

using System;
using System.Collections.Generic;
using System.Text;
using Mogre;

namespace Demo.CameraTrack
class Program
static void Main(string[] args)
CameraTrack a = new CameraTrack();

class CameraTrack : Mogre.Demo.ExampleApplication.Example

AnimationState animState;

public override void CreateScene()
// Set ambient light
sceneMgr.AmbientLight = new ColourValue(0.2f, 0.2f, 0.2f);

// Create a light
Light l = sceneMgr.CreateLight("MainLight");
// Accept default settings: point light, white diffuse, just set position
// NB I could attach the light to a SceneNode if I wanted it to move automatically with
// other objects, but I don't
l.Position = new Vector3(20.0f, 80.0f, 50.0f);

Entity ent;

// Define a floor plane mesh
Plane p;
p.normal = Vector3.UNIT_Y;
p.d = 200.0f;
MeshManager.Singleton.CreatePlane("FloorPlane", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, p, 20000.0f, 20000.0f, 20, 20, true, 1, 50.0f, 50.0f, Vector3.UNIT_Z);

// Create an entity (the floor)
ent = sceneMgr.CreateEntity("floor", "FloorPlane");
// Attach to child of root node, better for culling (otherwise bounds are the combination of the 2)

// Add a head, give it it's own node
SceneNode headNode = sceneMgr.RootSceneNode.CreateChildSceneNode();
ent = sceneMgr.CreateEntity("head", "ogrehead.mesh");

// Make sure the camera track this node
camera.SetAutoTracking(true, headNode);

// Create the camera node & attach camera
SceneNode camNode = sceneMgr.RootSceneNode.CreateChildSceneNode();

// set up spline animation of node
Animation anim = sceneMgr.CreateAnimation("CameraTrack", 10.0f);
// Spline it for nice curves
// Create a track to animate the camera's node
NodeAnimationTrack track = anim.CreateNodeTrack(0, camNode);
// Setup keyframes
TransformKeyFrame key = track.CreateNodeKeyFrame(0); // startposition
key = track.CreateNodeKeyFrame(2.5f);
key.Translate = new Vector3(500.0f,500.0f,-1000.0f);
key = track.CreateNodeKeyFrame(5.0f);
key.Translate = new Vector3(-1500.0f,1000.0f,-600.0f);
key = track.CreateNodeKeyFrame(7.5f);
key.Translate = new Vector3(0.0f,-100.0f,0.0f);
key = track.CreateNodeKeyFrame(10.0f);
key.Translate = new Vector3(0.0f,0.0f,0.0f);
// Create a new animation state to track this
animState = sceneMgr.CreateAnimationState("CameraTrack");
animState.Enabled = true;

// Put in a bit of fog for the hell of it
sceneMgr.SetFog(FogMode.FOG_EXP, ColourValue.White, 0.0002f);
root.FrameStarted += new FrameListener.FrameStartedHandler(root_FrameStarted);

bool root_FrameStarted(FrameEvent evt)
return true;

*edit* over the next couple of days i`ll try to port the other demos aswell, so if a maintainer is interested, i could provide them aswell


25-07-2007 04:16:37

thanx nataz.
u r doing a helpful job for all who r using MOGRE.

could u port the CEGUI demo first? which would help me a lot.


25-07-2007 06:34:50


will try to do that tonight. But the thing i really want to do is wrapping up RBGui and make it available for .NET users, because i want to use it in my project aswell.
But first i have to play around with the original demos, so CEGUI demo will be done aswell.

*edit* CEGUI Seems to be broken in Mogre, so i cant port it right now, i am looking into CEGUI# now, maybe i can get something to work over there, but it will be a bit of work because there is no Mogre renderer yet