Coder Social home page Coder Social logo

Comments (5)

AgentCodeBanks avatar AgentCodeBanks commented on June 12, 2024 1

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?

from camera-controls.

yomotsu avatar yomotsu commented on June 12, 2024

Thanks for using camera-controls.
I think it's because setOrbitPoint calls setFocalOffset internally, and focalOffset causes many problems, like

TBH, I would like to remove focalOffset and related features such as setOrbitPoint, but still available for backward compat😒

The best solution is, to avoid using setFocalOffset...

from camera-controls.

DmitriyIudokhin avatar DmitriyIudokhin commented on June 12, 2024

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)?

from camera-controls.

yomotsu avatar yomotsu commented on June 12, 2024

setOrbitPoint with dollyToCursor

Come to think of it, that's right.
Would you mind providing a simplified working demo using codesanbox or so to just reproduce your problem?

setFocalOffset will break dollyToCursor = true anyway...

from camera-controls.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.