How to get details (Position ,Rotation, Scale) of the Game Object that is placed in real world as AR?

huangapple go评论66阅读模式
英文:

How to get details (Position ,Rotation, Scale) of the Game Object that is placed in real world as AR?

问题

当我使用Unity中的AR将游戏对象(例如:立方体)放置在现实世界中时,我想要以文本形式接收该游戏对象的详细信息,例如位置、旋转和在XYZ平面上的缩放,是否可能实现?

英文:

When I place a game object (e.g.: Cube) in the real world with the help of AR using Unity, I want to receive detail of that game object like the position, rotation and scale in xyz plane separately. Will it be possible to get it in text form?

答案1

得分: 1

最简单的方法是分别获取位置、旋转和缩放,代码如下:

Vector3 worldPosition = this.transform.position;
string worldPositionStr = worldPosition.x + ", " + worldPosition.y + ", " + worldPosition.z;

假设该脚本附加到相关对象上。要获取旋转,请使用this.transform.eulerAngles而不是this.transform.position,对于缩放,请使用this.transform.lossyScale(查看每个字段的文档以更好地理解它们)。

但请记住,这些值是在当前AR会话的空间中。因此,这些值取决于您启动AR会话的位置,并且可能在每次重新启动会话时发生变化。

英文:

The easiest way to get position, rotation and scale separately would be like this:

Vector3 worldPosition = this.transform.position;
string worldPositionStr = worldPosition.x + ", " + worldPosition.y + ", " + worldPosition.z;

assuming the script is attached to the object in question.
For rotation use this.transform.eulerAngles instead of this.transform.position and this.transform.lossyScale for scale (have a look at the documentation of each of those fields to better understand them).

You should keep in mind though that these values are in the space of the current AR session. So these values depend on where you start the AR session and might change each time you restart your session.

huangapple
  • 本文由 发表于 2023年2月27日 15:04:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75577559.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定