//TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(displayMesh, seed); //Is adding memory each time we run it in playmode, which could maybe //have been solved by destroying the meshes we create each update??? //But DrawMesh is similar private void OnDrawGizmos() { if (multiColoredMeshes != null) { foreach (Mesh m in multiColoredMeshes) { TestAlgorithmsHelpMethods.DisplayMeshEdges(m, Color.black); } } //This point is set to be outside if its not active Gizmos.color = Color.white; //Gizmos.DrawWireSphere(activePoint.ToVector3(), 0.3f); //Connected points if (connectedPoints != null) { Gizmos.color = Color.white; for (int i = 0; i < connectedPoints.Count; i++) { //Show the circle Gizmos.DrawWireSphere(connectedPoints[i].ToVector3(), 0.2f); //Line to previous point if (i > 0) { Gizmos.DrawLine(connectedPoints[i].ToVector3(), connectedPoints[i - 1].ToVector3()); } } } }
//Is a triangle intersecting with a triangle? private void TriangleTriangle() { //3d to 2d Triangle2 t1 = new Triangle2( t1_p1_trans.transform.position.ToMyVector2(), t1_p2_trans.transform.position.ToMyVector2(), t1_p3_trans.transform.position.ToMyVector2()); Triangle2 t2 = new Triangle2( t2_p1_trans.transform.position.ToMyVector2(), t2_p2_trans.transform.position.ToMyVector2(), t2_p3_trans.transform.position.ToMyVector2()); bool isIntersecting = _Intersections.TriangleTriangle2D(t1, t2, do_AABB_test: false); //Display //Color color = isIntersecting ? Color.red : Color.white; //TestAlgorithmsHelpMethods.DisplayTriangle(t1.p1.ToVector3(), t1.p2.ToVector3(), t1.p3.ToVector3(), color); //TestAlgorithmsHelpMethods.DisplayTriangle(t2.p1.ToVector3(), t2.p2.ToVector3(), t2.p3.ToVector3(), color); //With mesh to better see what's going on TestAlgorithmsHelpMethods.DisplayTriangleMesh(t1.p1, t1.p2, t1.p3, Color.white); Color meshColor = isIntersecting ? Color.red : Color.white; TestAlgorithmsHelpMethods.DisplayTriangleMesh(t2.p1, t2.p2, t2.p3, meshColor); }
//Is a triangle oriented clockwise private void IsTriangleOrientedClockwise(MyVector2 a, MyVector2 b, MyVector2 c) { Triangle2 t = new Triangle2(a, b, c); bool isOrientedClockwise = _Geometry.IsTriangleOrientedClockwise(t.p1, t.p2, t.p3); Debug.Log("Is oriented clockwise: " + isOrientedClockwise); //We can also test if changing orientation is working t.ChangeOrientation(); bool isOrientedClockwiseAfterRotation = _Geometry.IsTriangleOrientedClockwise(t.p1, t.p2, t.p3); Debug.Log("Is oriented clockwise after changing orientation: " + isOrientedClockwiseAfterRotation); //Display the triangle Gizmos.color = Color.white; Gizmos.DrawLine(a.ToVector3(), b.ToVector3()); Gizmos.DrawLine(b.ToVector3(), c.ToVector3()); Gizmos.DrawLine(c.ToVector3(), a.ToVector3()); //Arrows showing the direction of the triangle float arrowSize = 0.1f; TestAlgorithmsHelpMethods.DisplayArrow(a.ToVector3(), b.ToVector3(), arrowSize, Color.white); TestAlgorithmsHelpMethods.DisplayArrow(b.ToVector3(), c.ToVector3(), arrowSize, Color.white); TestAlgorithmsHelpMethods.DisplayArrow(c.ToVector3(), a.ToVector3(), arrowSize, Color.white); }
//Is a point to the left or to the right of a vector going from a to b private void PointInRelationToVector(MyVector2 a, MyVector2 b, MyVector2 p) { //bool isToLeft = Geometry.IsPointLeftOfVector(a, b, p); //Debug.Log("Is to left: " + isToLeft); LeftOnRight value = _Geometry.IsPoint_Left_On_Right_OfVector(a, b, p); if (value == LeftOnRight.Left) { Debug.Log("Left"); } if (value == LeftOnRight.On) { Debug.Log("On"); } if (value == LeftOnRight.Right) { Debug.Log("Right"); } //Display Vector3 a_3d = a.ToVector3(); Vector3 b_3d = b.ToVector3(); Gizmos.DrawLine(a_3d, b_3d); float arrowSize = 0.1f; TestAlgorithmsHelpMethods.DisplayArrow(a_3d, b_3d, arrowSize, Color.white); Gizmos.DrawWireSphere(p.ToVector3(), 0.1f); }
//Display a connected set of points, like a convex hull //Can also show direction by displaying a tiny arrow public static void DisplayConnectedPoints(List <Vector3> points, Color color, bool showDirection = false) { if (points == null) { return; } Gizmos.color = color; for (int i = 0; i < points.Count; i++) { Vector3 p1 = points[MathUtility.ClampListIndex(i - 1, points.Count)]; Vector3 p2 = points[MathUtility.ClampListIndex(i + 0, points.Count)]; //Direction is important so we should display an arrow show the order of the points if (i == 0 && showDirection) { TestAlgorithmsHelpMethods.DisplayArrow(p1, p2, 0.2f, color); } else { Gizmos.DrawLine(p1, p2); } Gizmos.DrawWireSphere(p1, 0.1f); } }
private void OnDrawGizmos() { HashSet <Triangle2> grid = _GenerateMesh.GenerateGrid(width, cells); if (grid != null) { //But this will not display each triangle, so we don't know if the mesh is correct //Gizmos.DrawMesh(grid, Vector3.zero, Quaternion.identity); //Convert the triangles to a mesh //2d to 3d HashSet <Triangle3> grid_3d = new HashSet <Triangle3>(); foreach (Triangle2 t in grid) { Triangle3 t_3d = new Triangle3(t.p1.ToMyVector3_Yis3D(), t.p2.ToMyVector3_Yis3D(), t.p3.ToMyVector3_Yis3D()); grid_3d.Add(t_3d); } //Triangle to mesh //Will also test that the triangle->mesh is working //Mesh meshGrid = TransformBetweenDataStructures.Triangle3ToCompressedMesh(grid_3d); Mesh meshGrid = _TransformBetweenDataStructures.Triangle3ToMesh(grid_3d); TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(meshGrid, 0); } }
private void OnDrawGizmos() { if (triangulatedMesh != null) { //Display the triangles with a random color TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(triangulatedMesh, seed); //Display the points TestAlgorithmsHelpMethods.DisplayPoints(points, 0.1f, Color.black); //Display the points on the hull if (pointsOnHull != null && pointsOnHull.Count > 0) { HashSet <Vector3> pointsOnHull_3d = new HashSet <Vector3>(); foreach (MyVector2 p in pointsOnHull) { pointsOnHull_3d.Add(p.ToVector3()); } TestAlgorithmsHelpMethods.DisplayPoints(pointsOnHull_3d, 0.3f, Color.black); } } if (testTriangles != null) { List <Triangle2> test = new List <Triangle2>(testTriangles); testTriangleNumber = Mathf.Clamp(testTriangleNumber, 0, testTriangles.Count - 1); Triangle2 t = test[testTriangleNumber]; TestAlgorithmsHelpMethods.DisplayTriangle(t.p1.ToVector3(), t.p2.ToVector3(), t.p3.ToVector3(), Color.white); } }
private void DisplayConnectedPoints(Transform parentToPoints, Color color) { List <Vector3> pointsOnHull = GetPointsFromParent(parentToPoints); if (pointsOnHull == null) { Debug.Log("We have no points on the hull"); return; } //Debug.Log(pointsOnHull.Count); Gizmos.color = color; for (int i = 0; i < pointsOnHull.Count; i++) { Vector3 p1 = pointsOnHull[MathUtility.ClampListIndex(i - 1, pointsOnHull.Count)]; Vector3 p2 = pointsOnHull[MathUtility.ClampListIndex(i + 0, pointsOnHull.Count)]; //Direction is important so we should display an arrow show the order of the points if (i == 0) { TestAlgorithmsHelpMethods.DisplayArrow(p1, p2, 0.2f, color); } else { Gizmos.DrawLine(p1, p2); } Gizmos.DrawWireSphere(p1, 0.1f); } }
//Is a point intersecting with a triangle? private void PointTriangle() { MyVector2 p = pointTrans.position.ToMyVector2(); MyVector2 t_p1 = t1_p1_trans.position.ToMyVector2(); MyVector2 t_p2 = t1_p2_trans.position.ToMyVector2(); MyVector2 t_p3 = t1_p3_trans.position.ToMyVector2(); Triangle2 t = new Triangle2(t_p1, t_p2, t_p3); bool isIntersecting = _Intersections.PointTriangle(t, p, includeBorder: true); //Display //Gizmos.color = isIntersecting ? Color.red : Color.white; //Gizmos.DrawWireSphere(p.ToVector3(), 0.1f); //Gizmos.DrawLine(t.p1.ToVector3(), t.p2.ToVector3()); //Gizmos.DrawLine(t.p2.ToVector3(), t.p3.ToVector3()); //Gizmos.DrawLine(t.p3.ToVector3(), t.p1.ToVector3()); //With mesh to better see what's going on //Triangle TestAlgorithmsHelpMethods.DisplayTriangleMesh(t_p1, t_p2, t_p3, Color.white); //Point Color pointColor = isIntersecting ? Color.red : Color.white; TestAlgorithmsHelpMethods.DisplayCircleMesh(p, 1f, 20, pointColor); }
private void StartConvexHull() { //Get random points in 3d space //HashSet<Vector3> points_Unity = TestAlgorithmsHelpMethods.GenerateRandomPoints3D(seed: 0, halfCubeSize: 1f, numberOfPoints: 50); //Get random points on a sphere HashSet <Vector3> points_Unity = TestAlgorithmsHelpMethods.GenerateRandomPointsOnSphere(seed: 0, radius: 1f, numberOfPoints: 50); //Generate points we can display foreach (Vector3 p in points_Unity) { GameObject newPoint = Instantiate(pointObj, p, Quaternion.identity); newPoint.SetActive(true); allPoints.Add(newPoint); } //Standardize the data //To MyVector3 HashSet <MyVector3> points = new HashSet <MyVector3>(points_Unity.Select(x => x.ToMyVector3())); //Normalize normalizer = new Normalizer3(new List <MyVector3>(points)); HashSet <MyVector3> points_normalized = normalizer.Normalize(points); VisualizeIterativeConvexHull visualizeThisAlgorithm = GetComponent <VisualizeIterativeConvexHull>(); visualizeThisAlgorithm.StartVisualizer(points_normalized); }
//Is a line intersecting with a plane? private void LinePlane() { Vector3 planeNormal = planeTrans.forward; Vector3 planePos = planeTrans.position; Vector3 line_p1 = t1_p1_trans.position; Vector3 line_p2 = t1_p2_trans.position; //2d space MyVector2 planeNormal_2d = planeNormal.ToMyVector2(); MyVector2 planePos_2d = planePos.ToMyVector2(); MyVector2 line_p1_2d = line_p1.ToMyVector2(); MyVector2 line_p2_2d = line_p2.ToMyVector2(); bool isIntersecting = _Intersections.LinePlane(planePos_2d, planeNormal_2d, line_p1_2d, line_p2_2d); //Debug //TestAlgorithmsHelpMethods.DrawPlane(planePos_2d, planeNormal_2d, Color.blue); ////Line //Gizmos.color = Color.white; //Gizmos.DrawWireSphere(line_p1, 0.1f); //Gizmos.DrawWireSphere(line_p2, 0.1f); //if (isIntersecting) //{ // Gizmos.color = Color.red; // MyVector2 intersectionPoint = Intersections.GetLinePlaneIntersectionPoint(planePos_2d, planeNormal_2d, line_p1_2d, line_p2_2d); // Gizmos.DrawWireSphere(intersectionPoint.ToVector3(), 0.2f); //} //Gizmos.DrawLine(line_p1, line_p2); //Display with mesh //Plane TestAlgorithmsHelpMethods.DisplayPlaneMesh(planePos_2d, planeNormal_2d, 0.5f, Color.blue); //Line TestAlgorithmsHelpMethods.DisplayLineMesh(line_p1_2d, line_p2_2d, 0.5f, Color.white); if (isIntersecting) { MyVector2 intersectionPoint = _Intersections.GetLinePlaneIntersectionPoint(planePos_2d, planeNormal_2d, line_p1_2d, line_p2_2d); TestAlgorithmsHelpMethods.DisplayCircleMesh(intersectionPoint, 1f, 20, Color.red); } }
//Connected list of points public static void DisplayConnectedLinesMesh(List <MyVector2> points, float lineWidth, Color color) { HashSet <Triangle2> triangles = GenerateMesh.ConnectedLineSegments(points, lineWidth, isConnected: true); Mesh mesh = _TransformBetweenDataStructures.Triangles2ToMesh(triangles, false); TestAlgorithmsHelpMethods.DisplayMesh(mesh, color); }
//Circle public static void DisplayCircleMesh(MyVector2 center, float radius, int resolution, Color color) { HashSet <Triangle2> triangles = GenerateMesh.Circle(center, radius, resolution); Mesh mesh = _TransformBetweenDataStructures.Triangles2ToMesh(triangles, false); TestAlgorithmsHelpMethods.DisplayMesh(mesh, color); }
//Arrow public static void DisplayArrowMesh(MyVector2 a, MyVector2 b, float width, float arrowSize, Color color) { HashSet <Triangle2> triangles = GenerateMesh.Arrow(a, b, width, arrowSize); Mesh mesh = _TransformBetweenDataStructures.Triangles2ToMesh(triangles, false); TestAlgorithmsHelpMethods.DisplayMesh(mesh, color); }
private void LineSegmemt(MyVector2 pA, MyVector2 pB) { HashSet <Triangle2> triangles = _GenerateMesh.LineSegment(pA, pB, 0.2f); Mesh mesh = _TransformBetweenDataStructures.Triangles2ToMesh(triangles, useCompressedMesh: false); //Display TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(mesh, 0); }
private void CircleMeshHollow(MyVector2 pA) { HashSet <Triangle2> triangles = _GenerateMesh.CircleHollow(pA, innerRadius: 3f, resolution: 30, width: 1f); Mesh mesh = _TransformBetweenDataStructures.Triangles2ToMesh(triangles, useCompressedMesh: false); //Display //TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(mesh, 0); TestAlgorithmsHelpMethods.DisplayMesh(mesh, Color.white); }
private void BezierCubic(MyVector3 posA, MyVector3 posB, MyVector3 handleA, MyVector3 handleB) { //Store the interpolated values so we later can display them List <Vector3> interpolatedValues = new List <Vector3>(); //Loop between 0 and 1 in steps, where 1 step is minimum //So if steps is 5 then the line will be cut in 5 sections int steps = 20; float stepSize = 1f / (float)steps; float t = 0f; //+1 becuase wa also have to include the first point for (int i = 0; i < steps + 1; i++) { //Debug.Log(t); MyVector3 interpolatedPos = _Interpolation.BezierCubic(posA, posB, handleA, handleB, t); interpolatedValues.Add(interpolatedPos.ToVector3()); t += stepSize; } //Display the curve DisplayInterpolatedValues(interpolatedValues, useRandomColor: true); //Display the start and end values and the handle points DisplayHandle(handleA.ToVector3(), posA.ToVector3()); DisplayHandle(handleB.ToVector3(), posB.ToVector3()); //Display other related data //Get the orientation of the point at t BezierCubic bezierCubic = new BezierCubic(posA, posB, handleA, handleB); InterpolationTransform trans = bezierCubic.GetTransform(tSliderValue); //Multiply the orientation with a direction vector to rotate the direction Vector3 forwardDir = trans.Forward.ToVector3(); //- right vector because in this test files we are looking from above //so -right looks like up even though in the actual coordinate system it is -right Vector3 upDir = -trans.Right.ToVector3(); Vector3 slidePos = _Interpolation.BezierCubic(posA, posB, handleA, handleB, tSliderValue).ToVector3(); TestAlgorithmsHelpMethods.DisplayArrow(slidePos, slidePos + forwardDir * 2f, 0.2f, Color.blue); TestAlgorithmsHelpMethods.DisplayArrow(slidePos, slidePos + upDir * 2f, 0.2f, Color.blue); Gizmos.color = Color.red; Gizmos.DrawWireSphere(slidePos, 0.15f); }
private void OnDrawGizmos() { // // Generate the random sites // HashSet <Vector3> randomSites = new HashSet <Vector3>(); //Generate random numbers with a seed Random.InitState(seed); float max = halfMapSize; float min = -halfMapSize; for (int i = 0; i < numberOfPoints; i++) { float randomX = Random.Range(min, max); float randomZ = Random.Range(min, max); randomSites.Add(new Vector3(randomX, 0f, randomZ)); } //Points outside of the screen for voronoi which has some cells that are infinite float bigSize = halfMapSize * 5f; //Star shape which will give a better result when a cell is infinite large //When using other shapes, some of the infinite cells misses triangles randomSites.Add(new Vector3(0f, 0f, bigSize)); randomSites.Add(new Vector3(0f, 0f, -bigSize)); randomSites.Add(new Vector3(bigSize, 0f, 0f)); randomSites.Add(new Vector3(-bigSize, 0f, 0f)); //3d to 2d HashSet <MyVector2> randomSites_2d = new HashSet <MyVector2>(); foreach (Vector3 v in randomSites) { randomSites_2d.Add(v.ToMyVector2()); } //Generate the voronoi List <VoronoiCell2> voronoiCells = _Voronoi.DelaunyToVoronoi(randomSites_2d); //Display the voronoi diagram DisplayVoronoiCells(voronoiCells); //Display the sites TestAlgorithmsHelpMethods.DisplayPoints(randomSites, 0.1f, Color.black); //Generate delaunay for comparisons GenerateDelaunay(randomSites_2d); }
//Is a point intersecting with a circle? private void PointCircle() { MyVector2 testPoint = pointTrans.position.ToMyVector2(); MyVector2 circlePointA = t1_p1_trans.position.ToMyVector2(); MyVector2 circlePointB = t1_p2_trans.position.ToMyVector2(); MyVector2 circlePointC = t1_p3_trans.position.ToMyVector2(); //Is a point in a circle determines by three other points IntersectionCases intersectionCases = _Intersections.PointCircle(circlePointA, circlePointB, circlePointC, testPoint); //print(isPointInCircle); //Display the circle //if (intersectionCases == IntersectionCases.NoIntersection) //{ // Gizmos.color = Color.white; //} //if (intersectionCases == IntersectionCases.IsInside) //{ // Gizmos.color = Color.red; //} //if (intersectionCases == IntersectionCases.IsOnEdge) //{ // Gizmos.color = Color.blue; //} MyVector2 centerOfCicle = _Geometry.CalculateCircleCenter(circlePointA, circlePointB, circlePointC); float radius = MyVector2.Distance(centerOfCicle, circlePointA); //Gizmos.DrawWireSphere(centerOfCicle.ToVector3(), radius); ////Display the points //float pointRadius = 0.2f; //Gizmos.DrawWireSphere(pointTrans.position, pointRadius); //Gizmos.DrawWireSphere(t1_p1_trans.position, pointRadius); //Gizmos.DrawWireSphere(t1_p2_trans.position, pointRadius); //Gizmos.DrawWireSphere(t1_p3_trans.position, pointRadius); //With mesh //Big circle TestAlgorithmsHelpMethods.DisplayCircleMesh(centerOfCicle, radius, 60, Color.white); //Small circle Color circleColor = (intersectionCases == IntersectionCases.IsInside) ? Color.red : Color.white; TestAlgorithmsHelpMethods.DisplayCircleMesh(testPoint, 1f, 20, circleColor); }
//The mesh we generate with the Marching Squares algorithm private void DisplayGeneratedMesh() { if (grid == null) { return; } Mesh mesh = grid.GenerateUnityMesh(0f); TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(mesh, 0); }
private void GenerateDelaunay(HashSet <MyVector2> points_2d) { //Normalize AABB2 normalizingBox = new AABB2(new List <MyVector2>(points_2d)); float dMax = HelpMethods.CalculateDMax(normalizingBox); HashSet <MyVector2> points_2d_normalized = HelpMethods.Normalize(points_2d, normalizingBox, dMax); //Generate delaunay //HalfEdgeData2 delaunayData = _Delaunay.FlippingEdges(points_2d_normalized, new HalfEdgeData2()); HalfEdgeData2 delaunayData = _Delaunay.PointByPoint(points_2d_normalized, new HalfEdgeData2()); //UnNormalize HalfEdgeData2 triangleData = HelpMethods.UnNormalize(delaunayData, normalizingBox, dMax); //From halfedge to triangle HashSet <Triangle2> triangles = _TransformBetweenDataStructures.HalfEdge2ToTriangle2(triangleData); //Make sure they have the correct orientation triangles = HelpMethods.OrientTrianglesClockwise(triangles); //2d to 3d HashSet <Triangle3> triangles_3d = new HashSet <Triangle3>(); int counter = -1; foreach (Triangle2 t in triangles) { counter++; //if (counter != 2) //{ // continue; //} triangles_3d.Add(new Triangle3(t.p1.ToMyVector3_Yis3D(), t.p2.ToMyVector3_Yis3D(), t.p3.ToMyVector3_Yis3D())); //Debug.Log($"p1: {t.p1.x} {t.p1.y} p2: {t.p2.x} {t.p2.y} p3: {t.p3.x} {t.p3.y}"); //MyVector2 circleCenter = _Geometry.CalculateCircleCenter(t.p1, t.p2, t.p3); //Debug.Log("Circle center: " + circleCenter.x + " " + circleCenter.y); } Mesh delaunayMesh = _TransformBetweenDataStructures.Triangle3ToCompressedMesh(triangles_3d); //Display the delaunay triangles TestAlgorithmsHelpMethods.DisplayMeshEdges(delaunayMesh, Color.black); }
//Is a plane intersecting with a plane private void PlanePlane() { Vector3 planeNormal_1 = planeTrans.forward; Vector3 planePos_1 = planeTrans.position; Vector3 planeNormal_2 = rayTrans.forward; Vector3 planePos_2 = rayTrans.position; //3d to 2d MyVector2 normal_1 = planeNormal_1.ToMyVector2(); MyVector2 normal_2 = planeNormal_2.ToMyVector2(); MyVector2 pos1 = planePos_1.ToMyVector2(); MyVector2 pos2 = planePos_2.ToMyVector2(); Plane2 plane_1 = new Plane2(pos1, normal_1); Plane2 plane_2 = new Plane2(pos2, normal_2); //Intersections bool isIntersecting = _Intersections.PlanePlane(plane_1, plane_2); Debug.Log("Are planes intersecting: " + isIntersecting); //Display //if (isIntersecting) //{ // MyVector2 intersectionPoint = Intersections.GetPlanePlaneIntersectionPoint(pos1, normal_1, pos2, normal_2); // Gizmos.DrawWireSphere(intersectionPoint.ToVector3(), 0.2f); //} //Color planeColor = isIntersecting ? Color.red : Color.white; //TestAlgorithmsHelpMethods.DrawPlane(pos1, normal_1, planeColor); //TestAlgorithmsHelpMethods.DrawPlane(pos2, normal_2, planeColor); //Display with mesh TestAlgorithmsHelpMethods.DisplayPlaneMesh(pos1, normal_1, 0.5f, Color.blue); TestAlgorithmsHelpMethods.DisplayPlaneMesh(pos2, normal_2, 0.5f, Color.blue); if (isIntersecting) { MyVector2 intersectionPoint = _Intersections.GetPlanePlaneIntersectionPoint(plane_1, plane_2); TestAlgorithmsHelpMethods.DisplayCircleMesh(intersectionPoint, 1f, 20, Color.red); } }
//Triangle public static void DisplayTriangleMesh(MyVector2 a, MyVector2 b, MyVector2 c, Color color) { Triangle2 t = new Triangle2(a, b, c); HashSet <Triangle2> triangles = new HashSet <Triangle2>(); triangles.Add(t); triangles = HelpMethods.OrientTrianglesClockwise(triangles); Mesh mesh = _TransformBetweenDataStructures.Triangles2ToMesh(triangles, false); TestAlgorithmsHelpMethods.DisplayMesh(mesh, color); }
private void DisplayTriangles() { if (triangulation == null) { return; } //Convert from triangle to mesh Mesh mesh = _TransformBetweenDataStructures.Triangles2ToMesh(triangulation, false); TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(mesh, 0); //TestAlgorithmsHelpMethods.DisplayMesh(mesh, Color.gray); }
private void PassedWaypoint(MyVector2 wp1, MyVector2 wp2, MyVector2 testPoint) { bool hasPassed = _Geometry.HasPassedWaypoint(wp1, wp2, testPoint); Debug.Log(hasPassed); //Diplay TestAlgorithmsHelpMethods.DisplayArrow(wp1.ToVector3(), wp2.ToVector3(), 0.5f, Color.white); Gizmos.color = hasPassed ? Color.red : Color.black; Gizmos.DrawWireSphere(testPoint.ToVector3(), 0.5f); }
private void OnDrawGizmos() { if (triangulatedMesh != null) { TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(triangulatedMesh, seed); } //Display the obstacles if (constraints != null) { //DebugResults.DisplayConnectedPoints(obstacle, Color.black); } }
private void Arrow(MyVector2 pA, MyVector2 pB) { HashSet <Triangle2> triangles = _GenerateMesh.Arrow(pA, pB, lineWidth: 0.2f, arrowSize: 0.6f); if (triangles == null) { return; } Mesh mesh = _TransformBetweenDataStructures.Triangles2ToMesh(triangles, useCompressedMesh: false); //Display TestAlgorithmsHelpMethods.DisplayMesh(mesh, Color.white); }
//TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(displayMesh, seed); //Is adding memory each time we run it in playmode, which could maybe //have been solved by destroying the meshes we create each update??? //But DrawMesh is similar private void OnDrawGizmos() { if (triangleMeshes != null) { foreach (Mesh m in triangleMeshes) { TestAlgorithmsHelpMethods.DisplayMeshEdges(m, Color.black); } Gizmos.color = Color.white; Gizmos.DrawWireSphere(activePoint.ToVector3(), 0.3f); } }
private void ConnectedLines(MyVector2 pA, MyVector2 pB, MyVector2 pC, MyVector2 pD) { List <MyVector2> lines = new List <MyVector2>(); lines.Add(pA); lines.Add(pB); lines.Add(pC); lines.Add(pD); HashSet <Triangle2> triangles = _GenerateMesh.ConnectedLineSegments(lines, 0.5f, isConnected: true); Mesh mesh = _TransformBetweenDataStructures.Triangles2ToMesh(triangles, useCompressedMesh: false); //Display TestAlgorithmsHelpMethods.DisplayMesh(mesh, Color.white); }
private void BezierQuadratic(MyVector3 posA, MyVector3 posB, MyVector3 handle) { //Store the interpolated values so we later can display them List <Vector3> interpolatedValues = new List <Vector3>(); //Loop between 0 and 1 in steps, where 1 step is minimum //So if steps is 5 then the line will be cut in 5 sections int steps = 10; float stepSize = 1f / (float)steps; float t = 0f; //+1 becuase wa also have to include the first point for (int i = 0; i < steps + 1; i++) { //Debug.Log(t); MyVector3 interpolatedValue = _Interpolation.BezierQuadratic(posA, posB, handle, t); interpolatedValues.Add(interpolatedValue.ToVector3()); t += stepSize; } //Display the curve DisplayInterpolatedValues(interpolatedValues, useRandomColor: true); //Display the start and end values and the handle points DisplayHandle(handle.ToVector3(), posA.ToVector3()); DisplayHandle(handle.ToVector3(), posB.ToVector3()); //Display other related data //Get the forwrd dir of the point at t and display it MyVector3 forwardDir = _Interpolation.BezierQuadraticForwardDir(posA, posB, handle, tSliderValue); MyVector3 slidePos = _Interpolation.BezierQuadratic(posA, posB, handle, tSliderValue); TestAlgorithmsHelpMethods.DisplayArrow(slidePos.ToVector3(), (slidePos + forwardDir * 2f).ToVector3(), 0.2f, Color.blue); Gizmos.color = Color.red; Gizmos.DrawWireSphere(slidePos.ToVector3(), 0.15f); }