Cant seem to get MogreNewt to collide

dannypb

11-07-2011 18:36:03

I wish we had better documentation, I've gone through the Ogre examples as best I could for Mogre. I am not implementing a terrain though (Space Game), so my needs are only for collision detection. I am using Mogre 1.7.1. I've not installed any additional newton libraries beyond the dll's included. The program will compile without errors (the only warnings are on purpose by me to find code section easily). Once in game collision does not work. I pass right through objects that are set with newton. What I have done is this:

Camera body creation

gCamera = gSceneMgr.CreateCamera("Camera");
gCamNode = gSceneMgr.RootSceneNode.CreateChildSceneNode();
gCamNode.AttachObject(gCamera);

gCamNode.Position = new Mogre.Vector3(connReader.GetInt32(11), connReader.GetInt32(12), connReader.GetInt32(13));
gCamNode.LookAt(new Mogre.Vector3(connReader.GetInt32(14), connReader.GetInt32(15), connReader.GetInt32(16)), Mogre.Node.TransformSpace.TS_LOCAL);
mRenderWindow.AddViewport(gCamera);
mRenderWindow.GetViewport(0).BackgroundColour = fadeColour;
ssysid = connReader.GetString(2);
loctid = connReader.GetString(4);

try
{
//implement Camera Physics
MogreNewt.Collision gCamColl = new MogreNewt.CollisionPrimitives.Capsule(gWorld, 1000, 1000, 0);
gCamBody = new MogreNewt.Body(gWorld, gCamColl, true);
gCamBody.AttachNode(gCamNode);
}
catch (Exception e)
{
Console.WriteLine("Newt Camera Creation Error: " + e.Message);
}



A static geometry object I want to collide with



Entity planet = gSceneMgr.CreateEntity(connReader.GetString(5), connReader.GetString(8));
planet.SetMaterialName(connReader.GetString(9));
int find_staticworldsection;
staticPlanet.AddEntity(planet, new Mogre.Vector3(connReader.GetInt32(11), connReader.GetInt32(12), connReader.GetInt32(13)),
new Mogre.Quaternion(1.0f, 0.0f, 0.0f, 0.0f),
new Mogre.Vector3(connReader.GetFloat(17), connReader.GetFloat(18), connReader.GetFloat(19)));

if (connReader.GetString(6) == "station")
{
MogreNewt.Collision gStationColl = new MogreNewt.CollisionPrimitives.TreeCollision(gWorld);
MogreNewt.Body gStationBody = new MogreNewt.Body(gWorld, gStationColl, true);
gStationBody.AttachNode(gCamNode);
}



and a large ship to collide with


Entity currEnt = gSceneMgr.CreateEntity(connReader.GetString(5), connReader.GetString(8));
gEntities[connReader.GetInt32(0)].eEntity = currEnt;
if (connReader.GetString(9).Length > 1)
gEntities[connReader.GetInt32(0)].eEntity.SetMaterialName(connReader.GetString(9));
SceneNode currNode = gSceneMgr.RootSceneNode.CreateChildSceneNode();
gEntities[connReader.GetInt32(0)].eNode = currNode;
gEntities[connReader.GetInt32(0)].eNode.Position = new Mogre.Vector3(connReader.GetInt32(11), connReader.GetInt32(12), connReader.GetInt32(13));
gEntities[connReader.GetInt32(0)].eNode.Scale(connReader.GetFloat(17), connReader.GetFloat(18), connReader.GetFloat(19));
gEntities[connReader.GetInt32(0)].eNode.AttachObject(gEntities[connReader.GetInt32(0)].eEntity);
gEntities[connReader.GetInt32(0)].eActive = true;
gEntities[connReader.GetInt32(0)].eX = connReader.GetInt32(11);
gEntities[connReader.GetInt32(0)].eY = connReader.GetInt32(12);
gEntities[connReader.GetInt32(0)].eZ = connReader.GetInt32(13);
gEntities[connReader.GetInt32(0)].eName = connReader.GetString(5);
gEntities[connReader.GetInt32(0)].eID = connReader.GetString(0);



// add physics to capitolShips
if (connReader.GetString(6) == "capitolship")
{
MogreNewt.Collision gCapColl = new MogreNewt.CollisionPrimitives.Box(gWorld, new Mogre.Vector3(100, 100, 100), 0);
MogreNewt.Body gCapBody = new MogreNewt.Body(gWorld, gCapColl, true);
gCapBody.AttachNode(gEntities[connReader.GetInt32(0)].eNode);
}



I made the collision objects big also to try to get them to work, at least a scale value of 100 seemed large to me. I can't help but feeling I don't have all the steps here. Am I missing something? My basic steps for Newton are:

1. Create physics world object
2. Create the collision object
3. create the body object
4. attach the body to a scene node

I am expecting this to work once implemented. I have no code to detection in the frame listener, since according to the Newton documentation I read, I don't need to since it relies on callbacks through the scene node attachment to the physics object. I appreciate any help you can give here. Also I will be tryin to next figure out how to use Newton to fly through space with proper drift, ie inertia . If you know where i can see an example of that, I would appreciate knowing that also.

Thanx,

Dan

ianhfar

14-07-2011 16:08:30

Dan,

1. Create physics world object
2. Create the collision object
3. create the body object
4. attach the body to a scene node
Without seeing all your code, some pointeres to confirm you have all the steps
5.SetPositionOrientation() on bodies as you move them
6.body.UpdateNode();
7.gWorld.CollisionUpdate();
8.gWorld.Update(m_update);
9.Define callback
class BodyContact : ContactCallback
{

public override int UserAABBOverlap(ContactMaterial material, Body body0, Body body1, int threadIndex)
{

return 1;
}

public override void UserProcess(ContactJoint contact, float timestep, int threadIndex)
{
}
}


10. register callBack
matPair = new MaterialPair(m_World, m_World.DefaultMaterialID, m_World.DefaultMaterialID);
// Callback instead of manual collision detection.
matPair.SetContactCallback(new BodyContact(this));

dannypb

14-07-2011 16:29:04

k, so I am missing some steps. I was thinking that newton auto handled position and orientation once you attach it to an object. I will add updating the newton body every frame. and call the world updates, then work on the callbacks.

Thanx, I'll repost when I fail :) or if I get it working :)