TreeCollision woes, please help

bowringjb

17-11-2006 23:53:18

Hi, can anyone advise me please, im pulling my hair out trying to get this code to work, i have ogrenewt up and running, my program loads a scene, creates a sphere body attached to a node and creates a tree body to represent the environment. i originally wrote the code quickly in a non object oriented way, with my functions for creating collisions and bodies at the top of the source. This worked fine, running with my sphere body bouncing around the scene perfectly, however I then tried to clean up my code and implemented the whole thing with classes but since doing this i am getting an inexplicable error. The code compiles but throws an exception when it tries to create the tree collison object.
It points me towards ogrenewt_collisionprimitives.cpp and the following section of code:

while (child_it.hasMoreElements())
{
_parseNode( (Ogre::SceneNode*)child_it.getNext(), thisOrient, thisPos );
}


in the function TreeCollisionSceneParser::_parseNode

Heres the definition of my application class:

class MutateApp : public FrameListener
{
public:
virtual void go(void);
virtual bool setupScene(void);
virtual void setupResources();
virtual void createFrameListener();
virtual bool frameStarted(const FrameEvent& evt);
virtual bool frameEnded(const FrameEvent& evt);
virtual bool setupInput();
virtual bool setupPhysics();
virtual OgreNewt::Body* MutateApp::CreateBoxBody ( OgreNewt::World* world, SceneNode* node, Vector3 pos, Quaternion rot, Vector3 scale, Real mass );
virtual OgreNewt::Body* MutateApp::CreateSphereBody ( OgreNewt::World* world, SceneNode* node, Vector3 pos, Quaternion rot, Vector3 size, Real mass );
virtual OgreNewt::Body* MutateApp::CreateTreeBody ( OgreNewt::World* world, SceneNode* node );

Root* mRoot;
RenderWindow* mWindow;
SceneManager* mSceneManager;
Camera* mCamera;
Viewport* mViewport;
SceneNode* nLevel;
SceneNode* nPlayer;
OISInterface* Input;
OgreNewt::World* mWorld;
OgreNewt::Body* rbPlayer;
OgreNewt::Body* rbLevel;
};


here is the code for setting up the scene:

bool MutateApp::setupScene(void)
{
// Initialisation of Root and SceneManager
mRoot = new Root("E:/XPDocuments/Programming/ogre/installation/OgreSDK/bin/release/plugins.cfg","../ogre.cfg","C:/OGRE/ogreprojects/mutability/Mutability2/Mutability2/log/ogre.log");

// Get graphics conig
if(!mRoot->showConfigDialog())
{
return 1;
}

// create window
mWindow = mRoot->initialise(true,"Mutability");

// create scenemanager
mSceneManager = mRoot->createSceneManager(ST_GENERIC,"sceneManager");

// create camera
mCamera = mSceneManager->createCamera("Camera");
mCamera->setPosition(Vector3(50.0f,50.0f,50.0f));
mCamera->lookAt(Vector3(0.0f,0.0f,0.0f));
mCamera->setNearClipDistance(5.0f);
mCamera->setFarClipDistance(5000.0f);
mCamera->setProjectionType(PT_PERSPECTIVE);
mCamera->setFOVy(Radian(Angle(36)));

// add viewport and bind camera
mViewport = mWindow->addViewport(mCamera);
mViewport->setBackgroundColour(ColourValue(0.0f,0.0f,0.0f));

// set camera aspect ratio
mCamera->setAspectRatio(Real(mViewport->getActualWidth())/Real(mViewport->getActualHeight()));

// add light
Light* light = mSceneManager->createLight( "Light1" );
light->setType( Light::LT_POINT );
light->setPosition( Vector3(0, 550, 250) );
light->setDiffuseColour( 1.0, 1.0, 1.0 );
light->setSpecularColour( 1.0, 1.0, 1.0 );

//setup resource paths
setupResources();

//create frame listener
createFrameListener();

//setup input
setupInput();

// Load Level
Entity* eLevel = mSceneManager->createEntity( "level","level2.mesh" );
nLevel = mSceneManager->getRootSceneNode()->createChildSceneNode("static_level_node");
nLevel->attachObject(eLevel);
nLevel->setPosition(Vector3(0,0,0));

// Load Player
Entity* ePlayer = mSceneManager->createEntity( "player","texbox.mesh" );
nPlayer = mSceneManager->getRootSceneNode()->createChildSceneNode("dyn_player_node");
nPlayer->attachObject(ePlayer);

//setup physics
setupPhysics();

return true;
}


and the code for setting up the physics:

bool MutateApp::setupPhysics()
{
// create world and set world extents
Vector3 min = Vector3(-1000,-1000,-1000);
Vector3 max = Vector3(1000,1000,1000);
mWorld = new OgreNewt::World();
mWorld->setWorldSize(min,max);

//create player and place in world
rbPlayer = CreateSphereBody(mWorld,nPlayer,Vector3(0,10,0),Quaternion::IDENTITY,Vector3(5,5,5),5);
rbPlayer->setStandardForceCallback();

//create level and place in world
rbLevel = CreateTreeBody(mWorld,nLevel);
return true;
}


and finally the routine which actually throws the error:

OgreNewt::Body* MutateApp::CreateTreeBody ( OgreNewt::World* world, SceneNode* node )
{
OgreNewt::CollisionPrimitives::TreeCollisionSceneParser* coll;
coll = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser(world);
coll->parseScene(node, true);
OgreNewt::Body* body = new OgreNewt::Body(world,coll);
return body;
}


any help would be greatly appreciated, thanks

lonwolf

19-11-2006 16:07:44

0.o what ur tryin to there mate sounds really new to me.. heres a more simple way to use TreeColision or TCSceneParser. and its works:

//Setup terrain
Entity* teren = main_var.mSceneMgr->createEntity( "terenentity", "insula_khalazar.mesh" );
SceneNode *ts = main_var.mSceneMgr->getRootSceneNode()->createChildSceneNode("tn", Vector3(0,27,0), Quaternion::IDENTITY);
ts->attachObject( teren );
teren->setNormaliseNormals(true);
OgreNewt::Collision* colDotScenw = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser(mWorld,ts);
OgreNewt::Body* bodDotScenw = new OgreNewt::Body( mWorld, colDotScenw );
delete colDotScenw;
bodDotScenw->attachToNode(ts);
main_var.teren_body=bodDotScenw;
Entity* river_1 = main_var.mSceneMgr->createEntity("corupted_river","rau1.mesh");
SceneNode* river_1_n = main_var.mSceneMgr->getRootSceneNode()->createChildSceneNode("corupted_river_node",Vector3(-106.609,50.5214,-941.629),Quaternion(-0.693558,0,-0.720401,0));
river_1_n->attachObject(river_1);
river_1->setMaterialName("rau_dirty_cg");
Entity* river_2 = main_var.mSceneMgr->createEntity("clean_river","rau2.mesh");
SceneNode* river_2_n = main_var.mSceneMgr->getRootSceneNode()->createChildSceneNode("clean_river_node",Vector3(309.865,40.6258,695.74),Quaternion(-1,0,0,0));
river_2_n->attachObject(river_2);
river_2->setMaterialName("rau_clean_cg");


note that here the TreeColisionSceneParser receives the NewtonWorld and the sceneNode and returns a colision object. its much easier because you dont need to parse the node with that _parse() function. simple use the constructor and you shall get your colision object, use it to create a body, ad voila you have a complex colision object (and like all treecol with infinite mass and thus unmovable :))

bowringjb

19-11-2006 23:59:55

okay, i tried your approach but now it wont compile because of this line:

OgreNewt::Collision* colDotScenw = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser(mWorld,ts);

it claims that TreeCollisionSceneParser only takes one argument (mWorld)

lonwolf

20-11-2006 17:53:03

thats because of the version of ogreNewt your using... i forgot the version im using.. it was the last version available in august 2006. i dont know really. if the lib changed (if your using something newer) then shout for Walaber for a sample code. im using the lib and that code and it works..