A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by PJani » Wed Jul 25, 2012 10:31 am
Yep tried using SetScaleLocal and "normal" SetScale same result...i will try to do something else
The problem is because it colides at thows debug lines! And center of mass is shifted towards bigger sub collision.
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
-

PJani
-
- Posts: 448
- Joined: Mon Feb 02, 2009 7:18 pm
- Location: Slovenia
by Julio Jerez » Wed Jul 25, 2012 10:35 am
I adapted the no uniform scale demo to use local scale, I can see there is somethopng wrong still. It looks like the center of mass is not in the right place. I'll check it out
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Wed Jul 25, 2012 10:44 am
yes they is a big bug, the funtion that calculat eteh inertia asumes specifc matrxi order an dstill use the vector form of the matrix,
dgMatrix dgCollisionConvex::CalculateInertiaAndCenterOfMass (const dgMatrix& matrix, const dgVector& scale) const
I need to fix that, but that is not so eassy,
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Wed Jul 25, 2012 11:01 am
Oh, no ther eis no bug in teh engine the bug is in the demo, thsi function
NewtonCollision* CreateConvexCollision (NewtonWorld* world, const dMatrix& srcMatrix, const dVector& originalSize, PrimitiveType type, int materialID__)
was no settin teh offset matrix in teh shape, so teh cog was alwya at the origin. That fix teh COG bug, I still do no t knwo if i fteh local scale is correct, I think it is not.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Wed Jul 25, 2012 11:05 am
yes inerta matrix is calculet incorretly when the scale is local, it is thsi funtion here
- Code: Select all
void dgCollisionInstance::CalculateInertia (dgVector& inertia, dgVector& origin) const
{
if (IsType(dgCollision::dgCollisionMesh_RTTI)) {
inertia = dgVector (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));
origin = dgVector (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));
} else {
dgMatrix fullInertia (m_childShape->CalculateInertiaAndCenterOfMass (m_localMatrix, m_scale));
// for now use the principal inertia, soon there will be another function to support full inertia matrix
inertia = dgVector (fullInertia[0][0], fullInertia[1][1], fullInertia[2][2], dgFloat32 (0.0f));
origin = fullInertia.m_posit;
}
}
functinatlly it is eassy to fix, all I need to do is add another conditional to check if teh scale is local, and is so then call teh same fintion but with the match similar tranformation matrix. stand by I will fix it.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Wed Jul 25, 2012 11:14 am
Ok it is all fixed now, it should be correct now
this is teh funtion that make the correction.
- Code: Select all
void dgCollisionInstance::CalculateInertia (dgVector& inertia, dgVector& origin) const
{
if (IsType(dgCollision::dgCollisionMesh_RTTI)) {
inertia = dgVector (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));
origin = dgVector (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));
} else if (m_scaleIsLocal){
dgMatrix similarMatrix (m_scaleMatrix * m_localMatrix * m_invScaleMatrix);
dgMatrix fullInertia (m_childShape->CalculateInertiaAndCenterOfMass (similarMatrix, m_scale));
inertia = dgVector (fullInertia[0][0], fullInertia[1][1], fullInertia[2][2], dgFloat32 (0.0f));
origin = fullInertia.m_posit;
} else {
dgMatrix fullInertia (m_childShape->CalculateInertiaAndCenterOfMass (m_localMatrix, m_scale));
// for now use the principal inertia, soon there will be another function to support full inertia matrix
inertia = dgVector (fullInertia[0][0], fullInertia[1][1], fullInertia[2][2], dgFloat32 (0.0f));
origin = fullInertia.m_posit;
}
}
I tested with the same box offset by one unit alone y an dteh COM is perfect in all cases (local, or global scale)
see if it works for you now.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by PJani » Wed Jul 25, 2012 11:24 am
I will check it right out just give me 10min...because i have some weird stuff going on with my code
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
-

PJani
-
- Posts: 448
- Joined: Mon Feb 02, 2009 7:18 pm
- Location: Slovenia
by Julio Jerez » Wed Jul 25, 2012 11:37 am
Ok I check in the demo with an assortment of non uniform local scaled shapes.
I should work, with no scale mesh collision.
Scale mesh collision will fail because scale mesh collision
makes the assumption that the scale matrix is diagonal, and no a genera PSD.
This will generate very bad collision contact, but this is not trivial to fix now, I will do that Saturday.
every else should work find.
I think that what I will do is to re factor the complete Instance class and make so that the scale is local by default
instead for the General form for the collision matrix be
W = L * S * M
be
W = S * L * M
where M = the Body Matrix
S is the scale matrix
L is the local matrix
the first mode which is what is use now is the correct way algebraically, but decades people make graphics engine using bad linear algebra has made almost impossible to provide a library that does the correct linear algebra.
I can no change that so it is better to use the second mode and take advantage op the special case that come from it.
If I leave like that and people use local; scale then the code will follow the General case which is always more expensive. Of cores I can always implement it using the general PDS matrix
inv (M) * S * M
and it will be only one pathway that will always works, this is what core 200 use for the transform modifiers, but this add about three time as many matrix multiplication as there are need it when you know that the scale is diagonal.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Wed Jul 25, 2012 11:52 am
The secund benefix we get from apply local scale i sthat we do no nee to save the scale as a full matrix an dthe inv scale as a full matrix, if we ste a rulle that all scales are local.
then the applucation can deal with global scale form the high level by apply the scale and scaling the local offset poistion of the matrix, for soers in some case this will not work when usin no unifom scale bu thsi sare vert rare cases.
I will start make the change to use, and use only. The code sodul be simples an dteh instace will take a lot less memory, twovecors instead of two matrices for scale
W = S * L * M
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by PJani » Wed Jul 25, 2012 12:19 pm
Finaly it works

And it gives correct com with sqrt...dFloat scale = sqrt(mass * invRefMass);
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
-

PJani
-
- Posts: 448
- Joined: Mon Feb 02, 2009 7:18 pm
- Location: Slovenia
by Julio Jerez » Wed Jul 25, 2012 12:31 pm
I do not undertand why you keep postiong teh sqrt (sqrt(mass * invRefMass);
where are you getting that from?
also remember I will change the scale to be only local.
the change should be very minor form your side. but it is important because using the local scale force the engine to do serius more expensive calculation ove the entire collison system
because it uses the general form of scaling.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by PJani » Wed Jul 25, 2012 2:04 pm
Hmm good question...i don't know why but it seems the com is more true when i use sqrt.
I don't know i maybe i am just confused...
What if you could precalculate global matrix for scaling

| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
-

PJani
-
- Posts: 448
- Joined: Mon Feb 02, 2009 7:18 pm
- Location: Slovenia
by PJani » Wed Jul 25, 2012 9:51 pm
I figured out it is not sqrt but a cubic root...if i scale whole volume(density / refDensity) then i need to know much their sides changed so side_scale^3 = density / refDensity ==> side_scale = pow(density / refDensity, 1/3.0);
This local scaling doesn't work right i get center of mass at wrong location. When scaling locally sub collisions are moved. I don't know why.(they are not scaled from their geometric center).
Now the real question is it even possible to calculate inertia and center of mass without scaling each sub collision?
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
-

PJani
-
- Posts: 448
- Joined: Mon Feb 02, 2009 7:18 pm
- Location: Slovenia
by Julio Jerez » Thu Jul 26, 2012 9:36 am
give me a day or two until I change the scale to be local only, that will clear many issues.
regard to the inetia of a body with different density using the scale of sub shapes, in my opnion using the scale it is the fastest, eassiest and most elegant way because it build on top of building blocks that we have and we know are correct.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by PJani » Thu Jul 26, 2012 10:03 am
Ok i will continue with user mesh collision meanwhile
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
-

PJani
-
- Posts: 448
- Joined: Mon Feb 02, 2009 7:18 pm
- Location: Slovenia
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 0 guests