Skip to content

Commit

Permalink
cleaned up some confusion regarding what mass to use when calculating…
Browse files Browse the repository at this point in the history
… the planetary positions
  • Loading branch information
OlleMattsson committed Mar 21, 2024
1 parent 36f6594 commit 93fe825
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
21 changes: 11 additions & 10 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,23 @@ import { initUniverse, universeProperties } from "./universe";
import { initSolarSystem, solarSystem} from "./solarsystem";
import { drawPlanetToPlanetLine, shipLine, p2pPos } from "./drawPlanetToPlanetLine";
import shiftNPush from "./shiftNPush";
import {solarSystemProperties} from './solarsystem'


// GUI
const gui = new GUI();
const guiDomElement = gui.domElement;
guiDomElement.style.position = 'absolute';
guiDomElement.style.top = '0px';
guiDomElement.style.left = '0px';
guiDomElement.style.removeProperty('right');


// Scene setup
// Scene
const scene = new THREE.Scene();
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);


/*
CAMERA
*/
// Camera
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
Expand All @@ -35,13 +32,15 @@ const camera = new THREE.PerspectiveCamera(
camera.position.x = 10;
camera.position.y = 25;
camera.position.z = 30

// Controls
const controls = new OrbitControls(camera, renderer.domElement);
controls.target.set(0, 0, 0); // Set the look at point to the center of the star
controls.enableZoom = true;
controls.zoomSpeed = 1.0;
controls.update(); // Must be called after any manual changes to the camera's transform


// init assets & gui elements
initUniverse(gui, scene, renderer, camera)
initSolarSystem(gui, scene, renderer, camera)

Expand Down Expand Up @@ -166,8 +165,10 @@ function updatePlanetPositions(deltaTime) {

planets.forEach((p, i) => {

// Standard Gravitational parameter (mu)
const mu = universeProperties.G * p.mass
// Standard Gravitational parameter
// We only need the mass of the central body
// The mass of the satellite is negligable in comparison to the mass of the central body
const mu = universeProperties.G * solarSystemProperties.sunMass // mass of the central body (eg satellite orbiting a moon)

// Calculate the mean motion (n) - the rate at which the mean anomaly increases
planets[i].n = Math.sqrt(mu / Math.pow(p.a, 3));
Expand Down
5 changes: 3 additions & 2 deletions solarsystem.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as THREE from "three";
import { createPolarGrid } from "./polarGrid";

const solarSystemProperties = {
export const solarSystemProperties = {
rotateX: 10,
rotateY: 10,
rotateZ: 10,
showEquatorialGrid: false,
showPole: false,
poleLength: 25
poleLength: 25,
sunMass: 10000000
}

export const solarSystem = new THREE.Group();
Expand Down

1 comment on commit 93fe825

@OlleMattsson
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has the latest working "spaceship" logic with collision detection

Please sign in to comment.