API Docs for: 0.1.0
Show:

AstronomicalObject Class

AstronomicalObject is a class that represents Planets, Moons, the Sun, Galaxy, and Saturn's Rings.

Constructor

AstronomicalObject

(
  • config
)

Parameters:

  • config Object

    The config object.

    • name String

      Name of the Astronomical Body. Useful for debugging, but also used in generating the instructions for the keyboard shortcuts.

    • origin Array

      X, Y, Z co-ordinates of the origin of the body in space.

    • orbitDistance Int

      (in miles) from whatever it is orbiting. This is then automatically reduced for presen tation purposes.

    • orbitalPeriod Float

      Number of days to make a full orbit.

    • spinPeriod Float

      Number of days to rotate fully on its axis.

    • radius Int

      (in miles). This is then automatically increased for presentation purposes.

    • axis Float

      Rotational axis (in degrees).

    • texture String

      Url pointing to the texture image to be mapped to the object.

    • specularTexture String

      Url pointing to the specular map to be mapped to the object.

    • shortcutKey String

      The key that when pressed should make the camera snap to the object.

    • spins Boolean

      Determines whether or not the object should spin on its axis.

    • spinsClockwise Boolean

      Defaults to false. Determines spin direction.

    • useLighting Boolean

      Determines whether or not the object should be affected by Phong shading.

    • spherical Boolean

      Determines which buffers to initialise and draw the object with (cuboidal or spherical).

Methods

afterOrbit

(
  • spinAmount
)

Rotation to perform after orbit.

Parameters:

  • spinAmount Float

    Spin amount to take into account.

animate

(
  • millisecondsPerDay
  • millisecondsSinceLastFrame
)

Performs the calculations necessary for the object to orbit and spin on its axis, if applicable.

Parameters:

  • millisecondsPerDay Float

    The number of milliseconds that represent a day - this is integral in some of the calculations of the animation.

  • millisecondsSinceLastFrame Float

    The number of milliseconds since the last frame was rendered.

beforeOrbit

(
  • translationMatrix
)

Rotation to perform before orbit.

Parameters:

  • translationMatrix Object

    glMatrix to multiply by modelViewMatrix

calculatePortionOf

(
  • attribute
  • millisecondsSinceLastFrame
  • millisecondsPerDay
)
Float

Calculates the portion of a given attribute, based on the number of milliseconds since the last frame and the number of milliseconds which represents a day.

Parameters:

  • attribute Int

    A property of the current object, e.g. orbitalPeriod

  • millisecondsSinceLastFrame Float

    Number of milliseconds since last frame.

  • millisecondsPerDay Float

    The number of milliseconds that represent a day - this is integral in some of the calculations of the animation.

Returns:

Float:

Angle (in radians) that should be moved by.

degreesToRadians

(
  • celsius
)
Float

Converts degrees to radians.

Parameters:

  • celsius Int

    Value in degrees.

Returns:

Float:

Converted value in radians.

draw

(
  • projectionMatrix
)

Draws the object, relative to a projection matrix handles by the Camera object.

Parameters:

  • projectionMatrix Array

    glMatrix object (mat4) representing projection of the camera.

getBoolean

(
  • attribute
  • defaultValue
)
Boolean

Converts the given value into a boolean.

Parameters:

  • attribute Object

    Value to convert (typically a boolean or null)

  • defaultValue Boolean

    Value to default to if one is not specified.

Returns:

Boolean:

The boolean value.

handleLoadedTexture

(
  • texture
  • imageProperty
)

Handle the image texture once it has downloaded.

Parameters:

  • texture Object

    A WebGL TEXTURE_2D object.

  • imageProperty String

    The property to set texture to on this object.

initMatrix

()

Initialises the model view matrix.

initTexture

(
  • imageSrc
  • imageProperty
)

Initialises a texture for the object.

Parameters:

  • imageSrc String

    URL pointing to the texture image.

  • imageProperty String

    The property to set texture to on this object.

initTextures

()

Initialises the textures for the object.

normalise

()

Adjusts the scales and radiuses for aesthetic reasons.

prepareSpecialCases

()

Executes code specific to individual entities, e.g. the Sun/Saturn's Rings. In future, this could be extracted out into a subclass.

setAttributes

(
  • config
)

Sets the attributes of the object instance based on the passed config object.

Parameters:

  • config Object

    The config object.

setAxis

(
  • axis
)

Sets the axis of the object.

Parameters:

  • axis Int

    Axis (in degrees) that the object rotates on.

setOrigin

(
  • origin
)

Sets the origin of the object, using the passed value if there is one, or calculating based on the orbited object if there isn't.

Parameters:

  • origin Array

    Three-value array representing the origin, or null.

setRandomStartingOrbit

()

Called on initialisation - this moves the object to a position in its orbit, randomised to prevent all objects starting off in a long straight line.

setupLighting

(
  • projectionMatrix
)

Initialises the shader variables for lighting.

Parameters:

  • projectionMatrix Array

    glMatrix object (mat4) representing projection of the camera.

setupTexture

()

Sets up the texture.

updateAttributes

(
  • orbitAmount
  • spinAmount
)

Updates the object's attributes concerning angles.

Parameters:

  • orbitAmount Float

    Last orbit amount travelled

  • spinAmount Float

    Last spin amount spun

Properties

isReady

Boolean

False until all assets for the Astronomical Object have been downloaded (i.e. the texture maps).

Default: false