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

Restore CameraPosition after setOrbitPoint dosn't work #316

Open
EberleAutomatischeSysteme opened this issue Oct 21, 2022 · 10 comments · May be fixed by #507
Open

Restore CameraPosition after setOrbitPoint dosn't work #316

EberleAutomatischeSysteme opened this issue Oct 21, 2022 · 10 comments · May be fixed by #507

Comments

@EberleAutomatischeSysteme
Copy link

EberleAutomatischeSysteme commented Oct 21, 2022

Describe the bug

I rotate the scene the mouse point, for this I set the current hitpoint of the raycaster at setOrbitPoint().

This also works perfectly.

Now I reset the camera occasionally to a saved position. These are determined with cameraControls.getPosition() and cameraControls.getTarget().

The resetting of this position does not work after I changed the OrbitPoint once. Even if I reset the OrbitPoint to (0,0,0), which I set as default position, the camera is not set to the saved position anymore.

Saving the camera state as JSON is unfortunately not possible, because other controllers may be used. Which do not offer this function.

To Reproduce

  1. Store position with cameraControls.getPosition() and target with cameraControls.getTarget() in variable.

  2. Move and rotate an object, setOrbitPoint() must be called once to change the OrbitPoint.

  3. The previous saved position cannot be restored with cameraControls.setPosition(x,y,z) and cameraControls.setTarget(x,y,z,).

  4. The saved position matches the current one, but the image is not the same anymore.

Code

//save the current camera status
var position = cameraControls.getPosition() 
var target = cameraControls.getTarget() 

--> Move and rotate object

//restore camera state
cameraControls.setOrbitPoint(0,0,0) // -> does not work with or without restore the orbit point
cameraControls.setPosition(position.x, position.y, position.z)
cameraControls.setTarget(target.x, target.y, target.z)
cameraControls.update()

cameraControls.getPosition() == position and 
cameraControls.getTarget() == target
but scene images is not same as when it was when saved the camera position

Live example

https://yomotsu.github.io/camera-controls/examples/click-to-set-orbit-point.html

Expected behavior

Camera should return to the same position

Screenshots or Video

No response

Device

Desktop

OS

Windows

Browser

Chrome

@yomotsu
Copy link
Owner

yomotsu commented Oct 21, 2022

setOrbitPoint() changes focalOffset as well.
you may need to save focalOffset and restore that after setting the target and position.

like

const position = cameraControls.getPosition() 
const target = cameraControls.getTarget() 
const offset = cameraControls.getFocalOffset()

then

cameraControls.setOrbitPoint( 0, 0, 0, false )
cameraControls.setLookAt( position.x, position.y, position.z, target.x, target.y, target.z, false )
cameraControls.setFocalOffset( offset.x, offset.y, offset.z, false )
cameraControls.update( 0 )

(not tested tho)

@EberleAutomatischeSysteme
Copy link
Author

All right, I understand.
That's right, that's how to solve the problem.

Thanks for the answer and this great project!

@EberleAutomatischeSysteme
Copy link
Author

I also noticed that if the orbit point is set or changed for an orthographic camera. The DollyToCourser is no longer calculated correctly. I then zoom by an offset around the actual point. If I set the focalOffset to (0,0,0) it works normally again but the image then jumps once according to the offset.
I assume that when calculating the zoom direction the offset has to be considered?

@yomotsu
Copy link
Owner

yomotsu commented Nov 4, 2022

Actually, dolly-to-courser in Orthographic has a complex problem (dolly-to-courser for Orthographic should be removed until it's fixed, but keep it as it is for backward compat )

@EberleAutomatischeSysteme
Copy link
Author

It would be cool if the dolly-to-courser with the rotate around mouse point would work. We would also like to offer our help to solve this problem, if that's ok?

@yomotsu
Copy link
Owner

yomotsu commented Nov 18, 2022

Absolutely!
Would it be possible for you to make a pull request?

Also, would you mind elaborating "the dolly-to-courser with the rotate around mouse point"?
I think drag-to-rotate uses the mouse pointer move, thus cursor position keeps moving during rotation. Therefore I don't think "rotate around mouse point" would work.

@EberleAutomatischeSysteme
Copy link
Author

With rotate-around-mouse-point I mean changing the orbit point (the camera rotates around the point of the cursor (mouse)). Currently there is the problem that when the orbit point (focal offset) is set or changed, the orthographic camera no longer zooms in the direction of the mouse cursor. The goal would be that, when changing the orbit point the orthographic camera zooms in the direction of the cursor.

@yomotsu
Copy link
Owner

yomotsu commented Nov 18, 2022

I think we must fix zoom-to-cursor in Orthographic Camera first then.
Currently, zoom-to-cursor in orthographic camera is wrong. It actually behaves as dolly-to-cursor even in Orthographic, and it causes problems. It has to be ZOOM-to-cursor, the camera position is stationary and changes FOV angle.

@yomotsu
Copy link
Owner

yomotsu commented Nov 20, 2022

The problem I mentioned right above ("zoom-to-cursor in orthographic camera is wrong") has just been fixed!
So, you don't need to think about that.

@EberleAutomatischeSysteme
Copy link
Author

Great, thank you very much. As soon as I have some time again I will try to get the focal offset with the orthographic camera.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants