Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize matrix calculation for labels #7967

Merged
merged 1 commit into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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