Noob question on Ogre

Problems building or running the engine, queries about how to use features etc.
Post Reply
Jeff
Gnoblar
Posts: 17
Joined: Mon Feb 07, 2005 8:28 pm

Noob question on Ogre

Post 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 :(
User avatar
Clay
OGRE Community Helper
OGRE Community Helper
Posts: 518
Joined: Wed Mar 17, 2004 4:14 am
x 1
Contact:

Re: Noob question on Ogre

Post 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. =)
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8
Contact:

Re: Noob question on Ogre

Post 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. ;)
team-pantheon programmer
creators of Rastullahs Lockenpracht
Jeff
Gnoblar
Posts: 17
Joined: Mon Feb 07, 2005 8:28 pm

Post 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
Post Reply