本文介绍了在 Three.js 中,如何翻译一个 Vector3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个名为 ori
的 Vector3()
,并填充了它的坐标 x、y 和 z.现在,我该如何平移这个向量,比如沿 z 轴,指定值?
I have created a Vector3()
called ori
, and I have populated its coordinates x, y and z. How, now, do I translate this vector, say along axis z, of the indicated value?
我试过了:
ori.translateZ( - 100);
这让我出错(TypeError:无法读取未定义的属性translateZ")
This gets me an error (TypeError: Cannot read property 'translateZ' of undefined)
推荐答案
如果你想通过单轴平移,就像添加平移值一样简单:
If you want to translate by a single axis, it's as simple as adding the translation value:
ori.z += -100;
如果你想用向量翻译,同样很简单:
If you want to translate by a vector, it's again very simple:
var trans = new THREE.Vector3(-100,-200,-300);
ori.add(trans);
这篇关于在 Three.js 中,如何翻译一个 Vector3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!