Newton Engine

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums

Newton Engine

Postby omar shaaban » Sat Sep 12, 2009 4:32 am

i made a program with many sphere nodes in it,and, i wanted to use a physics engine because i noticed that the spheres where moving and passing each other.
so i used newton engine and set Collision bodies to the spheres
but before that if i wanted to move the spheres i would work with irrlicht directly
Code: Select all
node->setPostion(pos);

but now i have to work with newton and irrlicht updates from it
so my question is: How to move objects through newton?
User avatar
omar shaaban
 
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt

Postby Seven » Sat Sep 12, 2009 1:33 pm

How to move objects through newton?

i think the preferred method is to allow the physics engine to update all of it's objects, then update the irrlicht nodes to match.

Level::Frame()
{
updatePhyscisEngine();
updateAllObjects();
Render();
}

myObject::Frame()
{
m_Node->setPosition(physicsObject->getPosition());
m_Node->setRotation(physicsObject->getRotation());
}

there are some good examples using physics engines in the links
Seven
 
Posts: 599
Joined: Mon Nov 14, 2005 2:03 pm

Postby omar shaaban » Sat Sep 12, 2009 6:30 pm

no no, thats updating postions....i mean when like u press w and the sphere moves
so what shall i move do i move the irrlicht scene node or newton body !!?
and i know its newton body then what is the code to move it???
User avatar
omar shaaban
 
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt

Postby Seven » Sat Sep 12, 2009 7:24 pm

omar shaaban wrote:no no, thats updating postions....i mean when like u press w and the sphere moves
so what shall i move do i move the irrlicht scene node or newton body !!?
and i know its newton body then what is the code to move it???



have you looked at IrrNewt? it will give you a good example of doing what you are asking.
Seven
 
Posts: 599
Joined: Mon Nov 14, 2005 2:03 pm

Postby omar shaaban » Sat Sep 12, 2009 10:09 pm

i will have a look ,so doing it by newton aone is hard or needs alot of functions?
User avatar
omar shaaban
 
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt

Postby Seven » Sat Sep 12, 2009 10:56 pm

IrrNewt is a good library that youc an integrate very easily into your game design. Give it a try and see what you think. if you have any questions with it, we can help out.
Seven
 
Posts: 599
Joined: Mon Nov 14, 2005 2:03 pm

Postby Dorth » Sun Sep 13, 2009 3:28 am

Impulses are what you are looking for.
Dorth
 
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Postby omar shaaban » Sun Sep 13, 2009 3:37 am

Dorth wrote:Impulses are what you are looking for.

i understand..what i meant was who is controlling who...
irrlicht scene node or newton body node
anyway i am using or atleast trying irrnewt which cant compile!!
User avatar
omar shaaban
 
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt

Postby Seven » Sun Sep 13, 2009 4:02 am

omar shaaban wrote:
Dorth wrote:Impulses are what you are looking for.

i understand..what i meant was who is controlling who...
irrlicht scene node or newton body node
anyway i am using or atleast trying irrnewt which cant compile!!


newton controls irrlicht in this situation.
Seven
 
Posts: 599
Joined: Mon Nov 14, 2005 2:03 pm

Postby Seven » Sun Sep 13, 2009 5:26 am

this is how i do it...., but remember that IrrNewt already has access to the Irrlicht node and moves it when I access m_NewtonBody->SetPosition(vec); if you are not using IrrNewt, then you just need to move the Irrlicht node yourself.

Code: Select all
void CSObject::Frame()
{
   if (m_NewtonBody)
   {
    SetPosition(m_NewtonBody->getPosition());
   SetRotation(m_NewtonBody->getRotationBody());
   }
}




Code: Select all
void CSObject::SetPosition(vector3df pos)
{
   m_Position = pos;
   if (m_NewtonBody)
   {
      m_NewtonBody->setPosition(pos);
   }
   else
   {
      if (m_Node) m_Node->setPosition(pos);
      if (m_AnimatedSceneNode) m_AnimatedSceneNode->setPosition(pos);
   }
}

void CSObject::SetRotation(vector3df rot)
{
   if(rot.X > 360) rot.X = rot.X-360;
   if(rot.X < 0) rot.X = 360+rot.X;
   if(rot.Y > 360) rot.Y = rot.Y-360;
   if(rot.Y < 0) rot.Y = 360+rot.Y;
   if(rot.Z > 360) rot.Z = rot.Z-360;
   if(rot.Z < 0) rot.Z = 360+rot.Z;

   m_Rotation = rot;

   if (m_NewtonBody) m_NewtonBody->setRotation(rot);
   else
   {
      if (m_Node) m_Node->setRotation(rot);
      if (m_AnimatedSceneNode) m_AnimatedSceneNode->setRotation(rot);
   }
}
Seven
 
Posts: 599
Joined: Mon Nov 14, 2005 2:03 pm


Return to Game Programming

Who is online

Users browsing this forum: No registered users and 1 guest