在 OrbitControls 中的 Three.js 限制平移 [英] Three.js limit pan in OrbitControls

查看:84
本文介绍了在 OrbitControls 中的 Three.js 限制平移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Three.js 中,我应该添加或限制用户在使用 OrbitControls 时可以向左/向右/向上/向下平移多远?我不希望平移太远以至于您看不到场景中的物体.

In Three.js, wow do I add or put limits on how far left/right/up/down a user can pan when using OrbitControls? I'd prefer not to be able to pan so far away that you are unable to see the objects in the scene.

推荐答案

在当前版本的 OrbitControls.js 中,位置会随着平移变化而更新 此处.

In the current version of OrbitControls.js, the position is updated with the panning changes here.

现在如果你想限制平移到一些边界,你可以简单地检查相机的新位置是否在这个边界内,否则你不更新位置:

Now if you want to limit the panning to some boundaries, you can simply check if the new position of the camera lies within this boundaries, otherwise you do not update the position:

var newX = this.target.x + pan.x;
var newY = this.target.y + pan.y;
if (newX <= this.maxXPan && newX >= this.minXPan 
        && newY <= this.maxYPan && newY >= this.minYPan) {
    this.target.add( pan );
}

这篇关于在 OrbitControls 中的 Three.js 限制平移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆