mirror of
https://github.com/openglobus/openglobus.git
synced 2025-12-08 19:25:27 +00:00
need commit
This commit is contained in:
parent
e2d0673315
commit
e95f7beae1
14
.gitignore
vendored
14
.gitignore
vendored
@ -1,7 +1,11 @@
|
||||
/.metadata
|
||||
.metadata
|
||||
|
||||
Thumbs.db
|
||||
Release/
|
||||
Debug/
|
||||
private/
|
||||
*.opensdf
|
||||
|
||||
Release
|
||||
|
||||
Debug
|
||||
|
||||
*.opensdf
|
||||
|
||||
*.sdf
|
||||
1
private/og_depthwriter.bat
Normal file
1
private/og_depthwriter.bat
Normal file
@ -0,0 +1 @@
|
||||
"e:\my projects\closure-library\closure\bin\build\depswriter.py" --root_with_prefix="../src/og/ ../../../og/src/og/" > "e:\my projects\openglobus\src\og\og-deps.js"
|
||||
@ -1,19 +1,19 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>OpenGlobus - Earth planet</title>
|
||||
<link rel="stylesheet" href="../../css/spinner.css" type="text/css"/>
|
||||
<link rel="stylesheet" href="../../css/og.css" type="text/css"/>
|
||||
|
||||
<script src="../../../closure-library/closure/goog/base.js"></script>
|
||||
<script src="../../src/og/og-deps.js"></script>
|
||||
|
||||
<script src="my-deps.js"></script>
|
||||
<script src="main.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body style="width: 100%; height: 100%; padding: 0; margin: 0;" onload="start();">
|
||||
<canvas id="canvas" style="width: 100%; height: 100%; display: block"></canvas>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<html>
|
||||
<head>
|
||||
<title>OpenGlobus - Earth planet</title>
|
||||
<link rel="stylesheet" href="../../css/spinner.css" type="text/css"/>
|
||||
<link rel="stylesheet" href="../../css/og.css" type="text/css"/>
|
||||
|
||||
<script src="../../../closure-library/closure/goog/base.js"></script>
|
||||
<script src="../../src/og/og-deps.js"></script>
|
||||
|
||||
<script src="my-deps.js"></script>
|
||||
<script src="main.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body style="width: 100%; height: 100%; padding: 0; margin: 0;" onload="start();">
|
||||
<canvas id="canvas" style="width: 100%; height: 100%; display: block"></canvas>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@ -1,66 +1,66 @@
|
||||
goog.require('og');
|
||||
goog.require('og.webgl.Handler');
|
||||
goog.require('og.Renderer');
|
||||
goog.require('og.control.SimpleNavigation');
|
||||
goog.require('og.shaderProgram');
|
||||
goog.require('og.node.Axes');
|
||||
goog.require('my.Cubes');
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
function start() {
|
||||
|
||||
og.webgl.MAX_FRAME_DELAY = 15;
|
||||
|
||||
var flatShader = new og.shaderProgram.ShaderProgram("flat", {
|
||||
uniforms: {
|
||||
uPMVMatrix: { type: og.shaderProgram.types.MAT4 }
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true },
|
||||
aVertexColor: { type: og.shaderProgram.types.VEC4, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "flat_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "flat_fs.txt")
|
||||
});
|
||||
|
||||
var colorShader = new og.shaderProgram.ShaderProgram("colorShader", {
|
||||
uniforms: {
|
||||
uPMVMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
uSampler: { type: og.shaderProgram.types.SAMPLER2D },
|
||||
uColor: { type: og.shaderProgram.types.VEC4 }
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true }
|
||||
},
|
||||
vertexShader: "attribute vec3 aVertexPosition; \
|
||||
uniform mat4 uPMVMatrix; \
|
||||
void main(void) { \
|
||||
gl_Position = uPMVMatrix * vec4(aVertexPosition, 1.0); \
|
||||
}",
|
||||
fragmentShader: "precision mediump float; \
|
||||
uniform vec4 uColor; \
|
||||
void main(void) { \
|
||||
gl_FragColor = uColor; \
|
||||
}"
|
||||
});
|
||||
|
||||
context = new og.webgl.Handler("canvas");
|
||||
context.addShaderProgram(flatShader);
|
||||
context.addShaderProgram(colorShader);
|
||||
context.init();
|
||||
|
||||
renderer = new og.Renderer(context);
|
||||
renderer.init();
|
||||
|
||||
var axes = new og.node.Axes(10000);
|
||||
|
||||
renderer.addRenderNode(new my.Cubes("Cubes", 500));
|
||||
renderer.addRenderNode(axes);
|
||||
|
||||
renderer.addControls([
|
||||
new og.control.SimpleNavigation({ autoActivate: true }),
|
||||
]);
|
||||
|
||||
renderer.activeCamera.eye.set(697.3292203935438, 5246.773531464112, 4722.195080923377);
|
||||
renderer.start();
|
||||
goog.require('og');
|
||||
goog.require('og.webgl.Handler');
|
||||
goog.require('og.Renderer');
|
||||
goog.require('og.control.SimpleNavigation');
|
||||
goog.require('og.shaderProgram');
|
||||
goog.require('og.node.Axes');
|
||||
goog.require('my.Cubes');
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
function start() {
|
||||
|
||||
og.webgl.MAX_FRAME_DELAY = 15;
|
||||
|
||||
var flatShader = new og.shaderProgram.ShaderProgram("flat", {
|
||||
uniforms: {
|
||||
uPMVMatrix: { type: og.shaderProgram.types.MAT4 }
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true },
|
||||
aVertexColor: { type: og.shaderProgram.types.VEC4, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "flat_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "flat_fs.txt")
|
||||
});
|
||||
|
||||
var colorShader = new og.shaderProgram.ShaderProgram("colorShader", {
|
||||
uniforms: {
|
||||
uPMVMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
uSampler: { type: og.shaderProgram.types.SAMPLER2D },
|
||||
uColor: { type: og.shaderProgram.types.VEC4 }
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true }
|
||||
},
|
||||
vertexShader: "attribute vec3 aVertexPosition; \
|
||||
uniform mat4 uPMVMatrix; \
|
||||
void main(void) { \
|
||||
gl_Position = uPMVMatrix * vec4(aVertexPosition, 1.0); \
|
||||
}",
|
||||
fragmentShader: "precision mediump float; \
|
||||
uniform vec4 uColor; \
|
||||
void main(void) { \
|
||||
gl_FragColor = uColor; \
|
||||
}"
|
||||
});
|
||||
|
||||
context = new og.webgl.Handler("canvas");
|
||||
context.addShaderProgram(flatShader);
|
||||
context.addShaderProgram(colorShader);
|
||||
context.init();
|
||||
|
||||
renderer = new og.Renderer(context);
|
||||
renderer.init();
|
||||
|
||||
var axes = new og.node.Axes(10000);
|
||||
|
||||
renderer.addRenderNode(new my.Cubes("Cubes", 500));
|
||||
renderer.addRenderNode(axes);
|
||||
|
||||
renderer.addControls([
|
||||
new og.control.SimpleNavigation({ autoActivate: true }),
|
||||
]);
|
||||
|
||||
renderer.activeCamera.eye.set(697.3292203935438, 5246.773531464112, 4722.195080923377);
|
||||
renderer.start();
|
||||
};
|
||||
@ -1,3 +1,3 @@
|
||||
// This file was autogenerated by D:\my projects\closure-library\closure\bin\build\depswriter.py.
|
||||
// Please do not edit.
|
||||
goog.addDependency('../../../og/sandbox/2/mycubes.js', ['my.Cubes'], ['og.math', 'og.math.Matrix4', 'og.math.Quaternion', 'og.math.Vector3', 'og.node.RenderNode', 'og.webgl.Framebuffer']);
|
||||
// This file was autogenerated by D:\my projects\closure-library\closure\bin\build\depswriter.py.
|
||||
// Please do not edit.
|
||||
goog.addDependency('../../../og/sandbox/2/mycubes.js', ['my.Cubes'], ['og.math', 'og.math.Matrix4', 'og.math.Quaternion', 'og.math.Vector3', 'og.node.RenderNode', 'og.webgl.Framebuffer']);
|
||||
|
||||
@ -1,202 +1,202 @@
|
||||
goog.provide('my.Cubes');
|
||||
|
||||
goog.require('og.node.RenderNode');
|
||||
goog.require('og.math');
|
||||
goog.require('og.math.Quaternion');
|
||||
goog.require('og.math.Matrix4');
|
||||
goog.require('og.math.Vector3');
|
||||
goog.require('og.webgl.Framebuffer');
|
||||
|
||||
|
||||
my.Cubes = function (name, size) {
|
||||
og.inheritance.base(this, name);
|
||||
this.size = size * 0.5;
|
||||
this.cubeVertexPositionBuffer1 = null;
|
||||
this.cubeVertexIndexBuffer1 = null;
|
||||
this.cubeVertexPositionBuffer2 = null;
|
||||
this.cubeVertexIndexBuffer2 = null;
|
||||
this.cubeVertexPositionBuffer3 = null;
|
||||
this.cubeVertexIndexBuffer3 = null;
|
||||
this.mxRotation = new og.math.Matrix4().setIdentity();
|
||||
this.mxTranslation1 = new og.math.Matrix4().setIdentity();
|
||||
this.mxTranslation2 = new og.math.Matrix4().setIdentity();
|
||||
this.mxTranslation3 = new og.math.Matrix4().setIdentity();
|
||||
this.mxScale = new og.math.Matrix4().setIdentity();
|
||||
this.mxTRS = new og.math.Matrix4();
|
||||
this.orientation = new og.math.Quaternion(0, 0, 0, 0);
|
||||
this.rot = 0;
|
||||
this.framebuffer;
|
||||
};
|
||||
|
||||
og.inheritance.extend(my.Cubes, og.node.RenderNode);
|
||||
|
||||
my.Cubes.prototype.initialization = function () {
|
||||
this.createBuffers();
|
||||
this.drawMode = this.renderer.handler.gl.TRIANGLES;
|
||||
this.mxTranslation1.translate(new og.math.Vector3(0, 0, 0));
|
||||
this.mxTranslation2.translate(new og.math.Vector3(1000, 1000, 1000));
|
||||
this.mxTranslation3.translate(new og.math.Vector3(2000, 2000, 2000));
|
||||
this.renderer.events.on("onresize", this, this.onResize);
|
||||
this.framebuffer = new og.webgl.Framebuffer(this.renderer.handler.gl);
|
||||
this.framebuffer.initialize();
|
||||
|
||||
this.ff = new og.webgl.Framebuffer(this.renderer.handler.gl);
|
||||
this.ff.initialize();
|
||||
|
||||
this.renderer.events.on("onmouselbuttonclick", this, function (e) {
|
||||
var x = e.x,
|
||||
y = e.y;
|
||||
var pixelValues = this.framebuffer.readPixels(x, this.renderer.handler.gl.canvas.height - y);
|
||||
if (pixelValues[0] == 255 && pixelValues[1] == 0 && pixelValues[2] == 0) {
|
||||
console.log("Location: (" + x + ", " + y +
|
||||
") is in the RED!");
|
||||
} else if (pixelValues[0] == 0 && pixelValues[1] == 255 && pixelValues[2] == 0) {
|
||||
console.log("Location: (" + x + ", " + y +
|
||||
") is in the GREEN!");
|
||||
} else if (pixelValues[0] == 0 && pixelValues[1] == 0 && pixelValues[2] == 255) {
|
||||
console.log("Location: (" + x + ", " + y +
|
||||
") is in the BLUE!");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
my.Cubes.prototype.onResize = function (obj) {
|
||||
this.framebuffer.setSize(obj.clientWidth, obj.clientHeight);
|
||||
};
|
||||
|
||||
my.Cubes.prototype.createBuffers = function () {
|
||||
var vertices = [
|
||||
// Front face
|
||||
-1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
|
||||
// Back face
|
||||
-1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
|
||||
// Top face
|
||||
-1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
|
||||
// Bottom face
|
||||
-1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
|
||||
// Right face
|
||||
1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
|
||||
// Left face
|
||||
-1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
-1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
];
|
||||
|
||||
var cubeVertexIndices = [
|
||||
0, 1, 2, 0, 2, 3, // Front face
|
||||
4, 5, 6, 4, 6, 7, // Back face
|
||||
8, 9, 10, 8, 10, 11, // Top face
|
||||
12, 13, 14, 12, 14, 15, // Bottom face
|
||||
16, 17, 18, 16, 18, 19, // Right face
|
||||
20, 21, 22, 20, 22, 23 // Left face
|
||||
]
|
||||
|
||||
this.cubeVertexPositionBuffer1 = this.renderer.handler.createArrayBuffer(new Float32Array(vertices), 3, 24);
|
||||
this.cubeVertexIndexBuffer1 = this.renderer.handler.createElementArrayBuffer(new Uint16Array(cubeVertexIndices), 1, 36);
|
||||
|
||||
this.cubeVertexPositionBuffer2 = this.renderer.handler.createArrayBuffer(new Float32Array(vertices), 3, 24);
|
||||
this.cubeVertexIndexBuffer2 = this.renderer.handler.createElementArrayBuffer(new Uint16Array(cubeVertexIndices), 1, 36);
|
||||
|
||||
this.cubeVertexPositionBuffer3 = this.renderer.handler.createArrayBuffer(new Float32Array(vertices), 3, 24);
|
||||
this.cubeVertexIndexBuffer3 = this.renderer.handler.createElementArrayBuffer(new Uint16Array(cubeVertexIndices), 1, 36);
|
||||
|
||||
};
|
||||
|
||||
my.Cubes.prototype.draw = function () {
|
||||
|
||||
this.mxTRS = this.mxTranslation1.mul(this.orientation.setFromAxisAngle(new og.math.Vector3(1, 1, 1), this.rot * og.math.RADIANS).getMatrix4());
|
||||
this.renderer.handler.shaderPrograms.colorShader.set({
|
||||
uPMVMatrix: this.renderer.activeCamera.pmvMatrix.mul(this.mxTRS)._m,
|
||||
aVertexPosition: this.cubeVertexPositionBuffer1,
|
||||
uColor: [1, 0, 0, 1]
|
||||
});
|
||||
this.renderer.handler.shaderPrograms.colorShader.drawIndexBuffer(this.drawMode, this.cubeVertexIndexBuffer1);
|
||||
|
||||
|
||||
this.mxTRS = this.mxTranslation2.mul(this.orientation.setFromAxisAngle(new og.math.Vector3(1, 1, 1), this.rot * og.math.RADIANS).getMatrix4());
|
||||
this.renderer.handler.shaderPrograms.colorShader.set({
|
||||
uPMVMatrix: this.renderer.activeCamera.pmvMatrix.mul(this.mxTRS)._m,
|
||||
aVertexPosition: this.cubeVertexPositionBuffer2,
|
||||
uColor: [0, 1, 0, 1]
|
||||
});
|
||||
this.renderer.handler.shaderPrograms.colorShader.drawIndexBuffer(this.drawMode, this.cubeVertexIndexBuffer2);
|
||||
|
||||
|
||||
this.mxTRS = this.mxTranslation3.mul(this.orientation.setFromAxisAngle(new og.math.Vector3(1, 1, 1), this.rot * og.math.RADIANS).getMatrix4());
|
||||
this.renderer.handler.shaderPrograms.colorShader.set({
|
||||
uPMVMatrix: this.renderer.activeCamera.pmvMatrix.mul(this.mxTRS)._m,
|
||||
aVertexPosition: this.cubeVertexPositionBuffer3,
|
||||
uColor: [0, 0, 1, 1]
|
||||
});
|
||||
this.renderer.handler.shaderPrograms.colorShader.drawIndexBuffer(this.drawMode, this.cubeVertexIndexBuffer3);
|
||||
};
|
||||
|
||||
my.Cubes.prototype.draw2 = function () {
|
||||
|
||||
this.mxTRS = this.mxTranslation1.mul(this.orientation.setFromAxisAngle(new og.math.Vector3(1, 1, 1), 2 * this.rot * og.math.RADIANS).getMatrix4());
|
||||
this.renderer.handler.shaderPrograms.colorShader.set({
|
||||
uPMVMatrix: this.renderer.activeCamera.pmvMatrix.mul(this.mxTRS)._m,
|
||||
aVertexPosition: this.cubeVertexPositionBuffer1,
|
||||
uColor: [1, 0, 0, 1]
|
||||
});
|
||||
this.renderer.handler.shaderPrograms.colorShader.drawIndexBuffer(this.drawMode, this.cubeVertexIndexBuffer1);
|
||||
|
||||
|
||||
this.mxTRS = this.mxTranslation2.mul(this.orientation.setFromAxisAngle(new og.math.Vector3(1, 1, 1), 3 * this.rot * og.math.RADIANS).getMatrix4());
|
||||
this.renderer.handler.shaderPrograms.colorShader.set({
|
||||
uPMVMatrix: this.renderer.activeCamera.pmvMatrix.mul(this.mxTRS)._m,
|
||||
aVertexPosition: this.cubeVertexPositionBuffer2,
|
||||
uColor: [0, 1, 0, 1]
|
||||
});
|
||||
this.renderer.handler.shaderPrograms.colorShader.drawIndexBuffer(this.drawMode, this.cubeVertexIndexBuffer2);
|
||||
|
||||
|
||||
this.mxTRS = this.mxTranslation3.mul(this.orientation.setFromAxisAngle(new og.math.Vector3(1, 1, 1), 5 * this.rot * og.math.RADIANS).getMatrix4());
|
||||
this.renderer.handler.shaderPrograms.colorShader.set({
|
||||
uPMVMatrix: this.renderer.activeCamera.pmvMatrix.mul(this.mxTRS)._m,
|
||||
aVertexPosition: this.cubeVertexPositionBuffer3,
|
||||
uColor: [0, 0, 1, 1]
|
||||
});
|
||||
this.renderer.handler.shaderPrograms.colorShader.drawIndexBuffer(this.drawMode, this.cubeVertexIndexBuffer3);
|
||||
};
|
||||
|
||||
|
||||
|
||||
my.Cubes.prototype.frame = function () {
|
||||
|
||||
this.renderer.handler.shaderPrograms.colorShader.activate();
|
||||
|
||||
this.framebuffer.activate();
|
||||
this.framebuffer.clear();
|
||||
this.draw();
|
||||
this.framebuffer.deactivate();
|
||||
|
||||
this.ff.activate();
|
||||
this.ff.clear();
|
||||
this.draw2();
|
||||
this.ff.deactivate();
|
||||
|
||||
this.draw();
|
||||
this.rot++;
|
||||
goog.provide('my.Cubes');
|
||||
|
||||
goog.require('og.node.RenderNode');
|
||||
goog.require('og.math');
|
||||
goog.require('og.math.Quaternion');
|
||||
goog.require('og.math.Matrix4');
|
||||
goog.require('og.math.Vector3');
|
||||
goog.require('og.webgl.Framebuffer');
|
||||
|
||||
|
||||
my.Cubes = function (name, size) {
|
||||
og.inheritance.base(this, name);
|
||||
this.size = size * 0.5;
|
||||
this.cubeVertexPositionBuffer1 = null;
|
||||
this.cubeVertexIndexBuffer1 = null;
|
||||
this.cubeVertexPositionBuffer2 = null;
|
||||
this.cubeVertexIndexBuffer2 = null;
|
||||
this.cubeVertexPositionBuffer3 = null;
|
||||
this.cubeVertexIndexBuffer3 = null;
|
||||
this.mxRotation = new og.math.Matrix4().setIdentity();
|
||||
this.mxTranslation1 = new og.math.Matrix4().setIdentity();
|
||||
this.mxTranslation2 = new og.math.Matrix4().setIdentity();
|
||||
this.mxTranslation3 = new og.math.Matrix4().setIdentity();
|
||||
this.mxScale = new og.math.Matrix4().setIdentity();
|
||||
this.mxTRS = new og.math.Matrix4();
|
||||
this.orientation = new og.math.Quaternion(0, 0, 0, 0);
|
||||
this.rot = 0;
|
||||
this.framebuffer;
|
||||
};
|
||||
|
||||
og.inheritance.extend(my.Cubes, og.node.RenderNode);
|
||||
|
||||
my.Cubes.prototype.initialization = function () {
|
||||
this.createBuffers();
|
||||
this.drawMode = this.renderer.handler.gl.TRIANGLES;
|
||||
this.mxTranslation1.translate(new og.math.Vector3(0, 0, 0));
|
||||
this.mxTranslation2.translate(new og.math.Vector3(1000, 1000, 1000));
|
||||
this.mxTranslation3.translate(new og.math.Vector3(2000, 2000, 2000));
|
||||
this.renderer.events.on("onresize", this, this.onResize);
|
||||
this.framebuffer = new og.webgl.Framebuffer(this.renderer.handler.gl);
|
||||
this.framebuffer.initialize();
|
||||
|
||||
this.ff = new og.webgl.Framebuffer(this.renderer.handler.gl);
|
||||
this.ff.initialize();
|
||||
|
||||
this.renderer.events.on("onmouselbuttonclick", this, function (e) {
|
||||
var x = e.x,
|
||||
y = e.y;
|
||||
var pixelValues = this.framebuffer.readPixels(x, this.renderer.handler.gl.canvas.height - y);
|
||||
if (pixelValues[0] == 255 && pixelValues[1] == 0 && pixelValues[2] == 0) {
|
||||
console.log("Location: (" + x + ", " + y +
|
||||
") is in the RED!");
|
||||
} else if (pixelValues[0] == 0 && pixelValues[1] == 255 && pixelValues[2] == 0) {
|
||||
console.log("Location: (" + x + ", " + y +
|
||||
") is in the GREEN!");
|
||||
} else if (pixelValues[0] == 0 && pixelValues[1] == 0 && pixelValues[2] == 255) {
|
||||
console.log("Location: (" + x + ", " + y +
|
||||
") is in the BLUE!");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
my.Cubes.prototype.onResize = function (obj) {
|
||||
this.framebuffer.setSize(obj.clientWidth, obj.clientHeight);
|
||||
};
|
||||
|
||||
my.Cubes.prototype.createBuffers = function () {
|
||||
var vertices = [
|
||||
// Front face
|
||||
-1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
|
||||
// Back face
|
||||
-1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
|
||||
// Top face
|
||||
-1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
|
||||
// Bottom face
|
||||
-1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
|
||||
// Right face
|
||||
1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
|
||||
// Left face
|
||||
-1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
-1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
];
|
||||
|
||||
var cubeVertexIndices = [
|
||||
0, 1, 2, 0, 2, 3, // Front face
|
||||
4, 5, 6, 4, 6, 7, // Back face
|
||||
8, 9, 10, 8, 10, 11, // Top face
|
||||
12, 13, 14, 12, 14, 15, // Bottom face
|
||||
16, 17, 18, 16, 18, 19, // Right face
|
||||
20, 21, 22, 20, 22, 23 // Left face
|
||||
]
|
||||
|
||||
this.cubeVertexPositionBuffer1 = this.renderer.handler.createArrayBuffer(new Float32Array(vertices), 3, 24);
|
||||
this.cubeVertexIndexBuffer1 = this.renderer.handler.createElementArrayBuffer(new Uint16Array(cubeVertexIndices), 1, 36);
|
||||
|
||||
this.cubeVertexPositionBuffer2 = this.renderer.handler.createArrayBuffer(new Float32Array(vertices), 3, 24);
|
||||
this.cubeVertexIndexBuffer2 = this.renderer.handler.createElementArrayBuffer(new Uint16Array(cubeVertexIndices), 1, 36);
|
||||
|
||||
this.cubeVertexPositionBuffer3 = this.renderer.handler.createArrayBuffer(new Float32Array(vertices), 3, 24);
|
||||
this.cubeVertexIndexBuffer3 = this.renderer.handler.createElementArrayBuffer(new Uint16Array(cubeVertexIndices), 1, 36);
|
||||
|
||||
};
|
||||
|
||||
my.Cubes.prototype.draw = function () {
|
||||
|
||||
this.mxTRS = this.mxTranslation1.mul(this.orientation.setFromAxisAngle(new og.math.Vector3(1, 1, 1), this.rot * og.math.RADIANS).getMatrix4());
|
||||
this.renderer.handler.shaderPrograms.colorShader.set({
|
||||
uPMVMatrix: this.renderer.activeCamera.pmvMatrix.mul(this.mxTRS)._m,
|
||||
aVertexPosition: this.cubeVertexPositionBuffer1,
|
||||
uColor: [1, 0, 0, 1]
|
||||
});
|
||||
this.renderer.handler.shaderPrograms.colorShader.drawIndexBuffer(this.drawMode, this.cubeVertexIndexBuffer1);
|
||||
|
||||
|
||||
this.mxTRS = this.mxTranslation2.mul(this.orientation.setFromAxisAngle(new og.math.Vector3(1, 1, 1), this.rot * og.math.RADIANS).getMatrix4());
|
||||
this.renderer.handler.shaderPrograms.colorShader.set({
|
||||
uPMVMatrix: this.renderer.activeCamera.pmvMatrix.mul(this.mxTRS)._m,
|
||||
aVertexPosition: this.cubeVertexPositionBuffer2,
|
||||
uColor: [0, 1, 0, 1]
|
||||
});
|
||||
this.renderer.handler.shaderPrograms.colorShader.drawIndexBuffer(this.drawMode, this.cubeVertexIndexBuffer2);
|
||||
|
||||
|
||||
this.mxTRS = this.mxTranslation3.mul(this.orientation.setFromAxisAngle(new og.math.Vector3(1, 1, 1), this.rot * og.math.RADIANS).getMatrix4());
|
||||
this.renderer.handler.shaderPrograms.colorShader.set({
|
||||
uPMVMatrix: this.renderer.activeCamera.pmvMatrix.mul(this.mxTRS)._m,
|
||||
aVertexPosition: this.cubeVertexPositionBuffer3,
|
||||
uColor: [0, 0, 1, 1]
|
||||
});
|
||||
this.renderer.handler.shaderPrograms.colorShader.drawIndexBuffer(this.drawMode, this.cubeVertexIndexBuffer3);
|
||||
};
|
||||
|
||||
my.Cubes.prototype.draw2 = function () {
|
||||
|
||||
this.mxTRS = this.mxTranslation1.mul(this.orientation.setFromAxisAngle(new og.math.Vector3(1, 1, 1), 2 * this.rot * og.math.RADIANS).getMatrix4());
|
||||
this.renderer.handler.shaderPrograms.colorShader.set({
|
||||
uPMVMatrix: this.renderer.activeCamera.pmvMatrix.mul(this.mxTRS)._m,
|
||||
aVertexPosition: this.cubeVertexPositionBuffer1,
|
||||
uColor: [1, 0, 0, 1]
|
||||
});
|
||||
this.renderer.handler.shaderPrograms.colorShader.drawIndexBuffer(this.drawMode, this.cubeVertexIndexBuffer1);
|
||||
|
||||
|
||||
this.mxTRS = this.mxTranslation2.mul(this.orientation.setFromAxisAngle(new og.math.Vector3(1, 1, 1), 3 * this.rot * og.math.RADIANS).getMatrix4());
|
||||
this.renderer.handler.shaderPrograms.colorShader.set({
|
||||
uPMVMatrix: this.renderer.activeCamera.pmvMatrix.mul(this.mxTRS)._m,
|
||||
aVertexPosition: this.cubeVertexPositionBuffer2,
|
||||
uColor: [0, 1, 0, 1]
|
||||
});
|
||||
this.renderer.handler.shaderPrograms.colorShader.drawIndexBuffer(this.drawMode, this.cubeVertexIndexBuffer2);
|
||||
|
||||
|
||||
this.mxTRS = this.mxTranslation3.mul(this.orientation.setFromAxisAngle(new og.math.Vector3(1, 1, 1), 5 * this.rot * og.math.RADIANS).getMatrix4());
|
||||
this.renderer.handler.shaderPrograms.colorShader.set({
|
||||
uPMVMatrix: this.renderer.activeCamera.pmvMatrix.mul(this.mxTRS)._m,
|
||||
aVertexPosition: this.cubeVertexPositionBuffer3,
|
||||
uColor: [0, 0, 1, 1]
|
||||
});
|
||||
this.renderer.handler.shaderPrograms.colorShader.drawIndexBuffer(this.drawMode, this.cubeVertexIndexBuffer3);
|
||||
};
|
||||
|
||||
|
||||
|
||||
my.Cubes.prototype.frame = function () {
|
||||
|
||||
this.renderer.handler.shaderPrograms.colorShader.activate();
|
||||
|
||||
this.framebuffer.activate();
|
||||
this.framebuffer.clear();
|
||||
this.draw();
|
||||
this.framebuffer.deactivate();
|
||||
|
||||
this.ff.activate();
|
||||
this.ff.clear();
|
||||
this.draw2();
|
||||
this.ff.deactivate();
|
||||
|
||||
this.draw();
|
||||
this.rot++;
|
||||
};
|
||||
@ -1 +1 @@
|
||||
"d:\my projects\closure-library\closure\bin\build\depswriter.py" --root_with_prefix="./ ../../../og/sandbox/billboard/" > "d:\my projects\openglobus\sandbox\billboard\my-deps.js"
|
||||
"e:\my projects\closure-library\closure\bin\build\depswriter.py" --root_with_prefix="./ ../../../og/sandbox/billboard/" > "e:\my projects\openglobus\sandbox\billboard\my-deps.js"
|
||||
@ -1,144 +1,144 @@
|
||||
var CubeNode = function (size) {
|
||||
CubeNode.superclass.constructor.call(this, "CUBE");
|
||||
this.size = size * 0.5;
|
||||
//this.cubeVertexColorBuffer = null;
|
||||
this.cubeVertexPositionBuffer = null;
|
||||
this.cubeVertexIndexBuffer = null;
|
||||
|
||||
this.texture;
|
||||
this.textureImageFileName;
|
||||
this.cubeVertexTextureCoordBuffer = null;
|
||||
}
|
||||
|
||||
extend(CubeNode, Node3D);
|
||||
|
||||
CubeNode.prototype.initialization = function () {
|
||||
|
||||
this.initTexture("nehe.gif");
|
||||
this.createBuffers();
|
||||
this.drawMode = WebGLContext.GL_TRIANGLES;
|
||||
}
|
||||
|
||||
CubeNode.prototype.initTexture = function(fileName) {
|
||||
var image = new Image();
|
||||
var handle = this;
|
||||
image.onload = function () {
|
||||
handle.texture = handle.renderer.ctx.createTextureFromImage(image);
|
||||
}
|
||||
image.src = this.textureImageFileName = fileName;
|
||||
}
|
||||
|
||||
CubeNode.prototype.frame = function () {
|
||||
this.renderer.ctx.bindTexture(this.texture);
|
||||
this.renderer.ctx.drawBuffer(this.cubeVertexPositionBuffer, this.cubeVertexTextureCoordBuffer, this.cubeVertexIndexBuffer);
|
||||
}
|
||||
|
||||
CubeNode.prototype.createBuffers = function () {
|
||||
vertices = [
|
||||
// Front face
|
||||
-1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
|
||||
// Back face
|
||||
-1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
|
||||
// Top face
|
||||
-1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
|
||||
// Bottom face
|
||||
-1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
|
||||
// Right face
|
||||
1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
|
||||
// Left face
|
||||
-1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
-1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
];
|
||||
|
||||
var cubeVertexIndices = [
|
||||
0, 1, 2, 0, 2, 3, // Front face
|
||||
4, 5, 6, 4, 6, 7, // Back face
|
||||
8, 9, 10, 8, 10, 11, // Top face
|
||||
12, 13, 14, 12, 14, 15, // Bottom face
|
||||
16, 17, 18, 16, 18, 19, // Right face
|
||||
20, 21, 22, 20, 22, 23 // Left face
|
||||
]
|
||||
|
||||
//var colors = [
|
||||
// [1.0, 0.0, 0.0, 1.0], // Front face
|
||||
// [1.0, 1.0, 0.0, 1.0], // Back face
|
||||
// [0.0, 1.0, 0.0, 1.0], // Top face
|
||||
// [1.0, 0.5, 0.5, 1.0], // Bottom face
|
||||
// [1.0, 0.0, 1.0, 1.0], // Right face
|
||||
// [0.0, 0.0, 1.0, 1.0], // Left face
|
||||
//];
|
||||
|
||||
//var unpackedColors = [];
|
||||
//for (var i in colors) {
|
||||
// var color = colors[i];
|
||||
// for (var j=0; j < 4; j++) {
|
||||
// unpackedColors = unpackedColors.concat(color);
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
var textureCoords = [
|
||||
// Front face
|
||||
0.0, 0.0,
|
||||
1.0, 0.0,
|
||||
1.0, 1.0,
|
||||
0.0, 1.0,
|
||||
|
||||
// Back face
|
||||
1.0, 0.0,
|
||||
1.0, 1.0,
|
||||
0.0, 1.0,
|
||||
0.0, 0.0,
|
||||
|
||||
// Top face
|
||||
0.0, 1.0,
|
||||
0.0, 0.0,
|
||||
1.0, 0.0,
|
||||
1.0, 1.0,
|
||||
|
||||
// Bottom face
|
||||
1.0, 1.0,
|
||||
0.0, 1.0,
|
||||
0.0, 0.0,
|
||||
1.0, 0.0,
|
||||
|
||||
// Right face
|
||||
1.0, 0.0,
|
||||
1.0, 1.0,
|
||||
0.0, 1.0,
|
||||
0.0, 0.0,
|
||||
|
||||
// Left face
|
||||
0.0, 0.0,
|
||||
1.0, 0.0,
|
||||
1.0, 1.0,
|
||||
0.0, 1.0
|
||||
];
|
||||
|
||||
//this.cubeVertexColorBuffer = this.ctx.createArrayBuffer( new Float32Array(unpackedColors), 4, 24 );
|
||||
this.cubeVertexPositionBuffer = this.renderer.ctx.createArrayBuffer( new Float32Array(vertices), 3, 24 );
|
||||
this.cubeVertexTextureCoordBuffer = this.renderer.ctx.createArrayBuffer(new Float32Array(textureCoords), 2, 24);
|
||||
this.cubeVertexIndexBuffer = this.renderer.ctx.createElementArrayBuffer(new Uint16Array(cubeVertexIndices), 1, 36);
|
||||
var CubeNode = function (size) {
|
||||
CubeNode.superclass.constructor.call(this, "CUBE");
|
||||
this.size = size * 0.5;
|
||||
//this.cubeVertexColorBuffer = null;
|
||||
this.cubeVertexPositionBuffer = null;
|
||||
this.cubeVertexIndexBuffer = null;
|
||||
|
||||
this.texture;
|
||||
this.textureImageFileName;
|
||||
this.cubeVertexTextureCoordBuffer = null;
|
||||
}
|
||||
|
||||
extend(CubeNode, Node3D);
|
||||
|
||||
CubeNode.prototype.initialization = function () {
|
||||
|
||||
this.initTexture("nehe.gif");
|
||||
this.createBuffers();
|
||||
this.drawMode = WebGLContext.GL_TRIANGLES;
|
||||
}
|
||||
|
||||
CubeNode.prototype.initTexture = function(fileName) {
|
||||
var image = new Image();
|
||||
var handle = this;
|
||||
image.onload = function () {
|
||||
handle.texture = handle.renderer.ctx.createTextureFromImage(image);
|
||||
}
|
||||
image.src = this.textureImageFileName = fileName;
|
||||
}
|
||||
|
||||
CubeNode.prototype.frame = function () {
|
||||
this.renderer.ctx.bindTexture(this.texture);
|
||||
this.renderer.ctx.drawBuffer(this.cubeVertexPositionBuffer, this.cubeVertexTextureCoordBuffer, this.cubeVertexIndexBuffer);
|
||||
}
|
||||
|
||||
CubeNode.prototype.createBuffers = function () {
|
||||
vertices = [
|
||||
// Front face
|
||||
-1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
|
||||
// Back face
|
||||
-1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
|
||||
// Top face
|
||||
-1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
|
||||
// Bottom face
|
||||
-1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
|
||||
// Right face
|
||||
1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
|
||||
// Left face
|
||||
-1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
|
||||
-1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
|
||||
-1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
|
||||
];
|
||||
|
||||
var cubeVertexIndices = [
|
||||
0, 1, 2, 0, 2, 3, // Front face
|
||||
4, 5, 6, 4, 6, 7, // Back face
|
||||
8, 9, 10, 8, 10, 11, // Top face
|
||||
12, 13, 14, 12, 14, 15, // Bottom face
|
||||
16, 17, 18, 16, 18, 19, // Right face
|
||||
20, 21, 22, 20, 22, 23 // Left face
|
||||
]
|
||||
|
||||
//var colors = [
|
||||
// [1.0, 0.0, 0.0, 1.0], // Front face
|
||||
// [1.0, 1.0, 0.0, 1.0], // Back face
|
||||
// [0.0, 1.0, 0.0, 1.0], // Top face
|
||||
// [1.0, 0.5, 0.5, 1.0], // Bottom face
|
||||
// [1.0, 0.0, 1.0, 1.0], // Right face
|
||||
// [0.0, 0.0, 1.0, 1.0], // Left face
|
||||
//];
|
||||
|
||||
//var unpackedColors = [];
|
||||
//for (var i in colors) {
|
||||
// var color = colors[i];
|
||||
// for (var j=0; j < 4; j++) {
|
||||
// unpackedColors = unpackedColors.concat(color);
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
var textureCoords = [
|
||||
// Front face
|
||||
0.0, 0.0,
|
||||
1.0, 0.0,
|
||||
1.0, 1.0,
|
||||
0.0, 1.0,
|
||||
|
||||
// Back face
|
||||
1.0, 0.0,
|
||||
1.0, 1.0,
|
||||
0.0, 1.0,
|
||||
0.0, 0.0,
|
||||
|
||||
// Top face
|
||||
0.0, 1.0,
|
||||
0.0, 0.0,
|
||||
1.0, 0.0,
|
||||
1.0, 1.0,
|
||||
|
||||
// Bottom face
|
||||
1.0, 1.0,
|
||||
0.0, 1.0,
|
||||
0.0, 0.0,
|
||||
1.0, 0.0,
|
||||
|
||||
// Right face
|
||||
1.0, 0.0,
|
||||
1.0, 1.0,
|
||||
0.0, 1.0,
|
||||
0.0, 0.0,
|
||||
|
||||
// Left face
|
||||
0.0, 0.0,
|
||||
1.0, 0.0,
|
||||
1.0, 1.0,
|
||||
0.0, 1.0
|
||||
];
|
||||
|
||||
//this.cubeVertexColorBuffer = this.ctx.createArrayBuffer( new Float32Array(unpackedColors), 4, 24 );
|
||||
this.cubeVertexPositionBuffer = this.renderer.ctx.createArrayBuffer( new Float32Array(vertices), 3, 24 );
|
||||
this.cubeVertexTextureCoordBuffer = this.renderer.ctx.createArrayBuffer(new Float32Array(textureCoords), 2, 24);
|
||||
this.cubeVertexIndexBuffer = this.renderer.ctx.createElementArrayBuffer(new Uint16Array(cubeVertexIndices), 1, 36);
|
||||
}
|
||||
@ -1 +1 @@
|
||||
"d:\my projects\closure-library\closure\bin\build\depswriter.py" --root_with_prefix="./ ../../../og/sandbox/geoImage/" > "d:\my projects\openglobus\sandbox\geoImage\my-deps.js"
|
||||
"e:\my projects\closure-library\closure\bin\build\depswriter.py" --root_with_prefix="./ ../../../og/sandbox/geoImage/" > "e:\my projects\openglobus\sandbox\geoImage\my-deps.js"
|
||||
@ -1,33 +1,33 @@
|
||||
var GridNode = function (gridSize, squareSize) {
|
||||
GridNode.superclass.constructor.call(this, "GRID");
|
||||
this.gridSize = gridSize;
|
||||
this.squareSize = squareSize;
|
||||
this.gridBuffer;
|
||||
this.gridColorBuffer;
|
||||
}
|
||||
|
||||
extend(GridNode, Node3D);
|
||||
|
||||
GridNode.prototype.initialization = function () {
|
||||
this.createGridBuffer(this.gridSize);
|
||||
}
|
||||
|
||||
GridNode.prototype.frame = function () {
|
||||
this.ctx.drawLinesBuffer(this.gridBuffer, this.gridColorBuffer);
|
||||
//this.ctx.gl.disable(this.ctx.gl.DEPTH_TEST);
|
||||
}
|
||||
|
||||
GridNode.prototype.createGridBuffer = function (gridSize) {
|
||||
|
||||
var vertices = [];
|
||||
var colors = [];
|
||||
for (var i = -gridSize; i < gridSize; i++) {
|
||||
vertices.push(-gridSize * this.squareSize, 0.0, i * this.squareSize, (gridSize - 1)*this.squareSize, 0.0, i * this.squareSize);
|
||||
vertices.push(i * this.squareSize, 0.0, -gridSize * this.squareSize, i * this.squareSize, 0.0, (gridSize - 1) * this.squareSize);
|
||||
colors.push(0.78, 0.78, 0.78, 1.0, 0.78, 0.78, 0.78, 1.0);
|
||||
colors.push(0.78, 0.78, 0.78, 1.0, 0.78, 0.78, 0.78, 1.0);
|
||||
}
|
||||
|
||||
this.gridBuffer = this.ctx.createArrayBuffer(new Float32Array(vertices), 3, 24/*gridSize * 4 * 2*/);
|
||||
this.gridColorBuffer = this.ctx.createArrayBuffer(new Float32Array(colors), 4, 24/*gridSize * 4 * 2*/);
|
||||
var GridNode = function (gridSize, squareSize) {
|
||||
GridNode.superclass.constructor.call(this, "GRID");
|
||||
this.gridSize = gridSize;
|
||||
this.squareSize = squareSize;
|
||||
this.gridBuffer;
|
||||
this.gridColorBuffer;
|
||||
}
|
||||
|
||||
extend(GridNode, Node3D);
|
||||
|
||||
GridNode.prototype.initialization = function () {
|
||||
this.createGridBuffer(this.gridSize);
|
||||
}
|
||||
|
||||
GridNode.prototype.frame = function () {
|
||||
this.ctx.drawLinesBuffer(this.gridBuffer, this.gridColorBuffer);
|
||||
//this.ctx.gl.disable(this.ctx.gl.DEPTH_TEST);
|
||||
}
|
||||
|
||||
GridNode.prototype.createGridBuffer = function (gridSize) {
|
||||
|
||||
var vertices = [];
|
||||
var colors = [];
|
||||
for (var i = -gridSize; i < gridSize; i++) {
|
||||
vertices.push(-gridSize * this.squareSize, 0.0, i * this.squareSize, (gridSize - 1)*this.squareSize, 0.0, i * this.squareSize);
|
||||
vertices.push(i * this.squareSize, 0.0, -gridSize * this.squareSize, i * this.squareSize, 0.0, (gridSize - 1) * this.squareSize);
|
||||
colors.push(0.78, 0.78, 0.78, 1.0, 0.78, 0.78, 0.78, 1.0);
|
||||
colors.push(0.78, 0.78, 0.78, 1.0, 0.78, 0.78, 0.78, 1.0);
|
||||
}
|
||||
|
||||
this.gridBuffer = this.ctx.createArrayBuffer(new Float32Array(vertices), 3, 24/*gridSize * 4 * 2*/);
|
||||
this.gridColorBuffer = this.ctx.createArrayBuffer(new Float32Array(colors), 4, 24/*gridSize * 4 * 2*/);
|
||||
}
|
||||
@ -1,30 +1,30 @@
|
||||
precision mediump float;
|
||||
|
||||
#define MAX_POINTS 30
|
||||
|
||||
uniform vec2 resolution;
|
||||
// a point is: a position (x, y), a distance (z), a weight (w)
|
||||
uniform vec4 points[MAX_POINTS];
|
||||
uniform int pointsLength;
|
||||
|
||||
|
||||
vec3 heat (float v) {
|
||||
float value = 1.-v;
|
||||
return (0.5 + 0.5 * smoothstep(0.0, 0.1, value)) * vec3(
|
||||
smoothstep(0.5, 0.3, value),
|
||||
value < 0.3 ? smoothstep(0.0, 0.3, value) : smoothstep(1.0, 0.6, value),
|
||||
smoothstep(0.4, 0.6, value)
|
||||
);
|
||||
}
|
||||
|
||||
void main () {
|
||||
vec2 p = gl_FragCoord.xy / resolution.xy;
|
||||
float sum = 0.0;
|
||||
for (int i = 0; i < MAX_POINTS; ++i) {
|
||||
if (i == pointsLength) break;
|
||||
vec4 point = points[i];
|
||||
sum += point.w * smoothstep(point.z, 0.0, distance(point.xy, p));
|
||||
}
|
||||
|
||||
gl_FragColor = vec4(heat(sum), 1.0);
|
||||
precision mediump float;
|
||||
|
||||
#define MAX_POINTS 30
|
||||
|
||||
uniform vec2 resolution;
|
||||
// a point is: a position (x, y), a distance (z), a weight (w)
|
||||
uniform vec4 points[MAX_POINTS];
|
||||
uniform int pointsLength;
|
||||
|
||||
|
||||
vec3 heat (float v) {
|
||||
float value = 1.-v;
|
||||
return (0.5 + 0.5 * smoothstep(0.0, 0.1, value)) * vec3(
|
||||
smoothstep(0.5, 0.3, value),
|
||||
value < 0.3 ? smoothstep(0.0, 0.3, value) : smoothstep(1.0, 0.6, value),
|
||||
smoothstep(0.4, 0.6, value)
|
||||
);
|
||||
}
|
||||
|
||||
void main () {
|
||||
vec2 p = gl_FragCoord.xy / resolution.xy;
|
||||
float sum = 0.0;
|
||||
for (int i = 0; i < MAX_POINTS; ++i) {
|
||||
if (i == pointsLength) break;
|
||||
vec4 point = points[i];
|
||||
sum += point.w * smoothstep(point.z, 0.0, distance(point.xy, p));
|
||||
}
|
||||
|
||||
gl_FragColor = vec4(heat(sum), 1.0);
|
||||
}
|
||||
@ -1,55 +1,55 @@
|
||||
//goog.provide('Heatmap');
|
||||
|
||||
//goog.require('og.node.RenderNode');
|
||||
|
||||
Heatmap = function () {
|
||||
og.inheritance.base(this);
|
||||
|
||||
this._verticesBuffer;
|
||||
|
||||
this.position = [0, 0, 0.3, 0.7];
|
||||
this.resolution = [800, 800];
|
||||
this.points = [0.6, 0.6, 0.3, 0.7, 0.8, 0.3, 0.2, 0.3, 0.3, 0.1, 0.2, 0.4];
|
||||
};
|
||||
|
||||
og.inheritance.extend(Heatmap, og.node.RenderNode);
|
||||
|
||||
Heatmap.prototype.initialization = function () {
|
||||
this.drawMode = this.renderer.handler.gl.TRIANGLES;
|
||||
|
||||
var vertices = [
|
||||
-1.0, -1.0,
|
||||
1.0, -1.0,
|
||||
-1.0, 1.0,
|
||||
-1.0, 1.0,
|
||||
1.0, -1.0,
|
||||
1.0, 1.0];
|
||||
|
||||
this._verticesBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(vertices), 2, vertices.length / 2);
|
||||
|
||||
this.renderer.events.on("onmousemove", this, this.onMouseMove);
|
||||
this.renderer.events.on("onmouselbuttondown", this, this.onMouseLeftButtonClick);
|
||||
};
|
||||
|
||||
Heatmap.prototype.onMouseMove = function (e) {
|
||||
this.position[0] = e.x / this.resolution[0];
|
||||
this.position[1] = this.renderer.handler.gl.canvas.height / this.resolution[1] - e.y / this.resolution[1];
|
||||
};
|
||||
|
||||
Heatmap.prototype.onMouseLeftButtonClick = function () {
|
||||
this.points.push.apply(this.points, this.position);
|
||||
};
|
||||
|
||||
Heatmap.prototype.frame = function () {
|
||||
|
||||
this.renderer.handler.shaderPrograms.heatmap.activate();
|
||||
|
||||
this.renderer.handler.shaderPrograms.heatmap.set({
|
||||
a_position: this._verticesBuffer,
|
||||
resolution: this.resolution,
|
||||
pointsLength: this.points.length / 4 + 1,
|
||||
points: this.position.concat(this.points)
|
||||
});
|
||||
|
||||
this.renderer.handler.shaderPrograms.heatmap.drawArray(this.drawMode, this._verticesBuffer.numItems);
|
||||
//goog.provide('Heatmap');
|
||||
|
||||
//goog.require('og.node.RenderNode');
|
||||
|
||||
Heatmap = function () {
|
||||
og.inheritance.base(this);
|
||||
|
||||
this._verticesBuffer;
|
||||
|
||||
this.position = [0, 0, 0.3, 0.7];
|
||||
this.resolution = [800, 800];
|
||||
this.points = [0.6, 0.6, 0.3, 0.7, 0.8, 0.3, 0.2, 0.3, 0.3, 0.1, 0.2, 0.4];
|
||||
};
|
||||
|
||||
og.inheritance.extend(Heatmap, og.node.RenderNode);
|
||||
|
||||
Heatmap.prototype.initialization = function () {
|
||||
this.drawMode = this.renderer.handler.gl.TRIANGLES;
|
||||
|
||||
var vertices = [
|
||||
-1.0, -1.0,
|
||||
1.0, -1.0,
|
||||
-1.0, 1.0,
|
||||
-1.0, 1.0,
|
||||
1.0, -1.0,
|
||||
1.0, 1.0];
|
||||
|
||||
this._verticesBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(vertices), 2, vertices.length / 2);
|
||||
|
||||
this.renderer.events.on("onmousemove", this, this.onMouseMove);
|
||||
this.renderer.events.on("onmouselbuttondown", this, this.onMouseLeftButtonClick);
|
||||
};
|
||||
|
||||
Heatmap.prototype.onMouseMove = function (e) {
|
||||
this.position[0] = e.x / this.resolution[0];
|
||||
this.position[1] = this.renderer.handler.gl.canvas.height / this.resolution[1] - e.y / this.resolution[1];
|
||||
};
|
||||
|
||||
Heatmap.prototype.onMouseLeftButtonClick = function () {
|
||||
this.points.push.apply(this.points, this.position);
|
||||
};
|
||||
|
||||
Heatmap.prototype.frame = function () {
|
||||
|
||||
this.renderer.handler.shaderPrograms.heatmap.activate();
|
||||
|
||||
this.renderer.handler.shaderPrograms.heatmap.set({
|
||||
a_position: this._verticesBuffer,
|
||||
resolution: this.resolution,
|
||||
pointsLength: this.points.length / 4 + 1,
|
||||
points: this.position.concat(this.points)
|
||||
});
|
||||
|
||||
this.renderer.handler.shaderPrograms.heatmap.drawArray(this.drawMode, this._verticesBuffer.numItems);
|
||||
};
|
||||
@ -1,20 +1,20 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>OpenGlobus - Earth planet</title>
|
||||
<link rel="stylesheet" href="../../css/og.css" type="text/css"/>
|
||||
|
||||
<!-- script src="../../../closure-library/closure/goog/base.js"></script -->
|
||||
<!-- script src="../../src/og/og-deps.js"></script -->
|
||||
|
||||
<!-- script src="my-deps.js"></script -->
|
||||
<script src="http://www.openglobus.org/og.js"></script>
|
||||
<script src="heatmap.js"></script>
|
||||
<script src="main.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body style="width: 100%; height: 100%; padding: 0; margin: 0;" onload="start();">
|
||||
<canvas id="canvas" style="width: 100%; height: 100%; display: block"></canvas>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<html>
|
||||
<head>
|
||||
<title>OpenGlobus - Earth planet</title>
|
||||
<link rel="stylesheet" href="../../css/og.css" type="text/css"/>
|
||||
|
||||
<!-- script src="../../../closure-library/closure/goog/base.js"></script -->
|
||||
<!-- script src="../../src/og/og-deps.js"></script -->
|
||||
|
||||
<!-- script src="my-deps.js"></script -->
|
||||
<script src="http://www.openglobus.org/og.js"></script>
|
||||
<script src="heatmap.js"></script>
|
||||
<script src="main.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body style="width: 100%; height: 100%; padding: 0; margin: 0;" onload="start();">
|
||||
<canvas id="canvas" style="width: 100%; height: 100%; display: block"></canvas>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@ -1,42 +1,42 @@
|
||||
//goog.require('og');
|
||||
//goog.require('og.webgl.Handler');
|
||||
//goog.require('og.Renderer');
|
||||
//goog.require('og.control.KeyboardNavigation');
|
||||
//goog.require('og.shaderProgram.shape');
|
||||
//goog.require('og.node.Axes');
|
||||
//goog.require('my.Heatmap');
|
||||
//goog.require('og.math.Vector3');
|
||||
//goog.require('og.utils');
|
||||
|
||||
function start() {
|
||||
|
||||
og.webgl.MAX_FRAME_DELAY = 15;
|
||||
|
||||
|
||||
var heatmap = new og.shaderProgram.ShaderProgram("heatmap", {
|
||||
uniforms: {
|
||||
resolution: { type: og.shaderProgram.types.VEC2 },
|
||||
type: { type: og.shaderProgram.types.FLOAT },
|
||||
points: { type: og.shaderProgram.types.VEC4 },
|
||||
pointsLength: { type: og.shaderProgram.types.INT }
|
||||
},
|
||||
attributes: {
|
||||
a_position: { type: og.shaderProgram.types.VEC2, enableArray: true }
|
||||
},
|
||||
//'attribute vec2 position; void main() { gl_Position = vec4(2.0*position-1.0, 0.0, 1.0);}'
|
||||
vertexShader: og.utils.readTextFile("vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile("fs.txt")
|
||||
});
|
||||
|
||||
context = new og.webgl.Handler("canvas");
|
||||
context.addShaderProgram(heatmap);
|
||||
context.init();
|
||||
|
||||
renderer = new og.Renderer(context);
|
||||
renderer.init();
|
||||
|
||||
hm = new Heatmap();
|
||||
renderer.addRenderNode(hm);
|
||||
|
||||
renderer.start();
|
||||
//goog.require('og');
|
||||
//goog.require('og.webgl.Handler');
|
||||
//goog.require('og.Renderer');
|
||||
//goog.require('og.control.KeyboardNavigation');
|
||||
//goog.require('og.shaderProgram.shape');
|
||||
//goog.require('og.node.Axes');
|
||||
//goog.require('my.Heatmap');
|
||||
//goog.require('og.math.Vector3');
|
||||
//goog.require('og.utils');
|
||||
|
||||
function start() {
|
||||
|
||||
og.webgl.MAX_FRAME_DELAY = 15;
|
||||
|
||||
|
||||
var heatmap = new og.shaderProgram.ShaderProgram("heatmap", {
|
||||
uniforms: {
|
||||
resolution: { type: og.shaderProgram.types.VEC2 },
|
||||
type: { type: og.shaderProgram.types.FLOAT },
|
||||
points: { type: og.shaderProgram.types.VEC4 },
|
||||
pointsLength: { type: og.shaderProgram.types.INT }
|
||||
},
|
||||
attributes: {
|
||||
a_position: { type: og.shaderProgram.types.VEC2, enableArray: true }
|
||||
},
|
||||
//'attribute vec2 position; void main() { gl_Position = vec4(2.0*position-1.0, 0.0, 1.0);}'
|
||||
vertexShader: og.utils.readTextFile("vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile("fs.txt")
|
||||
});
|
||||
|
||||
context = new og.webgl.Handler("canvas");
|
||||
context.addShaderProgram(heatmap);
|
||||
context.init();
|
||||
|
||||
renderer = new og.Renderer(context);
|
||||
renderer.init();
|
||||
|
||||
hm = new Heatmap();
|
||||
renderer.addRenderNode(hm);
|
||||
|
||||
renderer.start();
|
||||
};
|
||||
@ -1,3 +1,3 @@
|
||||
// This file was autogenerated by D:\my projects\closure-library\closure\bin\build\depswriter.py.
|
||||
// Please do not edit.
|
||||
goog.addDependency('../../../og/sandbox/heatmap/heatmap.js', ['my.Heatmap'], ['og.node.RenderNode']);
|
||||
// This file was autogenerated by D:\my projects\closure-library\closure\bin\build\depswriter.py.
|
||||
// Please do not edit.
|
||||
goog.addDependency('../../../og/sandbox/heatmap/heatmap.js', ['my.Heatmap'], ['og.node.RenderNode']);
|
||||
|
||||
@ -1 +1 @@
|
||||
"d:\my projects\closure-library\closure\bin\build\depswriter.py" --root_with_prefix="./ ../../../og/sandbox/heatmap/" > "d:\my projects\openglobus\sandbox\heatmap\my-deps.js"
|
||||
"e:\my projects\closure-library\closure\bin\build\depswriter.py" --root_with_prefix="./ ../../../og/sandbox/heatmap/" > "e:\my projects\openglobus\sandbox\heatmap\my-deps.js"
|
||||
@ -1,5 +1,5 @@
|
||||
attribute vec2 a_position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_position, 0, 1);
|
||||
attribute vec2 a_position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_position, 0, 1);
|
||||
}
|
||||
@ -1,18 +1,18 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>OpenGlobus - Earth planet</title>
|
||||
<link rel="stylesheet" href="../../css/og.css" type="text/css"/>
|
||||
|
||||
<script src="../../../closure-library/closure/goog/base.js"></script>
|
||||
<script src="../../src/og/og-deps.js"></script>
|
||||
|
||||
<script src="my-deps.js"></script>
|
||||
<script src="main.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body style="width: 100%; height: 100%; padding: 0; margin: 0;" onload="start();">
|
||||
<canvas id="canvas" style="width: 100%; height: 100%; display: block"></canvas>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<html>
|
||||
<head>
|
||||
<title>OpenGlobus - Earth planet</title>
|
||||
<link rel="stylesheet" href="../../css/og.css" type="text/css"/>
|
||||
|
||||
<script src="../../../closure-library/closure/goog/base.js"></script>
|
||||
<script src="../../src/og/og-deps.js"></script>
|
||||
|
||||
<script src="my-deps.js"></script>
|
||||
<script src="main.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body style="width: 100%; height: 100%; padding: 0; margin: 0;" onload="start();">
|
||||
<canvas id="canvas" style="width: 100%; height: 100%; display: block"></canvas>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@ -1,70 +1,70 @@
|
||||
goog.require('og.webgl.Handler');
|
||||
goog.require('og.Renderer');
|
||||
goog.require('og.control.SimpleNavigation');
|
||||
goog.require('og.shaderProgram');
|
||||
goog.require('og.node.Axes');
|
||||
goog.require('my.Plane');
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
function start() {
|
||||
|
||||
og.webgl.MAX_FRAME_DELAY = 15;
|
||||
|
||||
var flatShader = new og.shaderProgram.ShaderProgram("flat", {
|
||||
uniforms: {
|
||||
uPMVMatrix: { type: og.shaderProgram.types.MAT4 }
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true },
|
||||
aVertexColor: { type: og.shaderProgram.types.VEC4, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "flat_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "flat_fs.txt")
|
||||
});
|
||||
|
||||
var colorShader = new og.shaderProgram.ShaderProgram("colorShader", {
|
||||
uniforms: {
|
||||
uMVMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
uPMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
uNMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
|
||||
pointLightsPositions: { type: og.shaderProgram.types.VEC3 },
|
||||
pointLightsParamsv: { type: og.shaderProgram.types.VEC3 },
|
||||
pointLightsParamsf: { type: og.shaderProgram.types.FLOAT },
|
||||
|
||||
uSampler: { type: og.shaderProgram.types.SAMPLER2D },
|
||||
uNormalsMap: { type: og.shaderProgram.types.SAMPLER2D }
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true },
|
||||
aTextureCoord: { type: og.shaderProgram.types.VEC2, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile("plane_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile("plane_fs.txt")
|
||||
});
|
||||
|
||||
context = new og.webgl.Handler("canvas");
|
||||
context.addShaderProgram(flatShader);
|
||||
context.addShaderProgram(colorShader);
|
||||
context.init();
|
||||
|
||||
renderer = new og.Renderer(context);
|
||||
renderer.init();
|
||||
|
||||
var axes = new og.node.Axes(10000);
|
||||
|
||||
plane = new my.Plane("Plane");
|
||||
renderer.addRenderNode(axes);
|
||||
renderer.addRenderNode(plane);
|
||||
|
||||
renderer.addControls([
|
||||
new og.control.SimpleNavigation({ autoActivate: true }),
|
||||
]);
|
||||
|
||||
renderer.start();
|
||||
|
||||
renderer.activeCamera.eye.x = 1114.1424013103258;
|
||||
renderer.activeCamera.eye.y = 2086.749969128237;
|
||||
renderer.activeCamera.eye.z = 8824.474084480114;
|
||||
renderer.activeCamera.refresh();
|
||||
goog.require('og.webgl.Handler');
|
||||
goog.require('og.Renderer');
|
||||
goog.require('og.control.SimpleNavigation');
|
||||
goog.require('og.shaderProgram');
|
||||
goog.require('og.node.Axes');
|
||||
goog.require('my.Plane');
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
function start() {
|
||||
|
||||
og.webgl.MAX_FRAME_DELAY = 15;
|
||||
|
||||
var flatShader = new og.shaderProgram.ShaderProgram("flat", {
|
||||
uniforms: {
|
||||
uPMVMatrix: { type: og.shaderProgram.types.MAT4 }
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true },
|
||||
aVertexColor: { type: og.shaderProgram.types.VEC4, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "flat_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "flat_fs.txt")
|
||||
});
|
||||
|
||||
var colorShader = new og.shaderProgram.ShaderProgram("colorShader", {
|
||||
uniforms: {
|
||||
uMVMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
uPMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
uNMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
|
||||
pointLightsPositions: { type: og.shaderProgram.types.VEC3 },
|
||||
pointLightsParamsv: { type: og.shaderProgram.types.VEC3 },
|
||||
pointLightsParamsf: { type: og.shaderProgram.types.FLOAT },
|
||||
|
||||
uSampler: { type: og.shaderProgram.types.SAMPLER2D },
|
||||
uNormalsMap: { type: og.shaderProgram.types.SAMPLER2D }
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true },
|
||||
aTextureCoord: { type: og.shaderProgram.types.VEC2, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile("plane_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile("plane_fs.txt")
|
||||
});
|
||||
|
||||
context = new og.webgl.Handler("canvas");
|
||||
context.addShaderProgram(flatShader);
|
||||
context.addShaderProgram(colorShader);
|
||||
context.init();
|
||||
|
||||
renderer = new og.Renderer(context);
|
||||
renderer.init();
|
||||
|
||||
var axes = new og.node.Axes(10000);
|
||||
|
||||
plane = new my.Plane("Plane");
|
||||
renderer.addRenderNode(axes);
|
||||
renderer.addRenderNode(plane);
|
||||
|
||||
renderer.addControls([
|
||||
new og.control.SimpleNavigation({ autoActivate: true }),
|
||||
]);
|
||||
|
||||
renderer.start();
|
||||
|
||||
renderer.activeCamera.eye.x = 1114.1424013103258;
|
||||
renderer.activeCamera.eye.y = 2086.749969128237;
|
||||
renderer.activeCamera.eye.z = 8824.474084480114;
|
||||
renderer.activeCamera.refresh();
|
||||
};
|
||||
@ -1,3 +1,3 @@
|
||||
// This file was autogenerated by D:\my projects\closure-library\closure\bin\build\depswriter.py.
|
||||
// Please do not edit.
|
||||
goog.addDependency('../../../og/sandbox/plane/plane.js', ['my.Plane'], ['og.inheritance', 'og.light.PointLight', 'og.node.RenderNode', 'og.planetSegment.PlanetSegmentHelper', 'og.utils.NormalMapCreator']);
|
||||
// This file was autogenerated by D:\my projects\closure-library\closure\bin\build\depswriter.py.
|
||||
// Please do not edit.
|
||||
goog.addDependency('../../../og/sandbox/plane/plane.js', ['my.Plane'], ['og.inheritance', 'og.light.PointLight', 'og.node.RenderNode', 'og.planetSegment.PlanetSegmentHelper', 'og.utils.NormalMapCreator']);
|
||||
|
||||
@ -1,261 +1,261 @@
|
||||
goog.provide('my.Plane');
|
||||
|
||||
goog.require('og.node.RenderNode');
|
||||
goog.require('og.inheritance');
|
||||
goog.require('og.planetSegment.PlanetSegmentHelper');
|
||||
goog.require('og.light.PointLight');
|
||||
|
||||
goog.require('og.utils.NormalMapCreator');
|
||||
|
||||
|
||||
my.Plane = function (name) {
|
||||
og.inheritance.base(this, name);
|
||||
this.vertexPositionBuffer = null;
|
||||
this.indexBuffer = null;
|
||||
this.size = 30;
|
||||
|
||||
this.light = null;
|
||||
|
||||
this.texture = null;
|
||||
};
|
||||
|
||||
og.inheritance.extend(my.Plane, og.node.RenderNode);
|
||||
|
||||
my.Plane.prototype.normalsPack = function () {
|
||||
normalsPacked = [];
|
||||
for (var i = 0; i < normals.length; i++) {
|
||||
normalsPacked[i] = normals[i] * 0.5 + 0.5;
|
||||
}
|
||||
};
|
||||
|
||||
my.Plane.prototype.normalsUnpack = function () {
|
||||
normalsUnpacked = [];
|
||||
for (var i = 0; i < normals.length; i++) {
|
||||
normalsUnpacked[i] = (normalsPacked[i] - 0.5) * 2.0
|
||||
}
|
||||
};
|
||||
|
||||
my.Plane.prototype.initialization = function () {
|
||||
this.createBuffers();
|
||||
this.drawMode = this.renderer.handler.gl.TRIANGLE_STRIP;
|
||||
this.light = new og.light.PointLight();
|
||||
|
||||
this.light.setAmbient(new og.math.Vector3(0.14, 0.1, 0.2));
|
||||
this.light.setDiffuse(new og.math.Vector3(0.9, 0.9, 0.8));
|
||||
this.light.setSpecular(new og.math.Vector3(0.01, 0.01, 0.009));
|
||||
this.light.setShininess(8);
|
||||
this.light.addTo(this);
|
||||
this.light._position = new og.math.Vector3(5, 5, 5);
|
||||
|
||||
this.lightEnabled = true;
|
||||
|
||||
this.renderer.events.on("oncharkeypressed", this, this.toogleWireframe, og.input.KEY_X);
|
||||
this.renderer.events.on("oncharkeypressed", this, this.toogleLightPosition, og.input.KEY_C);
|
||||
|
||||
|
||||
this.normalMapHelper = new og.utils.NormalMapCreator();
|
||||
|
||||
var that = this;
|
||||
var segment = {
|
||||
terrainNormals: normals, createNormalMap: function (canvas) {
|
||||
that.normalsTexture = that.renderer.handler.createTexture(canvas);
|
||||
}
|
||||
};
|
||||
texture = this.normalMapHelper.draw(normals);
|
||||
that.normalsTexture = this.renderer.handler.createTexture(texture);
|
||||
//var img = new Image();
|
||||
//img.onload = function () {
|
||||
// that.normalsTexture = that.renderer.handler.createTexture(this);
|
||||
//};
|
||||
//img.src = "n_blur.png"
|
||||
};
|
||||
|
||||
my.Plane.prototype.toogleWireframe = function (e) {
|
||||
if (this.drawMode === this.renderer.handler.gl.LINE_STRIP) {
|
||||
this.drawMode = this.renderer.handler.gl.TRIANGLE_STRIP;
|
||||
} else {
|
||||
this.drawMode = this.renderer.handler.gl.LINE_STRIP;
|
||||
}
|
||||
};
|
||||
|
||||
my.Plane.prototype.toogleLightPosition = function () {
|
||||
this.light._position = this.renderer.activeCamera.eye.clone();
|
||||
};
|
||||
|
||||
my.Plane.prototype.createBuffers = function () {
|
||||
og.planetSegment.PlanetSegmentHelper.initIndexesTables(6);
|
||||
|
||||
|
||||
vertices = [];
|
||||
vertices0 = [];
|
||||
|
||||
var step = 1;
|
||||
var size = 32;
|
||||
|
||||
for (var i = 0; i <= size; i++) {
|
||||
for (var j = 0; j <= size; j++) {
|
||||
var x = j * step,
|
||||
y = (size) * step - i * step,
|
||||
z = Math.sin(1 * x / 2) * Math.cos(1 * y / 2) * 8600;
|
||||
|
||||
var z0 = 0;
|
||||
|
||||
vertices.push(x * this.size * 20, y * this.size * 20, z);
|
||||
vertices0.push(x * this.size * 20, y * this.size * 20, z0);
|
||||
}
|
||||
}
|
||||
|
||||
vertices0 = vertices;
|
||||
|
||||
var gs = size + 1;
|
||||
normals = new Float64Array(gs * gs * 3);
|
||||
|
||||
var vertexIndices = og.planetSegment.PlanetSegmentHelper.createSegmentIndexes(size, [size, size, size, size]);
|
||||
|
||||
|
||||
for (var i = 0; i < gs - 1; i++) {
|
||||
for (var j = 0; j < gs - 1; j++) {
|
||||
|
||||
var vInd0 = (i * gs + j) * 3;
|
||||
var vInd1 = (i * gs + j + 1) * 3;
|
||||
var vInd2 = ((i + 1) * gs + j) * 3;
|
||||
var vInd3 = ((i + 1) * gs + (j + 1)) * 3;
|
||||
|
||||
var v0 = new og.math.Vector3(vertices[vInd0], vertices[vInd0 + 1], vertices[vInd0 + 2]),
|
||||
v1 = new og.math.Vector3(vertices[vInd1], vertices[vInd1 + 1], vertices[vInd1 + 2]),
|
||||
v2 = new og.math.Vector3(vertices[vInd2], vertices[vInd2 + 1], vertices[vInd2 + 2]),
|
||||
v3 = new og.math.Vector3(vertices[vInd3], vertices[vInd3 + 1], vertices[vInd3 + 2]);
|
||||
|
||||
var e10 = og.math.Vector3.sub(v1, v0),
|
||||
e20 = og.math.Vector3.sub(v2, v0),
|
||||
e30 = og.math.Vector3.sub(v3, v0);
|
||||
|
||||
var sw = e20.cross(e30);//.normalize();
|
||||
var ne = e30.cross(e10);//.normalize();
|
||||
|
||||
var n0 = og.math.Vector3.add(ne, sw);
|
||||
var n3 = og.math.Vector3.add(ne, sw);
|
||||
var n1 = og.math.Vector3.add(ne, sw);
|
||||
var n2 = og.math.Vector3.add(ne, sw);
|
||||
|
||||
//n0.normalize();
|
||||
//n1.normalize();
|
||||
//n3.normalize();
|
||||
//n2.normalize();
|
||||
|
||||
normals[vInd0] += n0.x;
|
||||
normals[vInd0 + 1] += n0.y;
|
||||
normals[vInd0 + 2] += n0.z;
|
||||
|
||||
normals[vInd1] += n1.x;
|
||||
normals[vInd1 + 1] += n1.y;
|
||||
normals[vInd1 + 2] += n1.z;
|
||||
|
||||
normals[vInd2] += n2.x;
|
||||
normals[vInd2 + 1] += n2.y;
|
||||
normals[vInd2 + 2] += n2.z;
|
||||
|
||||
normals[vInd3] += n3.x;
|
||||
normals[vInd3 + 1] += n3.y;
|
||||
normals[vInd3 + 2] += n3.z;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (var i = 0; i < normals.length; i += 3) {
|
||||
var l = Math.sqrt(normals[i] * normals[i] + normals[i + 1] * normals[i + 1] + normals[i + 2] * normals[i + 2]);
|
||||
normals[i] /= l;
|
||||
normals[i + 1] /= l;
|
||||
normals[i + 2] /= l;
|
||||
}
|
||||
|
||||
var textureCoords = og.planetSegment.PlanetSegmentHelper.textureCoordsTable[size];
|
||||
|
||||
this.positionBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(vertices0), 3, vertices0.length / 3);
|
||||
//this.normalBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(normals), 3, normals.length / 3);
|
||||
this.textureCoordBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(textureCoords), 2, textureCoords.length / 2);
|
||||
this.indexBuffer = this.renderer.handler.createElementArrayBuffer(new Uint16Array(vertexIndices), 1, vertexIndices.length);
|
||||
|
||||
|
||||
var lines = [];
|
||||
var colors = [];
|
||||
for (var i = 0; i < normals.length; i += 3) {
|
||||
|
||||
lines.push(vertices[i], vertices[i + 1], vertices[i + 2],
|
||||
vertices[i] + normals[i] * 100, vertices[i + 1] + normals[i + 1] * 100, vertices[i + 2] + normals[i + 2] * 100);
|
||||
|
||||
colors.push(1.0, 0.0, 0.0, 1.0,
|
||||
1.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
this.linesBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(lines), 3, 2 * vertices.length / 3);
|
||||
this.linesColorBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(colors), 4, 2 * vertices.length / 3);
|
||||
};
|
||||
|
||||
my.Plane.prototype.frame = function () {
|
||||
|
||||
var r = this.renderer;
|
||||
|
||||
var sh, p, gl;
|
||||
|
||||
//
|
||||
// Draw surface
|
||||
sh = r.handler.shaderPrograms.colorShader;
|
||||
p = sh._program;
|
||||
gl = r.handler.gl,
|
||||
sha = p.attributes,
|
||||
shu = p.uniforms;
|
||||
|
||||
sh.activate();
|
||||
|
||||
//gl.uniform4fv(shu.uColor._pName, [1, 1, 1, 1]);
|
||||
|
||||
//point light
|
||||
gl.uniform3fv(shu.pointLightsPositions._pName, this._pointLightsTransformedPositions);
|
||||
gl.uniform3fv(shu.pointLightsParamsv._pName, this._pointLightsParamsv);
|
||||
gl.uniform1fv(shu.pointLightsParamsf._pName, this._pointLightsParamsf);
|
||||
|
||||
//matrices
|
||||
gl.uniformMatrix4fv(shu.uPMatrix._pName, false, r.activeCamera.pMatrix._m);
|
||||
gl.uniformMatrix4fv(shu.uMVMatrix._pName, false, r.activeCamera.mvMatrix._m);
|
||||
gl.uniformMatrix3fv(shu.uNMatrix._pName, false, r.activeCamera.nMatrix._m);
|
||||
|
||||
//diffuse texture
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.normalsTexture);
|
||||
gl.uniform1i(shu.uSampler._pName, 0);
|
||||
|
||||
gl.activeTexture(gl.TEXTURE1);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.normalsTexture);
|
||||
gl.uniform1i(shu.uNormalsMap._pName, 1);
|
||||
|
||||
|
||||
//normals
|
||||
//gl.bindBuffer(gl.ARRAY_BUFFER, this.normalBuffer);
|
||||
//gl.vertexAttribPointer(sha.aVertexNormal._pName, this.normalBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
||||
|
||||
//vertices positions
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer);
|
||||
gl.vertexAttribPointer(sha.aVertexPosition._pName, this.positionBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
||||
|
||||
//texture coordinates
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.textureCoordBuffer);
|
||||
gl.vertexAttribPointer(sha.aTextureCoord._pName, this.textureCoordBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
||||
|
||||
//draw indexes
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
||||
gl.drawElements(this.drawMode, this.indexBuffer.numItems, gl.UNSIGNED_SHORT, 0);
|
||||
|
||||
|
||||
//
|
||||
//Draw normals
|
||||
//r.handler.shaderPrograms.flat.activate();
|
||||
|
||||
//r.handler.shaderPrograms.flat.set({
|
||||
// uPMVMatrix: r.activeCamera.pmvMatrix._m,
|
||||
// aVertexPosition: this.linesBuffer,
|
||||
// aVertexColor: this.linesColorBuffer
|
||||
//});
|
||||
//r.handler.shaderPrograms.flat.drawArray(r.handler.gl.LINES, this.linesBuffer.numItems);
|
||||
|
||||
goog.provide('my.Plane');
|
||||
|
||||
goog.require('og.node.RenderNode');
|
||||
goog.require('og.inheritance');
|
||||
goog.require('og.planetSegment.PlanetSegmentHelper');
|
||||
goog.require('og.light.PointLight');
|
||||
|
||||
goog.require('og.utils.NormalMapCreator');
|
||||
|
||||
|
||||
my.Plane = function (name) {
|
||||
og.inheritance.base(this, name);
|
||||
this.vertexPositionBuffer = null;
|
||||
this.indexBuffer = null;
|
||||
this.size = 30;
|
||||
|
||||
this.light = null;
|
||||
|
||||
this.texture = null;
|
||||
};
|
||||
|
||||
og.inheritance.extend(my.Plane, og.node.RenderNode);
|
||||
|
||||
my.Plane.prototype.normalsPack = function () {
|
||||
normalsPacked = [];
|
||||
for (var i = 0; i < normals.length; i++) {
|
||||
normalsPacked[i] = normals[i] * 0.5 + 0.5;
|
||||
}
|
||||
};
|
||||
|
||||
my.Plane.prototype.normalsUnpack = function () {
|
||||
normalsUnpacked = [];
|
||||
for (var i = 0; i < normals.length; i++) {
|
||||
normalsUnpacked[i] = (normalsPacked[i] - 0.5) * 2.0
|
||||
}
|
||||
};
|
||||
|
||||
my.Plane.prototype.initialization = function () {
|
||||
this.createBuffers();
|
||||
this.drawMode = this.renderer.handler.gl.TRIANGLE_STRIP;
|
||||
this.light = new og.light.PointLight();
|
||||
|
||||
this.light.setAmbient(new og.math.Vector3(0.14, 0.1, 0.2));
|
||||
this.light.setDiffuse(new og.math.Vector3(0.9, 0.9, 0.8));
|
||||
this.light.setSpecular(new og.math.Vector3(0.01, 0.01, 0.009));
|
||||
this.light.setShininess(8);
|
||||
this.light.addTo(this);
|
||||
this.light._position = new og.math.Vector3(5, 5, 5);
|
||||
|
||||
this.lightEnabled = true;
|
||||
|
||||
this.renderer.events.on("oncharkeypressed", this, this.toogleWireframe, og.input.KEY_X);
|
||||
this.renderer.events.on("oncharkeypressed", this, this.toogleLightPosition, og.input.KEY_C);
|
||||
|
||||
|
||||
this.normalMapHelper = new og.utils.NormalMapCreator();
|
||||
|
||||
var that = this;
|
||||
var segment = {
|
||||
terrainNormals: normals, createNormalMap: function (canvas) {
|
||||
that.normalsTexture = that.renderer.handler.createTexture(canvas);
|
||||
}
|
||||
};
|
||||
texture = this.normalMapHelper.draw(normals);
|
||||
that.normalsTexture = this.renderer.handler.createTexture(texture);
|
||||
//var img = new Image();
|
||||
//img.onload = function () {
|
||||
// that.normalsTexture = that.renderer.handler.createTexture(this);
|
||||
//};
|
||||
//img.src = "n_blur.png"
|
||||
};
|
||||
|
||||
my.Plane.prototype.toogleWireframe = function (e) {
|
||||
if (this.drawMode === this.renderer.handler.gl.LINE_STRIP) {
|
||||
this.drawMode = this.renderer.handler.gl.TRIANGLE_STRIP;
|
||||
} else {
|
||||
this.drawMode = this.renderer.handler.gl.LINE_STRIP;
|
||||
}
|
||||
};
|
||||
|
||||
my.Plane.prototype.toogleLightPosition = function () {
|
||||
this.light._position = this.renderer.activeCamera.eye.clone();
|
||||
};
|
||||
|
||||
my.Plane.prototype.createBuffers = function () {
|
||||
og.planetSegment.PlanetSegmentHelper.initIndexesTables(6);
|
||||
|
||||
|
||||
vertices = [];
|
||||
vertices0 = [];
|
||||
|
||||
var step = 1;
|
||||
var size = 32;
|
||||
|
||||
for (var i = 0; i <= size; i++) {
|
||||
for (var j = 0; j <= size; j++) {
|
||||
var x = j * step,
|
||||
y = (size) * step - i * step,
|
||||
z = Math.sin(1 * x / 2) * Math.cos(1 * y / 2) * 8600;
|
||||
|
||||
var z0 = 0;
|
||||
|
||||
vertices.push(x * this.size * 20, y * this.size * 20, z);
|
||||
vertices0.push(x * this.size * 20, y * this.size * 20, z0);
|
||||
}
|
||||
}
|
||||
|
||||
vertices0 = vertices;
|
||||
|
||||
var gs = size + 1;
|
||||
normals = new Float64Array(gs * gs * 3);
|
||||
|
||||
var vertexIndices = og.planetSegment.PlanetSegmentHelper.createSegmentIndexes(size, [size, size, size, size]);
|
||||
|
||||
|
||||
for (var i = 0; i < gs - 1; i++) {
|
||||
for (var j = 0; j < gs - 1; j++) {
|
||||
|
||||
var vInd0 = (i * gs + j) * 3;
|
||||
var vInd1 = (i * gs + j + 1) * 3;
|
||||
var vInd2 = ((i + 1) * gs + j) * 3;
|
||||
var vInd3 = ((i + 1) * gs + (j + 1)) * 3;
|
||||
|
||||
var v0 = new og.math.Vector3(vertices[vInd0], vertices[vInd0 + 1], vertices[vInd0 + 2]),
|
||||
v1 = new og.math.Vector3(vertices[vInd1], vertices[vInd1 + 1], vertices[vInd1 + 2]),
|
||||
v2 = new og.math.Vector3(vertices[vInd2], vertices[vInd2 + 1], vertices[vInd2 + 2]),
|
||||
v3 = new og.math.Vector3(vertices[vInd3], vertices[vInd3 + 1], vertices[vInd3 + 2]);
|
||||
|
||||
var e10 = og.math.Vector3.sub(v1, v0),
|
||||
e20 = og.math.Vector3.sub(v2, v0),
|
||||
e30 = og.math.Vector3.sub(v3, v0);
|
||||
|
||||
var sw = e20.cross(e30);//.normalize();
|
||||
var ne = e30.cross(e10);//.normalize();
|
||||
|
||||
var n0 = og.math.Vector3.add(ne, sw);
|
||||
var n3 = og.math.Vector3.add(ne, sw);
|
||||
var n1 = og.math.Vector3.add(ne, sw);
|
||||
var n2 = og.math.Vector3.add(ne, sw);
|
||||
|
||||
//n0.normalize();
|
||||
//n1.normalize();
|
||||
//n3.normalize();
|
||||
//n2.normalize();
|
||||
|
||||
normals[vInd0] += n0.x;
|
||||
normals[vInd0 + 1] += n0.y;
|
||||
normals[vInd0 + 2] += n0.z;
|
||||
|
||||
normals[vInd1] += n1.x;
|
||||
normals[vInd1 + 1] += n1.y;
|
||||
normals[vInd1 + 2] += n1.z;
|
||||
|
||||
normals[vInd2] += n2.x;
|
||||
normals[vInd2 + 1] += n2.y;
|
||||
normals[vInd2 + 2] += n2.z;
|
||||
|
||||
normals[vInd3] += n3.x;
|
||||
normals[vInd3 + 1] += n3.y;
|
||||
normals[vInd3 + 2] += n3.z;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (var i = 0; i < normals.length; i += 3) {
|
||||
var l = Math.sqrt(normals[i] * normals[i] + normals[i + 1] * normals[i + 1] + normals[i + 2] * normals[i + 2]);
|
||||
normals[i] /= l;
|
||||
normals[i + 1] /= l;
|
||||
normals[i + 2] /= l;
|
||||
}
|
||||
|
||||
var textureCoords = og.planetSegment.PlanetSegmentHelper.textureCoordsTable[size];
|
||||
|
||||
this.positionBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(vertices0), 3, vertices0.length / 3);
|
||||
//this.normalBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(normals), 3, normals.length / 3);
|
||||
this.textureCoordBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(textureCoords), 2, textureCoords.length / 2);
|
||||
this.indexBuffer = this.renderer.handler.createElementArrayBuffer(new Uint16Array(vertexIndices), 1, vertexIndices.length);
|
||||
|
||||
|
||||
var lines = [];
|
||||
var colors = [];
|
||||
for (var i = 0; i < normals.length; i += 3) {
|
||||
|
||||
lines.push(vertices[i], vertices[i + 1], vertices[i + 2],
|
||||
vertices[i] + normals[i] * 100, vertices[i + 1] + normals[i + 1] * 100, vertices[i + 2] + normals[i + 2] * 100);
|
||||
|
||||
colors.push(1.0, 0.0, 0.0, 1.0,
|
||||
1.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
this.linesBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(lines), 3, 2 * vertices.length / 3);
|
||||
this.linesColorBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(colors), 4, 2 * vertices.length / 3);
|
||||
};
|
||||
|
||||
my.Plane.prototype.frame = function () {
|
||||
|
||||
var r = this.renderer;
|
||||
|
||||
var sh, p, gl;
|
||||
|
||||
//
|
||||
// Draw surface
|
||||
sh = r.handler.shaderPrograms.colorShader;
|
||||
p = sh._program;
|
||||
gl = r.handler.gl,
|
||||
sha = p.attributes,
|
||||
shu = p.uniforms;
|
||||
|
||||
sh.activate();
|
||||
|
||||
//gl.uniform4fv(shu.uColor._pName, [1, 1, 1, 1]);
|
||||
|
||||
//point light
|
||||
gl.uniform3fv(shu.pointLightsPositions._pName, this._pointLightsTransformedPositions);
|
||||
gl.uniform3fv(shu.pointLightsParamsv._pName, this._pointLightsParamsv);
|
||||
gl.uniform1fv(shu.pointLightsParamsf._pName, this._pointLightsParamsf);
|
||||
|
||||
//matrices
|
||||
gl.uniformMatrix4fv(shu.uPMatrix._pName, false, r.activeCamera.pMatrix._m);
|
||||
gl.uniformMatrix4fv(shu.uMVMatrix._pName, false, r.activeCamera.mvMatrix._m);
|
||||
gl.uniformMatrix3fv(shu.uNMatrix._pName, false, r.activeCamera.nMatrix._m);
|
||||
|
||||
//diffuse texture
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.normalsTexture);
|
||||
gl.uniform1i(shu.uSampler._pName, 0);
|
||||
|
||||
gl.activeTexture(gl.TEXTURE1);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.normalsTexture);
|
||||
gl.uniform1i(shu.uNormalsMap._pName, 1);
|
||||
|
||||
|
||||
//normals
|
||||
//gl.bindBuffer(gl.ARRAY_BUFFER, this.normalBuffer);
|
||||
//gl.vertexAttribPointer(sha.aVertexNormal._pName, this.normalBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
||||
|
||||
//vertices positions
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer);
|
||||
gl.vertexAttribPointer(sha.aVertexPosition._pName, this.positionBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
||||
|
||||
//texture coordinates
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.textureCoordBuffer);
|
||||
gl.vertexAttribPointer(sha.aTextureCoord._pName, this.textureCoordBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
||||
|
||||
//draw indexes
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
||||
gl.drawElements(this.drawMode, this.indexBuffer.numItems, gl.UNSIGNED_SHORT, 0);
|
||||
|
||||
|
||||
//
|
||||
//Draw normals
|
||||
//r.handler.shaderPrograms.flat.activate();
|
||||
|
||||
//r.handler.shaderPrograms.flat.set({
|
||||
// uPMVMatrix: r.activeCamera.pmvMatrix._m,
|
||||
// aVertexPosition: this.linesBuffer,
|
||||
// aVertexColor: this.linesColorBuffer
|
||||
//});
|
||||
//r.handler.shaderPrograms.flat.drawArray(r.handler.gl.LINES, this.linesBuffer.numItems);
|
||||
|
||||
};
|
||||
@ -1,42 +1,42 @@
|
||||
precision highp float;
|
||||
|
||||
varying vec4 vPosition;
|
||||
varying vec2 vTextureCoord;
|
||||
varying mat3 v_NMatrix;
|
||||
|
||||
uniform sampler2D uSampler;
|
||||
uniform sampler2D uNormalsMap;
|
||||
|
||||
#define MAX_POINT_LIGHTS 1
|
||||
|
||||
uniform int pointLightsQuantity;
|
||||
uniform vec3 pointLightsPositions[MAX_POINT_LIGHTS];
|
||||
uniform vec3 pointLightsParamsv[MAX_POINT_LIGHTS * 3];
|
||||
uniform float pointLightsParamsf[MAX_POINT_LIGHTS];
|
||||
|
||||
void main(void) {
|
||||
|
||||
vec3 lightWeighting;
|
||||
vec3 lightDirection;
|
||||
vec3 normal;
|
||||
vec3 eyeDirection;
|
||||
vec3 reflectionDirection;
|
||||
float specularLightWeighting;
|
||||
float diffuseLightWeighting;
|
||||
|
||||
//i=0
|
||||
lightDirection = normalize(pointLightsPositions[0] - vPosition.xyz);
|
||||
//float distance = length(dir);
|
||||
//float attenuation = 1.0/(1.0+0.1*distance+0.01*distance*distance);
|
||||
vec4 normalColor = texture2D(uNormalsMap, vTextureCoord);
|
||||
vec4 nc = (normalColor - 0.5) * 2.0;
|
||||
normal = normalize(v_NMatrix * normalize(nc.xyz));
|
||||
eyeDirection = normalize(-vPosition.xyz);
|
||||
reflectionDirection = reflect(-lightDirection, normal);
|
||||
specularLightWeighting = pow(max(dot(reflectionDirection, eyeDirection), 0.0), pointLightsParamsf[0]);
|
||||
diffuseLightWeighting = max(dot(normal, lightDirection), 0.0);
|
||||
lightWeighting = pointLightsParamsv[0] + pointLightsParamsv[1] * diffuseLightWeighting + pointLightsParamsv[2] * specularLightWeighting;
|
||||
|
||||
vec4 tColor = texture2D( uSampler, vTextureCoord.st );
|
||||
gl_FragColor = vec4(/*tColor.rgb*/vec3(1.0) * lightWeighting, 1.0);
|
||||
precision highp float;
|
||||
|
||||
varying vec4 vPosition;
|
||||
varying vec2 vTextureCoord;
|
||||
varying mat3 v_NMatrix;
|
||||
|
||||
uniform sampler2D uSampler;
|
||||
uniform sampler2D uNormalsMap;
|
||||
|
||||
#define MAX_POINT_LIGHTS 1
|
||||
|
||||
uniform int pointLightsQuantity;
|
||||
uniform vec3 pointLightsPositions[MAX_POINT_LIGHTS];
|
||||
uniform vec3 pointLightsParamsv[MAX_POINT_LIGHTS * 3];
|
||||
uniform float pointLightsParamsf[MAX_POINT_LIGHTS];
|
||||
|
||||
void main(void) {
|
||||
|
||||
vec3 lightWeighting;
|
||||
vec3 lightDirection;
|
||||
vec3 normal;
|
||||
vec3 eyeDirection;
|
||||
vec3 reflectionDirection;
|
||||
float specularLightWeighting;
|
||||
float diffuseLightWeighting;
|
||||
|
||||
//i=0
|
||||
lightDirection = normalize(pointLightsPositions[0] - vPosition.xyz);
|
||||
//float distance = length(dir);
|
||||
//float attenuation = 1.0/(1.0+0.1*distance+0.01*distance*distance);
|
||||
vec4 normalColor = texture2D(uNormalsMap, vTextureCoord);
|
||||
vec4 nc = (normalColor - 0.5) * 2.0;
|
||||
normal = normalize(v_NMatrix * normalize(nc.xyz));
|
||||
eyeDirection = normalize(-vPosition.xyz);
|
||||
reflectionDirection = reflect(-lightDirection, normal);
|
||||
specularLightWeighting = pow(max(dot(reflectionDirection, eyeDirection), 0.0), pointLightsParamsf[0]);
|
||||
diffuseLightWeighting = max(dot(normal, lightDirection), 0.0);
|
||||
lightWeighting = pointLightsParamsv[0] + pointLightsParamsv[1] * diffuseLightWeighting + pointLightsParamsv[2] * specularLightWeighting;
|
||||
|
||||
vec4 tColor = texture2D( uSampler, vTextureCoord.st );
|
||||
gl_FragColor = vec4(/*tColor.rgb*/vec3(1.0) * lightWeighting, 1.0);
|
||||
}
|
||||
@ -1,19 +1,19 @@
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec2 aTextureCoord;
|
||||
|
||||
uniform mat4 uPMatrix;
|
||||
uniform mat4 uMVMatrix;
|
||||
uniform mat3 uNMatrix;
|
||||
|
||||
varying vec3 vTransformedNormal;
|
||||
varying vec4 vPosition;
|
||||
varying vec2 vTextureCoord;
|
||||
|
||||
varying mat3 v_NMatrix;
|
||||
|
||||
void main(void) {
|
||||
vPosition = uMVMatrix * vec4(aVertexPosition, 1.0);
|
||||
vTextureCoord = aTextureCoord;
|
||||
v_NMatrix = uNMatrix;
|
||||
gl_Position = uPMatrix * vPosition;
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec2 aTextureCoord;
|
||||
|
||||
uniform mat4 uPMatrix;
|
||||
uniform mat4 uMVMatrix;
|
||||
uniform mat3 uNMatrix;
|
||||
|
||||
varying vec3 vTransformedNormal;
|
||||
varying vec4 vPosition;
|
||||
varying vec2 vTextureCoord;
|
||||
|
||||
varying mat3 v_NMatrix;
|
||||
|
||||
void main(void) {
|
||||
vPosition = uMVMatrix * vec4(aVertexPosition, 1.0);
|
||||
vTextureCoord = aTextureCoord;
|
||||
v_NMatrix = uNMatrix;
|
||||
gl_Position = uPMatrix * vPosition;
|
||||
}
|
||||
@ -1,19 +1,19 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>OpenGlobus - Earth planet</title>
|
||||
<link rel="stylesheet" href="../../css/spinner.css" type="text/css"/>
|
||||
<link rel="stylesheet" href="../../css/og.css" type="text/css"/>
|
||||
|
||||
<script src="../../../closure-library/closure/goog/base.js"></script>
|
||||
<script src="../../src/og/og-deps.js"></script>
|
||||
|
||||
<script src="my-deps.js"></script>
|
||||
<script src="main.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body style="width: 100%; height: 100%; padding: 0; margin: 0;" onload="start();">
|
||||
<canvas id="canvas" style="width: 100%; height: 100%; display: block"></canvas>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<html>
|
||||
<head>
|
||||
<title>OpenGlobus - Earth planet</title>
|
||||
<link rel="stylesheet" href="../../css/spinner.css" type="text/css"/>
|
||||
<link rel="stylesheet" href="../../css/og.css" type="text/css"/>
|
||||
|
||||
<script src="../../../closure-library/closure/goog/base.js"></script>
|
||||
<script src="../../src/og/og-deps.js"></script>
|
||||
|
||||
<script src="my-deps.js"></script>
|
||||
<script src="main.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body style="width: 100%; height: 100%; padding: 0; margin: 0;" onload="start();">
|
||||
<canvas id="canvas" style="width: 100%; height: 100%; display: block"></canvas>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@ -1,219 +1,219 @@
|
||||
var StripNode = function (size) {
|
||||
StripNode.superclass.constructor.call(this, "CUBE");
|
||||
this.size = size * 0.5;
|
||||
//this.cubeVertexColorBuffer = null;
|
||||
this.cubeVertexPositionBuffer = null;
|
||||
this.cubeVertexIndexBuffer = null;
|
||||
|
||||
this.texture;
|
||||
this.textureImageFileName;
|
||||
this.cubeVertexTextureCoordBuffer = null;
|
||||
}
|
||||
|
||||
extend(StripNode, Node3D);
|
||||
|
||||
StripNode.prototype.initialization = function () {
|
||||
|
||||
this.initTexture("nehe.jpg");
|
||||
this.createBuffers();
|
||||
this.drawMode = WebGLContext.GL_TRIANGLE_STRIP;
|
||||
}
|
||||
|
||||
StripNode.prototype.initTexture = function (fileName) {
|
||||
var image = new Image();
|
||||
var handle = this;
|
||||
image.onload = function () {
|
||||
handle.texture = handle.renderer.ctx.createTextureFromImage(image);
|
||||
}
|
||||
image.src = this.textureImageFileName = fileName;
|
||||
}
|
||||
|
||||
StripNode.prototype.frame = function () {
|
||||
this.renderer.ctx.bindTexture(this.texture);
|
||||
this.renderer.ctx.setTextureBias([0, 0, 1]);
|
||||
this.renderer.ctx.drawBuffer(this.cubeVertexPositionBuffer, this.cubeVertexTextureCoordBuffer, this.cubeVertexIndexBuffer);
|
||||
}
|
||||
|
||||
|
||||
//StripNode.createCenterBody = function (width, height, indexes) {
|
||||
|
||||
// var i0 = 1,
|
||||
// j0 = 1;
|
||||
|
||||
// var i1 = 1,
|
||||
// j1 = 1;
|
||||
|
||||
// var ind1, ind2, nr;
|
||||
// for (var i = i0; i < height - 1 - i1; i++) {
|
||||
// for (var j = j0; j < width - j1; j++) {
|
||||
// ind1 = i * width + j;
|
||||
// nr = (i + 1) * width;
|
||||
// ind2 = nr + j;
|
||||
// indexes.push(ind1, ind2);
|
||||
// }
|
||||
// indexes.push(ind2, nr + j0);
|
||||
// }
|
||||
// indexes.push(indexes[indexes.length - 1], width * height - width);
|
||||
//}
|
||||
|
||||
//StripNode.createWestNeighborSkirt = function (width, height, deltaGr, indexes) {
|
||||
// var grCount = (width - 1) / deltaGr;
|
||||
// var b = width * height - width;
|
||||
// var k = 0;
|
||||
// for (var i = 0; i < height - 2; i++) {
|
||||
// if (i % grCount === 0) {
|
||||
// k = i;
|
||||
// }
|
||||
// var rind = b - width * i - width + 1,
|
||||
// lind = b - width * k;
|
||||
// indexes.push(lind, rind);
|
||||
// }
|
||||
|
||||
// if (deltaGr === (height - 1)) {
|
||||
// indexes.push(width);
|
||||
// indexes.push(0);
|
||||
// }
|
||||
//}
|
||||
|
||||
//StripNode.createNorthNeighborSkirt = function (width, height, deltaGr, indexes) {
|
||||
// var grCount = (width - 1) / deltaGr;
|
||||
// var k = 0;
|
||||
// for (var i = 0; i < height - 2; i++) {
|
||||
// if (i % grCount === 0) {
|
||||
// k = i;
|
||||
// }
|
||||
// var rind = width + i + 1,
|
||||
// lind = k;
|
||||
// indexes.push(lind, rind);
|
||||
// }
|
||||
|
||||
// if (deltaGr === (width - 1)) {
|
||||
// indexes.push(width - 2);
|
||||
// indexes.push(width - 1);
|
||||
// }
|
||||
//}
|
||||
|
||||
//StripNode.createEastNeighborSkirt = function (width, height, deltaGr, indexes) {
|
||||
// var grCount = (width - 1) / deltaGr;
|
||||
// var k = 0;
|
||||
// for (var i = 0; i < height - 2; i++) {
|
||||
// if (i % grCount === 0) {
|
||||
// k = i;
|
||||
// }
|
||||
// var rind = width * (i + 1) + width - 2,
|
||||
// lind = width + width * k - 1;
|
||||
// indexes.push(lind, rind);
|
||||
// }
|
||||
|
||||
// if (deltaGr === (height - 1)) {
|
||||
// indexes.push(width * (height - 1) - 1);
|
||||
// indexes.push(width * height - 1);
|
||||
// }
|
||||
//}
|
||||
|
||||
//StripNode.createSouthNeighborSkirt = function (width, height, deltaGr, indexes) {
|
||||
// var grCount = (width - 1) / deltaGr;
|
||||
// var k = 0;
|
||||
// var rb = width * (height - 1) - 2;
|
||||
// var lb = width * height - 1;
|
||||
// for (var i = 0; i < height - 2; i++) {
|
||||
// if (i % grCount === 0) {
|
||||
// k = i;
|
||||
// }
|
||||
// var rind = rb - i,
|
||||
// lind = lb - k;
|
||||
// indexes.push(lind, rind);
|
||||
// }
|
||||
|
||||
// if (deltaGr === (width - 1)) {
|
||||
// indexes.push(width * height - width + 1);
|
||||
// }
|
||||
// indexes.push(width * height - width);
|
||||
//}
|
||||
|
||||
//StripNode.initIndexesBodySkirts = function (pow) {
|
||||
// var table = [];
|
||||
// table[N] = [];
|
||||
// table[W] = [];
|
||||
// table[S] = [];
|
||||
// table[E] = [];
|
||||
|
||||
// for (var i = 0; i <= pow; i++) {
|
||||
// var d = Math.pow(2, i);
|
||||
// table[N][d+1] = [];
|
||||
// table[W][d+1] = [];
|
||||
// table[S][d+1] = [];
|
||||
// table[E][d+1] = [];
|
||||
// for (var j = 0; j <= pow; j++) {
|
||||
// var dd = Math.pow(2, j);
|
||||
// var nt = table[N][d+1][dd] = [];
|
||||
// var wt = table[W][d+1][dd] = [];
|
||||
// var st = table[S][d+1][dd] = [];
|
||||
// var et = table[E][d+1][dd] = [];
|
||||
// StripNode.createWestNeighborSkirt(d + 1, d + 1, dd, wt);
|
||||
// StripNode.createNorthNeighborSkirt(d + 1, d + 1, dd, nt);
|
||||
// StripNode.createEastNeighborSkirt(d + 1, d + 1, dd, et);
|
||||
// StripNode.createSouthNeighborSkirt(d + 1, d + 1, dd, st);
|
||||
// }
|
||||
// }
|
||||
// return table;
|
||||
//}
|
||||
|
||||
//StripNode.initTextureCoordsTable = function (pow) {
|
||||
// var table = [];
|
||||
// for (var i = 0; i <= pow; i++) {
|
||||
// var d = Math.pow(2, i);
|
||||
// table[d] = StripNode.createTextureCoords(d);
|
||||
// }
|
||||
// return table;
|
||||
//}
|
||||
|
||||
//StripNode.initIndexBodiesTable = function (pow) {
|
||||
// var table = [];
|
||||
// for (var i = 0; i <= pow; i++) {
|
||||
// var d = Math.pow(2, i) + 1;
|
||||
// var t = table[d] = [];
|
||||
// StripNode.createCenterBody(d, d, t);
|
||||
// }
|
||||
// return table;
|
||||
//}
|
||||
|
||||
//StripNode.createTextureCoords = function (size) {
|
||||
// var texCoords = [];
|
||||
// for (var i = 0; i <= size; i++) {
|
||||
// for (var j = 0; j <= size; j++) {
|
||||
// texCoords.push(j / size, i / size);
|
||||
// }
|
||||
// }
|
||||
// return texCoords;
|
||||
//}
|
||||
|
||||
StripNode.prototype.createBuffers = function () {
|
||||
PlanetSegmentHelper.initIndexesTables(5);
|
||||
|
||||
vertices = [];
|
||||
|
||||
var step = 1;
|
||||
var size = 1;
|
||||
|
||||
for (var i = 0; i <= size; i++) {
|
||||
for (var j = 0; j <= size; j++) {
|
||||
var x = j * step,
|
||||
y = (size-1) * step - i * step,
|
||||
z = 0;
|
||||
|
||||
vertices.push(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
textureCoords = PlanetSegmentHelper.textureCoordsTable[size];
|
||||
|
||||
var cubeVertexIndices = [];
|
||||
PlanetSegmentHelper.createSegmentIndexes(cubeVertexIndices, size, 1,1,1,1);
|
||||
|
||||
|
||||
//this.cubeVertexColorBuffer = this.ctx.createArrayBuffer( new Float32Array(unpackedColors), 4, 24 );
|
||||
this.cubeVertexPositionBuffer = this.renderer.ctx.createArrayBuffer(new Float32Array(vertices), 3, vertices.length / 3);
|
||||
this.cubeVertexTextureCoordBuffer = this.renderer.ctx.createArrayBuffer(new Float32Array(textureCoords), 2, textureCoords.length / 2);
|
||||
this.cubeVertexIndexBuffer = this.renderer.ctx.createElementArrayBuffer(new Uint16Array(cubeVertexIndices), 1, cubeVertexIndices.length);
|
||||
var StripNode = function (size) {
|
||||
StripNode.superclass.constructor.call(this, "CUBE");
|
||||
this.size = size * 0.5;
|
||||
//this.cubeVertexColorBuffer = null;
|
||||
this.cubeVertexPositionBuffer = null;
|
||||
this.cubeVertexIndexBuffer = null;
|
||||
|
||||
this.texture;
|
||||
this.textureImageFileName;
|
||||
this.cubeVertexTextureCoordBuffer = null;
|
||||
}
|
||||
|
||||
extend(StripNode, Node3D);
|
||||
|
||||
StripNode.prototype.initialization = function () {
|
||||
|
||||
this.initTexture("nehe.jpg");
|
||||
this.createBuffers();
|
||||
this.drawMode = WebGLContext.GL_TRIANGLE_STRIP;
|
||||
}
|
||||
|
||||
StripNode.prototype.initTexture = function (fileName) {
|
||||
var image = new Image();
|
||||
var handle = this;
|
||||
image.onload = function () {
|
||||
handle.texture = handle.renderer.ctx.createTextureFromImage(image);
|
||||
}
|
||||
image.src = this.textureImageFileName = fileName;
|
||||
}
|
||||
|
||||
StripNode.prototype.frame = function () {
|
||||
this.renderer.ctx.bindTexture(this.texture);
|
||||
this.renderer.ctx.setTextureBias([0, 0, 1]);
|
||||
this.renderer.ctx.drawBuffer(this.cubeVertexPositionBuffer, this.cubeVertexTextureCoordBuffer, this.cubeVertexIndexBuffer);
|
||||
}
|
||||
|
||||
|
||||
//StripNode.createCenterBody = function (width, height, indexes) {
|
||||
|
||||
// var i0 = 1,
|
||||
// j0 = 1;
|
||||
|
||||
// var i1 = 1,
|
||||
// j1 = 1;
|
||||
|
||||
// var ind1, ind2, nr;
|
||||
// for (var i = i0; i < height - 1 - i1; i++) {
|
||||
// for (var j = j0; j < width - j1; j++) {
|
||||
// ind1 = i * width + j;
|
||||
// nr = (i + 1) * width;
|
||||
// ind2 = nr + j;
|
||||
// indexes.push(ind1, ind2);
|
||||
// }
|
||||
// indexes.push(ind2, nr + j0);
|
||||
// }
|
||||
// indexes.push(indexes[indexes.length - 1], width * height - width);
|
||||
//}
|
||||
|
||||
//StripNode.createWestNeighborSkirt = function (width, height, deltaGr, indexes) {
|
||||
// var grCount = (width - 1) / deltaGr;
|
||||
// var b = width * height - width;
|
||||
// var k = 0;
|
||||
// for (var i = 0; i < height - 2; i++) {
|
||||
// if (i % grCount === 0) {
|
||||
// k = i;
|
||||
// }
|
||||
// var rind = b - width * i - width + 1,
|
||||
// lind = b - width * k;
|
||||
// indexes.push(lind, rind);
|
||||
// }
|
||||
|
||||
// if (deltaGr === (height - 1)) {
|
||||
// indexes.push(width);
|
||||
// indexes.push(0);
|
||||
// }
|
||||
//}
|
||||
|
||||
//StripNode.createNorthNeighborSkirt = function (width, height, deltaGr, indexes) {
|
||||
// var grCount = (width - 1) / deltaGr;
|
||||
// var k = 0;
|
||||
// for (var i = 0; i < height - 2; i++) {
|
||||
// if (i % grCount === 0) {
|
||||
// k = i;
|
||||
// }
|
||||
// var rind = width + i + 1,
|
||||
// lind = k;
|
||||
// indexes.push(lind, rind);
|
||||
// }
|
||||
|
||||
// if (deltaGr === (width - 1)) {
|
||||
// indexes.push(width - 2);
|
||||
// indexes.push(width - 1);
|
||||
// }
|
||||
//}
|
||||
|
||||
//StripNode.createEastNeighborSkirt = function (width, height, deltaGr, indexes) {
|
||||
// var grCount = (width - 1) / deltaGr;
|
||||
// var k = 0;
|
||||
// for (var i = 0; i < height - 2; i++) {
|
||||
// if (i % grCount === 0) {
|
||||
// k = i;
|
||||
// }
|
||||
// var rind = width * (i + 1) + width - 2,
|
||||
// lind = width + width * k - 1;
|
||||
// indexes.push(lind, rind);
|
||||
// }
|
||||
|
||||
// if (deltaGr === (height - 1)) {
|
||||
// indexes.push(width * (height - 1) - 1);
|
||||
// indexes.push(width * height - 1);
|
||||
// }
|
||||
//}
|
||||
|
||||
//StripNode.createSouthNeighborSkirt = function (width, height, deltaGr, indexes) {
|
||||
// var grCount = (width - 1) / deltaGr;
|
||||
// var k = 0;
|
||||
// var rb = width * (height - 1) - 2;
|
||||
// var lb = width * height - 1;
|
||||
// for (var i = 0; i < height - 2; i++) {
|
||||
// if (i % grCount === 0) {
|
||||
// k = i;
|
||||
// }
|
||||
// var rind = rb - i,
|
||||
// lind = lb - k;
|
||||
// indexes.push(lind, rind);
|
||||
// }
|
||||
|
||||
// if (deltaGr === (width - 1)) {
|
||||
// indexes.push(width * height - width + 1);
|
||||
// }
|
||||
// indexes.push(width * height - width);
|
||||
//}
|
||||
|
||||
//StripNode.initIndexesBodySkirts = function (pow) {
|
||||
// var table = [];
|
||||
// table[N] = [];
|
||||
// table[W] = [];
|
||||
// table[S] = [];
|
||||
// table[E] = [];
|
||||
|
||||
// for (var i = 0; i <= pow; i++) {
|
||||
// var d = Math.pow(2, i);
|
||||
// table[N][d+1] = [];
|
||||
// table[W][d+1] = [];
|
||||
// table[S][d+1] = [];
|
||||
// table[E][d+1] = [];
|
||||
// for (var j = 0; j <= pow; j++) {
|
||||
// var dd = Math.pow(2, j);
|
||||
// var nt = table[N][d+1][dd] = [];
|
||||
// var wt = table[W][d+1][dd] = [];
|
||||
// var st = table[S][d+1][dd] = [];
|
||||
// var et = table[E][d+1][dd] = [];
|
||||
// StripNode.createWestNeighborSkirt(d + 1, d + 1, dd, wt);
|
||||
// StripNode.createNorthNeighborSkirt(d + 1, d + 1, dd, nt);
|
||||
// StripNode.createEastNeighborSkirt(d + 1, d + 1, dd, et);
|
||||
// StripNode.createSouthNeighborSkirt(d + 1, d + 1, dd, st);
|
||||
// }
|
||||
// }
|
||||
// return table;
|
||||
//}
|
||||
|
||||
//StripNode.initTextureCoordsTable = function (pow) {
|
||||
// var table = [];
|
||||
// for (var i = 0; i <= pow; i++) {
|
||||
// var d = Math.pow(2, i);
|
||||
// table[d] = StripNode.createTextureCoords(d);
|
||||
// }
|
||||
// return table;
|
||||
//}
|
||||
|
||||
//StripNode.initIndexBodiesTable = function (pow) {
|
||||
// var table = [];
|
||||
// for (var i = 0; i <= pow; i++) {
|
||||
// var d = Math.pow(2, i) + 1;
|
||||
// var t = table[d] = [];
|
||||
// StripNode.createCenterBody(d, d, t);
|
||||
// }
|
||||
// return table;
|
||||
//}
|
||||
|
||||
//StripNode.createTextureCoords = function (size) {
|
||||
// var texCoords = [];
|
||||
// for (var i = 0; i <= size; i++) {
|
||||
// for (var j = 0; j <= size; j++) {
|
||||
// texCoords.push(j / size, i / size);
|
||||
// }
|
||||
// }
|
||||
// return texCoords;
|
||||
//}
|
||||
|
||||
StripNode.prototype.createBuffers = function () {
|
||||
PlanetSegmentHelper.initIndexesTables(5);
|
||||
|
||||
vertices = [];
|
||||
|
||||
var step = 1;
|
||||
var size = 1;
|
||||
|
||||
for (var i = 0; i <= size; i++) {
|
||||
for (var j = 0; j <= size; j++) {
|
||||
var x = j * step,
|
||||
y = (size-1) * step - i * step,
|
||||
z = 0;
|
||||
|
||||
vertices.push(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
textureCoords = PlanetSegmentHelper.textureCoordsTable[size];
|
||||
|
||||
var cubeVertexIndices = [];
|
||||
PlanetSegmentHelper.createSegmentIndexes(cubeVertexIndices, size, 1,1,1,1);
|
||||
|
||||
|
||||
//this.cubeVertexColorBuffer = this.ctx.createArrayBuffer( new Float32Array(unpackedColors), 4, 24 );
|
||||
this.cubeVertexPositionBuffer = this.renderer.ctx.createArrayBuffer(new Float32Array(vertices), 3, vertices.length / 3);
|
||||
this.cubeVertexTextureCoordBuffer = this.renderer.ctx.createArrayBuffer(new Float32Array(textureCoords), 2, textureCoords.length / 2);
|
||||
this.cubeVertexIndexBuffer = this.renderer.ctx.createElementArrayBuffer(new Uint16Array(cubeVertexIndices), 1, cubeVertexIndices.length);
|
||||
}
|
||||
@ -1,43 +1,43 @@
|
||||
precision highp float;
|
||||
|
||||
varying vec2 vTexCoord;
|
||||
|
||||
uniform sampler2D u_texture;
|
||||
uniform float resolution;
|
||||
uniform float radius;
|
||||
uniform vec2 dir;
|
||||
|
||||
void main() {
|
||||
//this will be our RGBA sum
|
||||
vec4 sum = vec4(0.0);
|
||||
|
||||
//our original texcoord for this fragment
|
||||
vec2 tc = vTexCoord;
|
||||
|
||||
//the amount to blur, i.e. how far off center to sample from
|
||||
//1.0 -> blur by one pixel
|
||||
//2.0 -> blur by two pixels, etc.
|
||||
float blur = radius/resolution;
|
||||
|
||||
//the direction of our blur
|
||||
//(1.0, 0.0) -> x-axis blur
|
||||
//(0.0, 1.0) -> y-axis blur
|
||||
float hstep = dir.x;
|
||||
float vstep = dir.y;
|
||||
|
||||
//apply blurring, using a 9-tap filter with predefined gaussian weights
|
||||
|
||||
sum += texture2D(u_texture, vec2(tc.x - 4.0 * blur * hstep, tc.y - 4.0 * blur * vstep)) * 0.0162162162;
|
||||
sum += texture2D(u_texture, vec2(tc.x - 3.0 * blur * hstep, tc.y - 3.0 * blur * vstep)) * 0.0540540541;
|
||||
sum += texture2D(u_texture, vec2(tc.x - 2.0 * blur * hstep, tc.y - 2.0 * blur * vstep)) * 0.1216216216;
|
||||
sum += texture2D(u_texture, vec2(tc.x - 1.0 * blur * hstep, tc.y - 1.0 * blur * vstep)) * 0.1945945946;
|
||||
|
||||
sum += texture2D(u_texture, vec2(tc.x, tc.y)) * 0.2270270270;
|
||||
|
||||
sum += texture2D(u_texture, vec2(tc.x + 1.0 * blur * hstep, tc.y + 1.0 * blur * vstep)) * 0.1945945946;
|
||||
sum += texture2D(u_texture, vec2(tc.x + 2.0 * blur * hstep, tc.y + 2.0 * blur * vstep)) * 0.1216216216;
|
||||
sum += texture2D(u_texture, vec2(tc.x + 3.0 * blur * hstep, tc.y + 3.0 * blur * vstep)) * 0.0540540541;
|
||||
sum += texture2D(u_texture, vec2(tc.x + 4.0 * blur * hstep, tc.y + 4.0 * blur * vstep)) * 0.0162162162;
|
||||
|
||||
gl_FragColor = vec4(sum.rgb, 1.0);
|
||||
precision highp float;
|
||||
|
||||
varying vec2 vTexCoord;
|
||||
|
||||
uniform sampler2D u_texture;
|
||||
uniform float resolution;
|
||||
uniform float radius;
|
||||
uniform vec2 dir;
|
||||
|
||||
void main() {
|
||||
//this will be our RGBA sum
|
||||
vec4 sum = vec4(0.0);
|
||||
|
||||
//our original texcoord for this fragment
|
||||
vec2 tc = vTexCoord;
|
||||
|
||||
//the amount to blur, i.e. how far off center to sample from
|
||||
//1.0 -> blur by one pixel
|
||||
//2.0 -> blur by two pixels, etc.
|
||||
float blur = radius/resolution;
|
||||
|
||||
//the direction of our blur
|
||||
//(1.0, 0.0) -> x-axis blur
|
||||
//(0.0, 1.0) -> y-axis blur
|
||||
float hstep = dir.x;
|
||||
float vstep = dir.y;
|
||||
|
||||
//apply blurring, using a 9-tap filter with predefined gaussian weights
|
||||
|
||||
sum += texture2D(u_texture, vec2(tc.x - 4.0 * blur * hstep, tc.y - 4.0 * blur * vstep)) * 0.0162162162;
|
||||
sum += texture2D(u_texture, vec2(tc.x - 3.0 * blur * hstep, tc.y - 3.0 * blur * vstep)) * 0.0540540541;
|
||||
sum += texture2D(u_texture, vec2(tc.x - 2.0 * blur * hstep, tc.y - 2.0 * blur * vstep)) * 0.1216216216;
|
||||
sum += texture2D(u_texture, vec2(tc.x - 1.0 * blur * hstep, tc.y - 1.0 * blur * vstep)) * 0.1945945946;
|
||||
|
||||
sum += texture2D(u_texture, vec2(tc.x, tc.y)) * 0.2270270270;
|
||||
|
||||
sum += texture2D(u_texture, vec2(tc.x + 1.0 * blur * hstep, tc.y + 1.0 * blur * vstep)) * 0.1945945946;
|
||||
sum += texture2D(u_texture, vec2(tc.x + 2.0 * blur * hstep, tc.y + 2.0 * blur * vstep)) * 0.1216216216;
|
||||
sum += texture2D(u_texture, vec2(tc.x + 3.0 * blur * hstep, tc.y + 3.0 * blur * vstep)) * 0.0540540541;
|
||||
sum += texture2D(u_texture, vec2(tc.x + 4.0 * blur * hstep, tc.y + 4.0 * blur * vstep)) * 0.0162162162;
|
||||
|
||||
gl_FragColor = vec4(sum.rgb, 1.0);
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
attribute vec2 a_position;
|
||||
|
||||
varying vec2 vTexCoord;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_position, 0, 1);
|
||||
vec2 vt = a_position * 0.5 + 0.5;
|
||||
vTexCoord = vec2(vt.x, 1.0 - vt.y);//a_texCoords;
|
||||
attribute vec2 a_position;
|
||||
|
||||
varying vec2 vTexCoord;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_position, 0, 1);
|
||||
vec2 vt = a_position * 0.5 + 0.5;
|
||||
vTexCoord = vec2(vt.x, 1.0 - vt.y);//a_texCoords;
|
||||
}
|
||||
@ -1,72 +1,72 @@
|
||||
goog.require('og.webgl.Handler');
|
||||
goog.require('og.Renderer');
|
||||
goog.require('og.control.SimpleNavigation');
|
||||
goog.require('og.shaderProgram');
|
||||
goog.require('og.node.Axes');
|
||||
goog.require('my.Plane');
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
function start() {
|
||||
|
||||
og.webgl.MAX_FRAME_DELAY = 15;
|
||||
|
||||
var flatShader = new og.shaderProgram.ShaderProgram("flat", {
|
||||
uniforms: {
|
||||
uPMVMatrix: { type: og.shaderProgram.types.MAT4 }
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true },
|
||||
aVertexColor: { type: og.shaderProgram.types.VEC4, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "flat_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "flat_fs.txt")
|
||||
});
|
||||
|
||||
var colorShader = new og.shaderProgram.ShaderProgram("colorShader", {
|
||||
uniforms: {
|
||||
uMVMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
uPMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
uNMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
|
||||
pointLightsPositions: { type: og.shaderProgram.types.VEC3 },
|
||||
pointLightsParamsv: { type: og.shaderProgram.types.VEC3 },
|
||||
pointLightsParamsf: { type: og.shaderProgram.types.FLOAT },
|
||||
|
||||
//uColor: { type: og.shaderProgram.types.VEC4 },
|
||||
uSampler: { type: og.shaderProgram.types.SAMPLER2D },
|
||||
uNormalsMap: { type: og.shaderProgram.types.SAMPLER2D }
|
||||
},
|
||||
attributes: {
|
||||
aVertexNormal: { type: og.shaderProgram.types.VEC3, enableArray: true },
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true },
|
||||
aTextureCoord: { type: og.shaderProgram.types.VEC2, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile("plane_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile("plane_fs.txt")
|
||||
});
|
||||
|
||||
context = new og.webgl.Handler("canvas", null, ["OES_standard_derivatives"]);
|
||||
context.addShaderProgram(flatShader);
|
||||
context.addShaderProgram(colorShader);
|
||||
context.init();
|
||||
|
||||
renderer = new og.Renderer(context);
|
||||
renderer.init();
|
||||
|
||||
var axes = new og.node.Axes(10000);
|
||||
|
||||
plane = new my.Plane("Plane");
|
||||
renderer.addRenderNode(axes);
|
||||
renderer.addRenderNode(plane);
|
||||
|
||||
renderer.addControls([
|
||||
new og.control.SimpleNavigation({ autoActivate: true }),
|
||||
]);
|
||||
|
||||
renderer.start();
|
||||
|
||||
renderer.activeCamera.eye.x = 1114.1424013103258;
|
||||
renderer.activeCamera.eye.y = 2086.749969128237;
|
||||
renderer.activeCamera.eye.z = 8824.474084480114;
|
||||
renderer.activeCamera.refresh();
|
||||
goog.require('og.webgl.Handler');
|
||||
goog.require('og.Renderer');
|
||||
goog.require('og.control.SimpleNavigation');
|
||||
goog.require('og.shaderProgram');
|
||||
goog.require('og.node.Axes');
|
||||
goog.require('my.Plane');
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
function start() {
|
||||
|
||||
og.webgl.MAX_FRAME_DELAY = 15;
|
||||
|
||||
var flatShader = new og.shaderProgram.ShaderProgram("flat", {
|
||||
uniforms: {
|
||||
uPMVMatrix: { type: og.shaderProgram.types.MAT4 }
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true },
|
||||
aVertexColor: { type: og.shaderProgram.types.VEC4, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "flat_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "flat_fs.txt")
|
||||
});
|
||||
|
||||
var colorShader = new og.shaderProgram.ShaderProgram("colorShader", {
|
||||
uniforms: {
|
||||
uMVMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
uPMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
uNMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
|
||||
pointLightsPositions: { type: og.shaderProgram.types.VEC3 },
|
||||
pointLightsParamsv: { type: og.shaderProgram.types.VEC3 },
|
||||
pointLightsParamsf: { type: og.shaderProgram.types.FLOAT },
|
||||
|
||||
//uColor: { type: og.shaderProgram.types.VEC4 },
|
||||
uSampler: { type: og.shaderProgram.types.SAMPLER2D },
|
||||
uNormalsMap: { type: og.shaderProgram.types.SAMPLER2D }
|
||||
},
|
||||
attributes: {
|
||||
aVertexNormal: { type: og.shaderProgram.types.VEC3, enableArray: true },
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true },
|
||||
aTextureCoord: { type: og.shaderProgram.types.VEC2, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile("plane_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile("plane_fs.txt")
|
||||
});
|
||||
|
||||
context = new og.webgl.Handler("canvas", null, ["OES_standard_derivatives"]);
|
||||
context.addShaderProgram(flatShader);
|
||||
context.addShaderProgram(colorShader);
|
||||
context.init();
|
||||
|
||||
renderer = new og.Renderer(context);
|
||||
renderer.init();
|
||||
|
||||
var axes = new og.node.Axes(10000);
|
||||
|
||||
plane = new my.Plane("Plane");
|
||||
renderer.addRenderNode(axes);
|
||||
renderer.addRenderNode(plane);
|
||||
|
||||
renderer.addControls([
|
||||
new og.control.SimpleNavigation({ autoActivate: true }),
|
||||
]);
|
||||
|
||||
renderer.start();
|
||||
|
||||
renderer.activeCamera.eye.x = 1114.1424013103258;
|
||||
renderer.activeCamera.eye.y = 2086.749969128237;
|
||||
renderer.activeCamera.eye.z = 8824.474084480114;
|
||||
renderer.activeCamera.refresh();
|
||||
};
|
||||
@ -1,3 +1,3 @@
|
||||
// This file was autogenerated by D:\my projects\closure-library\closure\bin\build\depswriter.py.
|
||||
// Please do not edit.
|
||||
goog.addDependency('../../../og/sandbox/plane/plane.js', ['my.Plane'], ['og.inheritance', 'og.light.PointLight', 'og.node.RenderNode', 'og.planetSegment.PlanetSegmentHelper', 'og.webgl.Framebuffer']);
|
||||
// This file was autogenerated by D:\my projects\closure-library\closure\bin\build\depswriter.py.
|
||||
// Please do not edit.
|
||||
goog.addDependency('../../../og/sandbox/plane/plane.js', ['my.Plane'], ['og.inheritance', 'og.light.PointLight', 'og.node.RenderNode', 'og.planetSegment.PlanetSegmentHelper', 'og.webgl.Framebuffer']);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
precision mediump float;
|
||||
|
||||
varying vec3 v_color;
|
||||
|
||||
void main () {
|
||||
gl_FragColor = vec4(v_color, 1.0);
|
||||
precision mediump float;
|
||||
|
||||
varying vec3 v_color;
|
||||
|
||||
void main () {
|
||||
gl_FragColor = vec4(v_color, 1.0);
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
attribute vec2 a_position;
|
||||
attribute vec3 a_normal;
|
||||
|
||||
varying vec3 v_color;
|
||||
|
||||
void main() {
|
||||
gl_PointSize = 1.0;
|
||||
gl_Position = vec4(a_position, 0, 1);
|
||||
v_color = a_normal * 0.5 + 0.5;
|
||||
attribute vec2 a_position;
|
||||
attribute vec3 a_normal;
|
||||
|
||||
varying vec3 v_color;
|
||||
|
||||
void main() {
|
||||
gl_PointSize = 1.0;
|
||||
gl_Position = vec4(a_position, 0, 1);
|
||||
v_color = a_normal * 0.5 + 0.5;
|
||||
}
|
||||
@ -1,441 +1,441 @@
|
||||
goog.provide('my.Plane');
|
||||
|
||||
goog.require('og.node.RenderNode');
|
||||
goog.require('og.inheritance');
|
||||
goog.require('og.planetSegment.PlanetSegmentHelper');
|
||||
goog.require('og.light.PointLight');
|
||||
goog.require('og.webgl.Framebuffer');
|
||||
|
||||
//goog.require('og.SyncQueue');
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////
|
||||
Heatmap = function (handler) {
|
||||
|
||||
this.handler = handler;
|
||||
this._verticesBuffer;
|
||||
};
|
||||
|
||||
Heatmap.prototype.init = function () {
|
||||
|
||||
var vertices = [];
|
||||
|
||||
for (var i = 0; i < 33; i++) {
|
||||
for (var j = 0; j < 33; j++) {
|
||||
vertices.push(-1 + j / (32 / 2), -1 + i / (32 / 2));
|
||||
}
|
||||
}
|
||||
|
||||
this._verticesBuffer = this.handler.createArrayBuffer(new Float32Array(vertices), 2, vertices.length / 2);
|
||||
var indexes = og.planetSegment.PlanetSegmentHelper.createSegmentIndexes(32, [32, 32, 32, 32]);
|
||||
this._indexBuffer = this.handler.createElementArrayBuffer(indexes, 1, indexes.length);
|
||||
|
||||
var positions = [
|
||||
-1.0, -1.0,
|
||||
1.0, -1.0,
|
||||
-1.0, 1.0,
|
||||
1.0, 1.0];
|
||||
|
||||
this._positionBuffer = this.handler.createArrayBuffer(new Float32Array(positions), 2, positions.length / 2);
|
||||
|
||||
this.framebuffer = new og.webgl.Framebuffer(this.handler.gl, 128, 128);
|
||||
this.framebuffer.initialize();
|
||||
};
|
||||
|
||||
|
||||
Heatmap.prototype.drawNormalMap = function (normals) {
|
||||
|
||||
this._normalsBuffer = this.handler.createArrayBuffer(new Float32Array(normals), 3, normals.length / 3);
|
||||
|
||||
this.handler.deactivateFaceCulling();
|
||||
//this.handler.clearFrame();
|
||||
|
||||
this.framebuffer.activate();
|
||||
this.framebuffer.clear();
|
||||
|
||||
this.handler.shaderPrograms.heatmap.activate();
|
||||
|
||||
this.handler.shaderPrograms.heatmap.set({
|
||||
a_position: this._verticesBuffer,
|
||||
a_normal: this._normalsBuffer
|
||||
});
|
||||
|
||||
//draw indexes
|
||||
this.handler.gl.bindBuffer(this.handler.gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
||||
this.handler.gl.drawElements(this.handler.gl.TRIANGLE_STRIP, this._indexBuffer.numItems, this.handler.gl.UNSIGNED_SHORT, 0);
|
||||
|
||||
//this.handler.shaderPrograms.heatmap.drawArray(this.handler.gl.POINTS, this._verticesBuffer.numItems);
|
||||
this.framebuffer.deactivate();
|
||||
};
|
||||
|
||||
Heatmap.prototype.drawTexture = function (texture) {
|
||||
|
||||
this.handler.clearFrame();
|
||||
|
||||
this.handler.shaderPrograms.texture.activate();
|
||||
|
||||
this.handler.shaderPrograms.texture.set({
|
||||
a_position: this._positionBuffer,
|
||||
u_sampler: texture
|
||||
});
|
||||
|
||||
this.handler.shaderPrograms.texture.drawArray(this.handler.gl.TRIANGLE_STRIP, this._positionBuffer.numItems);
|
||||
};
|
||||
|
||||
Heatmap.prototype.drawBlur = function (texture, dir, size, radius) {
|
||||
|
||||
this.handler.clearFrame();
|
||||
|
||||
this.handler.shaderPrograms.blur.activate();
|
||||
|
||||
this.handler.shaderPrograms.blur.set({
|
||||
a_position: this._positionBuffer,
|
||||
u_texture: texture,
|
||||
resolution: size,
|
||||
radius: radius,
|
||||
dir: dir
|
||||
});
|
||||
|
||||
this.handler.shaderPrograms.blur.drawArray(this.handler.gl.TRIANGLE_STRIP, this._positionBuffer.numItems);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
my.Plane = function (name) {
|
||||
og.inheritance.base(this, name);
|
||||
this.vertexPositionBuffer = null;
|
||||
this.indexBuffer = null;
|
||||
this.size = 100;
|
||||
|
||||
this.light = null;
|
||||
|
||||
this.texture = null;
|
||||
};
|
||||
|
||||
og.inheritance.extend(my.Plane, og.node.RenderNode);
|
||||
|
||||
my.Plane.prototype.normalsPack = function () {
|
||||
normalsPacked = [];
|
||||
for (var i = 0; i < normals.length; i++) {
|
||||
normalsPacked[i] = normals[i] * 0.5 + 0.5;
|
||||
}
|
||||
};
|
||||
|
||||
my.Plane.prototype.normalsUnpack = function () {
|
||||
normalsUnpacked = [];
|
||||
for (var i = 0; i < normals.length; i++) {
|
||||
normalsUnpacked[i] = (normalsPacked[i] - 0.5) * 2.0;
|
||||
}
|
||||
};
|
||||
|
||||
my.Plane.prototype.initialization = function () {
|
||||
this.createBuffers();
|
||||
this.drawMode = this.renderer.handler.gl.TRIANGLE_STRIP;
|
||||
this.light = new og.light.PointLight();
|
||||
|
||||
this.light.setAmbient(new og.math.Vector3(0.14, 0.1, 0.2));
|
||||
this.light.setDiffuse(new og.math.Vector3(0.9, 0.9, 0.8));
|
||||
this.light.setSpecular(new og.math.Vector3(0.01, 0.01, 0.009));
|
||||
this.light.setShininess(8);
|
||||
this.light.addTo(this);
|
||||
this.light._position = new og.math.Vector3(5, 5, 5);
|
||||
|
||||
this.lightEnabled = true;
|
||||
|
||||
this.renderer.events.on("oncharkeypressed", this, this.toogleWireframe, og.input.KEY_X);
|
||||
this.renderer.events.on("oncharkeypressed", this, this.toogleLightPosition, og.input.KEY_C);
|
||||
|
||||
//
|
||||
//Hiddent context experiment
|
||||
//
|
||||
var normalMap = new og.shaderProgram.ShaderProgram("heatmap", {
|
||||
attributes: {
|
||||
a_position: { type: og.shaderProgram.types.VEC2, enableArray: true },
|
||||
a_normal: { type: og.shaderProgram.types.VEC3, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile("normalmap_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile("normalmap_fs.txt")
|
||||
});
|
||||
|
||||
var texture = new og.shaderProgram.ShaderProgram("texture", {
|
||||
attributes: {
|
||||
a_position: { type: og.shaderProgram.types.VEC2, enableArray: true }
|
||||
},
|
||||
uniforms: {
|
||||
u_sampler: { type: og.shaderProgram.types.SAMPLER2D }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile("texture_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile("texture_fs.txt")
|
||||
});
|
||||
|
||||
var blur = new og.shaderProgram.ShaderProgram("blur", {
|
||||
attributes: {
|
||||
a_position: { type: og.shaderProgram.types.VEC2, enableArray: true }
|
||||
},
|
||||
uniforms: {
|
||||
u_texture: { type: og.shaderProgram.types.SAMPLER2D },
|
||||
resolution: { type: og.shaderProgram.types.FLOAT },
|
||||
radius: { type: og.shaderProgram.types.FLOAT },
|
||||
dir: { type: og.shaderProgram.types.VEC2 }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile("blur_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile("blur_fs.txt")
|
||||
});
|
||||
|
||||
|
||||
this._hiddenHandler = new og.webgl.Handler();
|
||||
this._hiddenHandler.addShaderProgram(texture);
|
||||
this._hiddenHandler.addShaderProgram(blur);
|
||||
this._hiddenHandler.addShaderProgram(normalMap);
|
||||
this._hiddenHandler.init();
|
||||
|
||||
this._hiddenNode = new Heatmap(this._hiddenHandler, { alpha: false, depth: false });
|
||||
this._hiddenNode.init();
|
||||
|
||||
//make normal map
|
||||
this._hiddenHandler.setSize(128, 128);
|
||||
this._hiddenNode.drawNormalMap(normals);
|
||||
|
||||
//this._hiddenHandler.setSize(256, 256);
|
||||
//this._hiddenNode.drawTexture(this._hiddenNode.framebuffer.texture);
|
||||
|
||||
this._hiddenNode.drawBlur(/*this._hiddenHandler.createTexture(this._hiddenHandler.canvas)*/this._hiddenNode.framebuffer.texture, [1.0, 0.0], 128, 1);
|
||||
this._hiddenNode.drawBlur(this._hiddenHandler.createTexture(this._hiddenHandler.canvas), [0.0, 1.0], 128, 1);
|
||||
this.realNormals = this.renderer.handler.createTexture(this._hiddenHandler.canvas);
|
||||
|
||||
var img = new Image();
|
||||
var that = this;
|
||||
img.onload = function (e) {
|
||||
that.normalsTexture = that.renderer.handler.createTexture(this);
|
||||
};
|
||||
|
||||
img.src = "3912-normal.jpg";
|
||||
|
||||
};
|
||||
|
||||
my.Plane.prototype.toogleWireframe = function (e) {
|
||||
if (this.drawMode === this.renderer.handler.gl.LINE_STRIP) {
|
||||
this.drawMode = this.renderer.handler.gl.TRIANGLE_STRIP;
|
||||
} else {
|
||||
this.drawMode = this.renderer.handler.gl.LINE_STRIP;
|
||||
}
|
||||
};
|
||||
|
||||
my.Plane.prototype.toogleLightPosition = function () {
|
||||
this.light._position = this.renderer.activeCamera.eye.clone();
|
||||
};
|
||||
|
||||
my.Plane.prototype.createBuffers = function () {
|
||||
og.planetSegment.PlanetSegmentHelper.initIndexesTables(6);
|
||||
|
||||
|
||||
vertices = [];
|
||||
|
||||
var step = 1;
|
||||
var size = 32;
|
||||
|
||||
for (var i = 0; i <= size; i++) {
|
||||
for (var j = 0; j <= size; j++) {
|
||||
var x = j * step,
|
||||
y = (size) * step - i * step,
|
||||
z = Math.sin(x / 5) * Math.cos(1 * y / 5) * 1400;
|
||||
|
||||
vertices.push(x * this.size * 2, y * this.size * 2, z);
|
||||
}
|
||||
}
|
||||
|
||||
var gs = size + 1;
|
||||
normals = new Float64Array(gs * gs * 3);
|
||||
|
||||
var vertexIndices = og.planetSegment.PlanetSegmentHelper.createSegmentIndexes(size, [size, size, size, size]);
|
||||
var textureCoords = og.planetSegment.PlanetSegmentHelper.textureCoordsTable[size];
|
||||
|
||||
//function getVertex(i, j) {
|
||||
// if (i < 0) i = 0;
|
||||
// if (j < 0) j = 0;
|
||||
// if (i > gs - 1) i = gs - 1;
|
||||
// if (j > gs - 1) j = gs - 1;
|
||||
// var vInd = (i * gs + j) * 3;
|
||||
// return new og.math.Vector3(vertices[vInd], vertices[vInd + 1], vertices[vInd + 2]);
|
||||
//}
|
||||
|
||||
//for (var i = 0; i < gs - 1; i++) {
|
||||
// for (var j = 0; j < gs - 1; j++) {
|
||||
// var C = getVertex(i, j);
|
||||
// var B = getVertex(i - 1, j);
|
||||
// var D = getVertex(i, j - 1);
|
||||
// var E = getVertex(i, j + 1);
|
||||
// var F = getVertex(i + 1, j);
|
||||
|
||||
|
||||
// var vBC = og.math.Vector3.sub(C, B);
|
||||
// var vBE = og.math.Vector3.sub(E, B);
|
||||
// var nBCE = vBC.cross(vBE).normalize();
|
||||
|
||||
// var vDC = og.math.Vector3.sub(C, D);
|
||||
// var vDF = og.math.Vector3.sub(F, D);
|
||||
// var nDFC = vDF.cross(vDC).normalize();
|
||||
|
||||
// var vDB = og.math.Vector3.sub(B, D);
|
||||
// var nDCB = vDC.cross(vDB).normalize();
|
||||
|
||||
// var vCF = og.math.Vector3.sub(F, C);
|
||||
// var vCE = og.math.Vector3.sub(E, C);
|
||||
// var nCFE = vCF.cross(vCE).normalize();
|
||||
|
||||
// var nC = new og.math.Vector3((nBCE.x + nDFC.x + nDCB.x + nCFE.x) / 4, (nBCE.y + nDFC.y + nDCB.y + nCFE.y) / 4,
|
||||
// (nBCE.z + nDFC.z + nDCB.z + nCFE.z) / 4);
|
||||
|
||||
// // nC.normalize();
|
||||
|
||||
// var vInd = (i * gs + j) * 3;
|
||||
// normals[vInd] = nC.x;
|
||||
// normals[vInd + 1] = nC.y;
|
||||
// normals[vInd + 2] = nC.z;
|
||||
// }
|
||||
//}
|
||||
|
||||
for (var i = 0; i < gs - 1; i++) {
|
||||
for (var j = 0; j < gs - 1; j++) {
|
||||
|
||||
var vInd0 = (i * gs + j) * 3;
|
||||
var vInd1 = (i * gs + j + 1) * 3;
|
||||
var vInd2 = ((i + 1) * gs + j) * 3;
|
||||
var vInd3 = ((i + 1) * gs + (j + 1)) * 3;
|
||||
|
||||
var v0 = new og.math.Vector3(vertices[vInd0], vertices[vInd0 + 1], vertices[vInd0 + 2]),
|
||||
v1 = new og.math.Vector3(vertices[vInd1], vertices[vInd1 + 1], vertices[vInd1 + 2]),
|
||||
v2 = new og.math.Vector3(vertices[vInd2], vertices[vInd2 + 1], vertices[vInd2 + 2]),
|
||||
v3 = new og.math.Vector3(vertices[vInd3], vertices[vInd3 + 1], vertices[vInd3 + 2]);
|
||||
|
||||
var e10 = og.math.Vector3.sub(v1, v0),
|
||||
e20 = og.math.Vector3.sub(v2, v0),
|
||||
e30 = og.math.Vector3.sub(v3, v0);
|
||||
|
||||
var sw = e20.cross(e30);//.normalize();
|
||||
var ne = e30.cross(e10);//.normalize();
|
||||
|
||||
var n0 = og.math.Vector3.add(ne, sw);
|
||||
var n3 = og.math.Vector3.add(ne, sw);
|
||||
var n1 = og.math.Vector3.add(ne, sw);
|
||||
var n2 = og.math.Vector3.add(ne, sw);
|
||||
|
||||
//n0.normalize();
|
||||
//n1.normalize();
|
||||
//n3.normalize();
|
||||
//n2.normalize();
|
||||
|
||||
normals[vInd0] += n0.x;
|
||||
normals[vInd0 + 1] += n0.y;
|
||||
normals[vInd0 + 2] += n0.z;
|
||||
|
||||
normals[vInd1] += n1.x;
|
||||
normals[vInd1 + 1] += n1.y;
|
||||
normals[vInd1 + 2] += n1.z;
|
||||
|
||||
normals[vInd2] += n2.x;
|
||||
normals[vInd2 + 1] += n2.y;
|
||||
normals[vInd2 + 2] += n2.z;
|
||||
|
||||
normals[vInd3] += n3.x;
|
||||
normals[vInd3 + 1] += n3.y;
|
||||
normals[vInd3 + 2] += n3.z;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (var i = 0; i < normals.length; i += 3) {
|
||||
var l = Math.sqrt(normals[i] * normals[i] + normals[i + 1] * normals[i + 1] + normals[i + 2] * normals[i + 2]);
|
||||
normals[i] /= l;
|
||||
normals[i + 1] /= l;
|
||||
normals[i + 2] /= l;
|
||||
}
|
||||
|
||||
this.positionBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(vertices), 3, vertices.length / 3);
|
||||
this.normalBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(normals), 3, normals.length / 3);
|
||||
this.textureCoordBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(textureCoords), 2, textureCoords.length / 2);
|
||||
this.indexBuffer = this.renderer.handler.createElementArrayBuffer(new Uint16Array(vertexIndices), 1, vertexIndices.length);
|
||||
|
||||
|
||||
var lines = [];
|
||||
var colors = [];
|
||||
for (var i = 0; i < normals.length; i += 3) {
|
||||
|
||||
lines.push(vertices[i], vertices[i + 1], vertices[i + 2],
|
||||
vertices[i] + normals[i] * 100, vertices[i + 1] + normals[i + 1] * 100, vertices[i + 2] + normals[i + 2] * 100);
|
||||
|
||||
colors.push(1.0, 0.0, 0.0, 1.0,
|
||||
1.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
this.linesBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(lines), 3, 2 * vertices.length / 3);
|
||||
this.linesColorBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(colors), 4, 2 * vertices.length / 3);
|
||||
};
|
||||
|
||||
my.Plane.prototype.frame = function () {
|
||||
|
||||
var r = this.renderer;
|
||||
|
||||
var sh, p, gl;
|
||||
|
||||
//
|
||||
// Draw surface
|
||||
sh = r.handler.shaderPrograms.colorShader;
|
||||
p = sh._program;
|
||||
gl = r.handler.gl,
|
||||
sha = p.attributes,
|
||||
shu = p.uniforms;
|
||||
|
||||
sh.activate();
|
||||
|
||||
//gl.uniform4fv(shu.uColor._pName, [1, 1, 1, 1]);
|
||||
|
||||
//point light
|
||||
gl.uniform3fv(shu.pointLightsPositions._pName, this._pointLightsTransformedPositions);
|
||||
gl.uniform3fv(shu.pointLightsParamsv._pName, this._pointLightsParamsv);
|
||||
gl.uniform1fv(shu.pointLightsParamsf._pName, this._pointLightsParamsf);
|
||||
|
||||
//matrices
|
||||
gl.uniformMatrix4fv(shu.uPMatrix._pName, false, r.activeCamera.pMatrix._m);
|
||||
gl.uniformMatrix4fv(shu.uMVMatrix._pName, false, r.activeCamera.mvMatrix._m);
|
||||
gl.uniformMatrix3fv(shu.uNMatrix._pName, false, r.activeCamera.nMatrix._m);
|
||||
|
||||
//diffuse texture
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.realNormals);
|
||||
gl.uniform1i(shu.uSampler._pName, 0);
|
||||
|
||||
gl.activeTexture(gl.TEXTURE1);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.normalsTexture);
|
||||
gl.uniform1i(shu.uNormalsMap._pName, 1);
|
||||
|
||||
|
||||
//normals
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.normalBuffer);
|
||||
gl.vertexAttribPointer(sha.aVertexNormal._pName, this.normalBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
||||
|
||||
//vertices positions
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer);
|
||||
gl.vertexAttribPointer(sha.aVertexPosition._pName, this.positionBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
||||
|
||||
//texture coordinates
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.textureCoordBuffer);
|
||||
gl.vertexAttribPointer(sha.aTextureCoord._pName, this.textureCoordBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
||||
|
||||
//draw indexes
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
||||
gl.drawElements(this.drawMode, this.indexBuffer.numItems, gl.UNSIGNED_SHORT, 0);
|
||||
|
||||
|
||||
//
|
||||
//Draw normals
|
||||
//r.handler.shaderPrograms.flat.activate();
|
||||
|
||||
//r.handler.shaderPrograms.flat.set({
|
||||
// uPMVMatrix: r.activeCamera.pmvMatrix._m,
|
||||
// aVertexPosition: this.linesBuffer,
|
||||
// aVertexColor: this.linesColorBuffer
|
||||
//});
|
||||
//r.handler.shaderPrograms.flat.drawArray(r.handler.gl.LINES, this.linesBuffer.numItems);
|
||||
|
||||
goog.provide('my.Plane');
|
||||
|
||||
goog.require('og.node.RenderNode');
|
||||
goog.require('og.inheritance');
|
||||
goog.require('og.planetSegment.PlanetSegmentHelper');
|
||||
goog.require('og.light.PointLight');
|
||||
goog.require('og.webgl.Framebuffer');
|
||||
|
||||
//goog.require('og.SyncQueue');
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////
|
||||
Heatmap = function (handler) {
|
||||
|
||||
this.handler = handler;
|
||||
this._verticesBuffer;
|
||||
};
|
||||
|
||||
Heatmap.prototype.init = function () {
|
||||
|
||||
var vertices = [];
|
||||
|
||||
for (var i = 0; i < 33; i++) {
|
||||
for (var j = 0; j < 33; j++) {
|
||||
vertices.push(-1 + j / (32 / 2), -1 + i / (32 / 2));
|
||||
}
|
||||
}
|
||||
|
||||
this._verticesBuffer = this.handler.createArrayBuffer(new Float32Array(vertices), 2, vertices.length / 2);
|
||||
var indexes = og.planetSegment.PlanetSegmentHelper.createSegmentIndexes(32, [32, 32, 32, 32]);
|
||||
this._indexBuffer = this.handler.createElementArrayBuffer(indexes, 1, indexes.length);
|
||||
|
||||
var positions = [
|
||||
-1.0, -1.0,
|
||||
1.0, -1.0,
|
||||
-1.0, 1.0,
|
||||
1.0, 1.0];
|
||||
|
||||
this._positionBuffer = this.handler.createArrayBuffer(new Float32Array(positions), 2, positions.length / 2);
|
||||
|
||||
this.framebuffer = new og.webgl.Framebuffer(this.handler.gl, 128, 128);
|
||||
this.framebuffer.initialize();
|
||||
};
|
||||
|
||||
|
||||
Heatmap.prototype.drawNormalMap = function (normals) {
|
||||
|
||||
this._normalsBuffer = this.handler.createArrayBuffer(new Float32Array(normals), 3, normals.length / 3);
|
||||
|
||||
this.handler.deactivateFaceCulling();
|
||||
//this.handler.clearFrame();
|
||||
|
||||
this.framebuffer.activate();
|
||||
this.framebuffer.clear();
|
||||
|
||||
this.handler.shaderPrograms.heatmap.activate();
|
||||
|
||||
this.handler.shaderPrograms.heatmap.set({
|
||||
a_position: this._verticesBuffer,
|
||||
a_normal: this._normalsBuffer
|
||||
});
|
||||
|
||||
//draw indexes
|
||||
this.handler.gl.bindBuffer(this.handler.gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
||||
this.handler.gl.drawElements(this.handler.gl.TRIANGLE_STRIP, this._indexBuffer.numItems, this.handler.gl.UNSIGNED_SHORT, 0);
|
||||
|
||||
//this.handler.shaderPrograms.heatmap.drawArray(this.handler.gl.POINTS, this._verticesBuffer.numItems);
|
||||
this.framebuffer.deactivate();
|
||||
};
|
||||
|
||||
Heatmap.prototype.drawTexture = function (texture) {
|
||||
|
||||
this.handler.clearFrame();
|
||||
|
||||
this.handler.shaderPrograms.texture.activate();
|
||||
|
||||
this.handler.shaderPrograms.texture.set({
|
||||
a_position: this._positionBuffer,
|
||||
u_sampler: texture
|
||||
});
|
||||
|
||||
this.handler.shaderPrograms.texture.drawArray(this.handler.gl.TRIANGLE_STRIP, this._positionBuffer.numItems);
|
||||
};
|
||||
|
||||
Heatmap.prototype.drawBlur = function (texture, dir, size, radius) {
|
||||
|
||||
this.handler.clearFrame();
|
||||
|
||||
this.handler.shaderPrograms.blur.activate();
|
||||
|
||||
this.handler.shaderPrograms.blur.set({
|
||||
a_position: this._positionBuffer,
|
||||
u_texture: texture,
|
||||
resolution: size,
|
||||
radius: radius,
|
||||
dir: dir
|
||||
});
|
||||
|
||||
this.handler.shaderPrograms.blur.drawArray(this.handler.gl.TRIANGLE_STRIP, this._positionBuffer.numItems);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
my.Plane = function (name) {
|
||||
og.inheritance.base(this, name);
|
||||
this.vertexPositionBuffer = null;
|
||||
this.indexBuffer = null;
|
||||
this.size = 100;
|
||||
|
||||
this.light = null;
|
||||
|
||||
this.texture = null;
|
||||
};
|
||||
|
||||
og.inheritance.extend(my.Plane, og.node.RenderNode);
|
||||
|
||||
my.Plane.prototype.normalsPack = function () {
|
||||
normalsPacked = [];
|
||||
for (var i = 0; i < normals.length; i++) {
|
||||
normalsPacked[i] = normals[i] * 0.5 + 0.5;
|
||||
}
|
||||
};
|
||||
|
||||
my.Plane.prototype.normalsUnpack = function () {
|
||||
normalsUnpacked = [];
|
||||
for (var i = 0; i < normals.length; i++) {
|
||||
normalsUnpacked[i] = (normalsPacked[i] - 0.5) * 2.0;
|
||||
}
|
||||
};
|
||||
|
||||
my.Plane.prototype.initialization = function () {
|
||||
this.createBuffers();
|
||||
this.drawMode = this.renderer.handler.gl.TRIANGLE_STRIP;
|
||||
this.light = new og.light.PointLight();
|
||||
|
||||
this.light.setAmbient(new og.math.Vector3(0.14, 0.1, 0.2));
|
||||
this.light.setDiffuse(new og.math.Vector3(0.9, 0.9, 0.8));
|
||||
this.light.setSpecular(new og.math.Vector3(0.01, 0.01, 0.009));
|
||||
this.light.setShininess(8);
|
||||
this.light.addTo(this);
|
||||
this.light._position = new og.math.Vector3(5, 5, 5);
|
||||
|
||||
this.lightEnabled = true;
|
||||
|
||||
this.renderer.events.on("oncharkeypressed", this, this.toogleWireframe, og.input.KEY_X);
|
||||
this.renderer.events.on("oncharkeypressed", this, this.toogleLightPosition, og.input.KEY_C);
|
||||
|
||||
//
|
||||
//Hiddent context experiment
|
||||
//
|
||||
var normalMap = new og.shaderProgram.ShaderProgram("heatmap", {
|
||||
attributes: {
|
||||
a_position: { type: og.shaderProgram.types.VEC2, enableArray: true },
|
||||
a_normal: { type: og.shaderProgram.types.VEC3, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile("normalmap_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile("normalmap_fs.txt")
|
||||
});
|
||||
|
||||
var texture = new og.shaderProgram.ShaderProgram("texture", {
|
||||
attributes: {
|
||||
a_position: { type: og.shaderProgram.types.VEC2, enableArray: true }
|
||||
},
|
||||
uniforms: {
|
||||
u_sampler: { type: og.shaderProgram.types.SAMPLER2D }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile("texture_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile("texture_fs.txt")
|
||||
});
|
||||
|
||||
var blur = new og.shaderProgram.ShaderProgram("blur", {
|
||||
attributes: {
|
||||
a_position: { type: og.shaderProgram.types.VEC2, enableArray: true }
|
||||
},
|
||||
uniforms: {
|
||||
u_texture: { type: og.shaderProgram.types.SAMPLER2D },
|
||||
resolution: { type: og.shaderProgram.types.FLOAT },
|
||||
radius: { type: og.shaderProgram.types.FLOAT },
|
||||
dir: { type: og.shaderProgram.types.VEC2 }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile("blur_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile("blur_fs.txt")
|
||||
});
|
||||
|
||||
|
||||
this._hiddenHandler = new og.webgl.Handler();
|
||||
this._hiddenHandler.addShaderProgram(texture);
|
||||
this._hiddenHandler.addShaderProgram(blur);
|
||||
this._hiddenHandler.addShaderProgram(normalMap);
|
||||
this._hiddenHandler.init();
|
||||
|
||||
this._hiddenNode = new Heatmap(this._hiddenHandler, { alpha: false, depth: false });
|
||||
this._hiddenNode.init();
|
||||
|
||||
//make normal map
|
||||
this._hiddenHandler.setSize(128, 128);
|
||||
this._hiddenNode.drawNormalMap(normals);
|
||||
|
||||
//this._hiddenHandler.setSize(256, 256);
|
||||
//this._hiddenNode.drawTexture(this._hiddenNode.framebuffer.texture);
|
||||
|
||||
this._hiddenNode.drawBlur(/*this._hiddenHandler.createTexture(this._hiddenHandler.canvas)*/this._hiddenNode.framebuffer.texture, [1.0, 0.0], 128, 1);
|
||||
this._hiddenNode.drawBlur(this._hiddenHandler.createTexture(this._hiddenHandler.canvas), [0.0, 1.0], 128, 1);
|
||||
this.realNormals = this.renderer.handler.createTexture(this._hiddenHandler.canvas);
|
||||
|
||||
var img = new Image();
|
||||
var that = this;
|
||||
img.onload = function (e) {
|
||||
that.normalsTexture = that.renderer.handler.createTexture(this);
|
||||
};
|
||||
|
||||
img.src = "3912-normal.jpg";
|
||||
|
||||
};
|
||||
|
||||
my.Plane.prototype.toogleWireframe = function (e) {
|
||||
if (this.drawMode === this.renderer.handler.gl.LINE_STRIP) {
|
||||
this.drawMode = this.renderer.handler.gl.TRIANGLE_STRIP;
|
||||
} else {
|
||||
this.drawMode = this.renderer.handler.gl.LINE_STRIP;
|
||||
}
|
||||
};
|
||||
|
||||
my.Plane.prototype.toogleLightPosition = function () {
|
||||
this.light._position = this.renderer.activeCamera.eye.clone();
|
||||
};
|
||||
|
||||
my.Plane.prototype.createBuffers = function () {
|
||||
og.planetSegment.PlanetSegmentHelper.initIndexesTables(6);
|
||||
|
||||
|
||||
vertices = [];
|
||||
|
||||
var step = 1;
|
||||
var size = 32;
|
||||
|
||||
for (var i = 0; i <= size; i++) {
|
||||
for (var j = 0; j <= size; j++) {
|
||||
var x = j * step,
|
||||
y = (size) * step - i * step,
|
||||
z = Math.sin(x / 5) * Math.cos(1 * y / 5) * 1400;
|
||||
|
||||
vertices.push(x * this.size * 2, y * this.size * 2, z);
|
||||
}
|
||||
}
|
||||
|
||||
var gs = size + 1;
|
||||
normals = new Float64Array(gs * gs * 3);
|
||||
|
||||
var vertexIndices = og.planetSegment.PlanetSegmentHelper.createSegmentIndexes(size, [size, size, size, size]);
|
||||
var textureCoords = og.planetSegment.PlanetSegmentHelper.textureCoordsTable[size];
|
||||
|
||||
//function getVertex(i, j) {
|
||||
// if (i < 0) i = 0;
|
||||
// if (j < 0) j = 0;
|
||||
// if (i > gs - 1) i = gs - 1;
|
||||
// if (j > gs - 1) j = gs - 1;
|
||||
// var vInd = (i * gs + j) * 3;
|
||||
// return new og.math.Vector3(vertices[vInd], vertices[vInd + 1], vertices[vInd + 2]);
|
||||
//}
|
||||
|
||||
//for (var i = 0; i < gs - 1; i++) {
|
||||
// for (var j = 0; j < gs - 1; j++) {
|
||||
// var C = getVertex(i, j);
|
||||
// var B = getVertex(i - 1, j);
|
||||
// var D = getVertex(i, j - 1);
|
||||
// var E = getVertex(i, j + 1);
|
||||
// var F = getVertex(i + 1, j);
|
||||
|
||||
|
||||
// var vBC = og.math.Vector3.sub(C, B);
|
||||
// var vBE = og.math.Vector3.sub(E, B);
|
||||
// var nBCE = vBC.cross(vBE).normalize();
|
||||
|
||||
// var vDC = og.math.Vector3.sub(C, D);
|
||||
// var vDF = og.math.Vector3.sub(F, D);
|
||||
// var nDFC = vDF.cross(vDC).normalize();
|
||||
|
||||
// var vDB = og.math.Vector3.sub(B, D);
|
||||
// var nDCB = vDC.cross(vDB).normalize();
|
||||
|
||||
// var vCF = og.math.Vector3.sub(F, C);
|
||||
// var vCE = og.math.Vector3.sub(E, C);
|
||||
// var nCFE = vCF.cross(vCE).normalize();
|
||||
|
||||
// var nC = new og.math.Vector3((nBCE.x + nDFC.x + nDCB.x + nCFE.x) / 4, (nBCE.y + nDFC.y + nDCB.y + nCFE.y) / 4,
|
||||
// (nBCE.z + nDFC.z + nDCB.z + nCFE.z) / 4);
|
||||
|
||||
// // nC.normalize();
|
||||
|
||||
// var vInd = (i * gs + j) * 3;
|
||||
// normals[vInd] = nC.x;
|
||||
// normals[vInd + 1] = nC.y;
|
||||
// normals[vInd + 2] = nC.z;
|
||||
// }
|
||||
//}
|
||||
|
||||
for (var i = 0; i < gs - 1; i++) {
|
||||
for (var j = 0; j < gs - 1; j++) {
|
||||
|
||||
var vInd0 = (i * gs + j) * 3;
|
||||
var vInd1 = (i * gs + j + 1) * 3;
|
||||
var vInd2 = ((i + 1) * gs + j) * 3;
|
||||
var vInd3 = ((i + 1) * gs + (j + 1)) * 3;
|
||||
|
||||
var v0 = new og.math.Vector3(vertices[vInd0], vertices[vInd0 + 1], vertices[vInd0 + 2]),
|
||||
v1 = new og.math.Vector3(vertices[vInd1], vertices[vInd1 + 1], vertices[vInd1 + 2]),
|
||||
v2 = new og.math.Vector3(vertices[vInd2], vertices[vInd2 + 1], vertices[vInd2 + 2]),
|
||||
v3 = new og.math.Vector3(vertices[vInd3], vertices[vInd3 + 1], vertices[vInd3 + 2]);
|
||||
|
||||
var e10 = og.math.Vector3.sub(v1, v0),
|
||||
e20 = og.math.Vector3.sub(v2, v0),
|
||||
e30 = og.math.Vector3.sub(v3, v0);
|
||||
|
||||
var sw = e20.cross(e30);//.normalize();
|
||||
var ne = e30.cross(e10);//.normalize();
|
||||
|
||||
var n0 = og.math.Vector3.add(ne, sw);
|
||||
var n3 = og.math.Vector3.add(ne, sw);
|
||||
var n1 = og.math.Vector3.add(ne, sw);
|
||||
var n2 = og.math.Vector3.add(ne, sw);
|
||||
|
||||
//n0.normalize();
|
||||
//n1.normalize();
|
||||
//n3.normalize();
|
||||
//n2.normalize();
|
||||
|
||||
normals[vInd0] += n0.x;
|
||||
normals[vInd0 + 1] += n0.y;
|
||||
normals[vInd0 + 2] += n0.z;
|
||||
|
||||
normals[vInd1] += n1.x;
|
||||
normals[vInd1 + 1] += n1.y;
|
||||
normals[vInd1 + 2] += n1.z;
|
||||
|
||||
normals[vInd2] += n2.x;
|
||||
normals[vInd2 + 1] += n2.y;
|
||||
normals[vInd2 + 2] += n2.z;
|
||||
|
||||
normals[vInd3] += n3.x;
|
||||
normals[vInd3 + 1] += n3.y;
|
||||
normals[vInd3 + 2] += n3.z;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (var i = 0; i < normals.length; i += 3) {
|
||||
var l = Math.sqrt(normals[i] * normals[i] + normals[i + 1] * normals[i + 1] + normals[i + 2] * normals[i + 2]);
|
||||
normals[i] /= l;
|
||||
normals[i + 1] /= l;
|
||||
normals[i + 2] /= l;
|
||||
}
|
||||
|
||||
this.positionBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(vertices), 3, vertices.length / 3);
|
||||
this.normalBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(normals), 3, normals.length / 3);
|
||||
this.textureCoordBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(textureCoords), 2, textureCoords.length / 2);
|
||||
this.indexBuffer = this.renderer.handler.createElementArrayBuffer(new Uint16Array(vertexIndices), 1, vertexIndices.length);
|
||||
|
||||
|
||||
var lines = [];
|
||||
var colors = [];
|
||||
for (var i = 0; i < normals.length; i += 3) {
|
||||
|
||||
lines.push(vertices[i], vertices[i + 1], vertices[i + 2],
|
||||
vertices[i] + normals[i] * 100, vertices[i + 1] + normals[i + 1] * 100, vertices[i + 2] + normals[i + 2] * 100);
|
||||
|
||||
colors.push(1.0, 0.0, 0.0, 1.0,
|
||||
1.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
this.linesBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(lines), 3, 2 * vertices.length / 3);
|
||||
this.linesColorBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(colors), 4, 2 * vertices.length / 3);
|
||||
};
|
||||
|
||||
my.Plane.prototype.frame = function () {
|
||||
|
||||
var r = this.renderer;
|
||||
|
||||
var sh, p, gl;
|
||||
|
||||
//
|
||||
// Draw surface
|
||||
sh = r.handler.shaderPrograms.colorShader;
|
||||
p = sh._program;
|
||||
gl = r.handler.gl,
|
||||
sha = p.attributes,
|
||||
shu = p.uniforms;
|
||||
|
||||
sh.activate();
|
||||
|
||||
//gl.uniform4fv(shu.uColor._pName, [1, 1, 1, 1]);
|
||||
|
||||
//point light
|
||||
gl.uniform3fv(shu.pointLightsPositions._pName, this._pointLightsTransformedPositions);
|
||||
gl.uniform3fv(shu.pointLightsParamsv._pName, this._pointLightsParamsv);
|
||||
gl.uniform1fv(shu.pointLightsParamsf._pName, this._pointLightsParamsf);
|
||||
|
||||
//matrices
|
||||
gl.uniformMatrix4fv(shu.uPMatrix._pName, false, r.activeCamera.pMatrix._m);
|
||||
gl.uniformMatrix4fv(shu.uMVMatrix._pName, false, r.activeCamera.mvMatrix._m);
|
||||
gl.uniformMatrix3fv(shu.uNMatrix._pName, false, r.activeCamera.nMatrix._m);
|
||||
|
||||
//diffuse texture
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.realNormals);
|
||||
gl.uniform1i(shu.uSampler._pName, 0);
|
||||
|
||||
gl.activeTexture(gl.TEXTURE1);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.normalsTexture);
|
||||
gl.uniform1i(shu.uNormalsMap._pName, 1);
|
||||
|
||||
|
||||
//normals
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.normalBuffer);
|
||||
gl.vertexAttribPointer(sha.aVertexNormal._pName, this.normalBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
||||
|
||||
//vertices positions
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer);
|
||||
gl.vertexAttribPointer(sha.aVertexPosition._pName, this.positionBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
||||
|
||||
//texture coordinates
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.textureCoordBuffer);
|
||||
gl.vertexAttribPointer(sha.aTextureCoord._pName, this.textureCoordBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
||||
|
||||
//draw indexes
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
||||
gl.drawElements(this.drawMode, this.indexBuffer.numItems, gl.UNSIGNED_SHORT, 0);
|
||||
|
||||
|
||||
//
|
||||
//Draw normals
|
||||
//r.handler.shaderPrograms.flat.activate();
|
||||
|
||||
//r.handler.shaderPrograms.flat.set({
|
||||
// uPMVMatrix: r.activeCamera.pmvMatrix._m,
|
||||
// aVertexPosition: this.linesBuffer,
|
||||
// aVertexColor: this.linesColorBuffer
|
||||
//});
|
||||
//r.handler.shaderPrograms.flat.drawArray(r.handler.gl.LINES, this.linesBuffer.numItems);
|
||||
|
||||
};
|
||||
@ -1,71 +1,71 @@
|
||||
#extension GL_OES_standard_derivatives : enable
|
||||
|
||||
precision highp float;
|
||||
|
||||
varying vec4 v_TransformedNormal;
|
||||
varying vec4 v_Position;
|
||||
varying vec2 v_TextureCoord;
|
||||
varying vec4 v_lightDirection;
|
||||
varying vec4 v_EyeVec;
|
||||
|
||||
|
||||
|
||||
//uniform vec4 uColor;
|
||||
uniform sampler2D uSampler;
|
||||
uniform sampler2D uNormalsMap;
|
||||
|
||||
#define MAX_POINT_LIGHTS 1
|
||||
|
||||
uniform vec3 pointLightsParamsv[MAX_POINT_LIGHTS * 3];
|
||||
uniform float pointLightsParamsf[MAX_POINT_LIGHTS];
|
||||
|
||||
varying mat3 v_NMatrix;
|
||||
|
||||
mat3 cotangent_frame(vec3 N, vec3 p, vec2 uv)
|
||||
{
|
||||
// get edge vectors of the pixel triangle
|
||||
vec3 dp1 = dFdx( p );
|
||||
vec3 dp2 = dFdy( p );
|
||||
vec2 duv1 = dFdx( uv );
|
||||
vec2 duv2 = dFdy( uv );
|
||||
|
||||
// solve the linear system
|
||||
vec3 dp2perp = cross( dp2, N );
|
||||
vec3 dp1perp = cross( N, dp1 );
|
||||
vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;
|
||||
vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;
|
||||
|
||||
// construct a scale-invariant frame
|
||||
float invmax = inversesqrt( max( dot(T,T), dot(B,B) ) );
|
||||
return mat3( T * invmax, B * invmax, N );
|
||||
}
|
||||
|
||||
vec3 perturb_normal( vec3 N, vec3 V, vec2 texcoord )
|
||||
{
|
||||
// assume N, the interpolated vertex normal and
|
||||
// V, the view vector (vertex to eye)
|
||||
vec3 map = texture2D(uNormalsMap, texcoord ).xyz;
|
||||
map = map * 255./127. - 128./127.;
|
||||
mat3 TBN = cotangent_frame(N, -V, texcoord);
|
||||
return normalize(TBN * map);
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
|
||||
vec2 uv = v_TextureCoord;
|
||||
vec3 N = normalize(v_TransformedNormal.xyz);
|
||||
vec3 L = normalize(v_lightDirection.xyz);
|
||||
vec3 V = normalize(v_EyeVec.xyz);
|
||||
|
||||
vec3 PN = perturb_normal(N, V, uv);
|
||||
|
||||
vec3 R = reflect(-L, PN);
|
||||
|
||||
float specular = pow(max(dot(R, V), 0.0), pointLightsParamsf[0]);
|
||||
float lambertTerm = max(dot(PN, L), 0.0);
|
||||
vec3 lightWeighting = pointLightsParamsv[0] + pointLightsParamsv[1] * lambertTerm + pointLightsParamsv[2] * specular;
|
||||
|
||||
vec4 tColor = vec4(1.0);//texture2D( uSampler, v_TextureCoord.st );
|
||||
|
||||
gl_FragColor = vec4(tColor.rgb * lightWeighting, 1.0);
|
||||
#extension GL_OES_standard_derivatives : enable
|
||||
|
||||
precision highp float;
|
||||
|
||||
varying vec4 v_TransformedNormal;
|
||||
varying vec4 v_Position;
|
||||
varying vec2 v_TextureCoord;
|
||||
varying vec4 v_lightDirection;
|
||||
varying vec4 v_EyeVec;
|
||||
|
||||
|
||||
|
||||
//uniform vec4 uColor;
|
||||
uniform sampler2D uSampler;
|
||||
uniform sampler2D uNormalsMap;
|
||||
|
||||
#define MAX_POINT_LIGHTS 1
|
||||
|
||||
uniform vec3 pointLightsParamsv[MAX_POINT_LIGHTS * 3];
|
||||
uniform float pointLightsParamsf[MAX_POINT_LIGHTS];
|
||||
|
||||
varying mat3 v_NMatrix;
|
||||
|
||||
mat3 cotangent_frame(vec3 N, vec3 p, vec2 uv)
|
||||
{
|
||||
// get edge vectors of the pixel triangle
|
||||
vec3 dp1 = dFdx( p );
|
||||
vec3 dp2 = dFdy( p );
|
||||
vec2 duv1 = dFdx( uv );
|
||||
vec2 duv2 = dFdy( uv );
|
||||
|
||||
// solve the linear system
|
||||
vec3 dp2perp = cross( dp2, N );
|
||||
vec3 dp1perp = cross( N, dp1 );
|
||||
vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;
|
||||
vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;
|
||||
|
||||
// construct a scale-invariant frame
|
||||
float invmax = inversesqrt( max( dot(T,T), dot(B,B) ) );
|
||||
return mat3( T * invmax, B * invmax, N );
|
||||
}
|
||||
|
||||
vec3 perturb_normal( vec3 N, vec3 V, vec2 texcoord )
|
||||
{
|
||||
// assume N, the interpolated vertex normal and
|
||||
// V, the view vector (vertex to eye)
|
||||
vec3 map = texture2D(uNormalsMap, texcoord ).xyz;
|
||||
map = map * 255./127. - 128./127.;
|
||||
mat3 TBN = cotangent_frame(N, -V, texcoord);
|
||||
return normalize(TBN * map);
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
|
||||
vec2 uv = v_TextureCoord;
|
||||
vec3 N = normalize(v_TransformedNormal.xyz);
|
||||
vec3 L = normalize(v_lightDirection.xyz);
|
||||
vec3 V = normalize(v_EyeVec.xyz);
|
||||
|
||||
vec3 PN = perturb_normal(N, V, uv);
|
||||
|
||||
vec3 R = reflect(-L, PN);
|
||||
|
||||
float specular = pow(max(dot(R, V), 0.0), pointLightsParamsf[0]);
|
||||
float lambertTerm = max(dot(PN, L), 0.0);
|
||||
vec3 lightWeighting = pointLightsParamsv[0] + pointLightsParamsv[1] * lambertTerm + pointLightsParamsv[2] * specular;
|
||||
|
||||
vec4 tColor = vec4(1.0);//texture2D( uSampler, v_TextureCoord.st );
|
||||
|
||||
gl_FragColor = vec4(tColor.rgb * lightWeighting, 1.0);
|
||||
}
|
||||
@ -1,28 +1,28 @@
|
||||
attribute vec3 aVertexNormal;
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec2 aTextureCoord;
|
||||
|
||||
uniform mat4 uPMatrix;
|
||||
uniform mat4 uMVMatrix;
|
||||
uniform mat3 uNMatrix;
|
||||
|
||||
uniform vec3 pointLightsPositions[1];
|
||||
|
||||
|
||||
varying vec4 v_TransformedNormal;
|
||||
varying vec4 v_Position;
|
||||
varying vec2 v_TextureCoord;
|
||||
varying vec4 v_lightDirection;
|
||||
varying vec4 v_EyeVec;
|
||||
|
||||
varying mat3 v_NMatrix;
|
||||
|
||||
void main(void) {
|
||||
v_Position = uMVMatrix * vec4(aVertexPosition, 1.0);
|
||||
v_EyeVec = -v_Position;
|
||||
gl_Position = uPMatrix * v_Position;
|
||||
v_TransformedNormal = vec4(uNMatrix * aVertexNormal, 1.0);
|
||||
v_TextureCoord = aTextureCoord;
|
||||
v_NMatrix = uNMatrix;
|
||||
v_lightDirection = vec4(pointLightsPositions[0], 1.0) - v_Position;
|
||||
}
|
||||
attribute vec3 aVertexNormal;
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec2 aTextureCoord;
|
||||
|
||||
uniform mat4 uPMatrix;
|
||||
uniform mat4 uMVMatrix;
|
||||
uniform mat3 uNMatrix;
|
||||
|
||||
uniform vec3 pointLightsPositions[1];
|
||||
|
||||
|
||||
varying vec4 v_TransformedNormal;
|
||||
varying vec4 v_Position;
|
||||
varying vec2 v_TextureCoord;
|
||||
varying vec4 v_lightDirection;
|
||||
varying vec4 v_EyeVec;
|
||||
|
||||
varying mat3 v_NMatrix;
|
||||
|
||||
void main(void) {
|
||||
v_Position = uMVMatrix * vec4(aVertexPosition, 1.0);
|
||||
v_EyeVec = -v_Position;
|
||||
gl_Position = uPMatrix * v_Position;
|
||||
v_TransformedNormal = vec4(uNMatrix * aVertexNormal, 1.0);
|
||||
v_TextureCoord = aTextureCoord;
|
||||
v_NMatrix = uNMatrix;
|
||||
v_lightDirection = vec4(pointLightsPositions[0], 1.0) - v_Position;
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
precision highp float;
|
||||
|
||||
varying vec2 v_texCoords;
|
||||
|
||||
uniform sampler2D u_sampler;
|
||||
|
||||
void main(void) {
|
||||
vec4 tColor = texture2D( u_sampler, v_texCoords.st );
|
||||
gl_FragColor = vec4(tColor.rgb, 1.0);
|
||||
precision highp float;
|
||||
|
||||
varying vec2 v_texCoords;
|
||||
|
||||
uniform sampler2D u_sampler;
|
||||
|
||||
void main(void) {
|
||||
vec4 tColor = texture2D( u_sampler, v_texCoords.st );
|
||||
gl_FragColor = vec4(tColor.rgb, 1.0);
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
attribute vec2 a_position;
|
||||
//attribute vec2 a_texCoords;
|
||||
|
||||
varying vec2 v_texCoords;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_position, 0, 1);
|
||||
vec2 vt = a_position * 0.5 + 0.5;
|
||||
v_texCoords = vec2(vt.x, 1.0 - vt.y);//a_texCoords;
|
||||
attribute vec2 a_position;
|
||||
//attribute vec2 a_texCoords;
|
||||
|
||||
varying vec2 v_texCoords;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_position, 0, 1);
|
||||
vec2 vt = a_position * 0.5 + 0.5;
|
||||
v_texCoords = vec2(vt.x, 1.0 - vt.y);//a_texCoords;
|
||||
}
|
||||
@ -1,31 +1,31 @@
|
||||
og.layer.MapServers = {
|
||||
"MapQuest": { url: "http://otile1.mqcdn.com/tiles/1.0.0/map/{zoom}/{tilex}/{tiley}.jpg", maxZoom: -1 },
|
||||
"MapQuestSat": { url: "http://otile1.mqcdn.com/tiles/1.0.0/sat/{zoom}/{tilex}/{tiley}.jpg", maxZoom: -1 },
|
||||
"GoogleMap": { url: "http://mt1.google.com/vt/lyrs=m&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"GoogleTerrain": { url: "http://mt1.google.com/vt/lyrs=p&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"GoogleSat": { url: "http://mt1.google.com/vt/lyrs=s&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"GoogleHibrid": { url: "http://mt1.google.com/vt/lyrs=y&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"OSM": { url: "http://a.tile.openstreetmap.org/{zoom}/{tilex}/{tiley}.png", maxZoom: -1 },
|
||||
"OSMb": { url: "http://b.tile.opencyclemap.org/cycle/{zoom}/{tilex}/{tiley}.png", maxZoom: -1 },
|
||||
"ArcGISBoundaries": { url: "http://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/{zoom}/{tilex}/{tiley}", maxZoom: -1},
|
||||
"ArcGISWorldImagery": { url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{zoom}/{tilex}/{tiley}", maxZoom: -1 },
|
||||
"ArcGISWorldStreetMap": { url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{zoom}/{tilex}/{tiley}", maxZoom: -1 },
|
||||
"ArcGISNatGeo": { url: "http://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{zoom}/{tilx}/{tiley}", maxZoom: -1 },
|
||||
"Cosmosnimki": { url: "http://maps.kosmosnimki.ru/TileService.ashx?Request=gettile&apikey=L5VW1QBBHJ&layerName=4F9F7CCCCBBC4BD08469F58C02F17AE4&crs=epsg:3857&z={zoom}&x={tilex}&y={tiley}", maxZoom: -1 }
|
||||
};
|
||||
|
||||
og.layer.MapServersProxy = {
|
||||
"MapQuest": { url: "http://127.0.0.1/tiles/1.0.0/map/{zoom}/{tilex}/{tiley}.jpg", maxZoom: -1 },
|
||||
"MapQuestSat": { url: "http://127.0.0.1/tiles/1.0.0/sat/{zoom}/{tilex}/{tiley}.jpg", maxZoom: -1 },
|
||||
"GoogleMap": { url: "http://mt1.google.com/vt/lyrs=m&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"GoogleTerrain": { url: "http://mt1.google.com/vt/lyrs=p&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"GoogleSat": { url: "http://mt1.google.com/vt/lyrs=s&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"GoogleHibrid": { url: "http://mt1.google.com/vt/lyrs=y&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"OSM": { url: "http://127.0.0.1/osm/{zoom}/{tilex}/{tiley}.png", maxZoom: -1 },
|
||||
"OSMb": { url: "http://127.0.0.1/osmb/cycle/{zoom}/{tilex}/{tiley}.png", maxZoom: -1 },
|
||||
"ArcGISBoundaries": { url: "http://127.0.0.1/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/{zoom}/{tiley}/{tilex}", maxZoom: -1},
|
||||
"ArcGISWorldImagery": { url: "http://127.0.0.1/ArcGIS/rest/services/World_Imagery/MapServer/tile/{zoom}/{tiley}/{tilex}", maxZoom: -1 },
|
||||
"ArcGISWorldStreetMap": { url: "http://127.0.0.1/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{zoom}/{tiley}/{tilex}", maxZoom: -1 },
|
||||
"ArcGISNatGeo": { url: "http://127.0.0.1/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{zoom}/{tiley}/{tilex}", maxZoom: -1 },
|
||||
"Cosmosnimki": { url: "http://127.0.0.1/TileService.ashx?Request=gettile&apikey=L5VW1QBBHJ&layerName=4F9F7CCCCBBC4BD08469F58C02F17AE4&crs=epsg:3857&z={zoom}&x={tilex}&y={tiley}", maxZoom: -1 }
|
||||
};
|
||||
og.layer.MapServers = {
|
||||
"MapQuest": { url: "http://otile1.mqcdn.com/tiles/1.0.0/map/{zoom}/{tilex}/{tiley}.jpg", maxZoom: -1 },
|
||||
"MapQuestSat": { url: "http://otile1.mqcdn.com/tiles/1.0.0/sat/{zoom}/{tilex}/{tiley}.jpg", maxZoom: -1 },
|
||||
"GoogleMap": { url: "http://mt1.google.com/vt/lyrs=m&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"GoogleTerrain": { url: "http://mt1.google.com/vt/lyrs=p&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"GoogleSat": { url: "http://mt1.google.com/vt/lyrs=s&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"GoogleHibrid": { url: "http://mt1.google.com/vt/lyrs=y&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"OSM": { url: "http://a.tile.openstreetmap.org/{zoom}/{tilex}/{tiley}.png", maxZoom: -1 },
|
||||
"OSMb": { url: "http://b.tile.opencyclemap.org/cycle/{zoom}/{tilex}/{tiley}.png", maxZoom: -1 },
|
||||
"ArcGISBoundaries": { url: "http://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/{zoom}/{tilex}/{tiley}", maxZoom: -1},
|
||||
"ArcGISWorldImagery": { url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{zoom}/{tilex}/{tiley}", maxZoom: -1 },
|
||||
"ArcGISWorldStreetMap": { url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{zoom}/{tilex}/{tiley}", maxZoom: -1 },
|
||||
"ArcGISNatGeo": { url: "http://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{zoom}/{tilx}/{tiley}", maxZoom: -1 },
|
||||
"Cosmosnimki": { url: "http://maps.kosmosnimki.ru/TileService.ashx?Request=gettile&apikey=L5VW1QBBHJ&layerName=4F9F7CCCCBBC4BD08469F58C02F17AE4&crs=epsg:3857&z={zoom}&x={tilex}&y={tiley}", maxZoom: -1 }
|
||||
};
|
||||
|
||||
og.layer.MapServersProxy = {
|
||||
"MapQuest": { url: "http://127.0.0.1/tiles/1.0.0/map/{zoom}/{tilex}/{tiley}.jpg", maxZoom: -1 },
|
||||
"MapQuestSat": { url: "http://127.0.0.1/tiles/1.0.0/sat/{zoom}/{tilex}/{tiley}.jpg", maxZoom: -1 },
|
||||
"GoogleMap": { url: "http://mt1.google.com/vt/lyrs=m&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"GoogleTerrain": { url: "http://mt1.google.com/vt/lyrs=p&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"GoogleSat": { url: "http://mt1.google.com/vt/lyrs=s&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"GoogleHibrid": { url: "http://mt1.google.com/vt/lyrs=y&hl=ru&x={tilex}&y={tiley}&z={zoom}", maxZoom: -1 },
|
||||
"OSM": { url: "http://127.0.0.1/osm/{zoom}/{tilex}/{tiley}.png", maxZoom: -1 },
|
||||
"OSMb": { url: "http://127.0.0.1/osmb/cycle/{zoom}/{tilex}/{tiley}.png", maxZoom: -1 },
|
||||
"ArcGISBoundaries": { url: "http://127.0.0.1/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/{zoom}/{tiley}/{tilex}", maxZoom: -1},
|
||||
"ArcGISWorldImagery": { url: "http://127.0.0.1/ArcGIS/rest/services/World_Imagery/MapServer/tile/{zoom}/{tiley}/{tilex}", maxZoom: -1 },
|
||||
"ArcGISWorldStreetMap": { url: "http://127.0.0.1/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{zoom}/{tiley}/{tilex}", maxZoom: -1 },
|
||||
"ArcGISNatGeo": { url: "http://127.0.0.1/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{zoom}/{tiley}/{tilex}", maxZoom: -1 },
|
||||
"Cosmosnimki": { url: "http://127.0.0.1/TileService.ashx?Request=gettile&apikey=L5VW1QBBHJ&layerName=4F9F7CCCCBBC4BD08469F58C02F17AE4&crs=epsg:3857&z={zoom}&x={tilex}&y={tiley}", maxZoom: -1 }
|
||||
};
|
||||
|
||||
174
src/og/ajax.js
174
src/og/ajax.js
@ -1,88 +1,88 @@
|
||||
goog.provide('og.Ajax');
|
||||
|
||||
og.Ajax = {
|
||||
ReadyState:
|
||||
{
|
||||
Uninitialized: 0,
|
||||
Loading: 1,
|
||||
Loaded: 2,
|
||||
Interactive: 3,
|
||||
Complete: 4
|
||||
},
|
||||
Status:
|
||||
{
|
||||
OK: 200,
|
||||
Created: 201,
|
||||
Accepted: 202,
|
||||
NoContent: 204,
|
||||
BadRequest: 400,
|
||||
Forbidden: 403,
|
||||
NotFound: 404,
|
||||
Gone: 410,
|
||||
ServerError: 500
|
||||
},
|
||||
Method: { Get: "GET", Post: "POST" },
|
||||
Asynchronous: true,
|
||||
Synchronous: false
|
||||
};
|
||||
|
||||
|
||||
og.Ajax.defaultParams = { type: og.Ajax.Method.Get, async: og.Ajax.Asynchronous, data: null, sender: null, responseType: "text" };
|
||||
|
||||
og.Ajax.createXMLHttp = function () {
|
||||
var xhr = null;
|
||||
if (typeof (XMLHttpRequest) != undefined) {
|
||||
xhr = new XMLHttpRequest;
|
||||
return xhr;
|
||||
} else if (window.ActiveXObject) {
|
||||
var ieXMLHttpVersions = ['MSXML2.XMLHttp.5.0', 'MSXML2.XMLHttp.4.0', 'MSXML2.XMLHttp.3.0', 'MSXML2.XMLHttp', 'Microsoft.XMLHttp'];
|
||||
for (var i = 0; i < ieXMLHttpVersions.length; i++) {
|
||||
try {
|
||||
xhr = new ActiveXObject(ieXMLHttpVersions[i]);
|
||||
return xhr;
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
og.Ajax.request = function (url, params) {
|
||||
|
||||
var p = {};
|
||||
|
||||
for (var i in og.Ajax.defaultParams) {
|
||||
p[i] = og.Ajax.defaultParams[i];
|
||||
}
|
||||
|
||||
for (var i in params) {
|
||||
p[i] = params[i];
|
||||
}
|
||||
|
||||
var xhr = og.Ajax.createXMLHttp();
|
||||
|
||||
xhr.open(p.type, url, p.async);
|
||||
|
||||
if (p.type === og.Ajax.Method.Post) {
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
}
|
||||
|
||||
if (p.async)
|
||||
xhr.responseType = p.responseType;
|
||||
|
||||
xhr.overrideMimeType("text/plain");
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === og.Ajax.ReadyState.Complete) {
|
||||
if (xhr.status === og.Ajax.Status.OK) {
|
||||
if (params.success)
|
||||
params.success.call(params.sender ? params.sender : this, xhr.response);
|
||||
} else {
|
||||
if (params.error)
|
||||
params.error.call(params.sender ? params.sender : this, xhr.response, xhr.status);
|
||||
}
|
||||
} else {
|
||||
//still loading
|
||||
}
|
||||
};
|
||||
xhr.send(params.data ? params.data : og.Ajax.defaultParams.data);
|
||||
goog.provide('og.Ajax');
|
||||
|
||||
og.Ajax = {
|
||||
ReadyState:
|
||||
{
|
||||
Uninitialized: 0,
|
||||
Loading: 1,
|
||||
Loaded: 2,
|
||||
Interactive: 3,
|
||||
Complete: 4
|
||||
},
|
||||
Status:
|
||||
{
|
||||
OK: 200,
|
||||
Created: 201,
|
||||
Accepted: 202,
|
||||
NoContent: 204,
|
||||
BadRequest: 400,
|
||||
Forbidden: 403,
|
||||
NotFound: 404,
|
||||
Gone: 410,
|
||||
ServerError: 500
|
||||
},
|
||||
Method: { Get: "GET", Post: "POST" },
|
||||
Asynchronous: true,
|
||||
Synchronous: false
|
||||
};
|
||||
|
||||
|
||||
og.Ajax.defaultParams = { type: og.Ajax.Method.Get, async: og.Ajax.Asynchronous, data: null, sender: null, responseType: "text" };
|
||||
|
||||
og.Ajax.createXMLHttp = function () {
|
||||
var xhr = null;
|
||||
if (typeof (XMLHttpRequest) != undefined) {
|
||||
xhr = new XMLHttpRequest;
|
||||
return xhr;
|
||||
} else if (window.ActiveXObject) {
|
||||
var ieXMLHttpVersions = ['MSXML2.XMLHttp.5.0', 'MSXML2.XMLHttp.4.0', 'MSXML2.XMLHttp.3.0', 'MSXML2.XMLHttp', 'Microsoft.XMLHttp'];
|
||||
for (var i = 0; i < ieXMLHttpVersions.length; i++) {
|
||||
try {
|
||||
xhr = new ActiveXObject(ieXMLHttpVersions[i]);
|
||||
return xhr;
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
og.Ajax.request = function (url, params) {
|
||||
|
||||
var p = {};
|
||||
|
||||
for (var i in og.Ajax.defaultParams) {
|
||||
p[i] = og.Ajax.defaultParams[i];
|
||||
}
|
||||
|
||||
for (var i in params) {
|
||||
p[i] = params[i];
|
||||
}
|
||||
|
||||
var xhr = og.Ajax.createXMLHttp();
|
||||
|
||||
xhr.open(p.type, url, p.async);
|
||||
|
||||
if (p.type === og.Ajax.Method.Post) {
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
}
|
||||
|
||||
if (p.async)
|
||||
xhr.responseType = p.responseType;
|
||||
|
||||
xhr.overrideMimeType("text/plain");
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === og.Ajax.ReadyState.Complete) {
|
||||
if (xhr.status === og.Ajax.Status.OK) {
|
||||
if (params.success)
|
||||
params.success.call(params.sender ? params.sender : this, xhr.response);
|
||||
} else {
|
||||
if (params.error)
|
||||
params.error.call(params.sender ? params.sender : this, xhr.response, xhr.status);
|
||||
}
|
||||
} else {
|
||||
//still loading
|
||||
}
|
||||
};
|
||||
xhr.send(params.data ? params.data : og.Ajax.defaultParams.data);
|
||||
};
|
||||
@ -1,28 +1,28 @@
|
||||
goog.provide('og.bv.Box');
|
||||
|
||||
goog.require('og.bv');
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
og.bv.Box = function () {
|
||||
this.vertices = [new og.math.Vector3(), new og.math.Vector3(), new og.math.Vector3(), new og.math.Vector3(), new og.math.Vector3(), new og.math.Vector3(), new og.math.Vector3(), new og.math.Vector3()];
|
||||
};
|
||||
|
||||
og.bv.Box.prototype.setFromBounds = function (bounds) {
|
||||
var xmin = bounds[0], xmax = bounds[1],
|
||||
ymin = bounds[2], ymax = bounds[3],
|
||||
zmin = bounds[4], zmax = bounds[5];
|
||||
|
||||
this.vertices[0].set(xmin, ymin, zmin);
|
||||
this.vertices[1].set(xmax, ymin, zmin);
|
||||
this.vertices[2].set(xmax, ymin, zmax);
|
||||
this.vertices[3].set(xmin, ymin, zmax);
|
||||
this.vertices[4].set(xmin, ymax, zmin);
|
||||
this.vertices[5].set(xmax, ymax, zmin);
|
||||
this.vertices[6].set(xmax, ymax, zmax);
|
||||
this.vertices[7].set(xmin, ymax, zmax);
|
||||
|
||||
};
|
||||
|
||||
og.bv.Box.prototype.setFromExtent = function (ellipsoid, extent) {
|
||||
this.setFromBounds(og.bv.getBoundsFromExtent(ellipsoid, extent));
|
||||
goog.provide('og.bv.Box');
|
||||
|
||||
goog.require('og.bv');
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
og.bv.Box = function () {
|
||||
this.vertices = [new og.math.Vector3(), new og.math.Vector3(), new og.math.Vector3(), new og.math.Vector3(), new og.math.Vector3(), new og.math.Vector3(), new og.math.Vector3(), new og.math.Vector3()];
|
||||
};
|
||||
|
||||
og.bv.Box.prototype.setFromBounds = function (bounds) {
|
||||
var xmin = bounds[0], xmax = bounds[1],
|
||||
ymin = bounds[2], ymax = bounds[3],
|
||||
zmin = bounds[4], zmax = bounds[5];
|
||||
|
||||
this.vertices[0].set(xmin, ymin, zmin);
|
||||
this.vertices[1].set(xmax, ymin, zmin);
|
||||
this.vertices[2].set(xmax, ymin, zmax);
|
||||
this.vertices[3].set(xmin, ymin, zmax);
|
||||
this.vertices[4].set(xmin, ymax, zmin);
|
||||
this.vertices[5].set(xmax, ymax, zmin);
|
||||
this.vertices[6].set(xmax, ymax, zmax);
|
||||
this.vertices[7].set(xmin, ymax, zmax);
|
||||
|
||||
};
|
||||
|
||||
og.bv.Box.prototype.setFromExtent = function (ellipsoid, extent) {
|
||||
this.setFromBounds(og.bv.getBoundsFromExtent(ellipsoid, extent));
|
||||
};
|
||||
@ -1,5 +1,5 @@
|
||||
goog.provide('og.bv');
|
||||
|
||||
goog.require('og.Extent');
|
||||
goog.require('og.math');
|
||||
goog.provide('og.bv');
|
||||
|
||||
goog.require('og.Extent');
|
||||
goog.require('og.math');
|
||||
goog.require('og.LonLat');
|
||||
@ -1,14 +1,14 @@
|
||||
goog.provide('og.bv.Sphere');
|
||||
|
||||
goog.require('og.bv');
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
og.bv.Sphere = function (radius, center) {
|
||||
this.radius = radius || 0;
|
||||
this.center = center ? center.clone() : new og.math.Vector3();
|
||||
};
|
||||
|
||||
og.bv.Sphere.prototype.setFromBounds = function (bounds) {
|
||||
this.center.set(bounds[0] + (bounds[1] - bounds[0]) / 2, bounds[2] + (bounds[3] - bounds[2]) / 2, bounds[4] + (bounds[5] - bounds[4]) / 2);
|
||||
this.radius = this.center.distance(new og.math.Vector3(bounds[0], bounds[2], bounds[4]));
|
||||
};
|
||||
goog.provide('og.bv.Sphere');
|
||||
|
||||
goog.require('og.bv');
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
og.bv.Sphere = function (radius, center) {
|
||||
this.radius = radius || 0;
|
||||
this.center = center ? center.clone() : new og.math.Vector3();
|
||||
};
|
||||
|
||||
og.bv.Sphere.prototype.setFromBounds = function (bounds) {
|
||||
this.center.set(bounds[0] + (bounds[1] - bounds[0]) / 2, bounds[2] + (bounds[3] - bounds[2]) / 2, bounds[4] + (bounds[5] - bounds[4]) / 2);
|
||||
this.radius = this.center.distance(new og.math.Vector3(bounds[0], bounds[2], bounds[4]));
|
||||
};
|
||||
|
||||
@ -1,44 +1,44 @@
|
||||
goog.provide('og.control.Control');
|
||||
|
||||
/**
|
||||
* Class Control
|
||||
* Controls affect the display or behaviour of the render. They allow everything
|
||||
* from navigating to displaying a scale indicator.
|
||||
* Example:
|
||||
*
|
||||
* >
|
||||
* >
|
||||
* >
|
||||
*/
|
||||
|
||||
og.control.Control = function (options) {
|
||||
this.renderer = null;
|
||||
this.activated = false;
|
||||
if (options) {
|
||||
this.autoActivate = options.autoActivate ? options.autoActivate : false;
|
||||
this.active = options.active ? options.active : false;
|
||||
}
|
||||
};
|
||||
|
||||
og.control.Control.prototype.setRenderer = function (renderer) {
|
||||
this.renderer = renderer;
|
||||
if (this.autoActivate) {
|
||||
this.initialize();
|
||||
this.active = true;
|
||||
}
|
||||
};
|
||||
|
||||
og.control.Control.prototype.initialize = function () {
|
||||
if (this.init) {
|
||||
this.init();
|
||||
}
|
||||
this.activated = true;
|
||||
};
|
||||
|
||||
og.control.Control.prototype.activate = function () {
|
||||
this.active = true;
|
||||
};
|
||||
|
||||
og.control.Control.prototype.deactivate = function () {
|
||||
this.active = false;
|
||||
goog.provide('og.control.Control');
|
||||
|
||||
/**
|
||||
* Class Control
|
||||
* Controls affect the display or behaviour of the render. They allow everything
|
||||
* from navigating to displaying a scale indicator.
|
||||
* Example:
|
||||
*
|
||||
* >
|
||||
* >
|
||||
* >
|
||||
*/
|
||||
|
||||
og.control.Control = function (options) {
|
||||
this.renderer = null;
|
||||
this.activated = false;
|
||||
if (options) {
|
||||
this.autoActivate = options.autoActivate ? options.autoActivate : false;
|
||||
this.active = options.active ? options.active : false;
|
||||
}
|
||||
};
|
||||
|
||||
og.control.Control.prototype.setRenderer = function (renderer) {
|
||||
this.renderer = renderer;
|
||||
if (this.autoActivate) {
|
||||
this.initialize();
|
||||
this.active = true;
|
||||
}
|
||||
};
|
||||
|
||||
og.control.Control.prototype.initialize = function () {
|
||||
if (this.init) {
|
||||
this.init();
|
||||
}
|
||||
this.activated = true;
|
||||
};
|
||||
|
||||
og.control.Control.prototype.activate = function () {
|
||||
this.active = true;
|
||||
};
|
||||
|
||||
og.control.Control.prototype.deactivate = function () {
|
||||
this.active = false;
|
||||
};
|
||||
@ -1,155 +1,155 @@
|
||||
goog.provide('og.control.LayerSwitcher');
|
||||
|
||||
goog.require('og.inheritance');
|
||||
|
||||
og.control.LayerSwitcher = function (options) {
|
||||
og.inheritance.base(this, options);
|
||||
this.dialog = null;
|
||||
this.baseLayersDiv = null;
|
||||
this.overlaysDiv = null;
|
||||
this._id = og.control.LayerSwitcher.numSwitches++;
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.numSwitches = 0;
|
||||
|
||||
og.inheritance.extend(og.control.LayerSwitcher, og.control.Control);
|
||||
|
||||
og.control.LayerSwitcher.prototype.init = function () {
|
||||
this.renderer.renderNodes.Earth.events.on("onlayeradded", this, this.onLayerAdded);
|
||||
this.renderer.renderNodes.Earth.events.on("onlayerremoved", this, this.onLayerRemoved);
|
||||
this.renderer.renderNodes.Earth.events.on("onbaselayerchanged", this, this.onBaseLayerChanged);
|
||||
this.renderer.renderNodes.Earth.events.on("onlayervisibilitychanged", this, this.onLayerVisibilityChanged);
|
||||
this.createSwitcher();
|
||||
this.createDialog();
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.onLayerAdded = function (layer) {
|
||||
console.log("added");
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.onLayerRemoved = function (layer) {
|
||||
console.log("removed");
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.onBaseLayerChanged = function (layer) {
|
||||
console.log("basechanged");
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.onLayerVisibilityChanged = function (layer) {
|
||||
console.log("changed " + layer.id);
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.createBaseLayersDiv = function () {
|
||||
var layersDiv = document.createElement('div');
|
||||
layersDiv.className = "layersDiv";
|
||||
this.dialog.appendChild(layersDiv);
|
||||
|
||||
var baseLayersLbl = document.createElement('div');
|
||||
baseLayersLbl.className = "layersDiv";
|
||||
baseLayersLbl.innerHTML = "Base Layer";
|
||||
layersDiv.appendChild(baseLayersLbl);
|
||||
|
||||
this.baseLayersDiv = document.createElement('div');
|
||||
layersDiv.appendChild(this.baseLayersDiv);
|
||||
this.createBaseLayersList(this.baseLayersDiv);
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.createOverlaysDiv = function () {
|
||||
var overlaysDiv = document.createElement('div');
|
||||
overlaysDiv.className = "layersDiv";
|
||||
this.dialog.appendChild(overlaysDiv);
|
||||
|
||||
var overlaysLbl = document.createElement('div');
|
||||
overlaysLbl.className = "layersDiv";
|
||||
overlaysLbl.innerHTML = "Overlays";
|
||||
overlaysDiv.appendChild(overlaysLbl);
|
||||
|
||||
this.overlaysDiv = document.createElement('div');
|
||||
overlaysDiv.appendChild(this.overlaysDiv);
|
||||
this.createOverlaysList(this.overlaysDiv);
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.createDialog = function () {
|
||||
this.dialog = document.createElement('div');
|
||||
this.dialog.id = "ogLayerSwitcherDialog";
|
||||
this.dialog.className = "displayNone";
|
||||
this.renderer.div.appendChild(this.dialog);
|
||||
|
||||
this.createBaseLayersDiv();
|
||||
this.createOverlaysDiv();
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.createOverlaysList = function (block) {
|
||||
var i, inp, lbl, that = this,
|
||||
layers = this.renderer.renderNodes.Earth.layers;
|
||||
|
||||
for (i = 0; i < layers.length; i++) {
|
||||
if (!layers[i].isBaseLayer) {
|
||||
inp = document.createElement('input');
|
||||
inp.type = "checkbox";
|
||||
inp.value = i;
|
||||
inp.checked = layers[i].visibility;
|
||||
inp.name = "ogBaseLayerCheckbox";
|
||||
inp.className = "ogLayerSwitcherInput";
|
||||
inp.onclick = function () { that.switchLayerVisibility.call(that, this); };
|
||||
block.appendChild(inp);
|
||||
|
||||
lbl = document.createElement('label');
|
||||
lbl.className = "ogLayerSwitcherLabel";
|
||||
lbl.innerHTML = layers[i].name + "</br>";
|
||||
block.appendChild(lbl);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.createBaseLayersList = function (block) {
|
||||
var i, inp, lbl, that = this,
|
||||
layers = this.renderer.renderNodes.Earth.layers;
|
||||
|
||||
for (i = 0; i < layers.length; i++) {
|
||||
if (layers[i].isBaseLayer) {
|
||||
inp = document.createElement('input');
|
||||
inp.type = "radio";
|
||||
inp.value = i;
|
||||
inp.checked = layers[i].visibility;
|
||||
inp.name = "ogBaseLayerRadiosId" + this._id;
|
||||
inp.className = "ogLayerSwitcherInput";
|
||||
inp.onclick = function () { that.switchLayer.call(that, this); };
|
||||
block.appendChild(inp);
|
||||
|
||||
lbl = document.createElement('label');
|
||||
lbl.className = "ogLayerSwitcherLabel";
|
||||
lbl.innerHTML = layers[i].name + "</br>";
|
||||
block.appendChild(lbl);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.switchLayer = function (obj) {
|
||||
var rn = this.renderer.renderNodes.Earth;
|
||||
rn.setBaseLayer(rn.layers[obj.value]);
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.switchLayerVisibility = function (obj) {
|
||||
var rn = this.renderer.renderNodes.Earth;
|
||||
var lr = rn.layers[obj.value];
|
||||
lr.setVisibility(lr.getVisibility() ? false : true);
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.createSwitcher = function () {
|
||||
var button = document.createElement('div');
|
||||
button.className = 'ogLayerSwitcherButton';
|
||||
button.id = "ogLayerSwitcherButtonMaximize";
|
||||
var that = this;
|
||||
button.onclick = function (e) {
|
||||
if (this.id === "ogLayerSwitcherButtonMaximize") {
|
||||
this.id = "ogLayerSwitcherButtonMinimize";
|
||||
that.dialog.className = "displayBlock";
|
||||
} else {
|
||||
this.id = "ogLayerSwitcherButtonMaximize";
|
||||
that.dialog.className = "displayNone";
|
||||
}
|
||||
};
|
||||
this.renderer.div.appendChild(button);
|
||||
};
|
||||
|
||||
goog.provide('og.control.LayerSwitcher');
|
||||
|
||||
goog.require('og.inheritance');
|
||||
|
||||
og.control.LayerSwitcher = function (options) {
|
||||
og.inheritance.base(this, options);
|
||||
this.dialog = null;
|
||||
this.baseLayersDiv = null;
|
||||
this.overlaysDiv = null;
|
||||
this._id = og.control.LayerSwitcher.numSwitches++;
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.numSwitches = 0;
|
||||
|
||||
og.inheritance.extend(og.control.LayerSwitcher, og.control.Control);
|
||||
|
||||
og.control.LayerSwitcher.prototype.init = function () {
|
||||
this.renderer.renderNodes.Earth.events.on("onlayeradded", this, this.onLayerAdded);
|
||||
this.renderer.renderNodes.Earth.events.on("onlayerremoved", this, this.onLayerRemoved);
|
||||
this.renderer.renderNodes.Earth.events.on("onbaselayerchanged", this, this.onBaseLayerChanged);
|
||||
this.renderer.renderNodes.Earth.events.on("onlayervisibilitychanged", this, this.onLayerVisibilityChanged);
|
||||
this.createSwitcher();
|
||||
this.createDialog();
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.onLayerAdded = function (layer) {
|
||||
console.log("added");
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.onLayerRemoved = function (layer) {
|
||||
console.log("removed");
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.onBaseLayerChanged = function (layer) {
|
||||
console.log("basechanged");
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.onLayerVisibilityChanged = function (layer) {
|
||||
console.log("changed " + layer.id);
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.createBaseLayersDiv = function () {
|
||||
var layersDiv = document.createElement('div');
|
||||
layersDiv.className = "layersDiv";
|
||||
this.dialog.appendChild(layersDiv);
|
||||
|
||||
var baseLayersLbl = document.createElement('div');
|
||||
baseLayersLbl.className = "layersDiv";
|
||||
baseLayersLbl.innerHTML = "Base Layer";
|
||||
layersDiv.appendChild(baseLayersLbl);
|
||||
|
||||
this.baseLayersDiv = document.createElement('div');
|
||||
layersDiv.appendChild(this.baseLayersDiv);
|
||||
this.createBaseLayersList(this.baseLayersDiv);
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.createOverlaysDiv = function () {
|
||||
var overlaysDiv = document.createElement('div');
|
||||
overlaysDiv.className = "layersDiv";
|
||||
this.dialog.appendChild(overlaysDiv);
|
||||
|
||||
var overlaysLbl = document.createElement('div');
|
||||
overlaysLbl.className = "layersDiv";
|
||||
overlaysLbl.innerHTML = "Overlays";
|
||||
overlaysDiv.appendChild(overlaysLbl);
|
||||
|
||||
this.overlaysDiv = document.createElement('div');
|
||||
overlaysDiv.appendChild(this.overlaysDiv);
|
||||
this.createOverlaysList(this.overlaysDiv);
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.createDialog = function () {
|
||||
this.dialog = document.createElement('div');
|
||||
this.dialog.id = "ogLayerSwitcherDialog";
|
||||
this.dialog.className = "displayNone";
|
||||
this.renderer.div.appendChild(this.dialog);
|
||||
|
||||
this.createBaseLayersDiv();
|
||||
this.createOverlaysDiv();
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.createOverlaysList = function (block) {
|
||||
var i, inp, lbl, that = this,
|
||||
layers = this.renderer.renderNodes.Earth.layers;
|
||||
|
||||
for (i = 0; i < layers.length; i++) {
|
||||
if (!layers[i].isBaseLayer) {
|
||||
inp = document.createElement('input');
|
||||
inp.type = "checkbox";
|
||||
inp.value = i;
|
||||
inp.checked = layers[i].visibility;
|
||||
inp.name = "ogBaseLayerCheckbox";
|
||||
inp.className = "ogLayerSwitcherInput";
|
||||
inp.onclick = function () { that.switchLayerVisibility.call(that, this); };
|
||||
block.appendChild(inp);
|
||||
|
||||
lbl = document.createElement('label');
|
||||
lbl.className = "ogLayerSwitcherLabel";
|
||||
lbl.innerHTML = layers[i].name + "</br>";
|
||||
block.appendChild(lbl);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.createBaseLayersList = function (block) {
|
||||
var i, inp, lbl, that = this,
|
||||
layers = this.renderer.renderNodes.Earth.layers;
|
||||
|
||||
for (i = 0; i < layers.length; i++) {
|
||||
if (layers[i].isBaseLayer) {
|
||||
inp = document.createElement('input');
|
||||
inp.type = "radio";
|
||||
inp.value = i;
|
||||
inp.checked = layers[i].visibility;
|
||||
inp.name = "ogBaseLayerRadiosId" + this._id;
|
||||
inp.className = "ogLayerSwitcherInput";
|
||||
inp.onclick = function () { that.switchLayer.call(that, this); };
|
||||
block.appendChild(inp);
|
||||
|
||||
lbl = document.createElement('label');
|
||||
lbl.className = "ogLayerSwitcherLabel";
|
||||
lbl.innerHTML = layers[i].name + "</br>";
|
||||
block.appendChild(lbl);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.switchLayer = function (obj) {
|
||||
var rn = this.renderer.renderNodes.Earth;
|
||||
rn.setBaseLayer(rn.layers[obj.value]);
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.switchLayerVisibility = function (obj) {
|
||||
var rn = this.renderer.renderNodes.Earth;
|
||||
var lr = rn.layers[obj.value];
|
||||
lr.setVisibility(lr.getVisibility() ? false : true);
|
||||
};
|
||||
|
||||
og.control.LayerSwitcher.prototype.createSwitcher = function () {
|
||||
var button = document.createElement('div');
|
||||
button.className = 'ogLayerSwitcherButton';
|
||||
button.id = "ogLayerSwitcherButtonMaximize";
|
||||
var that = this;
|
||||
button.onclick = function (e) {
|
||||
if (this.id === "ogLayerSwitcherButtonMaximize") {
|
||||
this.id = "ogLayerSwitcherButtonMinimize";
|
||||
that.dialog.className = "displayBlock";
|
||||
} else {
|
||||
this.id = "ogLayerSwitcherButtonMaximize";
|
||||
that.dialog.className = "displayNone";
|
||||
}
|
||||
};
|
||||
this.renderer.div.appendChild(button);
|
||||
};
|
||||
|
||||
|
||||
@ -1,53 +1,53 @@
|
||||
goog.provide('og.control.LoadingSpinner');
|
||||
|
||||
goog.require('og.inheritance');
|
||||
goog.require('og.control.Control');
|
||||
|
||||
og.control.LoadingSpinner = function (options) {
|
||||
og.inheritance.base(this, options);
|
||||
this.spinnerElement = null;
|
||||
};
|
||||
|
||||
og.inheritance.extend(og.control.LoadingSpinner, og.control.Control);
|
||||
|
||||
og.control.LoadingSpinner.prototype.init = function () {
|
||||
this.spinnerElement = document.createElement('div');
|
||||
this.spinnerElement.id = 'circleG';
|
||||
|
||||
var a = document.createElement('div');
|
||||
var b = document.createElement('div');
|
||||
var c = document.createElement('div');
|
||||
|
||||
this.spinnerElement.appendChild(a);
|
||||
this.spinnerElement.appendChild(b);
|
||||
this.spinnerElement.appendChild(c);
|
||||
|
||||
a.id = "circleG_1"; a.className = "circleG";
|
||||
b.id = "circleG_2"; b.className = "circleG";
|
||||
c.id = "circleG_3"; c.className = "circleG";
|
||||
|
||||
this.spinnerElement.className = "displayBlock";
|
||||
document.body.appendChild(this.spinnerElement);
|
||||
this.renderer.events.on("ondraw", this, this.draw);
|
||||
};
|
||||
|
||||
og.control.LoadingSpinner.prototype.draw = function () {
|
||||
var spinning = false,
|
||||
p = this.renderer.renderNodes.Earth,
|
||||
l = p.layers,
|
||||
i = 0;
|
||||
|
||||
while(i < l.length) {
|
||||
if( l[i++].counter != 0 ) {
|
||||
spinning = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(p.terrainProvider.counter != 0 || spinning) {
|
||||
this.spinnerElement.className = "displayBlock";
|
||||
} else {
|
||||
this.spinnerElement.className = "displayNone";
|
||||
}
|
||||
};
|
||||
|
||||
goog.provide('og.control.LoadingSpinner');
|
||||
|
||||
goog.require('og.inheritance');
|
||||
goog.require('og.control.Control');
|
||||
|
||||
og.control.LoadingSpinner = function (options) {
|
||||
og.inheritance.base(this, options);
|
||||
this.spinnerElement = null;
|
||||
};
|
||||
|
||||
og.inheritance.extend(og.control.LoadingSpinner, og.control.Control);
|
||||
|
||||
og.control.LoadingSpinner.prototype.init = function () {
|
||||
this.spinnerElement = document.createElement('div');
|
||||
this.spinnerElement.id = 'circleG';
|
||||
|
||||
var a = document.createElement('div');
|
||||
var b = document.createElement('div');
|
||||
var c = document.createElement('div');
|
||||
|
||||
this.spinnerElement.appendChild(a);
|
||||
this.spinnerElement.appendChild(b);
|
||||
this.spinnerElement.appendChild(c);
|
||||
|
||||
a.id = "circleG_1"; a.className = "circleG";
|
||||
b.id = "circleG_2"; b.className = "circleG";
|
||||
c.id = "circleG_3"; c.className = "circleG";
|
||||
|
||||
this.spinnerElement.className = "displayBlock";
|
||||
document.body.appendChild(this.spinnerElement);
|
||||
this.renderer.events.on("ondraw", this, this.draw);
|
||||
};
|
||||
|
||||
og.control.LoadingSpinner.prototype.draw = function () {
|
||||
var spinning = false,
|
||||
p = this.renderer.renderNodes.Earth,
|
||||
l = p.layers,
|
||||
i = 0;
|
||||
|
||||
while(i < l.length) {
|
||||
if( l[i++].counter != 0 ) {
|
||||
spinning = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(p.terrainProvider.counter != 0 || spinning) {
|
||||
this.spinnerElement.className = "displayBlock";
|
||||
} else {
|
||||
this.spinnerElement.className = "displayNone";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -1,23 +1,23 @@
|
||||
goog.provide('og.control.ToggleWireframe');
|
||||
|
||||
goog.require('og.inheritance');
|
||||
goog.require('og.webgl');
|
||||
goog.require('og.input');
|
||||
|
||||
og.control.ToggleWireframe = function (options) {
|
||||
og.inheritance.base(this, options);
|
||||
};
|
||||
|
||||
og.inheritance.extend(og.control.ToggleWireframe, og.control.Control);
|
||||
|
||||
og.control.ToggleWireframe.prototype.init = function () {
|
||||
this.renderer.events.on("oncharkeypressed", this, this.toogleWireframe, og.input.KEY_X);
|
||||
};
|
||||
|
||||
og.control.ToggleWireframe.prototype.toogleWireframe = function (e) {
|
||||
if (this.renderer.renderNodes.Earth.drawMode === this.renderer.handler.gl.LINE_STRIP) {
|
||||
this.renderer.renderNodes.Earth.setDrawMode(this.renderer.handler.gl.TRIANGLE_STRIP);
|
||||
} else {
|
||||
this.renderer.renderNodes.Earth.setDrawMode(this.renderer.handler.gl.LINE_STRIP);
|
||||
}
|
||||
};
|
||||
goog.provide('og.control.ToggleWireframe');
|
||||
|
||||
goog.require('og.inheritance');
|
||||
goog.require('og.webgl');
|
||||
goog.require('og.input');
|
||||
|
||||
og.control.ToggleWireframe = function (options) {
|
||||
og.inheritance.base(this, options);
|
||||
};
|
||||
|
||||
og.inheritance.extend(og.control.ToggleWireframe, og.control.Control);
|
||||
|
||||
og.control.ToggleWireframe.prototype.init = function () {
|
||||
this.renderer.events.on("oncharkeypressed", this, this.toogleWireframe, og.input.KEY_X);
|
||||
};
|
||||
|
||||
og.control.ToggleWireframe.prototype.toogleWireframe = function (e) {
|
||||
if (this.renderer.renderNodes.Earth.drawMode === this.renderer.handler.gl.LINE_STRIP) {
|
||||
this.renderer.renderNodes.Earth.setDrawMode(this.renderer.handler.gl.TRIANGLE_STRIP);
|
||||
} else {
|
||||
this.renderer.renderNodes.Earth.setDrawMode(this.renderer.handler.gl.LINE_STRIP);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,80 +1,80 @@
|
||||
goog.provide('og.Ellipsoid');
|
||||
|
||||
goog.require('og.math');
|
||||
goog.require('og.math.Vector3');
|
||||
goog.require('og.LonLat');
|
||||
|
||||
og.Ellipsoid = function (equatorialSize, polarSize) {
|
||||
var a = this._a = equatorialSize;
|
||||
var b = this._b = polarSize;
|
||||
this.flattening = a / b;
|
||||
this.a2 = a * a;
|
||||
this.b2 = b * b;
|
||||
this._e = Math.sqrt(this.a2 - this.b2) / a;
|
||||
this._e2 = Math.pow(this._e, 2);
|
||||
this._k = Math.sqrt(this.a2 - this.b2) / b;
|
||||
this._k2 = Math.pow(this._k, 2);
|
||||
this._radii = new og.math.Vector3(equatorialSize, polarSize, equatorialSize);
|
||||
this._radii2 = new og.math.Vector3(equatorialSize * equatorialSize, polarSize * polarSize, equatorialSize * equatorialSize);
|
||||
this._invRadii = new og.math.Vector3(1 / equatorialSize, 1 / polarSize, 1 / equatorialSize);
|
||||
this._invRadii2 = new og.math.Vector3(1 / (equatorialSize * equatorialSize), 1 / (polarSize * polarSize), 1 / (equatorialSize * equatorialSize));
|
||||
};
|
||||
|
||||
og.Ellipsoid.prototype.N = function (phi) {
|
||||
var ss = Math.pow(Math.sin(phi), 2);
|
||||
var ss2 = this._e2 * ss;
|
||||
var ss3 = Math.sqrt(1 - ss2);
|
||||
return this._a / ss3;
|
||||
};
|
||||
|
||||
og.Ellipsoid.prototype.LonLat2ECEF = function (lonlat) {
|
||||
var latrad = og.math.DEG2RAD(lonlat.lat),
|
||||
lonrad = og.math.DEG2RAD(lonlat.lon);
|
||||
var x = (this.N(latrad) + lonlat.height) * Math.cos(latrad) * Math.cos(lonrad);
|
||||
var y = (this.N(latrad) + lonlat.height) * Math.cos(latrad) * Math.sin(lonrad);
|
||||
var z = (this.N(latrad) * (1 - this._e2) + lonlat.height) * Math.sin(latrad);
|
||||
return new og.math.Vector3(y, z, x);
|
||||
};
|
||||
|
||||
og.Ellipsoid.prototype.ECEF2LonLat = function (cartesian) {
|
||||
var x = cartesian.z,
|
||||
y = cartesian.x,
|
||||
z = cartesian.y;
|
||||
var ecc2 = this._e2;
|
||||
var ecc22 = this._k2;
|
||||
var r2 = x * x + y * y;
|
||||
var r = Math.sqrt(r2);
|
||||
var e2 = this.a2 - this.b2;
|
||||
var z2 = z * z;
|
||||
var f = 54.0 * this.b2 * z2;
|
||||
var g = r2 + (1 - ecc2) * z2 + ecc2 * e2;
|
||||
var g2 = g * g;
|
||||
var c = ecc2 * ecc2 * f * r2 / (g2 * g);
|
||||
var s = Math.pow((1 + c + Math.sqrt(c * (c + 2))), 1 / 3);
|
||||
var p = f / (3 * Math.pow((s + 1 / s + 1), 2) * g2);
|
||||
var q = Math.sqrt(1 + 2 * ecc2 * ecc2 * p);
|
||||
var r0 = -(p * ecc2 * r) / 1 + q + Math.sqrt(0.5 * this.a2 * (1 + 1 / q) - p * (1 - ecc2) * z2 / (q * (1 + q)) - 0.5 * p * r2);
|
||||
var u = Math.sqrt(Math.pow((r - ecc2 * r0), 2) + z2);
|
||||
var v = Math.sqrt(Math.pow((r - ecc2 * r0), 2) + (1 - ecc2) * z2);
|
||||
var z0 = this.b2 * z / (this._a * v);
|
||||
var h = u * (1 - this.b2 / (this._a * v));
|
||||
var phi = Math.atan((z + ecc22 * z0) / r);
|
||||
var lambda = Math.atan2(y, x);
|
||||
var lat = phi / Math.PI * 180;
|
||||
var lon = lambda / Math.PI * 180;
|
||||
return new og.LonLat(lon, lat, h);
|
||||
};
|
||||
|
||||
og.Ellipsoid.prototype.getSurfaceNormal = function (x, y, z) {
|
||||
var r2 = this._invRadii2;
|
||||
var nx = x * r2.x, ny = y * r2.y, nz = z * r2.z;
|
||||
var l = 1 / Math.sqrt(nx * nx + ny * ny + nz * nz);
|
||||
return new og.math.Vector3(nx * l, ny * l, nz * l);
|
||||
};
|
||||
|
||||
og.Ellipsoid.prototype.getCartesianHeight = function (x, y, z, h) {
|
||||
var r2 = this._invRadii2;
|
||||
var nx = x * r2.x, ny = y * r2.y, nz = z * r2.z;
|
||||
var l = 1 / Math.sqrt(nx * nx + ny * ny + nz * nz);
|
||||
return new og.math.Vector3(x + h * nx * l, y + h * ny * l, z + h * nz * l);
|
||||
};
|
||||
goog.provide('og.Ellipsoid');
|
||||
|
||||
goog.require('og.math');
|
||||
goog.require('og.math.Vector3');
|
||||
goog.require('og.LonLat');
|
||||
|
||||
og.Ellipsoid = function (equatorialSize, polarSize) {
|
||||
var a = this._a = equatorialSize;
|
||||
var b = this._b = polarSize;
|
||||
this.flattening = a / b;
|
||||
this.a2 = a * a;
|
||||
this.b2 = b * b;
|
||||
this._e = Math.sqrt(this.a2 - this.b2) / a;
|
||||
this._e2 = Math.pow(this._e, 2);
|
||||
this._k = Math.sqrt(this.a2 - this.b2) / b;
|
||||
this._k2 = Math.pow(this._k, 2);
|
||||
this._radii = new og.math.Vector3(equatorialSize, polarSize, equatorialSize);
|
||||
this._radii2 = new og.math.Vector3(equatorialSize * equatorialSize, polarSize * polarSize, equatorialSize * equatorialSize);
|
||||
this._invRadii = new og.math.Vector3(1 / equatorialSize, 1 / polarSize, 1 / equatorialSize);
|
||||
this._invRadii2 = new og.math.Vector3(1 / (equatorialSize * equatorialSize), 1 / (polarSize * polarSize), 1 / (equatorialSize * equatorialSize));
|
||||
};
|
||||
|
||||
og.Ellipsoid.prototype.N = function (phi) {
|
||||
var ss = Math.pow(Math.sin(phi), 2);
|
||||
var ss2 = this._e2 * ss;
|
||||
var ss3 = Math.sqrt(1 - ss2);
|
||||
return this._a / ss3;
|
||||
};
|
||||
|
||||
og.Ellipsoid.prototype.LonLat2ECEF = function (lonlat) {
|
||||
var latrad = og.math.DEG2RAD(lonlat.lat),
|
||||
lonrad = og.math.DEG2RAD(lonlat.lon);
|
||||
var x = (this.N(latrad) + lonlat.height) * Math.cos(latrad) * Math.cos(lonrad);
|
||||
var y = (this.N(latrad) + lonlat.height) * Math.cos(latrad) * Math.sin(lonrad);
|
||||
var z = (this.N(latrad) * (1 - this._e2) + lonlat.height) * Math.sin(latrad);
|
||||
return new og.math.Vector3(y, z, x);
|
||||
};
|
||||
|
||||
og.Ellipsoid.prototype.ECEF2LonLat = function (cartesian) {
|
||||
var x = cartesian.z,
|
||||
y = cartesian.x,
|
||||
z = cartesian.y;
|
||||
var ecc2 = this._e2;
|
||||
var ecc22 = this._k2;
|
||||
var r2 = x * x + y * y;
|
||||
var r = Math.sqrt(r2);
|
||||
var e2 = this.a2 - this.b2;
|
||||
var z2 = z * z;
|
||||
var f = 54.0 * this.b2 * z2;
|
||||
var g = r2 + (1 - ecc2) * z2 + ecc2 * e2;
|
||||
var g2 = g * g;
|
||||
var c = ecc2 * ecc2 * f * r2 / (g2 * g);
|
||||
var s = Math.pow((1 + c + Math.sqrt(c * (c + 2))), 1 / 3);
|
||||
var p = f / (3 * Math.pow((s + 1 / s + 1), 2) * g2);
|
||||
var q = Math.sqrt(1 + 2 * ecc2 * ecc2 * p);
|
||||
var r0 = -(p * ecc2 * r) / 1 + q + Math.sqrt(0.5 * this.a2 * (1 + 1 / q) - p * (1 - ecc2) * z2 / (q * (1 + q)) - 0.5 * p * r2);
|
||||
var u = Math.sqrt(Math.pow((r - ecc2 * r0), 2) + z2);
|
||||
var v = Math.sqrt(Math.pow((r - ecc2 * r0), 2) + (1 - ecc2) * z2);
|
||||
var z0 = this.b2 * z / (this._a * v);
|
||||
var h = u * (1 - this.b2 / (this._a * v));
|
||||
var phi = Math.atan((z + ecc22 * z0) / r);
|
||||
var lambda = Math.atan2(y, x);
|
||||
var lat = phi / Math.PI * 180;
|
||||
var lon = lambda / Math.PI * 180;
|
||||
return new og.LonLat(lon, lat, h);
|
||||
};
|
||||
|
||||
og.Ellipsoid.prototype.getSurfaceNormal = function (x, y, z) {
|
||||
var r2 = this._invRadii2;
|
||||
var nx = x * r2.x, ny = y * r2.y, nz = z * r2.z;
|
||||
var l = 1 / Math.sqrt(nx * nx + ny * ny + nz * nz);
|
||||
return new og.math.Vector3(nx * l, ny * l, nz * l);
|
||||
};
|
||||
|
||||
og.Ellipsoid.prototype.getCartesianHeight = function (x, y, z, h) {
|
||||
var r2 = this._invRadii2;
|
||||
var nx = x * r2.x, ny = y * r2.y, nz = z * r2.z;
|
||||
var l = 1 / Math.sqrt(nx * nx + ny * ny + nz * nz);
|
||||
return new og.math.Vector3(x + h * nx * l, y + h * ny * l, z + h * nz * l);
|
||||
};
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
goog.provide('og.ellipsoid.wgs84');
|
||||
|
||||
goog.require('og.Ellipsoid');
|
||||
|
||||
og.ellipsoid.wgs84 = new og.Ellipsoid(6378137.000, 6356752.3142);
|
||||
goog.provide('og.ellipsoid.wgs84');
|
||||
|
||||
goog.require('og.Ellipsoid');
|
||||
|
||||
og.ellipsoid.wgs84 = new og.Ellipsoid(6378137.000, 6356752.3142);
|
||||
|
||||
@ -1,24 +1,24 @@
|
||||
goog.provide('og.Events');
|
||||
|
||||
og.Events = function () { };
|
||||
|
||||
og.Events.prototype.registerNames = function (eventNames) {
|
||||
for (var i = 0; i < eventNames.length; i++) {
|
||||
this[eventNames[i]] = { "active": true, "handlers": [] };
|
||||
}
|
||||
};
|
||||
|
||||
og.Events.prototype.on = function (name, sender, callback) {
|
||||
this[name].handlers.push({ sender: sender, callback: callback });
|
||||
};
|
||||
|
||||
og.Events.prototype.dispatch = function (event, obj) {
|
||||
if (event && event.active) {
|
||||
var h = event.handlers;
|
||||
var i = h.length;
|
||||
while (i--) {
|
||||
var e = h[i];
|
||||
e.callback.call(e.sender, obj);
|
||||
}
|
||||
}
|
||||
goog.provide('og.Events');
|
||||
|
||||
og.Events = function () { };
|
||||
|
||||
og.Events.prototype.registerNames = function (eventNames) {
|
||||
for (var i = 0; i < eventNames.length; i++) {
|
||||
this[eventNames[i]] = { "active": true, "handlers": [] };
|
||||
}
|
||||
};
|
||||
|
||||
og.Events.prototype.on = function (name, sender, callback) {
|
||||
this[name].handlers.push({ sender: sender, callback: callback });
|
||||
};
|
||||
|
||||
og.Events.prototype.dispatch = function (event, obj) {
|
||||
if (event && event.active) {
|
||||
var h = event.handlers;
|
||||
var i = h.length;
|
||||
while (i--) {
|
||||
var e = h[i];
|
||||
e.callback.call(e.sender, obj);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -1,99 +1,99 @@
|
||||
goog.provide('og.Frustum');
|
||||
|
||||
og.Frustum = function () {
|
||||
this._f = new Array(6);
|
||||
for (var i = 0; i < 6; i++)
|
||||
this._f[i] = new Array(4);
|
||||
};
|
||||
|
||||
og.Frustum.prototype.setFrustum = function (clip) {
|
||||
/* Right */
|
||||
this._f[0][0] = clip[3] - clip[0];
|
||||
this._f[0][1] = clip[7] - clip[4];
|
||||
this._f[0][2] = clip[11] - clip[8];
|
||||
this._f[0][3] = clip[15] - clip[12];
|
||||
this.planeNormalize(this._f[0]);
|
||||
|
||||
/* Left */
|
||||
this._f[1][0] = clip[3] + clip[0];
|
||||
this._f[1][1] = clip[7] + clip[4];
|
||||
this._f[1][2] = clip[11] + clip[8];
|
||||
this._f[1][3] = clip[15] + clip[12];
|
||||
this.planeNormalize(this._f[1]);
|
||||
|
||||
/* Bottom */
|
||||
this._f[2][0] = clip[3] + clip[1];
|
||||
this._f[2][1] = clip[7] + clip[5];
|
||||
this._f[2][2] = clip[11] + clip[9];
|
||||
this._f[2][3] = clip[15] + clip[13];
|
||||
this.planeNormalize(this._f[2]);
|
||||
|
||||
/* Top */
|
||||
this._f[3][0] = clip[3] - clip[1];
|
||||
this._f[3][1] = clip[7] - clip[5];
|
||||
this._f[3][2] = clip[11] - clip[9];
|
||||
this._f[3][3] = clip[15] - clip[13];
|
||||
this.planeNormalize(this._f[3]);
|
||||
|
||||
/* Backward */
|
||||
this._f[4][0] = clip[3] - clip[2];
|
||||
this._f[4][1] = clip[7] - clip[6];
|
||||
this._f[4][2] = clip[11] - clip[10];
|
||||
this._f[4][3] = clip[15] - clip[14];
|
||||
this.planeNormalize(this._f[4]);
|
||||
|
||||
/* Forward */
|
||||
this._f[5][0] = clip[3] + clip[2];
|
||||
this._f[5][1] = clip[7] + clip[6];
|
||||
this._f[5][2] = clip[11] + clip[10];
|
||||
this._f[5][3] = clip[15] + clip[14];
|
||||
this.planeNormalize(this._f[5]);
|
||||
};
|
||||
|
||||
og.Frustum.prototype.planeNormalize = function (plane) {
|
||||
var t = Math.sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
plane[0] /= t;
|
||||
plane[1] /= t;
|
||||
plane[2] /= t;
|
||||
plane[3] /= t;
|
||||
};
|
||||
|
||||
og.Frustum.prototype.containsPoint = function (point) {
|
||||
var d;
|
||||
for (var p = 0; p < 6; p++) {
|
||||
d = point.dotArr(this._f[p]) + this._f[p][3];
|
||||
if ( d <= 0 )
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
og.Frustum.prototype.containsSphere = function (sphere) {
|
||||
var d;
|
||||
for( var p = 0; p < 6; p++ ) {
|
||||
d = sphere.center.dotArr(this._f[p]) + this._f[p][3];
|
||||
if( d <= -sphere.radius )
|
||||
return -1;
|
||||
}
|
||||
return d + sphere.radius;
|
||||
};
|
||||
|
||||
og.Frustum.prototype.containsBox = function (box) {
|
||||
var result = true, cout, cin;
|
||||
|
||||
for(var i=0; i < 6; i++) {
|
||||
cout=0; cin=0;
|
||||
for (var k = 0; k < 8 && (cin==0 || cout==0); k++) {
|
||||
var d = box.vertices[k].dotArr(this._f[i]) + this._f[i][3];
|
||||
if (d < 0)
|
||||
cout++;
|
||||
else
|
||||
cin++;
|
||||
}
|
||||
if (cin==0)
|
||||
return false;
|
||||
else if (cout>0)
|
||||
result = true;
|
||||
}
|
||||
return(result);
|
||||
};
|
||||
goog.provide('og.Frustum');
|
||||
|
||||
og.Frustum = function () {
|
||||
this._f = new Array(6);
|
||||
for (var i = 0; i < 6; i++)
|
||||
this._f[i] = new Array(4);
|
||||
};
|
||||
|
||||
og.Frustum.prototype.setFrustum = function (clip) {
|
||||
/* Right */
|
||||
this._f[0][0] = clip[3] - clip[0];
|
||||
this._f[0][1] = clip[7] - clip[4];
|
||||
this._f[0][2] = clip[11] - clip[8];
|
||||
this._f[0][3] = clip[15] - clip[12];
|
||||
this.planeNormalize(this._f[0]);
|
||||
|
||||
/* Left */
|
||||
this._f[1][0] = clip[3] + clip[0];
|
||||
this._f[1][1] = clip[7] + clip[4];
|
||||
this._f[1][2] = clip[11] + clip[8];
|
||||
this._f[1][3] = clip[15] + clip[12];
|
||||
this.planeNormalize(this._f[1]);
|
||||
|
||||
/* Bottom */
|
||||
this._f[2][0] = clip[3] + clip[1];
|
||||
this._f[2][1] = clip[7] + clip[5];
|
||||
this._f[2][2] = clip[11] + clip[9];
|
||||
this._f[2][3] = clip[15] + clip[13];
|
||||
this.planeNormalize(this._f[2]);
|
||||
|
||||
/* Top */
|
||||
this._f[3][0] = clip[3] - clip[1];
|
||||
this._f[3][1] = clip[7] - clip[5];
|
||||
this._f[3][2] = clip[11] - clip[9];
|
||||
this._f[3][3] = clip[15] - clip[13];
|
||||
this.planeNormalize(this._f[3]);
|
||||
|
||||
/* Backward */
|
||||
this._f[4][0] = clip[3] - clip[2];
|
||||
this._f[4][1] = clip[7] - clip[6];
|
||||
this._f[4][2] = clip[11] - clip[10];
|
||||
this._f[4][3] = clip[15] - clip[14];
|
||||
this.planeNormalize(this._f[4]);
|
||||
|
||||
/* Forward */
|
||||
this._f[5][0] = clip[3] + clip[2];
|
||||
this._f[5][1] = clip[7] + clip[6];
|
||||
this._f[5][2] = clip[11] + clip[10];
|
||||
this._f[5][3] = clip[15] + clip[14];
|
||||
this.planeNormalize(this._f[5]);
|
||||
};
|
||||
|
||||
og.Frustum.prototype.planeNormalize = function (plane) {
|
||||
var t = Math.sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
plane[0] /= t;
|
||||
plane[1] /= t;
|
||||
plane[2] /= t;
|
||||
plane[3] /= t;
|
||||
};
|
||||
|
||||
og.Frustum.prototype.containsPoint = function (point) {
|
||||
var d;
|
||||
for (var p = 0; p < 6; p++) {
|
||||
d = point.dotArr(this._f[p]) + this._f[p][3];
|
||||
if ( d <= 0 )
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
og.Frustum.prototype.containsSphere = function (sphere) {
|
||||
var d;
|
||||
for( var p = 0; p < 6; p++ ) {
|
||||
d = sphere.center.dotArr(this._f[p]) + this._f[p][3];
|
||||
if( d <= -sphere.radius )
|
||||
return -1;
|
||||
}
|
||||
return d + sphere.radius;
|
||||
};
|
||||
|
||||
og.Frustum.prototype.containsBox = function (box) {
|
||||
var result = true, cout, cin;
|
||||
|
||||
for(var i=0; i < 6; i++) {
|
||||
cout=0; cin=0;
|
||||
for (var k = 0; k < 8 && (cin==0 || cout==0); k++) {
|
||||
var d = box.vertices[k].dotArr(this._f[i]) + this._f[i][3];
|
||||
if (d < 0)
|
||||
cout++;
|
||||
else
|
||||
cin++;
|
||||
}
|
||||
if (cin==0)
|
||||
return false;
|
||||
else if (cout>0)
|
||||
result = true;
|
||||
}
|
||||
return(result);
|
||||
};
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
goog.provide('og.inheritance');
|
||||
|
||||
og.inheritance.extend = function (Child, Parent) {
|
||||
var F = function () { };
|
||||
F.prototype = Parent.prototype;
|
||||
Child.prototype = new F();
|
||||
Child.prototype.constructor = Child;
|
||||
Child.superclass = Parent.prototype;
|
||||
Child.superclass.constructor = Parent;
|
||||
};
|
||||
|
||||
og.inheritance.base = function (me) {
|
||||
var caller = arguments.callee.caller;
|
||||
caller.superclass.constructor.apply(me, Array.prototype.slice.call(arguments, 1));
|
||||
goog.provide('og.inheritance');
|
||||
|
||||
og.inheritance.extend = function (Child, Parent) {
|
||||
var F = function () { };
|
||||
F.prototype = Parent.prototype;
|
||||
Child.prototype = new F();
|
||||
Child.prototype.constructor = Child;
|
||||
Child.superclass = Parent.prototype;
|
||||
Child.superclass.constructor = Parent;
|
||||
};
|
||||
|
||||
og.inheritance.base = function (me) {
|
||||
var caller = arguments.callee.caller;
|
||||
caller.superclass.constructor.apply(me, Array.prototype.slice.call(arguments, 1));
|
||||
};
|
||||
@ -1,24 +1,24 @@
|
||||
goog.provide('og.input');
|
||||
|
||||
og.input.KEY_SHIFT = 16;
|
||||
og.input.KEY_SPACE = 32;
|
||||
og.input.KEY_LEFT = 37;
|
||||
og.input.KEY_UP = 38;
|
||||
og.input.KEY_RIGHT = 39;
|
||||
og.input.KEY_DOWN = 40;
|
||||
og.input.KEY_A = 65;
|
||||
og.input.KEY_C = 67;
|
||||
og.input.KEY_D = 68;
|
||||
og.input.KEY_E = 69;
|
||||
og.input.KEY_H = 72;
|
||||
og.input.KEY_L = 76;
|
||||
og.input.KEY_Q = 81;
|
||||
og.input.KEY_S = 83;
|
||||
og.input.KEY_V = 86;
|
||||
og.input.KEY_W = 87;
|
||||
og.input.KEY_X = 88;
|
||||
og.input.KEY_F1 = 112;
|
||||
|
||||
og.input.MB_LEFT = 0;
|
||||
og.input.MB_RIGHT = 2;
|
||||
goog.provide('og.input');
|
||||
|
||||
og.input.KEY_SHIFT = 16;
|
||||
og.input.KEY_SPACE = 32;
|
||||
og.input.KEY_LEFT = 37;
|
||||
og.input.KEY_UP = 38;
|
||||
og.input.KEY_RIGHT = 39;
|
||||
og.input.KEY_DOWN = 40;
|
||||
og.input.KEY_A = 65;
|
||||
og.input.KEY_C = 67;
|
||||
og.input.KEY_D = 68;
|
||||
og.input.KEY_E = 69;
|
||||
og.input.KEY_H = 72;
|
||||
og.input.KEY_L = 76;
|
||||
og.input.KEY_Q = 81;
|
||||
og.input.KEY_S = 83;
|
||||
og.input.KEY_V = 86;
|
||||
og.input.KEY_W = 87;
|
||||
og.input.KEY_X = 88;
|
||||
og.input.KEY_F1 = 112;
|
||||
|
||||
og.input.MB_LEFT = 0;
|
||||
og.input.MB_RIGHT = 2;
|
||||
og.input.MB_MIDDLE = 1;
|
||||
@ -1,26 +1,26 @@
|
||||
goog.provide('og.layer.CanvasTiles');
|
||||
|
||||
goog.require('og.inheritance');
|
||||
goog.require('og.layer.Layer');
|
||||
goog.require('og.ImageCanvas');
|
||||
|
||||
og.layer.CanvasTiles = function (name, options) {
|
||||
og.inheritance.base(this, name, options);
|
||||
|
||||
this.width = options && options.width ? options.width : 256;
|
||||
this.height = options && options.height ? options.height : 256;
|
||||
};
|
||||
|
||||
og.inheritance.extend(og.layer.CanvasTiles, og.layer.Layer);
|
||||
|
||||
|
||||
og.layer.CanvasTiles.prototype.handleSegmentTile = function (material) {
|
||||
if (this.drawTile) {
|
||||
this.drawTile(material, function (canvas) {
|
||||
material.imageReady = false;
|
||||
material.applyTexture(canvas);
|
||||
});
|
||||
} else {
|
||||
material.textureNotExists();
|
||||
}
|
||||
goog.provide('og.layer.CanvasTiles');
|
||||
|
||||
goog.require('og.inheritance');
|
||||
goog.require('og.layer.Layer');
|
||||
goog.require('og.ImageCanvas');
|
||||
|
||||
og.layer.CanvasTiles = function (name, options) {
|
||||
og.inheritance.base(this, name, options);
|
||||
|
||||
this.width = options && options.width ? options.width : 256;
|
||||
this.height = options && options.height ? options.height : 256;
|
||||
};
|
||||
|
||||
og.inheritance.extend(og.layer.CanvasTiles, og.layer.Layer);
|
||||
|
||||
|
||||
og.layer.CanvasTiles.prototype.handleSegmentTile = function (material) {
|
||||
if (this.drawTile) {
|
||||
this.drawTile(material, function (canvas) {
|
||||
material.imageReady = false;
|
||||
material.applyTexture(canvas);
|
||||
});
|
||||
} else {
|
||||
material.textureNotExists();
|
||||
}
|
||||
};
|
||||
@ -1,29 +1,29 @@
|
||||
goog.provide('og.layer.WMS');
|
||||
|
||||
goog.require('og.inheritance');
|
||||
goog.require('og.layer.XYZ');
|
||||
|
||||
og.layer.WMS = function (name, options) {
|
||||
og.inheritance.base(this, name, options);
|
||||
this.layers = options.layers;
|
||||
}
|
||||
|
||||
og.inheritance.extend(og.layer.WMS, og.layer.XYZ);
|
||||
|
||||
og.layer.WMS.prototype.handleSegmentTile = function (material) {
|
||||
if (og.layer.requestsCounter >= og.layer.MAX_REQUESTS && this.counter) {
|
||||
this.pendingsQueue.push(material);
|
||||
} else {
|
||||
this.loadSegmentTileImage(material);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
og.layer.WMS.prototype.GetHTTPRequestString = function (segment) {
|
||||
return this.url + "wms?" + "LAYERS=" + this.layers +
|
||||
"&FORMAT=image/jpeg&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap" +
|
||||
"&SRS=" + segment._projection.code +
|
||||
"&BBOX=" + segment.extent.getWest() + "," + segment.extent.getSouth() + "," + segment.extent.getEast() + "," + segment.extent.getNorth() +
|
||||
"&WIDTH=" + (this.width ? this.width : 256) +
|
||||
"&HEIGHT=" + (this.height ? this.height : 256);
|
||||
goog.provide('og.layer.WMS');
|
||||
|
||||
goog.require('og.inheritance');
|
||||
goog.require('og.layer.XYZ');
|
||||
|
||||
og.layer.WMS = function (name, options) {
|
||||
og.inheritance.base(this, name, options);
|
||||
this.layers = options.layers;
|
||||
}
|
||||
|
||||
og.inheritance.extend(og.layer.WMS, og.layer.XYZ);
|
||||
|
||||
og.layer.WMS.prototype.handleSegmentTile = function (material) {
|
||||
if (og.layer.requestsCounter >= og.layer.MAX_REQUESTS && this.counter) {
|
||||
this.pendingsQueue.push(material);
|
||||
} else {
|
||||
this.loadSegmentTileImage(material);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
og.layer.WMS.prototype.GetHTTPRequestString = function (segment) {
|
||||
return this.url + "wms?" + "LAYERS=" + this.layers +
|
||||
"&FORMAT=image/jpeg&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap" +
|
||||
"&SRS=" + segment._projection.code +
|
||||
"&BBOX=" + segment.extent.getWest() + "," + segment.extent.getSouth() + "," + segment.extent.getEast() + "," + segment.extent.getNorth() +
|
||||
"&WIDTH=" + (this.width ? this.width : 256) +
|
||||
"&HEIGHT=" + (this.height ? this.height : 256);
|
||||
};
|
||||
@ -1,166 +1,166 @@
|
||||
goog.provide('og.light.PointLight');
|
||||
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
og.light.PointLight = function (name, position, ambient, diffuse, specular, shininess) {
|
||||
this._name = name || ("p" + og.light.PointLight._counter++);
|
||||
this._renderNode = null;
|
||||
|
||||
this._position = position || new og.math.Vector3();
|
||||
|
||||
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);
|
||||
|
||||
this._shininess = shininess || 3.3;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
og.light.PointLight._counter = 0;
|
||||
|
||||
og.light.PointLight.prototype.clone = function () {
|
||||
|
||||
};
|
||||
|
||||
og.light.PointLight.prototype.setActive = function (active) {
|
||||
if (active && !this._active) {
|
||||
var rn = this._renderNode;
|
||||
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();
|
||||
this._tempDiffuse = this._diffuse.clone();
|
||||
this._tempSpecular = this._specular.clone();
|
||||
this._tempShininess = this._shininess;
|
||||
this.setBlack();
|
||||
this._active = false;
|
||||
}
|
||||
return this.active;
|
||||
};
|
||||
|
||||
og.light.PointLight.prototype.isActive = function () {
|
||||
return this._active;
|
||||
};
|
||||
|
||||
|
||||
og.light.PointLight.prototype.setPosition = function (position) {
|
||||
this._position = position;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.light.PointLight.prototype.setAmbient = function (rgb) {
|
||||
this._ambient = rgb;
|
||||
var rn = this._renderNode;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
if (rn) {
|
||||
var index = rn._pointLightsNames.indexOf(this._name);
|
||||
if (index != -1) {
|
||||
rn._pointLightsParamsf[index] = shininess;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
og.light.PointLight.prototype.setBlack = function () {
|
||||
this._ambient.clear();
|
||||
this._diffuse.clear();
|
||||
this._specular.clear();
|
||||
this._shininess = 0;
|
||||
var rn = this._renderNode;
|
||||
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;
|
||||
};
|
||||
|
||||
og.light.PointLight.prototype.addTo = function (renderNode) {
|
||||
this._renderNode = renderNode;
|
||||
renderNode._pointLights.push(this);
|
||||
renderNode._pointLightsNames.push(this._name);
|
||||
renderNode._pointLightsParamsf.push(this._shininess);
|
||||
renderNode._pointLightsParamsv.push.apply(renderNode._pointLightsParamsv, this._ambient.toVec());
|
||||
renderNode._pointLightsParamsv.push.apply(renderNode._pointLightsParamsv, this._diffuse.toVec());
|
||||
renderNode._pointLightsParamsv.push.apply(renderNode._pointLightsParamsv, this._specular.toVec());
|
||||
return this;
|
||||
};
|
||||
|
||||
og.light.PointLight.prototype.remove = function () {
|
||||
var rn = this.renderNode;
|
||||
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;
|
||||
goog.provide('og.light.PointLight');
|
||||
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
og.light.PointLight = function (name, position, ambient, diffuse, specular, shininess) {
|
||||
this._name = name || ("p" + og.light.PointLight._counter++);
|
||||
this._renderNode = null;
|
||||
|
||||
this._position = position || new og.math.Vector3();
|
||||
|
||||
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);
|
||||
|
||||
this._shininess = shininess || 3.3;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
og.light.PointLight._counter = 0;
|
||||
|
||||
og.light.PointLight.prototype.clone = function () {
|
||||
|
||||
};
|
||||
|
||||
og.light.PointLight.prototype.setActive = function (active) {
|
||||
if (active && !this._active) {
|
||||
var rn = this._renderNode;
|
||||
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();
|
||||
this._tempDiffuse = this._diffuse.clone();
|
||||
this._tempSpecular = this._specular.clone();
|
||||
this._tempShininess = this._shininess;
|
||||
this.setBlack();
|
||||
this._active = false;
|
||||
}
|
||||
return this.active;
|
||||
};
|
||||
|
||||
og.light.PointLight.prototype.isActive = function () {
|
||||
return this._active;
|
||||
};
|
||||
|
||||
|
||||
og.light.PointLight.prototype.setPosition = function (position) {
|
||||
this._position = position;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.light.PointLight.prototype.setAmbient = function (rgb) {
|
||||
this._ambient = rgb;
|
||||
var rn = this._renderNode;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
if (rn) {
|
||||
var index = rn._pointLightsNames.indexOf(this._name);
|
||||
if (index != -1) {
|
||||
rn._pointLightsParamsf[index] = shininess;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
og.light.PointLight.prototype.setBlack = function () {
|
||||
this._ambient.clear();
|
||||
this._diffuse.clear();
|
||||
this._specular.clear();
|
||||
this._shininess = 0;
|
||||
var rn = this._renderNode;
|
||||
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;
|
||||
};
|
||||
|
||||
og.light.PointLight.prototype.addTo = function (renderNode) {
|
||||
this._renderNode = renderNode;
|
||||
renderNode._pointLights.push(this);
|
||||
renderNode._pointLightsNames.push(this._name);
|
||||
renderNode._pointLightsParamsf.push(this._shininess);
|
||||
renderNode._pointLightsParamsv.push.apply(renderNode._pointLightsParamsv, this._ambient.toVec());
|
||||
renderNode._pointLightsParamsv.push.apply(renderNode._pointLightsParamsv, this._diffuse.toVec());
|
||||
renderNode._pointLightsParamsv.push.apply(renderNode._pointLightsParamsv, this._specular.toVec());
|
||||
return this;
|
||||
};
|
||||
|
||||
og.light.PointLight.prototype.remove = function () {
|
||||
var rn = this.renderNode;
|
||||
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;
|
||||
};
|
||||
@ -1,39 +1,39 @@
|
||||
goog.provide('og.math.coder');
|
||||
|
||||
goog.require('og.math');
|
||||
goog.require('og.math.Vector4');
|
||||
|
||||
og.math.coder.encodeFloatToRGBA = function (f) {
|
||||
var F = Math.abs(f);
|
||||
var s = og.math.step(0.0, -f);
|
||||
var e = Math.floor(og.math.log2(F));
|
||||
var m = (og.math.exp2(-e) * F);
|
||||
e = Math.floor(og.math.log2(F) + 127.0) + Math.floor(og.math.log2(m));
|
||||
return new og.math.Vector4(
|
||||
128.0 * s + Math.floor(e * og.math.exp2(-1.0)),
|
||||
128.0 * og.math.mod(e, 2.0) + og.math.mod(Math.floor(m * 128.0), 128.0),
|
||||
Math.floor(og.math.mod(Math.floor(m * og.math.exp2(23.0 - 8.0)), og.math.exp2(8.0))),
|
||||
Math.floor(og.math.exp2(23.0) * og.math.mod(m, og.math.exp2(-15.0)))
|
||||
);
|
||||
};
|
||||
|
||||
og.math.coder.decodeFloatFromRGBA = function (rgba) {
|
||||
var s = 1.0 - og.math.step(128.0, rgba.x) * 2.0;
|
||||
var e = 2.0 * og.math.mod(rgba.x, 128.0) + og.math.step(128.0, rgba.y) - 127.0;
|
||||
var m = og.math.mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.00;
|
||||
return s * og.math.exp2(e) * (m * og.math.exp2(-23.0));
|
||||
};
|
||||
|
||||
og.math.coder.doubleToTwoFloats = function (value) {
|
||||
var high, low;
|
||||
if (value >= 0.0) {
|
||||
var doubleHigh = Math.floor(value / 65536.0) * 65536.0;
|
||||
high = Math.fround(doubleHigh);
|
||||
low = Math.fround(value - doubleHigh);
|
||||
} else {
|
||||
var doubleHigh = Math.floor(-value / 65536.0) * 65536.0;
|
||||
high = Math.fround(-doubleHigh);
|
||||
low = Math.fround(value + doubleHigh);
|
||||
}
|
||||
return [high, low];
|
||||
goog.provide('og.math.coder');
|
||||
|
||||
goog.require('og.math');
|
||||
goog.require('og.math.Vector4');
|
||||
|
||||
og.math.coder.encodeFloatToRGBA = function (f) {
|
||||
var F = Math.abs(f);
|
||||
var s = og.math.step(0.0, -f);
|
||||
var e = Math.floor(og.math.log2(F));
|
||||
var m = (og.math.exp2(-e) * F);
|
||||
e = Math.floor(og.math.log2(F) + 127.0) + Math.floor(og.math.log2(m));
|
||||
return new og.math.Vector4(
|
||||
128.0 * s + Math.floor(e * og.math.exp2(-1.0)),
|
||||
128.0 * og.math.mod(e, 2.0) + og.math.mod(Math.floor(m * 128.0), 128.0),
|
||||
Math.floor(og.math.mod(Math.floor(m * og.math.exp2(23.0 - 8.0)), og.math.exp2(8.0))),
|
||||
Math.floor(og.math.exp2(23.0) * og.math.mod(m, og.math.exp2(-15.0)))
|
||||
);
|
||||
};
|
||||
|
||||
og.math.coder.decodeFloatFromRGBA = function (rgba) {
|
||||
var s = 1.0 - og.math.step(128.0, rgba.x) * 2.0;
|
||||
var e = 2.0 * og.math.mod(rgba.x, 128.0) + og.math.step(128.0, rgba.y) - 127.0;
|
||||
var m = og.math.mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.00;
|
||||
return s * og.math.exp2(e) * (m * og.math.exp2(-23.0));
|
||||
};
|
||||
|
||||
og.math.coder.doubleToTwoFloats = function (value) {
|
||||
var high, low;
|
||||
if (value >= 0.0) {
|
||||
var doubleHigh = Math.floor(value / 65536.0) * 65536.0;
|
||||
high = Math.fround(doubleHigh);
|
||||
low = Math.fround(value - doubleHigh);
|
||||
} else {
|
||||
var doubleHigh = Math.floor(-value / 65536.0) * 65536.0;
|
||||
high = Math.fround(-doubleHigh);
|
||||
low = Math.fround(value + doubleHigh);
|
||||
}
|
||||
return [high, low];
|
||||
};
|
||||
@ -1,47 +1,47 @@
|
||||
goog.provide('og.math.Matrix3');
|
||||
|
||||
goog.require('og.math');
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
og.math.Matrix3 = function () {
|
||||
this._m = new Array(9);
|
||||
};
|
||||
|
||||
og.math.Matrix3.prototype.set = function (m) {
|
||||
this._m[0] = m[0];
|
||||
this._m[1] = m[1];
|
||||
this._m[2] = m[2];
|
||||
this._m[3] = m[3];
|
||||
this._m[4] = m[4];
|
||||
this._m[5] = m[5];
|
||||
this._m[6] = m[6];
|
||||
this._m[7] = m[7];
|
||||
this._m[8] = m[8];
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix3.prototype.clone = function () {
|
||||
var res = new og.math.Matrix3();
|
||||
res.set(this);
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix3.prototype.copy = function (a) {
|
||||
this.set(a._m);
|
||||
};
|
||||
|
||||
og.math.Matrix3.prototype.transpose = function () {
|
||||
var res = new og.math.Matrix3();
|
||||
var m = this._m;
|
||||
res._m[0] = m[0]; res._m[1] = m[3]; res._m[2] = m[6];
|
||||
res._m[3] = m[1]; res._m[4] = m[4]; res._m[5] = m[7];
|
||||
res._m[6] = m[2]; res._m[7] = m[5]; res._m[8] = m[8];
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix3.prototype.setIdentity = function () {
|
||||
this._m[0] = 1; this._m[1] = 0; this._m[2] = 0;
|
||||
this._m[3] = 0; this._m[4] = 1; this._m[5] = 0;
|
||||
this._m[6] = 0; this._m[7] = 0; this._m[8] = 1;
|
||||
return this;
|
||||
goog.provide('og.math.Matrix3');
|
||||
|
||||
goog.require('og.math');
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
og.math.Matrix3 = function () {
|
||||
this._m = new Array(9);
|
||||
};
|
||||
|
||||
og.math.Matrix3.prototype.set = function (m) {
|
||||
this._m[0] = m[0];
|
||||
this._m[1] = m[1];
|
||||
this._m[2] = m[2];
|
||||
this._m[3] = m[3];
|
||||
this._m[4] = m[4];
|
||||
this._m[5] = m[5];
|
||||
this._m[6] = m[6];
|
||||
this._m[7] = m[7];
|
||||
this._m[8] = m[8];
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix3.prototype.clone = function () {
|
||||
var res = new og.math.Matrix3();
|
||||
res.set(this);
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix3.prototype.copy = function (a) {
|
||||
this.set(a._m);
|
||||
};
|
||||
|
||||
og.math.Matrix3.prototype.transpose = function () {
|
||||
var res = new og.math.Matrix3();
|
||||
var m = this._m;
|
||||
res._m[0] = m[0]; res._m[1] = m[3]; res._m[2] = m[6];
|
||||
res._m[3] = m[1]; res._m[4] = m[4]; res._m[5] = m[7];
|
||||
res._m[6] = m[2]; res._m[7] = m[5]; res._m[8] = m[8];
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix3.prototype.setIdentity = function () {
|
||||
this._m[0] = 1; this._m[1] = 0; this._m[2] = 0;
|
||||
this._m[3] = 0; this._m[4] = 1; this._m[5] = 0;
|
||||
this._m[6] = 0; this._m[7] = 0; this._m[8] = 1;
|
||||
return this;
|
||||
};
|
||||
@ -1,255 +1,255 @@
|
||||
goog.provide('og.math.Matrix4');
|
||||
|
||||
goog.require('og.math');
|
||||
goog.require('og.math.Vector3');
|
||||
goog.require('og.math.Vector4');
|
||||
goog.require('og.math.Matrix3');
|
||||
//goog.require('og.math.Quaternion');
|
||||
|
||||
og.math.Matrix4 = function () {
|
||||
this._m = new Array(16);
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.set = function (m) {
|
||||
this._m[0] = m[0];
|
||||
this._m[1] = m[1];
|
||||
this._m[2] = m[2];
|
||||
this._m[3] = m[3];
|
||||
this._m[4] = m[4];
|
||||
this._m[5] = m[5];
|
||||
this._m[6] = m[6];
|
||||
this._m[7] = m[7];
|
||||
this._m[8] = m[8];
|
||||
this._m[9] = m[9];
|
||||
this._m[10] = m[10];
|
||||
this._m[11] = m[11];
|
||||
this._m[12] = m[12];
|
||||
this._m[13] = m[13];
|
||||
this._m[14] = m[14];
|
||||
this._m[15] = m[15];
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.clone = function () {
|
||||
var res = new og.math.Matrix4();
|
||||
res.set(this);
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.copy = function (a) {
|
||||
this.set(a._m);
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.mulVec3 = function (p) {
|
||||
var d = p.x, e = p.y, g = p.z;
|
||||
return new og.math.Vector3(
|
||||
this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12],
|
||||
this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13],
|
||||
this._m[2] * d + this._m[6] * e + this._m[10] * g + this._m[14]
|
||||
);
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.mulVec4 = function (p) {
|
||||
var d = p.x, e = p.y, g = p.z, f = p.w;
|
||||
return new og.math.Vector4(
|
||||
this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12] * f,
|
||||
this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13] * f,
|
||||
this._m[2] * d + this._m[6] * e + this._m[10] * g + this._m[14] * f,
|
||||
this._m[3] * d + this._m[7] * e + this._m[11] * g + this._m[15] * f
|
||||
);
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.toInverseMatrix3 = function () {
|
||||
var a = this._m;
|
||||
var c = a[0], d = a[1], e = a[2],
|
||||
g = a[4], f = a[5], h = a[6],
|
||||
i = a[8], j = a[9], k = a[10],
|
||||
l = k * f - h * j,
|
||||
o = -k * g + h * i,
|
||||
m = j * g - f * i,
|
||||
n = c * l + d * o + e * m;
|
||||
if (!n)
|
||||
return null;
|
||||
n = 1 / n;
|
||||
|
||||
var res = new og.math.Matrix3();
|
||||
res._m[0] = l * n;
|
||||
res._m[1] = (-k * d + e * j) * n;
|
||||
res._m[2] = (h * d - e * f) * n;
|
||||
res._m[3] = o * n;
|
||||
res._m[4] = (k * c - e * i) * n;
|
||||
res._m[5] = (-h * c + e * g) * n;
|
||||
res._m[6] = m * n;
|
||||
res._m[7] = (-j * c + d * i) * n;
|
||||
res._m[8] = (f * c - d * g) * n;
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.inverse = function () {
|
||||
var c = this._m[0], d = this._m[1], e = this._m[2], g = this._m[3],
|
||||
f = this._m[4], h = this._m[5], i = this._m[6], j = this._m[7],
|
||||
k = this._m[8], l = this._m[9], o = this._m[10], m = this._m[11],
|
||||
n = this._m[12], p = this._m[13], r = this._m[14], s = this._m[15],
|
||||
A = c * h - d * f,
|
||||
B = c * i - e * f,
|
||||
t = c * j - g * f,
|
||||
u = d * i - e * h,
|
||||
v = d * j - g * h,
|
||||
w = e * j - g * i,
|
||||
x = k * p - l * n,
|
||||
y = k * r - o * n,
|
||||
z = k * s - m * n,
|
||||
C = l * r - o * p,
|
||||
D = l * s - m * p,
|
||||
E = o * s - m * r,
|
||||
q = 1 / (A * E - B * D + t * C + u * z - v * y + w * x),
|
||||
res = new og.math.Matrix4();
|
||||
|
||||
res._m[0] = (h * E - i * D + j * C) * q; res._m[1] = (-d * E + e * D - g * C) * q; res._m[2] = (p * w - r * v + s * u) * q; res._m[3] = (-l * w + o * v - m * u) * q;
|
||||
res._m[4] = (-f * E + i * z - j * y) * q; res._m[5] = (c * E - e * z + g * y) * q; res._m[6] = (-n * w + r * t - s * B) * q; res._m[7] = (k * w - o * t + m * B) * q;
|
||||
res._m[8] = (f * D - h * z + j * x) * q; res._m[9] = (-c * D + d * z - g * x) * q; res._m[10] = (n * v - p * t + s * A) * q; res._m[11] = (-k * v + l * t - m * A) * q;
|
||||
res._m[12] = (-f * C + h * y - i * x) * q; res._m[13] = (c * C - d * y + e * x) * q; res._m[14] = (-n * u + p * B - r * A) * q; res._m[15] = (k * u - l * B + o * A) * q;
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.transpose = function () {
|
||||
var res = new og.math.Matrix4();
|
||||
res._m[0] = this._m[0]; res._m[1] = this._m[4]; res._m[2] = this._m[8]; res._m[3] = this._m[12];
|
||||
res._m[4] = this._m[1]; res._m[5] = this._m[5]; res._m[6] = this._m[9]; res._m[7] = this._m[13];
|
||||
res._m[8] = this._m[2]; res._m[9] = this._m[6]; res._m[10] = this._m[10]; res._m[11] = this._m[14];
|
||||
res._m[12] = this._m[3]; res._m[13] = this._m[7]; res._m[14] = this._m[11]; res._m[15] = this._m[15];
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.setIdentity = function () {
|
||||
this._m[0] = 1; this._m[1] = 0; this._m[2] = 0; this._m[3] = 0;
|
||||
this._m[4] = 0; this._m[5] = 1; this._m[6] = 0; this._m[7] = 0;
|
||||
this._m[8] = 0; this._m[9] = 0; this._m[10] = 1; this._m[11] = 0;
|
||||
this._m[12] = 0; this._m[13] = 0; this._m[14] = 0; this._m[15] = 1;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix4.identity = function () {
|
||||
var res = new og.math.Matrix4();
|
||||
res._m[0] = 1; res._m[1] = 0; res._m[2] = 0; res._m[3] = 0;
|
||||
res._m[4] = 0; res._m[5] = 1; res._m[6] = 0; res._m[7] = 0;
|
||||
res._m[8] = 0; res._m[9] = 0; res._m[10] = 1; res._m[11] = 0;
|
||||
res._m[12] = 0; res._m[13] = 0; res._m[14] = 0; res._m[15] = 1;
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.mul = function (mx) {
|
||||
var d = this._m[0], e = this._m[1], g = this._m[2], f = this._m[3],
|
||||
h = this._m[4], i = this._m[5], j = this._m[6], k = this._m[7],
|
||||
l = this._m[8], o = this._m[9], m = this._m[10], n = this._m[11],
|
||||
p = this._m[12], r = this._m[13], s = this._m[14]; a = this._m[15];
|
||||
|
||||
var A = mx._m[0], B = mx._m[1], t = mx._m[2], u = mx._m[3],
|
||||
v = mx._m[4], w = mx._m[5], x = mx._m[6], y = mx._m[7],
|
||||
z = mx._m[8], C = mx._m[9], D = mx._m[10], E = mx._m[11],
|
||||
q = mx._m[12], F = mx._m[13], G = mx._m[14]; b = mx._m[15];
|
||||
|
||||
var res = new og.math.Matrix4();
|
||||
res._m[0] = A * d + B * h + t * l + u * p; res._m[1] = A * e + B * i + t * o + u * r; res._m[2] = A * g + B * j + t * m + u * s; res._m[3] = A * f + B * k + t * n + u * a;
|
||||
res._m[4] = v * d + w * h + x * l + y * p; res._m[5] = v * e + w * i + x * o + y * r; res._m[6] = v * g + w * j + x * m + y * s; res._m[7] = v * f + w * k + x * n + y * a;
|
||||
res._m[8] = z * d + C * h + D * l + E * p; res._m[9] = z * e + C * i + D * o + E * r; res._m[10] = z * g + C * j + D * m + E * s; res._m[11] = z * f + C * k + D * n + E * a;
|
||||
res._m[12] = q * d + F * h + G * l + b * p; res._m[13] = q * e + F * i + G * o + b * r; res._m[14] = q * g + F * j + G * m + b * s; res._m[15] = q * f + F * k + G * n + b * a;
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.translate = function (v) {
|
||||
var d = v.x, e = v.y, b = v.z;
|
||||
var a = this._m;
|
||||
a[12] = a[0] * d + a[4] * e + a[8] * b + a[12];
|
||||
a[13] = a[1] * d + a[5] * e + a[9] * b + a[13];
|
||||
a[14] = a[2] * d + a[6] * e + a[10] * b + a[14];
|
||||
a[15] = a[3] * d + a[7] * e + a[11] * b + a[15];
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.translateToPosition = function (v) {
|
||||
var a = this._m;
|
||||
a[12] = v.x;
|
||||
a[13] = v.y;
|
||||
a[14] = v.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.rotate = function (u, angle) {
|
||||
var c = Math.cos(angle),
|
||||
s = Math.sin(angle);
|
||||
var mx = this._m;
|
||||
mx[0] = c + (1 - c) * u.x * u.x; mx[1] = (1 - c) * u.y * u.x - s * u.z; mx[2] = (1 - c) * u.z * u.x + s * u.y; mx[3] = 0;
|
||||
mx[4] = (1 - c) * u.x * u.y + s * u.z; mx[5] = c + (1 - c) * u.y * u.y; mx[6] = (1 - c) * u.z * u.y - s * u.x; mx[7] = 0;
|
||||
mx[8] = (1 - c) * u.x * u.z - s * u.y; mx[9] = (1 - c) * u.y * u.z + s * u.x; mx[10] = c + (1 - c) * u.z * u.z; mx[11] = 0;
|
||||
mx[12] = 0; mx[13] = 0; mx[14] = 0; mx[15] = 1;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.rotateBetweenVectors = function (a, b) {
|
||||
var q = og.math.Quaternion.getRotationBetweenVectors(a, b);
|
||||
return q.getMatrix4();
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.scale = function (v) {
|
||||
var mx = this._m;
|
||||
mx[0] = mx[0] * v.x; mx[1] = mx[1] * v.x; mx[2] = mx[2] * v.x; mx[3] = mx[3] * v.x;
|
||||
mx[4] = mx[4] * v.y; mx[5] = mx[5] * v.y; mx[6] = mx[6] * v.y; mx[7] = mx[7] * v.y;
|
||||
mx[8] = mx[8] * v.z; mx[9] = mx[9] * v.z; mx[10] = mx[10] * v.z; mx[11] = mx[11] * v.z;
|
||||
mx[12] = mx[12]; mx[13] = mx[13]; mx[14] = mx[14]; mx[15] = mx[15];
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.setFrustum = function (a, b, c, d, e, g) {
|
||||
|
||||
this.right = b;
|
||||
this.left = a;
|
||||
this.top = d;
|
||||
this.bottom = c;
|
||||
this.far = g;
|
||||
this.near = e;
|
||||
|
||||
var h = b - a, i = d - c, j = g - e;
|
||||
this._m[0] = e * 2 / h; this._m[1] = 0; this._m[2] = 0; this._m[3] = 0;
|
||||
this._m[4] = 0; this._m[5] = e * 2 / i; this._m[6] = 0; this._m[7] = 0;
|
||||
this._m[8] = (b + a) / h; this._m[9] = (d + c) / i; this._m[10] = -(g + e) / j; this._m[11] = -1;
|
||||
this._m[12] = 0; this._m[13] = 0; this._m[14] = -(g * e * 2) / j; this._m[15] = 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.setPerspective = function (angle, aspect, near, far) {
|
||||
angle = near * Math.tan(angle * Math.PI / 360);
|
||||
aspect = angle * aspect;
|
||||
return this.setFrustum(-aspect, aspect, -angle, angle, near, far)
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.eulerToMatrix = function (ax, ay, az) {
|
||||
var a = Math.cos(ax),
|
||||
b = Math.sin(ax),
|
||||
c = Math.cos(ay),
|
||||
d = Math.sin(ay),
|
||||
e = Math.cos(az),
|
||||
f = Math.sin(az);
|
||||
|
||||
var ad = a * d,
|
||||
bd = b * d;
|
||||
|
||||
var mat = this._m;
|
||||
|
||||
mat[0] = c * e;
|
||||
mat[1] = -c * f;
|
||||
mat[2] = -d;
|
||||
mat[4] = -bd * e + a * f;
|
||||
mat[5] = bd * f + a * e;
|
||||
mat[6] = -b * c;
|
||||
mat[8] = ad * e + b * f;
|
||||
mat[9] = -ad * f + b * e;
|
||||
mat[10] = a * c;
|
||||
mat[3] = mat[7] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
|
||||
mat[15] = 1;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.getEulerAngles = function () {
|
||||
//TODO
|
||||
};
|
||||
|
||||
goog.provide('og.math.Matrix4');
|
||||
|
||||
goog.require('og.math');
|
||||
goog.require('og.math.Vector3');
|
||||
goog.require('og.math.Vector4');
|
||||
goog.require('og.math.Matrix3');
|
||||
//goog.require('og.math.Quaternion');
|
||||
|
||||
og.math.Matrix4 = function () {
|
||||
this._m = new Array(16);
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.set = function (m) {
|
||||
this._m[0] = m[0];
|
||||
this._m[1] = m[1];
|
||||
this._m[2] = m[2];
|
||||
this._m[3] = m[3];
|
||||
this._m[4] = m[4];
|
||||
this._m[5] = m[5];
|
||||
this._m[6] = m[6];
|
||||
this._m[7] = m[7];
|
||||
this._m[8] = m[8];
|
||||
this._m[9] = m[9];
|
||||
this._m[10] = m[10];
|
||||
this._m[11] = m[11];
|
||||
this._m[12] = m[12];
|
||||
this._m[13] = m[13];
|
||||
this._m[14] = m[14];
|
||||
this._m[15] = m[15];
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.clone = function () {
|
||||
var res = new og.math.Matrix4();
|
||||
res.set(this);
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.copy = function (a) {
|
||||
this.set(a._m);
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.mulVec3 = function (p) {
|
||||
var d = p.x, e = p.y, g = p.z;
|
||||
return new og.math.Vector3(
|
||||
this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12],
|
||||
this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13],
|
||||
this._m[2] * d + this._m[6] * e + this._m[10] * g + this._m[14]
|
||||
);
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.mulVec4 = function (p) {
|
||||
var d = p.x, e = p.y, g = p.z, f = p.w;
|
||||
return new og.math.Vector4(
|
||||
this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12] * f,
|
||||
this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13] * f,
|
||||
this._m[2] * d + this._m[6] * e + this._m[10] * g + this._m[14] * f,
|
||||
this._m[3] * d + this._m[7] * e + this._m[11] * g + this._m[15] * f
|
||||
);
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.toInverseMatrix3 = function () {
|
||||
var a = this._m;
|
||||
var c = a[0], d = a[1], e = a[2],
|
||||
g = a[4], f = a[5], h = a[6],
|
||||
i = a[8], j = a[9], k = a[10],
|
||||
l = k * f - h * j,
|
||||
o = -k * g + h * i,
|
||||
m = j * g - f * i,
|
||||
n = c * l + d * o + e * m;
|
||||
if (!n)
|
||||
return null;
|
||||
n = 1 / n;
|
||||
|
||||
var res = new og.math.Matrix3();
|
||||
res._m[0] = l * n;
|
||||
res._m[1] = (-k * d + e * j) * n;
|
||||
res._m[2] = (h * d - e * f) * n;
|
||||
res._m[3] = o * n;
|
||||
res._m[4] = (k * c - e * i) * n;
|
||||
res._m[5] = (-h * c + e * g) * n;
|
||||
res._m[6] = m * n;
|
||||
res._m[7] = (-j * c + d * i) * n;
|
||||
res._m[8] = (f * c - d * g) * n;
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.inverse = function () {
|
||||
var c = this._m[0], d = this._m[1], e = this._m[2], g = this._m[3],
|
||||
f = this._m[4], h = this._m[5], i = this._m[6], j = this._m[7],
|
||||
k = this._m[8], l = this._m[9], o = this._m[10], m = this._m[11],
|
||||
n = this._m[12], p = this._m[13], r = this._m[14], s = this._m[15],
|
||||
A = c * h - d * f,
|
||||
B = c * i - e * f,
|
||||
t = c * j - g * f,
|
||||
u = d * i - e * h,
|
||||
v = d * j - g * h,
|
||||
w = e * j - g * i,
|
||||
x = k * p - l * n,
|
||||
y = k * r - o * n,
|
||||
z = k * s - m * n,
|
||||
C = l * r - o * p,
|
||||
D = l * s - m * p,
|
||||
E = o * s - m * r,
|
||||
q = 1 / (A * E - B * D + t * C + u * z - v * y + w * x),
|
||||
res = new og.math.Matrix4();
|
||||
|
||||
res._m[0] = (h * E - i * D + j * C) * q; res._m[1] = (-d * E + e * D - g * C) * q; res._m[2] = (p * w - r * v + s * u) * q; res._m[3] = (-l * w + o * v - m * u) * q;
|
||||
res._m[4] = (-f * E + i * z - j * y) * q; res._m[5] = (c * E - e * z + g * y) * q; res._m[6] = (-n * w + r * t - s * B) * q; res._m[7] = (k * w - o * t + m * B) * q;
|
||||
res._m[8] = (f * D - h * z + j * x) * q; res._m[9] = (-c * D + d * z - g * x) * q; res._m[10] = (n * v - p * t + s * A) * q; res._m[11] = (-k * v + l * t - m * A) * q;
|
||||
res._m[12] = (-f * C + h * y - i * x) * q; res._m[13] = (c * C - d * y + e * x) * q; res._m[14] = (-n * u + p * B - r * A) * q; res._m[15] = (k * u - l * B + o * A) * q;
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.transpose = function () {
|
||||
var res = new og.math.Matrix4();
|
||||
res._m[0] = this._m[0]; res._m[1] = this._m[4]; res._m[2] = this._m[8]; res._m[3] = this._m[12];
|
||||
res._m[4] = this._m[1]; res._m[5] = this._m[5]; res._m[6] = this._m[9]; res._m[7] = this._m[13];
|
||||
res._m[8] = this._m[2]; res._m[9] = this._m[6]; res._m[10] = this._m[10]; res._m[11] = this._m[14];
|
||||
res._m[12] = this._m[3]; res._m[13] = this._m[7]; res._m[14] = this._m[11]; res._m[15] = this._m[15];
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.setIdentity = function () {
|
||||
this._m[0] = 1; this._m[1] = 0; this._m[2] = 0; this._m[3] = 0;
|
||||
this._m[4] = 0; this._m[5] = 1; this._m[6] = 0; this._m[7] = 0;
|
||||
this._m[8] = 0; this._m[9] = 0; this._m[10] = 1; this._m[11] = 0;
|
||||
this._m[12] = 0; this._m[13] = 0; this._m[14] = 0; this._m[15] = 1;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix4.identity = function () {
|
||||
var res = new og.math.Matrix4();
|
||||
res._m[0] = 1; res._m[1] = 0; res._m[2] = 0; res._m[3] = 0;
|
||||
res._m[4] = 0; res._m[5] = 1; res._m[6] = 0; res._m[7] = 0;
|
||||
res._m[8] = 0; res._m[9] = 0; res._m[10] = 1; res._m[11] = 0;
|
||||
res._m[12] = 0; res._m[13] = 0; res._m[14] = 0; res._m[15] = 1;
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.mul = function (mx) {
|
||||
var d = this._m[0], e = this._m[1], g = this._m[2], f = this._m[3],
|
||||
h = this._m[4], i = this._m[5], j = this._m[6], k = this._m[7],
|
||||
l = this._m[8], o = this._m[9], m = this._m[10], n = this._m[11],
|
||||
p = this._m[12], r = this._m[13], s = this._m[14]; a = this._m[15];
|
||||
|
||||
var A = mx._m[0], B = mx._m[1], t = mx._m[2], u = mx._m[3],
|
||||
v = mx._m[4], w = mx._m[5], x = mx._m[6], y = mx._m[7],
|
||||
z = mx._m[8], C = mx._m[9], D = mx._m[10], E = mx._m[11],
|
||||
q = mx._m[12], F = mx._m[13], G = mx._m[14]; b = mx._m[15];
|
||||
|
||||
var res = new og.math.Matrix4();
|
||||
res._m[0] = A * d + B * h + t * l + u * p; res._m[1] = A * e + B * i + t * o + u * r; res._m[2] = A * g + B * j + t * m + u * s; res._m[3] = A * f + B * k + t * n + u * a;
|
||||
res._m[4] = v * d + w * h + x * l + y * p; res._m[5] = v * e + w * i + x * o + y * r; res._m[6] = v * g + w * j + x * m + y * s; res._m[7] = v * f + w * k + x * n + y * a;
|
||||
res._m[8] = z * d + C * h + D * l + E * p; res._m[9] = z * e + C * i + D * o + E * r; res._m[10] = z * g + C * j + D * m + E * s; res._m[11] = z * f + C * k + D * n + E * a;
|
||||
res._m[12] = q * d + F * h + G * l + b * p; res._m[13] = q * e + F * i + G * o + b * r; res._m[14] = q * g + F * j + G * m + b * s; res._m[15] = q * f + F * k + G * n + b * a;
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.translate = function (v) {
|
||||
var d = v.x, e = v.y, b = v.z;
|
||||
var a = this._m;
|
||||
a[12] = a[0] * d + a[4] * e + a[8] * b + a[12];
|
||||
a[13] = a[1] * d + a[5] * e + a[9] * b + a[13];
|
||||
a[14] = a[2] * d + a[6] * e + a[10] * b + a[14];
|
||||
a[15] = a[3] * d + a[7] * e + a[11] * b + a[15];
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.translateToPosition = function (v) {
|
||||
var a = this._m;
|
||||
a[12] = v.x;
|
||||
a[13] = v.y;
|
||||
a[14] = v.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.rotate = function (u, angle) {
|
||||
var c = Math.cos(angle),
|
||||
s = Math.sin(angle);
|
||||
var mx = this._m;
|
||||
mx[0] = c + (1 - c) * u.x * u.x; mx[1] = (1 - c) * u.y * u.x - s * u.z; mx[2] = (1 - c) * u.z * u.x + s * u.y; mx[3] = 0;
|
||||
mx[4] = (1 - c) * u.x * u.y + s * u.z; mx[5] = c + (1 - c) * u.y * u.y; mx[6] = (1 - c) * u.z * u.y - s * u.x; mx[7] = 0;
|
||||
mx[8] = (1 - c) * u.x * u.z - s * u.y; mx[9] = (1 - c) * u.y * u.z + s * u.x; mx[10] = c + (1 - c) * u.z * u.z; mx[11] = 0;
|
||||
mx[12] = 0; mx[13] = 0; mx[14] = 0; mx[15] = 1;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.rotateBetweenVectors = function (a, b) {
|
||||
var q = og.math.Quaternion.getRotationBetweenVectors(a, b);
|
||||
return q.getMatrix4();
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.scale = function (v) {
|
||||
var mx = this._m;
|
||||
mx[0] = mx[0] * v.x; mx[1] = mx[1] * v.x; mx[2] = mx[2] * v.x; mx[3] = mx[3] * v.x;
|
||||
mx[4] = mx[4] * v.y; mx[5] = mx[5] * v.y; mx[6] = mx[6] * v.y; mx[7] = mx[7] * v.y;
|
||||
mx[8] = mx[8] * v.z; mx[9] = mx[9] * v.z; mx[10] = mx[10] * v.z; mx[11] = mx[11] * v.z;
|
||||
mx[12] = mx[12]; mx[13] = mx[13]; mx[14] = mx[14]; mx[15] = mx[15];
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.setFrustum = function (a, b, c, d, e, g) {
|
||||
|
||||
this.right = b;
|
||||
this.left = a;
|
||||
this.top = d;
|
||||
this.bottom = c;
|
||||
this.far = g;
|
||||
this.near = e;
|
||||
|
||||
var h = b - a, i = d - c, j = g - e;
|
||||
this._m[0] = e * 2 / h; this._m[1] = 0; this._m[2] = 0; this._m[3] = 0;
|
||||
this._m[4] = 0; this._m[5] = e * 2 / i; this._m[6] = 0; this._m[7] = 0;
|
||||
this._m[8] = (b + a) / h; this._m[9] = (d + c) / i; this._m[10] = -(g + e) / j; this._m[11] = -1;
|
||||
this._m[12] = 0; this._m[13] = 0; this._m[14] = -(g * e * 2) / j; this._m[15] = 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.setPerspective = function (angle, aspect, near, far) {
|
||||
angle = near * Math.tan(angle * Math.PI / 360);
|
||||
aspect = angle * aspect;
|
||||
return this.setFrustum(-aspect, aspect, -angle, angle, near, far)
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.eulerToMatrix = function (ax, ay, az) {
|
||||
var a = Math.cos(ax),
|
||||
b = Math.sin(ax),
|
||||
c = Math.cos(ay),
|
||||
d = Math.sin(ay),
|
||||
e = Math.cos(az),
|
||||
f = Math.sin(az);
|
||||
|
||||
var ad = a * d,
|
||||
bd = b * d;
|
||||
|
||||
var mat = this._m;
|
||||
|
||||
mat[0] = c * e;
|
||||
mat[1] = -c * f;
|
||||
mat[2] = -d;
|
||||
mat[4] = -bd * e + a * f;
|
||||
mat[5] = bd * f + a * e;
|
||||
mat[6] = -b * c;
|
||||
mat[8] = ad * e + b * f;
|
||||
mat[9] = -ad * f + b * e;
|
||||
mat[10] = a * c;
|
||||
mat[3] = mat[7] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
|
||||
mat[15] = 1;
|
||||
};
|
||||
|
||||
og.math.Matrix4.prototype.getEulerAngles = function () {
|
||||
//TODO
|
||||
};
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
goog.provide('og.math.Pixel');
|
||||
|
||||
og.math.Pixel = function (x, y) {
|
||||
this.x = x || 0;
|
||||
this.y = y || 0;
|
||||
goog.provide('og.math.Pixel');
|
||||
|
||||
og.math.Pixel = function (x, y) {
|
||||
this.x = x || 0;
|
||||
this.y = y || 0;
|
||||
};
|
||||
@ -1,150 +1,150 @@
|
||||
goog.provide('og.math.Ray');
|
||||
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
og.math.Ray = function (origin, direction) {
|
||||
this.origin = origin.clone();
|
||||
this.direction = direction.clone().normalize();
|
||||
};
|
||||
|
||||
og.math.Ray.prototype.set = function (origin, direction) {
|
||||
this.origin = origin.clone();
|
||||
this.direction = direction.clone();
|
||||
};
|
||||
|
||||
og.math.Ray.prototype.getPoint = function (distance) {
|
||||
return og.Vector3.add(this.origin, this.direction.scaleTo(distance));
|
||||
};
|
||||
|
||||
og.math.Ray.OUTSIDE = 0;
|
||||
og.math.Ray.INSIDE = 1;
|
||||
og.math.Ray.INPLANE = 2;
|
||||
og.math.Ray.AWAY = 3;
|
||||
|
||||
og.math.Ray.prototype.hitTriangle = function (v0, v1, v2, res) {
|
||||
var state;
|
||||
var u = og.math.Vector3.sub(v1, v0);
|
||||
var v = og.math.Vector3.sub(v2, v0);
|
||||
var n = u.cross(v);
|
||||
|
||||
var w0 = og.math.Vector3.sub(this.origin, v0);
|
||||
var a = -n.dot(w0);
|
||||
var b = n.dot(this.direction);
|
||||
|
||||
// ray is parallel to triangle plane
|
||||
if (Math.abs(b) < og.math.EPSILON10) {
|
||||
if (a == 0) {
|
||||
res.copy(this.origin);
|
||||
// ray lies in triangle plane
|
||||
return og.math.Ray.INPLANE;
|
||||
} else {
|
||||
// ray disjoint from plane
|
||||
return og.math.Ray.OUTSIDE;
|
||||
}
|
||||
}
|
||||
|
||||
var r = a / b;
|
||||
|
||||
// intersect point of ray and plane
|
||||
res.copy(og.math.Vector3.add(this.origin, this.direction.scaleTo(r)));
|
||||
|
||||
// ray goes away from triangle
|
||||
if (r < 0.0)
|
||||
return og.math.Ray.AWAY;
|
||||
|
||||
// is I inside triangle?
|
||||
var uu = u.dot(u);
|
||||
var uv = u.dot(v);
|
||||
var vv = v.dot(v);
|
||||
var w = og.math.Vector3.sub(res, v0);
|
||||
var wu = w.dot(u);
|
||||
var wv = w.dot(v);
|
||||
var D = uv * uv - uu * vv;
|
||||
|
||||
var s = (uv * wv - vv * wu) / D;
|
||||
if (s < 0.0 || s > 1.0)
|
||||
return og.math.Ray.OUTSIDE;
|
||||
|
||||
var t = (uv * wu - uu * wv) / D;
|
||||
if (t < 0.0 || (s + t) > 1.0)
|
||||
return og.math.Ray.OUTSIDE;
|
||||
|
||||
return og.math.Ray.INSIDE;
|
||||
};
|
||||
|
||||
//from JGT
|
||||
//og.math.Ray.prototype.hitTriangle = function (vert0, vert1, vert2) {
|
||||
// var edge1 = og.math.Vector3.sub(vert1, vert0);
|
||||
// var edge2 = og.math.Vector3.sub(vert2, vert0);
|
||||
|
||||
// var pvec = this.direction.cross(edge2);
|
||||
|
||||
// /* if determinant is near zero, ray lies in plane of triangle */
|
||||
// var det = edge1.dot(pvec);
|
||||
|
||||
// if (det > -og.math.EPSILON6 && det < og.math.EPSILON6)
|
||||
// return null;
|
||||
|
||||
// var inv_det = 1.0 / det;
|
||||
|
||||
// var tvec = og.math.Vector3.sub(this.origin, vert0);
|
||||
|
||||
// var u = tvec.dot(pvec) * inv_det;
|
||||
// if (u < 0.0 || u > 1.0)
|
||||
// return null;
|
||||
|
||||
// var qvec = tvec.cross(edge1);
|
||||
|
||||
// var v = this.direction.dot(qvec) * inv_det;
|
||||
// if (v < 0.0 || u + v > 1.0)
|
||||
// return null;
|
||||
|
||||
// var t = edge2.dot(qvec) * inv_det;
|
||||
|
||||
// return new og.math.Vector3(u, v, t);
|
||||
//};
|
||||
|
||||
og.math.Ray.prototype.hitPlane = function (point, normal) {
|
||||
|
||||
};
|
||||
|
||||
og.math.Ray.prototype.hitSphere = function (sphere) {
|
||||
var r = sphere.radius, c = sphere.center,
|
||||
o = this.origin, d = this.direction;
|
||||
var vpc = og.math.Vector3.sub(c, o);
|
||||
if (vpc.dot(d) < 0) {
|
||||
var l = vpc.length();
|
||||
if (l > r) {
|
||||
return null;
|
||||
} else if (l === r) {
|
||||
return o.clone();
|
||||
}
|
||||
var pc = c.projToRay(o, vpc);
|
||||
var lc = og.math.Vector3.sub(pc, c).length();
|
||||
var dist = Math.sqrt(r * r - lc * lc);
|
||||
var di1 = dist - og.math.Vector3.sub(pc, o).length();
|
||||
var intersection = og.math.Vector3.add(o, d.scaleTo(di1));
|
||||
return intersection;
|
||||
} else {
|
||||
var pc = c.projToRay(o, d);
|
||||
var cpcl = og.math.Vector3.sub(c, pc).length();
|
||||
if (cpcl > sphere.radius) {
|
||||
return null;
|
||||
} else {
|
||||
var dist = Math.sqrt(r * r - cpcl * cpcl);
|
||||
var di1;
|
||||
pc.sub(o);
|
||||
if (vpc.length() > r) {
|
||||
di1 = pc.length() - dist;
|
||||
} else {
|
||||
di1 = pc.length() + dist;
|
||||
}
|
||||
var intersection = og.math.Vector3.add(o, d.scaleTo(di1));
|
||||
return intersection;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
og.math.Ray.prototype.hitBox = function (box) {
|
||||
|
||||
goog.provide('og.math.Ray');
|
||||
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
og.math.Ray = function (origin, direction) {
|
||||
this.origin = origin.clone();
|
||||
this.direction = direction.clone().normalize();
|
||||
};
|
||||
|
||||
og.math.Ray.prototype.set = function (origin, direction) {
|
||||
this.origin = origin.clone();
|
||||
this.direction = direction.clone();
|
||||
};
|
||||
|
||||
og.math.Ray.prototype.getPoint = function (distance) {
|
||||
return og.Vector3.add(this.origin, this.direction.scaleTo(distance));
|
||||
};
|
||||
|
||||
og.math.Ray.OUTSIDE = 0;
|
||||
og.math.Ray.INSIDE = 1;
|
||||
og.math.Ray.INPLANE = 2;
|
||||
og.math.Ray.AWAY = 3;
|
||||
|
||||
og.math.Ray.prototype.hitTriangle = function (v0, v1, v2, res) {
|
||||
var state;
|
||||
var u = og.math.Vector3.sub(v1, v0);
|
||||
var v = og.math.Vector3.sub(v2, v0);
|
||||
var n = u.cross(v);
|
||||
|
||||
var w0 = og.math.Vector3.sub(this.origin, v0);
|
||||
var a = -n.dot(w0);
|
||||
var b = n.dot(this.direction);
|
||||
|
||||
// ray is parallel to triangle plane
|
||||
if (Math.abs(b) < og.math.EPSILON10) {
|
||||
if (a == 0) {
|
||||
res.copy(this.origin);
|
||||
// ray lies in triangle plane
|
||||
return og.math.Ray.INPLANE;
|
||||
} else {
|
||||
// ray disjoint from plane
|
||||
return og.math.Ray.OUTSIDE;
|
||||
}
|
||||
}
|
||||
|
||||
var r = a / b;
|
||||
|
||||
// intersect point of ray and plane
|
||||
res.copy(og.math.Vector3.add(this.origin, this.direction.scaleTo(r)));
|
||||
|
||||
// ray goes away from triangle
|
||||
if (r < 0.0)
|
||||
return og.math.Ray.AWAY;
|
||||
|
||||
// is I inside triangle?
|
||||
var uu = u.dot(u);
|
||||
var uv = u.dot(v);
|
||||
var vv = v.dot(v);
|
||||
var w = og.math.Vector3.sub(res, v0);
|
||||
var wu = w.dot(u);
|
||||
var wv = w.dot(v);
|
||||
var D = uv * uv - uu * vv;
|
||||
|
||||
var s = (uv * wv - vv * wu) / D;
|
||||
if (s < 0.0 || s > 1.0)
|
||||
return og.math.Ray.OUTSIDE;
|
||||
|
||||
var t = (uv * wu - uu * wv) / D;
|
||||
if (t < 0.0 || (s + t) > 1.0)
|
||||
return og.math.Ray.OUTSIDE;
|
||||
|
||||
return og.math.Ray.INSIDE;
|
||||
};
|
||||
|
||||
//from JGT
|
||||
//og.math.Ray.prototype.hitTriangle = function (vert0, vert1, vert2) {
|
||||
// var edge1 = og.math.Vector3.sub(vert1, vert0);
|
||||
// var edge2 = og.math.Vector3.sub(vert2, vert0);
|
||||
|
||||
// var pvec = this.direction.cross(edge2);
|
||||
|
||||
// /* if determinant is near zero, ray lies in plane of triangle */
|
||||
// var det = edge1.dot(pvec);
|
||||
|
||||
// if (det > -og.math.EPSILON6 && det < og.math.EPSILON6)
|
||||
// return null;
|
||||
|
||||
// var inv_det = 1.0 / det;
|
||||
|
||||
// var tvec = og.math.Vector3.sub(this.origin, vert0);
|
||||
|
||||
// var u = tvec.dot(pvec) * inv_det;
|
||||
// if (u < 0.0 || u > 1.0)
|
||||
// return null;
|
||||
|
||||
// var qvec = tvec.cross(edge1);
|
||||
|
||||
// var v = this.direction.dot(qvec) * inv_det;
|
||||
// if (v < 0.0 || u + v > 1.0)
|
||||
// return null;
|
||||
|
||||
// var t = edge2.dot(qvec) * inv_det;
|
||||
|
||||
// return new og.math.Vector3(u, v, t);
|
||||
//};
|
||||
|
||||
og.math.Ray.prototype.hitPlane = function (point, normal) {
|
||||
|
||||
};
|
||||
|
||||
og.math.Ray.prototype.hitSphere = function (sphere) {
|
||||
var r = sphere.radius, c = sphere.center,
|
||||
o = this.origin, d = this.direction;
|
||||
var vpc = og.math.Vector3.sub(c, o);
|
||||
if (vpc.dot(d) < 0) {
|
||||
var l = vpc.length();
|
||||
if (l > r) {
|
||||
return null;
|
||||
} else if (l === r) {
|
||||
return o.clone();
|
||||
}
|
||||
var pc = c.projToRay(o, vpc);
|
||||
var lc = og.math.Vector3.sub(pc, c).length();
|
||||
var dist = Math.sqrt(r * r - lc * lc);
|
||||
var di1 = dist - og.math.Vector3.sub(pc, o).length();
|
||||
var intersection = og.math.Vector3.add(o, d.scaleTo(di1));
|
||||
return intersection;
|
||||
} else {
|
||||
var pc = c.projToRay(o, d);
|
||||
var cpcl = og.math.Vector3.sub(c, pc).length();
|
||||
if (cpcl > sphere.radius) {
|
||||
return null;
|
||||
} else {
|
||||
var dist = Math.sqrt(r * r - cpcl * cpcl);
|
||||
var di1;
|
||||
pc.sub(o);
|
||||
if (vpc.length() > r) {
|
||||
di1 = pc.length() - dist;
|
||||
} else {
|
||||
di1 = pc.length() + dist;
|
||||
}
|
||||
var intersection = og.math.Vector3.add(o, d.scaleTo(di1));
|
||||
return intersection;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
og.math.Ray.prototype.hitBox = function (box) {
|
||||
|
||||
};
|
||||
@ -1,235 +1,235 @@
|
||||
goog.provide('og.math.Vector2');
|
||||
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
og.math.Vector2 = function (x, y) {
|
||||
this.x = x || 0.0;
|
||||
this.y = y || 0.0;
|
||||
}
|
||||
|
||||
og.math.Vector2.prototype.toVector3 = function () {
|
||||
return new og.math.Vector3(this.x, this.y, 0);
|
||||
};
|
||||
|
||||
og.math.Vector2.UP = new og.math.Vector2(0, 1);
|
||||
og.math.Vector2.DOWN = new og.math.Vector2(0, -1);
|
||||
og.math.Vector2.RIGHT = new og.math.Vector2(1, 0);
|
||||
og.math.Vector2.LEFT = new og.math.Vector2(-1, 0);
|
||||
og.math.Vector2.ZERO = new og.math.Vector2();
|
||||
|
||||
og.math.Vector2.prototype.clone = function () {
|
||||
return new og.math.Vector2(this.x, this.y);
|
||||
};
|
||||
|
||||
og.math.Vector2.add = function (a, b) {
|
||||
var res = new og.math.Vector2(a.x, a.y);
|
||||
res.add(b);
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Vector2.sub = function (a, b) {
|
||||
var res = new og.math.Vector2(a.x, a.y);
|
||||
res.sub(b);
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Vector2.scale = function (a, scale) {
|
||||
var res = new og.math.Vector2(a.x, a.y);
|
||||
res.scale(scale)
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Vector2.mull = function (a, b) {
|
||||
var res = new og.math.Vector2(a.x, a.y);
|
||||
res.mull(b);
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Vector2.div = function (a, b) {
|
||||
var res = new og.math.Vector2(a.x, a.y);
|
||||
res.div(b);
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.equal = function (p) {
|
||||
return this.x === p.x && this.y === p.y;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.copy = function (point2) {
|
||||
this.x = point2.x;
|
||||
this.y = point2.y;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.length = function () {
|
||||
return Math.sqrt(this.x * this.x + this.y * this.y);
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.length2 = function () {
|
||||
return this.x * this.x + this.y * this.y;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.add = function (v) {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.sub = function (v) {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.scale = function (scale) {
|
||||
this.x *= scale;
|
||||
this.y *= scale;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.scaleTo = function (scale) {
|
||||
return new og.math.Vector2(this.x * scale, this.y * scale);
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.mull = function (vec) {
|
||||
this.x *= vec.x;
|
||||
this.y *= vec.y;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.div = function (vec) {
|
||||
this.x /= vec.x;
|
||||
this.y /= vec.y;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.dot = function (v) {
|
||||
return v.x * this.x + v.y * this.y + v.z * this.z;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.dotArr = function (arr) {
|
||||
return arr[0] * this.x + arr[1] * this.y;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.cross = function (v) {
|
||||
return this.x * v.y - this.y * v.x;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.clear = function () {
|
||||
this.x = this.y = 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.normal = function () {
|
||||
var res = new og.math.Vector2();
|
||||
res.copy(this);
|
||||
|
||||
var length = 1.0 / res.length();
|
||||
|
||||
res.x *= length;
|
||||
res.y *= length;
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.normalize = function () {
|
||||
var length = 1.0 / this.length();
|
||||
|
||||
this.x *= length;
|
||||
this.y *= length;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.toVec = function () {
|
||||
var x = new og.math.GLArray(2);
|
||||
x[0] = this.x;
|
||||
x[1] = this.y;
|
||||
return x;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.distance = function (p) {
|
||||
var vec = og.math.Vector2.sub(this, p);
|
||||
return vec.length();
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.set = function (x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.negate = function () {
|
||||
this.x = -this.x;
|
||||
this.y = -this.y;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.getNegate = function () {
|
||||
return new og.math.Vector2(-this.x, -this.y);
|
||||
};
|
||||
|
||||
og.math.Vector2.proj_b_to_a = function (b, a) {
|
||||
return a.scaleTo(a.dot(b) / a.dot(a));
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.projToRay = function (pos, direction) {
|
||||
var v = og.math.Vector2.proj_b_to_a(og.math.Vector2.sub(this, pos), direction);
|
||||
v.add(pos);
|
||||
return v;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.angle = function (a) {
|
||||
return og.math.Vector2.angle(this, a);
|
||||
};
|
||||
|
||||
og.math.Vector2.angle = function (a, b) {
|
||||
return Math.acos(a.dot(b) / Math.sqrt(a.length2() * b.length2()));
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.lerp = function (v1, v2, l) {
|
||||
var res = og.math.Vector2.clone(this);
|
||||
if (l <= 0.0) {
|
||||
res.copy(v1);
|
||||
} else if (l >= 1.0) {
|
||||
res.copy(v2);
|
||||
} else {
|
||||
res = og.math.Vector2.add(v1, og.math.Vector2.sub(v2, v1).scale(l));
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Vector2.LERP_DELTA = 1e-6;
|
||||
|
||||
og.math.Vector2.prototype.slerp = function (v1, v2, t) {
|
||||
var res = new og.math.Vector2();
|
||||
|
||||
if (t <= 0.0) {
|
||||
res.copy(v1);
|
||||
return;
|
||||
} else if (t >= 1.0) {
|
||||
res.copy(v2);
|
||||
return;
|
||||
}
|
||||
|
||||
var omega, sinom, scale0, scale1;
|
||||
var cosom = v1.dot(v2);
|
||||
|
||||
if ((1.0 - cosom) > Vector2.LERP_DELTA) {
|
||||
omega = Math.acos(cosom);
|
||||
sinom = Math.sin(omega);
|
||||
scale0 = Math.sin((1.0 - t) * omega) / sinom;
|
||||
scale1 = Math.sin(t * omega) / sinom;
|
||||
} else {
|
||||
scale0 = 1.0 - t;
|
||||
scale1 = t;
|
||||
}
|
||||
|
||||
return og.math.Vector2.add(v1.scale(scale0), v2.scale(scale1));
|
||||
};
|
||||
|
||||
og.math.Vector2.orthoNormalize = function (normal, tangent) {
|
||||
normal = normal.normal();
|
||||
normal.scale(tangent.dot(normal));
|
||||
return tangent.sub(normal).normalize();
|
||||
goog.provide('og.math.Vector2');
|
||||
|
||||
goog.require('og.math.Vector3');
|
||||
|
||||
og.math.Vector2 = function (x, y) {
|
||||
this.x = x || 0.0;
|
||||
this.y = y || 0.0;
|
||||
}
|
||||
|
||||
og.math.Vector2.prototype.toVector3 = function () {
|
||||
return new og.math.Vector3(this.x, this.y, 0);
|
||||
};
|
||||
|
||||
og.math.Vector2.UP = new og.math.Vector2(0, 1);
|
||||
og.math.Vector2.DOWN = new og.math.Vector2(0, -1);
|
||||
og.math.Vector2.RIGHT = new og.math.Vector2(1, 0);
|
||||
og.math.Vector2.LEFT = new og.math.Vector2(-1, 0);
|
||||
og.math.Vector2.ZERO = new og.math.Vector2();
|
||||
|
||||
og.math.Vector2.prototype.clone = function () {
|
||||
return new og.math.Vector2(this.x, this.y);
|
||||
};
|
||||
|
||||
og.math.Vector2.add = function (a, b) {
|
||||
var res = new og.math.Vector2(a.x, a.y);
|
||||
res.add(b);
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Vector2.sub = function (a, b) {
|
||||
var res = new og.math.Vector2(a.x, a.y);
|
||||
res.sub(b);
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Vector2.scale = function (a, scale) {
|
||||
var res = new og.math.Vector2(a.x, a.y);
|
||||
res.scale(scale)
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Vector2.mull = function (a, b) {
|
||||
var res = new og.math.Vector2(a.x, a.y);
|
||||
res.mull(b);
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Vector2.div = function (a, b) {
|
||||
var res = new og.math.Vector2(a.x, a.y);
|
||||
res.div(b);
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.equal = function (p) {
|
||||
return this.x === p.x && this.y === p.y;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.copy = function (point2) {
|
||||
this.x = point2.x;
|
||||
this.y = point2.y;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.length = function () {
|
||||
return Math.sqrt(this.x * this.x + this.y * this.y);
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.length2 = function () {
|
||||
return this.x * this.x + this.y * this.y;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.add = function (v) {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.sub = function (v) {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.scale = function (scale) {
|
||||
this.x *= scale;
|
||||
this.y *= scale;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.scaleTo = function (scale) {
|
||||
return new og.math.Vector2(this.x * scale, this.y * scale);
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.mull = function (vec) {
|
||||
this.x *= vec.x;
|
||||
this.y *= vec.y;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.div = function (vec) {
|
||||
this.x /= vec.x;
|
||||
this.y /= vec.y;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.dot = function (v) {
|
||||
return v.x * this.x + v.y * this.y + v.z * this.z;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.dotArr = function (arr) {
|
||||
return arr[0] * this.x + arr[1] * this.y;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.cross = function (v) {
|
||||
return this.x * v.y - this.y * v.x;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.clear = function () {
|
||||
this.x = this.y = 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.normal = function () {
|
||||
var res = new og.math.Vector2();
|
||||
res.copy(this);
|
||||
|
||||
var length = 1.0 / res.length();
|
||||
|
||||
res.x *= length;
|
||||
res.y *= length;
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.normalize = function () {
|
||||
var length = 1.0 / this.length();
|
||||
|
||||
this.x *= length;
|
||||
this.y *= length;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.toVec = function () {
|
||||
var x = new og.math.GLArray(2);
|
||||
x[0] = this.x;
|
||||
x[1] = this.y;
|
||||
return x;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.distance = function (p) {
|
||||
var vec = og.math.Vector2.sub(this, p);
|
||||
return vec.length();
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.set = function (x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.negate = function () {
|
||||
this.x = -this.x;
|
||||
this.y = -this.y;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.getNegate = function () {
|
||||
return new og.math.Vector2(-this.x, -this.y);
|
||||
};
|
||||
|
||||
og.math.Vector2.proj_b_to_a = function (b, a) {
|
||||
return a.scaleTo(a.dot(b) / a.dot(a));
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.projToRay = function (pos, direction) {
|
||||
var v = og.math.Vector2.proj_b_to_a(og.math.Vector2.sub(this, pos), direction);
|
||||
v.add(pos);
|
||||
return v;
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.angle = function (a) {
|
||||
return og.math.Vector2.angle(this, a);
|
||||
};
|
||||
|
||||
og.math.Vector2.angle = function (a, b) {
|
||||
return Math.acos(a.dot(b) / Math.sqrt(a.length2() * b.length2()));
|
||||
};
|
||||
|
||||
og.math.Vector2.prototype.lerp = function (v1, v2, l) {
|
||||
var res = og.math.Vector2.clone(this);
|
||||
if (l <= 0.0) {
|
||||
res.copy(v1);
|
||||
} else if (l >= 1.0) {
|
||||
res.copy(v2);
|
||||
} else {
|
||||
res = og.math.Vector2.add(v1, og.math.Vector2.sub(v2, v1).scale(l));
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
og.math.Vector2.LERP_DELTA = 1e-6;
|
||||
|
||||
og.math.Vector2.prototype.slerp = function (v1, v2, t) {
|
||||
var res = new og.math.Vector2();
|
||||
|
||||
if (t <= 0.0) {
|
||||
res.copy(v1);
|
||||
return;
|
||||
} else if (t >= 1.0) {
|
||||
res.copy(v2);
|
||||
return;
|
||||
}
|
||||
|
||||
var omega, sinom, scale0, scale1;
|
||||
var cosom = v1.dot(v2);
|
||||
|
||||
if ((1.0 - cosom) > Vector2.LERP_DELTA) {
|
||||
omega = Math.acos(cosom);
|
||||
sinom = Math.sin(omega);
|
||||
scale0 = Math.sin((1.0 - t) * omega) / sinom;
|
||||
scale1 = Math.sin(t * omega) / sinom;
|
||||
} else {
|
||||
scale0 = 1.0 - t;
|
||||
scale1 = t;
|
||||
}
|
||||
|
||||
return og.math.Vector2.add(v1.scale(scale0), v2.scale(scale1));
|
||||
};
|
||||
|
||||
og.math.Vector2.orthoNormalize = function (normal, tangent) {
|
||||
normal = normal.normal();
|
||||
normal.scale(tangent.dot(normal));
|
||||
return tangent.sub(normal).normalize();
|
||||
};
|
||||
@ -1,109 +1,109 @@
|
||||
goog.provide('og.math.Vector4');
|
||||
|
||||
goog.require('og.math.Vector3');
|
||||
goog.require('og.math');
|
||||
|
||||
og.math.Vector4 = function (x, y, z, w) {
|
||||
this.x = x || 0.0;
|
||||
this.y = y || 0.0;
|
||||
this.z = z || 0.0;
|
||||
this.w = w || 0.0;
|
||||
};
|
||||
|
||||
og.math.Vector4.identity = new og.math.Vector4(0, 0, 0, 1);
|
||||
|
||||
og.math.Vector4.prototype.toVector3 = function () {
|
||||
return new og.math.Vector3(this.x, this.y, this.z);
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.clone = function (v) {
|
||||
return new og.math.Vector4(this.x, this.y, this.z, this.w);
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.equal = function (v) {
|
||||
return this.x === v.x && this.y === v.y && this.z === v.z && this.w === v.w;
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.copy = function (v) {
|
||||
this.x = v.x;
|
||||
this.y = v.y;
|
||||
this.z = v.z;
|
||||
this.w = v.w;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.toVec = function () {
|
||||
var x = new og.math.GLArray(4);
|
||||
x[0] = this.x;
|
||||
x[1] = this.y;
|
||||
x[2] = this.z;
|
||||
x[3] = this.w;
|
||||
return x;
|
||||
};
|
||||
|
||||
og.math.Vector4.fromVec = function (arr) {
|
||||
return new og.math.Vector4(arr[0], arr[1], arr[2], arr[3]);
|
||||
}
|
||||
|
||||
og.math.Vector4.prototype.set = function (x, y, z, w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.add = function (v) {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
this.z += v.z;
|
||||
this.w += v.w;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.sub = function (v) {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
this.z -= v.z;
|
||||
this.w -= v.w;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.scale = function (scale) {
|
||||
this.x *= scale;
|
||||
this.y *= scale;
|
||||
this.z *= scale;
|
||||
this.w *= scale;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.affinity = function () {
|
||||
var iw = 1 / this.w;
|
||||
this.x *= iw;
|
||||
this.y *= iw;
|
||||
this.z *= iw;
|
||||
this.w = 1.0;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.scaleTo = function (scale) {
|
||||
return new og.math.Vector4(this.x * scale, this.y * scale, this.z * scale, this.w * scale);
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.getStep = function (edge) {
|
||||
return new og.math.Vector4(
|
||||
this.x < edge ? 0.0 : 1.0,
|
||||
this.y < edge ? 0.0 : 1.0,
|
||||
this.z < edge ? 0.0 : 1.0,
|
||||
this.w < edge ? 0.0 : 1.0
|
||||
);
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.getFrac = function (v) {
|
||||
return new og.math.Vector4(
|
||||
og.math.frac(v.x),
|
||||
og.math.frac(v.y),
|
||||
og.math.frac(v.z),
|
||||
og.math.frac(v.w)
|
||||
);
|
||||
goog.provide('og.math.Vector4');
|
||||
|
||||
goog.require('og.math.Vector3');
|
||||
goog.require('og.math');
|
||||
|
||||
og.math.Vector4 = function (x, y, z, w) {
|
||||
this.x = x || 0.0;
|
||||
this.y = y || 0.0;
|
||||
this.z = z || 0.0;
|
||||
this.w = w || 0.0;
|
||||
};
|
||||
|
||||
og.math.Vector4.identity = new og.math.Vector4(0, 0, 0, 1);
|
||||
|
||||
og.math.Vector4.prototype.toVector3 = function () {
|
||||
return new og.math.Vector3(this.x, this.y, this.z);
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.clone = function (v) {
|
||||
return new og.math.Vector4(this.x, this.y, this.z, this.w);
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.equal = function (v) {
|
||||
return this.x === v.x && this.y === v.y && this.z === v.z && this.w === v.w;
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.copy = function (v) {
|
||||
this.x = v.x;
|
||||
this.y = v.y;
|
||||
this.z = v.z;
|
||||
this.w = v.w;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.toVec = function () {
|
||||
var x = new og.math.GLArray(4);
|
||||
x[0] = this.x;
|
||||
x[1] = this.y;
|
||||
x[2] = this.z;
|
||||
x[3] = this.w;
|
||||
return x;
|
||||
};
|
||||
|
||||
og.math.Vector4.fromVec = function (arr) {
|
||||
return new og.math.Vector4(arr[0], arr[1], arr[2], arr[3]);
|
||||
}
|
||||
|
||||
og.math.Vector4.prototype.set = function (x, y, z, w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.add = function (v) {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
this.z += v.z;
|
||||
this.w += v.w;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.sub = function (v) {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
this.z -= v.z;
|
||||
this.w -= v.w;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.scale = function (scale) {
|
||||
this.x *= scale;
|
||||
this.y *= scale;
|
||||
this.z *= scale;
|
||||
this.w *= scale;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.affinity = function () {
|
||||
var iw = 1 / this.w;
|
||||
this.x *= iw;
|
||||
this.y *= iw;
|
||||
this.z *= iw;
|
||||
this.w = 1.0;
|
||||
return this;
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.scaleTo = function (scale) {
|
||||
return new og.math.Vector4(this.x * scale, this.y * scale, this.z * scale, this.w * scale);
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.getStep = function (edge) {
|
||||
return new og.math.Vector4(
|
||||
this.x < edge ? 0.0 : 1.0,
|
||||
this.y < edge ? 0.0 : 1.0,
|
||||
this.z < edge ? 0.0 : 1.0,
|
||||
this.w < edge ? 0.0 : 1.0
|
||||
);
|
||||
};
|
||||
|
||||
og.math.Vector4.prototype.getFrac = function (v) {
|
||||
return new og.math.Vector4(
|
||||
og.math.frac(v.x),
|
||||
og.math.frac(v.y),
|
||||
og.math.frac(v.z),
|
||||
og.math.frac(v.w)
|
||||
);
|
||||
};
|
||||
@ -1,50 +1,50 @@
|
||||
goog.provide('og.node.Axes');
|
||||
|
||||
|
||||
goog.require('og.inheritance');
|
||||
goog.require('og.node.RenderNode');
|
||||
|
||||
og.node.Axes = function (size) {
|
||||
og.inheritance.base(this, "Axes");
|
||||
this.size = size;
|
||||
this.axesBuffer;
|
||||
this.axesColorBuffer;
|
||||
};
|
||||
|
||||
og.inheritance.extend(og.node.Axes, og.node.RenderNode);
|
||||
|
||||
og.node.Axes.prototype.initialization = function () {
|
||||
this.createAxisBuffer(this.size);
|
||||
this.drawMode = this.renderer.handler.gl.LINES;
|
||||
};
|
||||
|
||||
og.node.Axes.prototype.frame = function () {
|
||||
|
||||
this.renderer.handler.shaderPrograms.flat.activate();
|
||||
|
||||
this.renderer.handler.shaderPrograms.flat.set({
|
||||
uPMVMatrix: this.renderer.activeCamera.pmvMatrix._m,
|
||||
aVertexPosition: this.axisBuffer,
|
||||
aVertexColor: this.axisColorBuffer
|
||||
});
|
||||
|
||||
this.renderer.handler.shaderPrograms.flat.drawArray(this.drawMode, this.axisBuffer.numItems);
|
||||
};
|
||||
|
||||
og.node.Axes.prototype.createAxisBuffer = function (gridSize) {
|
||||
|
||||
var vertices = [
|
||||
0.0, 0.0, 0.0, gridSize - 1, 0.0, 0.0, // x - R
|
||||
0.0, 0.0, 0.0, 0.0, gridSize - 1, 0.0, // y - B
|
||||
0.0, 0.0, 0.0, 0.0, 0.0, gridSize - 1 // z - G
|
||||
];
|
||||
|
||||
var colors = [
|
||||
1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, // x - R
|
||||
0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, // y - B
|
||||
0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, // z - G
|
||||
];
|
||||
|
||||
this.axisBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(vertices), 3, 6);
|
||||
this.axisColorBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(colors), 4, 6);
|
||||
goog.provide('og.node.Axes');
|
||||
|
||||
|
||||
goog.require('og.inheritance');
|
||||
goog.require('og.node.RenderNode');
|
||||
|
||||
og.node.Axes = function (size) {
|
||||
og.inheritance.base(this, "Axes");
|
||||
this.size = size;
|
||||
this.axesBuffer;
|
||||
this.axesColorBuffer;
|
||||
};
|
||||
|
||||
og.inheritance.extend(og.node.Axes, og.node.RenderNode);
|
||||
|
||||
og.node.Axes.prototype.initialization = function () {
|
||||
this.createAxisBuffer(this.size);
|
||||
this.drawMode = this.renderer.handler.gl.LINES;
|
||||
};
|
||||
|
||||
og.node.Axes.prototype.frame = function () {
|
||||
|
||||
this.renderer.handler.shaderPrograms.flat.activate();
|
||||
|
||||
this.renderer.handler.shaderPrograms.flat.set({
|
||||
uPMVMatrix: this.renderer.activeCamera.pmvMatrix._m,
|
||||
aVertexPosition: this.axisBuffer,
|
||||
aVertexColor: this.axisColorBuffer
|
||||
});
|
||||
|
||||
this.renderer.handler.shaderPrograms.flat.drawArray(this.drawMode, this.axisBuffer.numItems);
|
||||
};
|
||||
|
||||
og.node.Axes.prototype.createAxisBuffer = function (gridSize) {
|
||||
|
||||
var vertices = [
|
||||
0.0, 0.0, 0.0, gridSize - 1, 0.0, 0.0, // x - R
|
||||
0.0, 0.0, 0.0, 0.0, gridSize - 1, 0.0, // y - B
|
||||
0.0, 0.0, 0.0, 0.0, 0.0, gridSize - 1 // z - G
|
||||
];
|
||||
|
||||
var colors = [
|
||||
1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, // x - R
|
||||
0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, // y - B
|
||||
0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, // z - G
|
||||
];
|
||||
|
||||
this.axisBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(vertices), 3, 6);
|
||||
this.axisColorBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(colors), 4, 6);
|
||||
};
|
||||
@ -1,102 +1,102 @@
|
||||
// This file was autogenerated by D:\my projects\closure-library\closure\bin\build\depswriter.py.
|
||||
// This file was autogenerated by depswriter.py.
|
||||
// Please do not edit.
|
||||
goog.addDependency('../../../og/src/og/ajax.js', ['og.Ajax'], []);
|
||||
goog.addDependency('../../../og/src/og/bv/box.js', ['og.bv.Box'], ['og.bv', 'og.math.Vector3']);
|
||||
goog.addDependency('../../../og/src/og/bv/bv.js', ['og.bv'], ['og.Extent', 'og.LonLat', 'og.math']);
|
||||
goog.addDependency('../../../og/src/og/bv/sphere.js', ['og.bv.Sphere'], ['og.bv', 'og.math.Vector3']);
|
||||
goog.addDependency('../../../og/src/og/camera/camera.js', ['og.Camera'], ['og.Events', 'og.Frustum', 'og.math', 'og.math.Matrix4', 'og.math.Pixel', 'og.math.Vector3']);
|
||||
goog.addDependency('../../../og/src/og/camera/planetCamera.js', ['og.PlanetCamera'], ['og.Camera', 'og.inheritance', 'og.math.Vector3']);
|
||||
goog.addDependency('../../../og/src/og/control/control.js', ['og.control.Control'], []);
|
||||
goog.addDependency('../../../og/src/og/control/keyboardNavigation.js', ['og.control.KeyboardNavigation'], ['og.control.Control', 'og.inheritance', 'og.input']);
|
||||
goog.addDependency('../../../og/src/og/control/layerSwitcher.js', ['og.control.LayerSwitcher'], ['og.inheritance']);
|
||||
goog.addDependency('../../../og/src/og/control/loadingSpinner.js', ['og.control.LoadingSpinner'], ['og.control.Control', 'og.inheritance']);
|
||||
goog.addDependency('../../../og/src/og/control/mouseNavigation.js', ['og.control.MouseNavigation'], ['og.bv.Sphere', 'og.control.Control', 'og.inheritance', 'og.math', 'og.math.Matrix4', 'og.math.Quaternion', 'og.math.Ray', 'og.math.Vector3']);
|
||||
goog.addDependency('../../../og/src/og/control/mousePosition.js', ['og.control.MousePosition'], ['og.control.Control', 'og.inheritance', 'og.mercator', 'og.planetSegment']);
|
||||
goog.addDependency('../../../og/src/og/control/showFps.js', ['og.control.ShowFps'], ['og.control.Control', 'og.inheritance']);
|
||||
goog.addDependency('../../../og/src/og/control/simpleNavigation.js', ['og.control.SimpleNavigation'], ['og.control.Control', 'og.inheritance', 'og.input']);
|
||||
goog.addDependency('../../../og/src/og/control/toggleWireframe.js', ['og.control.ToggleWireframe'], ['og.inheritance', 'og.input', 'og.webgl']);
|
||||
goog.addDependency('../../../og/src/og/control/touchNavigation.js', ['og.control.TouchNavigation'], ['og.bv.Sphere', 'og.control.Control', 'og.inheritance', 'og.math', 'og.math.Matrix4', 'og.math.Pixel', 'og.math.Quaternion', 'og.math.Ray', 'og.math.Vector3']);
|
||||
goog.addDependency('../../../og/src/og/control/zoomControl.js', ['og.control.ZoomControl'], ['og.control.Control', 'og.control.MouseNavigation', 'og.inheritance']);
|
||||
goog.addDependency('../../../og/src/og/ellipsoid/ellipsoid.js', ['og.Ellipsoid'], ['og.LonLat', 'og.math', 'og.math.Vector3']);
|
||||
goog.addDependency('../../../og/src/og/ellipsoid/wgs84ellipsoid.js', ['og.ellipsoid.wgs84'], ['og.Ellipsoid']);
|
||||
goog.addDependency('../../../og/src/og/entity/baseBillboard.js', ['og.BaseBillboard'], ['og.math.Vector3', 'og.math.Vector4']);
|
||||
goog.addDependency('../../../og/src/og/entity/billboard.js', ['og.Billboard'], ['og.BaseBillboard', 'og.inheritance', 'og.math.Vector2']);
|
||||
goog.addDependency('../../../og/src/og/entity/billboardHandler.js', ['og.BillboardHandler'], ['og.shaderProgram.billboard']);
|
||||
goog.addDependency('../../../og/src/og/entity/entity.js', ['og.Entity'], ['og.Billboard', 'og.Label', 'og.math.Vector3']);
|
||||
goog.addDependency('../../../og/src/og/entity/entityCollection.js', ['og.EntityCollection'], ['og.BillboardHandler', 'og.LabelHandler']);
|
||||
goog.addDependency('../../../og/src/og/entity/label.js', ['og.Label'], ['og.BaseBillboard', 'og.inheritance']);
|
||||
goog.addDependency('../../../og/src/og/entity/labelHandler.js', ['og.LabelHandler'], ['og.BillboardHandler', 'og.inheritance', 'og.shaderProgram.label']);
|
||||
goog.addDependency('../../../og/src/og/events/events.js', ['og.Events'], []);
|
||||
goog.addDependency('../../../og/src/og/extent/extent.js', ['og.Extent'], ['og.LonLat', 'og.math']);
|
||||
goog.addDependency('../../../og/src/og/frustum.js', ['og.Frustum'], []);
|
||||
goog.addDependency('../../../og/src/og/geoImage.js', ['og.GeoImage'], ['og.Extent', 'og.LonLat', 'og.mercator']);
|
||||
goog.addDependency('../../../og/src/og/globus.js', ['og.Globus'], ['og.Renderer', 'og.ellipsoid.wgs84', 'og.node.Planet', 'og.terrainProvider.EmptyTerrainProvider', 'og.webgl.Handler']);
|
||||
goog.addDependency('../../../og/src/og/imageCanvas/imageCanvas.js', ['og.ImageCanvas'], []);
|
||||
goog.addDependency('../../../og/src/og/inheritance.js', ['og.inheritance'], []);
|
||||
goog.addDependency('../../../og/src/og/input/input.js', ['og.input'], []);
|
||||
goog.addDependency('../../../og/src/og/input/keyboardHandler.js', ['og.input.KeyboardHandler'], []);
|
||||
goog.addDependency('../../../og/src/og/input/mouseHandler.js', ['og.input.MouseHandler'], []);
|
||||
goog.addDependency('../../../og/src/og/input/touchHandler.js', ['og.input.TouchHandler'], []);
|
||||
goog.addDependency('../../../og/src/og/layer/canvasTiles.js', ['og.layer.CanvasTiles'], ['og.ImageCanvas', 'og.inheritance', 'og.layer.Layer']);
|
||||
goog.addDependency('../../../og/src/og/layer/layer.js', ['og.layer', 'og.layer.Layer'], ['og.Events', 'og.QueueArray']);
|
||||
goog.addDependency('../../../og/src/og/layer/wms.js', ['og.layer.WMS'], ['og.inheritance', 'og.layer.XYZ']);
|
||||
goog.addDependency('../../../og/src/og/layer/xyz.js', ['og.layer.XYZ'], ['og.inheritance', 'og.layer.Layer', 'og.proj.EPSG3857', 'og.quadTree']);
|
||||
goog.addDependency('../../../og/src/og/light/pointLight.js', ['og.light.PointLight'], ['og.math.Vector3']);
|
||||
goog.addDependency('../../../og/src/og/lonlat.js', ['og.LonLat'], ['og.mercator']);
|
||||
goog.addDependency('../../../og/src/og/math/coder.js', ['og.math.coder'], ['og.math', 'og.math.Vector4']);
|
||||
goog.addDependency('../../../og/src/og/math/math.js', ['og.math'], []);
|
||||
goog.addDependency('../../../og/src/og/math/matrix3.js', ['og.math.Matrix3'], ['og.math', 'og.math.Vector3']);
|
||||
goog.addDependency('../../../og/src/og/math/matrix4.js', ['og.math.Matrix4'], ['og.math', 'og.math.Matrix3', 'og.math.Vector3', 'og.math.Vector4']);
|
||||
goog.addDependency('../../../og/src/og/math/pixel.js', ['og.math.Pixel'], []);
|
||||
goog.addDependency('../../../og/src/og/math/quaternion.js', ['og.math.Quaternion'], ['og.math', 'og.math.Matrix4']);
|
||||
goog.addDependency('../../../og/src/og/math/ray.js', ['og.math.Ray'], ['og.math.Vector3']);
|
||||
goog.addDependency('../../../og/src/og/math/vector2.js', ['og.math.Vector2'], ['og.math.Vector3']);
|
||||
goog.addDependency('../../../og/src/og/math/vector3.js', ['og.math.Vector3'], []);
|
||||
goog.addDependency('../../../og/src/og/math/vector4.js', ['og.math.Vector4'], ['og.math', 'og.math.Vector3']);
|
||||
goog.addDependency('../../../og/src/og/mercator.js', ['og.mercator'], []);
|
||||
goog.addDependency('../../../og/src/og/node/axes.js', ['og.node.Axes'], ['og.inheritance', 'og.node.RenderNode']);
|
||||
goog.addDependency('../../../og/src/og/node/node.js', ['og.node.Node'], []);
|
||||
goog.addDependency('../../../og/src/og/node/planet.js', ['og.node.Planet'], ['og.Events', 'og.Extent', 'og.ImageCanvas', 'og.PlanetCamera', 'og.bv.Sphere', 'og.inheritance', 'og.layer', 'og.light.PointLight', '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.PlanetSegmentHelper', 'og.planetSegment.Wgs84PlanetSegment', 'og.proj.EPSG4326', 'og.quadTree', 'og.quadTree.QuadNode', 'og.shaderProgram.overlays_nl', 'og.shaderProgram.overlays_wl', 'og.shaderProgram.picking', 'og.shaderProgram.single_nl', 'og.shaderProgram.single_wl', 'og.webgl.Framebuffer']);
|
||||
goog.addDependency('../../../og/src/og/node/renderNode.js', ['og.node.RenderNode'], ['og.inheritance', 'og.math.Matrix4', 'og.math.Vector3', 'og.node.Node', 'og.utils.FontAtlas', 'og.utils.TextureAtlas', 'og.webgl']);
|
||||
goog.addDependency('../../../og/src/og/node/skyBox.js', ['og.node.SkyBox'], ['og.inheritance', 'og.node.RenderNode', 'og.shaderProgram.skybox']);
|
||||
goog.addDependency('../../../og/src/og/node/skySphere.js', ['og.node.SkySphere'], ['og.inheritance', 'og.node.RenderNode', 'og.shaderProgram.skysphere']);
|
||||
goog.addDependency('../../../og/src/og/og.js', ['og'], []);
|
||||
goog.addDependency('../../../og/src/og/planetSegment/GeoImageTileCreatorQueue.js', ['og.planetSegment.GeoImageTileCreatorQueue'], ['og.QueueArray', 'og.inheritance', 'og.utils.GeoImageTileCreator']);
|
||||
goog.addDependency('../../../og/src/og/planetSegment/NormalMapCreatorQueue.js', ['og.planetSegment.NormalMapCreatorQueue'], ['og.QueueArray', 'og.inheritance', 'og.utils.NormalMapCreator']);
|
||||
goog.addDependency('../../../og/src/og/planetSegment/planetSegment.js', ['og.planetSegment', 'og.planetSegment.PlanetSegment'], ['og.Extent', 'og.LonLat', 'og.bv.Box', 'og.bv.Sphere', 'og.layer', 'og.math', 'og.math.Vector3', 'og.mercator', 'og.planetSegment.PlanetSegmentHelper', 'og.proj.EPSG3857']);
|
||||
goog.addDependency('../../../og/src/og/planetSegment/planetSegmentHelper.js', ['og.planetSegment.PlanetSegmentHelper'], ['og.quadTree']);
|
||||
goog.addDependency('../../../og/src/og/planetSegment/planetSegmentMaterial.js', ['og.planetSegment.PlanetSegmentMaterial'], []);
|
||||
goog.addDependency('../../../og/src/og/planetSegment/wgs84planetSegment.js', ['og.planetSegment.Wgs84PlanetSegment'], ['og.LonLat', 'og.inheritance', 'og.planetSegment.PlanetSegment', 'og.proj.EPSG4326']);
|
||||
goog.addDependency('../../../og/src/og/proj/epsg3857.js', ['og.proj.EPSG3857'], ['og.Units', 'og.proj.Projection']);
|
||||
goog.addDependency('../../../og/src/og/proj/epsg4326.js', ['og.proj.EPSG4326'], ['og.Units', 'og.proj.Projection']);
|
||||
goog.addDependency('../../../og/src/og/proj/proj.js', ['og.Units', 'og.proj', 'og.proj.METERS_PER_UNIT', 'og.proj.Projection'], []);
|
||||
goog.addDependency('../../../og/src/og/quadTree/quadNode.js', ['og.quadTree.QuadNode'], ['og.Extent', 'og.LonLat', 'og.mercator', 'og.planetSegment.PlanetSegmentMaterial', 'og.proj.EPSG4326', 'og.quadTree']);
|
||||
goog.addDependency('../../../og/src/og/quadTree/quadTree.js', ['og.quadTree'], []);
|
||||
goog.addDependency('../../../og/src/og/queueArray.js', ['og.QueueArray'], []);
|
||||
goog.addDependency('../../../og/src/og/rectangle.js', ['og.Rectangle'], []);
|
||||
goog.addDependency('../../../og/src/og/renderer/renderer.js', ['og.Renderer'], ['og.Camera', 'og.RendererEvents', 'og.math.Pixel', 'og.math.Vector3']);
|
||||
goog.addDependency('../../../og/src/og/renderer/rendererEvents.js', ['og.RendererEvents'], ['og.Events', 'og.inheritance', 'og.input', 'og.input.KeyboardHandler', 'og.input.MouseHandler', 'og.input.TouchHandler']);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/billboard.js', ['og.shaderProgram.billboard'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types', 'og.utils']);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/callbacks.js', ['og.shaderProgram.callbacks'], ['og.shaderProgram.types']);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/label.js', ['og.shaderProgram.label'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types', 'og.utils']);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/overlays.js', ['og.shaderProgram.overlays_nl', 'og.shaderProgram.overlays_wl'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types', 'og.utils']);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/picking.js', ['og.shaderProgram.picking'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types']);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/shaderProgram.js', ['og.shaderProgram', 'og.shaderProgram.ShaderProgram'], ['og.shaderProgram.callbacks']);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/shape.js', ['og.shaderProgram.shape_nl', 'og.shaderProgram.shape_wl'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types', 'og.utils']);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/single.js', ['og.shaderProgram.single_nl', 'og.shaderProgram.single_wl'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types']);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/skybox.js', ['og.shaderProgram.skybox'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types', 'og.utils']);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/skysphere.js', ['og.shaderProgram.skysphere'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types', 'og.utils']);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/types.js', ['og.shaderProgram.types'], []);
|
||||
goog.addDependency('../../../og/src/og/shapes/baseShape.js', ['og.shapes.BaseShape'], ['og.math.Matrix4', 'og.math.Quaternion', 'og.math.Vector3']);
|
||||
goog.addDependency('../../../og/src/og/shapes/sphere.js', ['og.shapes.Sphere'], ['og.shapes.BaseShape']);
|
||||
goog.addDependency('../../../og/src/og/terrainProvider/terrainProvider.js', ['og.terrainProvider.EmptyTerrainProvider', 'og.terrainProvider.TerrainProvider'], ['og.Ajax', 'og.Events', 'og.QueueArray', 'og.inheritance', 'og.layer', 'og.proj.EPSG3857', 'og.quadTree']);
|
||||
goog.addDependency('../../../og/src/og/utils/fontAtlas.js', ['og.utils.FontAtlas'], ['og.ImageCanvas', 'og.math', 'og.utils.TextureAtlas']);
|
||||
goog.addDependency('../../../og/src/og/utils/geoImageTileCreator.js', ['og.utils.GeoImageTileCreator'], ['og.shaderProgram.ShaderProgram', 'og.webgl.Framebuffer', 'og.webgl.Handler']);
|
||||
goog.addDependency('../../../og/src/og/utils/imagesCacheManager.js', ['og.utils.ImagesCacheManager'], ['og.QueueArray']);
|
||||
goog.addDependency('../../../og/src/og/utils/normalMapCreator.js', ['og.utils.NormalMapCreator'], ['og.planetSegment.PlanetSegmentHelper', 'og.shaderProgram.ShaderProgram', 'og.webgl.Framebuffer', 'og.webgl.Handler']);
|
||||
goog.addDependency('../../../og/src/og/utils/textureAtlas.js', ['og.utils.TextureAtlas', 'og.utils.TextureAtlasNode'], ['og.ImageCanvas', 'og.Rectangle', 'og.utils.ImagesCacheManager']);
|
||||
goog.addDependency('../../../og/src/og/utils/utils.js', ['og.utils'], ['og.Ajax']);
|
||||
goog.addDependency('../../../og/src/og/webgl/framebuffer.js', ['og.webgl.Framebuffer'], ['og.ImageCanvas', 'og.webgl']);
|
||||
goog.addDependency('../../../og/src/og/webgl/handler.js', ['og.webgl.Handler'], ['og.ImageCanvas', 'og.math', 'og.webgl', 'og.webgl.ShaderController']);
|
||||
goog.addDependency('../../../og/src/og/webgl/shaderController.js', ['og.webgl.ShaderController'], []);
|
||||
goog.addDependency('../../../og/src/og/webgl/webgl.js', ['og.webgl'], ['og.utils']);
|
||||
goog.addDependency('../../../og/src/og/ajax.js', ['og.Ajax'], [], false);
|
||||
goog.addDependency('../../../og/src/og/bv/box.js', ['og.bv.Box'], ['og.bv', 'og.math.Vector3'], false);
|
||||
goog.addDependency('../../../og/src/og/bv/bv.js', ['og.bv'], ['og.Extent', 'og.LonLat', 'og.math'], false);
|
||||
goog.addDependency('../../../og/src/og/bv/sphere.js', ['og.bv.Sphere'], ['og.bv', 'og.math.Vector3'], false);
|
||||
goog.addDependency('../../../og/src/og/camera/camera.js', ['og.Camera'], ['og.Events', 'og.Frustum', 'og.math', 'og.math.Matrix4', 'og.math.Pixel', 'og.math.Vector3'], false);
|
||||
goog.addDependency('../../../og/src/og/camera/planetCamera.js', ['og.PlanetCamera'], ['og.Camera', 'og.inheritance', 'og.math.Vector3'], false);
|
||||
goog.addDependency('../../../og/src/og/control/control.js', ['og.control.Control'], [], false);
|
||||
goog.addDependency('../../../og/src/og/control/keyboardNavigation.js', ['og.control.KeyboardNavigation'], ['og.control.Control', 'og.inheritance', 'og.input'], false);
|
||||
goog.addDependency('../../../og/src/og/control/layerSwitcher.js', ['og.control.LayerSwitcher'], ['og.inheritance'], false);
|
||||
goog.addDependency('../../../og/src/og/control/loadingSpinner.js', ['og.control.LoadingSpinner'], ['og.control.Control', 'og.inheritance'], false);
|
||||
goog.addDependency('../../../og/src/og/control/mouseNavigation.js', ['og.control.MouseNavigation'], ['og.bv.Sphere', 'og.control.Control', 'og.inheritance', 'og.math', 'og.math.Matrix4', 'og.math.Quaternion', 'og.math.Ray', 'og.math.Vector3'], false);
|
||||
goog.addDependency('../../../og/src/og/control/mousePosition.js', ['og.control.MousePosition'], ['og.control.Control', 'og.inheritance', 'og.mercator', 'og.planetSegment'], false);
|
||||
goog.addDependency('../../../og/src/og/control/showFps.js', ['og.control.ShowFps'], ['og.control.Control', 'og.inheritance'], false);
|
||||
goog.addDependency('../../../og/src/og/control/simpleNavigation.js', ['og.control.SimpleNavigation'], ['og.control.Control', 'og.inheritance', 'og.input'], 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.Control', '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.Control', 'og.control.MouseNavigation', 'og.inheritance'], false);
|
||||
goog.addDependency('../../../og/src/og/ellipsoid/ellipsoid.js', ['og.Ellipsoid'], ['og.LonLat', 'og.math', 'og.math.Vector3'], false);
|
||||
goog.addDependency('../../../og/src/og/ellipsoid/wgs84ellipsoid.js', ['og.ellipsoid.wgs84'], ['og.Ellipsoid'], false);
|
||||
goog.addDependency('../../../og/src/og/entity/baseBillboard.js', ['og.BaseBillboard'], ['og.math.Vector3', 'og.math.Vector4'], false);
|
||||
goog.addDependency('../../../og/src/og/entity/billboard.js', ['og.Billboard'], ['og.BaseBillboard', 'og.inheritance', 'og.math.Vector2'], false);
|
||||
goog.addDependency('../../../og/src/og/entity/billboardHandler.js', ['og.BillboardHandler'], ['og.shaderProgram.billboard'], false);
|
||||
goog.addDependency('../../../og/src/og/entity/entity.js', ['og.Entity'], ['og.Billboard', 'og.Label', 'og.math.Vector3'], false);
|
||||
goog.addDependency('../../../og/src/og/entity/entityCollection.js', ['og.EntityCollection'], ['og.BillboardHandler', 'og.LabelHandler'], false);
|
||||
goog.addDependency('../../../og/src/og/entity/label.js', ['og.Label'], ['og.BaseBillboard', 'og.inheritance'], false);
|
||||
goog.addDependency('../../../og/src/og/entity/labelHandler.js', ['og.LabelHandler'], ['og.BillboardHandler', 'og.inheritance', 'og.shaderProgram.label'], false);
|
||||
goog.addDependency('../../../og/src/og/events/events.js', ['og.Events'], [], false);
|
||||
goog.addDependency('../../../og/src/og/extent/extent.js', ['og.Extent'], ['og.LonLat', 'og.math'], false);
|
||||
goog.addDependency('../../../og/src/og/frustum.js', ['og.Frustum'], [], false);
|
||||
goog.addDependency('../../../og/src/og/geoImage.js', ['og.GeoImage'], ['og.Extent', 'og.LonLat', 'og.mercator'], false);
|
||||
goog.addDependency('../../../og/src/og/globus.js', ['og.Globus'], ['og.Renderer', 'og.ellipsoid.wgs84', 'og.node.Planet', 'og.terrainProvider.EmptyTerrainProvider', 'og.webgl.Handler'], false);
|
||||
goog.addDependency('../../../og/src/og/imageCanvas/imageCanvas.js', ['og.ImageCanvas'], [], false);
|
||||
goog.addDependency('../../../og/src/og/inheritance.js', ['og.inheritance'], [], false);
|
||||
goog.addDependency('../../../og/src/og/input/input.js', ['og.input'], [], false);
|
||||
goog.addDependency('../../../og/src/og/input/keyboardHandler.js', ['og.input.KeyboardHandler'], [], false);
|
||||
goog.addDependency('../../../og/src/og/input/mouseHandler.js', ['og.input.MouseHandler'], [], false);
|
||||
goog.addDependency('../../../og/src/og/input/touchHandler.js', ['og.input.TouchHandler'], [], false);
|
||||
goog.addDependency('../../../og/src/og/layer/canvasTiles.js', ['og.layer.CanvasTiles'], ['og.ImageCanvas', 'og.inheritance', 'og.layer.Layer'], false);
|
||||
goog.addDependency('../../../og/src/og/layer/layer.js', ['og.layer', 'og.layer.Layer'], ['og.Events', 'og.QueueArray'], 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'], false);
|
||||
goog.addDependency('../../../og/src/og/light/pointLight.js', ['og.light.PointLight'], ['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);
|
||||
goog.addDependency('../../../og/src/og/math/matrix3.js', ['og.math.Matrix3'], ['og.math', 'og.math.Vector3'], false);
|
||||
goog.addDependency('../../../og/src/og/math/matrix4.js', ['og.math.Matrix4'], ['og.math', 'og.math.Matrix3', 'og.math.Vector3', 'og.math.Vector4'], false);
|
||||
goog.addDependency('../../../og/src/og/math/pixel.js', ['og.math.Pixel'], [], false);
|
||||
goog.addDependency('../../../og/src/og/math/quaternion.js', ['og.math.Quaternion'], ['og.math', 'og.math.Matrix4'], false);
|
||||
goog.addDependency('../../../og/src/og/math/ray.js', ['og.math.Ray'], ['og.math.Vector3'], false);
|
||||
goog.addDependency('../../../og/src/og/math/vector2.js', ['og.math.Vector2'], ['og.math.Vector3'], false);
|
||||
goog.addDependency('../../../og/src/og/math/vector3.js', ['og.math.Vector3'], [], false);
|
||||
goog.addDependency('../../../og/src/og/math/vector4.js', ['og.math.Vector4'], ['og.math', 'og.math.Vector3'], false);
|
||||
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.Events', 'og.Extent', 'og.ImageCanvas', 'og.PlanetCamera', 'og.bv.Sphere', 'og.inheritance', 'og.layer', 'og.light.PointLight', '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.PlanetSegmentHelper', 'og.planetSegment.Wgs84PlanetSegment', 'og.proj.EPSG4326', 'og.quadTree', 'og.quadTree.QuadNode', 'og.shaderProgram.overlays_nl', 'og.shaderProgram.overlays_wl', 'og.shaderProgram.picking', 'og.shaderProgram.single_nl', 'og.shaderProgram.single_wl', 'og.webgl.Framebuffer'], false);
|
||||
goog.addDependency('../../../og/src/og/node/renderNode.js', ['og.node.RenderNode'], ['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);
|
||||
goog.addDependency('../../../og/src/og/node/skySphere.js', ['og.node.SkySphere'], ['og.inheritance', 'og.node.RenderNode', 'og.shaderProgram.skysphere'], false);
|
||||
goog.addDependency('../../../og/src/og/og.js', ['og'], [], false);
|
||||
goog.addDependency('../../../og/src/og/planetSegment/GeoImageTileCreatorQueue.js', ['og.planetSegment.GeoImageTileCreatorQueue'], ['og.QueueArray', 'og.inheritance', 'og.utils.GeoImageTileCreator'], false);
|
||||
goog.addDependency('../../../og/src/og/planetSegment/NormalMapCreatorQueue.js', ['og.planetSegment.NormalMapCreatorQueue'], ['og.QueueArray', 'og.inheritance', 'og.utils.NormalMapCreator'], false);
|
||||
goog.addDependency('../../../og/src/og/planetSegment/planetSegment.js', ['og.planetSegment', 'og.planetSegment.PlanetSegment'], ['og.Extent', 'og.LonLat', 'og.bv.Box', 'og.bv.Sphere', 'og.layer', 'og.math', 'og.math.Vector3', 'og.mercator', 'og.planetSegment.PlanetSegmentHelper', 'og.proj.EPSG3857'], false);
|
||||
goog.addDependency('../../../og/src/og/planetSegment/planetSegmentHelper.js', ['og.planetSegment.PlanetSegmentHelper'], ['og.quadTree'], false);
|
||||
goog.addDependency('../../../og/src/og/planetSegment/planetSegmentMaterial.js', ['og.planetSegment.PlanetSegmentMaterial'], [], false);
|
||||
goog.addDependency('../../../og/src/og/planetSegment/wgs84planetSegment.js', ['og.planetSegment.Wgs84PlanetSegment'], ['og.LonLat', 'og.inheritance', 'og.planetSegment.PlanetSegment', 'og.proj.EPSG4326'], false);
|
||||
goog.addDependency('../../../og/src/og/proj/epsg3857.js', ['og.proj.EPSG3857'], ['og.Units', 'og.proj.Projection'], false);
|
||||
goog.addDependency('../../../og/src/og/proj/epsg4326.js', ['og.proj.EPSG4326'], ['og.Units', 'og.proj.Projection'], false);
|
||||
goog.addDependency('../../../og/src/og/proj/proj.js', ['og.Units', 'og.proj', 'og.proj.METERS_PER_UNIT', 'og.proj.Projection'], [], false);
|
||||
goog.addDependency('../../../og/src/og/quadTree/quadNode.js', ['og.quadTree.QuadNode'], ['og.Extent', 'og.LonLat', 'og.mercator', 'og.planetSegment.PlanetSegmentMaterial', 'og.proj.EPSG4326', 'og.quadTree'], false);
|
||||
goog.addDependency('../../../og/src/og/quadTree/quadTree.js', ['og.quadTree'], [], false);
|
||||
goog.addDependency('../../../og/src/og/queueArray.js', ['og.QueueArray'], [], false);
|
||||
goog.addDependency('../../../og/src/og/rectangle.js', ['og.Rectangle'], [], false);
|
||||
goog.addDependency('../../../og/src/og/renderer/renderer.js', ['og.Renderer'], ['og.Camera', 'og.RendererEvents', 'og.math.Pixel', 'og.math.Vector3'], false);
|
||||
goog.addDependency('../../../og/src/og/renderer/rendererEvents.js', ['og.RendererEvents'], ['og.Events', 'og.inheritance', 'og.input', 'og.input.KeyboardHandler', 'og.input.MouseHandler', 'og.input.TouchHandler'], false);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/billboard.js', ['og.shaderProgram.billboard'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types', 'og.utils'], false);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/callbacks.js', ['og.shaderProgram.callbacks'], ['og.shaderProgram.types'], false);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/label.js', ['og.shaderProgram.label'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types', 'og.utils'], false);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/overlays.js', ['og.shaderProgram.overlays_nl', 'og.shaderProgram.overlays_wl'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types', 'og.utils'], false);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/picking.js', ['og.shaderProgram.picking'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types'], false);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/shaderProgram.js', ['og.shaderProgram', 'og.shaderProgram.ShaderProgram'], ['og.shaderProgram.callbacks'], false);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/shape.js', ['og.shaderProgram.shape_nl', 'og.shaderProgram.shape_wl'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types', 'og.utils'], false);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/single.js', ['og.shaderProgram.single_nl', 'og.shaderProgram.single_wl'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types'], false);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/skybox.js', ['og.shaderProgram.skybox'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types', 'og.utils'], false);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/skysphere.js', ['og.shaderProgram.skysphere'], ['og.shaderProgram', 'og.shaderProgram.ShaderProgram', 'og.shaderProgram.types', 'og.utils'], false);
|
||||
goog.addDependency('../../../og/src/og/shaderProgram/types.js', ['og.shaderProgram.types'], [], false);
|
||||
goog.addDependency('../../../og/src/og/shapes/baseShape.js', ['og.shapes.BaseShape'], ['og.math.Matrix4', 'og.math.Quaternion', 'og.math.Vector3'], false);
|
||||
goog.addDependency('../../../og/src/og/shapes/sphere.js', ['og.shapes.Sphere'], ['og.shapes.BaseShape'], false);
|
||||
goog.addDependency('../../../og/src/og/terrainProvider/terrainProvider.js', ['og.terrainProvider.EmptyTerrainProvider', 'og.terrainProvider.TerrainProvider'], ['og.Ajax', 'og.Events', 'og.QueueArray', 'og.inheritance', 'og.layer', 'og.proj.EPSG3857', 'og.quadTree'], false);
|
||||
goog.addDependency('../../../og/src/og/utils/fontAtlas.js', ['og.utils.FontAtlas'], ['og.ImageCanvas', 'og.math', 'og.utils.TextureAtlas'], false);
|
||||
goog.addDependency('../../../og/src/og/utils/geoImageTileCreator.js', ['og.utils.GeoImageTileCreator'], ['og.shaderProgram.ShaderProgram', 'og.webgl.Framebuffer', 'og.webgl.Handler'], false);
|
||||
goog.addDependency('../../../og/src/og/utils/imagesCacheManager.js', ['og.utils.ImagesCacheManager'], ['og.QueueArray'], false);
|
||||
goog.addDependency('../../../og/src/og/utils/normalMapCreator.js', ['og.utils.NormalMapCreator'], ['og.planetSegment.PlanetSegmentHelper', 'og.shaderProgram.ShaderProgram', 'og.webgl.Framebuffer', 'og.webgl.Handler'], false);
|
||||
goog.addDependency('../../../og/src/og/utils/textureAtlas.js', ['og.utils.TextureAtlas', 'og.utils.TextureAtlasNode'], ['og.ImageCanvas', 'og.Rectangle', 'og.utils.ImagesCacheManager'], false);
|
||||
goog.addDependency('../../../og/src/og/utils/utils.js', ['og.utils'], ['og.Ajax'], false);
|
||||
goog.addDependency('../../../og/src/og/webgl/framebuffer.js', ['og.webgl.Framebuffer'], ['og.ImageCanvas', 'og.webgl'], false);
|
||||
goog.addDependency('../../../og/src/og/webgl/handler.js', ['og.webgl.Handler'], ['og.ImageCanvas', 'og.math', 'og.webgl', 'og.webgl.ShaderController'], false);
|
||||
goog.addDependency('../../../og/src/og/webgl/shaderController.js', ['og.webgl.ShaderController'], [], false);
|
||||
goog.addDependency('../../../og/src/og/webgl/webgl.js', ['og.webgl'], ['og.utils'], false);
|
||||
|
||||
@ -1,208 +1,208 @@
|
||||
goog.provide('og.planetSegment.PlanetSegmentHelper');
|
||||
|
||||
goog.require('og.quadTree');
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.initIndexesTables = function (powerOfTwo) {
|
||||
if (powerOfTwo != og.planetSegment.PlanetSegmentHelper.powerOfTwo) {
|
||||
og.planetSegment.PlanetSegmentHelper.powerOfTwo = powerOfTwo;
|
||||
og.planetSegment.PlanetSegmentHelper.centerIndexesTable = og.planetSegment.PlanetSegmentHelper.initIndexBodiesTable(powerOfTwo);
|
||||
og.planetSegment.PlanetSegmentHelper.textureCoordsTable = og.planetSegment.PlanetSegmentHelper.initTextureCoordsTable(powerOfTwo);
|
||||
og.planetSegment.PlanetSegmentHelper.skirtsIndexesTable = og.planetSegment.PlanetSegmentHelper.initIndexesBodySkirts(powerOfTwo);
|
||||
}
|
||||
og.planetSegment.PlanetSegmentHelper.centerIndexesTable[0] = [];
|
||||
og.planetSegment.PlanetSegmentHelper.textureCoordsTable[0] = [];
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.createSegmentIndexes = function (size, sidesSizes) {
|
||||
if (size != 1) {
|
||||
var c = og.planetSegment.PlanetSegmentHelper.centerIndexesTable[size],
|
||||
w = og.planetSegment.PlanetSegmentHelper.skirtsIndexesTable[og.quadTree.W][size][sidesSizes[og.quadTree.W]],
|
||||
n = og.planetSegment.PlanetSegmentHelper.skirtsIndexesTable[og.quadTree.N][size][sidesSizes[og.quadTree.N]],
|
||||
e = og.planetSegment.PlanetSegmentHelper.skirtsIndexesTable[og.quadTree.E][size][sidesSizes[og.quadTree.E]],
|
||||
s = og.planetSegment.PlanetSegmentHelper.skirtsIndexesTable[og.quadTree.S][size][sidesSizes[og.quadTree.S]];
|
||||
var indexes = new Uint16Array(c.length + w.length + n.length + e.length + s.length);
|
||||
var k = 0, i = 0;
|
||||
for (k = 0; k < c.length; k++) {
|
||||
indexes[i++] = c[k];
|
||||
}
|
||||
for (k = 0; k < w.length; k++) {
|
||||
indexes[i++] = w[k];
|
||||
}
|
||||
for (k = 0; k < n.length; k++) {
|
||||
indexes[i++] = n[k];
|
||||
}
|
||||
for (k = 0; k < e.length; k++) {
|
||||
indexes[i++] = e[k];
|
||||
}
|
||||
for (k = 0; k < s.length; k++) {
|
||||
indexes[i++] = s[k];
|
||||
}
|
||||
return indexes;
|
||||
} else {
|
||||
return new Uint16Array([0, 2, 1, 3]);
|
||||
}
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.createCenterBodyIndexes = function (size, indexes) {
|
||||
|
||||
var i0 = 1,
|
||||
j0 = 1;
|
||||
|
||||
var i1 = 1,
|
||||
j1 = 1;
|
||||
|
||||
var ind1, ind2, nr;
|
||||
for (var i = i0; i < size - 1 - i1; i++) {
|
||||
for (var j = j0; j < size - j1; j++) {
|
||||
ind1 = i * size + j;
|
||||
nr = (i + 1) * size;
|
||||
ind2 = nr + j;
|
||||
indexes.push(ind1, ind2);
|
||||
}
|
||||
indexes.push(ind2, nr + j0);
|
||||
}
|
||||
indexes.push(indexes[indexes.length - 1], size * size - size);
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.createWestNeighborSkirt = function (size, deltaGr, indexes) {
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var b = size * size - size;
|
||||
var k = 0;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = b - size * i - size + 1,
|
||||
lind = b - size * k;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size);
|
||||
indexes.push(0);
|
||||
}
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.createNorthNeighborSkirt = function (size, deltaGr, indexes) {
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var k = 0;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = size + i + 1,
|
||||
lind = k;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size - 2);
|
||||
indexes.push(size - 1);
|
||||
}
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.createEastNeighborSkirt = function (size, deltaGr, indexes) {
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var k = 0;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = size * (i + 1) + size - 2,
|
||||
lind = size + size * k - 1;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size * (size - 1) - 1);
|
||||
indexes.push(size * size - 1);
|
||||
}
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.createSouthNeighborSkirt = function (size, deltaGr, indexes) {
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var k = 0;
|
||||
var rb = size * (size - 1) - 2;
|
||||
var lb = size * size - 1;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = rb - i,
|
||||
lind = lb - k;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size * size - size + 1);
|
||||
}
|
||||
indexes.push(size * size - size);
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.initIndexesBodySkirts = function (pow) {
|
||||
var table = [];
|
||||
table[og.quadTree.N] = [];
|
||||
table[og.quadTree.W] = [];
|
||||
table[og.quadTree.S] = [];
|
||||
table[og.quadTree.E] = [];
|
||||
|
||||
table[og.quadTree.N][0] = [];
|
||||
table[og.quadTree.W][0] = [];
|
||||
table[og.quadTree.S][0] = [];
|
||||
table[og.quadTree.E][0] = [];
|
||||
|
||||
for (var i = 0; i <= pow; i++) {
|
||||
var d = Math.pow(2, i);
|
||||
table[og.quadTree.N][d] = [];
|
||||
table[og.quadTree.W][d] = [];
|
||||
table[og.quadTree.S][d] = [];
|
||||
table[og.quadTree.E][d] = [];
|
||||
|
||||
table[og.quadTree.N][d][0] = [];
|
||||
table[og.quadTree.W][d][0] = [];
|
||||
table[og.quadTree.S][d][0] = [];
|
||||
table[og.quadTree.E][d][0] = [];
|
||||
|
||||
for (var j = 0; j <= pow; j++) {
|
||||
var dd = Math.pow(2, j);
|
||||
var nt = table[og.quadTree.N][d][dd] = [];
|
||||
var wt = table[og.quadTree.W][d][dd] = [];
|
||||
var st = table[og.quadTree.S][d][dd] = [];
|
||||
var et = table[og.quadTree.E][d][dd] = [];
|
||||
og.planetSegment.PlanetSegmentHelper.createWestNeighborSkirt(d + 1, dd, wt);
|
||||
og.planetSegment.PlanetSegmentHelper.createNorthNeighborSkirt(d + 1, dd, nt);
|
||||
og.planetSegment.PlanetSegmentHelper.createEastNeighborSkirt(d + 1, dd, et);
|
||||
og.planetSegment.PlanetSegmentHelper.createSouthNeighborSkirt(d + 1, dd, st);
|
||||
}
|
||||
}
|
||||
return table;
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.initTextureCoordsTable = function (pow) {
|
||||
var table = [];
|
||||
for (var i = 0; i <= pow; i++) {
|
||||
var d = Math.pow(2, i);
|
||||
table[d] = og.planetSegment.PlanetSegmentHelper.createTextureCoords(d);
|
||||
}
|
||||
return table;
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.initIndexBodiesTable = function (pow) {
|
||||
var table = [];
|
||||
for (var i = 0; i <= pow; i++) {
|
||||
var d = Math.pow(2, i);
|
||||
var t = table[d] = [];
|
||||
og.planetSegment.PlanetSegmentHelper.createCenterBodyIndexes(d + 1, t);
|
||||
}
|
||||
return table;
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.createTextureCoords = function (size) {
|
||||
var texCoords = [];
|
||||
for (var i = 0; i <= size; i++) {
|
||||
for (var j = 0; j <= size; j++) {
|
||||
texCoords.push(j / size, i / size);
|
||||
}
|
||||
}
|
||||
return texCoords;
|
||||
goog.provide('og.planetSegment.PlanetSegmentHelper');
|
||||
|
||||
goog.require('og.quadTree');
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.initIndexesTables = function (powerOfTwo) {
|
||||
if (powerOfTwo != og.planetSegment.PlanetSegmentHelper.powerOfTwo) {
|
||||
og.planetSegment.PlanetSegmentHelper.powerOfTwo = powerOfTwo;
|
||||
og.planetSegment.PlanetSegmentHelper.centerIndexesTable = og.planetSegment.PlanetSegmentHelper.initIndexBodiesTable(powerOfTwo);
|
||||
og.planetSegment.PlanetSegmentHelper.textureCoordsTable = og.planetSegment.PlanetSegmentHelper.initTextureCoordsTable(powerOfTwo);
|
||||
og.planetSegment.PlanetSegmentHelper.skirtsIndexesTable = og.planetSegment.PlanetSegmentHelper.initIndexesBodySkirts(powerOfTwo);
|
||||
}
|
||||
og.planetSegment.PlanetSegmentHelper.centerIndexesTable[0] = [];
|
||||
og.planetSegment.PlanetSegmentHelper.textureCoordsTable[0] = [];
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.createSegmentIndexes = function (size, sidesSizes) {
|
||||
if (size != 1) {
|
||||
var c = og.planetSegment.PlanetSegmentHelper.centerIndexesTable[size],
|
||||
w = og.planetSegment.PlanetSegmentHelper.skirtsIndexesTable[og.quadTree.W][size][sidesSizes[og.quadTree.W]],
|
||||
n = og.planetSegment.PlanetSegmentHelper.skirtsIndexesTable[og.quadTree.N][size][sidesSizes[og.quadTree.N]],
|
||||
e = og.planetSegment.PlanetSegmentHelper.skirtsIndexesTable[og.quadTree.E][size][sidesSizes[og.quadTree.E]],
|
||||
s = og.planetSegment.PlanetSegmentHelper.skirtsIndexesTable[og.quadTree.S][size][sidesSizes[og.quadTree.S]];
|
||||
var indexes = new Uint16Array(c.length + w.length + n.length + e.length + s.length);
|
||||
var k = 0, i = 0;
|
||||
for (k = 0; k < c.length; k++) {
|
||||
indexes[i++] = c[k];
|
||||
}
|
||||
for (k = 0; k < w.length; k++) {
|
||||
indexes[i++] = w[k];
|
||||
}
|
||||
for (k = 0; k < n.length; k++) {
|
||||
indexes[i++] = n[k];
|
||||
}
|
||||
for (k = 0; k < e.length; k++) {
|
||||
indexes[i++] = e[k];
|
||||
}
|
||||
for (k = 0; k < s.length; k++) {
|
||||
indexes[i++] = s[k];
|
||||
}
|
||||
return indexes;
|
||||
} else {
|
||||
return new Uint16Array([0, 2, 1, 3]);
|
||||
}
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.createCenterBodyIndexes = function (size, indexes) {
|
||||
|
||||
var i0 = 1,
|
||||
j0 = 1;
|
||||
|
||||
var i1 = 1,
|
||||
j1 = 1;
|
||||
|
||||
var ind1, ind2, nr;
|
||||
for (var i = i0; i < size - 1 - i1; i++) {
|
||||
for (var j = j0; j < size - j1; j++) {
|
||||
ind1 = i * size + j;
|
||||
nr = (i + 1) * size;
|
||||
ind2 = nr + j;
|
||||
indexes.push(ind1, ind2);
|
||||
}
|
||||
indexes.push(ind2, nr + j0);
|
||||
}
|
||||
indexes.push(indexes[indexes.length - 1], size * size - size);
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.createWestNeighborSkirt = function (size, deltaGr, indexes) {
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var b = size * size - size;
|
||||
var k = 0;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = b - size * i - size + 1,
|
||||
lind = b - size * k;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size);
|
||||
indexes.push(0);
|
||||
}
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.createNorthNeighborSkirt = function (size, deltaGr, indexes) {
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var k = 0;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = size + i + 1,
|
||||
lind = k;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size - 2);
|
||||
indexes.push(size - 1);
|
||||
}
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.createEastNeighborSkirt = function (size, deltaGr, indexes) {
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var k = 0;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = size * (i + 1) + size - 2,
|
||||
lind = size + size * k - 1;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size * (size - 1) - 1);
|
||||
indexes.push(size * size - 1);
|
||||
}
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.createSouthNeighborSkirt = function (size, deltaGr, indexes) {
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var k = 0;
|
||||
var rb = size * (size - 1) - 2;
|
||||
var lb = size * size - 1;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = rb - i,
|
||||
lind = lb - k;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size * size - size + 1);
|
||||
}
|
||||
indexes.push(size * size - size);
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.initIndexesBodySkirts = function (pow) {
|
||||
var table = [];
|
||||
table[og.quadTree.N] = [];
|
||||
table[og.quadTree.W] = [];
|
||||
table[og.quadTree.S] = [];
|
||||
table[og.quadTree.E] = [];
|
||||
|
||||
table[og.quadTree.N][0] = [];
|
||||
table[og.quadTree.W][0] = [];
|
||||
table[og.quadTree.S][0] = [];
|
||||
table[og.quadTree.E][0] = [];
|
||||
|
||||
for (var i = 0; i <= pow; i++) {
|
||||
var d = Math.pow(2, i);
|
||||
table[og.quadTree.N][d] = [];
|
||||
table[og.quadTree.W][d] = [];
|
||||
table[og.quadTree.S][d] = [];
|
||||
table[og.quadTree.E][d] = [];
|
||||
|
||||
table[og.quadTree.N][d][0] = [];
|
||||
table[og.quadTree.W][d][0] = [];
|
||||
table[og.quadTree.S][d][0] = [];
|
||||
table[og.quadTree.E][d][0] = [];
|
||||
|
||||
for (var j = 0; j <= pow; j++) {
|
||||
var dd = Math.pow(2, j);
|
||||
var nt = table[og.quadTree.N][d][dd] = [];
|
||||
var wt = table[og.quadTree.W][d][dd] = [];
|
||||
var st = table[og.quadTree.S][d][dd] = [];
|
||||
var et = table[og.quadTree.E][d][dd] = [];
|
||||
og.planetSegment.PlanetSegmentHelper.createWestNeighborSkirt(d + 1, dd, wt);
|
||||
og.planetSegment.PlanetSegmentHelper.createNorthNeighborSkirt(d + 1, dd, nt);
|
||||
og.planetSegment.PlanetSegmentHelper.createEastNeighborSkirt(d + 1, dd, et);
|
||||
og.planetSegment.PlanetSegmentHelper.createSouthNeighborSkirt(d + 1, dd, st);
|
||||
}
|
||||
}
|
||||
return table;
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.initTextureCoordsTable = function (pow) {
|
||||
var table = [];
|
||||
for (var i = 0; i <= pow; i++) {
|
||||
var d = Math.pow(2, i);
|
||||
table[d] = og.planetSegment.PlanetSegmentHelper.createTextureCoords(d);
|
||||
}
|
||||
return table;
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.initIndexBodiesTable = function (pow) {
|
||||
var table = [];
|
||||
for (var i = 0; i <= pow; i++) {
|
||||
var d = Math.pow(2, i);
|
||||
var t = table[d] = [];
|
||||
og.planetSegment.PlanetSegmentHelper.createCenterBodyIndexes(d + 1, t);
|
||||
}
|
||||
return table;
|
||||
};
|
||||
|
||||
og.planetSegment.PlanetSegmentHelper.createTextureCoords = function (size) {
|
||||
var texCoords = [];
|
||||
for (var i = 0; i <= size; i++) {
|
||||
for (var j = 0; j <= size; j++) {
|
||||
texCoords.push(j / size, i / size);
|
||||
}
|
||||
}
|
||||
return texCoords;
|
||||
};
|
||||
@ -1,6 +1,6 @@
|
||||
goog.provide('og.proj.EPSG3857');
|
||||
|
||||
goog.require('og.proj.Projection');
|
||||
goog.require('og.Units');
|
||||
|
||||
goog.provide('og.proj.EPSG3857');
|
||||
|
||||
goog.require('og.proj.Projection');
|
||||
goog.require('og.Units');
|
||||
|
||||
og.proj.EPSG3857 = new og.proj.Projection({ code: "epsg:3857", units: og.Units.METERS });
|
||||
@ -1,6 +1,6 @@
|
||||
goog.provide('og.proj.EPSG4326');
|
||||
|
||||
goog.require('og.proj.Projection');
|
||||
goog.require('og.Units');
|
||||
|
||||
goog.provide('og.proj.EPSG4326');
|
||||
|
||||
goog.require('og.proj.Projection');
|
||||
goog.require('og.Units');
|
||||
|
||||
og.proj.EPSG4326 = new og.proj.Projection({ code: "epsg:4326", units: og.Units.DEGREES });
|
||||
@ -1,51 +1,51 @@
|
||||
goog.provide('og.proj');
|
||||
goog.provide('og.proj.Projection');
|
||||
goog.provide('og.Units');
|
||||
goog.provide('og.proj.METERS_PER_UNIT');
|
||||
|
||||
/**
|
||||
* Projection units: 'degrees', 'ft', 'm' or 'km'.
|
||||
* @enum {string}
|
||||
* @api
|
||||
*/
|
||||
og.proj.Units = {
|
||||
"DEGREES": "degrees",
|
||||
"FEET": "ft",
|
||||
"METERS": "m",
|
||||
"KILOMETERS": "km"
|
||||
};
|
||||
|
||||
/**
|
||||
* Meters per unit lookup table.
|
||||
* @const
|
||||
* @type {Object.<og.proj.Units, number>}
|
||||
* @api
|
||||
*/
|
||||
og.proj.METERS_PER_UNIT = {};
|
||||
og.proj.METERS_PER_UNIT[og.proj.Units.FEET] = 0.3048;
|
||||
og.proj.METERS_PER_UNIT[og.proj.Units.METERS] = 1;
|
||||
og.proj.METERS_PER_UNIT[og.proj.Units.KILOMETERS] = 1000;
|
||||
|
||||
og.proj.Projection = function (options) {
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {string}
|
||||
*/
|
||||
this.code = options.code;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {og.proj.Units}
|
||||
*/
|
||||
this.units = /** @type {ol.proj.Units} */ (options.units);
|
||||
|
||||
/**
|
||||
* Projection identifier, especially usefull for comparison.
|
||||
* @const
|
||||
* @type {integer}
|
||||
*/
|
||||
this.id = og.proj.Projection._counter++;
|
||||
};
|
||||
|
||||
goog.provide('og.proj');
|
||||
goog.provide('og.proj.Projection');
|
||||
goog.provide('og.Units');
|
||||
goog.provide('og.proj.METERS_PER_UNIT');
|
||||
|
||||
/**
|
||||
* Projection units: 'degrees', 'ft', 'm' or 'km'.
|
||||
* @enum {string}
|
||||
* @api
|
||||
*/
|
||||
og.proj.Units = {
|
||||
"DEGREES": "degrees",
|
||||
"FEET": "ft",
|
||||
"METERS": "m",
|
||||
"KILOMETERS": "km"
|
||||
};
|
||||
|
||||
/**
|
||||
* Meters per unit lookup table.
|
||||
* @const
|
||||
* @type {Object.<og.proj.Units, number>}
|
||||
* @api
|
||||
*/
|
||||
og.proj.METERS_PER_UNIT = {};
|
||||
og.proj.METERS_PER_UNIT[og.proj.Units.FEET] = 0.3048;
|
||||
og.proj.METERS_PER_UNIT[og.proj.Units.METERS] = 1;
|
||||
og.proj.METERS_PER_UNIT[og.proj.Units.KILOMETERS] = 1000;
|
||||
|
||||
og.proj.Projection = function (options) {
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {string}
|
||||
*/
|
||||
this.code = options.code;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {og.proj.Units}
|
||||
*/
|
||||
this.units = /** @type {ol.proj.Units} */ (options.units);
|
||||
|
||||
/**
|
||||
* Projection identifier, especially usefull for comparison.
|
||||
* @const
|
||||
* @type {integer}
|
||||
*/
|
||||
this.id = og.proj.Projection._counter++;
|
||||
};
|
||||
|
||||
og.proj.Projection._counter = 0;
|
||||
@ -1,31 +1,31 @@
|
||||
goog.provide('og.quadTree');
|
||||
|
||||
og.quadTree.NW = 0;
|
||||
og.quadTree.NE = 1;
|
||||
og.quadTree.SW = 2;
|
||||
og.quadTree.SE = 3;
|
||||
|
||||
og.quadTree.N = 0;
|
||||
og.quadTree.E = 1;
|
||||
og.quadTree.S = 2;
|
||||
og.quadTree.W = 3;
|
||||
|
||||
og.quadTree.WALKTHROUGH = 0;
|
||||
og.quadTree.RENDERING = 1;
|
||||
og.quadTree.NOTRENDERING = 2;
|
||||
|
||||
og.quadTree.OPSIDE = [og.quadTree.S, og.quadTree.W, og.quadTree.N, og.quadTree.E];
|
||||
|
||||
//Neighbor's oposite side. For example oposite side
|
||||
//on the east neighbor side is: [E][NW] = SW
|
||||
og.quadTree.NOPS = [[og.quadTree.NE, og.quadTree.NW, og.quadTree.SE, og.quadTree.SW],
|
||||
[og.quadTree.SW, og.quadTree.SE, og.quadTree.NW, og.quadTree.NE],
|
||||
[og.quadTree.NE, og.quadTree.NW, og.quadTree.SE, og.quadTree.SW],
|
||||
[og.quadTree.SW, og.quadTree.SE, og.quadTree.NW, og.quadTree.NE]];
|
||||
|
||||
//Neighbos's opside array order. For example NW node
|
||||
//by E side array index is 0, SE node by S side is 1.
|
||||
og.quadTree.NOPSORD = [[0, 1, 0, 1],
|
||||
[0, 0, 1, 1],
|
||||
[0, 1, 0, 1],
|
||||
goog.provide('og.quadTree');
|
||||
|
||||
og.quadTree.NW = 0;
|
||||
og.quadTree.NE = 1;
|
||||
og.quadTree.SW = 2;
|
||||
og.quadTree.SE = 3;
|
||||
|
||||
og.quadTree.N = 0;
|
||||
og.quadTree.E = 1;
|
||||
og.quadTree.S = 2;
|
||||
og.quadTree.W = 3;
|
||||
|
||||
og.quadTree.WALKTHROUGH = 0;
|
||||
og.quadTree.RENDERING = 1;
|
||||
og.quadTree.NOTRENDERING = 2;
|
||||
|
||||
og.quadTree.OPSIDE = [og.quadTree.S, og.quadTree.W, og.quadTree.N, og.quadTree.E];
|
||||
|
||||
//Neighbor's oposite side. For example oposite side
|
||||
//on the east neighbor side is: [E][NW] = SW
|
||||
og.quadTree.NOPS = [[og.quadTree.NE, og.quadTree.NW, og.quadTree.SE, og.quadTree.SW],
|
||||
[og.quadTree.SW, og.quadTree.SE, og.quadTree.NW, og.quadTree.NE],
|
||||
[og.quadTree.NE, og.quadTree.NW, og.quadTree.SE, og.quadTree.SW],
|
||||
[og.quadTree.SW, og.quadTree.SE, og.quadTree.NW, og.quadTree.NE]];
|
||||
|
||||
//Neighbos's opside array order. For example NW node
|
||||
//by E side array index is 0, SE node by S side is 1.
|
||||
og.quadTree.NOPSORD = [[0, 1, 0, 1],
|
||||
[0, 0, 1, 1],
|
||||
[0, 1, 0, 1],
|
||||
[0, 0, 1, 1]];
|
||||
@ -1,104 +1,104 @@
|
||||
goog.provide('og.shaderProgram.callbacks');
|
||||
|
||||
goog.require('og.shaderProgram.types');
|
||||
|
||||
og.shaderProgram.bindBuffer = function (program, variable) {
|
||||
var gl = program.gl;
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, variable.value);
|
||||
gl.vertexAttribPointer(variable._pName, variable.value.itemSize, gl.FLOAT, false, 0, 0);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u = [];
|
||||
og.shaderProgram.callbacks.a = [];
|
||||
|
||||
/*
|
||||
* Uniforms callbacks
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.MAT4] = function (program, variable) {
|
||||
program.gl.uniformMatrix4fv(variable._pName, false, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.MAT3] = function (program, variable) {
|
||||
program.gl.uniformMatrix3fv(variable._pName, false, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.FLOAT] = function (program, variable) {
|
||||
program.gl.uniform1f(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.INT] = function (program, variable) {
|
||||
program.gl.uniform1i(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.VEC2] = function (program, variable) {
|
||||
program.gl.uniform2fv(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.VEC3] = function (program, variable) {
|
||||
program.gl.uniform3fv(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.VEC4] = function (program, variable) {
|
||||
program.gl.uniform4fv(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.SAMPLER2D] = function (program, variable) {
|
||||
var pgl = program.gl;
|
||||
pgl.activeTexture(pgl.TEXTURE0 + program._textureID);
|
||||
pgl.bindTexture(pgl.TEXTURE_2D, variable.value);
|
||||
pgl.uniform1i(variable._pName, program._textureID);
|
||||
program._textureID++;
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.SAMPLERCUBE] = function (program, variable) {
|
||||
var pgl = program.gl;
|
||||
pgl.activeTexture(pgl.TEXTURE0 + program._textureID);
|
||||
pgl.bindTexture(pgl.TEXTURE_CUBE_MAP, variable.value);
|
||||
pgl.uniform1i(variable._pName, program._textureID);
|
||||
program._textureID++;
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.SAMPLER2DXX] = function (program, variable) {
|
||||
var pgl = program.gl,
|
||||
size = variable.value.length;
|
||||
var samplerArr = new Int32Array(size);
|
||||
for (var i = 0; i < size; i++) {
|
||||
pgl.activeTexture(pgl.TEXTURE0 + program._textureID + i);
|
||||
pgl.bindTexture(pgl.TEXTURE_2D, variable.value[i]);
|
||||
samplerArr[i] = i;
|
||||
}
|
||||
pgl.uniform1iv(variable._pName, samplerArr);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.INTXX] = function (program, variable) {
|
||||
pgl.uniform1iv(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.FLOATXX] = function (program, variable) {
|
||||
program.gl.uniform1fv(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
/*
|
||||
* Attributes callbacks
|
||||
*
|
||||
*/
|
||||
|
||||
og.shaderProgram.callbacks.a[og.shaderProgram.types.FLOAT] = function (program, variable) {
|
||||
program.gl.vertexAttrib1f(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.a[og.shaderProgram.types.VEC2] = function (program, variable) {
|
||||
program.gl.vertexAttrib2fv(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.a[og.shaderProgram.types.VEC3] = function (program, variable) {
|
||||
program.gl.vertexAttrib3fv(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.a[og.shaderProgram.types.VEC4] = function (program, variable) {
|
||||
program.gl.vertexAttrib4fv(variable._pName, variable.value);
|
||||
goog.provide('og.shaderProgram.callbacks');
|
||||
|
||||
goog.require('og.shaderProgram.types');
|
||||
|
||||
og.shaderProgram.bindBuffer = function (program, variable) {
|
||||
var gl = program.gl;
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, variable.value);
|
||||
gl.vertexAttribPointer(variable._pName, variable.value.itemSize, gl.FLOAT, false, 0, 0);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u = [];
|
||||
og.shaderProgram.callbacks.a = [];
|
||||
|
||||
/*
|
||||
* Uniforms callbacks
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.MAT4] = function (program, variable) {
|
||||
program.gl.uniformMatrix4fv(variable._pName, false, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.MAT3] = function (program, variable) {
|
||||
program.gl.uniformMatrix3fv(variable._pName, false, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.FLOAT] = function (program, variable) {
|
||||
program.gl.uniform1f(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.INT] = function (program, variable) {
|
||||
program.gl.uniform1i(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.VEC2] = function (program, variable) {
|
||||
program.gl.uniform2fv(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.VEC3] = function (program, variable) {
|
||||
program.gl.uniform3fv(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.VEC4] = function (program, variable) {
|
||||
program.gl.uniform4fv(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.SAMPLER2D] = function (program, variable) {
|
||||
var pgl = program.gl;
|
||||
pgl.activeTexture(pgl.TEXTURE0 + program._textureID);
|
||||
pgl.bindTexture(pgl.TEXTURE_2D, variable.value);
|
||||
pgl.uniform1i(variable._pName, program._textureID);
|
||||
program._textureID++;
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.SAMPLERCUBE] = function (program, variable) {
|
||||
var pgl = program.gl;
|
||||
pgl.activeTexture(pgl.TEXTURE0 + program._textureID);
|
||||
pgl.bindTexture(pgl.TEXTURE_CUBE_MAP, variable.value);
|
||||
pgl.uniform1i(variable._pName, program._textureID);
|
||||
program._textureID++;
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.SAMPLER2DXX] = function (program, variable) {
|
||||
var pgl = program.gl,
|
||||
size = variable.value.length;
|
||||
var samplerArr = new Int32Array(size);
|
||||
for (var i = 0; i < size; i++) {
|
||||
pgl.activeTexture(pgl.TEXTURE0 + program._textureID + i);
|
||||
pgl.bindTexture(pgl.TEXTURE_2D, variable.value[i]);
|
||||
samplerArr[i] = i;
|
||||
}
|
||||
pgl.uniform1iv(variable._pName, samplerArr);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.INTXX] = function (program, variable) {
|
||||
pgl.uniform1iv(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.u[og.shaderProgram.types.FLOATXX] = function (program, variable) {
|
||||
program.gl.uniform1fv(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
/*
|
||||
* Attributes callbacks
|
||||
*
|
||||
*/
|
||||
|
||||
og.shaderProgram.callbacks.a[og.shaderProgram.types.FLOAT] = function (program, variable) {
|
||||
program.gl.vertexAttrib1f(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.a[og.shaderProgram.types.VEC2] = function (program, variable) {
|
||||
program.gl.vertexAttrib2fv(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.a[og.shaderProgram.types.VEC3] = function (program, variable) {
|
||||
program.gl.vertexAttrib3fv(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
og.shaderProgram.callbacks.a[og.shaderProgram.types.VEC4] = function (program, variable) {
|
||||
program.gl.vertexAttrib4fv(variable._pName, variable.value);
|
||||
};
|
||||
@ -1,19 +1,19 @@
|
||||
goog.provide('og.shaderProgram.picking');
|
||||
|
||||
goog.require('og.shaderProgram');
|
||||
goog.require('og.shaderProgram.ShaderProgram');
|
||||
goog.require('og.shaderProgram.types');
|
||||
|
||||
og.shaderProgram.picking = function () {
|
||||
return new og.shaderProgram.ShaderProgram("picking", {
|
||||
uniforms: {
|
||||
uPMVMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
camPos: { type: og.shaderProgram.types.VEC3 }
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "picking_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "picking_fs.txt")
|
||||
});
|
||||
goog.provide('og.shaderProgram.picking');
|
||||
|
||||
goog.require('og.shaderProgram');
|
||||
goog.require('og.shaderProgram.ShaderProgram');
|
||||
goog.require('og.shaderProgram.types');
|
||||
|
||||
og.shaderProgram.picking = function () {
|
||||
return new og.shaderProgram.ShaderProgram("picking", {
|
||||
uniforms: {
|
||||
uPMVMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
camPos: { type: og.shaderProgram.types.VEC3 }
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "picking_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "picking_fs.txt")
|
||||
});
|
||||
};
|
||||
@ -1,148 +1,148 @@
|
||||
goog.provide('og.shaderProgram');
|
||||
goog.provide('og.shaderProgram.ShaderProgram');
|
||||
|
||||
goog.require('og.shaderProgram.callbacks');
|
||||
|
||||
if (COMPILED) {
|
||||
//og.shaderProgram.SHADERS_URL = "http://www.openglobus.org/shaders/";
|
||||
og.shaderProgram.SHADERS_URL = "/shaders/";
|
||||
} else {
|
||||
og.shaderProgram.SHADERS_URL = "../../src/og/shaders/";
|
||||
}
|
||||
|
||||
og.shaderProgram.ShaderProgram = function (name, material) {
|
||||
this.name = name;
|
||||
this.attributes = material.attributes;
|
||||
this.uniforms = material.uniforms;
|
||||
this._variables = {};
|
||||
this.vertexShader = material.vertexShader;
|
||||
this.fragmentShader = material.fragmentShader;
|
||||
this.gl = null;
|
||||
this._p = null;
|
||||
this._textureID = 0;
|
||||
this._attribArrays = [];
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.use = function () {
|
||||
this.gl.useProgram(this._p);
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.set = function (material) {
|
||||
this._textureID = 0;
|
||||
for (var i in material) {
|
||||
this._variables[i].value = material[i];
|
||||
this._variables[i]._callback(this, this._variables[i]);
|
||||
}
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.apply = function () {
|
||||
this._textureID = 0;
|
||||
var v = this._variables;
|
||||
for (var i in v) {
|
||||
v[i]._callback(this, v[i]);
|
||||
}
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.drawIndexBuffer = function (mode, buffer) {
|
||||
this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, buffer);
|
||||
this.gl.drawElements(mode, buffer.numItems, this.gl.UNSIGNED_SHORT, 0);
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.drawArray = function (mode, numItems) {
|
||||
this.gl.drawArrays(mode, 0, numItems);
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.getShaderCompileStatus = function (shader, src) {
|
||||
this.gl.shaderSource(shader, src);
|
||||
this.gl.compileShader(shader);
|
||||
if (!this.gl.getShaderParameter(shader, this.gl.COMPILE_STATUS)) {
|
||||
alert(this.gl.getShaderInfoLog(shader));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.createVertexShader = function (src) {
|
||||
var shader = this.gl.createShader(this.gl.VERTEX_SHADER);
|
||||
if (!this.getShaderCompileStatus(shader, src)) {
|
||||
return null;
|
||||
}
|
||||
return shader;
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.createFragmentShader = function (src) {
|
||||
var shader = this.gl.createShader(this.gl.FRAGMENT_SHADER);
|
||||
if (!this.getShaderCompileStatus(shader, src)) {
|
||||
return null;
|
||||
}
|
||||
return shader;
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.disableAttribArrays = function () {
|
||||
var gl = this.gl;
|
||||
var a = this._attribArrays;
|
||||
var i = a.length;
|
||||
while (i--) {
|
||||
gl.disableVertexAttribArray(a[i]);
|
||||
}
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.enableAttribArrays = function () {
|
||||
var gl = this.gl;
|
||||
var a = this._attribArrays;
|
||||
var i = a.length;
|
||||
while (i--) {
|
||||
gl.enableVertexAttribArray(a[i]);
|
||||
}
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.createProgram = function (gl) {
|
||||
this.gl = gl;
|
||||
this._p = this.gl.createProgram();
|
||||
|
||||
gl.attachShader(this._p, this.createFragmentShader(this.fragmentShader));
|
||||
gl.attachShader(this._p, this.createVertexShader(this.vertexShader));
|
||||
gl.linkProgram(this._p);
|
||||
|
||||
if (!gl.getProgramParameter(this._p, gl.LINK_STATUS)) {
|
||||
alert("Could not initialise shaders.");
|
||||
}
|
||||
|
||||
this.use();
|
||||
|
||||
for (var a in this.attributes) {
|
||||
this.attributes[a]._name = a;
|
||||
this._variables[a] = this.attributes[a];
|
||||
|
||||
if (this.attributes[a].enableArray)
|
||||
this.attributes[a]._callback = og.shaderProgram.bindBuffer;
|
||||
else
|
||||
this.attributes[a]._callback = og.shaderProgram.callbacks.a[this.attributes[a].type];
|
||||
|
||||
this._p[a] = gl.getAttribLocation(this._p, a);
|
||||
|
||||
if (!this._p[u]) {
|
||||
//alert("error: Shader program: attribute " + a + " is not exists.");
|
||||
}
|
||||
|
||||
if (this.attributes[a].enableArray) {
|
||||
this._attribArrays.push(this._p[a]);
|
||||
gl.enableVertexAttribArray(this._p[a]);
|
||||
}
|
||||
|
||||
this.attributes[a]._pName = this._p[a];
|
||||
}
|
||||
|
||||
for (var u in this.uniforms) {
|
||||
this.uniforms[u]._name = u;
|
||||
this.uniforms[u]._callback = og.shaderProgram.callbacks.u[this.uniforms[u].type];
|
||||
this._variables[u] = this.uniforms[u];
|
||||
this._p[u] = gl.getUniformLocation(this._p, u);
|
||||
|
||||
if (!this._p[u]) {
|
||||
//alert("error: Shader program: uniform " + u + " is not exists.");
|
||||
}
|
||||
|
||||
this.uniforms[u]._pName = this._p[u];
|
||||
}
|
||||
goog.provide('og.shaderProgram');
|
||||
goog.provide('og.shaderProgram.ShaderProgram');
|
||||
|
||||
goog.require('og.shaderProgram.callbacks');
|
||||
|
||||
if (COMPILED) {
|
||||
//og.shaderProgram.SHADERS_URL = "http://www.openglobus.org/shaders/";
|
||||
og.shaderProgram.SHADERS_URL = "/shaders/";
|
||||
} else {
|
||||
og.shaderProgram.SHADERS_URL = "../../src/og/shaders/";
|
||||
}
|
||||
|
||||
og.shaderProgram.ShaderProgram = function (name, material) {
|
||||
this.name = name;
|
||||
this.attributes = material.attributes;
|
||||
this.uniforms = material.uniforms;
|
||||
this._variables = {};
|
||||
this.vertexShader = material.vertexShader;
|
||||
this.fragmentShader = material.fragmentShader;
|
||||
this.gl = null;
|
||||
this._p = null;
|
||||
this._textureID = 0;
|
||||
this._attribArrays = [];
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.use = function () {
|
||||
this.gl.useProgram(this._p);
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.set = function (material) {
|
||||
this._textureID = 0;
|
||||
for (var i in material) {
|
||||
this._variables[i].value = material[i];
|
||||
this._variables[i]._callback(this, this._variables[i]);
|
||||
}
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.apply = function () {
|
||||
this._textureID = 0;
|
||||
var v = this._variables;
|
||||
for (var i in v) {
|
||||
v[i]._callback(this, v[i]);
|
||||
}
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.drawIndexBuffer = function (mode, buffer) {
|
||||
this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, buffer);
|
||||
this.gl.drawElements(mode, buffer.numItems, this.gl.UNSIGNED_SHORT, 0);
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.drawArray = function (mode, numItems) {
|
||||
this.gl.drawArrays(mode, 0, numItems);
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.getShaderCompileStatus = function (shader, src) {
|
||||
this.gl.shaderSource(shader, src);
|
||||
this.gl.compileShader(shader);
|
||||
if (!this.gl.getShaderParameter(shader, this.gl.COMPILE_STATUS)) {
|
||||
alert(this.gl.getShaderInfoLog(shader));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.createVertexShader = function (src) {
|
||||
var shader = this.gl.createShader(this.gl.VERTEX_SHADER);
|
||||
if (!this.getShaderCompileStatus(shader, src)) {
|
||||
return null;
|
||||
}
|
||||
return shader;
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.createFragmentShader = function (src) {
|
||||
var shader = this.gl.createShader(this.gl.FRAGMENT_SHADER);
|
||||
if (!this.getShaderCompileStatus(shader, src)) {
|
||||
return null;
|
||||
}
|
||||
return shader;
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.disableAttribArrays = function () {
|
||||
var gl = this.gl;
|
||||
var a = this._attribArrays;
|
||||
var i = a.length;
|
||||
while (i--) {
|
||||
gl.disableVertexAttribArray(a[i]);
|
||||
}
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.enableAttribArrays = function () {
|
||||
var gl = this.gl;
|
||||
var a = this._attribArrays;
|
||||
var i = a.length;
|
||||
while (i--) {
|
||||
gl.enableVertexAttribArray(a[i]);
|
||||
}
|
||||
};
|
||||
|
||||
og.shaderProgram.ShaderProgram.prototype.createProgram = function (gl) {
|
||||
this.gl = gl;
|
||||
this._p = this.gl.createProgram();
|
||||
|
||||
gl.attachShader(this._p, this.createFragmentShader(this.fragmentShader));
|
||||
gl.attachShader(this._p, this.createVertexShader(this.vertexShader));
|
||||
gl.linkProgram(this._p);
|
||||
|
||||
if (!gl.getProgramParameter(this._p, gl.LINK_STATUS)) {
|
||||
alert("Could not initialise shaders.");
|
||||
}
|
||||
|
||||
this.use();
|
||||
|
||||
for (var a in this.attributes) {
|
||||
this.attributes[a]._name = a;
|
||||
this._variables[a] = this.attributes[a];
|
||||
|
||||
if (this.attributes[a].enableArray)
|
||||
this.attributes[a]._callback = og.shaderProgram.bindBuffer;
|
||||
else
|
||||
this.attributes[a]._callback = og.shaderProgram.callbacks.a[this.attributes[a].type];
|
||||
|
||||
this._p[a] = gl.getAttribLocation(this._p, a);
|
||||
|
||||
if (!this._p[u]) {
|
||||
//alert("error: Shader program: attribute " + a + " is not exists.");
|
||||
}
|
||||
|
||||
if (this.attributes[a].enableArray) {
|
||||
this._attribArrays.push(this._p[a]);
|
||||
gl.enableVertexAttribArray(this._p[a]);
|
||||
}
|
||||
|
||||
this.attributes[a]._pName = this._p[a];
|
||||
}
|
||||
|
||||
for (var u in this.uniforms) {
|
||||
this.uniforms[u]._name = u;
|
||||
this.uniforms[u]._callback = og.shaderProgram.callbacks.u[this.uniforms[u].type];
|
||||
this._variables[u] = this.uniforms[u];
|
||||
this._p[u] = gl.getUniformLocation(this._p, u);
|
||||
|
||||
if (!this._p[u]) {
|
||||
//alert("error: Shader program: uniform " + u + " is not exists.");
|
||||
}
|
||||
|
||||
this.uniforms[u]._pName = this._p[u];
|
||||
}
|
||||
};
|
||||
@ -1,21 +1,21 @@
|
||||
goog.provide('og.shaderProgram.skybox');
|
||||
|
||||
goog.require('og.shaderProgram');
|
||||
goog.require('og.shaderProgram.ShaderProgram');
|
||||
goog.require('og.shaderProgram.types');
|
||||
goog.require('og.utils');
|
||||
|
||||
og.shaderProgram.skybox = function () {
|
||||
return new og.shaderProgram.ShaderProgram("skybox", {
|
||||
uniforms: {
|
||||
uPMVMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
uSampler: { type: og.shaderProgram.types.SAMPLERCUBE },
|
||||
pos: { type: og.shaderProgram.types.VEC3 }
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "skybox_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "skybox_fs.txt")
|
||||
});
|
||||
goog.provide('og.shaderProgram.skybox');
|
||||
|
||||
goog.require('og.shaderProgram');
|
||||
goog.require('og.shaderProgram.ShaderProgram');
|
||||
goog.require('og.shaderProgram.types');
|
||||
goog.require('og.utils');
|
||||
|
||||
og.shaderProgram.skybox = function () {
|
||||
return new og.shaderProgram.ShaderProgram("skybox", {
|
||||
uniforms: {
|
||||
uPMVMatrix: { type: og.shaderProgram.types.MAT4 },
|
||||
uSampler: { type: og.shaderProgram.types.SAMPLERCUBE },
|
||||
pos: { type: og.shaderProgram.types.VEC3 }
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: { type: og.shaderProgram.types.VEC3, enableArray: true }
|
||||
},
|
||||
vertexShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "skybox_vs.txt"),
|
||||
fragmentShader: og.utils.readTextFile(og.shaderProgram.SHADERS_URL + "skybox_fs.txt")
|
||||
});
|
||||
};
|
||||
@ -1,14 +1,14 @@
|
||||
goog.provide('og.shaderProgram.types');
|
||||
|
||||
og.shaderProgram.types._declarations = ["FLOAT", "DOUBLE", "BOOL", "INT", "UINT", "VEC2", "VEC3", "VEC4", "DVEC2",
|
||||
"DVEC3", "DVEC4", "BVEC2", "BVEC3", "BVEC4", "IVEC2", "IVEC3", "IVEC4", "UVEC2",
|
||||
"UVEC3", "UVEC4", "MAT2", "DMAT2", "MAT3", "DMAT3", "MAT4", "DMAT4", "MAT2X3",
|
||||
"MAT2X4", "MAT3X2", "MAT3X4", "MAT4X2", "MAT4X3", "DMAT2X3", "DMAT2X4", "DMAT3X2", "DMAT3X4",
|
||||
"DMAT4X2", "DMAT4X3", "SAMPLER1D", "SAMPLER2D", "SAMPLER3D", "SAMPLERCUBE", "SAMPLER2DSHADOW",
|
||||
"SAMPLER2DXX", "INTXX", "FLOATXX"];
|
||||
|
||||
|
||||
(function () {
|
||||
for (var i = 0; i < og.shaderProgram.types._declarations.length; i++)
|
||||
og.shaderProgram.types[og.shaderProgram.types._declarations[i]] = i;
|
||||
})();
|
||||
goog.provide('og.shaderProgram.types');
|
||||
|
||||
og.shaderProgram.types._declarations = ["FLOAT", "DOUBLE", "BOOL", "INT", "UINT", "VEC2", "VEC3", "VEC4", "DVEC2",
|
||||
"DVEC3", "DVEC4", "BVEC2", "BVEC3", "BVEC4", "IVEC2", "IVEC3", "IVEC4", "UVEC2",
|
||||
"UVEC3", "UVEC4", "MAT2", "DMAT2", "MAT3", "DMAT3", "MAT4", "DMAT4", "MAT2X3",
|
||||
"MAT2X4", "MAT3X2", "MAT3X4", "MAT4X2", "MAT4X3", "DMAT2X3", "DMAT2X4", "DMAT3X2", "DMAT3X4",
|
||||
"DMAT4X2", "DMAT4X3", "SAMPLER1D", "SAMPLER2D", "SAMPLER3D", "SAMPLERCUBE", "SAMPLER2DSHADOW",
|
||||
"SAMPLER2DXX", "INTXX", "FLOATXX"];
|
||||
|
||||
|
||||
(function () {
|
||||
for (var i = 0; i < og.shaderProgram.types._declarations.length; i++)
|
||||
og.shaderProgram.types[og.shaderProgram.types._declarations[i]] = i;
|
||||
})();
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
precision mediump float;
|
||||
|
||||
varying vec4 vColor;
|
||||
|
||||
void main(void) {
|
||||
gl_FragColor = vColor;
|
||||
precision mediump float;
|
||||
|
||||
varying vec4 vColor;
|
||||
|
||||
void main(void) {
|
||||
gl_FragColor = vColor;
|
||||
}
|
||||
@ -1,11 +1,11 @@
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec4 aVertexColor;
|
||||
|
||||
uniform mat4 uPMVMatrix;
|
||||
|
||||
varying vec4 vColor;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = uPMVMatrix * vec4(aVertexPosition, 1.0);
|
||||
vColor = aVertexColor;
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec4 aVertexColor;
|
||||
|
||||
uniform mat4 uPMVMatrix;
|
||||
|
||||
varying vec4 vColor;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = uPMVMatrix * vec4(aVertexPosition, 1.0);
|
||||
vColor = aVertexColor;
|
||||
}
|
||||
@ -1,19 +1,19 @@
|
||||
attribute vec3 aVertexNormal;
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec2 aTextureCoord;
|
||||
|
||||
uniform mat4 uPMatrix;
|
||||
uniform mat4 uMVMatrix;
|
||||
uniform mat4 uTRSMatrix;
|
||||
uniform mat3 uNMatrix;
|
||||
|
||||
varying vec2 vTextureCoord;
|
||||
varying vec3 vTransformedNormal;
|
||||
varying vec4 vPosition;
|
||||
|
||||
void main(void) {
|
||||
vPosition = uMVMatrix * uTRSMatrix * vec4(aVertexPosition, 1.0);
|
||||
gl_Position = uPMatrix * vPosition;
|
||||
vTransformedNormal = uNMatrix * aVertexNormal;
|
||||
vTextureCoord = aTextureCoord;
|
||||
attribute vec3 aVertexNormal;
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec2 aTextureCoord;
|
||||
|
||||
uniform mat4 uPMatrix;
|
||||
uniform mat4 uMVMatrix;
|
||||
uniform mat4 uTRSMatrix;
|
||||
uniform mat3 uNMatrix;
|
||||
|
||||
varying vec2 vTextureCoord;
|
||||
varying vec3 vTransformedNormal;
|
||||
varying vec4 vPosition;
|
||||
|
||||
void main(void) {
|
||||
vPosition = uMVMatrix * uTRSMatrix * vec4(aVertexPosition, 1.0);
|
||||
gl_Position = uPMatrix * vPosition;
|
||||
vTransformedNormal = uNMatrix * aVertexNormal;
|
||||
vTextureCoord = aTextureCoord;
|
||||
}
|
||||
@ -1,61 +1,61 @@
|
||||
goog.provide('og.shapes.Sphere');
|
||||
|
||||
goog.require('og.shapes.BaseShape');
|
||||
|
||||
|
||||
og.shapes.Sphere = function (renderer, radius, latBands, lonBands) {
|
||||
|
||||
goog.base(this, renderer);
|
||||
|
||||
this._radius = radius;
|
||||
this._latBands = latBands;
|
||||
this._lonBands = lonBands;
|
||||
|
||||
this.createData();
|
||||
this.createBuffers();
|
||||
};
|
||||
|
||||
goog.inherits(og.shapes.Sphere, og.shapes.BaseShape);
|
||||
|
||||
og.shapes.Sphere.prototype.createData = function () {
|
||||
|
||||
for (var latNumber = 0; latNumber <= this._latBands; latNumber++) {
|
||||
var theta = latNumber * Math.PI / this._latBands;
|
||||
var sinTheta = Math.sin(theta);
|
||||
var cosTheta = Math.cos(theta);
|
||||
|
||||
for (var longNumber = 0; longNumber <= this._lonBands; longNumber++) {
|
||||
var phi = longNumber * 2 * Math.PI / this._lonBands;
|
||||
var sinPhi = Math.sin(phi);
|
||||
var cosPhi = Math.cos(phi);
|
||||
var x = cosPhi * sinTheta;
|
||||
var y = cosTheta;
|
||||
var z = sinPhi * sinTheta;
|
||||
var u = 1 - (longNumber / this._lonBands);
|
||||
var v = latNumber / this._latBands;
|
||||
this._normalData.push(x);
|
||||
this._normalData.push(y);
|
||||
this._normalData.push(z);
|
||||
this._textureCoordData.push(u);
|
||||
this._textureCoordData.push(v);
|
||||
this._positionData.push(this._radius * x);
|
||||
this._positionData.push(this._radius * y);
|
||||
this._positionData.push(this._radius * z);
|
||||
}
|
||||
}
|
||||
|
||||
for (var latNumber = 0; latNumber < this._latBands; latNumber++) {
|
||||
for (var longNumber = 0; longNumber < this._lonBands; longNumber++) {
|
||||
var first = (latNumber * (this._lonBands + 1)) + longNumber;
|
||||
var second = first + this._lonBands + 1;
|
||||
|
||||
this._indexData.push(first);
|
||||
this._indexData.push(first + 1);
|
||||
this._indexData.push(second);
|
||||
|
||||
this._indexData.push(second);
|
||||
this._indexData.push(first + 1);
|
||||
this._indexData.push(second + 1);
|
||||
}
|
||||
}
|
||||
goog.provide('og.shapes.Sphere');
|
||||
|
||||
goog.require('og.shapes.BaseShape');
|
||||
|
||||
|
||||
og.shapes.Sphere = function (renderer, radius, latBands, lonBands) {
|
||||
|
||||
goog.base(this, renderer);
|
||||
|
||||
this._radius = radius;
|
||||
this._latBands = latBands;
|
||||
this._lonBands = lonBands;
|
||||
|
||||
this.createData();
|
||||
this.createBuffers();
|
||||
};
|
||||
|
||||
goog.inherits(og.shapes.Sphere, og.shapes.BaseShape);
|
||||
|
||||
og.shapes.Sphere.prototype.createData = function () {
|
||||
|
||||
for (var latNumber = 0; latNumber <= this._latBands; latNumber++) {
|
||||
var theta = latNumber * Math.PI / this._latBands;
|
||||
var sinTheta = Math.sin(theta);
|
||||
var cosTheta = Math.cos(theta);
|
||||
|
||||
for (var longNumber = 0; longNumber <= this._lonBands; longNumber++) {
|
||||
var phi = longNumber * 2 * Math.PI / this._lonBands;
|
||||
var sinPhi = Math.sin(phi);
|
||||
var cosPhi = Math.cos(phi);
|
||||
var x = cosPhi * sinTheta;
|
||||
var y = cosTheta;
|
||||
var z = sinPhi * sinTheta;
|
||||
var u = 1 - (longNumber / this._lonBands);
|
||||
var v = latNumber / this._latBands;
|
||||
this._normalData.push(x);
|
||||
this._normalData.push(y);
|
||||
this._normalData.push(z);
|
||||
this._textureCoordData.push(u);
|
||||
this._textureCoordData.push(v);
|
||||
this._positionData.push(this._radius * x);
|
||||
this._positionData.push(this._radius * y);
|
||||
this._positionData.push(this._radius * z);
|
||||
}
|
||||
}
|
||||
|
||||
for (var latNumber = 0; latNumber < this._latBands; latNumber++) {
|
||||
for (var longNumber = 0; longNumber < this._lonBands; longNumber++) {
|
||||
var first = (latNumber * (this._lonBands + 1)) + longNumber;
|
||||
var second = first + this._lonBands + 1;
|
||||
|
||||
this._indexData.push(first);
|
||||
this._indexData.push(first + 1);
|
||||
this._indexData.push(second);
|
||||
|
||||
this._indexData.push(second);
|
||||
this._indexData.push(first + 1);
|
||||
this._indexData.push(second + 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -14,8 +14,8 @@ og.utils.FontAtlas = function () {
|
||||
|
||||
og.utils.FontAtlas.tokens = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ь', 'э', 'ъ', 'ю', 'я',
|
||||
'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ь', 'Э', 'Ъ', 'Ю', 'Я',
|
||||
'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ь', 'э', 'ъ', 'ю', 'я',
|
||||
'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ь', 'Э', 'Ъ', 'Ю', 'Я',
|
||||
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
|
||||
'`', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '-', '=', '[', ']', '{', '}', '\\', '|', ';', ':', '"', ',', '.', '/', '<', '>', '?', ' ', ' '];
|
||||
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
goog.provide('og.utils');
|
||||
|
||||
goog.require('og.Ajax');
|
||||
|
||||
og.utils.readTextFile = function( fileUrl ) {
|
||||
var res = "";
|
||||
|
||||
og.Ajax.request(fileUrl, {
|
||||
async: false,
|
||||
success: function (data)
|
||||
{
|
||||
res = data;
|
||||
}
|
||||
});
|
||||
|
||||
return res;
|
||||
goog.provide('og.utils');
|
||||
|
||||
goog.require('og.Ajax');
|
||||
|
||||
og.utils.readTextFile = function( fileUrl ) {
|
||||
var res = "";
|
||||
|
||||
og.Ajax.request(fileUrl, {
|
||||
async: false,
|
||||
success: function (data)
|
||||
{
|
||||
res = data;
|
||||
}
|
||||
});
|
||||
|
||||
return res;
|
||||
};
|
||||
@ -1,48 +1,48 @@
|
||||
goog.provide('og.webgl.ShaderController');
|
||||
|
||||
|
||||
og.webgl.ShaderController = function (handler, shaderProgram) {
|
||||
this._program = shaderProgram;
|
||||
this._handler = handler;
|
||||
this._activated = false;
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.getProgram = function () {
|
||||
return this._program;
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.activate = function () {
|
||||
if (!this._activated) {
|
||||
this._handler.activeShaderProgram.deactivate();
|
||||
this._handler.activeShaderProgram = this;
|
||||
var p = this._program;
|
||||
this._activated = true;
|
||||
p.enableAttribArrays();
|
||||
p.use();
|
||||
}
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.deactivate = function () {
|
||||
this._program.disableAttribArrays();
|
||||
this._activated = false;
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.isActive = function () {
|
||||
return this._activated;
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.set = function (params) {
|
||||
this._program.set(params);
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.drawIndexBuffer = function (mode, buffer) {
|
||||
this._program.drawIndexBuffer(mode, buffer);
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.drawArray = function (mode, numItems) {
|
||||
this._program.drawArray(mode, numItems);
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.initialize = function () {
|
||||
this._program.createProgram(this._handler.gl);
|
||||
goog.provide('og.webgl.ShaderController');
|
||||
|
||||
|
||||
og.webgl.ShaderController = function (handler, shaderProgram) {
|
||||
this._program = shaderProgram;
|
||||
this._handler = handler;
|
||||
this._activated = false;
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.getProgram = function () {
|
||||
return this._program;
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.activate = function () {
|
||||
if (!this._activated) {
|
||||
this._handler.activeShaderProgram.deactivate();
|
||||
this._handler.activeShaderProgram = this;
|
||||
var p = this._program;
|
||||
this._activated = true;
|
||||
p.enableAttribArrays();
|
||||
p.use();
|
||||
}
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.deactivate = function () {
|
||||
this._program.disableAttribArrays();
|
||||
this._activated = false;
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.isActive = function () {
|
||||
return this._activated;
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.set = function (params) {
|
||||
this._program.set(params);
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.drawIndexBuffer = function (mode, buffer) {
|
||||
this._program.drawIndexBuffer(mode, buffer);
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.drawArray = function (mode, numItems) {
|
||||
this._program.drawArray(mode, numItems);
|
||||
};
|
||||
|
||||
og.webgl.ShaderController.prototype.initialize = function () {
|
||||
this._program.createProgram(this._handler.gl);
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user