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 	A PositionalLight inherits from Light. Unlike DirectionalLight,
 10 	a PositionalLight can have an attenuation factor.
 11 	@see c3dl.Light
 12 	@augments c3dl.Light
 13 */
 14 c3dl.PositionalLight = function()
 15 {
 16 	this.position = [0,0,0];
 17 	
 18 	// use opengl default attenuation factors.
 19 	// element 0 is for constant attenuation
 20 	// element 1 is for linear attenuation
 21 	// element 2 is for quadratic attenuation
 22 	this.attenuation = [1,0,0];
 23 	
 24 	// need to override the type the abstract class set.
 25 	this.type = c3dl.POSITIONAL_LIGHT;
 26 
 27 	/**	 
 28 		Get the attenuation factors of this light. This is an array of three values
 29 		which include constant attenuation, linear attenuation and quadratic attenuation.
 30 
 31 		@returns {Array} The attenuation factors
 32 	*/
 33 	this.getAttenuation = function()
 34 	{
 35 		return [this.attenuation[0], this.attenuation[1],this.attenuation[2]];
 36 	}
 37 
 38 	/**
 39 		Get the position of the light.
 40 
 41 		@returns {Array} the position of the light.
 42 	*/
 43 	this.getPosition = function()
 44 	{
 45 		return [this.position[0], this.position[1], this.position[2]];
 46 	}
 47 
 48 	/**
 49 		Set the attenuation factors of this light.
 50 		
 51 		the attenuation factor is calculated:
 52 		
 53 		attenuation factor = 1 / (C + L*D + Q*D^2) <br />
 54 		C = constant attenuation, 0th element <br />
 55 		L = linear attenuation, 1st element <br />
 56 		Q = quadratic attenuation, 2nd element<br />
 57 		D = distance between light and vertex.<br />
 58 
 59 		@param {Array} attenuation
 60 	*/
 61 	this.setAttenuation = function(attenuation)
 62 	{
 63 		this.attenuation = attenuation;
 64 	}
 65 
 66 	/**
 67 		Set the position of this light.
 68 
 69 		@param {Array} Position of the light relative to world space.
 70 	*/
 71 	this.setPosition = function(vec)
 72 	{
 73 		if(c3dl.isValidVector(vec))
 74 		{
 75 			this.position = vec;
 76 		}
 77 	}
 78 }
 79 
 80 c3dl.PositionalLight.prototype = new c3dl.Light;