msakuta / WebGL-Orbiter

A rocket orbit simulator powered by three.js (WebGL)
MIT License
34 stars 9 forks source link
javascript orbit-simulator webgl

WebGL-Orbiter

An orbit simulator for the solar system in real scale with Newtonian dynamics, which can be manipulated like amazing game Kerbal Space Program.

Try it now on your browser!

https://msakuta.github.io/WebGL-Orbiter/index.html

Screenshots

Controls

Autosave feature

The simulation state is automatically saved to your browser's localStorage. When you exit the application and load it again, you will continue from where you left off. If you want to reset state, choose "Earth orbit" from the scenarios.

User Interface

Overlays

Periapsis

Periapsis

This icon is shown on the periapsis of current orbit.

Apoapsis

Apoapsis

This icon is shown on the apoapsis of current orbit.

Navigation ball/Throttle bar

On the bottom of the screen is the navigation ball and throttle bar.

navball

Throttle bar

Navigation ball

The navigation ball on the right indicates the orientation of the vehicle in relation to currently orbiting body.

Pointing mouse cursor or holding touch on the navigation ball shows a set of arrows indicating rotation directions.

navball rotation

Pressing keyboard keys corresponding to the rotation direction or pressing the arrows by the mouse or finger on touch screen will rotate the rocket in the designated direction. Note that the rotation has inertia; the longer you hold pressing, the faster the spin will be and takes longer time to stop.

Prograde/retrograde icon

prograde retrograde

These icons on the navigation ball indicates which direction the rocket is going, in relation to the vehicle's orientation.

The left icon is called prograde, meaning the direction the vehicle is going. Accelerating in this direction will put more energy on the orbit and push it wider.

The right icon is retrograde, meaning the direction opposite to the vehicle is going. Accelerating in this direction will reduce the energy from the orbit and make it narrower.

Watermark

watermark

This icon indicates horizontal line in the vehicle's orientation. The navigation ball is oriented in a way that the watermark is fixed.

It is common to see this kind of instrument in actual aerospace vehicle. I guess this is useful for aerial vehicles, but not so much in space.

Simulation Speed Control

On top left corner of the screen is a widget for controlling the speed of the simulation, from real-time to a million times faster than reality.

Clicking on one of the green triangles sets the speed to that scale. Leftmost is slowest and it gets faster as you go right. Each triangle means 10 times faster than the previous one. You can also change the speed by '+' and '-' keys.

Note that you cannot turn or accelerate the vehicle unless you're in real-time scale.

You'll need it to travel distances between planets.

Scenarios

On top right corner of the screen is a little icon.

Clicking it will show a list of predefined scenarios.

Scenario selector

Clicking one of these items will teleport the rocket to specific location in the solar system.

Save State

On the 2nd from right top corner is an icon for saving simulation state.

Clicking it will show a list of saved states.

Saved states are like scenarios but you can create whenever and as many as you would like to.

You can either type a new save name or overwrite existing one by clicking on its name. You can delete a saved state by clicking on the trash can icon trashcan.

Load State

On the 3rd from right top corner is an icon for loading simulation state.

Clicking on it will show a list of saved states.

You can click on one of the items to load it. You can delete a saved state by clicking on the trash can icon trashcan.

Orbital Elements

Just below the Speed control is a little icon for toggling orbital elements display.

If you click on it, a little table shows up like below.

These are parameters that uniquely define the orbit, given an orbital plane as a reference frame. In this application, reference frame is ecliptic plane. If you're not familiar with orbital mechanics, Wikipedia is a good place to start learning.

Celestial Bodies

Below the Orbital Elements control is Celestial Bodies button.

If you click on it, a little table shows up like below.

Currently focused celestial body is highlighted. Clicking on a name of a body will make the focus move to that body.

Statistics

On the 4th from right top corner is an icon for statistics.

Clicking on it will toggle the display of statistics of the whole mission.

Settings

Just below the Statistics icon is an icon for toggling setting display.

Clicking on it will toggle the display of a panel for settings. Characters in parentheses indicate shortcut keys.

How to build

Use npm to build or debug the project.

  1. Install Node.js
  2. Run npm i
  3. Serve the page with npm run start
    1. and open http://localhost:8080 with a browser
    2. or use VSCode's Debugger for Chrome extension (msjsdiag.debugger-for-chrome) to debug the app
  4. or npm run build to make a static website in dist/ subdirectory.

Additional materials

Libraries

This project uses: