Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CylSphere testing, scenery collisions/sliding #720

Merged
merged 1 commit into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions Source/ACE.Server/Physics/Animation/Transition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,14 +551,6 @@ public bool FindTransitionalPosition()
CollisionInfo.ContactPlaneValid = false;
CollisionInfo.ContactPlaneIsWater = false;

// custom debugging
if (CollisionInfo.LastKnownContactPlaneValid)
{
CollisionInfo.ContactPlaneValid = true;
CollisionInfo.SetContactPlane(CollisionInfo.LastKnownContactPlane, CollisionInfo.LastKnownContactPlaneIsWater);
CollisionInfo.ContactPlaneCellID = CollisionInfo.LastKnownContactPlaneCellID;
}

if (SpherePath.InsertType != InsertType.Transition)
{
var insert = TransitionalInsert(3);
Expand Down
7 changes: 3 additions & 4 deletions Source/ACE.Server/Physics/Collision/GfxObj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,16 @@ public GfxObj(DatLoader.FileTypes.GfxObj gfxObj)
PhysicsPolygons = new Dictionary<ushort, Polygon>();
foreach (var kvp in gfxObj.PhysicsPolygons)
PhysicsPolygons.Add(kvp.Key, new Polygon(kvp.Value, gfxObj.VertexArray));
// usebuiltmesh
// physicssphere
PhysicsBSP = new BSP.BSPTree(gfxObj.PhysicsBSP, gfxObj.PhysicsPolygons, gfxObj.VertexArray);
PhysicsSphere = PhysicsBSP.GetSphere();
SortCenter = gfxObj.SortCenter;
NumPolygons = gfxObj.Polygons.Count;
Polygons = new Dictionary<ushort, Polygon>();
foreach (var kvp in gfxObj.Polygons)
Polygons.Add(kvp.Key, new Polygon(kvp.Value, gfxObj.VertexArray));
// drawing sphere
// usebuiltmesh
DrawingBSP = new BSP.BSPTree(gfxObj.DrawingBSP, gfxObj.Polygons, gfxObj.VertexArray);

DrawingSphere = DrawingBSP.GetSphere();
}

public TransitionState FindObjCollisions(GfxObj gfxObj, Transition transition, float scaleZ)
Expand Down
2 changes: 1 addition & 1 deletion Source/ACE.Server/Physics/Common/ObjCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public TransitionState FindObjCollisions(Transition transition)
{
var obj = shadowObj.PhysicsObj;

if (obj.Parent != null || obj == transition.ObjectInfo.Object)
if (obj.Parent != null || obj.Equals(transition.ObjectInfo.Object))
continue;

var state = obj.FindObjCollisions(transition);
Expand Down
69 changes: 35 additions & 34 deletions Source/ACE.Server/Physics/CylSphere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ACE.Server.Physics.Animation;
using ACE.Server.Physics.Collision;
using ACE.Server.Physics.Common;
using ACE.Server.Physics.Extensions;

namespace ACE.Server.Physics
{
Expand Down Expand Up @@ -102,9 +103,9 @@ public TransitionState CollideWithPoint(Transition transition, Sphere checkPos,
radsum += PhysicsGlobals.EPSILON;

// this is similar to ray/sphere intersection, could be inlined...
var xyMoveLenSq = movement.X * movement.X + movement.Y * movement.Y;
var xyDiff = -(movement.X * old_disp.X + movement.Y * old_disp.Y); // negative 2D dot product
var diffSq = xyDiff * xyDiff - (old_disp.X * old_disp.X + old_disp.Y * old_disp.Y - radsum * radsum) * xyMoveLenSq;
var xyMoveLenSq = movement.LengthSquared2D();
var xyDiff = -movement.Dot2D(old_disp);
var diffSq = xyDiff * xyDiff - (old_disp.LengthSquared2D() - radsum * radsum) * xyMoveLenSq;
var diff = (float)Math.Sqrt(diffSq);
Vector3 scaledMovement, offset;
float time; // calculated below, refactor
Expand All @@ -125,18 +126,18 @@ public TransitionState CollideWithPoint(Transition transition, Sphere checkPos,
}

scaledMovement = movement * time;
if ((scaledMovement.X + old_disp.X) * (scaledMovement.X + old_disp.X) +
(scaledMovement.Y + old_disp.Y) * (scaledMovement.Y + old_disp.Y) >= radsum * radsum)
var scaledLenSq = (scaledMovement + old_disp).LengthSquared2D();
if (scaledLenSq >= radsum * radsum)
{
if (Math.Abs(xyMoveLenSq) < PhysicsGlobals.EPSILON)
return TransitionState.Collided;

if (diffSq >= 0.0f && xyMoveLenSq > PhysicsGlobals.EPSILON)
{
if (xyDiff - diff < 0.0f)
time = (diff - (movement.X * old_disp.X + movement.Y * old_disp.Y)) / xyMoveLenSq;
time = (float)((diff - movement.Dot2D(old_disp)) / xyMoveLenSq);
else
time = (xyDiff - diff) / xyMoveLenSq;
time = (float)((xyDiff - diff) / xyMoveLenSq);

scaledMovement = movement * time;
}
Expand Down Expand Up @@ -181,9 +182,9 @@ public TransitionState CollideWithPoint(Transition transition, Sphere checkPos,
return TransitionState.Collided;

if (xyDiff - diff < 0.0f)
time = (diff - (movement.X * old_disp.X + movement.Y * old_disp.Y)) / xyMoveLenSq;
time = (float)((diff - movement.Dot2D(old_disp)) / xyMoveLenSq);
else
time = (xyDiff - diff) / xyMoveLenSq;
time = (float)((xyDiff - diff) / xyMoveLenSq);

scaledMovement = movement * time;
if (time < 0.0f || time > 1.0f)
Expand All @@ -203,13 +204,14 @@ public TransitionState CollideWithPoint(Transition transition, Sphere checkPos,
/// </summary>
public bool CollidesWithSphere(Sphere checkPos, Vector3 disp, float radsum)
{
if (disp.X * disp.X + disp.Y * disp.Y < radsum * radsum)
return true;
var result = false;

if (checkPos.Radius - PhysicsGlobals.EPSILON + Height * 0.5f < Math.Abs(Height * 0.5f - disp.Z))
return true;

return false;
if (disp.X * disp.X + disp.Y * disp.Y <= radsum * radsum)
{
if (checkPos.Radius - PhysicsGlobals.EPSILON + Height * 0.5f >= Math.Abs(Height * 0.5f - disp.Z))
result = true;
}
return result;
}

/// <summary>
Expand Down Expand Up @@ -241,13 +243,10 @@ public TransitionState IntersectsSphere(Transition transition)
if (CollidesWithSphere(globSphere, disp, radsum))
return TransitionState.Collided;

if (path.NumSphere > 1)
{
if (CollidesWithSphere(globSphere_, disp_, radsum))
return TransitionState.Collided; // backwards in original??
if (path.NumSphere > 1 && CollidesWithSphere(globSphere_, disp_, radsum))
return TransitionState.Collided;

return TransitionState.OK;
}
return TransitionState.OK;
}
else
{
Expand Down Expand Up @@ -306,7 +305,8 @@ public TransitionState IntersectsSphere(Transition transition)

// what is v39 pointing to before this?
var distSq = movement.LengthSquared();
var diff = -Vector3.Dot(movement, disp);
//var diff = -Vector3.Dot(movement, disp);
var diff = movement.Z * disp.Z - movement.Dot2D(disp);

if (Math.Abs(distSq) < PhysicsGlobals.EPSILON)
return TransitionState.Collided;
Expand All @@ -317,7 +317,7 @@ public TransitionState IntersectsSphere(Transition transition)
t = diff * 2 - diff;
var time = diff / distSq;
var timecheck = (1 - time) * transition.SpherePath.WalkInterp;
if (timecheck < transition.SpherePath.WalkableAllowance && timecheck < -0.1f)
if (timecheck >= transition.SpherePath.WalkInterp || timecheck < -0.1f)
return TransitionState.Collided;

movement *= time;
Expand All @@ -326,7 +326,8 @@ public TransitionState IntersectsSphere(Transition transition)
if (!transition.SpherePath.IsWalkableAllowable(disp.Z))
return TransitionState.OK;

var contactPlane = new Plane(disp, (globSphere.Center - disp * globSphere.Radius).Length()); // add plane
var pDist = -Vector3.Dot(disp, globSphere.Center - disp * globSphere.Radius);
var contactPlane = new Plane(disp, pDist);
transition.CollisionInfo.SetContactPlane(contactPlane, true);
transition.CollisionInfo.ContactPlaneCellID = transition.SpherePath.CheckPos.ObjCellID;
transition.SpherePath.WalkInterp = timecheck;
Expand Down Expand Up @@ -411,9 +412,9 @@ public TransitionState StepSphereDown(Transition transition, Sphere checkPos, Ve
if (interp >= path.WalkInterp || interp < -0.1f)
return TransitionState.Collided;

var contactPoint = new Vector3(checkPos.Center.X, checkPos.Center.Y, deltaz - checkPos.Radius);
var normal = new Vector3(0, 0, 1.0f);
var contactPlane = new Plane(normal, contactPoint.Length()); // add plane
var normal = Vector3.UnitZ;
var contactPoint = new Vector3(checkPos.Center.X, checkPos.Center.Y, checkPos.Center.Z + (deltaz - checkPos.Radius));
var contactPlane = new Plane(normal, -Vector3.Dot(normal, contactPoint));

var collisions = transition.CollisionInfo;
collisions.SetContactPlane(contactPlane, true); // is water?
Expand Down Expand Up @@ -451,16 +452,16 @@ public TransitionState StepSphereUp(Transition transition, Sphere checkPos, Vect
/// <summary>
/// Returns the collision normal for this CylSphere transition
/// </summary>
public bool CollisionNormal(Transition transition, Sphere checkPos, Vector3 disp, float radsum, int sphereNum, out Vector3 normal)
public bool CollisionNormal(Transition transition, Sphere checkPos, Vector3 _disp, float radsum, int sphereNum, out Vector3 normal)
{
var globCurCenter = transition.SpherePath.GlobalCurrCenter[sphereNum].Center - LowPoint;
if (radsum * radsum < globCurCenter.X * globCurCenter.X + globCurCenter.Y * globCurCenter.Y)
var disp = transition.SpherePath.GlobalCurrCenter[sphereNum].Center - LowPoint;
if (radsum * radsum < disp.LengthSquared2D())
{
normal = new Vector3(globCurCenter.X, globCurCenter.Y, 0);
return (checkPos.Radius - PhysicsGlobals.EPSILON + Height * 0.5f >= Math.Abs(Height * 0.5f - globCurCenter.Z)
|| Math.Abs(globCurCenter.Z - disp.Z) <= PhysicsGlobals.EPSILON);
normal = new Vector3(disp.X, disp.Y, 0);
return (checkPos.Radius - PhysicsGlobals.EPSILON + Height * 0.5f >= Math.Abs(Height * 0.5f - disp.Z)
|| Math.Abs(disp.Z - _disp.Z) <= PhysicsGlobals.EPSILON);
}
var normZ = (disp.Z - globCurCenter.Z <= 0.0f) ? 1 : -1; // -1082130432 == -1 || 4?
var normZ = (_disp.Z - disp.Z <= 0.0f) ? 1 : -1;
normal = new Vector3(0, 0, normZ);
return true;
}
Expand Down
7 changes: 4 additions & 3 deletions Source/ACE.Server/Physics/PartArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ public bool InitParts()
Parts[i].PhysObjIndex = i;
}

// can defaultscale count be less than numparts?
if (Setup.DefaultScale != null && Setup.DefaultScale.Count == NumParts)
{
for (var i = 0; i < NumParts; i++)
Expand Down Expand Up @@ -526,15 +525,17 @@ public bool SetPlacementFrame(int placementID)

public bool SetScaleInternal(Vector3 newScale)
{
Scale = newScale;

for (var i = 0; i < NumParts; i++)
{
var part = Parts[i];
if (part != null)
{
if (Setup.DefaultScale != null)
if (Setup.DefaultScale.Count > i)
part.GfxObjScale = Setup.DefaultScale[i] * newScale;
else
part.GfxObjScale = Scale;
part.GfxObjScale = newScale;
}
}
return true;
Expand Down