Skip to content

Commit 6e710df

Browse files
committed
Add Physics#updatePositions
1 parent 79beb0b commit 6e710df

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

js/modules/Physics.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
/*----- Imports --------------------------------------------------------------*/
88
import GameData from "./GameData.js";
9+
import Celestial from "./Celestial.js";
910

1011
/*----- Classes --------------------------------------------------------------*/
1112
/** @module Physics Manages the physics simulation. */
@@ -24,16 +25,19 @@ export default class Physics {
2425
/*----- Constants ----------------------------------------------------------*/
2526
/** @const {number} G Gravitational constant. */
2627
static G = 6.67e-11;
27-
/** @const {Object} scale Conversion rates for physics equations. */
28-
static scale = {
29-
/** @const {number} scale.space Space scale (meters per pixel). */
30-
space: 0.3e7,
31-
/** @const {number} scale.time Time scale (seconds per frame). */
32-
time: 0.5e3,
33-
};
28+
/** @const {number} timeScale Time scale (seconds per loop). */
29+
static timeScale = 0.5e3;
3430
/** @const {number} interval Interval time for physics loop. */
3531
static interval = 1e3 / 120;
3632

33+
/*----- Calculation Methods ------------------------------------------------*/
34+
updatePositions() {
35+
this.model.scene.forEach(
36+
/** @arg obj {Celestial} */
37+
(obj) => obj.position.add(obj.velocity.copy().scale(Physics.timeScale))
38+
);
39+
}
40+
3741
/*----- Running Methods ----------------------------------------------------*/
3842
/** Calculate physics on a set interval. */
3943
loop() {
@@ -48,5 +52,7 @@ export default class Physics {
4852
window.clearInterval(this._intervalId);
4953
}
5054
/** Calculate the physics for objects in the scene and apply to model. */
51-
step() {}
55+
step() {
56+
this.updatePositions();
57+
}
5258
}

0 commit comments

Comments
 (0)