三.JS旋转投影使y轴变成z轴

发布于 2024-12-18 02:21:54 字数 250 浏览 2 评论 0原文

传统上,在 3D 投影中,Y 轴是代表“上下”的轴。我学会了将它与其他引擎一起思考,因为该轴是 Z 轴。我想知道 Three.JS 是否有办法制作 Z 轴“上/下”轴。如果是的话,有什么后果吗?

这是我想要的图表: 在此处输入图像描述

Traditionally, in 3D projections, the Y-axis is the axis that represents "up and down". I learned to think of it, with other engines, as that axis being the Z-axis. What I was wondering was whether there is a way in Three.JS to make the Z-axis the "up/down" axis. If so, are there any consequences to it?

Here is a diagram of what I want:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

殊姿 2024-12-25 02:21:54

您可以只更改相机而不是整个坐标系。例如:

const WIDTH = 1024;
const HEIGHT = 768;
const VIEW_ANGLE = 45;
const ASPECT = WIDTH / HEIGHT;
const NEAR = 0.1;
const FAR = 10000;
camera = new THREE.PerspectiveCamera(VIEW_ANGLE, ASPECT, NEAR, FAR);
camera.position.z = 300;
camera.up = new THREE.Vector3( 0, 0, 1 );
scene.add(camera);

这会更改相机的向上向量以使用Z-UP。


为了说明示例,这里是您创建的 JSFiddle,稍加修改即可在设置 up 向量后调用 lookAthttp://jsfiddle.net/NycWc/1/

You could just change the camera rather than the entire coordinate system. For example:

const WIDTH = 1024;
const HEIGHT = 768;
const VIEW_ANGLE = 45;
const ASPECT = WIDTH / HEIGHT;
const NEAR = 0.1;
const FAR = 10000;
camera = new THREE.PerspectiveCamera(VIEW_ANGLE, ASPECT, NEAR, FAR);
camera.position.z = 300;
camera.up = new THREE.Vector3( 0, 0, 1 );
scene.add(camera);

This changes the up vector for the camera to use Z-UP.


To illustrate an example, here's the JSFiddle you created slightly modified to call lookAt after setting the up vector: http://jsfiddle.net/NycWc/1/

梦幻的味道 2024-12-25 02:21:54

以下将达到您想要的结果:

THREE.Object3D.DEFAULT_UP.set(0, 0, 1);

根据文档

.DEFAULT_UP:矢量3
对象的默认向上方向,也用作 DirectionalLight、HemisphereLight 和 Spotlight(创建从上到下照射的灯光)的默认位置。
默认设置为 ( 0, 1, 0 )。

要了解详细信息,请参阅源代码

The following will achieve your desired result:

THREE.Object3D.DEFAULT_UP.set(0, 0, 1);

According to the documentation:

.DEFAULT_UP : Vector3
The default up direction for objects, also used as the default position for DirectionalLight, HemisphereLight and Spotlight (which creates lights shining from the top down).
Set to ( 0, 1, 0 ) by default.

To learn more, see the source code.

爱的故事 2024-12-25 02:21:54

我对一个对象有这个问题。这是我修复它的方法。

object.rotation.z = 90 * Math.PI/180;
object.rotation.x = -90 * Math.PI/180;

正如您所要求的那样,这改变了它的方向。

I had this issue with an object. Here's how I fixed it.

object.rotation.z = 90 * Math.PI/180;
object.rotation.x = -90 * Math.PI/180;

This took changed it's orientation in just the way you're asking.

数理化全能战士 2024-12-25 02:21:54

xyz 坐标系应始终使用右手定则设置。创建自己的约定根本不是一个好的计划,并且会引起很多混乱。您可以随意旋转坐标系,但不要改变轴的方向。如果您确实想做您所显示的内容,您可以创建一个 x,y,-z 坐标系。

The xyz coordinate frame should always be set up with the right hand rule. Creating your own convention is simply not such a good plan and will cause a lot of confusion. You can rotate the coordinate frame at will but don't change the direction of the axis. If you really want to do what you display you can make an x,y,-z coordinate frame.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文