Mogernewt force help

Quall

18-02-2009 23:44:15

Hello, I am going through some basic newton examples but am having trouble getting the body to update without setting the velocity myself. If anyone sees something I am doing wrong or has some input on helping I would appreciate it.

I set up a basic body and scene node:


World _NewtonWorld = new World();

SceneNode node = _SceneManager.RootSceneNode.CreateChildSceneNode();
Entity ent = _SceneManager.CreateEntity( "Juno" , "Juno.mesh" );
node.AttachObject( ent );
node.SetPosition( 0 , 0 , 0 );

float mass = 1000;
Collision col = new CollisionPrimitives.Capsule( _NewtonWorld , ent.BoundingRadius , ent.BoundingBox.Size.y );
Body nodebody = new Body( _NewtonWorld , col );
nodebody.SetMassMatrix( mass , MogreNewt.MomentOfInertia.CalcCylinderSolid( mass , ent.BoundingRadius , ent.BoundingBox.Size.y ) );
nodebody.AttachToNode( node );
nodebody.IsGravityEnabled = false; //gravity does nothing?


Then in my update loop, I do this:

Vector3 force = new Vector3( 0 , -98f , 0 ); //sim gravity force
force *= 1000;
nodebody.AddForce( force );

_NewtonWorld.Update( timeSinceLastUpdate );


The body does not seem to move at all. I try adding local and global force as well, with no results. I do not set any callbacks because there is nothing to collide with in the scene, are they required? When I call this, it sets the velocity and the body then moves a little.
nodebody.Velocity = new Vector3( -10f , 0 , 0 );

GantZ

19-02-2009 11:58:18

you have to use a forcecallback for your body if you want to add force to it. the functions related to adding force only work on a forcecallback.

for exemple in the setup function you will have

nodebody.ForceCallback += new ForceCallbackHandler(ForceCallbackfunc);


and the forcecallback function related


void ForceCallbackfunc(Body body)
{
float mass;
Vector3 inertia;

body.GetMassMatrix(out mass,out inertia);

Vector3 force = new Vector3( 0 , -200f , 0 );
force *= mass;
body.AddForce( force );
}

Quall

20-02-2009 14:22:16

awesome thanks. That did the trick.