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:
in the function TreeCollisionSceneParser::_parseNode
Heres the definition of my application class:
here is the code for setting up the scene:
and the code for setting up the physics:
and finally the routine which actually throws the error:
any help would be greatly appreciated, thanks
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