Page 1 of 1

Noob question on Ogre

Posted: Sun Feb 13, 2005 11:50 pm
by Jeff
Hi - At the moment working through the tutorials and I'm breaking loose a bit and trying to render 3 ships in a row along the X axis.

This is my code:

Code: Select all

	for(int i=0; i<3;i++)
	{
	mShip = mSceneMgr->createEntity("myShip","razor.mesh");
	mShipNode[i] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	mShipNode[i]->attachObject(mShip);
	}
	//set position of ships
	mShipNode[0]->setPosition(-100,   0,   0);
	mShipNode[1]->setPosition(   0,   0,   0);
	mShipNode[2]->setPosition(   0,   0,-100);
Obviosly in the header I have:

Code: Select all

Entity* mShip;
	SceneNode *mShipNode[3];
It builds fine and everything but won't run - it tells me that there's already an object called "myShip". Does this mean I'll have to create 3 "mShip" Entities rather than try render the same one 3 times in different positions in the same scene?

I know I can do this in other 3D graphics packages to save on the total number of objects loaded in, I was just wondering if there's any [simple] way round it.

Again, I've just started using Ogre and have a basic understanding of C++ so if I've made a stupid mistake, please be gentle :(

Re: Noob question on Ogre

Posted: Mon Feb 14, 2005 12:04 am
by Clay
Jeff wrote:It builds fine and everything but won't run - it tells me that there's already an object called "myShip". Does this mean I'll have to create 3 "mShip" Entities rather than try render the same one 3 times in different positions in the same scene?
The problem is that every entity must have a unique name. You would need to create "myShip0", "myShip1", and "myShip3" (or whatever you want to call them). Try this:

Code: Select all

char buffer[128];
for (int i = 0; i < 3; i++)
{
   sprintf(buffer, "myShip%d", i);
   mShip = mSceneMgr->createEntity(buffer,"razor.mesh");
   mShipNode[i] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
   mShipNode[i]->attachObject(mShip); 
}
That's off of memory, so I'm not certain that's perfect, but it's the idea. You should also name your scene nodes something meaningful in case you have to get them later.
Again, I've just started using Ogre and have a basic understanding of C++ so if I've made a stupid mistake, please be gentle :(
No worries. Welcome to the community. =)

Re: Noob question on Ogre

Posted: Mon Feb 14, 2005 12:11 am
by haffax
You can't have two or more entities with the same name. But this doesn't mean Ogre loads three times the same mesh into memory. It checks if the mesh "razor.mesh" has already been loaded. If this is the case it doesn't load it again but uses the copy it has in memory. So the mesh is in memory only once.

PS:
Jeff wrote:please be gentle :(
This is an advise you should remind yourself when you don't get an answer from someone you expected to get one. But I'm not (that) resentful. ;)

Posted: Mon Feb 14, 2005 12:25 am
by Jeff
No, you misunderstand tanis, the point of my other post WAS to thank you, I was just a little bitter that you were the only person to have responded to my problems getting ogre started.

On topic now, thank to both Clay and Tanis... I'm dedicating my first ever OGRE screenshot to you :D
Image