[SOLVED] change scene?

r1cky17

25-09-2007 06:06:59

i try to make racing game, but i have a problem to change scene. like from stage 1 and then change to stage 2.

question :
1. how to change scene from stage 1 to stage 2?
2. how to set follow camera to the car?

Evak

25-09-2007 17:45:26

Most of that will require coding knowledge and understanding of Ogre. Ofusion Pro supports subfolder media loading with dynamic resource dir updating.

This helps avoid things like duplicate media because ogre gets its resources from the .OSM file. So basicly to load a new scene you would have to kill the current scene and simply load a new OSM scene file through the scene loader.

I'm not a programmer, so I can't help you with details, but thats basicly how you go about it.

For the camera behind the car, for a very basic static camera behind your car. You just link the camera to the car to make the camera a child of the car mesh in max. When you load your car OSM into the scene loader, moving the car will move the camera with it.

r1cky17

08-10-2007 03:21:36

thx Evak, i can change the scene right now.

but for the follow camera i try your solution but the camera position is diffirent from the max file and the camera target is rotate about 90 degree.

is it always like that?
how to fix that?

Evak

08-10-2007 03:58:07

actually I'm noticing the same thing here, you can flip the camera, but the position seems to be off. I hadn't used it for accuracy before, but this week I started using it for a third person camera and it was offset by quite a bit.



this last picture isn't very accurate as the max image is orthographic, and our editor image in perspective, so it might not actually show anything usefull.



However its obvious that there is a problem when you see the camera in relation to the player in the in game pics. (ignore scenery). It might be a bug, so hopefully lioric will read the thread and check.

Lioric

09-10-2007 16:27:05

The issue will be reviewed, could you provide us with a test scene where this can be reproduced?

Evak

10-10-2007 18:14:38

I'll sort you out with a scene for the camera tomorrow. Still on a short holiday break at the moment :).

r1cky17

14-10-2007 12:22:37

hi, i can change the scene. but the old map is still there.
so the map became combine the 1st map and the 2nd map.
here i show the 1st map and the 2nd map that i want, and the map that was combine

here is the 1st map


the 2nd map


the combine map


here is the code that i use for change the map

OSMScene *Track = new OSMScene(mSceneMgr, mWindow);
OSMSceneCallbacks *EventCallbacks = new OSMSceneCallbacks();

Track->initialise("t1.osm", EventCallbacks);
Track->createScene();
mSceneMgr = Track->getSceneManager();

Ogre::Vector3 pos = Ogre::Vector3(8.69634, 6.25449, -20.4713);
mCar->setPositionOrientation(pos, Quaternion(Degree(90), Vector3::UNIT_Y));


how to fix that combine osm?

Evak

14-10-2007 17:36:51

Were using our Blitzmax wrapper so I'm not sure about in C++. But we have a whole bunch of destroy functions for removing different parts of a scene.

The most basic one for an OSMSCENE_Destroy

theres also a bunch of destroy, destroy all, and destroy with name type functions for nodes, entities, and chilldren, all children etc.

You have to destroy the parts of your scene that you no longer need before loading in the next one.

r1cky17

15-10-2007 09:03:15

i can destroy the entity, but i do it manually.
so i must know the name of the entity and then i destroy that entity.

is there a way to destroy the entity automatically?
like taking all the name of the entity from the OSM file.

thx for the help

Evak

15-10-2007 15:56:49

it's normal to have to do it manualy. The way that ofusion currently works is the best way. With Ofusion pro you can load in your gameplay objects as seperate OSM files with their heirarchy and mount nodes intact. So you can load in seperate OSM's for scene, player characters, vehicles, powerups, lighting schemes etc.

If it automaticly removed the previous OSM when you loaded a new one you would be extremely limited in what you could do. It would be convenient if all you want to do is view a scene, but most people want to do more than that.

Lioric

16-10-2007 04:02:08

There are multiple methods for clearing the scene, and what method you use depends on your project needs

You can use the "clearScene" method of the scene manager to remove all of your scene contents before loading a different level

Or if you prefer more control, you can ask the OSMScene object for the entities, lights and cameras list ("getCameraList", "getLightList" and "getEntityList" methods), they will provide you with a list of the loaded objects of the scene, and use them as you need

r1cky17

16-10-2007 06:30:20

hi, i can delete the entity, but the colision from the 1st map is still there
how to clear the colision?

here is the code that i use to set colision

SceneNode* bodyNode = mSceneMgr->getSceneNode(bodyName);
Vector3 currPos = bodyNode->getPosition();
Quaternion currOrient = bodyNode->getOrientation();

OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision( m_World, bodyNode, false );
OgreNewt::Body* bod = new OgreNewt::Body( m_World, col );
delete col;

bod->attachToNode(bodyNode);
bod->setPositionOrientation(currPos, currOrient);


i have try to use clearScene before, but i got an error in the run time.
so i use xml file to delete that entity


TiXmlDocumentPtr mXMLDoc = TiXmlDocumentPtr(new TiXmlDocument());
DataStreamPtr pStream = ResourceGroupManager::getSingleton().openResource(mapFileName);

size_t iSize = pStream->size();
char *pBuf = new char[iSize+1];
memset(pBuf, 0, iSize+1);
pStream->read(pBuf, iSize);
pStream.setNull();
mXMLDoc->Parse(pBuf);
delete[] pBuf;

if(!mXMLDoc.isNull())
{
TiXmlElement* rootElem = mXMLDoc->RootElement();
try
{
TiXmlElement *pMeshNode = rootElem->FirstChildElement("entities");
if(pMeshNode)
{
for (TiXmlElement* pMeshElem = pMeshNode->FirstChildElement();
pMeshElem != 0; pMeshElem = pMeshElem->NextSiblingElement())
{
const char *pszFileName = pMeshElem->Attribute("name");
mSceneMgr->destroyEntity(pszFileName);
}
}
} catch(...)
{
}
}


thx for the help

Evak

16-10-2007 07:10:38

you probably have to clear the collision in your physics system, the physics is going to be seperate from your ofusion meshes and will probably have to be killed. Some kind of function that synchronises the killing of the collision with the ogre entity in the scene manager.

I don't know what physics lib you are using, they all handle collisions a little differently, and have various methods for creating and destroying collision and physics on an object.

Evak

16-10-2007 07:16:20

In our blitzmax ogre wrapper, for newton physics we have the following functions that might be used:

OGRENEWTWORLD_destroyAllBodies @4599
OGRENEWTWORLD_destroy @4612

OGRENEWTCOL_destroy @230
BODY_destroy @236

Which can all be used to destroy certain aspects of Newtons physics solution.

Lioric

16-10-2007 16:37:42

When you create the phy body object, add it (its pointer) as a "UserDefinedObject" to your entitiy (see the Ogre documentation)

When you are clearing your entitites, get the phy body object from the entitiy (from the previously added UserDefinedObject, or userAny methods) and use as you need

r1cky17

18-10-2007 07:37:51

how to add as UserDefinedObject?
i have try but i don't get it.

Lioric

18-10-2007 15:57:39

See the "setUserObject" or "setUserAny" methods of the Entity class (derived from MovableObject)

With these methods you can store the pointer to the geom body in each entitiy

r1cky17

11-11-2007 19:32:54

thx Lioric,
i can delete the body now :D
http://www.ogre3d.org/phpBB2addons/view ... 2156#32156

r1cky17

12-11-2007 07:53:19

hi, ask again :)
after i load the map, i delete all the entity object and the sceneNode of that object.
but some object not deleted
why? is there a problem from the exporting from 3DsMax?

i use this code to delete the entity and the sceneNode

TiXmlDocumentPtr mXMLDoc = TiXmlDocumentPtr(new TiXmlDocument());
DataStreamPtr pStream = ResourceGroupManager::getSingleton().openResource(mapFileName);

size_t iSize = pStream->size();
char *pBuf = new char[iSize+1];
memset(pBuf, 0, iSize+1);
pStream->read(pBuf, iSize);
pStream.setNull();
mXMLDoc->Parse(pBuf);
delete[] pBuf;
int count=0;

if(!mXMLDoc.isNull())
{
TiXmlElement* rootElem = mXMLDoc->RootElement();
try
{
// Get mesh filename from entities
TiXmlElement *pMeshNode = rootElem->FirstChildElement("entities");
if(pMeshNode)
{
// Iterate all meshes, creating them.
for (TiXmlElement* pMeshElem = pMeshNode->FirstChildElement();
pMeshElem != 0; pMeshElem = pMeshElem->NextSiblingElement())
{
// Declare mesh resource
const char *pszName = pMeshElem->Attribute("name");
mSceneMgr->destroyEntity (pszName);
mSceneMgr->destroySceneNode (pszName);
}
}
} catch(...)
{
}
}

Lioric

13-11-2007 00:44:27

What do you mean by "object not deleted", are that or those objects added by you or they were loaded by the scene?

Do you create other objects after you load the scene?

Debug your code and step into each entitiy removal, in there you can find why the entitiy is not removed