A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Julio Jerez » Sat Oct 29, 2011 7:17 pm
I am sorry, I mislead you. I was wrong the edge information does not depend on the optimization option, it is always present.
Let use do this, in file c:\\newton-dynamics-200\coreLibrary_200\source\physics\dgCollisionMesh.cpp find this function
- Code: Select all
dgInt32 dgCollisionMesh::dgCollisionConvexPolygon::ClipContacts (dgInt32 count, dgContactPoint* const contactOut, const dgMatrix& globalMatrix) const
{
dgVector normal (globalMatrix.RotateVector(m_normal));
if (m_normalIndex) {
add this hack
- Code: Select all
dgInt32 dgCollisionMesh::dgCollisionConvexPolygon::ClipContacts (dgInt32 count, dgContactPoint* const contactOut, const dgMatrix& globalMatrix) const
{
dgVector normal (globalMatrix.RotateVector(m_normal));
if (0) {
the will prevent the test to see if an edge normal in within a voronoi convex edge. I suspect the bug is there.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by pHySiQuE » Sat Oct 29, 2011 7:23 pm
Thanks I will try that tomorrow or maybe this evening later...
-
pHySiQuE
-
- Posts: 608
- Joined: Fri Sep 02, 2011 9:54 pm
by Julio Jerez » Sat Oct 29, 2011 7:25 pm
Ha Ok I found it, my mistake sorry.
In the fix I removed the check that test of the Normal is an edge normal, so now it is considering all collision as edge normals and producing bad result.
I have to put that check back.
stand by again.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Sun Oct 30, 2011 3:04 pm
Ok try again, sync to SVN and see hwo it works now.
There were some significant chnage I have to make, but I think it is much better now.
I added a new algorith to deternine edge collision, nwo it does it by matchin the edge id, at cliiping time, rather that before that was doing it by measuring the closest distance form the contact point to the edge.
The secund methot could declare edge collision on non edge and produce very bad result, I belever this method is much superior and produce more plausible physics behavior.
it passed all my test,
please let me know if it is better for you.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by pHySiQuE » Sun Oct 30, 2011 3:48 pm
I'm afraid revision 1017 has made it worse, and collision doesn't seem to work at all. I compiled the same code with the older version of Newton and the latest.
Most of the time when you pick something, the sphere will be placed at the camera's position. Click on an object, then let go of the mouse, move backwards, and there sphere will usually be placed where the camera was.
(You can ignore the block that is way off below the scene, that has some other issues.)
Last edited by
pHySiQuE on Mon Dec 05, 2011 4:56 am, edited 1 time in total.
-
pHySiQuE
-
- Posts: 608
- Joined: Fri Sep 02, 2011 9:54 pm
by Julio Jerez » Sun Oct 30, 2011 4:19 pm
can you make ther likned to the Newton DLL please? and not the the static library?
This was a big change and there migh be other place that need fixin still, but I can not see wher with a exe file
building the DLL is very simple, it should just compile out of the Box.
Most of the time when you pick something, the sphere will be placed at the camera's position.
Click on an object, then let go of the mouse, move backwards, and there sphere will usually be placed where the camera was.
for what you say it is the collision is working but it is retirning the wrong parameter.
if you can make the change it will be very good.
if you can not then maybe you can post the code you are using for the placement so that I can added to a SDK demo.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by pHySiQuE » Mon Oct 31, 2011 12:32 am
Okay, I got it set up to work with the DLL here.
Last edited by
pHySiQuE on Mon Dec 05, 2011 4:56 am, edited 1 time in total.
-
pHySiQuE
-
- Posts: 608
- Joined: Fri Sep 02, 2011 9:54 pm
by Julio Jerez » Mon Oct 31, 2011 9:15 am
Oh very good, thank it is a big help
I thonk I found the it is the old quadrtic calculation of the time of impact again. Maybe I had it right teh first time,
anyway when I put back the old part o fteh cast the collision work again byt it misses the edge,
the new code alway repor the hit point wrong, so it seem it is teh time of impat that is wrong bu the code is right.
I will compare the tow and see what the but is.
But is any case these fixe made teh code more rubos and more stable, so I am glad I work of teh edge collision whi was overt do for a very long time.
the function is quetsion is this one here
- Code: Select all
dgFloat32 dgCollisionMesh::dgCollisionConvexPolygon::MovingPointToPolygonContact (const dgVector& p, const dgVector& veloc, dgFloat32 radius, dgContactPoint& contact)
{
m_localPoly[0] = dgVector (&m_vertex[m_index[0] * m_stride]);
m_localPoly[1] = dgVector (&m_vertex[m_index[1] * m_stride]);
m_localPoly[2] = dgVector (&m_vertex[m_index[2] * m_stride]);
CalculateNormal();
bool isEdge = true;
dgFloat32 timestep = dgFloat32 (-1.0f);
dgVector closestPoint (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));
dgFloat32 minDist = dgFloat32 (1.0e20f);
for (dgInt32 j = 2; j < m_count; j ++) {
bool tmpIsEdge;
m_localPoly[j] = dgVector (&m_vertex[m_index[j] * m_stride]);
const dgVector q (ClosestDistanceToTriangle (p, m_localPoly[0], m_localPoly[j - 1], m_localPoly[j], tmpIsEdge));
isEdge &= tmpIsEdge;
const dgVector error (q - p);
dgFloat32 dist = error % error;
if (dist < minDist) {
minDist = dist;
closestPoint = q;
}
}
if (minDist <= (radius * radius)) {
dgVector dp (p - closestPoint);
dgFloat32 dist2 = dp % dp;
if (dist2 > dgFloat32 (0.0f)) {
_ASSERTE (dist2 > dgFloat32 (0.0f));
dgFloat32 dist2Inv = dgRsqrt (dist2);
dgFloat32 side = dist2 * dist2Inv - radius;
if (side < (-DG_RESTING_CONTACT_PENETRATION)) {
dgVector normal (dp.Scale (dist2Inv));
side = (dgAbsf (side) - DG_IMPULSIVE_CONTACT_PENETRATION);
if (side < dgFloat32 (0.0f)) {
side = dgFloat32 (0.0f);
}
timestep = dgFloat32 (0.0f);
contact.m_point = p - normal.Scale (radius + side * dgFloat32 (0.5f));
contact.m_normal = normal;
contact.m_penetration = side;
contact.m_isEdgeContact = 0;
}
}
}
// this is the old function and it works but misses the edge
if (timestep < 0.0f) {
dgFloat32 projVeloc = veloc % m_normal;
if (projVeloc < dgFloat32 (-1.0e-1f)) {
dgVector supportPoint (p - m_normal.Scale (radius));
dgFloat32 timeToImpact = -(m_normal % (supportPoint - m_localPoly[0])) / (m_normal % veloc);
dgVector point (supportPoint + veloc.Scale (timeToImpact));
dgVector closestPoint (point);
dgFloat32 minDist = dgFloat32 (1.0e20f);
for (int i = 2; i < m_count; i ++) {
bool tmpIsEdge;
const dgVector q (ClosestDistanceToTriangle (point, m_localPoly[0], m_localPoly[i - 1], m_localPoly[i], tmpIsEdge));
const dgVector error (q - point);
dgFloat32 dist = error % error;
if (dist < minDist) {
minDist = dist;
closestPoint = q;
}
}
if (minDist < dgFloat32 (1.0e-3f) ) {
timestep = GetMax (timeToImpact, dgFloat32 (0.0f));
contact.m_normal = m_normal;
contact.m_penetration = dgFloat32 (0.0f);
contact.m_point = (closestPoint + supportPoint).Scale (dgFloat32 (0.5f));
} else {
dgVector dp (closestPoint - p);
dgFloat32 a = veloc % veloc;
dgFloat32 b = - dgFloat32 (2.0f) * (dp % veloc);
dgFloat32 c = dp % dp - radius * radius;
dgFloat32 desc = b * b - dgFloat32 (4.0f) * a * c;
if (desc >= dgFloat32 (0.0f)) {
desc = dgSqrt (desc);
dgFloat32 t = dgFloat32 (0.5f) * GetMin ((b + desc), (b - desc)) / a;
if (t >= 0.0f) {
timestep = t;
_ASSERTE (timestep > dgFloat32 (0.0f));
contact.m_penetration = dgFloat32 (0.0f);
contact.m_point = closestPoint + veloc.Scale (timestep * dgFloat32 (0.5f));
contact.m_normal = dp.Scale (dgRsqrt (dp % dp));
}
}
}
}
}
return timestep;
/*
// this is the fix but some how it is still wrong function and it works but misses the edge, I have to find out why
if (timestep < 0.0f) {
dgFloat32 projVeloc = veloc % m_normal;
if (projVeloc < dgFloat32 (-1.0e-1f)) {
dgVector supportPoint (p - m_normal.Scale (radius));
dgFloat32 timeToImpact = -(m_normal % (supportPoint - m_localPoly[0])) / (m_normal % veloc);
_ASSERTE ((veloc % veloc) > 0.0f);
timestep = GetMax (timeToImpact, dgFloat32 (0.0f));
if (!isEdge) {
contact.m_normal = m_normal;
contact.m_penetration = dgFloat32 (0.0f);
contact.m_point = (closestPoint + supportPoint).Scale (dgFloat32 (0.5f));
contact.m_isEdgeContact = 0;
} else {
_ASSERTE (timestep < 1.0f);
dgVector dp (closestPoint - p);
contact.m_penetration = dgFloat32 (0.0f);
contact.m_point = (closestPoint + p + veloc.Scale (timestep)).Scale (dgFloat32 (0.5f));
contact.m_normal = dp.Scale (-dgRsqrt (dp % dp));
contact.m_isEdgeContact = ((contact.m_normal % m_normal) < dgFloat32 (0.9998f)) ? 1 : 0;
}
}
}
return timestep;
*/
}
standby I am working on the fix.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Mon Oct 31, 2011 3:18 pm
Alright I believe I fixed now.
Please sync again and see if it ok.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by pHySiQuE » Mon Oct 31, 2011 6:18 pm
Thanks, it's working much better now, but you can still get errors when the sphere goes over an edge where two coplanar triangles meet on a face. The time of impact will place the sphere somewhere around the camera position, instead of the collided position. This doesn't seem to happen when I use the "optimize" setting in NewtonTreeBuildEnd().

- Image2.jpg (60.07 KiB) Viewed 4426 times
Also, some angles cause it to miss corner collisions. You've just got to hold the mouse down and roll the sphere along edges and corners, and you will find the problems:

- Image3.jpg (45.44 KiB) Viewed 4423 times
-
pHySiQuE
-
- Posts: 608
- Joined: Fri Sep 02, 2011 9:54 pm
by Julio Jerez » Mon Oct 31, 2011 7:50 pm
I am very confused with thsi one because if I point to an edge and I click until teh ball dos no dispplay, then I move the mouse slighlly.
teh T paramater, teh normal and teh contact point are almost identical.
I cna no see how the ball can display in teh wrong location.
I can even see tha teh ball hit teh location.
how are you calculation the ball location?
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Mon Oct 31, 2011 8:18 pm
Ha okey I thonk I have a lead on the bug, this is a very subtle one. bu I beleive I foudn it.
That sweep command was very helpful in debugging it.
stand by again.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Wed Nov 02, 2011 11:04 pm
wow, this was a touff one but I beleiev I found it.
I figured out that and algorithm I was cor calculation teh intesetion of a moving sphere and a poly is wrong, it fail when teh hit point is on an edge.
anyway I am glad I had to wok o fthta bug because I fixe lot of oteh bugs in teh engien and also make more robust collision test in many oeh area.
anyway I will bring back my all test whi I beleiv is very safe but it si nor as fast.
I will check the fix tomorrow.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Thu Nov 03, 2011 11:19 am
Ok try again, I believe I have fix now.
I found some location where teh ball does no show but it does hit the face I can no figure out who to debug that because teh are too many block in teh scene.
i believe this is a another round off error (this calculation is very very sensitive to rounding error, I did not thnk it will be so complex)
if you find that case, can you make the test with jut one block, that way I do no have to debuig so much find then offending faces.
but fo rteh must part it si working now.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by pHySiQuE » Thu Nov 03, 2011 4:14 pm
You can replace "Models/navtest.mdl" with this one. It only includes the bottom block:
-
pHySiQuE
-
- Posts: 608
- Joined: Fri Sep 02, 2011 9:54 pm
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 1 guest