[solved] Body does not fall! Help!

Camelot

08-03-2008 08:19:01

Hello,
I’m a beginner and as all beginner, I’m having certainly little problems with my first ogreNewt application. It is very simple and I started following the unique tutorial found in wiki. Are there other tutorials for this add-on on internet? I will be very glad to you if you could indicate me other documents…
Going to my problem…. I wrote this simply code where a cylinder has to simply fall down on the floor.


#include "ExampleApplication.h"
#include <OgreNewt.h>



// Event handler
class CameraTrackListener: public ExampleFrameListener
{
protected:
public:
CameraTrackListener(RenderWindow* win, Camera* cam)
: ExampleFrameListener(win, cam)
{
}

bool frameStarted(const FrameEvent& evt)
{
if( ExampleFrameListener::frameStarted(evt) == false )
return false;


return true;
}
};

class CameraTrackApplication : public ExampleApplication
{
private:
OgreNewt::World* mWorld;
Ogre::FrameListener* mNewtonListener;
public:
CameraTrackApplication() {
mWorld = new OgreNewt::World();
}

~CameraTrackApplication() {
delete mWorld;
OgreNewt::Debugger::getSingleton().deInit();
}

protected:
SceneNode* mFountainNode;

// Just override the mandatory create scene method
void createScene(void)
{

// Set ambient light
mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));

// Create a skydome
mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);

// Create a light
Light* l = mSceneMgr->createLight("MainLight");
// Accept default settings: point light, white diffuse, just set position

l->setPosition(20,80,50);

Entity *ent;

// Define a floor plane mesh
Plane p;
p.normal = Vector3::UNIT_Y;
p.d = 200;
MeshManager::getSingleton().createPlane(
"FloorPlane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
p, 200000, 200000, 20, 20, true, 1, 50, 50, Vector3::UNIT_Z);

// Create an entity (the floor)
ent = mSceneMgr->createEntity("floor", "FloorPlane");
ent->setMaterialName("Examples/RustySteel");

// Attach to child of root node, better for culling (otherwise bounds are the combination of the 2)
SceneNode* floornode;
floornode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "FloorNode" );
floornode->attachObject(ent);

OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision( mWorld, floornode, false );
OgreNewt::Body* bod = new OgreNewt::Body( mWorld, col );
delete col;
bod->attachToNode( floornode );
bod->setPositionOrientation( Ogre::Vector3(0.0,-200,0.0), Ogre::Quaternion::IDENTITY );

Vector3 size = Ogre::Vector3( 10, 10, 10 );
SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
ent = mSceneMgr->createEntity("cylinder_body", "cylinder.mesh" );
node->attachObject( ent );
node->setScale( size );
// rigid body.
col = new OgreNewt::CollisionPrimitives::Cylinder( mWorld, 10, 10 );
OgreNewt::Body* bod1 = new OgreNewt::Body( mWorld, col );
bod1->attachToNode( node );
// initial position
bod1->setPositionOrientation( Ogre::Vector3(0,200,0), Ogre::Quaternion::IDENTITY );
delete col;
Ogre::Real mass = 10.0;
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcCylinderSolid( mass, 10, 10 );
bod1->setMassMatrix( mass, inertia );
bod1->setStandardForceCallback();


// Put in a bit of fog for the hell of it
mSceneMgr->setFog(FOG_EXP, ColourValue::White, 0.0002);

}

// Create new frame listener
void createFrameListener(void)
{
mFrameListener= new CameraTrackListener(mWindow, mCamera);
mRoot->addFrameListener(mFrameListener);

mNewtonListener = new OgreNewt::BasicFrameListener( mWindow, mSceneMgr, mWorld, 60 );
mRoot->addFrameListener(mNewtonListener);
}


};



#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
// Create application object
CameraTrackApplication app;

try {
app.go();
} catch( Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occured: " << e.getFullDescription();
#endif
}


return 0;
}

#ifdef __cplusplus
}
#endif



The proble is that if does not fall! :?
Could you kindly help me to solve the problem and go ahead?

Thank you,

Camelot

koirat

08-03-2008 09:04:57

I do not know if this is your problem since i did not read your whole code. But i have got problem with body not falling myself. Somebody forget to mention very important point in tutorials, World of newton contains in (-100,-100,100,100) box so everything outside or coliding with wals is going to stuck. In your code i saw setting position y=200. So this can be your problem. You can resize world box by calling World->SetSize or sth like his.

Camelot

08-03-2008 11:13:49

The problem was that. Thank you for the hint!
Do you now any good tutorial on the topic??

Camelot

koirat

08-03-2008 12:03:11

I have just started my fun with ogre and Newton and i do not know much, Right now im reading Tutorials that comes with newtonSDK there is no shortcut after installation Newton Dynamics, but you can find tutorials *.doc in your instalation location.

Camelot

08-03-2008 14:42:48

Thank you again! :D