2014-03-13 224 views
1

我在改變THREEJs旋轉方面困難重重。我基本上想讓我的相機圍繞我的物體旋轉,而不是圍繞標準點(0,0,0?)旋轉。其原因是,我的Vector3值是相當大的。(X,Z,Y)ThreeJS改變相機的旋轉焦點

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); 
}; 

回答

1

只需添加對象的相機應該圍繞旋轉的攝像頭的位置的位置。

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

你也可以嘗試改變控制的目標:

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

我希望我理解你的權利,因爲我目前無法運行代碼。

+0

墊,感謝您的時間和答案。我嘗試了兩種方法,但迄今爲止並不幸運。我必須首先添加一個位置到我的線上,對嗎?像'line.position.set(x,y,z);'? –

+1

得到它的工作,我只需要改變'controls.rotateSpeed = 0.3', 'controls.zoomSpeed = 0.2'and'controls.panSpeed = 0.05',它們設置得太慢了。技巧是'controls.target = YourObject.position.clone()'感謝Mat! –