gpt4 book ai didi

javascript - Raycaster 不报告与平面相交

转载 作者:行者123 更新时间:2023-11-29 22:14:08 27 4
gpt4 key购买 nike

我正在尝试检测与地形的碰撞,这是通过修改飞机的垂直高度创建的。

但 Raycaster 仅在大约 10% 的所有尝试中正确检测到碰撞。您可以看到其中一个交叉点,在以下示例中未正确检测到: http://cerno.ch/~kamen/threejs/test.html

我做错了什么?

编辑:这是 jsfiddle

var camera, scene, renderer, gump = 0;
var geometry, material, mesh, map, axis, ray;

init();
animate();

function init() {

//Create cam, so we can see what's happening
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.x = 500;
camera.position.y = 300;

//Init scene
scene = new THREE.Scene();

//Load terrain material
material = new THREE.MeshBasicMaterial( { color: 0xff6666, wireframe: false } );
geometry = new THREE.PlaneGeometry(128, 128, 127, 127);
mesh = new THREE.Mesh( geometry, material );
mesh.scale.set(50,50,50);
mesh.rotation.x = -Math.PI/2;
scene.add( mesh );

//Create axis with position and rotation of ray
axis = new THREE.AxisHelper( 100 );
axis.position = new THREE.Vector3(333.2637, 216.6575, -515.6349);
axis.rotation = new THREE.Vector3(1.6621025025, 0.119175114, -2.2270436357);
axis.scale.z = 10;
scene.add(axis);

//Create actual ray, use axis position and rotation
ray = new THREE.Raycaster();
ray.ray.origin.copy(axis.position);
ray.ray.direction.copy(axis.rotation);

//Renderer
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );

document.body.appendChild( renderer.domElement );
}

function animate() {
requestAnimationFrame( animate );

if (mesh)
{
var intersecionts = ray.intersectObject(mesh);
if (intersecionts.length > 0)
{
//Never actually happens
console.log("OK");
}

//Move axis so you can see, that it clearly goes throught mesh object
axis.translateZ(Math.cos(gump) * 2);
gump += 0.01;

//Focus camera on axis
camera.lookAt(axis.position);
}

renderer.render( scene, camera );

}

http://jsfiddle.net/BAGnd/

编辑:按要求添加系统规范:

Windows 7 64 位

Chrome 26.0.1410

三个 57

显卡:GTX 560 Ti

最佳答案

发现我的错误。我认为,用于旋转对象的旋转矢量和用于光线的方向矢量是相同的东西。在我将我的旋转矢量转移到方向矢量之后,它工作得很好。如何将旋转矢量转换为方向矢量:How to get Orientation of Camera in THREE.js

关于javascript - Raycaster 不报告与平面相交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16223376/

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