BodyPlotter.cs - MitchOSully/Visualising-the-DFN-Dataset GitHub Wiki

Summary

The backbone of the operation. It takes care of several important things:

  • Reading data from CSV files.
  • Calculating and assigning values to planets and meteoroids.
  • Instantiating planets and meteoroids at beginning of game.
  • Recalculating the positions of all bodies every frame.
  • Updates the scene when the time is changed.
  • Resizing halos and orbit lines according to camera distance every frame.
  • Activates / Reactivates bodies and orbit lines when a button is pressed on the GUI system. This script should be assigned to an empty GameObject.

List of Functions

Public Global Variables
Private Global Variables

void start()
void update()
void makePlanets()
void makeMeteoroids()
void updatePlanets()
void updateMeteoroids()
void createLine(GameObject body, string type)
void updateTrail(GameObject body, string type)
void checkCollision(GameObject meteoroid)
void resize(GameObject body, string type)
float getDistanceY(GameObject body)
void skipToDay(float newJD)

GUI Functions:

void pauseGame()
void resumeGame()
void changeYear(float newJD)
void planetsON(bool isOn)
void planetsOFF(bool isOn)
void meteoroidsON(bool isOn)
void meteoroidsOFF(bool isOn)
void planetLinesFADE(bool isOn)
void planetLinesSOLID(bool isOn)
void planetLinesOFF(bool isOn)
void meteoroidLinesFADE(bool isOn)
void meteoroidLinesSOLID(bool isOn)
void meteoroidLinesOFF(bool isOn)
void planetScaleAUTO(bool isOn)
void planetScaleREAL(bool isOn)
void planetScaleCUSTOM(float inScale)
void sunScaleAUTO(bool isOn)
void sunScaleREAL(bool isOn)
void sunScaleCUSTOM(float inScale)
void meteorScaleAUTO(bool isOn)
void meteorScaleCUSTOM(float inScale)

Public global variables

Datehelper helper

Allows access to helper functions in DateHelper script.

ScreenMaster screenScript

Must be given to planets to display info.

GameObject sun

Reference to sun object (for scaling).

GameObject mercury, venus, earth, mars, jupiter, saturn, uranus, neptune

Planet prefabs. Used to instantiate each planet.

GameObject meteoroidPrefab

Meteoroid prefab. Used to instantiate every meteoroid.

string meteorFile

The name of the CSV file to read (without the '.csv').

float plotScale

The scale of the distances in the scene. One unit in plotScale equals one astronomical unit (AU).

bool showMeteorLines = true

If true, calculates the orbit lines of all celestial bodies. If false, skips the calculation and inhibits the user from turning them on. Use this to speed the program up if the dataset is too large.
Default is true.

double daysPerFrame = 1

Determines the speed of the program; specifically, the number of days elapsing per frame.
Default is 1.

bool paused = false

Tells program if the game is in a paused state. The time and positions will be updated if paused is false, and will not be updated if it is true.
Default is false.

bool movingCamera = false

Tells program if user is currently moving the camera (dragging or scrolling).
Note: This can possibly be removed

Private global variables

GameObject[] planets, meteoroids

Arrays of the planet and meteoroid GameObjects in the scene.

double totalDays

The number of days that the program will run for.

List<Dictionary<string, object>>[] elLists

An array of lists that will each be filled by the elements in the planet CSV files.
Each array element is a List of lines in a planet CSV file.
Each list entry is a Dictionary of elements in a line. The keys are the column names (specified in the first line of the file) and the entries are the values in that column on the given line.
Note: This may not need to be global

void start()

Sets the global variable totalDays.
Calls functions to create planets and meteoroids.

Params

None

Returns

None

Calls

Called By

void update()

Increments the daysElapsed variable.
Calls functions to update planets and meteoroids.

Params

None

Returns

None

Calls

Called By

void makePlanets()

Reads the CSV planet files and assigns values to the planet scripts.

Instantiates all planets in their initial positions along with their orbital lines.

Params

None

Returns

None

Calls

Called by

void makeMeteoroids()

Reads the CSV meteoroid file and assigns values to the meteoroid scripts.

Instantiates all meteoroids in their initial positions along with their orbital lines.

Params

None

Returns

None

Calls

Called By

void updatePlanets()

Puts planets and their trails in the positions corresponding to the current day.

Also resizes the planets' lines and halos according to the camera distance.

Params

None

Returns

None

Calls

Called By

void updateMeteoroids()

Puts meteoroids and their trails in the positions corresponding to the current day. Also must check if the current day is past the meteoroid's crash date.

Also resizes lines and halos.

Params

None

Returns

None

Calls

Called By

void createLine(GameObject body, string type)

In charge of calculating positions for the solid orbit line and the fade-away trail line of the imported body. It gives these positions to the solid orbit line (a child of the body) and the body's script.

Params

Name Type Description
body GameObject Reference to the planet or meteoroid that we are assigning orbit lines to.
type string Tells us if it's a planet or meteoroid. We get the appropriate component and values based off this.

Returns

None

Calls

Called By

void updateTrail(GameObject body, string type)

Gives the newest positions to the trail of the imported body.

Params

Name Type Description
body GameObject Reference to the planet or meteoroid that the orbit trail belongs to.
type string Tells us if it's a planet or meteoroid. We get the appropriate component based on this.

Returns

None

Calls

None

Called By

void checkCollision(GameObject meteoroid)

Checks if the current time is past the imported meteoroid's crash date. If it is, then it sets the position of the meteoroid to its crash position, deactivates its trail and changes its colour to red. If it isn't, it reactivates the trail and sets the colour to white.

Params

Name Type Description
meteoroid GameObject Reference to the meteoroid we're checking.

Returns

None

Calls

None

Called By

void resize(GameObject body, string type)

Alters the size of the halo, sphere-collider and orbit line of the imported body according to its distance from the camera.

Called every frame.

Params

Name Type Description
body GameObject Reference to the planet or meteoroid that we are resizing.
type string Tells us if it's a planet or meteoroid. We get the appropriate component according to this.

Returns

None

Calls

Called By

float getDistanceY(GameObject body)

Calculates the y-component of the distance between camera and body. The y-direction is perpendicular to the solar system plane.

Params

Name Type Description
body GameObject Reference to the body that we are calculating the distance to.

Returns

Name Type Description
yDist double The y-component of the distance between body and camera.

Calls

None

Called By

void skipToDay(float newJD)

Moves all planets and meteoroids to their positions according to newJD.

Called on the pause screen when the time is changed by a GUI element.

Params

Name Type Description
newJD float The new date in Julian Days (JD)

Returns

None

Calls

Called By

void pauseGame()

GUI Method

Sets the paused variable to true.

Params

None

Calls

None

Called By

  • The pause button at the top-middle of the screen.

void resumeGame()

GUI Method

Sets the paused variable to false.

Params

None

Calls

None

Called By

  • The play button at the top-middle of the screen.

void changeYear(float newJD)

GUI Method

If the game is paused, calls skipToDay with the new JD.

Params

Name Type Description
newJD float The new date in Julian Days.

Calls

Called By

  • The time-slider that spans the top of the screen.

void planetsON(bool isOn)

GUI Method

Makes all the planet GameObjects active (visible).

Called By

  • The 'Planets On' toggle in the 'Settings' panel.

void planetsOFF(bool isOn)

GUI Method

Makes all the planet GameObjects inactive (invisible).

Called By

  • The 'Planets Off' toggle in the 'Settings' panel.

void meteoroidsON(bool isOn)

GUI Method

Makes all the meteoroid GameObjects active.

Called By

  • The 'Meteoroids On' toggle in the 'Settings' panel.

void meteoroidsOFF(bool isOn)

GUI Method

Makes all the meteoroid GameObjects inactive.

Called By

  • The 'Meteoroids Off' toggle in the 'Settings' panel.

void planetLinesFADE(bool isOn)

GUI Method

If toggle is being switched on, activates all planets' fade orbit lines. If being switched off, deactivates them.

Called By

  • The 'Planet Lines Fade' toggle in 'Settings' panel.

void planetLinesSOLID(bool isOn)

GUI Method

If toggle is being switched on, activates all planets' solid orbit lines. If being switched off, deactivates them.

Called By

  • The 'Planet Lines Solid' Toggle in 'Settings' panel.

void planetLinesOFF(bool isOn)

GUI Method

Deactivates all planets' solid and fade orbit lines.

Called By

  • The 'Planet Lines Off' toggle in 'Settings' panel.

void meteoroidLinesFADE(bool isOn)

If toggle is being switched on, activates all meteoroids' fade orbit lines. If being switched off, deactivates them.

Called By

  • The 'Meteoroid Lines Fade' toggle in 'Settings' panel.

void meteoroidLinesSOLID(bool isOn)

GUI Method

If toggle is being switched on, activates all meteoroids' solid orbit lines. If being switched off, deactivates them.

Called By

  • The 'Meteoroid Lines Solid' toggle in 'Settings' panel.

void meteoroidLinesOFF(bool isOn)

GUI Method

Deactivates all meteoroids' solid and fade orbit lines.

Called By

  • The 'Meteoroid Lines Off' toggle in 'Settings' panel.

void planetScaleAUTO(bool isOn)

GUI Method

Sets the sizes of all planets to a predetermined size that is visually appealing.

Called By

  • The 'Planet Scale Auto' toggle in 'Settings' panel.

void planetScaleREAL(bool isOn)

GUI Method

Sets the sizes of all planets to a size that is accurate with respect to the distances between them (this renders them invisible since they are smaller than a single pixel).

Called By

  • The 'Planet Scale Real' toggle in 'Settings' panel.

void planetScaleCUSTOM(float inScale)

GUI Method

Sets the sizes of all planets to their AUTO sizes multiplied by inScale.

Called By

  • The slider bar under 'Planet Scale' in 'Settings' panel.

void sunScaleAUTO(bool isOn)

GUI Method

Sets the size of the sun to a predetermined size that is visually appealing.

Called By

  • The 'Sun Scale Auto' toggle in 'Settings' panel.

void sunScaleREAL(bool isOn)

GUI Method

Sets the size of the sun to a size that is accurate with respect to the distances between bodies.

Called By

  • The 'Sun Scale Real' toggle in 'Settings' panel.

void sunScaleCUSTOM(float inScale)

GUI Method

Sets the size of the sun to its AUTO size multiplied by inScale.

Called By

  • The slider bar under 'Sun Scale' in 'Settings' panel.

void meteorScaleAUTO(bool isOn)

GUI Method

Sets the sizes of all meteoroid halos to a predetermined size that is visually appealing.

Called By

  • The 'Meteoroid Scale Auto' toggle in 'Settings' panel.

void meteorScaleCUSTOM(float inScale)

GUI Method

Sets the sizes of all meteoroid halos to the AUTO size multiplied by inScale.

Called By

  • The slider bar under 'Meteoroid Scale' in 'Settings' panel.