簡體   English   中英

如何將現實世界中的3d坐標統一繪制為平面圖的2d坐標?

[英]How to plot 3d coordinates in the real world into 2d coordinates of a floor plan in unity?

我正在使用ARkit開發AR應用程序。我想跟蹤用戶。我可以按用戶的x,y和z坐標。如何將現實世界中用戶位置的3d點映射到2d平面圖中。某些挑戰是因為打開應用程序時用戶位置(攝像機位置)是x,y,z =(0,0,0)。用戶位置是攝像機位置。關於此在2d平面圖中的映射因此,當用戶四處移動時,他的位置可以顯示在2D樓層平面圖中。

我可以添加AR模型並找到它們與用戶之間的距離,這將有助於找到用戶的坐標嗎?當我轉動設備時,坐標會發生變化,因此我們不能依靠用戶位置(相機位置)進行繪圖。

private Vector3 Campos;
public GameObject chagepos; //Added as a child of camera
private void LateUpdate()
{




//Created a starting point

Campos.x = 246f;//x-Coordinate of the floor plan
Campos.z = 121f;//y-Coordinate of the floor plan
chagepos.transform.position = new Vector3(Campos.x, 0, Campos.z);

Debug.Log(chagepos.transform.position);
}

在此處輸入圖片說明

如果用戶位置用Vector3表示,則只需提取x和z分量即可獲得Vector2:

Vector2 floorPlanPosition = new Vector2(playerPosition.x, playerPosition.z);

您可能需要將floorPlanPosition重新投影到平面圖對象的本地空間中(因為這大概也是3d對象)

Vector3 worldSpacePositionOfPlayerOnFloorplan = floorPlan.transform.TransformPoint(new Vector3(floorPlanPosition.x, 0, floorPlanPosition.y);

您可能還需要執行其他轉換,即,如果播放器不在平面圖中,則可能需要減去一些偏移位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM