Skip to content

Commit c143534

Browse files
committed
feat: add interaction showcase
1 parent aa93d3f commit c143534

29 files changed

Lines changed: 2262 additions & 594 deletions

build/spacekit.cjs.js

Lines changed: 182 additions & 182 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/spacekit.cjs.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/spacekit.esm.js

Lines changed: 181 additions & 181 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/spacekit.esm.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/spacekit.js

Lines changed: 182 additions & 182 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/spacekit.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/typescript/Camera.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ export default class Camera {
1111
private context;
1212
private camera;
1313
private cameraControls;
14-
private followMesh?;
14+
private followTarget?;
1515
/**
1616
* @param {Object} context The simulation context
1717
*/
1818
constructor(context: SimulationContext);
1919
/**
20-
* Move the camera to follow a SpaceObject as it moves. Currently only works
21-
* for non-particlesystems.
20+
* Move the camera to follow a SpaceObject as it moves.
2221
* @param {SpaceObject} obj SpaceObject to follow.
2322
* @param {Array.<Number>} position Position of the camera with respect to
2423
* the object.

build/typescript/Camera.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ var Camera = /** @class */ (function () {
3737
function Camera(context) {
3838
// TODO(ian): Accept either context or container
3939
this.context = context;
40-
// Optional mesh that we are following.
41-
this.followMesh = undefined;
40+
// Optional object that we are following.
41+
this.followTarget = undefined;
4242
var containerWidth = this.context.container.width;
4343
var containerHeight = this.context.container.height;
4444
var camera = new THREE.PerspectiveCamera(50, containerWidth / containerHeight, (0, Scale_1.rescaleNumber)(0.00001), (0, Scale_1.rescaleNumber)(2000));
@@ -67,35 +67,32 @@ var Camera = /** @class */ (function () {
6767
this.cameraControls = controls;
6868
}
6969
/**
70-
* Move the camera to follow a SpaceObject as it moves. Currently only works
71-
* for non-particlesystems.
70+
* Move the camera to follow a SpaceObject as it moves.
7271
* @param {SpaceObject} obj SpaceObject to follow.
7372
* @param {Array.<Number>} position Position of the camera with respect to
7473
* the object.
7574
*/
7675
Camera.prototype.followObject = function (obj, position) {
77-
var followMesh = obj.get3jsObjects()[0];
7876
this.cameraControls.enablePan = false;
7977
var rescaled = (0, Scale_1.rescaleArray)(position);
8078
this.camera.position.add(new THREE.Vector3(rescaled[0], rescaled[1], rescaled[2]));
8179
this.cameraControls.update();
82-
this.followMesh = followMesh;
80+
this.followTarget = obj;
8381
};
8482
/**
8583
* Stop the camera from following the object.
8684
*/
8785
Camera.prototype.stopFollowingObject = function () {
88-
if (this.followMesh) {
89-
this.followMesh.remove(this.camera);
90-
this.followMesh = undefined;
86+
if (this.followTarget) {
87+
this.followTarget = undefined;
9188
this.cameraControls.enablePan = true;
9289
}
9390
};
9491
/**
9592
* @returns {boolean} True if camera is following object.
9693
*/
9794
Camera.prototype.isFollowingObject = function () {
98-
return !!this.followMesh;
95+
return !!this.followTarget;
9996
};
10097
/**
10198
* @returns {THREE.PerspectiveCamera} The THREE.js camera object.
@@ -114,7 +111,8 @@ var Camera = /** @class */ (function () {
114111
*/
115112
Camera.prototype.update = function () {
116113
if (this.isFollowingObject()) {
117-
var newpos = this.followMesh.position.clone();
114+
var _a = this.followTarget.getPosition(this.context.simulation.getJd()), x = _a[0], y = _a[1], z = _a[2];
115+
var newpos = new THREE.Vector3(x, y, z);
118116
var offset = newpos.clone().sub(this.cameraControls.target);
119117
this.camera.position.add(offset);
120118
this.cameraControls.target.set(newpos.x, newpos.y, newpos.z);

build/typescript/Coordinates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var Coordinates = /** @class */ (function () {
4242
Coordinates.getNutationAndObliquity = function (jd) {
4343
if (jd === void 0) { jd = J2000; }
4444
var t = (jd - J2000) / 36525;
45-
var omega = Units_1["default"].rad(125.04452 - 1934.136261 * t + 0.0020708 * t * t + (t * t + t) / 450000);
45+
var omega = Units_1["default"].rad(125.04452 - 1934.136261 * t + 0.0020708 * t * t + (t * t * t) / 450000);
4646
var Lsun = Units_1["default"].rad(280.4665 + 36000.7698 * t);
4747
var Lmoon = Units_1["default"].rad(218.3165 + 481267.8813 * t);
4848
var nutation = (-17.2 / 3600) * Math.sin(omega) -

build/typescript/Ephem.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,16 @@ var Ephem = /** @class */ (function () {
217217
var n = this.getUnsafe('n');
218218
var GM = this.getUnsafe('GM');
219219
var period = this.getUnsafe('period');
220-
if (!isDef(period) && isDef(a)) {
221-
if (!isDef(GM)) {
222-
throw new Error('Expected ephemeris attribute GM to be set');
223-
}
224-
period =
225-
(2 * Math.PI * Math.sqrt((aMeters * aMeters * aMeters) / GM)) /
226-
SECONDS_IN_DAY;
227-
this.set('period', period);
228-
}
229220
if (e < 1.0) {
221+
if (!isDef(period) && isDef(a)) {
222+
if (!isDef(GM)) {
223+
throw new Error('Expected ephemeris attribute GM to be set');
224+
}
225+
period =
226+
(2 * Math.PI * Math.sqrt((aMeters * aMeters * aMeters) / GM)) /
227+
SECONDS_IN_DAY;
228+
this.set('period', period);
229+
}
230230
// Only work with mean motion for elliptical orbits.
231231
if (isDef(period) && !isDef(n)) {
232232
// Set radians

0 commit comments

Comments
 (0)