javascript - ThreeJS改变Camera的旋转焦点

标签 javascript camera rotation three.js

我很难理解如何改变 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();

我希望我理解正确,因为我目前无法运行您的代码。

关于javascript - ThreeJS改变Camera的旋转焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22371874/

相关文章:

javascript - 拖动时避免使用文本 anchor 跳跃 SVG 文本

javascript - 简单但困难。如何强制外部库函数按顺序运行?

iphone - 在我的应用程序中实现 iPhone 相机中的 Flash 按钮动画?

Python OpenCV cv2.VideoWriter 错误

Javascript点对点 Angular 计算

c++ - OpenGL 围绕点移动相机

javascript - 将 HTML 表格转换为数组

ios - 在 AVCaptureVideoPreviewLayer 上绘制一个矩形,可能吗?

math - 获取旋转矩形的边界

javascript - 允许用户使用 JavaScript 将文件上传到文件夹