三JS投影问题
Three JS Projection Issue
我试图在3d空间中查看多边形的中心,然后将其点转换为2d屏幕坐标。这就是不起作用的代码。如有任何帮助,不胜感激。
//calculate the center
var center = new THREE.Vector3();
for (var i = 0; i < positions.length; i++) {
center.add(positions[i]);
}
center.multiplyScalar(1 / positions.length);
//look at the center
var camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000);
camera.lookAt(center);
//calculate the screen coordinates
for (var i = 0; i < positions.length; i++) {
screenPositions.push(toScreenXY(positions[i], camera, width, height));
}
function toScreenXY(position, camera, width, height) {
var pos = position.clone();
pos.project(camera);
var halfWidth = width / 2,
halfHeight = height / 2;
return {
x: (pos.x + 1) * halfWidth + halfWidth,
y: (-pos.y + 1) * halfHeight + halfHeight
};
}
就好像摄像机的变换对投影没有影响
既然你改变了相机的旋转,你就需要更新相机的世界矩阵,因为方法project()
引用了它。
camera.position.set( x, y, z );
camera.lookAt( center );
camera.updateMatrixWorld(); // add this
渲染器在renderer.render()
中为你调用camera.updateMatrixWorld()
,但在这种情况下,你必须自己调用它。
three.js r.71
相关文章:
- 在指令控制器中使用$attrs时出现问题
- 将PHP变量传递给jQuery时遇到问题
- Canvas Html5绘图应用程序,移动画布会导致重大问题
- 参数变量出现ngTable指令问题
- 剑道网格jQuery动画()问题
- 我的jQuery插件参数没有正确启动,遇到了问题
- Phonegap-(安卓/iphone)多个图像的图像库出现问题
- TableExport jquery插件:文件名和扩展名问题
- JavaScript Pub/Sub属性访问问题
- JavaScript异步问题
- 如何解决Yii中的页面刷新问题
- Safari(Mac OS)上的jQuery平滑滚动问题
- jqGrid树网格问题
- 使用正则表达式评估电子邮件地址时出现性能问题
- 如何消除代码中的未定义和其他问题
- JavaScript代码问题:我正在将对象转换为数组
- 三星智能电视应用程序;Brightcove示例应用程序远程控制问题
- svg投影问题在Chrome:而不是添加阴影仅图形的阴影被添加到实际的容器
- Openlayers -从一个点获得纬度/经度时的投影问题
- 三JS投影问题