void RunBallPivot(float[] passes) { startTime = Time.realtimeSinceStartup; f = new Front(); ballRadius = passes[0]; pivoter = new Pivoter(cloud, ballRadius); Debug.Log("Pivoter initialized in: " + (Time.realtimeSinceStartup - startTime) + "s"); while (true) { Edge e; while ((e = f.GetActiveEdge()) != null) { Tuple <int, Triangle> t = pivoter.Pivot(e); if (t != null && (!pivoter.IsUsed(t.Item1) || f.InFront(t.Item1))) { preMesh.Add(t.Item2); f.JoinAndGlue(t, pivoter); } else { f.SetInactive(e); } } Triangle tri; if ((tri = pivoter.FindSeed()) != null) { preMesh.Add(tri); f.AddEdges(tri); } else { pivoter.FindSeed(); break; } } }
bool StepBallPivot() { bool updated = false; Edge e; int i = 0; if (pivotingInAction) { if (currentPivotStepNum < pivotAnimationSteps) { currentPivotStepNum++; if (currentPivotStepNum == pivotAnimationSteps) { pivotingInAction = false; currentPivotStepNum = 0; preMesh.Add(toAdd); updated = true; ball.transform.position = newPos; } else { //ball.transform.position = oldPos + (newPos - oldPos) * (1.0f / pivotAnimationSteps) * currentPivotStepNum; ball.transform.RotateAround(pivotEdge.MiddlePoint, (pivotEdge.Second.Item1 - pivotEdge.MiddlePoint).normalized, Mathf.Rad2Deg * pivotedAngle); } } } else { for (i = 0; i < pivotsPerUpdate && (e = f.GetActiveEdge()) != null; i++) { Tuple <int, Triangle> t = pivoter.Pivot(e); if (t != null && (!pivoter.IsUsed(t.Item1) || f.InFront(t.Item1))) { if (pivotsPerUpdate == 1) { pivotingInAction = true; toAdd = t.Item2; oldPos = e.BallCenter; newPos = t.Item2.BallCenter; ball.transform.position = oldPos; //pivotedAngle = (pivoter.PivotedAngle) * (1.0f / pivotAnimationSteps); Vector3 a = (oldPos - e.MiddlePoint); Vector3 b = newPos - e.MiddlePoint; pivotedAngle = Mathf.Acos(a.Dot(b) / (a.magnitude * b.magnitude)) * (1.0f / pivotAnimationSteps); pivotEdge = e; } else { preMesh.Add(t.Item2); updated = true; } f.JoinAndGlue(t, pivoter); } else { f.SetInactive(e); } } if (i == 0) { Triangle tri; if ((tri = pivoter.FindSeed()) != null) { preMesh.Add(tri); updated = true; ball.transform.position = tri.BallCenter; f.AddEdges(tri); } else { running = false; } } } return(updated); }