public void SignedDistanceFromPoint_IsMinus5() { var plane = new PlaneF() { A = 1, B = 0, C = 0, D = 5 }; var dist = plane.SignedDistanceFromPoint(new float3(0, 1, 0)); Assert.Equal(-5, dist); }
public void IntersectsAABBf_IsTrue() { var aabb = new AABBf(new float3(0, 0, -1), new float3(6, 1, 1)); var plane = new PlaneF() { A = 1, B = 0, C = 0, D = 5 }; Assert.True(plane.Intersects(aabb)); }
public void InsideOrIntersectingOBBf_IsFalse() { var aabb = new AABBf(new float3(6, 0, 0), new float3(7, 1, 1)); var plane = new PlaneF() { A = 1, B = 0, C = 0, D = 5 }; Assert.False(plane.InsideOrIntersecting(aabb)); }
public static IEnumerable <object[]> GetInsideOrIntersectingAABBf_IsTrue() { var plane = new PlaneF() { A = 1, B = 0, C = 0, D = 5 }; yield return(new object[] { plane, new AABBf(new float3(0, 0, -1), new float3(6, 1, 1)) }); //Intersects true yield return(new object[] { plane, new AABBf(new float3(0, 0, -1), new float3(4, 1, 1)) }); //Inside true, Intersects false }
public static IEnumerable <object[]> GetIntersectsAABBf_IsFalse() { var plane = new PlaneF() { A = 1, B = 0, C = 0, D = 5 }; yield return(new object[] { plane, new AABBf(float3.Zero, new float3(4, 1, 1)) }); //Intersects false yield return(new object[] { plane, new AABBf(new float3(6, 0, 0), new float3(7, 1, 1)) }); //Outside true, Intersects false }
public void IntersectsOBBf_IsFalse() { var obb = new OBBf(new float3[3] { new float3(0, 0, 0), new float3(4, 0, 0), new float3(2, 5, 5) }); var plane = new PlaneF() { A = 1, B = 0, C = 0, D = 5 }; Assert.False(plane.Intersects(obb)); }
public LMFace(Face face, Solid solid) { Plane = new PlaneF(face.Plane); Normal = Plane.Normal; Vertices = face.Vertices.Select(x => new Vertex(x)).ToList(); CastsShadows = !(solid?.Parent?.GetEntityData()?.Name.Equals("noshadow", StringComparison.OrdinalIgnoreCase) ?? false); int i1 = 0; int i2 = 1; int i3 = 2; CoordinateF v1 = Vertices[i1].Location; CoordinateF v2 = Vertices[i2].Location; CoordinateF v3 = Vertices[i3].Location; float w1x = Vertices[i1].DiffU; float w1y = Vertices[i1].DiffV; float w2x = Vertices[i2].DiffU; float w2y = Vertices[i2].DiffV; float w3x = Vertices[i3].DiffU; float w3y = Vertices[i3].DiffV; float x1 = v2.X - v1.X; float x2 = v3.X - v1.X; float y1 = v2.Y - v1.Y; float y2 = v3.Y - v1.Y; float z1 = v2.Z - v1.Z; float z2 = v3.Z - v1.Z; float s1 = w2x - w1x; float s2 = w3x - w1x; float t1 = w2y - w1y; float t2 = w3y - w1y; float r = 1.0f / (s1 * t2 - s2 * t1); CoordinateF sdir = new CoordinateF((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r); CoordinateF tdir = new CoordinateF((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r); Tangent = (sdir - Normal * Normal.Dot(sdir)).Normalise(); Bitangent = (tdir - Normal * Normal.Dot(tdir)).Normalise(); LightBasis0 = Tangent * (-1.0f / (float)Math.Sqrt(6.0)) + Bitangent * (-1.0f / (float)Math.Sqrt(2.0)) + Normal * (1.0f / (float)Math.Sqrt(3.0)); LightBasis1 = Tangent * (-1.0f / (float)Math.Sqrt(6.0)) + Bitangent * (1.0f / (float)Math.Sqrt(2.0)) + Normal * (1.0f / (float)Math.Sqrt(3.0)); LightBasis2 = Tangent * ((float)Math.Sqrt(2.0 / 3.0)) + Normal * (1.0f / (float)Math.Sqrt(3.0)); Texture = face.Texture.Name; OriginalFace = face; UpdateBoundingBox(); }
public static IEnumerable <object[]> GetFrustumPlanes() { var projection = float4x4.CreatePerspectiveFieldOfView(M.PiOver2, 1, 2, 10); var frustum = new Frustum(); frustum.CalculateFrustumPlanes(projection); var left = new PlaneF() { A = -0.5f, B = 0, C = -0.5f, D = 0 }; var right = new PlaneF() { A = 0.5f, B = 0, C = -0.5f, D = 0 }; var near = new PlaneF() { A = 0, B = 0, C = -1, D = -2 }; var far = new PlaneF() { A = 0, B = 0, C = 1, D = 10 }; var top = new PlaneF() { A = 0, B = 0.5f, C = -0.5f, D = 0 }; var bottom = new PlaneF() { A = 0, B = -0.5f, C = -0.5f, D = 0 }; yield return(new object[] { near.Normalize(), frustum.Near.Normalize() }); yield return(new object[] { far.Normalize(), frustum.Far.Normalize() }); yield return(new object[] { left.Normalize(), frustum.Left.Normalize() }); yield return(new object[] { right.Normalize(), frustum.Right.Normalize() }); yield return(new object[] { top.Normalize(), frustum.Top.Normalize() }); yield return(new object[] { bottom.Normalize(), frustum.Bottom.Normalize() }); }
public static LightmapGroup FindCoplanar(List <LightmapGroup> lmGroups, LMFace otherFace) { foreach (LightmapGroup group in lmGroups) { if ((group.Plane.Normal - otherFace.Plane.Normal).LengthSquared() < 0.01f) { PlaneF plane2 = new PlaneF(otherFace.Plane.Normal, otherFace.Vertices[0].Location); if (Math.Abs(plane2.EvalAtPoint((group.Plane.PointOnPlane))) > 4.0f) { continue; } BoxF faceBox = new BoxF(otherFace.BoundingBox.Start - new CoordinateF(3.0f, 3.0f, 3.0f), otherFace.BoundingBox.End + new CoordinateF(3.0f, 3.0f, 3.0f)); if (faceBox.IntersectsWith(group.BoundingBox)) { return(group); } } } return(null); }
public void CalculateFrustumPlanes_IsFrustumPlanes(PlaneF actual, PlaneF expected) { Assert.Equal(expected, actual); }
public void IntersectsAABBf_IsFalse(PlaneF plane, AABBf aabb) { Assert.False(plane.Intersects(aabb)); }
public void Normalize_Instance(PlaneF plane, PlaneF expected) { var normalizedPlane = plane.Normalize(); Assert.Equal(normalizedPlane, expected); }
public void InsideOrIntersectingOBBf_IsTrue(PlaneF plane, OBBf obb) { Assert.True(plane.InsideOrIntersecting(obb)); }
public void InsideOrIntersectingAABBf_IsTrue(PlaneF plane, AABBf aabb) { Assert.True(plane.InsideOrIntersecting(aabb)); }