AstronomicalObject Class
AstronomicalObject is a class that represents Planets, Moons, the Sun, Galaxy, and Saturn's Rings.
Constructor
AstronomicalObject
-
config
Parameters:
-
config
ObjectThe config object.
-
name
StringName of the Astronomical Body. Useful for debugging, but also used in generating the instructions for the keyboard shortcuts.
-
origin
ArrayX, 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
FloatNumber of days to make a full orbit.
-
spinPeriod
FloatNumber of days to rotate fully on its axis.
-
radius
Int(in miles). This is then automatically increased for presentation purposes.
-
axis
FloatRotational axis (in degrees).
-
texture
StringUrl pointing to the texture image to be mapped to the object.
-
specularTexture
StringUrl pointing to the specular map to be mapped to the object.
-
shortcutKey
StringThe key that when pressed should make the camera snap to the object.
-
spins
BooleanDetermines whether or not the object should spin on its axis.
-
spinsClockwise
BooleanDefaults to false. Determines spin direction.
-
useLighting
BooleanDetermines whether or not the object should be affected by Phong shading.
-
spherical
BooleanDetermines which buffers to initialise and draw the object with (cuboidal or spherical).
-
Item Index
Methods
Properties
Methods
afterOrbit
-
spinAmount
Rotation to perform after orbit.
Parameters:
-
spinAmount
FloatSpin 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
FloatThe number of milliseconds that represent a day - this is integral in some of the calculations of the animation.
-
millisecondsSinceLastFrame
FloatThe number of milliseconds since the last frame was rendered.
beforeOrbit
-
translationMatrix
Rotation to perform before orbit.
Parameters:
-
translationMatrix
ObjectglMatrix to multiply by modelViewMatrix
calculatePortionOf
-
attribute
-
millisecondsSinceLastFrame
-
millisecondsPerDay
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
IntA property of the current object, e.g. orbitalPeriod
-
millisecondsSinceLastFrame
FloatNumber of milliseconds since last frame.
-
millisecondsPerDay
FloatThe number of milliseconds that represent a day - this is integral in some of the calculations of the animation.
Returns:
Angle (in radians) that should be moved by.
degreesToRadians
-
celsius
Converts degrees to radians.
Parameters:
-
celsius
IntValue in degrees.
Returns:
Converted value in radians.
draw
-
projectionMatrix
Draws the object, relative to a projection matrix handles by the Camera object.
Parameters:
-
projectionMatrix
ArrayglMatrix object (mat4) representing projection of the camera.
getBoolean
-
attribute
-
defaultValue
Converts the given value into a boolean.
Parameters:
-
attribute
ObjectValue to convert (typically a boolean or null)
-
defaultValue
BooleanValue to default to if one is not specified.
Returns:
The boolean value.
handleLoadedTexture
-
texture
-
imageProperty
Handle the image texture once it has downloaded.
Parameters:
-
texture
ObjectA WebGL TEXTURE_2D object.
-
imageProperty
StringThe 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
StringURL pointing to the texture image.
-
imageProperty
StringThe 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
ObjectThe config object.
setAxis
-
axis
Sets the axis of the object.
Parameters:
-
axis
IntAxis (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
ArrayThree-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
ArrayglMatrix object (mat4) representing projection of the camera.
setupTexture
()
Sets up the texture.
updateAttributes
-
orbitAmount
-
spinAmount
Updates the object's attributes concerning angles.
Parameters:
-
orbitAmount
FloatLast orbit amount travelled
-
spinAmount
FloatLast spin amount spun
Properties
isReady
Boolean
False until all assets for the Astronomical Object have been downloaded (i.e. the texture maps).
Default: false