Newb: How do I place additional entities in the scene?

Problems building or running the engine, queries about how to use features etc.
EGD Eric
Halfling
Posts: 41
Joined: Mon Dec 13, 2004 4:07 pm
Location: St. Bruno, Quebec, Canada

Newb: How do I place additional entities in the scene?

Post by EGD Eric »

I'm on the Xorexis tutorial pack 1. I want to try to add another ship to the scene next to the first one, but nothing I try works. Am I supposed to attach another ship to the same sceneNode as the first one, after calling SceneNode::SetPosition, so it will end up somewhere different? I've tried making a different scene node, then adding another ship pointer to it, but I don't see any new objects in the scene that way either.

I've done everything the tutorial says to do up to the point where it suggests I add another ship (just after the lighting part).
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8

Post by haffax »

I will probably post the remaining chapters of xorekis' tutorial on sunday. Until then you find his second pack here. Two things have to be done:
1. create the entity via SceneManager::createEntity().
2. attach it to a SceneNode with SceneNode::attachObject();.

If it doesn't show up there can be several reasons for it: it is to near to the camera (move it at least 110 units away from the camera). It can have a material that has no ambient lighting and no light is lighting it. The camera looks into a different direction. (And some others I forgot about ;))

I might have converted the tutorial to the wiki, but I didn't read it yet. :oops:

Hope this helps. If not: please provide more informations and your source.
team-pantheon programmer
creators of Rastullahs Lockenpracht
User avatar
Project5
Goblin
Posts: 245
Joined: Mon Nov 22, 2004 11:56 pm
Location: New York, NY, USA

Post by Project5 »

The way I do it is:
Get a pointer to the sceneManager, and call it (for example) mSceneMgr.

then:
// Create a coordinate system

Code: Select all

mSceneMgr->createSceneNode("Razor");

// Add some geometry to the world
mSceneMgr->createEntity("razor", "razor.mesh");

// Attach the geometry to the coordinate system
mSceneMgr->getSceneNode("Razor")->attachObject(ogre->mSceneMgr->getEntity("razor"));

// Attach the coordinate system to the root so that Ogre renders it
mSceneMgr->getRootSceneNode()->addChild(ogre->mSceneMgr->getSceneNode("Razor"));
You can probably get around the get commands if you keep pointers around, but I suggest this method because it's easy.

--Ben
EGD Eric
Halfling
Posts: 41
Joined: Mon Dec 13, 2004 4:07 pm
Location: St. Bruno, Quebec, Canada

Post by EGD Eric »

Allright, thanks people! I got it working using Project5's method. So far, the only way I know how to add more objects to the scene is to have a sceneNode for each one. So I'm guessing, my object classes in the game would have some way of creating themselves, making their own names (each one has to have its own string) and sceneNodes for themselves.

Hey, what about the names? What if I have game with tons of baddies, constantly spawning into the game, some of them dying, etc.. My game is supposed to make some somewhere, so it would have to create the entity, but how would it know what names to give them? "Baddie1, Baddie 2, etc.."
I'd have to keep a count of the amount of baddies created, use itoa (convert it to a string), append that at the end of the name. At some point, I'd be at Baddie 1550, even though there's lots of free numbers left open since baddies 16 through 40 died.

Tanis: What's wiki?
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8

Post by haffax »

EGD Eric wrote:Tanis: What's wiki?
It's a webpage everybody can edit. Anyway I meant the Ogre-wiki. It can be found here.
team-pantheon programmer
creators of Rastullahs Lockenpracht
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8

Post by haffax »

As for your other problem: Don't make the constructors choose the names. Use some kind of abstract factory or factory method, that chooses the names. The factory could also keep track of all currently active Baddies. So if one dies the first free number could be used, if you have a destroy()-Method too that is.
team-pantheon programmer
creators of Rastullahs Lockenpracht
User avatar
Project5
Goblin
Posts: 245
Joined: Mon Nov 22, 2004 11:56 pm
Location: New York, NY, USA

Post by Project5 »

You can let Ogre name them for you:

Code: Select all

Ogre::String name = mSceneMgr->createSceneNode()->getName();
mSceneMgr->getSceneNode(name)->(do whatever you want to it here);
Ogre (I believe) starts counting upwards from 1, so unless you start getting a ridiculous number of scenenodes around or keep your simulation going for extended periods of time, this should work fine.