mean possition of Objects

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
olbr
Kobold
Posts: 30
Joined: Sat Mar 08, 2014 12:47 am

mean possition of Objects

Post by olbr »

Hello

I need to calculate kind of a center of the mass for the all objects on a scene.
I am just adding up there Vector3 positions and then dividing resulting vector on the total number of objects.

Am I doing correct ?


thanks
User avatar
tod
Troll
Posts: 1394
Joined: Wed Aug 02, 2006 9:41 am
Location: Bucharest
x 94
Contact:

Re: mean possition of Objects

Post by tod »

No.
You could use AABB's volume to do some rough estimate of mass for an object, but then the positions will really mater also. It will probably be easier to specify the "center of mass" directly in your editor.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: mean possition of Objects

Post by Kojack »

For example, think of meshes like the ogre ninja and robot. Their position is at their feet. So averaging wouldn't be a centre of mass. But as Tod said using the centre of their AABB instead of their position would be closer.
olbr
Kobold
Posts: 30
Joined: Sat Mar 08, 2014 12:47 am

Re: mean possition of Objects

Post by olbr »

Kojack wrote:For example, think of meshes like the ogre ninja and robot. Their position is at their feet. So averaging wouldn't be a centre of mass. But as Tod said using the centre of their AABB instead of their position would be closer.
Thanks

Well all my meshes (that I want a center of the position for) are actually round balls and their center is exactly their position, is averaging like I described above giving correct results ?


Best
citronaut
Gnoblar
Posts: 5
Joined: Tue Mar 18, 2014 10:09 pm
x 1

Re: mean possition of Objects

Post by citronaut »

Assuming all the sphere's have the same mass/size/density, it's reasonably correct. Since you say "kind of center of mass" I can only assume this isn't meant to be an exact physics simulation. If the objects have different size/mass you could at least also weight each vector in the sum by it's corresponding object's mass and then divide the resultant sum by the total mass of all of them.
olbr
Kobold
Posts: 30
Joined: Sat Mar 08, 2014 12:47 am

Re: mean possition of Objects

Post by olbr »

citronaut wrote:Assuming all the sphere's have the same mass/size/density, it's reasonably correct. Since you say "kind of center of mass" I can only assume this isn't meant to be an exact physics simulation. If the objects have different size/mass you could at least also weight each vector in the sum by it's corresponding object's mass and then divide the resultant sum by the total mass of all of them.

Hi

Thanks for the response, Well actually it should be exact physics simulations. I posted this questing on a forum as a separate topic, may be you can help me to cast light on it, thanks.


I am a bit confused with calculation center of AABB box. All my nodes are round balls of the same size. For the comparison I am calculating and outputting centers of AABB for the same nodes and there Derived positions like following:


// Steady object
Ogre::AxisAlignedBox box1 = node2->_getWorldAABB();
Ogre::Vector3 MyBox1 = box1.getCenter();
results<<"BoxCenter:"<< MyBox1 << endl;
Ogre::Vector3 Possition1 = node2R->_getDerivedPosition();
results<<"Possition:"<< Possition1 << endl;

// moving object
Ogre::AxisAlignedBox box = node1->_getWorldAABB();
MyBox = box.getCenter();
results<<"BoxCenter:"<< MyBox << endl;
Ogre::Vector3 Possition = node1->_getDerivedPosition();
results<<"Possition:"<< Possition << endl;


For the node that is not moving AABB center and its Position is constantly the same, but for the node that is moving AABB center and derived position are interchanging the values. Below is output file:

// First Frame
BoxCenter:Vector3(-0.18, -0.34, 0.3)
Possition:Vector3(-0.18, -0.34, 0.3)
BoxCenter:Vector3(-4.88006, 9.68, 2.3599)
Possition:Vector3(-4.88017, 9.68001, 2.3597)

// Second Frame
BoxCenter:Vector3(-0.18, -0.34, 0.3)
Possition:Vector3(-0.18, -0.34, 0.3)
BoxCenter:Vector3(-4.88017, 9.68001, 2.3597)
Possition:Vector3(-4.88033, 9.68003, 2.3594)

// Third Frame
BoxCenter:Vector3(-0.18, -0.34, 0.3)
Possition:Vector3(-0.18, -0.34, 0.3)
BoxCenter:Vector3(-4.88033, 9.68003, 2.3594)
Possition:Vector3(-4.88056, 9.68004, 2.35901)


That is happening for any kind of moves that I am performing on any scene object. Why is it happening like that ?


Thanks
Post Reply