轨道控制;夹角

Orbit controls; Angle clamping

我最近一直在为我想要开发的视觉效果开发一个小型项目,但我无法根据 Y 轴旋转来限制相机旋转,我不太清楚为什么或者我是如何遇到这个问题的。

我环顾四周,发现有人想要卸下角度夹,他们似乎总是提到 minAzimuthAngle 或 maxAzimuthAngle,但我似乎无法让它做任何事情。

// controls.minAzimuthAngle = -Math.PI, controls.maxAzimuthAngle = Math.PI

我只是在这里问,因为我在别处找不到太多可以解释我的问题的地方。我认为这只是我使用或渲染相机的具体方式,但除了松开它们之外,很难找到任何关于夹紧角度的参考。

var renderer, scene, camera;                                                      // scene render var creation
var orbitalControl = new THREE.OrbitControls(camera, renderer);                   //orbitcontrol setup
var controls = new THREE.OrbitControls( camera, renderer);                        // camera to renderer
    controls.addEventListener( 'change', render );                                //control listening
  scene = new THREE.Scene(), camera;                                              // scene creation
  var W = window.innerWidth, H = window.innerHeight;                              // scene size
  camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 2000);
  camera.position.set(0, 0, 400);                                                 // camera assignment
  camera.up = new THREE.Vector3(0,500,0);

  controls = new THREE.OrbitControls(camera);                                     // centeralising the camera
  controls.target = new THREE.Vector3(500, 200, 500);                             // controls
  controls.addEventListener('change', render);                                    // renderer based on controls

  scene.add(camera);                                                              // camera to scene
  controls.addEventListener( 'change', render );                                  // control adjustments
  controls.screenSpacePanning = false;
  controls.enableDamping = true, controls.dampingFactor = 0.25;
  controls.enableZoom = false, controls.autoRotate = false;   

  controls.minPolarAngle = Math.PI / 2 ; // radians
  controls.maxPolarAngle = Math.PI / 2 // radians
  controls.minAzimuthAngle = -Math.PI * 0.5;
    controls.maxAzimuthAngle = Math.PI * 0.5;

  controls.addEventListener("change", () => {
  if (this.renderer) this.renderer.render(this.scene, camera)});

无论我如何更改最小或最大 AzimuthAngle,它都不会做任何事情,但这是我从任何其他帖子中唯一提到的东西。

有什么东西与我尝试呈现的方式有冲突吗? 我真的不知道问题出在哪里。

提前感谢所有回复的人

github link 到整个项目; https://github.com/Thealonic/GENESIS

I'm having issues being able to limit the camera rotation based on the Y axis rotation,

在这种情况下,您必须配置 minAzimuthAnglemaxAzimuthAngle。请记住,您只能使用 [ - Math.PI, Math.PI ] 范围内的值。查看以下示例如何限制水平旋转的距离。

var mesh, renderer, scene, camera, controls;

init();
animate();

function init() {

    // renderer
    renderer = new THREE.WebGLRenderer();
    renderer.setSize( window.innerWidth, window.innerHeight );
    renderer.setPixelRatio( window.devicePixelRatio );
    document.body.appendChild( renderer.domElement );

    // scene
    scene = new THREE.Scene();
    
    // camera
    camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
    camera.position.set( 20, 20, 20 );

    // controls
    controls = new THREE.OrbitControls( camera, renderer.domElement );
    controls.minAzimuthAngle = 0;
    controls.maxAzimuthAngle = Math.PI * 0.5;
    
    // ambient
    scene.add( new THREE.AmbientLight( 0x222222 ) );
    
    // light
    var light = new THREE.DirectionalLight( 0xffffff, 1 );
    light.position.set( 20,20, 0 );
    scene.add( light );
    
    // axes
    scene.add( new THREE.AxesHelper( 20 ) );

    // geometry
    var geometry = new THREE.SphereGeometry( 5, 12, 8 );
    
    // material
    var material = new THREE.MeshPhongMaterial( {
        color: 0x00ffff, 
        flatShading: true,
        transparent: true,
        opacity: 0.7,
    } );
    
    // mesh
    mesh = new THREE.Mesh( geometry, material );
    scene.add( mesh );
    
}

function animate() {

    requestAnimationFrame( animate );
    renderer.render( scene, camera );

}
body {
  margin: 0;
}
canvas {
  display: block;
}
<script src="https://cdn.jsdelivr.net/npm/three@0.115/build/three.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.115/examples/js/controls/OrbitControls.js"></script>