Javascript 三个物体围绕球体旋转
因此,我最近一直在使用threejs,在尝试旋转地球表面有微型球体的地球时遇到了一些问题Javascript 三个物体围绕球体旋转,javascript,rotation,three.js,trigonometry,Javascript,Rotation,Three.js,Trigonometry,因此,我最近一直在使用threejs,在尝试旋转地球表面有微型球体的地球时遇到了一些问题 嘿,你已经在你的代码中这么做了,我只是从你的创建中复制,看看你的例子 如果(相交长度>=3) { 对于(变量i=0;i
嘿,你已经在你的代码中这么做了,我只是从你的创建中复制,看看你的例子
如果(相交长度>=3)
{
对于(变量i=0;i
我猜你是在纬度和姿态点上工作的。我计算φ,θ如下:
var phi = (90 - varible1) * Math.PI / 180;
var theta = (-variable2) * Math.PI / 180;
var RandomHeightOfLine = 1.5 // Or greater then your point distance to origin
作为向量=
new THREE.Vector3(RandomHeightOfLine * Math.sin(phi) * Math.cos(theta), RandomHeightOfLine * Math.cos(phi), RandomHeightOfLine * Math.sin(phi) * Math.sin(theta)));
As点=
var x = RandomHeightOfLine * Math.sin(phi) * Math.cos(theta);
var y = RandomHeightOfLine * Math.cos(phi);
var z = RandomHeightOfLine * Math.sin(phi) * Math.sin(theta);
controls.target.set( x, y, z );
如果你想移动相机,我建议用更大的随机高度计算x2,y2,z2
此外,如果你想顺利移动,我建议你使用吐温
var t;
var t2;
var t3; //Put as Global or use Array, because GC likes to remove Tween objects.
function tweenCamera(position, target, time){
console.log("tween");
updateTween = true;
beforeTweenPos = camera.position.clone();
beforeTweenTarg = controls.target.clone();
t = new TWEEN.Tween( camera.position ).to( {
x: position.x,
y: position.y,
z: position.z}, time )
.easing( TWEEN.Easing.Quadratic.In).start();
t2 = new TWEEN.Tween( camera.up ).to( {
x: 0,
y: 1,
z: 0}, time )
.easing( TWEEN.Easing.Quadratic.In).start();
t3 = new TWEEN.Tween( controls.target ).to( {
x: target.x,
y: target.y,
z: target.z}, time )
.easing( TWEEN.Easing.Quadratic.In)
.onComplete(function () {
updateTween = false;
console.log("Turning off Update Tween");
t = null;
t2 = null;
t3 = null;
}, this).start();
//camera.up = new THREE.Vector3(0,0,1); // If you don't want animation for this. And remove t3.
}
此外,您的动画更新还应包括:
...
lastTimeMsec = lastTimeMsec || nowMsec-1000/60;
deltaMsec = Math.min(200, nowMsec - lastTimeMsec);
lastTimeMsec = nowMsec;
if(updateTween)
{
TWEEN.update(lastTimeMsec); //Comment
} else
{
TWEEN.removeAll();
}
...
Tween JS:我看到了你的代码,至少在Firefox中,你能解释更多吗?正如我之前所说,我想让球体旋转,这样当我点击绿色斑点时,被点击的斑点就会居中,所以你可能想得到绿色斑点的坐标,然后旋转大球体,使绿色斑点位于屏幕的中心?是的,我已经能够计算出绿色斑点的3d位置和我希望绿色斑点显示的中心,我尝试使用一些基本函数来执行转换,但它不起作用,有什么想法吗?它似乎没有正确旋转,因为它没有到中心,这是我的问题
...
lastTimeMsec = lastTimeMsec || nowMsec-1000/60;
deltaMsec = Math.min(200, nowMsec - lastTimeMsec);
lastTimeMsec = nowMsec;
if(updateTween)
{
TWEEN.update(lastTimeMsec); //Comment
} else
{
TWEEN.removeAll();
}
...