a noob's problem : why i can't create do this?

tzw

02-08-2011 13:38:58

hi every one!. why i can't create entity & node by this way:
using Mogre;
using Mogre.TutorialFramework;
using System;



namespace Mogre.Tutorials
{
public class Tutorial : BaseApplication
{
public Entity ent;
public SceneNode node;
public static void Main()
{
Tutorial a_tut = new Tutorial();
a_tut.Go();
a_tut.level_create();
}

protected override void CreateScene()
{

}
private void level_create()
{
mSceneMgr.AmbientLight = new ColourValue(1, 1, 1);

ent = mSceneMgr.CreateEntity("Head", "ogrehead.mesh");
node = mSceneMgr.RootSceneNode.CreateChildSceneNode("HeadNode");
node.AttachObject(ent);
}
}
}

McDonte

03-08-2011 12:47:27

Hi tzw,

well you do create your entity and scene node this way, this is absolutely right. Your problem is that you are creating the entity outside the "CreateScene" method. I need to take a closer look onto the source of the TutorialFramework to say why it is necessary to edit the scene in the "CreateScene" mtheod.

Actually the only change you need is that you have to call the "level_create" method from inside the "CreateScene" method. Here is my adapted code:
class Tutorial : BaseApplication
{
public Entity ent;
public SceneNode node;

public static void Main()
{
Tutorial a_tut = new Tutorial();
a_tut.Go();
}

protected override void CreateScene()
{
level_create();
}

private void level_create()
{
mSceneMgr.AmbientLight = new ColourValue(1, 1, 1);

ent = mSceneMgr.CreateEntity("Head", "ogrehead.mesh");
node = mSceneMgr.RootSceneNode.CreateChildSceneNode("HeadNode");
node.AttachObject(ent);
}
}


I hope this helped!

Greetinsg,
McDonte

Beauty

03-08-2011 16:49:41

Hi twz,

welcome to our Mogre community. :D

Do you "just" use the Framework for your own project or do you have problems with a Mogre Tutorial?

The Mogre Basic Tutorial 1 should teach you how to create SceneNodes, Entities, etc.
It's highly to recommend to look to the Mogre Tutorials.

I don't remember the detailed framework source. Perhaps the SceneManager was not initialized or disposed.
You can look into the framework sourcecode. You even can include it to your project (instead of the dll file).

Maybe there the problem has an other source.
For example your entity was included, but you don't have a light. Or the camera is looking into the wrong direction.

Do you have any exception?
Are warnings or exceptions in the file ogre.log?
We need more to know to help you.

a_tut.Go();
a_tut.level_create();

Perhaps after a_tut.Go() the renderloop was stopped and the scene manager destroyed.
Then a_tut.level_create(); would be called when you leave your application. :mrgreen:

....
I looked into the Tutorial 1 now.
I suppose the problem is that you used your own method for scene creation.
Find the CreateScene() method. We will only be manipulating the contents of this method in this tutorial.
McDonte showed you how it should work.

tafkag

03-08-2011 17:04:33

This...
a_tut.Go();
...starts the rendering loop of Ogre, so you never leave this method until you quit the app which is a little late to create you scene. ;)

EDIT: Well, Beauty pointed this out a little more detailed a few minutes ago. :)

tzw

04-08-2011 08:15:11

@beauty : nope , i just copy the text from CreateScene to level_create. it works fine in CreateScene. i just wanna know why i HAVE TO use the CreateScene function to create sth for my level. i also look into the framework source and i don't find there is sth special at CreateScene.
for comparetion,i also use a event called "on_sence_create" bind the level_create function.
and i invoke it at:

try
{
if (!Setup())
return;
baseapplication.mRoot.StartRendering();
on_sence_create();
}
......................................................

and it works fine too (see a orc head )!!....
so i'm totally confused, i think there is no different beteween the on_sence_create() 's and level_create's place which be invoked.
why they make different effect?
sorry for my english....

McDonte

04-08-2011 10:56:01

@tzw: Can you please explain once again where you put your event handler? Did you use a FrameListener event? If yes, then the scene is of course created because all FrameListeners are called every frame. So your scene would be created many times a second...

tzw

04-08-2011 11:58:41

ok . i just put it in end of the "go" function.

public static void Go()
{
try
{
if (!Setup())
return;
baseapplication.mRoot.StartRendering();
on_sence_create();
}
catch (System.Runtime.InteropServices.SEHException e)
{
Console.WriteLine(e);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}

and i bind the event with the level_create like this:

class Tutorial
{
public Tutorial()
{
mogre_basic.on_sence_create += create_level;
}
public static void Main()
{
Tutorial a_new_one = new Tutorial();
mogre_basic.Go();
}
private void create_level()
{
//create a orc head...
}
}

it's work fine above


but this:

public Tutorial()
{
//don't bind it
//mogre_basic.on_sence_create += create_level;
}
public static void Main()
{
Tutorial a_new_one = new Tutorial();
mogre_basic.Go();
a_new_one.create_level()
}
private void create_level()
{
//create a orc head...
}
}

DON'T WORK..

Beauty

04-08-2011 23:16:56

你好学生 tzw。

i just wanna know why i HAVE TO use the CreateScene function to create sth for my level.
Keep in mind: The main purpose of the Mogre Tutorial Framework is to teach newcomers step by step how the Mogre basics work.
The Frameworks hides some complexity. By usage of the internal (hidden) framework structure, you can't use it as you want.
For more flexibility you need to write an application which doesn't use the framework. Nevertheless you can look into the framework code to learn and can copy useful code sections.

ok . i just put it in end of the "go" function.

baseapplication.mRoot.StartRendering();
on_sence_create();


The problem is similar to my first post. The method Root.StartRendering() will not return. It contains the render loop.
This is the reason, why your own method will not be applied.
For usage of the Tutorial Framework you need to call your create method from the CreateScene() method.
The CreateScene() method is still inside the framework. By overriding you "recreate" it with new content. It's a way of object oriented programming.

Here I quote the Ogre class documentation of Root::startRendering().
Look to the documentation page, if you want to see the links of this description text.

void Ogre::Root::startRendering ( void )

Starts / restarts the automatic rendering cycle.

Remarks:
This method begins the automatic rendering of the scene. It will NOT return until the rendering cycle is halted.

During rendering, any FrameListener classes registered using addFrameListener will be called back for each frame that is to be rendered, These classes can tell OGRE to halt the rendering if required, which will cause this method to return.

Note:
Users of the OGRE library do not have to use this automatic rendering loop. It is there as a convenience and is most useful for high frame rate applications e.g. games. For applications that don't need to constantly refresh the rendering targets (e.g. an editor utility), it is better to manually refresh each render target only when required by calling RenderTarget::update, or if you want to run your own render loop you can update all targets on demand using Root::renderOneFrame.
This frees up the CPU to do other things in between refreshes, since in this case frame rate is less important.
This method can only be called after Root::initialise has been called.


It's long time ago that I worked through the tutorials. As far as I remember the alternative usage (own render loop) will be explained in a further tutorial.

tzw

05-08-2011 11:05:51

thanks!!!!!!!
and thanks tafkag.........
so you never leave this method until you quit the app which is a little late to create you scene. ;)

so i know where i am wrong.....
thanks
thanks
thanks