/** * Raw Light API object - should always correspond with the Light Schema * @param id * @param lightType * @param name * @param color * @param intensity * @param position * @param targetPosition * @param quaternion * @param rotation * @param scale * @param distance * @param decay * @param power * @param angle * @param penumbra * @param parentEntity * @constructor */ GameLib.D3.API.Light = function( id, lightType, name, color, intensity, position, targetPosition, quaternion, rotation, scale, distance, decay, power, angle, penumbra, parentEntity ) { GameLib.Component.call( this, GameLib.Component.COMPONENT_LIGHT, null, null, parentEntity ); if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } this.id = id; if (GameLib.Utils.UndefinedOrNull(lightType)) { lightType = GameLib.D3.Light.LIGHT_TYPE_AMBIENT; } this.lightType = lightType; if (GameLib.Utils.UndefinedOrNull(name)) { name = 'Light (' + lightType + ')'; } this.name = name; if (GameLib.Utils.UndefinedOrNull(color)) { color = new GameLib.D3.API.Color(1,1,1,1); } this.color = color; if (GameLib.Utils.UndefinedOrNull(intensity)) { intensity = 1; } this.intensity = intensity; if (typeof position == 'undefined') { position = new GameLib.API.Vector3(0,10,0); } this.position = position; if (typeof targetPosition == 'undefined') { targetPosition = new GameLib.API.Vector3(0,0,0); } this.targetPosition = targetPosition; if (typeof quaternion == 'undefined'){ quaternion = new GameLib.API.Quaternion(); } this.quaternion = quaternion; if (typeof rotation == 'undefined'){ rotation = new GameLib.API.Vector3(0,0,0); } this.rotation = rotation; if (typeof scale == 'undefined'){ scale = new GameLib.API.Vector3(1,1,1); } this.scale = scale; if (typeof distance == 'undefined'){ distance = 0; } this.distance = distance; if (typeof decay == 'undefined'){ decay = 1; } this.decay = decay; if (typeof power == 'undefined'){ power = 4 * Math.PI; } this.power = power; if (typeof angle == 'undefined'){ angle = Math.PI / 3; } this.angle = angle; if (typeof penumbra == 'undefined'){ penumbra = 0; } this.penumbra = penumbra; }; GameLib.D3.API.Light.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.API.Light.prototype.constructor = GameLib.D3.API.Light; /** * Returns an API light from an Object light * @param objectLight * @constructor */ GameLib.D3.API.Light.FromObjectLight = function(objectLight) { return new GameLib.D3.API.Light( objectLight.id, objectLight.lightType, objectLight.name, GameLib.D3.API.Color.FromObjectColor(objectLight.color), objectLight.intensity, GameLib.API.Vector3.FromObjectVector(objectLight.position), GameLib.API.Vector3.FromObjectVector(objectLight.targetPosition), GameLib.API.Quaternion.FromObjectQuaternion(objectLight.quaternion), GameLib.API.Vector3.FromObjectVector(objectLight.rotation), GameLib.API.Vector3.FromObjectVector(objectLight.scale), objectLight.distance, objectLight.decay, objectLight.power, objectLight.angle, objectLight.penumbra, objectLight.parentEntity ); };