Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
not able to understand scene position importance

I am trying to write some sample code of three.js where i have a plane and i want that plane to rotate around.

This is my camera:

var camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1,  1000);
camera.position.set(50, 50, 60);
camera.lookAt(scene.position);

and this is my plane:

var planeGeometry = new THREE.PlaneGeometry(70, 30, 1, 1);
var planeMaterial = new THREE.MeshBasicMaterial({ color: green });
var plane = new THREE.Mesh(planeGeometry, planeMaterial);
plane.rotation.x = -0.5 * Math.PI;
scene.add(plane);

i have other code too but this is my render and animationframe code:

renderScene();

function cameraUpdate() {
  camera.position.x = cameraRadius * Math.cos(step);
  camera.position.z = cameraRadius * Math.sin(step);
  camera.lookAt(scene.position);
}

function renderScene() {
 //make update to position, rotation of objects in the scene
  step += 0.05;
  cameraUpdate();
  requestAnimationFrame(renderScene);
  renderer.render(scene, camera);
}

My question is that inside cameraUpdate function if dont put

  camera.lookAt(scene.position);

the rotation become very wierd and when i put this inside cameraUpdate, i get rotation of the plane in own axis which is desired !!!

My question is

  1. what does scene.position mean
  2. Why do i need to make camera lookat at every animation frame? i dont understand how its value get changed when camera is rotated

Thank you in advance !!!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you want the plane to rotate on its own, you should just use plane.rotation.y += 0.1 on each frame, or something simple like that. What you’re doing instead is that you’re making the camera move around in circles around the plane. Think of it as walking in a circle around a coffee table. If you keep your head looking forward, you won’t see the table as you walk past it. That’s what camera.lookAt() fixes. It makes the camera look at a point in space. You can read about it in the docs.

scene.position is by default at (0, 0, 0) so it’s just another way of telling the camera to look at the center of the scene.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda