在 Three.js 中,如何翻译一个 Vector3?

编程入门 行业动态 更新时间:2024-10-26 09:23:05
本文介绍了在 Three.js 中,如何翻译一个 Vector3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我创建了一个名为 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屋!

更多推荐

[db:关键词]

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

发布评论

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

>www.elefans.com

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