How to get RenderWindow from the handle?

CK_MACK

25-01-2007 03:46:58

First a quick thank you... With the help from the folks on the forum, I have been able to successfully get keyboard input to work without Axiom, and Mouse input as well!

Also, Animation works !

I am trying to rebuild some portions of the tutorials WITHOUT the MogreFramework... Basically, I need to find a way to handle this line of code properly:win.SceneManager.SetWorldGeometry("terrain.cfg");


Once I had the handle to the window, I thought I was home free.
Here's the code:

void CreateRenderWindow()
{
mRoot.Initialise(true, "Main Ogre Window");
mRoot.AutoCreatedWindow.GetCustomAttribute("HWND", out hwnd); // hwnd now holds the pointer to Mogre window (thanks Bekas!)
}


Skipping over some code, I then attempt to add terrain.cfg

private void CreateScene()

{
SceneManager mgr = mRoot.CreateSceneManager(SceneType.ST_GENERIC);

// mgr.SceneManager.SetWorldGeometry("terrain.cfg"); // FAILS



So, in the MogreFramework Tutorials, I would use code like this:
win.SceneManager.SetWorldGeometry("terrain.cfg");

Where win was declared as: MyOgreWindow win = new MyOgreWindow();
Tracing that back... MyOgreWindow : OgreWindow
and then OgreWindow : Form
Clearly, mgr does not EQUATE to what is required.

OK, so...
I have the Window Handle...
I went over what I had read earlier about creating a window, but in this case it seems to give Mogre a FORM?

How can I use that to declare "win" in the proper "form?"

Thanks,

Marc

Bekas

25-01-2007 11:28:55

The GENERIC SceneManager doesn't support terrain.
If you look in the tutorial 3 which loads terrain, you'll see
SceneManager = Root.CreateSceneManager(SceneType.ST_EXTERIOR_CLOSE);

CK_MACK

25-01-2007 20:49:46

Thanks for that: SceneManager = Root.CreateSceneManager(SceneType.ST_EXTERIOR_CLOSE);

I am not sure what the proper term for what I am looking for:
I guess its the root object? How do I declare the root object for ???.SceneManager.SetWorldGeometry("terrain.cfg");


Here's the code
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Mogre;
using System.Drawing;
using Microsoft.DirectX.DirectInput;


namespace Tutorial05
{
static class Program
{
[STAThread]
static void Main()
{
OgreStartup ogre = new OgreStartup();
ogre.Go();
}
}

class OgreStartup
{
Root mRoot = null;
IntPtr hwnd;
RenderWindow win = null;

int ticks; // REQUIRED change for tutorial to work.
const float TRANSLATE = .1f; // 200 for slower camera motion
Vector3 mTranslation = Vector3.ZERO;
Vector3 center = Vector3.ZERO;
Camera cam = null;
AnimationState[] _animState = new AnimationState[1];
float[] _animationSpeed = new float[1];
SceneNode mNode = null;

public void Go()
{
CreateRoot();
DefineResources();
SetupRenderSystem();
CreateRenderWindow();
InitializeResourceGroups();
CreateScene();
CreateInputHandler(); // added in the input handler
StartRenderLoop();
}

void CreateRoot()
{
mRoot = new Root();
}

void DefineResources()
{
ConfigFile cf = new ConfigFile();
cf.Load("resources.cfg", "\t:=", true);
ConfigFile.SectionIterator seci = cf.GetSectionIterator();
String secName, typeName, archName;

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);
}
}
}

void SetupRenderSystem()
{
if (!mRoot.ShowConfigDialog())
throw new Exception("The user canceled the configuration dialog.");
}

void CreateRenderWindow()
{
mRoot.Initialise(true, "Main Ogre Window");
mRoot.AutoCreatedWindow.GetCustomAttribute("HWND", out hwnd); // hwnd now holds the pointer to Mogre window
}

void InitializeResourceGroups()
{
TextureManager.Singleton.DefaultNumMipmaps = 5;
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();
}

// Whats the proper naming object naming convention for SceneManager.SetWorldGeometry("terrain.cfg");
// Since I dont have the MogreFramework, I cannot use win.SceneManager anymore...

private void CreateScene()

{
SceneManager mgr = mRoot.CreateSceneManager(SceneType.ST_EXTERIOR_CLOSE);

// ???.SceneManager.SetWorldGeometry("terrain.cfg");

cam = mgr.CreateCamera("Camera");
mRoot.AutoCreatedWindow.AddViewport(cam);
Entity ent = mgr.CreateEntity("robot", "robot.mesh");

mNode= mgr.RootSceneNode.CreateChildSceneNode();
mNode.AttachObject(ent);

cam.Position = new Vector3(0, 200, -400);
cam.NearClipDistance = 1;
cam.LookAt(ent.BoundingBox.Center);
center = ent.BoundingBox.Center;
// *** throw in a timer so we can end the demo after a short delay
mRoot.FrameEnded += new FrameListener.FrameEndedHandler(FrameEnded);
ticks = Environment.TickCount;
}
bool FrameEnded(FrameEvent evt)
{
if (Environment.TickCount - ticks > 5000)
return false;

return true;
}

void CreateInputHandler() // create the input handler
{
}

void StartRenderLoop()
{
mRoot.StartRendering();
}
}
}


Thanks,

Marc

Bekas

25-01-2007 21:09:34

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Mogre;
using System.Drawing;
using Microsoft.DirectX.DirectInput;


namespace Tutorial05
{
static class Program
{
[STAThread]
static void Main()
{
OgreStartup ogre = new OgreStartup();
ogre.Go();
}
}

class OgreStartup
{
Root mRoot = null;
IntPtr hwnd;
RenderWindow win = null;

int ticks; // REQUIRED change for tutorial to work.
const float TRANSLATE = .1f; // 200 for slower camera motion
Vector3 mTranslation = Vector3.ZERO;
Vector3 center = Vector3.ZERO;
Camera cam = null;
AnimationState[] _animState = new AnimationState[1];
float[] _animationSpeed = new float[1];
SceneNode mNode = null;

public void Go()
{
CreateRoot();
DefineResources();
SetupRenderSystem();
CreateRenderWindow();
InitializeResourceGroups();
CreateScene();
CreateInputHandler(); // added in the input handler
StartRenderLoop();
}

void CreateRoot()
{
mRoot = new Root();
}

void DefineResources()
{
ConfigFile cf = new ConfigFile();
cf.Load("resources.cfg", "\t:=", true);
ConfigFile.SectionIterator seci = cf.GetSectionIterator();
String secName, typeName, archName;

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);
}
}
}

void SetupRenderSystem()
{
if (!mRoot.ShowConfigDialog())
throw new Exception("The user canceled the configuration dialog.");
}

void CreateRenderWindow()
{
mRoot.Initialise(true, "Main Ogre Window");
mRoot.AutoCreatedWindow.GetCustomAttribute("HWND", out hwnd); // hwnd now holds the pointer to Mogre window
}

void InitializeResourceGroups()
{
TextureManager.Singleton.DefaultNumMipmaps = 5;
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();
}

private void CreateScene()
{
SceneManager mgr = mRoot.CreateSceneManager(SceneType.ST_EXTERIOR_CLOSE);
cam = mgr.CreateCamera("Camera");
mRoot.AutoCreatedWindow.AddViewport(cam);

mgr.SetWorldGeometry("terrain.cfg");
Entity ent = mgr.CreateEntity("robot", "robot.mesh");

mNode = mgr.RootSceneNode.CreateChildSceneNode();
mNode.AttachObject(ent);

cam.Position = new Vector3(0, 200, -400);
cam.NearClipDistance = 1;
cam.LookAt(ent.BoundingBox.Center);
center = ent.BoundingBox.Center;
// *** throw in a timer so we can end the demo after a short delay
mRoot.FrameEnded += new FrameListener.FrameEndedHandler(FrameEnded);
ticks = Environment.TickCount;
}
bool FrameEnded(FrameEvent evt)
{
if (Environment.TickCount - ticks > 5000)
return false;

return true;
}

void CreateInputHandler() // create the input handler
{
}

void StartRenderLoop()
{
mRoot.StartRendering();
}
}
}

CK_MACK

26-01-2007 00:21:30

Thanks Bekas,

Your code worked great.
I had tried a variation of that prior to posting:
mgr.SetWorldGeometry("terrain.cfg");
cam = mgr.CreateCamera("Camera");
mRoot.AutoCreatedWindow.AddViewport(cam);
But I got run time error: Program ... \MogreEngneV1.vshost.exe


I guess that ogre must require that SetWorldGeometry("terrain.cfg"); to occur after the camera.

Thank you very much for that.

Marc

Bekas

27-01-2007 14:31:17

Always use exception handling for Ogre exceptions or at least check "Ogre.log" where exceptions are logged.
You would see something like "camera not created" which is much more useful that the "run time error" one :wink: