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

Camera.lookAt crash #10252

Open
j9liu opened this issue Mar 31, 2022 · 1 comment
Open

Camera.lookAt crash #10252

j9liu opened this issue Mar 31, 2022 · 1 comment

Comments

@j9liu
Copy link
Contributor

j9liu commented Mar 31, 2022

This came up in #10092 using this Sandcastle. I intended to open a quick PR to fix this, but it exposed more issues that I'm not sure I understand.

image

Essentially, using camera.lookAt with an offset with range: 0 causes a crash. This is because the direction is calculated using the position derived from the offset parameters -- the position is zero, so the direction will be zero and unable to be normalized.

I was able to fix this by putting a check at around line 2420 of Camera.js:

if (!Cartesian3.equals(this.position, Cartesian3.ZERO)) {
    Cartesian3.negate(this.position, this.direction);
  }

and this prevents the Sandcastle from crashing. However, attempting to zoom in and out results in another crash:

image

The problem is that cartesianToCartographic(camera.position, zoom3DCartographic) returns undefined for the center of the ellipsoid, Cartesian.ZERO. I'm struggling to understand what's happening here, though, because the camera is not actually in the middle of the Earth in the Sandcastle. So why is camera.position zero, then? In any case, what should height default to in ScreenSpaceCameraController, line 2186, if the function returns undefined?

If those few questions get answered, I have no problem opening a PR with the changes, but I'm unfamiliar with the math here and don't want to make incorrect changes.

@lilleyse
Copy link
Contributor

So why is camera.position zero, then?

position is not actually the global position in all cases. When camera.lookAt is called it puts the camera in a local coordinate system and position is relative to that. This is the main difference between position and positionWC, which is always a global position.

Looking at the ScreenSpaceCameraController I think there's a faulty assumption that the position is in global space. My guess is that that code gets run but is overridden later whenever it handles the local space math.

Unfortunately to fix this bug there might be a cascade of issues like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants