large worlds engine compat refactor, change vector -> float
This commit is contained in:
@@ -157,11 +157,11 @@ namespace Game
|
||||
/// used for more than one triangle.
|
||||
/// </summary>
|
||||
public void GenerateHull(
|
||||
List<Vector3> points,
|
||||
List<Float3> points,
|
||||
bool splitVerts,
|
||||
ref List<Vector3> verts,
|
||||
ref List<Float3> verts,
|
||||
ref List<int> tris,
|
||||
ref List<Vector3> normals)
|
||||
ref List<Float3> normals)
|
||||
{
|
||||
if (points.Count < 4)
|
||||
throw new ArgumentException("Need at least 4 points to generate a convex hull");
|
||||
@@ -181,7 +181,7 @@ namespace Game
|
||||
/// Make sure all the buffers and variables needed for the algorithm
|
||||
/// are initialized.
|
||||
/// </summary>
|
||||
private void Initialize(List<Vector3> points, bool splitVerts)
|
||||
private void Initialize(List<Float3> points, bool splitVerts)
|
||||
{
|
||||
faceCount = 0;
|
||||
openSetTail = -1;
|
||||
@@ -226,7 +226,7 @@ namespace Game
|
||||
/// <summary>
|
||||
/// Create initial seed hull.
|
||||
/// </summary>
|
||||
private void GenerateInitialHull(List<Vector3> points)
|
||||
private void GenerateInitialHull(List<Float3> points)
|
||||
{
|
||||
// Find points suitable for use as the seed hull. Some varieties of
|
||||
// this algorithm pick extreme points here, but I'm not convinced
|
||||
@@ -235,10 +235,10 @@ namespace Game
|
||||
int b0, b1, b2, b3;
|
||||
FindInitialHullIndices(points, out b0, out b1, out b2, out b3);
|
||||
|
||||
Vector3 v0 = points[b0];
|
||||
Vector3 v1 = points[b1];
|
||||
Vector3 v2 = points[b2];
|
||||
Vector3 v3 = points[b3];
|
||||
Float3 v0 = points[b0];
|
||||
Float3 v1 = points[b1];
|
||||
Float3 v2 = points[b2];
|
||||
Float3 v3 = points[b3];
|
||||
|
||||
bool above = Dot(v3 - v1, Cross(v1 - v0, v2 - v0)) > 0.0f;
|
||||
|
||||
@@ -358,29 +358,29 @@ namespace Game
|
||||
/// Find four points in the point cloud that are not coplanar for the
|
||||
/// seed hull
|
||||
/// </summary>
|
||||
private void FindInitialHullIndices(List<Vector3> points, out int b0, out int b1, out int b2, out int b3)
|
||||
private void FindInitialHullIndices(List<Float3> points, out int b0, out int b1, out int b2, out int b3)
|
||||
{
|
||||
int count = points.Count;
|
||||
|
||||
for (int i0 = 0; i0 < count - 3; i0++)
|
||||
for (int i1 = i0 + 1; i1 < count - 2; i1++)
|
||||
{
|
||||
Vector3 p0 = points[i0];
|
||||
Vector3 p1 = points[i1];
|
||||
Float3 p0 = points[i0];
|
||||
Float3 p1 = points[i1];
|
||||
|
||||
if (AreCoincident(p0, p1))
|
||||
continue;
|
||||
|
||||
for (int i2 = i1 + 1; i2 < count - 1; i2++)
|
||||
{
|
||||
Vector3 p2 = points[i2];
|
||||
Float3 p2 = points[i2];
|
||||
|
||||
if (AreCollinear(p0, p1, p2))
|
||||
continue;
|
||||
|
||||
for (int i3 = i2 + 1; i3 < count - 0; i3++)
|
||||
{
|
||||
Vector3 p3 = points[i3];
|
||||
Float3 p3 = points[i3];
|
||||
|
||||
if (AreCoplanar(p0, p1, p2, p3))
|
||||
continue;
|
||||
@@ -402,7 +402,7 @@ namespace Game
|
||||
/// to encompass the point in openSet with the point furthest away
|
||||
/// from its face.
|
||||
/// </summary>
|
||||
private void GrowHull(List<Vector3> points)
|
||||
private void GrowHull(List<Float3> points)
|
||||
{
|
||||
Assert.IsTrue(openSetTail >= 0);
|
||||
Assert.IsTrue(openSet[0].Face != INSIDE);
|
||||
@@ -451,7 +451,7 @@ namespace Game
|
||||
/// only has to visit two (because one of them has already been
|
||||
/// visited, the one you came from).
|
||||
/// </summary>
|
||||
private void FindHorizon(List<Vector3> points, Vector3 point, int fi, Face face)
|
||||
private void FindHorizon(List<Float3> points, Float3 point, int fi, Face face)
|
||||
{
|
||||
// TODO should I use epsilon in the PointFaceDistance comparisons?
|
||||
|
||||
@@ -530,7 +530,7 @@ namespace Game
|
||||
/// <summary>
|
||||
/// Recursively search to find the horizon or lit set.
|
||||
/// </summary>
|
||||
private void SearchHorizon(List<Vector3> points, Vector3 point, int prevFaceIndex, int faceCount, Face face)
|
||||
private void SearchHorizon(List<Float3> points, Float3 point, int prevFaceIndex, int faceCount, Face face)
|
||||
{
|
||||
Assert.IsTrue(prevFaceIndex >= 0);
|
||||
Assert.IsTrue(litFaces.Contains(prevFaceIndex));
|
||||
@@ -631,7 +631,7 @@ namespace Game
|
||||
/// on the other side of the horizon to reflect it's new neighbor from
|
||||
/// the cone.
|
||||
/// </summary>
|
||||
private void ConstructCone(List<Vector3> points, int farthestPoint)
|
||||
private void ConstructCone(List<Float3> points, int farthestPoint)
|
||||
{
|
||||
foreach (int fi in litFaces)
|
||||
{
|
||||
@@ -642,7 +642,7 @@ namespace Game
|
||||
int firstNewFace = faceCount;
|
||||
|
||||
// Check for coplanar faces
|
||||
/*var firstNormal = new Vector3(0, 0, 0);
|
||||
/*var firstNormal = new Float3(0, 0, 0);
|
||||
int sameNormals = 1;
|
||||
for (int i = 0; i < horizon.Count; i++)
|
||||
{
|
||||
@@ -725,7 +725,7 @@ namespace Game
|
||||
/// doing that to make this loop shorter, a straight for-loop through
|
||||
/// a list is pretty darn fast. Still, it might be worth trying
|
||||
/// </summary>
|
||||
private void ReassignPoints(List<Vector3> points)
|
||||
private void ReassignPoints(List<Float3> points)
|
||||
{
|
||||
for (int i = 0; i <= openSetTail; i++)
|
||||
{
|
||||
@@ -734,7 +734,7 @@ namespace Game
|
||||
if (litFaces.Contains(fp.Face))
|
||||
{
|
||||
bool assigned = false;
|
||||
Vector3 point = points[fp.Point];
|
||||
Float3 point = points[fp.Point];
|
||||
|
||||
foreach (var kvp in faces)
|
||||
{
|
||||
@@ -785,14 +785,14 @@ namespace Game
|
||||
/// leaves the normal array empty.
|
||||
/// </summary>
|
||||
private void ExportMesh(
|
||||
List<Vector3> points,
|
||||
List<Float3> points,
|
||||
bool splitVerts,
|
||||
ref List<Vector3> verts,
|
||||
ref List<Float3> verts,
|
||||
ref List<int> tris,
|
||||
ref List<Vector3> normals)
|
||||
ref List<Float3> normals)
|
||||
{
|
||||
if (verts == null)
|
||||
verts = new List<Vector3>();
|
||||
verts = new List<Float3>();
|
||||
else
|
||||
verts.Clear();
|
||||
|
||||
@@ -802,7 +802,7 @@ namespace Game
|
||||
tris.Clear();
|
||||
|
||||
if (normals == null)
|
||||
normals = new List<Vector3>();
|
||||
normals = new List<Float3>();
|
||||
else
|
||||
normals.Clear();
|
||||
|
||||
@@ -858,7 +858,7 @@ namespace Game
|
||||
/// the point is above the face)
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private float PointFaceDistance(Vector3 point, Vector3 pointOnFace, Face face)
|
||||
private float PointFaceDistance(Float3 point, Float3 pointOnFace, Face face)
|
||||
{
|
||||
return Dot(face.Normal, point - pointOnFace);
|
||||
}
|
||||
@@ -867,7 +867,7 @@ namespace Game
|
||||
/// Calculate normal for triangle
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private Vector3 Normal(Vector3 v0, Vector3 v1, Vector3 v2)
|
||||
private Float3 Normal(Float3 v0, Float3 v1, Float3 v2)
|
||||
{
|
||||
return Cross(v1 - v0, v2 - v0).Normalized;
|
||||
}
|
||||
@@ -876,20 +876,20 @@ namespace Game
|
||||
/// Dot product, for convenience.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static float Dot(Vector3 a, Vector3 b)
|
||||
private static float Dot(Float3 a, Float3 b)
|
||||
{
|
||||
return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Vector3.Cross i left-handed, the algorithm is right-handed. Also,
|
||||
/// Float3.Cross i left-handed, the algorithm is right-handed. Also,
|
||||
/// i wanna test to see if using aggressive inlining makes any
|
||||
/// difference here.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static Vector3 Cross(Vector3 a, Vector3 b)
|
||||
private static Float3 Cross(Float3 a, Float3 b)
|
||||
{
|
||||
return new Vector3(
|
||||
return new Float3(
|
||||
a.Y * b.Z - a.Z * b.Y,
|
||||
a.Z * b.X - a.X * b.Z,
|
||||
a.X * b.Y - a.Y * b.X);
|
||||
@@ -899,7 +899,7 @@ namespace Game
|
||||
/// Check if two points are coincident
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private bool AreCoincident(Vector3 a, Vector3 b)
|
||||
private bool AreCoincident(Float3 a, Float3 b)
|
||||
{
|
||||
return (a - b).Length <= EPSILON;
|
||||
}
|
||||
@@ -908,7 +908,7 @@ namespace Game
|
||||
/// Check if three points are collinear
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private bool AreCollinear(Vector3 a, Vector3 b, Vector3 c)
|
||||
private bool AreCollinear(Float3 a, Float3 b, Float3 c)
|
||||
{
|
||||
return Cross(c - a, c - b).Length <= EPSILON;
|
||||
}
|
||||
@@ -917,17 +917,17 @@ namespace Game
|
||||
/// Check if four points are coplanar
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private bool AreCoplanar(Vector3 a, Vector3 b, Vector3 c, Vector3 d)
|
||||
private bool AreCoplanar(Float3 a, Float3 b, Float3 c, Float3 d)
|
||||
{
|
||||
Vector3 n1 = Cross(c - a, c - b);
|
||||
Vector3 n2 = Cross(d - a, d - b);
|
||||
Float3 n1 = Cross(c - a, c - b);
|
||||
Float3 n2 = Cross(d - a, d - b);
|
||||
|
||||
float m1 = n1.Length;
|
||||
float m2 = n2.Length;
|
||||
|
||||
return m1 <= EPSILON
|
||||
|| m2 <= EPSILON
|
||||
|| AreCollinear(Vector3.Zero,
|
||||
|| AreCollinear(Float3.Zero,
|
||||
1.0f / m1 * n1,
|
||||
1.0f / m2 * n2);
|
||||
}
|
||||
@@ -937,7 +937,7 @@ namespace Game
|
||||
/// sensible state. Conditionally compiled if DEBUG_QUICKHULL if
|
||||
/// defined.
|
||||
/// </summary>
|
||||
private void VerifyOpenSet(List<Vector3> points)
|
||||
private void VerifyOpenSet(List<Float3> points)
|
||||
{
|
||||
for (int i = 0; i < openSet.Count; i++)
|
||||
if (i > openSetTail)
|
||||
@@ -977,7 +977,7 @@ namespace Game
|
||||
/// sensible state. Conditionally compiled if DEBUG_QUICKHULL if
|
||||
/// defined.
|
||||
/// </summary>
|
||||
private void VerifyFaces(List<Vector3> points)
|
||||
private void VerifyFaces(List<Float3> points)
|
||||
{
|
||||
foreach (var kvp in faces)
|
||||
{
|
||||
@@ -1012,18 +1012,18 @@ namespace Game
|
||||
/// actually a convex hull of all the points. Conditionally compiled
|
||||
/// if DEBUG_QUICKHULL if defined.
|
||||
/// </summary>
|
||||
private void VerifyMesh(List<Vector3> points, ref List<Vector3> verts, ref List<int> tris)
|
||||
private void VerifyMesh(List<Float3> points, ref List<Float3> verts, ref List<int> tris)
|
||||
{
|
||||
Assert.IsTrue(tris.Count % 3 == 0);
|
||||
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
for (int j = 0; j < tris.Count; j += 3)
|
||||
{
|
||||
Vector3 t0 = verts[tris[j]];
|
||||
Vector3 t1 = verts[tris[j + 1]];
|
||||
Vector3 t2 = verts[tris[j + 2]];
|
||||
Float3 t0 = verts[tris[j]];
|
||||
Float3 t1 = verts[tris[j + 1]];
|
||||
Float3 t2 = verts[tris[j + 2]];
|
||||
|
||||
float dot = Dot(points[i] - t0, Vector3.Cross(t1 - t0, t2 - t0));
|
||||
float dot = Dot(points[i] - t0, Float3.Cross(t1 - t0, t2 - t0));
|
||||
//Assert.IsTrue(dot <= EPSILON, $"not convex hull: {dot} > {EPSILON}");
|
||||
if (!(dot <= EPSILON))
|
||||
Console.PrintError($"not convex hull: {dot} > {EPSILON}");
|
||||
@@ -1061,9 +1061,9 @@ namespace Game
|
||||
public int Opposite1;
|
||||
public int Opposite2;
|
||||
|
||||
public readonly Vector3 Normal;
|
||||
public readonly Float3 Normal;
|
||||
|
||||
public Face(int v0, int v1, int v2, int o0, int o1, int o2, Vector3 normal)
|
||||
public Face(int v0, int v1, int v2, int o0, int o1, int o2, Float3 normal)
|
||||
{
|
||||
Vertex0 = v0;
|
||||
Vertex1 = v1;
|
||||
|
||||
Reference in New Issue
Block a user