Open EberleAutomatischeSysteme opened 2 years ago
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)
All right, I understand. That's right, that's how to solve the problem.
Thanks for the answer and this great project!
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?
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 )
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?
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.
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.
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.
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.
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.
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
Store position with cameraControls.getPosition() and target with cameraControls.getTarget() in variable.
Move and rotate an object, setOrbitPoint() must be called once to change the OrbitPoint.
The previous saved position cannot be restored with cameraControls.setPosition(x,y,z) and cameraControls.setTarget(x,y,z,).
The saved position matches the current one, but the image is not the same anymore.
Code
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