OgreOde - how to make multiple Subarus?

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
User avatar
Bren
Goblin
Posts: 215
Joined: Tue Jul 08, 2003 4:41 pm
Location: 0,0,0
Contact:

OgreOde - how to make multiple Subarus?

Post by Bren » Fri Mar 04, 2005 9:29 pm

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?
0 x

User avatar
walaber
OGRE Expert User
OGRE Expert User
Posts: 829
Joined: Sat Oct 02, 2004 2:20 pm
Location: California, USA
Contact:

Post by walaber » Fri Mar 04, 2005 10:18 pm

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.
0 x
Go Go Gadget OGRE!!
Image

User avatar
monster
OGRE Community Helper
OGRE Community Helper
Posts: 1098
Joined: Mon Sep 22, 2003 2:40 am
Location: Melbourne, Australia
Contact:

Post by monster » Sat Mar 05, 2005 7:42 am

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.
0 x

Post Reply