AstronomicalObject Class
AstronomicalObject is a class that represents Planets, Moons, the Sun, Galaxy, and Saturn's Rings.
Constructor
AstronomicalObject
-
config
Parameters:
-
configObjectThe config object.
-
nameStringName of the Astronomical Body. Useful for debugging, but also used in generating the instructions for the keyboard shortcuts.
-
originArrayX, Y, Z co-ordinates of the origin of the body in space.
-
orbitDistanceInt(in miles) from whatever it is orbiting. This is then automatically reduced for presen tation purposes.
-
orbitalPeriodFloatNumber of days to make a full orbit.
-
spinPeriodFloatNumber of days to rotate fully on its axis.
-
radiusInt(in miles). This is then automatically increased for presentation purposes.
-
axisFloatRotational axis (in degrees).
-
textureStringUrl pointing to the texture image to be mapped to the object.
-
specularTextureStringUrl pointing to the specular map to be mapped to the object.
-
shortcutKeyStringThe key that when pressed should make the camera snap to the object.
-
spinsBooleanDetermines whether or not the object should spin on its axis.
-
spinsClockwiseBooleanDefaults to false. Determines spin direction.
-
useLightingBooleanDetermines whether or not the object should be affected by Phong shading.
-
sphericalBooleanDetermines 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:
-
spinAmountFloatSpin 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:
-
millisecondsPerDayFloatThe number of milliseconds that represent a day - this is integral in some of the calculations of the animation.
-
millisecondsSinceLastFrameFloatThe number of milliseconds since the last frame was rendered.
beforeOrbit
-
translationMatrix
Rotation to perform before orbit.
Parameters:
-
translationMatrixObjectglMatrix 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:
-
attributeIntA property of the current object, e.g. orbitalPeriod
-
millisecondsSinceLastFrameFloatNumber of milliseconds since last frame.
-
millisecondsPerDayFloatThe 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:
-
celsiusIntValue in degrees.
Returns:
Converted value in radians.
draw
-
projectionMatrix
Draws the object, relative to a projection matrix handles by the Camera object.
Parameters:
-
projectionMatrixArrayglMatrix object (mat4) representing projection of the camera.
getBoolean
-
attribute -
defaultValue
Converts the given value into a boolean.
Parameters:
-
attributeObjectValue to convert (typically a boolean or null)
-
defaultValueBooleanValue to default to if one is not specified.
Returns:
The boolean value.
handleLoadedTexture
-
texture -
imageProperty
Handle the image texture once it has downloaded.
Parameters:
-
textureObjectA WebGL TEXTURE_2D object.
-
imagePropertyStringThe property to set texture to on this object.
initMatrix
()
Initialises the model view matrix.
initTexture
-
imageSrc -
imageProperty
Initialises a texture for the object.
Parameters:
-
imageSrcStringURL pointing to the texture image.
-
imagePropertyStringThe 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:
-
configObjectThe config object.
setAxis
-
axis
Sets the axis of the object.
Parameters:
-
axisIntAxis (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:
-
originArrayThree-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:
-
projectionMatrixArrayglMatrix object (mat4) representing projection of the camera.
setupTexture
()
Sets up the texture.
updateAttributes
-
orbitAmount -
spinAmount
Updates the object's attributes concerning angles.
Parameters:
-
orbitAmountFloatLast orbit amount travelled
-
spinAmountFloatLast spin amount spun
Properties
isReady
Boolean
False until all assets for the Astronomical Object have been downloaded (i.e. the texture maps).
Default: false
