1 /*
  2   Copyright (c) 2008 Seneca College
  3   Licenced under the MIT License (http://www.c3dl.org/index.php/mit-license/)
  4 */
  5 
  6 
  7 /**
  8 	@class
  9 	
 10 	A DirectionalLight inherits from Light.  It does not have a position 
 11 	such as a PositionalLight. It only has a direction. Think if a 
 12 	directional light as being infinately far from the scene, but its light
 13 	rays travelling in the direction specified. Since it has no position, 
 14 	it will always light a side of an object.<br />
 15 	<br />
 16 	When specifying the direction, you are specifying where the light rays are going towards.<br />
 17 	<br />
 18 	A DirectionalLight is useful when a scene contains an 2D array of objects aligned in a square. If
 19 	all the objects are to be light the same way, a directional light would be a good choice to add
 20 	to the scene.
 21 	@augments c3dl.Light
 22 */
 23 c3dl.DirectionalLight = function()
 24 {	
 25 	// opengl will interpret the light as directional if
 26 	// the last value specified for POSITION is 0 and
 27 	// positional if the last value for POSITION is 1.
 28 	// We use a 'direction' variable, but when given the light direction needs
 29 	// to be specified, we just pass in our this.direction into the POSITION parameter.
 30 	this.direction = [0,0,1];
 31 	this.type = c3dl.DIRECTIONAL_LIGHT;
 32 
 33 	/**
 34 		Get the direction of this light. The default direction of the light is [0,0,1].
 35 
 36 		@returns {Array} the direction of the light which will be unit length.
 37 	*/
 38 	this.getDirection = function()
 39 	{
 40 		return [this.direction[0],this.direction[1],this.direction[2]]
 41 	}
 42 
 43 	/**
 44 		Set the direction of this light. The 'dir' argument will be scaled to
 45 		a unit vector before being assigned if not already unit length.
 46 		
 47 		@param {Array} dir Will be scaled to a unit vector before being assigned
 48 		if not already unit length.
 49 	*/
 50 	this.setDirection = function(dir)
 51 	{
 52 		if(c3dl.isValidVector(dir))
 53 		{
 54 			this.direction = c3dl.normalizeVector(dir);
 55 		}
 56 	}
 57 }
 58 
 59 c3dl.DirectionalLight.prototype = new c3dl.Light;
 60