【问题标题】:Threejs: Rotate sphere(globe) to another point(city) on the sphere itselfThreejs:将球体(地球)旋转到球体本身的另一个点(城市)
【发布时间】:2015-11-03 05:08:54
【问题描述】:

我正在构建一个地球(球体几何),其中包含一组预定义的地理映射位置并绘制为点(球体几何)。我想通过沿 y 轴旋转地球来聚焦(将一个位置移动到另一个位置)这些位置。我尝试了以下代码,似乎不适用于所有位置。

location.geometry.computeBoundingBox();
var position = new THREE.Vector3();
position.subVectors( location.geometry.boundingBox.max, location.geometry.boundingBox.min );
position.multiplyScalar( 0.20 );
position.sub( location.geometry.boundingBox.min );
location.matrixWorld.multiplyVector3( position );
var point1 = scene.clone().position;
var point2 = position;
var distance = point1.distanceTo( point2 );
locationCollection.rotation.y = distance;

我想,我对这个概念的理解不够。希望我能从社区中得到一些想法。

Fiddle

【问题讨论】:

  • 你能创建一个小提琴 (jsfiddle.net) 来显示你的代码的工作版本吗?
  • 我已经创建了小提琴。多一点代码。我已经为代码块编写了一些简短的 cmets。希望它实现了目的。下面是小提琴链接,jsfiddle.net/senthanal/j7mda/25

标签: javascript 3d three.js webgl


【解决方案1】:
var c = group.rotation.y;
var d = -b * (Math.PI / 180)%(2 * Math.PI);
var e = Math.PI / 2 * -1;
group.rotation.y = c % (2 * Math.PI);
group.rotation.x = a * (Math.PI / 180) % Math.PI;
group.rotation.y= d+e;

其中 a= 纬度,b= 经度,group=Object3D(或球体)

【讨论】:

  • 问它是否有任何困惑?
  • 如果您不使用组,您也可以将组更改为场景。
  • 我很困惑你为什么要设置 group.rotation.y 两次
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-18
  • 2019-05-03
  • 2012-08-24
  • 1970-01-01
  • 2013-12-05
  • 1970-01-01
  • 2014-09-24
相关资源
最近更新 更多