Newbie Question

Buckcherry

22-06-2006 21:13:11

Hi everybody,

I do not get to make to work OgreNewt. I do not know where is the error...

I have done the following:

In a class called Main I have defined:OgreNewt::World* mWorld;
OgreNewt::BasicFrameListener* mOgreNewtListener;
as Private.
The constructor of this class is like this:
Main::Main(): mGUIRenderer(0), mGUISystem(0), mEditorGuiSheet(0)
{
// OgreNewt
mWorld = new OgreNewt::World();
}


And the createFrameListener method is:

void Main::createFrameListener(void)
{
mFrameListener->showDebugOverlay(false);

mRoot->addFrameListener(mFrameListener);

// OgreNewt
mOgreNewtListener = new OgreNewt::BasicFrameListener( mWindow, mSceneMgr, mWorld, 120 );
mRoot->addFrameListener( mOgreNewtListener );

}


I pass the mWorld as parameter in the MouseQueryListener class:

mFrameListener = new MouseQueryListener(mWindow, mCamera, mSceneMgr, mGUIRenderer, mRoot, mGUISystem, mEditorGuiSheet, mWorld);

The MouseQuerListener's constructor is:

MouseQueryListener::MouseQueryListener(RenderWindow* &win, Camera* &cam, SceneManager* &sceneManager, CEGUI::OgreCEGUIRenderer* &renderer, Root* &root, CEGUI::System* &guiSystem, CEGUI::Window* &editorGuiSheet, OgreNewt::World* &mWorld)
: ExampleFrameListener(win, cam, true, true), mGUIRenderer(renderer)
{

...

// OgreNewt
_world = mWorld;

...

}


To create a physic body I use the function:

void createPhysicalBody(OgreNewt::World* &mWorld)
{

// rigid body.
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Cylinder( mWorld, 2, 4 );
mBody = new OgreNewt::Body( mWorld, col );
mBody->attachToNode( mMainNode );
// initial position
mBody->setPositionOrientation( Ogre::Vector3(-2,3,2), Ogre::Quaternion::IDENTITY );
delete col;
Ogre::Real mass = 10.0;
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcCylinderSolid( mass, 2, 4 );
mBody->setMassMatrix( mass, inertia );
mBody->setStandardForceCallback();

}


But when I run the game, the character does not fall due to the gravity!!!. In fact, there is not collision between bodies, gravity... nothing...

What is wrong?.

Any idea?

CaseyB

22-06-2006 21:37:38

You have to manually update the world each frame. If you look at the example frame listener it'll show you how to do this.

HexiDave

22-06-2006 22:50:20

No, he has a BasicFrameListener going - that takes care of Newton for the most part.

I just woke up, so I may have missed it - but where do you actually create an entity to attach a physics object to? Check the Wiki tutorial again or the sample code - you create a new sceneNode (child of your main sceneNode) and attach it to the entity and attach the body to the node.

Buckcherry

22-06-2006 23:43:47

Well, now I can see the rigid bodies, but when I move one towards the another one nothing happens!.

I am not using forces to move it, I am using setPositionOrientation.

What is wrong?.

Buckcherry

22-06-2006 23:56:53

HexiDave: As you can see the rigid body is attached to mMainNode, which is the SceneNode which contains the entity of the character. mMainNode is a child of rootSceneNode.

In the constructor character's class the createPhysicalBody method is called to create the rigid body for the character.

Do you know why the bodies does not fall due to the gravity???.

I have tried to use:

mWorld->update(evt.timeSinceLastFrame);

In the frameStarted method, but it does not make any difference.

Any idea?.

HexiDave

23-06-2006 00:23:52

Well, now I can see the rigid bodies, but when I move one towards the another one nothing happens!.

I am not using forces to move it, I am using setPositionOrientation.

What is wrong?.


You have to use forces, otherwise Newton doesn't do any collision detection, you're just pushing objects through each other.

Buckcherry

23-06-2006 07:51:56

I have put this line:

mBody->setStandardForceCallback();

And the body does not fall!!!. Why it is not affected by the gravity??.

What is wrong?

Buckcherry

23-06-2006 09:04:51

I have found the problem: I have to defined the WorldSize of OgreNewt.

This had not to be defined in the previous version, had it?.

Is there any way to detect collisions just moving the bodies rather than using forces?.

How do I apply the forces?. mBody->addForce() ???

HexiDave

23-06-2006 19:07:27

If you really want to just test intersections instead of using Newtonian physics (i.e. if circle A touches square B, you win) then look into using primitive shapes (circle, sphere, cube, etc) to test intersections. Google it.

Buckcherry

24-06-2006 20:25:27

Is it possible to use OgreNewt ONLY to dectect collisions between bodies?.

If so, how???

OvermindDL1

25-06-2006 04:10:36

Yes, and there is an entire namespace for the collision testing functions. :)

Buckcherry

25-06-2006 12:51:05

I have tried to move the bodies using setPositionOrientation and it that way there is not collision detection. Using setVelocity the collisions are detected.

Is there any way to detect collisions moving the bodies using setPositionOrientation ?

walaber

26-06-2006 07:03:54

yes. you have to check for collisions yourself.

in fact, if you JUST want to check for collisions, you don't need to make any Rigid Bodies. just make the Collision objects, and then use the collision commands directly. commands like CollisionCollide. this will tell you if any 2 collision shapes are colliding, and if they are, provide lots of information.

Buckcherry

26-06-2006 08:30:48

Ok. I will try...

THANKS!!! :D