-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
fix camera controller issue when tilt on terrain #9562
Conversation
Thank you so much for the pull request @renjianqiang! I noticed this is your first pull request and I wanted to say welcome to the Cesium community! The Pull Request Guidelines is a handy reference for making sure your PR gets accepted quickly, so make sure to skim that.
Reviewers, don't forget to make sure that:
|
Thanks @renjianqiang. I have to think a bit more about the changes but I can reproduce the issue you described and it looks like these changes fix it. Could you please update |
@ebogo1 CHANGES.md has been updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea behind this change makes sense to me, but I'm confused why the change doesn't introduce a new problem when using the old transform
matrix before the call to rotate3D()
with the horizontal flag set to true. It's an oversimplification, but if I understand correctly the current code computes the tilt like this:
setTransform(transform);
rotate3D(verticalOnly=false);
setTransform(verticalTransform);
rotate3D(verticalOnly=true);
And the changes like this:
setTransform(verticalTransform);
rotate3D(verticalOnly=true);
setTransform(transform);
rotate3D(verticalOnly=false);
The changes in this PR aim to fix the camera issue by performing the vertical rotate3D
before the verticalCenter
changes (and consequently, the verticalTransform
) from the horizontal rotate3D
. Maybe I'm missing something here, but wouldn't center
change after the vertical rotation the same way?
I also have a minor suggestion for the wording in CHANGES.md
.
@renjianqiang Do you have an idea about why it is safe to reuse the old transform
matrix with these changes? I think I'm on board with your changes but it'd be nice to have a better intuition for why this works before merging.
Co-authored-by: Eli Bogomolny <31491650+ebogo1@users.noreply.github.com>
@ebogo1 yeap, you are right, what I did was just changed the rotation order!
Because the As you see in the picture, the yellow var windowPosition = tilt3DWindowPos;
windowPosition.x = canvas.clientWidth / 2; // this is the horizontal center of the screen
windowPosition.y = controller._tiltCenterMousePosition.y; // _tiltCenterMousePosition is the position where mouse start clicked
ray = camera.getPickRay(windowPosition, tilt3DRay);
var mag = Cartesian3.magnitude(center);
var radii = Cartesian3.fromElements(mag, mag, mag, scratchRadii);
var newEllipsoid = Ellipsoid.fromCartesian3(radii, scratchEllipsoid);
intersection = IntersectionTests.rayEllipsoid(ray, newEllipsoid); Now, if we rotate horizontally first, the But if we rotate vertically first, the In addition,we can fix this problem by recalculate the Hope this helpful! |
@renjianqiang Thanks for the write-up - that makes sense. I pushed a couple changes to CHANGES.md but this will be ready after the CI passes. |
fix camera controller issue when tilt on terrain
When i drag the mouse middle button diagonally along the screen, i find there are some wrong with camera controller:
Then i find the
tilt3DOnTerrain
inScreenSpaceCameraController.js
have some problems. It first calculatedverticalCenter
, and do horizontal rotate first, but nowverticalCenter
has changed after horizontal rotate, so there are some errors introduced here. I fix this problems by change the rotation order.