Third tutorial -> Easy exercises

Problems building or running the engine, queries about how to use features etc.
Post Reply
Fahrenheit
Gnoblar
Posts: 6
Joined: Sun Dec 04, 2005 10:30 pm
Contact:

Third tutorial -> Easy exercises

Post by Fahrenheit »

Hello. In the third intermediate tutorial :
The TerrainSceneManager creates tiles with a default mask of ~0 (all queries select it). We fixed this problem by testing to see if the name of the movable object equaled "tile[0][0,2]". Even though it's not implemented yet, the TerrainSceneManager supports multiple pages, and if there were more things than just "tile[0][0,2]" this would cause our code to break down. Instead of making the test in the loop, fix the problem properly by setting all of the tile objects created by the TerrainSceneManager to have a unique mask. (Hint: The TerrainSceneManager creates a SceneNode called "Terrain" which contains all of these tiles. Loop through them and set the attached object's masks to something of your choosing.)
I don't understand how to do this. I try :

SceneNode::ConstObjectIterator it = "Terrain"->getAttachedObjectIterator();
while (it.hasMoreElements()) {
Entity* entity = static_cast<Entity*>(it.getNext());
entity->setQueryFlags(LOCKED_OBJECT_MASK);
}

but the two first lines don't work correctly. Someone can help me?
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 7
Contact:

Post by haffax »

In order to work with Ogre you need at least basic C++ experience.
You can't call a member function of a literal string like you try. The text explicitly says to use the SceneNode called "Terrain". See the API docs for how to retrieve it. And consult a good C++ book to learn about the language.

And for further posts remember: "Don't work correctly" is not an appropriate problem description.
team-pantheon programmer
creators of Rastullahs Lockenpracht
Rowan
Gnoblar
Posts: 14
Joined: Tue Apr 18, 2006 5:39 am
Location: Australia

Post by Rowan »

Hi, I too am having problems with this exercise, i was hoping someone could help . Here is my code so far ::

Code: Select all

    void createScene(void)
    {

       ....

       // World geometry
       mSceneMgr->setWorldGeometry( "terrain.cfg" );


	   SceneNode *mTerrainNode = mSceneMgr->getSceneNode( "Terrain" );
	   Ogre::SceneNode::ObjectIterator tnitr=mTerrainNode->getAttachedObjectIterator ();
	   while( tnitr.hasMoreElements() ) {
		    tnitr.getNext()->setQueryFlags( TERRAIN_MASK );
	   }
As stated in the exercise, I need to iterate through the terrain tiles and set their masks, but I'm not sure about the finding the correct nodes and then iterating through them.

My loop above is never entered, so I tested for the number of attached objects using mTerrainNode->numAttachedObjects(), which returned : 52428, which doesn't seem right anyway (as there appear to be only 64 selected tiles).

So I'm not sure how to actually find the Terrain Tile entities, and then iterate through them.

Any help is appreciated.
Rowan
Gnoblar
Posts: 14
Joined: Tue Apr 18, 2006 5:39 am
Location: Australia

Post by Rowan »

Well, like many other requests for help, I sorted it out myself, at least after hours of searching.
I stumbled upon a previous post which led me to the solution.

Here's the code for those in the same situation ::

Code: Select all

       // World geometry
       mSceneMgr->setWorldGeometry( "terrain.cfg" );


	   //--set the terrain tile masks
	   Ogre::SceneNode *mTerrainPageNode = (Ogre::SceneNode *) mSceneMgr->getSceneNode( "Terrain" )->getChild(0);
	   Ogre::SceneNode::ChildNodeIterator node_it=mTerrainPageNode->getChildIterator ();
	   while( node_it.hasMoreElements() ) {
			( (Ogre::SceneNode *) node_it.getNext() )->getAttachedObject(0)->setQueryFlags( TERRAIN_MASK );
	   }
The biggest problem was not knowing the structure of the "Terrain" node. It has a child node for a 'page' of the terrain (for terrain paging I assume), then each page has the tiles (a tile node with a child node being the tile entity).

I found this out after finding a function which dumps a node's structure to the log, here's the link (very useful in future I think) ::

http://www.ogre3d.org/wiki/index.php/DumpingNodeTree

Nb :: Perhaps my above code could be better, let me know if so. I know the proper way would actually be to loop through nodes at every level (the dumpnodes() function does this anyway), instead of going directly to the second (page) child node, as there might be more than one page of tiles.
Also, casting the getChild() calls to sceneNode * seemed to be the only way to access those methods.


Here's another seemingly useful link for us newb's : )

http://www.ogre3d.org/wiki/index.php/OogstsHowTo

[ I'll link to this thread from the tute's discussion page ]

Now if that was easy, I wonder how the intermediate exercises are going to be.. hmm.. :?:
User avatar
Toby
Halfling
Posts: 57
Joined: Thu Jul 28, 2005 11:14 am
Location: Caen
Contact:

Post by Toby »

I am doing the 3rd tutorial and same as you I don't manage to setQueryFlag.
this my code:

Code: Select all

 SceneNode *mTerrain = mSceneMgr->getSceneNode("Terrain");
Ogre::SceneNode::ObjectIterator node_it=mTerrain->getAttachedObjectIterator ();
      while( node_it.hasMoreElements() ) {
         (node_it.getNext())->setQueryFlags( TILES_MASK );
      }
This do nothing. When I launch program I can select tiles and move it. When I do this tile disappear.
Toby or not Toby

http://aubrun.thibaut.free.fr

Freelance software developper, perhaps ;)
Rowan
Gnoblar
Posts: 14
Joined: Tue Apr 18, 2006 5:39 am
Location: Australia

Post by Rowan »

I don't think you have node/object structure right, which was my original problem.

I think you need to get a NODE iterator (instead of an Object iterator), and then in the loop, get the Child Object of the Node and set it's Query Flag.

I suggest you check out the 'DumpingNodeTree' code I link in my post, run it for the Terrain SceneNode and check the log. It should show you how the Children Nodes & Objects are structured.
User avatar
Toby
Halfling
Posts: 57
Joined: Thu Jul 28, 2005 11:14 am
Location: Caen
Contact:

Post by Toby »

I will re-try it.
This easy question is hard. But I think it s just an organisation to understand.

ps: I use for my scene manager ST_EXTERIOR_COLSE, this create a Terrain scene manager?
Toby or not Toby

http://aubrun.thibaut.free.fr

Freelance software developper, perhaps ;)
Rowan
Gnoblar
Posts: 14
Joined: Tue Apr 18, 2006 5:39 am
Location: Australia

Post by Rowan »

Agreed.

Yes, that should be correct as far as I know. Goodluck! :)
Post Reply