【问题标题】:three.js Wrong camera position when moving light with TrackballControlsthree.js 使用 TrackballControls 移动灯光时相机位置错误
【发布时间】:2013-05-18 00:23:08
【问题描述】:

我想用我的相机移动光线。 我写道:

  scene = new THREE.Scene();

  camera = new THREE.PerspectiveCamera(40, windowWidth / windowHeight, 1, 10000);
  camera.position.z = 50;
  scene.add(camera);


  var dirLight = new THREE.DirectionalLight(0xffffff);
  **dirLight.position = camera.position;**
  dirLight.position.normalize();
  scene.add(dirLight);

  renderer = new THREE.WebGLRenderer();
  renderer.setSize(windowWidth, windowHeight);
  i_container.appendChild(renderer.domElement);

  controls = new THREE.TrackballControls(camera);

  controls.rotateSpeed = 1.0;
  controls.zoomSpeed = 1.2;
  controls.panSpeed = 0.8;

  controls.noZoom = false;
  controls.noPan = false;

  controls.staticMoving = true;
  controls.dynamicDampingFactor = 0.3;

  controls.keys = [65, 83, 68];

  controls.addEventListener('change', render);

一切正常:光线随着相机移动。 但是有一个问题:当场景初始化时,相机在我的对象内。所以我应该缩小以查看整个对象。

没有这一行 - “dirLight.position = camera.position;”场景初始化正常:我看到了整个对象。

你能解释一下有什么问题吗?我不改变相机的位置。为什么我在物体里面?

谢谢, 振亚

【问题讨论】:

    标签: javascript three.js


    【解决方案1】:

    这与TrackballControls 无关。这是因为

    dirLight.position = camera.position;
    dirLight.position.normalize();
    

    正在标准化相机位置。

    删除dirLight.position.normalize();它不再需要。

    事实上,我会改用 pointLight,但你所做的在当前版本的 three.js 下确实有效。

    three.js r.58

    【讨论】:

      猜你喜欢
      • 2012-06-02
      • 1970-01-01
      • 1970-01-01
      • 2018-09-03
      • 2016-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多