Replies: 1 comment 2 replies
-
I found maplibre-gl-js/src/geo/transform.ts Lines 939 to 941 in 868680e But I am still confused. Why must we scale the matrix with worldsize in order to work with [0, 0] nw, [1, 1] se coords? Wouldn't the scaling by worldsize mean this matrix is suitable for working with a meter based mercator space, which is not what i'm doing? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm doing some three.js rendering, and now want to employ a three raycaster. It's very simple code at the end of the day but many things aren't making much sense.
I have to get my hands slightly dirty as the typical Three.js Raycaster codepath will call
ray.origin.setFromMatrixPosition
withcamera.matrixWorld
but the canonical way to "bind" three's camera to maplibre's camera is via assignment ofprojectionMatrix
. When that happens thematrixWorld
is left in a stale and invalid state, it remains the identity matrix.Even though I figured the above out, I am testing the code
ray.origin.setFromMatrixPosition( {elements: mercatorMatrix} )
with the raw mercator matrix from maplibre.Now, this matrix is clearly valid and correct in some sense because it clearly controls three.js properly and all the 3d objects I insert (granted I need to fiddle with some inversion to deal with the left handed/right handed coordinate system situation) are correctly moving with respect to the map.
My roadblock now is that raycasting simply doesn't work. I'm looking at the ray origin position, which is (per
setFromMatrixPosition
) simply grabbing the mercatorMatrix's [12], [13], and [14] values, which are huge, with values such as {x: 244512.32882916788, y: -934734.2579967699, z: -1089157.7139949538}.Clearly there is some division or some other unknown operation I need to take into account for the mat4's coming from maplibre, that is not accounted for by
setFromMatrixPosition
simply taking the usual position vector out of the matrix.I know that when my camera is still positioned somewhere near earth, in terms of maplibre's coordinate system that means my coordinates should never be larger than 1 or 2 or so. Not in the millions.
Beta Was this translation helpful? Give feedback.
All reactions