簡體   English   中英

ThreeJS改變相機的旋轉焦點

[英]ThreeJS change rotation focus of Camera

我很難改變THREEjs的旋轉角度。 我基本上希望我的相機繞我的對象旋轉,而不是繞標准點(0,0,0?)旋轉。 原因是我的Vector3值相當大。.(x,z,y)

4312872.381146194 66.59563132658498 -25727937.924670007
4312475.124507734 66.59563132658498 -25728638.83021001 
4312004.77886603 133.19126265316996 -25728715.10960813 
4311292.30267081 133.19126265316996 -25728348.26316222
4310580.495996718 199.78689397975492 -25727972.97279594 
4310080.51032912 199.78689397975492 -25727395.118092548 
4309842.889229621 266.3825253063399 -25726583.881802954 
4309162.375115815 266.3825253063399 -25726174.132726204 

我將點與線連接起來,將相機位置設置為邊界框,並使用OrbitalControls來移動。 但是移動相機並不會專注於我的線條幾何。 如何更改輪換行為? 誰能把我放在正確的道路上?

var renderer,
    scene,
    camera,
    controls

renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColorHex( 0xeeeeee, 1.0 );

scene = new THREE.Scene();

var material = new THREE.LineBasicMaterial({
    color: 0xff00cc,
    fog: true
});
var geometryL = new THREE.Geometry();

之后,我將數據推送到幾何...

var line = new THREE.Line(geometryL, material);


geometryL.computeBoundingBox();
var bBox = geometryL.boundingBox;
console.log(bBox);
var x_max = bBox.max.x;
var y_max = bBox.max.y;
var z_max = bBox.max.z;

scene.add( line );

camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 5000000);
camera.position.set( x_max*1.01, y_max*1.01, z_max*1.01 );  

controls = new THREE.OrbitControls( camera );
controls.addEventListener( 'change', animate );

controls.rotateSpeed = 0.01;
controls.zoomSpeed = 0.01;
controls.panSpeed = 0.08;

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

controls.staticMoving = true;
controls.dynamicDampingFactor = 2;

animate();

function animate() {
    renderer.render( scene, camera );
};

只需將相機應旋轉的對象的位置添加到相機的位置即可。

camera.position.set( x_max*1.01, y_max*1.01, z_max*1.01 ).add(YourObject.position.clone());

您也可以嘗試更改控件的目標:

controls.target = YourObject.position.clone();

希望我對您的理解正確,因為我目前無法運行您的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM