I’m trying to implement a portal (https://playcanvas.com/editor/scene/1733137) like this:
Step 1: the white area will be the portal. Find its on-screen co-ordinates.
Step 2: Take the view from the portal (“blue”) camera
Step 3: Using the on-screen co-ordinates from step 1, a cropped version of the “blue” camera’s output is rendered into the white area.
It all seems to work, BUT breaks down when the camera is fairly close to the render area and the render area is only partially visible. See the animation below, as the viewer turns the render area suddenly jumps.
Investigation shows that the
worldToScreen function is returning incorrect values. Even for a small change in position there is a disproportionate change in the screen co-ordinates:
-21146095.956585325, 11261290.89697315, -21146095.956585333, -10686079.648416352, 235.775456045, 1072.028363128, 235.775456045, -78.914197592
After a small change, the right-most co-ordinates change sign
3635260.91483109, -1934543.5226093638, 3635260.91483109, 1836833.4723431966, 235.3796, 1072.2389787654, 235.3796, -79.1153285465
but I have no idea why.
I’ve put up a much simplified project at https://playcanvas.com/editor/scene/1773583.
The call of interest (
worldToScreen) is in the
Move the character controller along the x-axis, the threshold value is x: 6.261 - 6.262