Mogre Animacion de Robot en Windows Form

ZIDUKXUD

08-03-2011 19:21:16

Buenas tardes, he estado trabajando en un proyecto el cual estoy estancado. sucede que por el momento deseo animar al robot del tutorial, desde windows form; no deseo que el robot se traslade, solo deseo que el mismo robot se mueva, camine o muestre animacion en la posicion que esta, es decir, puede ser que el robot camine sin avanzar.

aqui les pongo mi codigo en C# Windows Form, la clase que viene con la solucion llamada "programa.cs" no le modificado absolutamente nada.

Por favor ayudenme

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Mogre;
using MogreFramework;
using System.Threading;


namespace Prueba_mogre_winform
{
public partial class Form1 : Form
{
protected OgreWindow mogreWin;

public Form1()
{
InitializeComponent();
this.Disposed += new EventHandler(Form1_Disposed);

mogreWin = new OgreWindow(new Point(100, 30), panel1.Handle);
mogreWin.InitMogre();
}

void Form1_Disposed(object sender, EventArgs e)
{
mogreWin.Dispose();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void panel1_Paint_1(object sender, PaintEventArgs e)
{
mogreWin.Paint();
}

}

public class OgreWindow
{
public Root root;
public SceneManager sceneMgr;

public FrameEvent evt;
public SceneNode node;
public Entity ent;

protected Camera camera;
protected Viewport viewport;
protected RenderWindow window;
protected Point position;
protected IntPtr hWnd;

public static AnimationState mAnimationState; //The AnimationState the moving object

public OgreWindow(Point origin, IntPtr hWnd)
{
position = origin;
this.hWnd = hWnd;
}

public void InitMogre()
{

//-----------------------------------------------------
// 1 enter ogre
//-----------------------------------------------------
root = new Root();

//-----------------------------------------------------
// 2 configure resource paths
//-----------------------------------------------------
ConfigFile cf = new ConfigFile();
cf.Load("resources.cfg", "\t:=", true);

// Go through all sections & settings in the file
ConfigFile.SectionIterator seci = cf.GetSectionIterator();

String secName, typeName, archName;

// Normally we would use the foreach syntax, which enumerates the values, but in this case we need CurrentKey too;
while (seci.MoveNext())
{
secName = seci.CurrentKey;
ConfigFile.SettingsMultiMap settings = seci.Current;
foreach (KeyValuePair<string, string> pair in settings)
{
typeName = pair.Key;
archName = pair.Value;
ResourceGroupManager.Singleton.AddResourceLocation(archName, typeName, secName);
}
}

//-----------------------------------------------------
// 3 Configures the application and creates the window
//-----------------------------------------------------
bool foundit = false;
foreach (RenderSystem rs in root.GetAvailableRenderers())
{
root.RenderSystem = rs;
String rname = root.RenderSystem.Name;
if (rname == "Direct3D9 Rendering Subsystem")
{
foundit = true;
break;
}
}

if (!foundit)
return; //we didn't find it... Raise exception?

//we found it, we might as well use it!
root.RenderSystem.SetConfigOption("Full Screen", "No");
root.RenderSystem.SetConfigOption("Video Mode", "640 x 480 @ 32-bit colour");

root.Initialise(false);
NameValuePairList misc = new NameValuePairList();
misc["externalWindowHandle"] = hWnd.ToString();
window = root.CreateRenderWindow("Simple Mogre Form Window", 0, 0, false, misc);
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();


//-----------------------------------------------------
// 4 Create the SceneManager
//
// ST_GENERIC = octree
// ST_EXTERIOR_CLOSE = simple terrain
// ST_EXTERIOR_FAR = nature terrain (depreciated)
// ST_EXTERIOR_REAL_FAR = paging landscape
// ST_INTERIOR = Quake3 BSP
//-----------------------------------------------------
sceneMgr = root.CreateSceneManager(SceneType.ST_GENERIC, "SceneMgr");
sceneMgr.AmbientLight = new ColourValue(0.5f, 0.5f, 0.5f);

//-----------------------------------------------------
// 5 Create the camera
//-----------------------------------------------------
camera = sceneMgr.CreateCamera("SimpleCamera");
camera.Position = new Vector3(0f, 0f, 100f);
// Look back along -Z
camera.LookAt(new Vector3(0f, 0f, -300f));
camera.NearClipDistance = 5;

viewport = window.AddViewport(camera);
viewport.BackgroundColour = new ColourValue(0.0f, 0.0f, 0.0f, 1.0f);


ent = sceneMgr.CreateEntity("Robot", "robot.mesh");
node = sceneMgr.RootSceneNode.CreateChildSceneNode("ogreNode");
node.AttachObject(ent);
node.SetPosition(0f, 0f, -100f);

mAnimationState = sceneMgr.GetEntity("Robot").GetAnimationState("Walk");
mAnimationState.Loop = true;
mAnimationState.Enabled = true;


Light luz = sceneMgr.CreateLight("Light");
luz.Type = Light.LightTypes.LT_POINT;
luz.Position = new Vector3(250, 150, 250);
luz.DiffuseColour = ColourValue.White;
luz.SpecularColour = ColourValue.White;

}

public void Paint()
{
root.StartRendering();

}

public void Dispose()
{
if (root != null)
{
root.Dispose();
root = null;
}
}
}

}

ianhfar

09-03-2011 12:24:12

One way to do it is

Create a windows timer in your OgreWindow class

System.Windows.Forms.Timer mRenderTimer;
mRenderTimer = new System.Windows.Forms.Timer();
mRenderTimer.Interval = 10;
mRenderTimer.Enabled = true;
mRenderTimer.Start();
mRenderTimer.Tick += new EventHandler(mRenderTimer_Tick);


then in your mRenderTimer_Tick event handler
allow the animation to step

mAnimationState.AddTime(dt); // where dt is delta time for example 0.1f