4

我目前正在开发自己的增强现实应用程序。我正在尝试编写自己的 AR 引擎,因为到目前为止我看到的所有框架都只能用于 GPS 数据。它将在室内使用,我正在从另一个系统获取我的位置数据。

到目前为止,我所拥有的是:

        float[] vector = { 2, 2, 1, 0 };
        float transformed[] = new float[4];
        float[] R = new float[16];
        float[] I = new float[16];
        float[] r = new float[16];
        float[] S = { 400f, 1, 1, 1, 1, -240f, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
        float[] B = { 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 400f, 240f, 1, 1 };
        float[] temp1 = new float[16];
        float[] temp2 = new float[16];
        float[] frustumM  = {1.5f,0,0,0,0,-1.5f,0,0,0,0,1.16f,1,0,0,-3.24f,0};

        //Rotationmatrix to get transformation for device to world coordinates
        SensorManager.getRotationMatrix(R, I, accelerometerValues, geomagneticMatrix);
        SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_X, SensorManager.AXIS_Z, r);
        //invert to get transformation for world to camera
        Matrix.invertM(R, 0, r, 0);
        Matrix.multiplyMM(temp1, 0, frustumM, 0, R, 0);
        Matrix.multiplyMM(temp2, 0, S, 0, temp1, 0);
        Matrix.multiplyMM(temp1, 0, B, 0, temp2, 0);

        Matrix.multiplyMV(transformed, 0, temp1, 0, vector, 0);

我知道它丑陋的代码,但我只是想让对象“向量”得到正确绘制,我的位置现在是 (0,0,0)。我的屏幕尺寸硬编码在矩阵 S 和 B (800x480) 中。

结果应该存储在“转换”中,并且应该采用像 transform = {x,y,z,w} 这样的形式对于数学,我使用了这个链接: http: //www.inf.fu-berlin.de /lehre/WS06/19605_Computergrafik/doku/rossbach_siewert/camera.html

有时我的图形被绘制了,但它会跳来跳去并且不在正确的位置。我已经用 SensorManager.getOrientation 记录了滚动,它们看起来不错且稳定。

所以我认为我做错了数学,但我找不到更好的数学来源来转换我的数据。有人可以帮我吗?提前致谢

马丁

4

0 回答 0