为什么 lookAt 不看指定的向量?

编程入门 行业动态 更新时间:2024-10-26 12:25:57
本文介绍了为什么 lookAt 不看指定的向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有这三个 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 16:11:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1396370.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:向量   不看   lookAt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!