javascript - 从三个js中的特定点开始相机旋转
问题描述
我在threejs中加载了一个全景图像,但它从下面的逻辑开始相机旋转,这在threejs中是默认的
if ( isUserInteracting === false ) {
lon += 0.1;
}
lat = Math.max( - 85, Math.min( 85, lat ) );
phi = THREE.Math.degToRad( 90 - lat );
theta = THREE.Math.degToRad( lon );
camera.target.x = 100 * Math.sin( phi ) * Math.cos( theta );
camera.target.y = 100 * Math.cos( phi );
camera.target.z = 100 * Math.sin( phi ) * Math.sin( theta );
我想要做的是将相机放置在我可以使用的特定点
camera.lookAt( -56.86954186163314, 0, -71.49481268065709 );
现在我想从上面的lookAt点开始正常的相机旋转。我目前正在做的是
camera.lookAt( -56.86954186163314 + camera.target.x, 0, -71.49481268065709 + camera.target.z);
我认为这是错误的.. PS(我在几何,罪,cos方面很弱)..任何1都可以帮助我吗?PS(我不想改变camera.target.y
它应该是0)..提前谢谢..
解决方案
This is best looked at from the perspective of vectors.
Take your lookAt
position: that's a vector. You can make that vector spin around an axis using Vector3.applyAxisAngle
. As you update the vector, make your camera look at it.
For your example, you want the camera to look at -56.86954186163314, 0, -71.49481268065709
, and then spin 360° about the Y-axis (the camera position doesn't change, and the lookAt
target doesn't change its Y value).
var lookVector = new THREE.Vector3();
// later...
lookVector.set(x, y, z); // -56.86954186163314, 0, -71.49481268065709
// down with your render function...
var axis = new THREE.Vector3(0, 1, 0);
function render(){
lookVector.applyAxisAngle(axis, 0.001); // or some other theta
camera.lookAt(lookVector);
renderer.render(scene, camera);
}
You'll need to track when your thetas add up to 360°, and perform logic to stop the rotation, but I'll leave that as an exercise for you.
推荐阅读
- python - 无法重新排序列数据
- java - 没有找到后端。请确保您的 CLASSPATH 上有一个后端模块。如何解决此错误
- python-3.x - 从日期列计算年份
- php - php图表未显示所有字段
- sql - 为什么我得到无限的结果?它不应该只显示 1 个 clienti.ID_Cliente 吗?
- python - 将包含 Macro-B 的 Fanuc g 代码转换为基本语法
- c# - 处理异步异常
- oracle-adf - 将应用程序部署到开源服务器
- javascript - 如何隐藏日期时间 x 轴但仍然能够在 Highcharts 甘特图中显示绘图线?
- highcharts - Highcharts:Y轴最大值应该大于数据点