| 45 | } |
| 46 | |
| 47 | public void Step() |
| 48 | { |
| 49 | Default.MeshSphere.Draw(Default.MaterialUnlit, Matrix.TS(center, 0.06f), Color.HSV(0.16f, 0.4f, 0.9f)); |
| 50 | for (int i = 0; i < bodies.Length; i++) { |
| 51 | Vec3 force = (bodies[i].position-center) * -200; |
| 52 | |
| 53 | // Make hands have mass |
| 54 | for (int h = 0; h < (int)Handed.Max; h++) |
| 55 | { |
| 56 | Hand hand = Input.Hand((Handed)h); |
| 57 | if (!hand.IsTracked) continue; |
| 58 | |
| 59 | Vec3 dir = hand.palm.position - bodies[i].position; |
| 60 | force += dir.Normalized * 300 * hand.gripActivation; |
| 61 | } |
| 62 | |
| 63 | for (int t = 0; t < bodies.Length; t++) { |
| 64 | if (i == t) continue; |
| 65 | |
| 66 | Vec3 dir = bodies[t].position - bodies[i].position; |
| 67 | Vec3 currForce = dir.Normalized * ((dir.MagnitudeSq * 50) / bodies[i].mass); |
| 68 | force += currForce; |
| 69 | } |
| 70 | |
| 71 | if (force.MagnitudeSq > 1) |
| 72 | force.Normalize(); |
| 73 | bodies[i].force = force; |
| 74 | } |
| 75 | for (int i = 0; i < bodies.Length; i++) |
| 76 | { |
| 77 | bodies[i].velocity += bodies[i].force * (Time.Stepf/bodies[i].mass); |
| 78 | if (bodies[i].velocity.MagnitudeSq > 1) |
| 79 | bodies[i].velocity.Normalize(); |
| 80 | bodies[i].position += bodies[i].velocity * Time.Stepf; |
| 81 | |
| 82 | Color col = bodies[i].color * Math.Min(0.5f, (bodies[i].position-center).MagnitudeSq/0.5f); |
| 83 | col.a = 1; |
| 84 | if (trailId == i) |
| 85 | { |
| 86 | bodies[i].trail.Add(new LinePoint(bodies[i].position, col, 0.02f)); |
| 87 | if (bodies[i].trail.Count > 1000) bodies[i].trail.RemoveAt(0); |
| 88 | } else if (bodies[i].trail.Count > 0) |
| 89 | { |
| 90 | bodies[i].trail[bodies[i].trail.Count-1] = new LinePoint(bodies[i].position, col, 0.02f); |
| 91 | } |
| 92 | Default.MeshSphere.Draw(Default.Material, Matrix.TS(bodies[i].position, 0.03f * bodies[i].mass), col); |
| 93 | Lines.Add(bodies[i].trail.ToArray()); |
| 94 | } |
| 95 | trailId = (trailId + 1) % bodies.Length; |
| 96 | |
| 97 | Demo.ShowSummary(title, description, new Bounds(V.XYZ(0,0,0.5f), V.XYZ(.8f, .8f, 0.8f))); |
| 98 | } |
| 99 | } |