Page 1 of 1

OgreOde - how to make multiple Subarus?

Posted: Fri Mar 04, 2005 9:29 pm
by Bren
Hi Monster,

How do I make multiple instances of the Subaru vehicle?

Making more than one "as is" using the DemoOgreOde_GranTurismOgre as a basis, I get errors because it tries to create multiple entities all named "Subaru_Entity".

If I change the name(s) passed to OgreOde_Prefab::Vehicle (to something like Subaru0, Subaru1, etc) then I get basically nothing because from OgreOde_Prefab::Vehicle::load cause it can't find a definition for "Subaru0".

I suppose I could just duplicate the entries in the SimpleScenes.ogreode file, but this seems ineffecient, and not exactly the intention.

Any suggestions?

Posted: Fri Mar 04, 2005 10:18 pm
by walaber
nono, just change the line where it created the Entity. you might want to add a static member to the class called "static int mSubaruCount"

then, do something like this:

ent = mSceneMgr->createEntity( "Subaru"+Ogre::StringConvertor::toString(mSubaruCount++), "whatever.mesh" );

something like that should fix the problem.

Posted: Sat Mar 05, 2005 7:42 am
by monster
Hmm yeah, fair enough. At the moment the vehicle definition is loaded based on it's name. What you need to do is;

Change the declaration of Vehicle::load to be;

Code: Select all

void load(const String &filename,const String &definition_name = StringUtil::BLANK);
In the body of Vehicle::load, change the top bit to be;

Code: Select all

void Vehicle::load(const String &filename,const String &definition_name)
{
	String my_name = definition_name;
	if(my_name == StringUtil::BLANK) my_name = _name;
        ...
And then change line 565 of OgreOdeVehicle to be;

Code: Select all

if(vehicle->Attribute("name") && (!strcmp(vehicle->Attribute("name"),my_name.c_str())))
Then you can do something like;

Code: Select all

		for(int i = 0;i < 5;++i)
		{
			// Create the vehicle from the config file
			vehicle = new OgreOde_Prefab::Vehicle("Subaru" + StringConverter::toString(i));
			vehicle->load("SimpleScenes.ogreode","Subaru");

			// Move the vehicle
			vehicle->setPosition(Vector3(-7.5 + (3.0 * (Real)i),0.82898,0));
		}

But note that you'll have to add extra code to delete your vehicles properly.

Or, like walaber says, create your vehicles programmatically with different names rather than by loading them from the config file.