qi-an
04-07-2008 10:36:03
I' m new for OgreNewt ,I want to implement picking and dragging object in physics world .
In my code,I create a floor and a box ,when I run it,evrything looks well,the box fall in the floor.But when I picking and dragging the box ,the collision detected loods as if it lose its effectiveness!
These are my code snippets:
what's wrong with me ?
I need any help and appreciate !
(I'am so sorry about my poor English!)
Thanks,again!
In my code,I create a floor and a box ,when I run it,evrything looks well,the box fall in the floor.But when I picking and dragging the box ,the collision detected loods as if it lose its effectiveness!
These are my code snippets:
public void CreateInputHandler()
{
mRoot.FrameStarted += new FrameListener.FrameStartedHandler(Newton_FrameStarted);
this.MouseDown += new MouseEventHandler(OgreForm_MouseDown);
this.MouseUp += new MouseEventHandler(OgreForm_MouseUp);
this.MouseMove += new MouseEventHandler(OgreForm_MouseMove);
}
void OgreForm_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mRaySceneQuery = mgr.CreateRayQuery(MouseRay);
mRaySceneQuery.SetSortByDistance(true);
RaySceneQueryResult mresult = mRaySceneQuery.Execute();
foreach ( RaySceneQueryResultEntry result in mresult)
{
mCurrentNode = result.movable.ParentSceneNode;
mCurrentNode .ShowBoundingBox = true ;
mRotating = true;
break;
}
}
}
bool Newton_FrameStarted(FrameEvent evt)
{
m_elapsed += evt.timeSinceLastFrame*3;
if ((m_elapsed > m_update) && (m_elapsed < (1.0f)))
{
while (m_elapsed > m_update)
{
myworld.Update(m_update);
m_elapsed -= m_update;
}
}
else
{
if (m_elapsed < (m_update))
{
// not enough time has passed this loop, so ignore for now.
}
else
{
myworld.Update(m_elapsed);
m_elapsed = 0.0f; // reset the elapsed time so we don't become "eternally behind".
}
}
return true;
}
public void SceneCreator()
{
// Create a Simple Scene
mgr = mRoot.CreateSceneManager(SceneType.ST_GENERIC);
cam = mgr.CreateCamera("Camera");
cam.SetPosition(60, 60, 60);
cam.LookAt(new Vector3(0, 0, 0));
cam.AutoAspectRatio = true;
cam.NearClipDistance = 5;
mviewport = mWindow.AddViewport(cam);
mviewport.BackgroundColour = new ColourValue(0.7f, 0.7f, 0.7f);
myworld.SetWorldSize(new Vector3 ( -1000, -1000, -1000),new Vector3 (1000,1000,1000));
MogreNewt.Debugger.Instance.Init(mgr);
Vector3 inertia = MomentOfInertia.CalcBoxSolid(100, new Vector3(100, 100, 100));
Vector3 size = new Vector3(20, 2, 20);
Entity floor = mgr.CreateEntity("floor", "Box.mesh");
SceneNode node1 = mgr.RootSceneNode.CreateChildSceneNode();
node1.AttachObject(floor);
floor.NormaliseNormals = true;
node1.Scale(size);
Collision col = new MogreNewt.CollisionPrimitives.TreeCollision (myworld,floor,true );
Body bod = new Body(myworld, col);
col.Dispose();
bod.AttachToNode(node1);
bod.SetMassMatrix(100, inertia);
bod.SetPositionOrientation(new Vector3(0, -30, 0), Quaternion.IDENTITY);
Entity ent2 = mgr.CreateEntity("ninja2", "box01.mesh");
SceneNode node2 = mgr.RootSceneNode.CreateChildSceneNode();
node2.AttachObject(ent2);
node2.Scale(0.1f, 0.1f, 0.1f);
Collision col1 = new MogreNewt .CollisionPrimitives .Box (myworld, new Vector3 (10,10,10) );
Body bod2 = new Body(myworld, col1);
Vector3 force = new Vector3(0, -980, 0);
bod2.AttachToNode(node2);
bod2.SetMassMatrix(100, inertia);
bod2.IsGravityEnabled = true;
bod2.SetPositionOrientation(new Vector3(0, 30, 0), Quaternion.IDENTITY);
bod2.Force = force;
}
what's wrong with me ?
I need any help and appreciate !
(I'am so sorry about my poor English!)
Thanks,again!