Adding new objects in old PCZSM scene

Problems building or running the engine, queries about how to use features etc.
Post Reply
lvella
Kobold
Posts: 35
Joined: Thu Nov 27, 2008 3:58 am

Adding new objects in old PCZSM scene

Post by lvella »

How can I add new objects on an up'n'running scene?

I have a character walking around a world with many zones, and he can throw objects. To throw the objects, I use the following code:
node = pSceneManager->createSceneNode();
entity = pSceneManager->createEntity(randomName, "object.mesh");
node->attachObject(entity);

Ogre::Vector3 scale(2.5f, 2.5f, 2.5f);
node->setScale(scale);

node->setPosition(characterNode->_getDerivedPosition());
Ogre::PCZone* zone = characterNode->getHomeZone();
pSceneManager->setNodeHomeZone(node, zone);
node->setPosition(origin);
It doen't seem to matter my call to pSceneManager::setNodeHomeZone(). I can only see the newly created objects if the character and the camera are inside the default zone. From the other zones, nothing is visibly thrown.
lvella
Kobold
Posts: 35
Joined: Thu Nov 27, 2008 3:58 am

Post by lvella »

It seems that only objects placed during scene setup are moved to the correct zone. Objects placed on a running scene always end up in the default zone.
Chaster
OGRE Expert User
OGRE Expert User
Posts: 557
Joined: Wed May 05, 2004 3:19 pm
Location: Portland, OR, USA
Contact:

Post by Chaster »

You can put new nodes in a zone dynamically. To do this, you need to do two things:

1) Set the node's home zone: theNode->setHomeZone(theZone)

and

2) Add the node to the zone: theZone->_addNode(theNode)

Chaster
lvella
Kobold
Posts: 35
Joined: Thu Nov 27, 2008 3:58 am

Post by lvella »

I changed the code to something like:

Code: Select all

node = pSceneManager->createSceneNode();
entity = pSceneManager->createEntity(randomName, "object.mesh");
node->attachObject(entity);

Ogre::Vector3 scale(2.5f, 2.5f, 2.5f);
node->setScale(scale);

node->setPosition(characterNode->_getDerivedPosition());
Ogre::PCZone* zone = characterNode->getHomeZone();
((Ogre::PCZSceneNode*)node)->setHomeZone(zone);
zone->_addNode((Ogre::PCZSceneNode*)node);
node->setPosition(origin);
but I still have no objects thrown outside the default zone.
Chaster
OGRE Expert User
OGRE Expert User
Posts: 557
Joined: Wed May 05, 2004 3:19 pm
Location: Portland, OR, USA
Contact:

Post by Chaster »

lvella,

I think you might be running into a bug which I just uncovered that was introduced with the last change I committed to the SVN. Check to see if your node is "anchored" to the default zone. I made the mistake of making all scenenodes created using PCZSceneNode::createChildSceneNode() anchored if the parent node was anchored. That was a bad assumption.

If that is indeed the problem, you'll need to modify the code a little bit to make sure the node is not anchored. I'll be checking in some modifications soon that will fix this particular bug (but they also introduce the conversion of Portals to a type of MovingObject, which is a pretty significant change..)


Chaster
p.s. If you have more questions/problems, please ask in the new PCZSceneManager subforum in the Addons Forum. I'm no longer actively monitoring these other forums for PCZSM related stuff.
Post Reply