Hello. I want to rotate a camera around model, but only on X axis. I tried to do it by using OrbitControls, but something is wrong. After using OrbitControls my camera looked at different place. I’ve found that changing controls.target is what i needed to do. And here is my problem. I literally can’t set it to make it look good! How can i set controls and camera to have exact same view like camera before using OrbitControls?
Before using OrbitControls:
After using OrbitControls:
Here is my code:
//Camera
const camera = new THREE.PerspectiveCamera(45, 390 / 844, 0.1, 100)
camera.position.set(0, 2.8, 5.5)
scene.add(camera)
//Renderer
const renderer = new THREE.WebGLRenderer({
canvas: canvas.value,
alpha: true,
antialias: true,
})
renderer.setPixelRatio(window.devicePixelRatio)
renderer.setSize(350, 250)
//Controls
const controls = new OrbitControls(camera, renderer.domElement)
controls.enableDamping = true
controls.enableZoom = false;
controls.minPolarAngle = Math.PI/4;
controls.maxPolarAngle = Math.PI/4;
//Animate loop
function animate() {
requestAnimationFrame(animate);
if (globalGltf) {
globalGltf.rotation.y -= 0.005
}
renderer.render(scene, camera)
}
animate();