Rotating Newton Body

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Rotating Newton Body

Postby Cyrus » Wed Jul 07, 2010 5:29 am

Hi,
I have a problem with the Newton body rotation. Whenever I rotate my Newton body, it is always rotated on the origin of the model (centre of mass of the obj file), whenever I change the centre of mass of the Newton body still it rotates on the origin of the model.
How to make my object to rotate on its centre??? (Now it is revolving but I need it to rotate)
I am using Newton 2.0

Code: Select all
vOr.FromAngleAxis(radian, new Vector3(0, 0, 1)); // vOr is Quaternion
bod[iSelect].SetPositionOrientation(vPos, vOr); // bod[iSelect] is MogreNewt.Body, vPos is Vector3


Thanks in advance.

Regards
Cyrus
Cyrus
 
Posts: 49
Joined: Mon May 17, 2010 1:04 am

Re: Rotating Newton Body

Postby Julio Jerez » Wed Jul 07, 2010 7:36 am

I do not undestand the question.
by the laws of phyisic a body rotate around it center of mass, an dI believe that's how Netwon works now.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Rotating Newton Body

Postby JernejL » Wed Jul 07, 2010 9:09 am

Centre of mass / mass matrix is not same as offset matrix (!)

a body origin is at it's offset matrix, mass matrix is a characteristic of simulating dynamics.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Rotating Newton Body

Postby Cyrus » Wed Jul 07, 2010 11:05 am

Thanks for the quick reply.
by the laws of phyisic a body rotate around it center of mass, an dI believe that's how Netwon works now.

In my case, eventhough I set the centre of mass of the body as

Code: Select all
1. bod.CenterOfMass = new Vector3(200f, 0f, 200f);
2. bod.CenterOfMass = new Vector3(0f, 0f, 0f);
3. bod.CenterOfMass = new Vector3(-100f, 0f, -100f);..................
..........

but still the body is rotating on its left-rear edge (it's a kind of revolution)!!!

So how can I set the CentreOfMass for the body, so that body can rotate on its centre (like a Fan/wheel of a car is rotating on its centre)?

Regards
Cyrus
Cyrus
 
Posts: 49
Joined: Mon May 17, 2010 1:04 am

Re: Rotating Newton Body

Postby Julio Jerez » Wed Jul 07, 2010 11:23 am

I do not know, you must have a bug some where in teh code that set the com.
there are a functions in Newton to set the center of mass of a NetwonBody.
void NewtonBodySetCentreOfMass (const NewtonBody* body, const dFloat* com);
void NewtonBodyGetCentreOfMass (const NewtonBody* body, dFloat* com);
try reading it afte you set it and see if it is doing what you want.

if you take a sphere for example and you set center to the lower bottom the it will rotate arond the center like a punch toy.
if you have a Box with the center at the lower bottom, and you set the center to the middle of the Box, then it will spin around the midle.
this is good for engines where abatars have the pivot at the bottom, if that is what you look for.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Rotating Newton Body

Postby Cyrus » Thu Jul 08, 2010 9:09 am

After using void NewtonBodySetCentreOfMass (const NewtonBody* body, const dFloat* com); also we have same issue :( .
Centre of mass / mass matrix is not same as offset matrix (!)
a body origin is at it's offset matrix, mass matrix is a characteristic of simulating dynamics.

Our body is made up of compound collision (which is created using list of convexhulls), now I have offset matrix for each convexhull (there are 10 convex hulls and now I got 10 offest matrix). So now How can I make use of list of offset matrices (what should I do to make the object to rotate on its centre)?
Cyrus
 
Posts: 49
Joined: Mon May 17, 2010 1:04 am

Re: Rotating Newton Body

Postby Julio Jerez » Thu Jul 08, 2010 12:19 pm

use this: void NewtonBodySetCentreOfMass (const NewtonBody* body, const dFloat* com);

it works, collision offset matrix have nothing to do wit teh body center of mass.
I doubt vert muc tha after 7 years they is a bug inteh cent of mass, all of teh demos in teh SDK use that funtion to offset the centr of mass and they all work as they should.,

just call NewtonBodySetCentreOfMass with com set to the local center of the object, and teh body will rotate around that center.
COM is the pivot use by newton so it must work otherwise nothing else would.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Rotating Newton Body

Postby rvangaal » Wed Dec 08, 2010 3:14 pm

Funnily I have the same problem; I had to move all my 3D models and related things (a car) to get the car to rotate around the CG.

Perhaps the confusion is that I retrieve the body position from Newton, and use that as the 'position' of the car. Does the car position move with the center of mass perhaps? I'd assume if centerOfMass!=0, that the position is offset relative to it. Hm.
Must be some confusion somewhere, perhaps in fetching the body matrix and retrieving position from that matrix.
rvangaal
 
Posts: 61
Joined: Mon Jun 08, 2009 1:11 pm

Re: Rotating Newton Body

Postby Julio Jerez » Wed Dec 08, 2010 4:16 pm

rvangaal wrote:Funnily I have the same problem; I had to move all my 3D models and related things (a car) to get the car to rotate around the CG.

I so much regret you have to do that unsesseary operartion.
That was presicelly why the center of Mass in the newton API is presented, so that people do not have to do that kind of abomination :( .

I think there is a confusion between center of mass and the center of the model. I will explain with an example.
If anyone remember during the 90's and still some game today place the center of a mesh at the lower bottom so that object placemen is easier.
with Physics engine becoming a common place, the center of mass is more important that the center of the model. and they do not have to be the same.
The very first versions of Physics engines, (like the Open source that are floating around) made the end user modify the mesh so that the center of teh mopdel is at the center of mass.
It was not until Newton came along that the concept of Center of mass became a standard API feature of a physics engine,
but for people who started with some these legacy engine they are still some confusion, specially when they set the center of mass at a position different than the center of the mesh.
The problem is very simple to resolve.
basically if you want to rotate the body relative to the centre of mass, so that the rotation match the rotation generated by the the physics.
all you need to do is a apply similar transformation.
A similar transform is matrix that produces the same invariant transformation indepepend of the space, you can look it up in Google.
basically it tis he process of transforming the object to its local space, applying the matrix and transfoming it back to its own space.
The process is like this:
say the body matrix is M, and it center of mass is T (in matrix from T is a identity matrix translate to the vector T)
the operation that place the body in the world is:

W = T * M

where:
W is the final world matrix
T is the center of mass matrix,
M is the body matrix

if we want to rotate the body by a rotation matrix R around its center mass.
we most write the expression

W1 = T * M *[ inv (T * M) * R * (T * M)]
W1 = T * M *[inv ( M) * inv (T) * R * (T * M)]
W1 = T * M * inv ( M) * inv (T) * [ R * (T * M)]
W1 = R * T * M

so it comes to make the a new matrix w = R * T * M

Code: Select all
-RotaBodyAournCenteOfMass (body, rotation)
{
              Vector T = NewtonBodyGetCenterOfMass(body)
             matrix M = NewtonBodyGetMatrix(body)
             M.Translation = M.TranformVcetor (T)
            M = Rotation  * M
           NewtonSetMatrix (body, M);
}


and that should do it.
Notice that when Center of mass vector T is a zero vector, then matrix R * T * M
becomes the usual pre-rotation R * M operation many people are familiar with.

I hope this is clear.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron