| 100 | |
| 101 | }) |
| 102 | } |
| 103 | |
| 104 | fun update(delta: Float) { |
| 105 | var timeStep = delta / 1000f |
| 106 | if (timeStep > 0.2) { |
| 107 | System.err.println(" warning: large timestep :" + timeStep) |
| 108 | timeStep = 0.2f |
| 109 | } else if (timeStep < 1e-8) { |
| 110 | timeStep = 1 / 30f; |
| 111 | } |
| 112 | |
| 113 | val velocityIterations = 6 |
| 114 | val positionIterations = 3 |
| 115 | |
| 116 | world.step(timeStep, velocityIterations, positionIterations) |
| 117 | |
| 118 | allPhysicsLines.forEach { |
| 119 | it.physicsToFLine() |
| 120 | } |
| 121 | |
| 122 | contacts.retainAll { |
| 123 | if (it.tick == TICK) { |
| 124 | fire<List<field.linalg.Vec2>>(it.A, onContactStart, it.points) |
| 125 | fire<List<field.linalg.Vec2>>(it.B, onContactStart, it.points) |
| 126 | } |
| 127 | if (it.terminated != -1L) { |
| 128 | fire(it.A, onContactEnd) |
| 129 | fire(it.B, onContactEnd) |
| 130 | false |
| 131 | } |
| 132 | true |
| 133 | } |
| 134 | TICK++ |
| 135 | } |
| 136 | |