MogreNewt problem

Eldritch

31-03-2007 11:55:24

I have a big problem with MogreNewt, check this thread:

http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=3952

If I comment out everything belonging to MogreNewt from that class, it works. Even if I uncomment only the World reference, the class stops working.

Blackbeard

31-03-2007 18:43:16

Just a shot in the blue:

Have you copied Newton.dll in your (i think) release/debug folder?
And cant see "using MogreNewt;" somewhere?

Eldritch

01-04-2007 02:04:02

I don't have the Newton.dll, but I do have MogreNewt.dll.

I have not defined "using MogreNewt" because I thought that was the problem first, but that is not really needed since I can just type MogreNewt.<whatever> to access objects from MogreNewt.

Blackbeard

01-04-2007 04:04:56

You mentioned that any class with MogreNewt involved crashes?
If i dont use MogreNewt.dll with Newton.dll, my app. crashes.
Made me think MogreNewt.dll depends on Newton.dll in any form.

It compiles fine if i put out the lines i dont have the code for (i.e GWF.Script?).
Me too is interested to hear what was wrong :wink:

ColorWolf

01-04-2007 08:20:53

I'm pretty sure you need Newton.dll too.

Bekas

01-04-2007 09:41:17

Read this: http://www.ogre3d.org/wiki/index.php/MogreNewt

Eldritch

01-04-2007 10:43:59

That worked! Thanks a lot Bekas. Weird error though.. usually you get an exception when you're missing a DLL, not a corrupt class :)

Now for my next question.. sorry for all those.. is it possible to set the gravity constant?

Bekas

01-04-2007 11:16:54

is it possible to set the gravity constant?
Nope, you should add your custom force like this:
body.IsGravityEnabled = false;
body.ForceCallback += new ForceCallbackHandler(body_ForceCallback);

void body_ForceCallback(Body body)
{
float mass;
Vector3 inertia;
body.getMassMatrix(out mass, out inertia);

Vector3 force = new Vector3(0, -9.8f, 0); // standard gravity
force *= mass;

body.addForce(force);
}


This custom force should be added manually to all newton bodies.

Eldritch

01-04-2007 11:19:33

Okey, great! Might never know if non-Earth gravity will be needed ;)

One last thing.. what is a good to calculate the size of a collision body? The following lines:


Collision col = new MogreNewt.CollisionPrimitives.Ellipsoid
(
CPhysicsServer_s.Instance.GetPhysWorld(),
refEntity.BoundingBox.Maximum
);

Collision col = new MogreNewt.CollisionPrimitives.Box
(
CPhysicsServer_s.Instance.GetPhysWorld(),
new Vector3(refEntity.BoundingRadius, refEntity.BoundingRadius, refEntity.BoundingRadius)
);


I use the maximum extents of the bounding box and the bounding radius, just to test.. but I feel I need a good way to calculate this. Any ideas?

Eldritch

01-04-2007 14:41:34

Nevermind me saying that the previous question was the last.. not entirely grasping how all this works.. physics was never my strong subject.

I am trying to move my entity. It's a robot. If I use setForce(), it does not move an inch, but if I use setVelocity() it moves, but topples over quite a lot.. how can I prevent that and keep it upright all the time?

The only stuff I really need this for is collision. I don't really need any rigid body dynamics or anything.

ColorWolf

01-04-2007 17:06:19

Check out this post

http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=2110&highlight=getbodyorientation

The 3rd step in the post might help you out.

Eldritch

01-04-2007 18:28:22

Thanks for showing me that thread!! Gave me quite useful information that I had missed out on in the SDK samples.

Now all I need is collision between several entities. I have a box and a robot. Both collide well with the geometry, but they do not collide with each other. What can be wrong there?

Eldritch

03-04-2007 06:51:33

Code:


// Creating World.
public void SetupPhysWorld()
{
m_refPhysWorld = new MogreNewt.World();
MogreNewt.CollisionPrimitives.TreeCollisionSceneParser parser = new MogreNewt.CollisionPrimitives.TreeCollisionSceneParser(m_refPhysWorld);
parser.parseScene(CObjectLibrary_s.Instance.GetWorldNode(), true);
MogreNewt.Body body = new MogreNewt.Body(m_refPhysWorld, parser);
parser.Dispose();

body.attachToNode(CObjectLibrary_s.Instance.GetWorldNode());
body.setPositionOrientation(CObjectLibrary_s.Instance.GetWorldNode().Position,
CObjectLibrary_s.Instance.GetWorldNode().Orientation);
}

// Updating. Constant value for now.
public void Update()
{
if (m_refPhysWorld != null)
m_refPhysWorld.update(0.01f);
}



// Setting up physics for a character.
public void SetupPhysBodyEllipsoid(CCharacter refCharacter)
{
Entity refEntity = refCharacter.GetEntity();
SceneNode refNode = refCharacter.GetSceneNode();

float mass = refEntity.BoundingBox.Volume * 2.5f;
Vector3 inert = MomentOfInertia.CalcEllipsoidSolid(mass, refEntity.BoundingBox.Maximum);

Collision col = new MogreNewt.CollisionPrimitives.Ellipsoid
(
CPhysicsServer_s.Instance.GetPhysWorld(),
new Vector3(1, 1, 1)
);

m_refPhysBody = new Body(CPhysicsServer_s.Instance.GetPhysWorld(), col);
col.Dispose();
m_refPhysBody.attachToNode(refNode);
m_refPhysBody.setMassMatrix(mass, inert);
m_refPhysBody.IsGravityEnabled = true;
m_refPhysBody.setPositionOrientation(refNode.Position, refNode.Orientation);
m_refPhysBody.setAutoFreeze(0);
m_refPhysBody.ForceCallback += new ForceCallbackHandler(Character_ForceCallback);

// Restrict rotation to X and Z axes only.
MogreNewt.BasicJoints.UpVector uv = new MogreNewt.BasicJoints.UpVector
(
CPhysicsServer_s.Instance.GetPhysWorld(),
m_refPhysBody,
Vector3.UNIT_Y
);

m_refParentCharacter = refCharacter;
}

// Setting up physics for a prop.
public void SetupPhysBodyBox(CProp refProp)
{
Entity refEntity = refProp.GetEntity();
SceneNode refNode = refProp.GetSceneNode();

float mass = refEntity.BoundingBox.Volume * 2.5f;
Vector3 inert = MomentOfInertia.CalcBoxSolid(mass, refEntity.BoundingBox.Maximum);

Collision col = new MogreNewt.CollisionPrimitives.Box
(
CPhysicsServer_s.Instance.GetPhysWorld(),
new Vector3(1, 1, 1)
);

m_refPhysBody = new Body(CPhysicsServer_s.Instance.GetPhysWorld(), col);
col.Dispose();
m_refPhysBody.attachToNode(refNode);
m_refPhysBody.setMassMatrix(mass, inert);
m_refPhysBody.IsGravityEnabled = true;
m_refPhysBody.setPositionOrientation(refNode.Position, refNode.Orientation);
m_refPhysBody.setAutoFreeze(0);
m_refPhysBody.ForceCallback += new ForceCallbackHandler(Prop_ForceCallback);
m_refParentProp = refProp;
}


I have no idea what can be missing to allow character-character and character-prop collisions...

Eldritch

04-04-2007 13:15:11

Seems like I defined a too small collision ellipsoid and box for the objects. However, increasing their size causes a lot of strange errors. My robot is effectively hovering now.. and starts to rise up from the ground when I boot the app... it's really weird.

Is there any way to display the collision primitives set on entities??? I need to see how large my ellipsoid really is.

Bekas

05-04-2007 11:09:41

You can display the newton debug lines. Check the MogreNewt samples to see how it's done (you press 'F3' at these samples for the debug lines to show up).

Eldritch

05-04-2007 12:50:21

I only get lines on the geometry.. not on anything else..