mirror of
https://github.com/openglobus/openglobus.git
synced 2025-12-08 19:25:27 +00:00
Lets the sunlight to shine.
This commit is contained in:
parent
7cb9913686
commit
a96594de3c
@ -31,18 +31,22 @@ og.light.PointLight.prototype.clone = function () {
|
||||
og.light.PointLight.prototype.setActive = function (active) {
|
||||
if (active && !this._active) {
|
||||
var rn = this._renderNode;
|
||||
var index = rn._pointLightsNames.indexOf(this._name);
|
||||
this._shininess = rn._pointLightsParamsf[index] = this._tempShininess;
|
||||
index *= 9;
|
||||
this._ambient.x = rn._pointLightsParamsv[index] = this._tempAmbient.x;
|
||||
this._ambient.y = rn._pointLightsParamsv[index + 1] = this._tempAmbient.y;
|
||||
this._ambient.z = rn._pointLightsParamsv[index + 2] = this._tempAmbient.z;
|
||||
this._diffuse.x = rn._pointLightsParamsv[index + 3] = this._tempDiffuse.x;
|
||||
this._diffuse.y = rn._pointLightsParamsv[index + 4] = this._tempDiffuse.y;
|
||||
this._diffuse.z = rn._pointLightsParamsv[index + 5] = this._tempDiffuse.z;
|
||||
this._specular.x = rn._pointLightsParamsv[index + 6] = this._tempSpecular.x;
|
||||
this._specular.y = rn._pointLightsParamsv[index + 7] = this._tempSpecular.y;
|
||||
this._specular.z = rn._pointLightsParamsv[index + 8] = this._tempSpecular.z;
|
||||
if (rn) {
|
||||
var index = rn._pointLightsNames.indexOf(this._name);
|
||||
this._shininess = rn._pointLightsParamsf[index] = this._tempShininess;
|
||||
if (index != -1) {
|
||||
index *= 9;
|
||||
this._ambient.x = rn._pointLightsParamsv[index] = this._tempAmbient.x;
|
||||
this._ambient.y = rn._pointLightsParamsv[index + 1] = this._tempAmbient.y;
|
||||
this._ambient.z = rn._pointLightsParamsv[index + 2] = this._tempAmbient.z;
|
||||
this._diffuse.x = rn._pointLightsParamsv[index + 3] = this._tempDiffuse.x;
|
||||
this._diffuse.y = rn._pointLightsParamsv[index + 4] = this._tempDiffuse.y;
|
||||
this._diffuse.z = rn._pointLightsParamsv[index + 5] = this._tempDiffuse.z;
|
||||
this._specular.x = rn._pointLightsParamsv[index + 6] = this._tempSpecular.x;
|
||||
this._specular.y = rn._pointLightsParamsv[index + 7] = this._tempSpecular.y;
|
||||
this._specular.z = rn._pointLightsParamsv[index + 8] = this._tempSpecular.z;
|
||||
}
|
||||
}
|
||||
this._active = true;
|
||||
} else if (!active && this._active) {
|
||||
this._tempAmbient = this._ambient.clone();
|
||||
@ -68,37 +72,54 @@ og.light.PointLight.prototype.setPosition = function (position) {
|
||||
og.light.PointLight.prototype.setAmbient = function (rgb) {
|
||||
this._ambient = rgb;
|
||||
var rn = this._renderNode;
|
||||
var index = 9 * rn._pointLightsNames.indexOf(this._name);
|
||||
rn._pointLightsParamsv[index] = rgb.x;
|
||||
rn._pointLightsParamsv[index + 1] = rgb.y;
|
||||
rn._pointLightsParamsv[index + 2] = rgb.z;
|
||||
if (rn) {
|
||||
var index = 9 * rn._pointLightsNames.indexOf(this._name);
|
||||
if (index != -1) {
|
||||
rn._pointLightsParamsv[index] = rgb.x;
|
||||
rn._pointLightsParamsv[index + 1] = rgb.y;
|
||||
rn._pointLightsParamsv[index + 2] = rgb.z;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
og.light.PointLight.prototype.setDiffuse = function (rgb) {
|
||||
this._diffuse = rgb;
|
||||
var rn = this._renderNode;
|
||||
var index = 9 * rn._pointLightsNames.indexOf(this._name);
|
||||
rn._pointLightsParamsv[index + 3] = rgb.x;
|
||||
rn._pointLightsParamsv[index + 4] = rgb.y;
|
||||
rn._pointLightsParamsv[index + 5] = rgb.z;
|
||||
if (rn) {
|
||||
var index = 9 * rn._pointLightsNames.indexOf(this._name);
|
||||
if (index != -1) {
|
||||
rn._pointLightsParamsv[index + 3] = rgb.x;
|
||||
rn._pointLightsParamsv[index + 4] = rgb.y;
|
||||
rn._pointLightsParamsv[index + 5] = rgb.z;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
og.light.PointLight.prototype.setSpecular = function (rgb) {
|
||||
this._specular = rgb;
|
||||
var rn = this._renderNode;
|
||||
var index = 9 * rn._pointLightsNames.indexOf(this._name);
|
||||
rn._pointLightsParamsv[index + 6] = rgb.x;
|
||||
rn._pointLightsParamsv[index + 7] = rgb.y;
|
||||
rn._pointLightsParamsv[index + 8] = rgb.z;
|
||||
if (rn) {
|
||||
var index = 9 * rn._pointLightsNames.indexOf(this._name);
|
||||
if (index != -1) {
|
||||
rn._pointLightsParamsv[index + 6] = rgb.x;
|
||||
rn._pointLightsParamsv[index + 7] = rgb.y;
|
||||
rn._pointLightsParamsv[index + 8] = rgb.z;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
og.light.PointLight.prototype.setShininess = function (shininess) {
|
||||
this._shininess = shininess;
|
||||
var rn = this._renderNode;
|
||||
rn._pointLightsParamsf[rn._pointLightsNames.indexOf(this._name)] = shininess;
|
||||
if (rn) {
|
||||
var index = rn._pointLightsNames.indexOf(this._name);
|
||||
if (index != -1) {
|
||||
rn._pointLightsParamsf[index] = shininess;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
@ -108,10 +129,14 @@ og.light.PointLight.prototype.setBlack = function () {
|
||||
this._specular.clear();
|
||||
this._shininess = 0;
|
||||
var rn = this._renderNode;
|
||||
var index = 9 * rn._pointLightsNames.indexOf(this._name);
|
||||
rn._pointLightsParamsv[index] = rn._pointLightsParamsv[index + 1] = rn._pointLightsParamsv[index + 2] =
|
||||
rn._pointLightsParamsv[index + 3] = rn._pointLightsParamsv[index + 4] = rn._pointLightsParamsv[index + 5] =
|
||||
rn._pointLightsParamsv[index + 6] = rn._pointLightsParamsv[index + 7] = rn._pointLightsParamsv[index + 8] = 0;
|
||||
if (rn) {
|
||||
var index = 9 * rn._pointLightsNames.indexOf(this._name);
|
||||
if (index != -1) {
|
||||
rn._pointLightsParamsv[index] = rn._pointLightsParamsv[index + 1] = rn._pointLightsParamsv[index + 2] =
|
||||
rn._pointLightsParamsv[index + 3] = rn._pointLightsParamsv[index + 4] = rn._pointLightsParamsv[index + 5] =
|
||||
rn._pointLightsParamsv[index + 6] = rn._pointLightsParamsv[index + 7] = rn._pointLightsParamsv[index + 8] = 0;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
@ -128,10 +153,14 @@ og.light.PointLight.prototype.addTo = function (renderNode) {
|
||||
|
||||
og.light.PointLight.prototype.remove = function () {
|
||||
var rn = this.renderNode;
|
||||
var li = rn.getLightById(this._name);
|
||||
rn._pointLights.splice(li, 1);
|
||||
rn._pointLightsNames.splice(li, 1);
|
||||
rn._pointLightsParamsf.splice(li, 1);
|
||||
rn._pointLightsParamsv.splice(li, 9);//3*3
|
||||
if (rn) {
|
||||
var li = rn.getLightById(this._name);
|
||||
if (li != -1) {
|
||||
rn._pointLights.splice(li, 1);
|
||||
rn._pointLightsNames.splice(li, 1);
|
||||
rn._pointLightsParamsf.splice(li, 1);
|
||||
rn._pointLightsParamsv.splice(li, 9);//3*3
|
||||
}
|
||||
}
|
||||
this._renderNode = null;
|
||||
};
|
||||
@ -55,6 +55,8 @@ og.node.Planet = function (name, ellipsoid) {
|
||||
this.cameraPosition_merc;
|
||||
|
||||
this.emptyTexture = null;
|
||||
|
||||
this.sunlight = null;
|
||||
};
|
||||
|
||||
og.inheritance.extend(og.node.Planet, og.node.RenderNode);
|
||||
@ -249,15 +251,13 @@ og.node.Planet.prototype.initialization = function () {
|
||||
this._viewChanged = true;
|
||||
});
|
||||
|
||||
sunlight = new og.light.PointLight();
|
||||
//l1._diffuse.set(1, 0, 0);
|
||||
sunlight._position.z = 149600000000;
|
||||
sunlight.addTo(this);
|
||||
sunlight.setAmbient(new og.math.Vector3(0.14, 0.1, 0.2));
|
||||
sunlight.setDiffuse(new og.math.Vector3(1, 0.99, 0.89));
|
||||
sunlight.setSpecular(new og.math.Vector3(0.4, 0.4, 0.3));
|
||||
sunlight.setShininess(8);
|
||||
|
||||
this.sunlight = new og.light.PointLight();
|
||||
this.sunlight._position.z = 149600000000;
|
||||
this.sunlight.setAmbient(new og.math.Vector3(0.14, 0.1, 0.2));
|
||||
this.sunlight.setDiffuse(new og.math.Vector3(0.9, 0.9, 0.8));
|
||||
this.sunlight.setSpecular(new og.math.Vector3(0.01, 0.01, 0.009));
|
||||
this.sunlight.setShininess(8);
|
||||
this.sunlight.addTo(this);
|
||||
};
|
||||
|
||||
og.node.Planet.prototype.updateVisibleLayers = function () {
|
||||
|
||||
@ -107,13 +107,15 @@ og.node.RenderNode.prototype.drawNodes = function () {
|
||||
if (this.frame) {
|
||||
|
||||
//calculate transformed lights
|
||||
var r = this.renderer;
|
||||
for (var i = 0; i < this._pointLights.length; i++) {
|
||||
var ii = i * 3;
|
||||
var tp = r.activeCamera.mvMatrix.mulVec3(this._pointLights[i]._position);
|
||||
this._pointLightsTransformedPositions[ii] = tp.x;
|
||||
this._pointLightsTransformedPositions[ii + 1] = tp.y;
|
||||
this._pointLightsTransformedPositions[ii + 2] = tp.z;
|
||||
if (this.lightEnabled) {
|
||||
var r = this.renderer;
|
||||
for (var i = 0; i < this._pointLights.length; i++) {
|
||||
var ii = i * 3;
|
||||
var tp = r.activeCamera.mvMatrix.mulVec3(this._pointLights[i]._position);
|
||||
this._pointLightsTransformedPositions[ii] = tp.x;
|
||||
this._pointLightsTransformedPositions[ii + 1] = tp.y;
|
||||
this._pointLightsTransformedPositions[ii + 2] = tp.z;
|
||||
}
|
||||
}
|
||||
|
||||
this.frame();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user