【问题标题】:How can I get the WorldToScreenPoint from a camera position in the past?如何从过去的相机位置获取 WorldToScreenPoint?
【发布时间】:2019-06-26 07:27:22
【问题描述】:

我在 Unity 中有一个点云,我正在做一些图像识别工作。图像识别完成后,我需要点云在屏幕空间中的屏幕点,从相机帧开始,当我开始图像识别时。由于图像识别需要一些时间,至少已经过去了几帧,并且相机有一个新的变换(位置、旋转)。

如何从旧相机位置获取屏幕空间点? (来自保存的投影矩阵和相机到世界矩阵)

【问题讨论】:

  • 你不能回到过去,除非你把它们保存在某个地方。
  • 是的,但是当我有投影矩阵、相机到世界矩阵和世界点时,如何计算屏幕空间位置?

标签: unity3d camera position point-clouds


【解决方案1】:

我自己找到了解决方案:

保存你相机的 projectionMatrix 和 worldToCameraMatrix 然后运行这个:

Matrix4x4 matrix = projectionMatrix * worldToCameraMatrix;
Vector3 screenPos = matrix.MultiplyPoint(destination.transform.position);

// (-1, 1)'s clip => (0 ,1)'s viewport 
screenPos = new Vector3(screenPos.x + 1f, screenPos.y + 1f, screenPos.z + 1f) / 2f;

// viewport => screen
screenPos = new Vector3(screenPos.x * Screen.width, screenPos.y * Screen.height, screenPos.z);
var unityScreenPos = new Vector2(screenPos.x, Screen.height - screenPos.y);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多