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
Post Reply
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Newton Engine

Post by omar shaaban »

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?
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

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
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

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???
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

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.
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

i will have a look ,so doing it by newton aone is hard or needs alot of functions?
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

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.
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

Impulses are what you are looking for.
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

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!!
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

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: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

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);
	}
}
Post Reply