Light source documentation has added.

This commit is contained in:
Zemledelec 2016-07-06 21:31:05 +03:00
parent f43e08fadb
commit dddddc3207
5 changed files with 176 additions and 46 deletions

View File

@ -2,7 +2,7 @@ goog.provide('og.control.Sun');
goog.require('og.inheritance');
goog.require('og.control.BaseControl');
goog.require('og.light.LightSource');
goog.require('og.LightSource');
goog.require('og.astro.earth');
goog.require('og.math.Quaternion');
@ -32,7 +32,7 @@ og.control.Sun = function (options) {
/**
* Light source.
* @public
* @type {og.light.LightSource}
* @type {og.LightSource}
*/
this.sunlight = null;
@ -61,11 +61,12 @@ og.control.Sun.prototype.oninit = function () {
this.planet.lightEnabled = true;
//sunlight initialization
this.sunlight = new og.light.LightSource();
this.sunlight.setAmbient(new og.math.Vector3(0.15, 0.15, 0.25));
this.sunlight.setDiffuse(new og.math.Vector3(0.9, 0.9, 0.8));
this.sunlight.setSpecular(new og.math.Vector3(0.1, 0.1, 0.06));
this.sunlight.setShininess(110);
this.sunlight = new og.LightSource("Sun", {
'ambient': new og.math.Vector3(0.15, 0.15, 0.25),
'diffuse': new og.math.Vector3(0.9, 0.9, 0.8),
'specular': new og.math.Vector3(0.1, 0.1, 0.06),
'shininess': 110
});
this.sunlight.addTo(this.planet);
var that = this;

View File

@ -1,36 +1,118 @@
goog.provide('og.light.LightSource');
goog.provide('og.LightSource');
goog.require('og.math.Vector3');
og.light.LightSource = function (name, position, ambient, diffuse, specular, shininess, directional) {
this._name = name || ("p" + og.light.LightSource._counter++);
/**
* Represents basic light source.
* @class
* @param {string} [name] - Light source name.
* @param {Object} [params] - Light parameters:
* @param {og.math.Vector3} [params.position] - Light source position if it is a point light, otherwise it is a light direction vector.
* @param {og.math.Vector3} [params.ambient] - Ambient RGB color.
* @param {og.math.Vector3} [params.diffuse] - Diffuse RGB color.
* @param {og.math.Vector3} [params.specular] - Specular RGB color.
* @param {number} [params.shininess] - Specular shininess.
*/
og.LightSource = function (name, params) {
params = params || {};
/**
* Light name.
* @protected
* @type {string}
*/
this._name = name || ("light_" + og.LightSource._counter++);
/**
* Render node where light is shines.
* @protected
* @type {og.node.RenderNode}
*/
this._renderNode = null;
this._position = position || new og.math.Vector3();
/**
* Light position.
* @protected
* @type {og.math.Vector3}
*/
this._position = params.position || new og.math.Vector3();
this.directional = true;// = directional || false;
/**
* True if the light is directional.
* @public
* @type {boolean}
*/
this.directional = params.derectional != undefined ? params.derectional : true;
this._ambient = ambient || new og.math.Vector3();
this._diffuse = diffuse || new og.math.Vector3(0.8, 0.8, 0.8);
this._specular = specular || new og.math.Vector3(0.18, 0.18, 0.18);
/**
* Ambient color.
* @protected
* @type {og.math.Vector3}
*/
this._ambient = params.ambient || new og.math.Vector3();
this._shininess = shininess || 3.3;
/**
* Diffuse color.
* @protected
* @type {og.math.Vector3}
*/
this._diffuse = params.diffuse || new og.math.Vector3(0.8, 0.8, 0.8);
/**
* Specular color.
* @protected
* @type {og.math.Vector3}
*/
this._specular = params.specular || new og.math.Vector3(0.18, 0.18, 0.18);
/**
* Shininess.
* @protected
* @type {number}
*/
this._shininess = params.shininess != undefined ? params.shininess : 3.3;
/**
* Light activity.
* @protected
* @type {boolean}
*/
this._active = true;
this._tempAmbient = ambient ? ambient.clone() : new og.math.Vector3();
this._tempDiffuse = diffuse ? diffuse.clone() : new og.math.Vector3();
this._tempSpecular = specular ? specular.clone() : new og.math.Vector3();
this._tempShininess = shininess || 1.0;
this._tempAmbient = this._ambient.clone();
this._tempDiffuse = this._diffuse.clone();
this._tempSpecular = this._specular.clone();
this._tempShininess = this._shininess;
};
og.light.LightSource._counter = 0;
og.LightSource._counter = 0;
og.light.LightSource.prototype.clone = function () {
/**
* Creates light source object.
* @function
* @param {string} [name] - Light name.
* @param {Object} [params] - Light parameters.
* @returns {og.LightSource}
*/
og.lightSource = function (name, params) {
return new og.LightSource(name, params);
};
/**
* Creates clone of the current light object.
* @public
* @returns {og.LightSource}
*/
og.LightSource.prototype.clone = function () {
};
og.light.LightSource.prototype.setActive = function (active) {
/**
* Set light activity. If activity is false the light doesn't shine.
* @public
* @param {boolean} active - Light activity.
*/
og.LightSource.prototype.setActive = function (active) {
if (active && !this._active) {
var rn = this._renderNode;
if (rn) {
@ -58,22 +140,37 @@ og.light.LightSource.prototype.setActive = function (active) {
this.setBlack();
this._active = false;
}
return this.active;
};
og.light.LightSource.prototype.isActive = function () {
/**
* Gets light activity.
* @public
* @returns {boolean}
*/
og.LightSource.prototype.isActive = function () {
return this._active;
};
og.light.LightSource.prototype.setPosition = function (position) {
/**
* Set light source position, or if it is a directional type sets light direction vector.
* @public
* @param {og.math.Vector3} position - Light position or direction vector.
* @returns {og.LightSource}
*/
og.LightSource.prototype.setPosition = function (position) {
this._position.x = position.x;
this._position.y = position.y;
this._position.z = position.z;
return this;
};
og.light.LightSource.prototype.setAmbient = function (rgb) {
/**
* Set ambient color.
* @public
* @param {og.math.Vector3} rgb - Ambient color.
* @returns {og.LightSource}
*/
og.LightSource.prototype.setAmbient = function (rgb) {
this._ambient = rgb;
var rn = this._renderNode;
if (rn) {
@ -87,7 +184,13 @@ og.light.LightSource.prototype.setAmbient = function (rgb) {
return this;
};
og.light.LightSource.prototype.setDiffuse = function (rgb) {
/**
* Set diffuse color.
* @public
* @param {og.math.Vector3} rgb - Diffuse color.
* @returns {og.LightSource}
*/
og.LightSource.prototype.setDiffuse = function (rgb) {
this._diffuse = rgb;
var rn = this._renderNode;
if (rn) {
@ -101,7 +204,13 @@ og.light.LightSource.prototype.setDiffuse = function (rgb) {
return this;
};
og.light.LightSource.prototype.setSpecular = function (rgb) {
/**
* Set specular color.
* @public
* @param {og.math.Vector3} rgb - Specular color.
* @returns {og.LightSource}
*/
og.LightSource.prototype.setSpecular = function (rgb) {
this._specular = rgb;
var rn = this._renderNode;
if (rn) {
@ -115,7 +224,13 @@ og.light.LightSource.prototype.setSpecular = function (rgb) {
return this;
};
og.light.LightSource.prototype.setShininess = function (shininess) {
/**
* Set material shininess.
* @public
* @param {number} shininess - Material shininess.
* @returns {og.LightSource}
*/
og.LightSource.prototype.setShininess = function (shininess) {
this._shininess = shininess;
var rn = this._renderNode;
if (rn) {
@ -127,7 +242,12 @@ og.light.LightSource.prototype.setShininess = function (shininess) {
return this;
};
og.light.LightSource.prototype.setBlack = function () {
/**
* Sets light to black.
* @public
* @returns {og.LightSource}
*/
og.LightSource.prototype.setBlack = function () {
this._ambient.clear();
this._diffuse.clear();
this._specular.clear();
@ -144,7 +264,13 @@ og.light.LightSource.prototype.setBlack = function () {
return this;
};
og.light.LightSource.prototype.addTo = function (renderNode) {
/**
* Adds current light to the render node scene.
* @public
* @param {og.node.RenderNode} renderNode - Render node scene.
* @returns {og.LightSource}
*/
og.LightSource.prototype.addTo = function (renderNode) {
this._renderNode = renderNode;
renderNode._lights.push(this);
renderNode._lightsNames.push(this._name);
@ -155,7 +281,11 @@ og.light.LightSource.prototype.addTo = function (renderNode) {
return this;
};
og.light.LightSource.prototype.remove = function () {
/**
* Removes from render node scene.
* @public
*/
og.LightSource.prototype.remove = function () {
var rn = this.renderNode;
if (rn) {
var li = rn.getLightById(this._name);
@ -163,7 +293,7 @@ og.light.LightSource.prototype.remove = function () {
rn._lights.splice(li, 1);
rn._lightsNames.splice(li, 1);
rn._lightsParamsf.splice(li, 1);
rn._lightsParamsv.splice(li, 9);//3*3
rn._lightsParamsv.splice(li, 9);
}
}
this._renderNode = null;

View File

@ -30,11 +30,10 @@ goog.require('og.webgl.Framebuffer');
goog.require('og.mercator');
goog.require('og.proj.EPSG4326');
goog.require('og.ImageCanvas');
goog.require('og.light.LightSource');
goog.require('og.planetSegment.NormalMapCreatorQueue');
goog.require('og.GeoImage');
goog.require('og.planetSegment.GeoImageTileCreatorQueue');
goog.require('og.ellipsoid.wgs84');
/**
* Main class for rendering planet
* @class
@ -55,12 +54,12 @@ og.node.Planet = function (name, ellipsoid) {
* @public
* @type {og.Ellipsoid}
*/
this.ellipsoid = ellipsoid;
this.ellipsoid = ellipsoid || og.ellipsoid.wgs84;
/**
* @protected
*/
this._planetRadius2 = ellipsoid.getPolarSize() * ellipsoid.getPolarSize();
this._planetRadius2 = this.ellipsoid.getPolarSize() * this.ellipsoid.getPolarSize();
/**
* All layers array.

View File

@ -57,7 +57,7 @@ og.node.RenderNode = function (name) {
/**
* Point light array.
* @private
* @type {Array.<og.light.LightSource>}
* @type {Array.<og.LightSource>}
*/
this._lights = [];
this._lightsTransformedPositions = [];
@ -138,7 +138,7 @@ og.node.RenderNode.prototype.removeEntityCollection = function (entityCollection
/**
* Adds point light source.
* @public
* @param {og.light.LightSource} light - Light source.
* @param {og.LightSource} light - Light source.
* @returns {og.node.RenderNode}
*/
og.node.RenderNode.prototype.addLight = function (light) {
@ -150,7 +150,7 @@ og.node.RenderNode.prototype.addLight = function (light) {
* Gets light object by its name.
* @public
* @param {string} name - Point light name.
* @returns {og.light.LightSource}
* @returns {og.LightSource}
*/
og.node.RenderNode.prototype.getLightByName = function (name) {
var li = this._lightsNames.indexOf(name);
@ -160,7 +160,7 @@ og.node.RenderNode.prototype.getLightByName = function (name) {
/**
* Removes light source.
* @public
* @param {og.light.LightSource} light - Light source object.
* @param {og.LightSource} light - Light source object.
*/
og.node.RenderNode.prototype.removeLight = function (light) {
light.remove();

View File

@ -22,7 +22,7 @@ goog.addDependency('../../../og/src/og/control/mouseNavigation.js', ['og.control
goog.addDependency('../../../og/src/og/control/showFps.js', ['og.control.ShowFps'], ['og.control.BaseControl', 'og.inheritance'], false);
goog.addDependency('../../../og/src/og/control/simpleNavigation.js', ['og.control.SimpleNavigation'], ['og.control.BaseControl', 'og.inheritance', 'og.input'], false);
goog.addDependency('../../../og/src/og/control/spinNavigation.js', ['og.SpinNavigation'], ['og.bv.Sphere', 'og.control.BaseControl', 'og.inheritance', 'og.math', 'og.math.Matrix4', 'og.math.Quaternion', 'og.math.Ray', 'og.math.Vector3'], false);
goog.addDependency('../../../og/src/og/control/sun.js', ['og.control.Sun'], ['og.astro.earth', 'og.control.BaseControl', 'og.inheritance', 'og.light.LightSource', 'og.math.Quaternion'], false);
goog.addDependency('../../../og/src/og/control/sun.js', ['og.control.Sun'], ['og.LightSource', 'og.astro.earth', 'og.control.BaseControl', 'og.inheritance', 'og.math.Quaternion'], false);
goog.addDependency('../../../og/src/og/control/toggleWireframe.js', ['og.control.ToggleWireframe'], ['og.inheritance', 'og.input', 'og.webgl'], false);
goog.addDependency('../../../og/src/og/control/touchNavigation.js', ['og.control.TouchNavigation'], ['og.bv.Sphere', 'og.control.BaseControl', 'og.inheritance', 'og.math', 'og.math.Matrix4', 'og.math.Pixel', 'og.math.Quaternion', 'og.math.Ray', 'og.math.Vector3'], false);
goog.addDependency('../../../og/src/og/control/zoomControl.js', ['og.control.ZoomControl'], ['og.control.BaseControl', 'og.control.MouseNavigation', 'og.inheritance'], false);
@ -54,7 +54,7 @@ goog.addDependency('../../../og/src/og/layer/layer.js', ['og.layer', 'og.layer.L
goog.addDependency('../../../og/src/og/layer/vector.js', ['og.layer.Vector'], ['og.Entity', 'og.EntityCollection', 'og.LonLat', 'og.QueueArray', 'og.inheritance', 'og.math', 'og.quadTree', 'og.quadTree.EntityCollectionQuadNode'], false);
goog.addDependency('../../../og/src/og/layer/wms.js', ['og.layer.WMS'], ['og.inheritance', 'og.layer.XYZ'], false);
goog.addDependency('../../../og/src/og/layer/xyz.js', ['og.layer.XYZ'], ['og.inheritance', 'og.layer.Layer', 'og.proj.EPSG3857', 'og.quadTree', 'og.utils'], false);
goog.addDependency('../../../og/src/og/light/lightSource.js', ['og.light.LightSource'], ['og.math.Vector3'], false);
goog.addDependency('../../../og/src/og/light/lightSource.js', ['og.LightSource'], ['og.math.Vector3'], false);
goog.addDependency('../../../og/src/og/lonlat.js', ['og.LonLat'], ['og.mercator'], false);
goog.addDependency('../../../og/src/og/math/coder.js', ['og.math.coder'], ['og.math', 'og.math.Vector4'], false);
goog.addDependency('../../../og/src/og/math/math.js', ['og.math'], [], false);
@ -69,7 +69,7 @@ goog.addDependency('../../../og/src/og/math/vector4.js', ['og.math.Vector4'], ['
goog.addDependency('../../../og/src/og/mercator.js', ['og.mercator'], [], false);
goog.addDependency('../../../og/src/og/node/axes.js', ['og.node.Axes'], ['og.inheritance', 'og.node.RenderNode'], false);
goog.addDependency('../../../og/src/og/node/node.js', ['og.node.Node'], [], false);
goog.addDependency('../../../og/src/og/node/planet.js', ['og.node.Planet'], ['og.Extent', 'og.GeoImage', 'og.ImageCanvas', 'og.LonLat', 'og.PlanetCamera', 'og.PlanetSegmentHelper', 'og.bv.Sphere', 'og.inheritance', 'og.layer', 'og.light.LightSource', 'og.math', 'og.math.Matrix4', 'og.math.Ray', 'og.math.Vector2', 'og.math.Vector3', 'og.math.coder', 'og.mercator', 'og.node.RenderNode', 'og.planetSegment', 'og.planetSegment.GeoImageTileCreatorQueue', 'og.planetSegment.NormalMapCreatorQueue', 'og.planetSegment.Segment', 'og.planetSegment.SegmentWGS84', 'og.proj.EPSG4326', 'og.quadTree', 'og.quadTree.QuadNode', 'og.shaderProgram.heightPicking', 'og.shaderProgram.overlays_nl', 'og.shaderProgram.overlays_wl', 'og.shaderProgram.single_nl', 'og.shaderProgram.single_wl', 'og.webgl', 'og.webgl.Framebuffer'], false);
goog.addDependency('../../../og/src/og/node/planet.js', ['og.node.Planet'], ['og.Extent', 'og.GeoImage', 'og.ImageCanvas', 'og.LonLat', 'og.PlanetCamera', 'og.PlanetSegmentHelper', 'og.bv.Sphere', 'og.ellipsoid.wgs84', 'og.inheritance', 'og.layer', 'og.math', 'og.math.Matrix4', 'og.math.Ray', 'og.math.Vector2', 'og.math.Vector3', 'og.math.coder', 'og.mercator', 'og.node.RenderNode', 'og.planetSegment', 'og.planetSegment.GeoImageTileCreatorQueue', 'og.planetSegment.NormalMapCreatorQueue', 'og.planetSegment.Segment', 'og.planetSegment.SegmentWGS84', 'og.proj.EPSG4326', 'og.quadTree', 'og.quadTree.QuadNode', 'og.shaderProgram.heightPicking', 'og.shaderProgram.overlays_nl', 'og.shaderProgram.overlays_wl', 'og.shaderProgram.single_nl', 'og.shaderProgram.single_wl', 'og.webgl', 'og.webgl.Framebuffer'], false);
goog.addDependency('../../../og/src/og/node/planetAtmosphere.js', ['og.node.PlanetAtmosphere'], ['og.inheritance', 'og.shaderProgram.atmosphereSpace', 'og.shaderProgram.overlaysAtmosphere_wl', 'og.shaderProgram.overlays_nl', 'og.shaderProgram.singleAtmosphere_wl', 'og.shaderProgram.single_nl', 'og.shape.Icosphere'], false);
goog.addDependency('../../../og/src/og/node/renderNode.js', ['og.node.RenderNode'], ['og.Events', 'og.inheritance', 'og.math.Matrix4', 'og.math.Vector3', 'og.node.Node', 'og.utils.FontAtlas', 'og.utils.TextureAtlas', 'og.webgl'], false);
goog.addDependency('../../../og/src/og/node/skyBox.js', ['og.node.SkyBox'], ['og.inheritance', 'og.node.RenderNode', 'og.shaderProgram.skybox'], false);