OgreMax with OgreNewt

tlc

24-01-2008 03:08:57

I tried the demo2 - Joint given by the OgreNewt samples :)

Thereafter, I added OgreMax scene file (I created a big plane as Floor) into the program, but the ball falls nicely, but now does not bounce when in contact with the floor (it falls through the floor).

DemoApplication.h
class DemoApplication : public ExampleApplication
{
public:
DemoApplication(void);
~DemoApplication(void);
private:
OgreNewt::World *mWorld;
OgreNewt::BasicFrameListener *mNewtonListener;

OgreMaxScene *mScene;
};


DemoApplication.cpp:
void DemoApplication::createScene()
{
mScene->Load("../../media/scenes/trial/trial.scene", mWindow);
SceneManager *mgr = mScene->GetSceneManager();
:
:
OgreNewt::CollisionPrimitives::TreeCollisionSceneParser *col = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser (mWorld);

col->parseScene ( mgr->getSceneNode("Floor"), true );
// 'Floor' node defined in .scene file
OgreNewt::Body *body = new OgreNewt::Body (mWorld, col);
delete col;
body->attachToNode( mgr->getSceneNode("Floor") );
:
:
}

void DemoApplication::createFrameListener()
{
mFrameListener = new DemoFrameListener (mWindow, mCamera, mScene->GetSceneManager(), mWorld, mCamNode);
mRoot->addFrameListener(mFrameListener);

mNewtonListener = new OgreNewt::BasicFrameListener(mWindow, mScene->GetSceneManager(), mWorld, 120 );
mRoot->addFrameListener(nNewtonListener);
}

DemoFrameListener.h
class DemoFrameListener : public ExampleFrameListener
{
protected:
OgreNewt::World *mWorld;
:
:
public:
DemoFrameListener(RenderWindow *win, Camera *cam, SceneManager *mgr, OgreNewt::World *W, SceneNode *ncam);
~DemoFrameListener(void);
:
:
};

DemoFrameListener.cpp:
DemoFrameListener::DemoFrameListener(RenderWindow *win, Camera *cam, SceneManager *mgr, OgreNewt::World *W, SceneNode *ncam) : ExampleFrameListener(win, cam)
{
mWorld = W;
mCamNode = ncam;
mSceneMgr = mgr;
mCamera = cam;
}

bool DemoFrameListener::frameStarted(const FrameEvent &evt)
{
// when spacebar is pressed
Entity *ent = mSceneMgr->createEntity("Ball", "ellipsoid.mesh");
SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Ball");
node->attachObject(ent);
ent->setMaterialName("Simple/dirt01");
ent->setNormaliseNormals(true);

OgreNewt::Collision *col = new OgreNewt::CollisionPrimitives::Ellipsoid (mWorld, Ogre::Vector3(1,1,1));
OgreNewt::Body *body = new OgreNewt::Body(mWorld, col);

Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcSphereSolid(10.0, 1.0);
body->setMassMatrix(10.0, inertia);
body->attachToNode(node);
body->setStandardForceCallback();
:
:
}


The floor body and the ball body does not interact :(

Rgds,
TLC

tlc

24-01-2008 06:17:11

Oops.. it was my mistake!

The height of the floor specified in the trial.scene file is -75.0. That's why the ball falls through.. :lol:

tlc

28-01-2008 05:16:21

I loaded a scene file (a simple one) and in my codes, I created another entity. I created a scenenode tree with the parent node from the scene file.

I used the TreeCollisionSceneParser to parse through the parent node. However, the collision only detect the parent node, but not the child node.

void DemoApplication::createScene()
{
mScene->Load("../../media/scenes/trial/trial.scene", mWindow);
SceneManager *mgr = mScene->GetSceneManager();

// create and setup the camera
mCamera = mgr->createCamera("Camera01");

Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(mCamera);

SceneNode *floornode = mgr->getSceneNode("Box13");

// add some other objects.
Entity *stair = mgr->createEntity("Stair", "WoodPallet.mesh");
SceneNode *stairnode = floornode->createChildSceneNode("Stair");
stairnode->attachObject(stair);
stair->setMaterialName("Examples/RustySteel");
stair->setCastShadows( false );
stairnode->setPosition( Ogre::Vector3(80.0f, 363.0f, 0.0f) );

// using the new "SceneParser" TreeCollision primitive. this will
// automatically parse an entire tree of SceneNodes (parsing all children),
// and add collision for all meshes in the tree.
OgreNewt::CollisionPrimitives::TreeCollisionSceneParser* stat_col = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser( mWorld );
stat_col->parseScene( floornode, true );
OgreNewt::Body* bod = new OgreNewt::Body( mWorld, stat_col );
delete stat_col;
bod->attachToNode( floornode );
bod->setPositionOrientation( Ogre::Vector3(0.0,-360.0,0.0), Ogre::Quaternion::IDENTITY );

Very puzzled why the childnode (stair) node not detected? :(

dudeabot

28-01-2008 14:15:36

humm

you can try using the ogremaxcallback finishedcreatingnode and see if it works :D

or change the node to roostcenenode

tlc

29-01-2008 02:12:34

humm

you can try using the ogremaxcallback finishedcreatingnode and see if it works :D

or change the node to roostcenenode


Thanks! I changed to rootscenenode and it works!