OgreNewt & PLSM2, Falling through terrain

danni

22-10-2006 16:01:47

This has had me baffled for the longest time and i have tried just about every solution i could see on the forums.

I am building a collision mesh per the tutorial and a few threads on the forum here.

First problem, I can press f3 and see the mesh while it is building, once it is complete f3 crashes the application. Same once the serialized data is loaded completely. I saw others having this issue, but no solutions.

Second, everything falls through the terrain like no collisions are occurring. Just for the sake of ruling potential sources out, i added a buoyancy plane for the water on the level, collides fine with that, so the issue is the generated collision mesh for the terrain. Any clues what i am missing here?


#include "TerrainListener.h"
#include "PlayState.h"


TerrainManager::TerrainManager(PagingLandScapeSceneManager* sceneMgr, OgreNewt::World *m_World, OgreNewt::MaterialID *mat) {

floormat = mat;
mSceneMgr = sceneMgr;
mWorld = m_World;
tileLoadDelegate=new PagingLandscapeDelegate();
tileLoadDelegate->bind(this,&TerrainManager::tileLoaded);
mSceneMgr->setOption("addLoadTileListener",tileLoadDelegate);

tileUnloadDelegate=new PagingLandscapeDelegate();
tileUnloadDelegate->bind(this,&TerrainManager::tileUnloaded);
mSceneMgr->setOption("addUnloadTileListener",tileUnloadDelegate);

mSceneMgr->setOption("LoadNow", NULL);
}

TerrainManager::~TerrainManager() {
delete mWorld;
}


void TerrainManager::tileLoaded(PagingLandscapeEvent* event) {

//recover PLSM2's tile object
int pageX=event->mPagex;
int pageZ=event->mPagez;
int tileX=event->mTilex;
int tileZ=event->mTilez;

String tileData = "page"+StringConverter::toString(pageX) +"-" + StringConverter::toString(pageZ) +"-tile"+StringConverter::toString(tileX)+"-"+StringConverter::toString(tileZ) + ".collision";

if (!tileBodies[tileData])
{

OgreNewt::TreeCollisionSerializer* serializer=new OgreNewt::TreeCollisionSerializer();
OgreNewt::CollisionPrimitives::TreeCollision* collision = NULL;

if(!ResourceGroupManager::getSingleton().resourceExists("PLSM2",tileData)){
vector<void*> params;
int renderLevel=2;
params.push_back(&pageX);
params.push_back(&pageZ);
params.push_back(&tileX);
params.push_back(&tileZ);
params.push_back(&renderLevel);
mSceneMgr->getOption("PageGetTileVertexData_2",&params);

int *numVtx=((int*)params[5]);
Vector3* vertices=((Vector3*)params[6]);

IndexData* indexData=((IndexData*)params[7]);
collision = new OgreNewt::CollisionPrimitives::TreeCollision(mWorld,*numVtx,vertices,indexData,true);

delete[] vertices;
delete numVtx;
serializer->exportTreeCollision(collision,"Collision//" + tileData);
} else {
collision=new OgreNewt::CollisionPrimitives::TreeCollision(mWorld);
DataStreamPtr ptr = ResourceGroupManager::getSingleton().openResource(tileData);
serializer->importTreeCollision(ptr,collision);
}
SceneNode *sn;
sn = mSceneMgr->getRootSceneNode()->createChildSceneNode (tileData);
sn->setPosition(event->mBbox.getCenter());

OgreNewt::Body* body=new OgreNewt::Body(mWorld,collision);
body->setMaterialGroupID(floormat);
body->attachToNode(sn);
tileBodies[tileData] = body;

delete serializer;
if (collision) delete collision;
}
}

void TerrainManager::tileUnloaded(PagingLandscapeEvent* event) {

size_t pageX=event->mPagex;
size_t pageZ=event->mPagez;
size_t tileX=event->mTilex;
size_t tileZ=event->mTilez;

String tileData = "page"+StringConverter::toString(pageX) +"-" + StringConverter::toString(pageZ) +"-tile"+StringConverter::toString(tileX)+"-"+StringConverter::toString(tileZ) + ".collision";

if (tileBodies[tileData]) {
mSceneMgr->getRootSceneNode()->removeAndDestroyChild (tileData);
OgreNewt::Body *body = tileBodies[tileData];
if (body) delete body;
tileBodies[tileData] = NULL;
}
}

sklug

22-10-2006 22:43:48

What size is your world? OgreNewt default to a pretty small size. Try putting in a line like this:


world_.setWorldSize( Vector3( -5000, 0, -5000 ), Vector3( 5000, 2000, 5000 ) );


sklug

P.S. I too have the problem with F3 crashing it, but my terrain collisions work fine.

danni

22-10-2006 23:04:49

Should be big enough.

m_World->setWorldSize(Ogre::AxisAlignedBox(-200000,-200000,-200000,200000,200000,200000));

sklug

22-10-2006 23:55:54

Yeah, thought about it after I posted and if the world wasn't big enough, the objects would simply not move. Doens't match your symptom. You probably know this, but if you've serialized the collision data, then you change the landscape you're loading, the collision data will be all wrong, leading to odd behavior. Just a thought.

sklug

danni

23-10-2006 03:33:49

Yeah, I make sure to clear the cache out if i make such changes. But it still does it even with freshly generated stuff. Thanks for the comments!

Dibalo

20-12-2006 17:50:04

Yeah, I make sure to clear the cache out if i make such changes. But it still does it even with freshly generated stuff. Thanks for the comments!
Please check this: http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=3040
There is the solution.. 8)