ISceneNode->GetTransformedBoundingBox()->GetExtent() ?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
qwertyCoder
Posts: 40
Joined: Wed May 07, 2008 4:37 pm
Location: Asheville, NC, USA

ISceneNode->GetTransformedBoundingBox()->GetExtent() ?

Post by qwertyCoder »

I'm trying to integrate Newton Game Dynamics into my project for obvious reasons. But the documentation is limited at best. So here is a quick questions for you guys.

I'm trying to use newton to create rigid bodies around my Meshed objects. For starters my terrain scene node I havent even started on but I know I cant use bounding boxes for it. Im thinking along the lines of a collision tree like the tutorials use for quake 3 maps. But thats a different issue. My primary concern is using Irrlicht to get the bounding box and then using that data to create my bounding box in newton. So I have the following:

Code: Select all

collision = NewtonCreateBox(m_nWorld,
						node->getTransformedBoundingBox().getExtent().X/2,
						node->getTransformedBoundingBox().getExtent().Y/2,
						node->getTransformedBoundingBox().getExtent().Z/2,
						m_ObjectList.size();,NULL);

My question here is what are the actual values returned by getExtent? are they the length, width, and height of the bounding box? or is it something else? Also when creating a newton box are the dimensions you pass in relative to the center of the box? ie. do I need the /2 or can i just pass in the extent params?

Also how does one go about creating a collision for just a camera scene node?
---------------------------------------

Code: Select all

int main()
{
	if (bCodeDoesntWork)
	{
		int res = AttemptFix(this);
		if (failed(res))
		{
			PullHair();
		}
	}
}
---------------------------------------
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: ISceneNode->GetTransformedBoundingBox()->GetExtent

Post by Acki »

qwertyCoder wrote:do I need the /2 or can i just pass in the extent params?
no, you can pass the extent params directly... ;)
but IIRC you'll also need to specify the center of the box and it's rotation:

Code: Select all

// get the center and rotation of the box
core::matrix4 centerMatrix;
centerMatrix.setTranslation(node->getBoundingBox().getCenter());
centerMatrix.setRotationDegrees(node->getRotation());

// get the size of the box
core::vector3df size = node->getTransformedBoundingBox().getExtent();

// create the rigid body
collision = NewtonCreateBox(nWorld, size.X, size.Y, size.Z, centerMatrix.pointer());
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
qwertyCoder
Posts: 40
Joined: Wed May 07, 2008 4:37 pm
Location: Asheville, NC, USA

Post by qwertyCoder »

What about creating a camera for collisions? How should I go about adding it to newton? Obviously I don't want a box. I'm looking for something similar to irrlicht's animators but newton documentation is not clear on applying gravity or checking for camera collisions, at least not as far as I have found.
Thanks again.
---------------------------------------

Code: Select all

int main()
{
	if (bCodeDoesntWork)
	{
		int res = AttemptFix(this);
		if (failed(res))
		{
			PullHair();
		}
	}
}
---------------------------------------
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

there is not a special collision for cameras though...
you handle it like any other scene node... ;)

I think best choice would either be a sphere (NewtonCreateSphere) or a capsule (NewtonCreateCapsule)... ;)

of course you want a constant up vector for the camera:

Code: Select all

f32 up[3] = {0,1,0};
NewtonConstraintCreateUpVector(nWorld, up, Body);
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
qwertyCoder
Posts: 40
Joined: Wed May 07, 2008 4:37 pm
Location: Asheville, NC, USA

Post by qwertyCoder »

awesome. Thanks for the help, but how do you setup gravity. Ive noticed a couple add force type functions but the comments on parameters and such are slim to none. Do I have to create a gravity force for each object or is there a global one somewhere?
---------------------------------------

Code: Select all

int main()
{
	if (bCodeDoesntWork)
	{
		int res = AttemptFix(this);
		if (failed(res))
		{
			PullHair();
		}
	}
}
---------------------------------------
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

well, there is not realy a gravity in Newton...
you'll apply it to each body as force in the PhysicsApplyForceAndTorque callback...
usually this way:

Code: Select all

void  PhysicsApplyForceAndTorque (const NewtonBody* body){
  dFloat Ixx;
  dFloat Iyy;
  dFloat Izz;
  dFloat mass;
  
  // get the mass of the body (mass = 0 >> static object)
  NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
  // calculate gravity force
  dVector force (0.0f, -mass * 9.8f, 0.0f);
  // apply force to the body
  NewtonBodySetForce (body, &force.m_x);
}
maybe you should have a look at the examples coming with Newton !?!?! ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
qwertyCoder
Posts: 40
Joined: Wed May 07, 2008 4:37 pm
Location: Asheville, NC, USA

Post by qwertyCoder »

Just a guess here but isn't m_x just the X value (using member notation) of force? If that is the case shouldn't I use the Y value because its the vertical force that I'm interested in?
---------------------------------------

Code: Select all

int main()
{
	if (bCodeDoesntWork)
	{
		int res = AttemptFix(this);
		if (failed(res))
		{
			PullHair();
		}
	}
}
---------------------------------------
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

qwertyCoder wrote:Just a guess here but isn't m_x just the X value (using member notation) of force? If that is the case shouldn't I use the Y value because its the vertical force that I'm interested in?
look again what you realy pass in there, maybe you get it then... :lol:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
qwertyCoder
Posts: 40
Joined: Wed May 07, 2008 4:37 pm
Location: Asheville, NC, USA

Post by qwertyCoder »

So if I wanted to stick with irrlicht's types I could use

Code: Select all

irr::f32 Ixx;
irr::f32 Iyy;
irr::f32 Izz;
irr::f32 mass;

NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
irr::core::vector3df force(0.0f, mass * -9.8f, 0.0f);
NewtonBodySetForce (body, &force);
?




-edit-
Ok I guess not, but I can
Last edited by qwertyCoder on Wed Jul 22, 2009 7:29 pm, edited 1 time in total.
---------------------------------------

Code: Select all

int main()
{
	if (bCodeDoesntWork)
	{
		int res = AttemptFix(this);
		if (failed(res))
		{
			PullHair();
		}
	}
}
---------------------------------------
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

qwertyCoder wrote:So if I wanted to stick with irrlicht's types I could use

Code: Select all

irr::f32 Ixx;
irr::f32 Iyy;
irr::f32 Izz;
irr::f32 mass;

NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
irr::core::vector3df force(0.0f, mass * -9.8f, 0.0f);
NewtonBodySetForce (body, &force);
?
I idn't try, but I guess it works, as long as you pass the right reference:

Code: Select all

NewtonBodySetForce (body, &force.X);
but this also can depend on the precision Newton was compiled with !!!
Best/savest is always to use the types the lib provides, so I would use dVector for Newton !!! ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
qwertyCoder
Posts: 40
Joined: Wed May 07, 2008 4:37 pm
Location: Asheville, NC, USA

Post by qwertyCoder »

compiler tells me that dVector is undefined....
---------------------------------------

Code: Select all

int main()
{
	if (bCodeDoesntWork)
	{
		int res = AttemptFix(this);
		if (failed(res))
		{
			PullHair();
		}
	}
}
---------------------------------------
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

a little bit self initiative would be nice :roll:

in the Newton SDK there should be a folder "toolBox" and there should be the dVector.h include file !!!

if you can't find it you also can test if it works with Irrlicht's vector3df (like mentioned before, but remember to pass a reference to X of the vector)...

or if all others fail you'll have to do it this way:

Code: Select all

core::vector3df newForce = (0, -10, 0); // previous declared
.
.
.
f32 f[3] = {newForce.X , newForce.Y, newForce.Z};
NewtonBodyAddForce(body, f);
or use the float array directly

Code: Select all

f32 f[3] = {0, -10, 0};
NewtonBodyAddForce(body, f);
this should work in either case... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
qwertyCoder
Posts: 40
Joined: Wed May 07, 2008 4:37 pm
Location: Asheville, NC, USA

Post by qwertyCoder »

Wow I was about to be really ill with you acki regarding the "self initiative". In the sdk folders there is no "toolbox" folder, however there is one in the samples\sdkDemos folder. Unfortunately there is no dVector.h in that folder, but I did find it in sdk\dMath. Trust me when I say I looked for it in the samples directory figuring that it would have to be included somewhere..... Anyway, Ill try it with the irrlicht types, that way, assuming it works, I dont have to convert parameters from irrlicht types to newton types and vice versa. *crosses fingers*
---------------------------------------

Code: Select all

int main()
{
	if (bCodeDoesntWork)
	{
		int res = AttemptFix(this);
		if (failed(res))
		{
			PullHair();
		}
	}
}
---------------------------------------
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

qwertyCoder wrote:In the sdk folders there is no "toolbox" folder, however there is one in the samples\sdkDemos folder. Unfortunately there is no dVector.h in that folder, but I did find it in sdk\dMath. Trust me when I say I looked for it in the samples directory figuring that it would have to be included somewhere.....
maybe the developers changed the place in newer versions as it's more suitable to place it in a math folder... ;)
but that's exactly what I meant with self initiative, do a search first, your OS has a pretty usefull search function...
also working through the Newton examples is a realy good start !!!
I learned using Newton by converting the examples to use Irrlicht instead of OpenGL... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
qwertyCoder
Posts: 40
Joined: Wed May 07, 2008 4:37 pm
Location: Asheville, NC, USA

Post by qwertyCoder »

Serious issue with the NewtonApplyForceAndTorque callback...
Ive tried compiling both the examples and my own source and get a similar error..


error C2664: 'NewtonBodySetForceAndTorqueCallback' : cannot convert parameter 2 from 'void (__cdecl *)(const NewtonBody *)' to 'NewtonApplyForceAndTorque'
None of the functions with this name in scope match the target type


The wiki docs state that the format for said function is as follows...

Code: Select all

void _cdecl callbackSimpleGravity(const NewtonBody* body)
{
	float force[3];
	float mass;
	float inertia[3];

	NewtonBodyGetMassMatrix( body, &mass, &inertia[0] );

	float force[0] = 0.0f;
	float force[1] = -9.8f * mass;
	float force[2] = 0.0f;

	NewtonBodyAddForce( body, &force[0] );
} 
while the example code for the sdk has this in the PhsyicsUtils.h and cpp

Code: Select all

//.h
void PhysicsApplyGravityForce (const NewtonBody* body, dFloat timestep, int threadIndex);


//.cpp
void  PhysicsApplyGravityForce (const NewtonBody* body, dFloat timestep, int threadIndex)
{
	dFloat Ixx;
	dFloat Iyy;
	dFloat Izz;
	dFloat mass;

	NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
	dVector force (0.0f, -mass * 10.0f, 0.0f);
	NewtonBodySetForce (body, &force.m_x);
}
So heres the issue, the examples dont follow the docs, or vice versa, neither code compiles and why would the examples use a different prototype than what the documentation states is required, including additional parameters?
---------------------------------------

Code: Select all

int main()
{
	if (bCodeDoesntWork)
	{
		int res = AttemptFix(this);
		if (failed(res))
		{
			PullHair();
		}
	}
}
---------------------------------------
Post Reply