public void Calculate_AABB() { var bounds = JMesh.CalculateBounds(JMeshPhysicsMeshes.triangle); TestMethods.AreEqualIsh(bounds.center, new Vector3(0.5f, 0, 0.5f)); TestMethods.AreEqualIsh(bounds.size, new Vector3(1f, 0, 1f)); }
public void CheckMatrixTransformation() { var diff = 0.0001f; var matrix = Matrix4x4.TRS(Vector3.one, Quaternion.Euler(Vector3.up * 45), Vector3.one * 2); TestMethods.AreEqualIsh(1.41421f, matrix.m00, diff); TestMethods.AreEqualIsh(0f, matrix.m01, diff); //Antar at dette er bortover TestMethods.AreEqualIsh(1.41421f, matrix.m02, diff); TestMethods.AreEqualIsh(1f, matrix.m03, diff); TestMethods.AreEqualIsh(0f, matrix.m10, diff); TestMethods.AreEqualIsh(2f, matrix.m11, diff); TestMethods.AreEqualIsh(0f, matrix.m12, diff); TestMethods.AreEqualIsh(1f, matrix.m13, diff); TestMethods.AreEqualIsh(-1.41421f, matrix.m20, diff); TestMethods.AreEqualIsh(0f, matrix.m21, diff); TestMethods.AreEqualIsh(1.41421f, matrix.m22, diff); TestMethods.AreEqualIsh(1f, matrix.m23, diff); TestMethods.AreEqualIsh(0f, matrix.m30, diff); TestMethods.AreEqualIsh(0f, matrix.m31, diff); TestMethods.AreEqualIsh(0f, matrix.m32, diff); TestMethods.AreEqualIsh(1f, matrix.m33, diff); }
public void Calculate_frame_instance_for_triangle_rotated_90_degrees_anti_clockwise_with_translation() { var startMesh = JMeshPhysicsMeshes.triangleMeshIdentity; var jMesh = JMesh.FromMeshAndTransform(startMesh, Matrix4x4.TRS( new Vector3(1, 0, 1), Quaternion.Euler(Vector3.up * -90), Vector3.one )); TestMethods.AreEqualIsh(Vector3.right, startMesh.EdgeOutwardNormals[1], "bc normal"); var vcs = jMesh.EdgeVertices; TestMethods.AreEqualIsh(new Vector3(1, 0, 1), vcs[0], "v0"); TestMethods.AreEqualIsh(new Vector3(1, 0, 2), vcs[1], "v1"); TestMethods.AreEqualIsh(new Vector3(0, 0, 2), vcs[2], "v2"); var ns = jMesh.EdgeOutwardNormals; TestMethods.AreEqualIsh(Vector3.right, ns[0], "ns0"); TestMethods.AreEqualIsh(Vector3.forward, ns[1], "ns1"); TestMethods.AreEqualIsh(new Vector3(-1, 0, -1).normalized, ns[2], "ns2"); var bounds = jMesh.AABB; var center = bounds.center; var min = bounds.min; var max = bounds.max; TestMethods.AreEqualIsh(new Vector3(0.5f, 0, 1.5f), center, "center"); TestMethods.AreEqualIsh(0f, min.x, TestMethods.VECTOR_DIFF); TestMethods.AreEqualIsh(1f, min.z, TestMethods.VECTOR_DIFF); TestMethods.AreEqualIsh(1f, max.x, TestMethods.VECTOR_DIFF); TestMethods.AreEqualIsh(2f, max.z, TestMethods.VECTOR_DIFF); }
public void Calculate_bounce_of_incoming_vector() { TestMethods.AreEqualIsh(new Vector3(-2, 0, 1), PhysicsManager.ScaleVectorInNormalDirection(new Vector3(-1, 0, 1), Vector3.left, 2f)); TestMethods.AreEqualIsh(new Vector3(-1, 0, 2), PhysicsManager.ScaleVectorInNormalDirection(Vector3.forward, new Vector3(-1, 0, 1), 2f)); TestMethods.AreEqualIsh(new Vector3(1, 0, -2), PhysicsManager.ScaleVectorInNormalDirection(Vector3.back, new Vector3(1, 0, -1), 2f)); TestMethods.AreEqualIsh(new Vector3(-0.4f, 0, 1.2f), PhysicsManager.ScaleVectorInNormalDirection(Vector3.forward, new Vector3(-2, 0, 1).normalized, 2f)); }
private void checkIntersect(Slope slopeA, Slope slopeB, Vector3 intersectionPoint) { var intersection = slopeA.CalculateIntersection(slopeB); Assert.AreEqual(IntersectionType.INTERSECT, intersection.Type); TestMethods.AreEqualIsh(intersectionPoint, intersection.Point); }
public void Calculate_frame_instance_for_square_rotated_45_degrees_clockwise() { var startMesh = JMeshPhysicsMeshes.squareMeshIdentity; var jMesh = JMesh.FromMeshAndTransform(startMesh, Matrix4x4.TRS( new Vector3(1, 0, 1), Quaternion.Euler(Vector3.up * 45), Vector3.one * 2 )); var halfHeight = Mathf.Sqrt(2); var upRightDirection = new Vector3(1, 0, 1).normalized; var vcs = jMesh.EdgeVertices; TestMethods.AreEqualIsh(new Vector3(1, 0, 1), vcs[0], "v0"); TestMethods.AreEqualIsh(new Vector3(1 + halfHeight, 0, 1 - halfHeight), vcs[1], "v1"); TestMethods.AreEqualIsh(new Vector3(1 + 2 * halfHeight, 0, 1), vcs[2], "v2"); TestMethods.AreEqualIsh(new Vector3(1 + halfHeight, 0, 1 + halfHeight), vcs[3], "v3"); var ns = jMesh.EdgeOutwardNormals; TestMethods.AreEqualIsh(-upRightDirection, ns[0], "ns0"); TestMethods.AreEqualIsh(new Vector3(upRightDirection.x, 0, -upRightDirection.z), ns[1], "ns1"); TestMethods.AreEqualIsh(upRightDirection, ns[2], "ns2"); TestMethods.AreEqualIsh(new Vector3(-upRightDirection.x, 0, upRightDirection.z), ns[3], "ns3"); }
public void Extract_triangle_edge_vertices_test() { var vertices = JMesh.ExtractEdgeVertices(JMeshPhysicsMeshes.triangle, JMeshPhysicsMeshes.triangleTriangles); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.triangle[0], vertices[0]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.triangle[1], vertices[1]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.triangle[2], vertices[2]); }
public void Extract_square_edge_vertices_for_reversed_triangle_faces_test() { var vertices = JMesh.ExtractEdgeVertices(JMeshPhysicsMeshes.square, JMeshPhysicsMeshes.squareTrianglesDifferentTriangles); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.square[0], vertices[0]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.square[1], vertices[1]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.square[2], vertices[2]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.square[3], vertices[3]); }
public void Extract_square_five_edge_vertices_test() { var vertices = JMesh.ExtractEdgeVertices(JMeshPhysicsMeshes.squareFive, JMeshPhysicsMeshes.squareFiveTriangles); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.squareFive[0], vertices[0]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.squareFive[1], vertices[1]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.squareFive[3], vertices[2]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.squareFive[4], vertices[3]); }
public void Calculate_minmumPushDistance_should_push_b_left() { var meshA = JMeshPhysicsMeshes.squareMeshIdentity; var meshB = JMesh.FromMeshAndTransform(JMeshPhysicsMeshes.triangleMeshIdentity, Matrix4x4.Translate(new Vector3(-0.8f, 0, 0.25f))); var pushResult = JMeshOverlapPushUtil.CalculateMinimumPush(meshA, meshB); TestMethods.AreEqualIshOrOppositeIsh(new Vector3(-1, 0, 0), pushResult.Direction); TestMethods.AreEqualIsh(0.2f, pushResult.Magnitude, TestMethods.VECTOR_DIFF); }
public void Calculate_outward_normals_of_square_different_triangles_should_give_same_as_normal_since_vertex_order_is_the_same() { var vertices = JMesh.ExtractEdgeVertices(JMeshPhysicsMeshes.square, JMeshPhysicsMeshes.squareTrianglesDifferentTriangles); var normals = JMesh.CalculateOutwardNormals(vertices); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.squareFiveNormals[0], normals[0]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.squareFiveNormals[1], normals[1]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.squareFiveNormals[2], normals[2]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.squareFiveNormals[3], normals[3]); }
public void Calculate_outward_normals_of_square() { var vertices = JMesh.ExtractEdgeVertices(JMeshPhysicsMeshes.square, JMeshPhysicsMeshes.squareTriangles); var normals = JMesh.CalculateOutwardNormals(vertices); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.squareNormals[0], normals[0]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.squareNormals[1], normals[1]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.squareNormals[2], normals[2]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.squareNormals[3], normals[3]); }
public void Calculate_outwards_normals_of_tall_triangle() { var vertices = JMesh.ExtractEdgeVertices(JMeshPhysicsMeshes.triangleTall, JMeshPhysicsMeshes.triangleTallTriangles); var normals = JMesh.CalculateOutwardNormals(vertices); Assert.AreEqual(3, normals.Length); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.triangleTallNormals[0], normals[0]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.triangleTallNormals[1], normals[1]); TestMethods.AreEqualIsh(JMeshPhysicsMeshes.triangleTallNormals[2], normals[2]); }
public void Calculate_minmumPushDistance_should_push_b_down_even_when_argument_order_is_reversed() { var meshA = JMeshPhysicsMeshes.squareMeshIdentity; var meshB = JMesh.FromMeshAndTransform(JMeshPhysicsMeshes.triangleMeshIdentity, Matrix4x4.Translate(new Vector3(0, 0, -0.5f))); var pushResult = JMeshOverlapPushUtil.CalculateMinimumPush(meshB, meshA); TestMethods.AreEqualIshOrOppositeIsh(new Vector3(-1, 0, 1).normalized, pushResult.Direction); TestMethods.AreEqualIsh(Mathf.Sin(45 * Mathf.Deg2Rad) / 2f, pushResult.Magnitude, TestMethods.VECTOR_DIFF); }
public void Check_calculated_tall_triangle_JMesh() { var triangle = JMeshPhysicsMeshes.triangleTallMeshIdentity; TestMethods.AreEqualIsh(new Vector3(1f, 0, 2f), triangle.AABB.size); TestMethods.AreEqualIsh(new Vector3(0, 0, -1), triangle.EdgeOutwardNormals[0]); TestMethods.AreEqualIsh(new Vector3(1, 0, 0), triangle.EdgeOutwardNormals[1]); TestMethods.AreEqualIsh(new Vector3(-2, 0, 1).normalized, triangle.EdgeOutwardNormals[2]); TestMethods.AreEqualIsh(new Vector3(0, 0, 0), triangle.EdgeVertices[0]); TestMethods.AreEqualIsh(new Vector3(1, 0, 0), triangle.EdgeVertices[1]); TestMethods.AreEqualIsh(new Vector3(1, 0, 2), triangle.EdgeVertices[2]); }
public void Calculate_frame_instance_for_nonunformly_scaled_triangle() { var transformed = JMesh.FromMeshAndTransform(JMeshPhysicsMeshes.triangleMeshIdentity, Matrix4x4.Scale(new Vector3(1, 1, 2))); var expected = JMeshPhysicsMeshes.triangleTallMeshIdentity; var tMesh = transformed; TestMethods.AreEqualIsh(expected.AABB.size, tMesh.AABB.size); TestMethods.AreEqualIsh(expected.EdgeOutwardNormals[0], tMesh.EdgeOutwardNormals[0]); TestMethods.AreEqualIsh(expected.EdgeOutwardNormals[1], tMesh.EdgeOutwardNormals[1]); TestMethods.AreEqualIsh(expected.EdgeOutwardNormals[2], tMesh.EdgeOutwardNormals[2]); TestMethods.AreEqualIsh(expected.EdgeVertices[0], tMesh.EdgeVertices[0]); TestMethods.AreEqualIsh(expected.EdgeVertices[1], tMesh.EdgeVertices[1]); TestMethods.AreEqualIsh(expected.EdgeVertices[2], tMesh.EdgeVertices[2]); }
public void Calculate_reflection_of_incoming_vector() { TestMethods.AreEqualIsh(new Vector3(-1, 0, 1), PhysicsManager.ReflectIncomingVector(new Vector3(1, 0, 1), Vector3.left)); TestMethods.AreEqualIsh(new Vector3(2, 0, 0), PhysicsManager.ReflectIncomingVector(new Vector3(0, 0, -2), new Vector3(1, 0, 1).normalized)); }