nataz
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.
*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
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();
a.Go();
}
}
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");
ent.SetMaterialName("Examples/RustySteel");
// Attach to child of root node, better for culling (otherwise bounds are the combination of the 2)
sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(ent);
// Add a head, give it it's own node
SceneNode headNode = sceneMgr.RootSceneNode.CreateChildSceneNode();
ent = sceneMgr.CreateEntity("head", "ogrehead.mesh");
headNode.AttachObject(ent);
// Make sure the camera track this node
camera.SetAutoTracking(true, headNode);
// Create the camera node & attach camera
SceneNode camNode = sceneMgr.RootSceneNode.CreateChildSceneNode();
camNode.AttachObject(camera);
// set up spline animation of node
Animation anim = sceneMgr.CreateAnimation("CameraTrack", 10.0f);
// Spline it for nice curves
anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);
// 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)
{
animState.AddTime(evt.timeSinceLastFrame);
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