private int createSubtree(int sides, int steps, Mobius root, CoinObject parent) { int count = 0; Mobius mob = new Mobius(root); mob.compose(new Mobius(0, Math.Cos(Math.PI / sides), false)); CoinObject co = createCoin(mob.apply(new Vector3(0, 1, 0), true)); co.setTree(parent, sides - 1); if (parent == null) { co = null; count++; } steps--; if (steps <= 0) { if (parent != null) { co.activate(); } return(count); } mob.compose(new Mobius(Math.PI)); for (int i = 0; i < sides - 1; i++) { mob.compose(new Mobius(Mathf.PI * 2 / sides)); count += createSubtree(sides, steps, mob, co); } return(count); }
private int createSubtree(int sides, int steps, CoinObject parent) { int count = 0; int sign = (steps % 2) * 2 - 1; ptr.Translate(new Vector3(sign * dist * (5f / 13), 0, dist * (12f / 13))); CoinObject co = createCoin(ptr.position); co.setTree(parent, 1); if (parent == null) { co = null; count++; } ptr.Translate(new Vector3(-sign * dist * (5f / 13), 0, dist * (12f / 13))); CoinObject co2 = createCoin(ptr.position); co2.setTree(co, sides - 1); if (co == null) { co2 = null; count++; } steps--; if (steps <= 0) { if (co2 != null) { co2.activate(); } ptr.Translate(new Vector3(0, 0, -2 * dist * (12f / 13))); return(count); } /*ptr.Rotate(0, 180f * angleScale, 0); * for (int i = 0; i < sides - 1; i++) { * ptr.Rotate(0, 360f / sides * angleScale, 0); * count += createSubtree(sides, steps, co); * } * for (int i = 0; i < sides - 1; i++) { * ptr.Rotate(0, -360f / sides * angleScale, 0); * } * ptr.Rotate(0, -180f * angleScale, 0);*/ ptr.Rotate(0, -45, 0); count += createSubtree(sides, steps, co2); ptr.Rotate(0, 90, 0); count += createSubtree(sides, steps, co2); ptr.Rotate(0, -45, 0); ptr.Translate(new Vector3(0, 0, -2 * dist * (12f / 13))); return(count); }