gpt4 book ai didi

three.js - 正交相机和pickRay?

转载 作者:行者123 更新时间:2023-12-02 22:12:31 27 4
gpt4 key购买 nike

我尝试实现一个在正交相机的舞台复合体中选择和移动对象的功能。

我想得到与以下相同的示例:http://threejs.org/examples/webgl_interactive_draggablecubes.html

但不适用于透视相机。

我已经替换了:

var camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 1000 );

与:

var camera =  new THREE.OrthographicCamera(window.innerWidth / -zoom, window.innerWidth / zoom, window.innerHeight / zoom, window.innerHeight / -zoom, -1000, 1000);

并替换了这个:

var ray = new THREE.Raycaster( camera.position, vector.sub( camera.position ).normalize() );

通过这个:

var ray = projector.pickingRay( vector, camera );

但是,它似乎还不足以运行。

那么,它缺少什么?

是否可以将投影仪和射线与 OrthographicCamera 一起使用?

谢谢。

最佳答案

请在您的示例中尝试此代码:

event.preventDefault();
if (event.button === 0) {

var projector = new THREE.Projector();
var vector = new THREE.Vector3((event.clientX / window.innerWidth) * 2 - 1, -(event.clientY / window.innerHeight) * 2 + 1, 0.5);
// use picking ray since it's an orthographic camera
var raycaster = projector.pickingRay(vector, camera);
//ditermine whether any of the supplied objects are hit by this ray
var intersertsObj = raycaster.intersectObjects(_entities);
// _entities : is array entities you put to scence
// you can store this list before you entity to scence:
// _entities.push(entity);
// scene.add(entity);
if (intersertsObj.length > 0) {
var pickedObject = intersertsObj[0];
}
}
event = null;

它在我的项目中运行良好。

关于three.js - 正交相机和pickRay?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20361776/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com