bug fix, and make Mesh-Mesh and Mesh-Terrain collisions a lot softer

avinationmerge
UbitUmarov 2015-10-14 02:32:51 +01:00
parent 9ec9eee75f
commit 7deaad7368
1 changed files with 78 additions and 72 deletions

View File

@ -633,17 +633,17 @@ namespace OpenSim.Region.PhysicsModule.ubOde
#region Collision Detection #region Collision Detection
// sets a global contact for a joint for contactgeom , and base contact description) // sets a global contact for a joint for contactgeom , and base contact description)
private IntPtr CreateContacJoint(ref d.ContactGeom contactGeom,bool smooth)
private IntPtr CreateContacJoint(ref d.ContactGeom contactGeom)
{ {
if (m_global_contactcount >= maxContactsbeforedeath) if (m_global_contactcount >= maxContactsbeforedeath)
return IntPtr.Zero; return IntPtr.Zero;
m_global_contactcount++; m_global_contactcount++;
if(smooth)
SharedTmpcontact.geom.depth = contactGeom.depth; SharedTmpcontact.geom.depth = contactGeom.depth * 0.05f;
else
SharedTmpcontact.geom.depth = contactGeom.depth;
SharedTmpcontact.geom.pos = contactGeom.pos;
SharedTmpcontact.geom.pos = contactGeom.pos; SharedTmpcontact.geom.pos = contactGeom.pos;
SharedTmpcontact.geom.normal = contactGeom.normal; SharedTmpcontact.geom.normal = contactGeom.normal;
@ -836,6 +836,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
bool dop1ava = false; bool dop1ava = false;
bool dop2ava = false; bool dop2ava = false;
bool ignore = false; bool ignore = false;
bool smoothMesh = false;
switch (p1.PhysicsActorType) switch (p1.PhysicsActorType)
{ {
@ -879,6 +880,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
if (relVlenSQ > 0.01f) if (relVlenSQ > 0.01f)
mu *= frictionMovementMult; mu *= frictionMovementMult;
if(d.GeomGetClass(g2) == d.GeomClassID.TriMeshClass &&
d.GeomGetClass(g1) == d.GeomClassID.TriMeshClass)
smoothMesh = true;
break; break;
case (int)ActorTypes.Ground: case (int)ActorTypes.Ground:
@ -889,13 +893,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
if (Math.Abs(p1.Velocity.X) > 0.1f || Math.Abs(p1.Velocity.Y) > 0.1f) if (Math.Abs(p1.Velocity.X) > 0.1f || Math.Abs(p1.Velocity.Y) > 0.1f)
mu *= frictionMovementMult; mu *= frictionMovementMult;
p1.CollidingGround = true; p1.CollidingGround = true;
/*
if (d.GeomGetClass(g1) == d.GeomClassID.TriMeshClass) if(d.GeomGetClass(g1) == d.GeomClassID.TriMeshClass)
{ smoothMesh = true;
if (curContact.side1 > 0)
IgnoreNegSides = true;
}
*/
break; break;
case (int)ActorTypes.Water: case (int)ActorTypes.Water:
@ -919,6 +919,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
if (Math.Abs(p2.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y) > 0.1f) if (Math.Abs(p2.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y) > 0.1f)
mu *= frictionMovementMult; mu *= frictionMovementMult;
if(d.GeomGetClass(g2) == d.GeomClassID.TriMeshClass)
smoothMesh = true;
} }
else else
ignore = true; ignore = true;
@ -951,76 +954,77 @@ namespace OpenSim.Region.PhysicsModule.ubOde
bool useAltcontact = false; bool useAltcontact = false;
bool noskip = true; bool noskip = true;
if(dop1ava || dop2ava)
smoothMesh = false;
while (true) while (true)
{ {
// if (!(IgnoreNegSides && curContact.side1 < 0)) noskip = true;
useAltcontact = false;
if (dop1ava)
{ {
noskip = true; if ((((OdeCharacter)p1).Collide(g1, g2, false, ref curContact, ref altContact , ref useAltcontact, ref FeetCollision)))
useAltcontact = false;
if (dop1ava)
{ {
if ((((OdeCharacter)p1).Collide(g1, g2, false, ref curContact, ref altContact , ref useAltcontact, ref FeetCollision))) if (p2.PhysicsActorType == (int)ActorTypes.Agent)
{ {
if (p2.PhysicsActorType == (int)ActorTypes.Agent) p1.CollidingObj = true;
{ p2.CollidingObj = true;
p1.CollidingObj = true;
p2.CollidingObj = true;
}
else if (p2.Velocity.LengthSquared() > 0.0f)
p2.CollidingObj = true;
} }
else else if (p2.Velocity.LengthSquared() > 0.0f)
noskip = false; p2.CollidingObj = true;
} }
else if (dop2ava) else
noskip = false;
}
else if (dop2ava)
{
if ((((OdeCharacter)p2).Collide(g2, g1, true, ref curContact, ref altContact , ref useAltcontact, ref FeetCollision)))
{ {
if ((((OdeCharacter)p2).Collide(g2, g1, true, ref curContact, ref altContact , ref useAltcontact, ref FeetCollision))) if (p1.PhysicsActorType == (int)ActorTypes.Agent)
{ {
if (p1.PhysicsActorType == (int)ActorTypes.Agent) p1.CollidingObj = true;
{ p2.CollidingObj = true;
p1.CollidingObj = true;
p2.CollidingObj = true;
}
else if (p2.Velocity.LengthSquared() > 0.0f)
p1.CollidingObj = true;
} }
else else if (p2.Velocity.LengthSquared() > 0.0f)
noskip = false; p1.CollidingObj = true;
}
else
noskip = false;
}
if (noskip)
{
if(useAltcontact)
Joint = CreateContacJoint(ref altContact,smoothMesh);
else
Joint = CreateContacJoint(ref curContact,smoothMesh);
if (Joint == IntPtr.Zero)
break;
d.JointAttach(Joint, b1, b2);
ncontacts++;
if (curContact.depth > maxDepthContact.PenetrationDepth)
{
maxDepthContact.Position.X = curContact.pos.X;
maxDepthContact.Position.Y = curContact.pos.Y;
maxDepthContact.Position.Z = curContact.pos.Z;
maxDepthContact.PenetrationDepth = curContact.depth;
maxDepthContact.CharacterFeet = FeetCollision;
} }
if (noskip) if (curContact.depth < minDepthContact.PenetrationDepth)
{ {
if(useAltcontact) minDepthContact.PenetrationDepth = curContact.depth;
Joint = CreateContacJoint(ref altContact); minDepthContact.SurfaceNormal.X = curContact.normal.X;
else minDepthContact.SurfaceNormal.Y = curContact.normal.Y;
Joint = CreateContacJoint(ref curContact); minDepthContact.SurfaceNormal.Z = curContact.normal.Z;
if (Joint == IntPtr.Zero)
break;
d.JointAttach(Joint, b1, b2);
ncontacts++;
if (curContact.depth > maxDepthContact.PenetrationDepth)
{
maxDepthContact.Position.X = curContact.pos.X;
maxDepthContact.Position.Y = curContact.pos.Y;
maxDepthContact.Position.Z = curContact.pos.Z;
maxDepthContact.PenetrationDepth = curContact.depth;
maxDepthContact.CharacterFeet = FeetCollision;
}
if (curContact.depth < minDepthContact.PenetrationDepth)
{
minDepthContact.PenetrationDepth = curContact.depth;
minDepthContact.SurfaceNormal.X = curContact.normal.X;
minDepthContact.SurfaceNormal.Y = curContact.normal.Y;
minDepthContact.SurfaceNormal.Z = curContact.normal.Z;
}
} }
} }
if (++i >= count) if (++i >= count)
break; break;
@ -1148,12 +1152,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
aprim.CollisionScore = 0; aprim.CollisionScore = 0;
aprim.IsColliding = false; aprim.IsColliding = false;
} }
}
lock (_activeprims)
{
try try
{ {
foreach (OdePrim aprim in _activeprims) foreach (OdePrim aprim in _activegroups)
{ {
if(d.BodyIsEnabled(aprim.Body)) if(!aprim.m_outbounds && d.BodyIsEnabled(aprim.Body))
{ {
d.SpaceCollide2(StaticSpace, aprim.collide_geom, IntPtr.Zero, nearCallback); d.SpaceCollide2(StaticSpace, aprim.collide_geom, IntPtr.Zero, nearCallback);
d.SpaceCollide2(GroundSpace, aprim.collide_geom, IntPtr.Zero, nearCallback); d.SpaceCollide2(GroundSpace, aprim.collide_geom, IntPtr.Zero, nearCallback);