Skip to content

Commit

Permalink
fixed ray intersection on 2d line geometry
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Deubler <[email protected]>
  • Loading branch information
TerminalTim committed Jul 10, 2024
1 parent 657c1ea commit 0f73a9d
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions packages/display/src/displays/webgl/buffer/templates/LineBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ export class LineBuffer extends TemplateBuffer {
const scaleByAltitude = <boolean>buffer.getUniform('u_scaleByAltitude');
const N_SCALE = 1.0 / 8192.0;


const stride = size * 3;
let index;

const m3 = rayCaster.sMat[3];
const m7 = rayCaster.sMat[7];
const m11 = rayCaster.sMat[11];
Expand All @@ -93,13 +90,11 @@ export class LineBuffer extends TemplateBuffer {
const dy0 = (ny0 & 1) * 2 - 1;
ny0 = dy0 * (ny0 >> 1) * N_SCALE;

let x0 = position[i];
let y0 = position[i + 1];
let z0 = size == 3 ? -position[i + 2] : 0;
let x0 = position[i++];
let y0 = position[i++];
let z0 = size == 3 ? -position[i++] : 0;
// convert normalized int16 to float meters (-500m ... +9000m)
// z0 = (z0 - 32267.0) * 0.14496292001098665;


let nx1 = normal[n + 4];
let ny1 = normal[n + 5];

Expand All @@ -109,9 +104,10 @@ export class LineBuffer extends TemplateBuffer {
const dy1 = (ny1 & 1) * 2 - 1;
ny1 = dy1 * (ny1 >> 1) * N_SCALE;

let x1 = position[i + 3];
let y1 = position[i + 4];
let z1 = size == 3 ? -position[i + 5] : 0;

let x1 = position[i++];
let y1 = position[i++];
let z1 = size == 3 ? -position[i++] : 0;

let nx2 = normal[n + 8];
let ny2 = normal[n + 9];
Expand All @@ -122,10 +118,9 @@ export class LineBuffer extends TemplateBuffer {
const dy2 = (ny2 & 1) * 2 - 1;
ny2 = dy2 * (ny2 >> 1) * N_SCALE;

let x2 = position[i + 6];
let y2 = position[i + 7];
let z2 = size == 3 ? -position[i + 8] : 0;

let x2 = position[i++];
let y2 = position[i++];
let z2 = size == 3 ? -position[i++] : 0;

const tileX0 = tileX + x0;
const tileY0 = tileY + y0;
Expand All @@ -144,15 +139,12 @@ export class LineBuffer extends TemplateBuffer {
t2[1] = tileY + y2 + ny2 * strokeWidth * scaleDZ;
t2[2] = z2;


let intersectRayLength = Raycaster.rayIntersectsTriangle(
rayOrigin,
rayDirection,
t0, t1, t2
);

i += stride;

if (intersectRayLength != null) {
if (intersectRayLength <= result.z) {
result.z = intersectRayLength;
Expand Down

0 comments on commit 0f73a9d

Please sign in to comment.