ol.vec.Mat4 improvements
* Rename ol.vec.Mat4.fromMatrix to ol.vec.Mat4.fromTransform * Make result from ol.vec.Mat4.fromTransform immutable by adding result matrix as argument.
This commit is contained in:
@@ -6,6 +6,13 @@ goog.require('ol');
|
||||
goog.require('ol.vec.Mat4');
|
||||
|
||||
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
* @private
|
||||
*/
|
||||
ol.dom.tmpMat4_ = ol.vec.Mat4.create();
|
||||
|
||||
|
||||
/**
|
||||
* Create an html canvas element and returns its 2d context.
|
||||
* @param {number=} opt_width Canvas width.
|
||||
@@ -136,7 +143,7 @@ ol.dom.transformElement2D = function(element, transform, opt_precision) {
|
||||
var i;
|
||||
if (ol.dom.canUseCssTransform3D()) {
|
||||
var value3D;
|
||||
var transform3D = ol.vec.Mat4.fromMatrix(transform);
|
||||
var transform3D = ol.vec.Mat4.fromTransform(ol.dom.tmpMat4_, transform);
|
||||
if (opt_precision !== undefined) {
|
||||
/** @type {Array.<string>} */
|
||||
var strings3D = new Array(16);
|
||||
|
||||
@@ -145,6 +145,12 @@ ol.render.webgl.ImageReplay = function(tolerance, maxExtent) {
|
||||
*/
|
||||
this.projectionMatrix_ = ol.transform.create();
|
||||
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
* @private
|
||||
*/
|
||||
this.tmpMat4_ = ol.vec.Mat4.create();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean|undefined}
|
||||
@@ -565,9 +571,12 @@ ol.render.webgl.ImageReplay.prototype.replay = function(context,
|
||||
ol.transform.rotate(offsetRotateMatrix, -rotation);
|
||||
}
|
||||
|
||||
gl.uniformMatrix4fv(locations.u_projectionMatrix, false, ol.vec.Mat4.fromMatrix(projectionMatrix));
|
||||
gl.uniformMatrix4fv(locations.u_offsetScaleMatrix, false, ol.vec.Mat4.fromMatrix(offsetScaleMatrix));
|
||||
gl.uniformMatrix4fv(locations.u_offsetRotateMatrix, false, ol.vec.Mat4.fromMatrix(offsetRotateMatrix));
|
||||
gl.uniformMatrix4fv(locations.u_projectionMatrix, false,
|
||||
ol.vec.Mat4.fromTransform(this.tmpMat4_, projectionMatrix));
|
||||
gl.uniformMatrix4fv(locations.u_offsetScaleMatrix, false,
|
||||
ol.vec.Mat4.fromTransform(this.tmpMat4_, offsetScaleMatrix));
|
||||
gl.uniformMatrix4fv(locations.u_offsetRotateMatrix, false,
|
||||
ol.vec.Mat4.fromTransform(this.tmpMat4_, offsetRotateMatrix));
|
||||
gl.uniform1f(locations.u_opacity, opacity);
|
||||
|
||||
// draw!
|
||||
|
||||
@@ -73,6 +73,12 @@ ol.renderer.webgl.Layer = function(mapRenderer, layer) {
|
||||
*/
|
||||
this.projectionMatrix = ol.transform.create();
|
||||
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
* @private
|
||||
*/
|
||||
this.tmpMat4_ = ol.vec.Mat4.create();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.renderer.webgl.map.shader.Default.Locations}
|
||||
@@ -169,9 +175,9 @@ ol.renderer.webgl.Layer.prototype.composeFrame = function(frameState, layerState
|
||||
}
|
||||
|
||||
gl.uniformMatrix4fv(locations.u_texCoordMatrix, false,
|
||||
ol.vec.Mat4.fromMatrix(this.getTexCoordMatrix()));
|
||||
ol.vec.Mat4.fromTransform(this.tmpMat4_, this.getTexCoordMatrix()));
|
||||
gl.uniformMatrix4fv(locations.u_projectionMatrix, false,
|
||||
ol.vec.Mat4.fromMatrix(this.getProjectionMatrix()));
|
||||
ol.vec.Mat4.fromTransform(this.tmpMat4_, this.getProjectionMatrix()));
|
||||
gl.uniform1f(locations.u_opacity, layerState.opacity);
|
||||
gl.bindTexture(goog.webgl.TEXTURE_2D, this.getTexture());
|
||||
gl.drawArrays(goog.webgl.TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
@@ -2,22 +2,24 @@ goog.provide('ol.vec.Mat4');
|
||||
|
||||
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
* @return {Array.<number>} 4x4 matrix representing a 3D identity transform.
|
||||
*/
|
||||
ol.vec.Mat4.tmpMatrix_ = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
||||
ol.vec.Mat4.create = function() {
|
||||
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Transform} mat Transformation matrix.
|
||||
* @param {Array.<number>} mat4 Flattened 4x4 matrix receiving the result.
|
||||
* @param {ol.Transform} transform Transformation matrix.
|
||||
* @return {Array.<number>} 2D transformation matrix as flattened 4x4 matrix.
|
||||
*/
|
||||
ol.vec.Mat4.fromMatrix = function(mat) {
|
||||
var mat4 = ol.vec.Mat4.tmpMatrix_;
|
||||
mat4[0] = mat[0];
|
||||
mat4[1] = mat[1];
|
||||
mat4[4] = mat[2];
|
||||
mat4[5] = mat[3];
|
||||
mat4[12] = mat[4];
|
||||
mat4[13] = mat[5];
|
||||
ol.vec.Mat4.fromTransform = function(mat4, transform) {
|
||||
mat4[0] = transform[0];
|
||||
mat4[1] = transform[1];
|
||||
mat4[4] = transform[2];
|
||||
mat4[5] = transform[3];
|
||||
mat4[12] = transform[4];
|
||||
mat4[13] = transform[5];
|
||||
return mat4;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user