为什么 lookAt 不看指定的向量? [英] Why is lookAt not looking at specified vector?

查看:23
本文介绍了为什么 lookAt 不看指定的向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这三个 js 场景:http://codepen.io/giorgiomartini/pen/ZWLWgX

I have this three js scene: http://codepen.io/giorgiomartini/pen/ZWLWgX

场景包含 5 件事:

相机 - 不可见

origen(3D 矢量)- 在 0,0,0.

origen (3D vector) - At 0,0,0.

objOne - 绿色

objParent - 红色

CenterOfscene - 蓝色

objOne 是 objParent 的孩子.而 ObjOne 看向 origen,它是 0,0,0 处的 3d 向量.

objOne is a child of objParent. And ObjOne looksAt origen, which is a 3d vector at 0,0,0.

但是 objOne 而不是看 0,0,0.原点向量在哪里,它看着 objParent....?

But the objOne instead of looking at the 0,0,0. where the origin vector is, It looks at objParent....?

有什么想法吗?

我想要的是 objOne 来查看 0,0,0.哪个是原向量.

What i want is the objOne to look at the 0,0,0. Which is the origen vector.

任何想法为什么这是行为不端?谢谢.

Any ideas why this is misbehaving? thanks.

THREE.SceneUtils.detach( objOne, objParent, scene );
THREE.SceneUtils.attach( objOne, scene, objParent );

var origen = new THREE.Vector3( 0, 0, 0 );

var render = function () {
    objOne.lookAt(origen);
    requestAnimationFrame( render );

    xOffset += 0.01;
    yOffset += 0.011;
    zOffset += 0.012;

    xOffsetParent += 0.0011;
    yOffsetParent += 0.0013;
    zOffsetParent += 0.0012;

    camXPos = centeredNoise(-1,1,xOffset);
    camYPos = centeredNoise(-1,1,yOffset);
    camZPos = centeredNoise(-1,1,zOffset);
    objOne.position.x = camXPos*4;
    objOne.position.y = camYPos*4;
    objOne.position.z = camZPos*4;

    camParentXPos = centeredNoise(-1,1,xOffsetParent);
    camParentYPos = centeredNoise(-1,1,yOffsetParent);
    camParentZPos = centeredNoise(-1,1,zOffsetParent);
    objParent.position.x = camParentXPos*10;
    objParent.position.y = camParentYPos*10;
    objParent.position.z = camParentZPos*10;

    renderer.render(scene, camera);
};

render();

推荐答案

Object3D.lookAt() 不支持具有旋转和/或平移父项的对象.

Object3D.lookAt() does not support objects with rotated and/or translated parent(s).

您的解决方法是 (1) 将子对象添加为场景的子对象,并且 (2) 将子对象替换为虚拟 Object3D,作为父对象,将与父对象一起移动.

Your work-around is to (1) add the child as a child of the scene, instead, and (2) replace the child object with a dummy Object3D, which, as a child of the parent object, will move with the parent.

然后,在你的渲染循环中,

Then, in your render loop,

child.position.setFromMatrixPosition( dummy.matrixWorld );
child.lookAt( origin );

three.js r.75

three.js r.75

这篇关于为什么 lookAt 不看指定的向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆