@@ -65,6 +65,41 @@ class Echo {
6565
6666 return listener ;
6767 }
68+ /**
69+ * Steps a `World` forward.
70+ * @param world
71+ * @param dt
72+ */
73+ public static function step (world : World , dt : Float ) {
74+ // Save World State to History
75+ if (world .history != null ) world .history .add ([
76+ for (b in world .members ) {
77+ id : b .id ,
78+ x : b .x ,
79+ y : b .y ,
80+ rotation : b .rotation ,
81+ velocity : b .velocity ,
82+ acceleration : b .acceleration ,
83+ rotational_velocity : b .rotational_velocity
84+ }
85+ ]);
86+
87+ // Apply Gravity
88+ world .for_each (member -> {
89+ member .acceleration .x + = world .gravity .x * member .gravity_scale ;
90+ member .acceleration .y + = world .gravity .y * member .gravity_scale ;
91+ });
92+ // Step the World incrementally based on the number of iterations
93+ var fdt = dt / world .iterations ;
94+ for (i in 0 ... world .iterations ) {
95+ Physics .step (world , fdt );
96+ Collisions .query (world );
97+ Physics .separate (world );
98+ Collisions .notify (world );
99+ }
100+ // Reset acceleration
101+ world .for_each (member -> member .acceleration .set (0 , 0 ));
102+ }
68103 /**
69104 * Casts a Line Created from the supplied floats, returning the Intersection with the closest Body.
70105 * @param x The X position to start the cast.
@@ -198,41 +233,6 @@ class Echo {
198233
199234 return intersections ;
200235 }
201- /**
202- * Steps a `World` forward.
203- * @param world
204- * @param dt
205- */
206- public static function step (world : World , dt : Float ) {
207- // Save World State to History
208- if (world .history != null ) world .history .add ([
209- for (b in world .members ) {
210- id : b .id ,
211- x : b .x ,
212- y : b .y ,
213- rotation : b .rotation ,
214- velocity : b .velocity ,
215- acceleration : b .acceleration ,
216- rotational_velocity : b .rotational_velocity
217- }
218- ]);
219-
220- // Apply Gravity
221- world .for_each (member -> {
222- member .acceleration .x + = world .gravity .x * member .gravity_scale ;
223- member .acceleration .y + = world .gravity .y * member .gravity_scale ;
224- });
225- // Step the World incrementally based on the number of iterations
226- var fdt = dt / world .iterations ;
227- for (i in 0 ... world .iterations ) {
228- Physics .step (world , fdt );
229- Collisions .query (world );
230- Physics .separate (world );
231- Collisions .notify (world );
232- }
233- // Reset acceleration
234- world .for_each (member -> member .acceleration .set (0 , 0 ));
235- }
236236 /**
237237 * Undo the World's last step
238238 * @param world
0 commit comments