-
-
Notifications
You must be signed in to change notification settings - Fork 260
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
Dolly to Cursor and focalOffset #491
Comments
Thanks for using camera-controls. TBH, I would like to remove The best solution is, to avoid using setFocalOffset... |
But in your examples setOrbitPoint with dollyToCursor is working well. Maybe it is because of using Perspective camera(your examples) instead of Orthographic(in my app)? |
Come to think of it, that's right.
|
I had the same problem with my project. I solved it by recalculating the target for the controller with every mouse-up event (after every rotation with changing the orbitPoint). I scale the look vector of the camera with the radius of the spherical in the control and then move the new target with moveTo. Similar to the fitToSphere const spherical = new THREE.Spherical(0, 0, 0);
const vTempA = new THREE.Vector3();
const vTempB = new THREE.Vector3();
container.addEventListener('mouseup', (evt) => {
if(event.which === 3 ){
if (controls._camera.isOrthographicCamera) {
controls.getSpherical(spherical); //Get sperical who is used to calculate the camera position in the update loop
vTempA.set(controls._camera.position.x, controls._camera.position.y, controls._camera.position.z); //Get camera position
vTempB.set(0, 0, -1).applyQuaternion(controls._camera.quaternion); //Get the look vector from the camera
vTempB.multiplyScalar(spherical.radius); //scale the look vector
vTempB.add(vTempA); // add the camera position to get the new target position
controls.setFocalOffset(0, 0, 0, false).then();
controls.moveTo(vTempB.x, vTempB.y, vTempB.z, false).then(); //Move the new target to the position
controls.update(0.0001);
} else {
controls.setOrbitPoint(0, 0, 0, false);
}
}
}); I haven't checked the other functions of the controller to see if they still work, as that was the most important thing for me that time. #yomotsu Do you see any possible problems with the code? |
Getting focalOffset working so we could use set orbitpoint without side effects would be very nice. Been a while since I tested, but doing reset on some actions might work.. think it was mainly when using AWSD keys I got some weird jumping, maybe dolly to cursor too. Think I will give it a new try this week 😄 |
Describe the bug
Hi. thanks for this library. It helps a lot but i cant solve one problem.
I have OrthographicCamera and dollyToCursor working well but when i setOrbitPoint manually ( i want rotation around my part on scene) or make a movement with offset => after that when zooming with dollyToCursor it jumps by some delta.
Video attached.
To Reproduce
Steps to reproduce the behavior:
Code
Live example
No response
Expected behavior
dolly to cursor dollies exactly to mouse location
Screenshots or Video
Recording.2024-03-11.143823.mp4
Device
Desktop
OS
Windows
Browser
Chrome
The text was updated successfully, but these errors were encountered: