ios - 投影矩阵有什么用?

标签 ios vector augmented-reality rotational-matrices projection-matrix

我一直在尝试分析 Apple 的 pARk(增强现实示例应用程序),我遇到了以下功能,

方法调用参数如下:

createProjectionMatrix(projectionTransform, 60.0f*DEGREES_TO_RADIANS, self.bounds.size.width*1.0f / self.bounds.size.height, 0.25f, 1000.0f);
void createProjectionMatrix(mat4f_t mout, float fovy, float aspect, float zNear, float zFar)
{
    float f = 1.0f / tanf(fovy/2.0f);

    mout[0] = f / aspect;
    mout[1] = 0.0f;
    mout[2] = 0.0f;
    mout[3] = 0.0f;

    mout[4] = 0.0f;
    mout[5] = f;
    mout[6] = 0.0f;
    mout[7] = 0.0f;

    mout[8] = 0.0f;
    mout[9] = 0.0f;
    mout[10] = (zFar+zNear) / (zNear-zFar);
    mout[11] = -1.0f;

    mout[12] = 0.0f;
    mout[13] = 0.0f;
    mout[14] = 2 * zFar * zNear /  (zNear-zFar);
    mout[15] = 0.0f;
}

我看到这个投影矩阵乘以旋转矩阵(通过motionManager.deviceMotion API获得)。 投影矩阵有什么用?为什么要和旋转矩阵相乘?

multiplyMatrixAndMatrix(projectionCameraTransform, projectionTransform, cameraTransform);

为什么结果矩阵必须再次与 PointOfInterest 向量坐标相乘?

multiplyMatrixAndVector(v, projectionCameraTransform, placesOfInterestCoordinates[i]);

在此感谢任何帮助。

示例代码 link here

最佳答案

在计算机视觉和机器人技术中,一个典型的任务是识别图像中的特定对象,并确定每个对象相对于某个坐标系的位置和方向(或平移和旋转)。

在增强现实中,我们通常会计算检测到的物体的姿态,然后在其上增强虚拟模型。如果我们知道检测到的物体的姿态,我们可以更真实地投影虚拟模型。

联合旋转平移矩阵 [R|t] 称为外部参数矩阵。它用于描述相机围绕静态场景的运动,反之亦然,静止相机前物体的刚性运动。也就是说,[R|t] 将点 (X, Y, Z) 的坐标转换为相对于相机固定的坐标系。这为您提供了移动 AR 所需的 6DOF 姿势(3 次旋转和 3 次平移)。

如果您想阅读更多内容,这是一本好书 http://games.ianterrell.com/learn-the-basics-of-opengl-with-glkit-in-ios-5/

抱歉,我只使用 Android AR。希望这会有所帮助:)

关于ios - 投影矩阵有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20992975/

相关文章:

ios - UITableViewCell 向右滑动触发 Action 或执行 segue

c++ - 通过循环删除 vector 的最后一个元素

c++ - 将 vector 作为参数传递并使用它,为什么会崩溃?

android - 如何在 Ubuntu 中运行 arcore android 模拟器

iphone - 产生两个数字的每个组合,例如 1000

ios - 解析 - 设置设备 token

java - 布局更改可见性

swift - 如何将Blender制作的动画加载到ARKit?

ios - objective-c - 帮助创建格式正则表达式 (#,#)

c++ - 二维随机单位 vector