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.