large worlds engine compat refactor, change vector -> float
This commit is contained in:
@@ -28,7 +28,7 @@ namespace Game
|
||||
face.halfEdges.Add(this);
|
||||
}
|
||||
|
||||
public Vector3 tail
|
||||
public Float3 tail
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -44,15 +44,15 @@ namespace Game
|
||||
|
||||
public struct Edge
|
||||
{
|
||||
public Vector3 v1, v2;
|
||||
public Float3 v1, v2;
|
||||
|
||||
public Edge(Vector3 v1, Vector3 v2)
|
||||
public Edge(Float3 v1, Float3 v2)
|
||||
{
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
}
|
||||
|
||||
public static Edge[] GetEdges(Vector3 v1, Vector3 v2, Vector3 v3)
|
||||
public static Edge[] GetEdges(Float3 v1, Float3 v2, Float3 v3)
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
@@ -97,11 +97,11 @@ namespace Game
|
||||
|
||||
public class Face
|
||||
{
|
||||
public Vector3 v1, v2, v3;
|
||||
public Float3 v1, v2, v3;
|
||||
public List<HalfEdge> halfEdges;
|
||||
public bool visited;
|
||||
|
||||
public Face(Vector3 v1, Vector3 v2, Vector3 v3)
|
||||
public Face(Float3 v1, Float3 v2, Float3 v3)
|
||||
{
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
@@ -119,7 +119,7 @@ namespace Game
|
||||
};
|
||||
}
|
||||
|
||||
public float DistanceToPoint(Vector3 point)
|
||||
public float DistanceToPoint(Float3 point)
|
||||
{
|
||||
Plane plane = new Plane(v1, v2, v3);
|
||||
|
||||
@@ -143,13 +143,13 @@ namespace Game
|
||||
{
|
||||
HalfEdge areaEdgeStart = halfEdges[0];
|
||||
HalfEdge areaEdge = areaEdgeStart.previous;
|
||||
Vector3 areaNorm = Vector3.Zero;
|
||||
Float3 areaNorm = Float3.Zero;
|
||||
int iters = 0;
|
||||
do
|
||||
{
|
||||
if (iters++ > 1000)
|
||||
throw new Exception("merge infinite loop");
|
||||
areaNorm += Vector3.Cross(areaEdge.edge.v1 - areaEdgeStart.edge.v1,
|
||||
areaNorm += Float3.Cross(areaEdge.edge.v1 - areaEdgeStart.edge.v1,
|
||||
areaEdge.next.edge.v1 - areaEdgeStart.edge.v1);
|
||||
areaEdge = areaEdge.previous;
|
||||
|
||||
@@ -161,9 +161,9 @@ namespace Game
|
||||
|
||||
public struct Tetrahedron
|
||||
{
|
||||
public Vector3 v1, v2, v3, v4;
|
||||
public Float3 v1, v2, v3, v4;
|
||||
|
||||
public Tetrahedron(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4)
|
||||
public Tetrahedron(Float3 v1, Vector3 v2, Vector3 v3, Vector3 v4)
|
||||
{
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
@@ -187,9 +187,9 @@ namespace Game
|
||||
{
|
||||
const float epsilon = 0.01f;
|
||||
|
||||
private void SortPoints(List<Vector3> points, Vector3 planeNormal)
|
||||
private void SortPoints(List<Float3> points, Vector3 planeNormal)
|
||||
{
|
||||
Vector3 center = Vector3.Zero;
|
||||
Vector3 center = Float3.Zero;
|
||||
foreach (var vert in points)
|
||||
{
|
||||
center += vert;
|
||||
@@ -200,7 +200,7 @@ namespace Game
|
||||
|
||||
points.Sort((v1, v2) =>
|
||||
{
|
||||
var dot = Vector3.Dot(planeNormal, Vector3.Cross(v1 - center, v2 - center));
|
||||
var dot = Float3.Dot(planeNormal, Float3.Cross(v1 - center, v2 - center));
|
||||
if (dot > 0)
|
||||
return 1;
|
||||
else
|
||||
@@ -208,7 +208,7 @@ namespace Game
|
||||
});
|
||||
}
|
||||
|
||||
float PointDistanceFromPlane(Vector3 point, Plane plane)
|
||||
float PointDistanceFromPlane(Float3 point, Plane plane)
|
||||
{
|
||||
float distance = (point.X * plane.Normal.X) + (point.Y * plane.Normal.Y) +
|
||||
(point.Z * plane.Normal.Z) + plane.D;
|
||||
@@ -217,15 +217,15 @@ namespace Game
|
||||
(plane.Normal.Z * plane.Normal.Z));
|
||||
}
|
||||
|
||||
private Face[] CreateInitialSimplex(Vector3[] points)
|
||||
private Face[] CreateInitialSimplex(Float3[] points)
|
||||
{
|
||||
if (false)
|
||||
{
|
||||
// TODO: more optimal to find first set of points which are not coplanar?
|
||||
|
||||
// find the longest edge
|
||||
Vector3 v1 = Vector3.Zero;
|
||||
Vector3 v2 = Vector3.Zero;
|
||||
Vector3 v1 = Float3.Zero;
|
||||
Vector3 v2 = Float3.Zero;
|
||||
foreach (var p1 in points)
|
||||
{
|
||||
foreach (var p2 in points)
|
||||
@@ -244,7 +244,7 @@ namespace Game
|
||||
Assert.IsTrue(v1 != v2, "a1 != a2");
|
||||
|
||||
// find the furthest point from the edge to form a face
|
||||
Vector3 v3 = Vector3.Zero;
|
||||
Vector3 v3 = Float3.Zero;
|
||||
float furthestDist = 0f;
|
||||
foreach (var point in points)
|
||||
{
|
||||
@@ -252,7 +252,7 @@ namespace Game
|
||||
// continue;
|
||||
|
||||
var edgeDir = (v2 - v1).Normalized;
|
||||
var closest = v1 + edgeDir * Vector3.Dot(point - v1, edgeDir);
|
||||
var closest = v1 + edgeDir * Float3.Dot(point - v1, edgeDir);
|
||||
|
||||
var dist = (point - closest).Length;
|
||||
if (dist > furthestDist)
|
||||
@@ -267,7 +267,7 @@ namespace Game
|
||||
|
||||
// find the furthest point from he face
|
||||
Plane plane = new Plane(v1, v2, v3);
|
||||
Vector3 v4 = Vector3.Zero;
|
||||
Vector3 v4 = Float3.Zero;
|
||||
float fourthDist = 0f;
|
||||
foreach (var point in points)
|
||||
{
|
||||
@@ -306,7 +306,7 @@ namespace Game
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 v1 = Vector3.Zero, v2 = Vector3.Zero, v3 = Vector3.Zero, v4 = Vector3.Zero;
|
||||
Vector3 v1 = Float3.Zero, v2 = Float3.Zero, v3 = Float3.Zero, v4 = Float3.Zero;
|
||||
bool found = false;
|
||||
|
||||
foreach (var p1 in points)
|
||||
@@ -403,7 +403,7 @@ namespace Game
|
||||
}
|
||||
}
|
||||
|
||||
public List<Vector3> QuickHull2(Vector3[] points)
|
||||
public List<Float3> QuickHull2(Float3[] points)
|
||||
{
|
||||
Assert.IsTrue(points.Length >= 4, "points.Length >= 4");
|
||||
|
||||
@@ -430,7 +430,7 @@ namespace Game
|
||||
|
||||
// verify
|
||||
{
|
||||
var tetrapoints = new List<Vector3>();
|
||||
var tetrapoints = new List<Float3>();
|
||||
foreach (var face in tetrahedron)
|
||||
{
|
||||
foreach (var he in face.halfEdges)
|
||||
@@ -569,7 +569,7 @@ namespace Game
|
||||
}
|
||||
|
||||
var hullFacesNew = new List<Face>();
|
||||
var unclaimedPoints = new List<Vector3>();
|
||||
var unclaimedPoints = new List<Float3>();
|
||||
|
||||
AddPointToHull(pointToAdd.Item2, pointFace, unclaimedPoints, outsideSet, horizonEdges, hullFacesNew);
|
||||
|
||||
@@ -629,7 +629,7 @@ namespace Game
|
||||
foreach (var f in discardedFaces)
|
||||
hullFaces.Remove(f);
|
||||
|
||||
List<Vector3> hullPoints = new List<Vector3>(hullFaces.Count * 3);
|
||||
List<Float3> hullPoints = new List<Float3>(hullFaces.Count * 3);
|
||||
foreach (var face in hullFaces)
|
||||
{
|
||||
hullPoints.Add(face.v1);
|
||||
@@ -640,7 +640,7 @@ namespace Game
|
||||
return hullPoints;
|
||||
}
|
||||
|
||||
private void AddUnique(List<Vector3> list, Vector3 point)
|
||||
private void AddUnique(List<Float3> list, Vector3 point)
|
||||
{
|
||||
foreach (var p in list)
|
||||
{
|
||||
@@ -650,27 +650,27 @@ namespace Game
|
||||
list.Add(point);
|
||||
}
|
||||
|
||||
bool AreCoincident(Vector3 a, Vector3 b)
|
||||
bool AreCoincident(Float3 a, Vector3 b)
|
||||
{
|
||||
return (a - b).Length <= epsilon;
|
||||
}
|
||||
|
||||
bool AreCollinear(Vector3 a, Vector3 b, Vector3 c)
|
||||
bool AreCollinear(Float3 a, Vector3 b, Vector3 c)
|
||||
{
|
||||
return Vector3.Cross(c - a, c - b).Length <= epsilon;
|
||||
return Float3.Cross(c - a, c - b).Length <= epsilon;
|
||||
}
|
||||
|
||||
bool AreCoplanar(Vector3 a, Vector3 b, Vector3 c, Vector3 d)
|
||||
bool AreCoplanar(Float3 a, Vector3 b, Vector3 c, Vector3 d)
|
||||
{
|
||||
var n1 = Vector3.Cross(c - a, c - b);
|
||||
var n2 = Vector3.Cross(d - a, d - b);
|
||||
var n1 = Float3.Cross(c - a, c - b);
|
||||
var n2 = Float3.Cross(d - a, d - b);
|
||||
|
||||
var m1 = n1.Length;
|
||||
var m2 = n2.Length;
|
||||
|
||||
return m1 > epsilon
|
||||
&& m2 > epsilon
|
||||
&& AreCollinear(Vector3.Zero,
|
||||
&& AreCollinear(Float3.Zero,
|
||||
(1.0f / m1) * n1,
|
||||
(1.0f / m2) * n2);
|
||||
}
|
||||
@@ -687,7 +687,7 @@ namespace Game
|
||||
bool merge = false;
|
||||
Vector3 ni = new Plane(face.v1, face.v2, face.v3).Normal;
|
||||
Vector3 nj = new Plane(oppFace.v1, oppFace.v2, oppFace.v3).Normal;
|
||||
float dotP = Vector3.Dot(ni, nj);
|
||||
float dotP = Float3.Dot(ni, nj);
|
||||
|
||||
if (dotP > maxdot_minang)
|
||||
{
|
||||
@@ -724,7 +724,7 @@ namespace Game
|
||||
|
||||
// construct the merged face
|
||||
List<HalfEdge> edges = new List<HalfEdge>();
|
||||
Face mergedFace = new Face(new Vector3(float.NaN), new Vector3(float.NaN), new Vector3(float.NaN));
|
||||
Face mergedFace = new Face(new Float3(float.NaN), new Float3(float.NaN), new Float3(float.NaN));
|
||||
|
||||
// copy the first face edges
|
||||
HalfEdge heTwin = null;
|
||||
@@ -828,7 +828,7 @@ namespace Game
|
||||
float mTolarenace = epsilon;//-1;
|
||||
float mPlaneTolerance = epsilon;//-1f;
|
||||
float maxDist = mPlaneTolerance;
|
||||
List<Vector3> uniqPoints = new List<Vector3>();
|
||||
List<Float3> uniqPoints = new List<Float3>();
|
||||
foreach (var hullFace in hullFaces)
|
||||
{
|
||||
AddUnique(uniqPoints, hullFace.v1);
|
||||
@@ -855,13 +855,13 @@ namespace Game
|
||||
|
||||
Vector3 edgeVector = (nextVertex - vertex).Normalized;
|
||||
Vector3 outVector =
|
||||
Vector3.Cross(-(new Plane(mergedFace.v1, mergedFace.v2, mergedFace.v3).Normal), edgeVector);
|
||||
Float3.Cross(-(new Plane(mergedFace.v1, mergedFace.v2, mergedFace.v3).Normal), edgeVector);
|
||||
|
||||
HalfEdge testHe = qhe.next;
|
||||
do
|
||||
{
|
||||
Vector3 testVertex = testHe.tail;
|
||||
float dist = Vector3.Dot(testVertex - vertex, outVector);
|
||||
float dist = Float3.Dot(testVertex - vertex, outVector);
|
||||
|
||||
if (dist > mTolarenace)
|
||||
return false;
|
||||
@@ -910,7 +910,7 @@ namespace Game
|
||||
return true;
|
||||
}
|
||||
|
||||
private void AddPointToHull(Vector3 point, Face face, List<Vector3> unclaimedPoints,
|
||||
private void AddPointToHull(Float3 point, Face face, List<Float3> unclaimedPoints,
|
||||
List<Tuple<Face, Vector3>> outsideSet,
|
||||
List<HalfEdge> horizonEdges, List<Face> hullFaces)
|
||||
{
|
||||
@@ -929,7 +929,7 @@ namespace Game
|
||||
var newFace = new Face(point, edge.edge.v1, edge.edge.v2);
|
||||
var newPlane = new Plane(newFace.v1, newFace.v2, newFace.v3);
|
||||
|
||||
var uniqPoints = new List<Vector3>();
|
||||
var uniqPoints = new List<Float3>();
|
||||
AddUnique(uniqPoints, newFace.v1);
|
||||
AddUnique(uniqPoints, newFace.v2);
|
||||
AddUnique(uniqPoints, newFace.v3);
|
||||
@@ -1070,7 +1070,7 @@ namespace Game
|
||||
}
|
||||
}
|
||||
|
||||
private bool AdjacentMerge(Vector3 point, Face face, List<Vector3> unclaimedPoints, List<Tuple<Face, Vector3>> outsideSet, bool mergeWrtLargerFace)
|
||||
private bool AdjacentMerge(Float3 point, Face face, List<Float3> unclaimedPoints, List<Tuple<Face, Vector3>> outsideSet, bool mergeWrtLargerFace)
|
||||
{
|
||||
const float tolerance = -1f;
|
||||
|
||||
@@ -1270,7 +1270,7 @@ namespace Game
|
||||
}
|
||||
|
||||
// calculates the outermost edges of the geometry seen from the eyePoint
|
||||
private void CalculateHorizon(Face face, Vector3 eyePoint, List<Vector3> unclaimedPoints,
|
||||
private void CalculateHorizon(Face face, Vector3 eyePoint, List<Float3> unclaimedPoints,
|
||||
List<Tuple<Face, Vector3>> outsideSet,
|
||||
List<HalfEdge> horizonEdges, HalfEdge currentEdge)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user