Skip to content

Commit

Permalink
make less temporary projection matrices (#7967)
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner authored Feb 28, 2019
1 parent 80fe23b commit a88b541
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
14 changes: 12 additions & 2 deletions src/geo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Transform {
alignedProjMatrix: Float64Array;
pixelMatrix: Float64Array;
pixelMatrixInverse: Float64Array;
glCoordMatrix: Float32Array;
labelPlaneMatrix: Float32Array;
_fov: number;
_pitch: number;
_zoom: number;
Expand Down Expand Up @@ -568,11 +570,19 @@ class Transform {
mat4.translate(alignedM, alignedM, [ dx > 0.5 ? dx - 1 : dx, dy > 0.5 ? dy - 1 : dy, 0 ]);
this.alignedProjMatrix = alignedM;

// matrix for conversion from location to screen coordinates
m = mat4.create();
mat4.scale(m, m, [this.width / 2, -this.height / 2, 1]);
mat4.translate(m, m, [1, -1, 0]);
this.pixelMatrix = mat4.multiply(new Float64Array(16), m, this.projMatrix);
this.labelPlaneMatrix = m;

m = mat4.create();
mat4.scale(m, m, [1, -1, 1]);
mat4.translate(m, m, [-1, -1, 0]);
mat4.scale(m, m, [2 / this.width, 2 / this.height, 1]);
this.glCoordMatrix = m;

// matrix for conversion from location to screen coordinates
this.pixelMatrix = mat4.multiply(new Float64Array(16), this.labelPlaneMatrix, this.projMatrix);

// inverse matrix for conversion from screen coordinaes to location
m = mat4.invert(new Float64Array(16), this.pixelMatrix);
Expand Down
16 changes: 5 additions & 11 deletions src/symbol/projection.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,14 @@ function getLabelPlaneMatrix(posMatrix: mat4,
rotateWithMap: boolean,
transform: Transform,
pixelsToTileUnits: number) {
const m = mat4.identity(new Float32Array(16));
const m = mat4.create();
if (pitchWithMap) {
mat4.identity(m);
mat4.scale(m, m, [1 / pixelsToTileUnits, 1 / pixelsToTileUnits, 1]);
if (!rotateWithMap) {
mat4.rotateZ(m, m, transform.angle);
}
} else {
mat4.scale(m, m, [transform.width / 2, -transform.height / 2, 1]);
mat4.translate(m, m, [1, -1, 0]);
mat4.multiply(m, m, posMatrix);
mat4.multiply(m, transform.labelPlaneMatrix, posMatrix);
}
return m;
}
Expand All @@ -96,19 +93,16 @@ function getGlCoordMatrix(posMatrix: mat4,
rotateWithMap: boolean,
transform: Transform,
pixelsToTileUnits: number) {
const m = mat4.identity(new Float32Array(16));
if (pitchWithMap) {
mat4.multiply(m, m, posMatrix);
const m = mat4.clone(posMatrix);
mat4.scale(m, m, [pixelsToTileUnits, pixelsToTileUnits, 1]);
if (!rotateWithMap) {
mat4.rotateZ(m, m, -transform.angle);
}
return m;
} else {
mat4.scale(m, m, [1, -1, 1]);
mat4.translate(m, m, [-1, -1, 0]);
mat4.scale(m, m, [2 / transform.width, 2 / transform.height, 1]);
return transform.glCoordMatrix;
}
return m;
}

function project(point: Point, matrix: mat4) {
Expand Down

0 comments on commit a88b541

Please sign in to comment.