在 Three.js 中,如何翻译一个 Vector3? [英] In Three.js, how to translate a Vector3?

查看:32
本文介绍了在 Three.js 中,如何翻译一个 Vector3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个名为 oriVector3(),并填充了它的坐标 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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