iOS:据我所知,GLKit矩阵乘法已中断 [英] iOS: GLKit matrix multiplication is broken as far as I can tell

查看:154
本文介绍了iOS:据我所知,GLKit矩阵乘法已中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是源代码. ANSWER是正确答案,RESULT是实际结果.

Here's the source code. ANSWER is the correct answer, RESULT is the actual result.

我是盲人,还是应该为1计算条目33-1?

Am I blind, or is it calculating a -1 for entry 33 when it should be a 1?

代码如下:

GLKMatrix4 a = GLKMatrix4Make(-1.000000, 0.000000, 0.000000, 0.000000,
        0.000000, 1.000000, 0.000000, 0.000000,
        0.000000, 0.000000, -1.000000, 0.000000,
        0.000000, 0.000000, 0.000000, 1.000000);

GLKMatrix4 b = GLKMatrix4Make(1.000000, 0.000000, 0.000000, 0.000000,
        0.000000, 1.000000, 0.000000, -1.000000,
        0.000000, 0.000000, 1.000000, -1.000000,
        0.000000, 0.000000, 0.000000, 1.000000);

GLKMatrix4 ANSWER = GLKMatrix4Make(-1.000000, 0.000000, 0.000000, 0.000000,
        0.000000, 1.000000, 0.000000, -1.000000,
        0.000000, 0.000000, -1.000000, 1.000000,
        0.000000, 0.000000, 0.000000, 1.000000);

NSLog(@"##################################################");
GLKMatrix4 RESULT = GLKMatrix4Multiply(a,b);
NSLog(@"Result:");
NSLog(@"    %f %f %f %f",RESULT.m00,RESULT.m01,RESULT.m02,RESULT.m03);
NSLog(@"    %f %f %f %f",RESULT.m10,RESULT.m11,RESULT.m12,RESULT.m13);
NSLog(@"    %f %f %f %f",RESULT.m20,RESULT.m21,RESULT.m22,RESULT.m23);
NSLog(@"    %f %f %f %f",RESULT.m30,RESULT.m31,RESULT.m32,RESULT.m33);
NSLog(@"Answer:");
NSLog(@"    %f %f %f %f",ANSWER.m00,ANSWER.m01,ANSWER.m02,ANSWER.m03);
NSLog(@"    %f %f %f %f",ANSWER.m10,ANSWER.m11,ANSWER.m12,ANSWER.m13);
NSLog(@"    %f %f %f %f",ANSWER.m20,ANSWER.m21,ANSWER.m22,ANSWER.m23);
NSLog(@"    %f %f %f %f",ANSWER.m30,ANSWER.m31,ANSWER.m32,ANSWER.m33);
NSLog(@"##################################################");

这是输出:

##################################################
Result:
    -1.000000 0.000000 0.000000 0.000000
    0.000000 1.000000 0.000000 -1.000000
    0.000000 0.000000 -1.000000 -1.000000
    0.000000 0.000000 0.000000 1.000000
Answer:
    -1.000000 0.000000 0.000000 0.000000
    0.000000 1.000000 0.000000 -1.000000
    0.000000 0.000000 -1.000000 1.000000
    0.000000 0.000000 0.000000 1.000000
##################################################

我花了最后5个小时尝试调试一些OpenGL代码,才发现这是问题所在.我肯定会想念一些东西.任何人都可以发现正在发生的事情,或者验证是否应该发生这种情况?

I've spent the last 5 hours trying to debug some OpenGL code only to find this is the problem. I must be missing something, surely. Can anyone spot what's going on, or verify this shouldn't be happening?

推荐答案

嗯,我得到的结果与您的结果"矩阵相同.

Um, I got the same result as your "RESULT" matrix.

我按照以下规则用纸和笔进行矩阵乘法:

I did the matrix multiplication with pen and paper, following these rules:

http://www.mathsisfun.com/algebra/matrix-multiplying.html

这是我使用您的两个矩阵a和b进行的操作:

This is how I did it using your two matrix a and b:

好的,我想我知道您出了错,您必须在错误的位置列出数字:

OK, I think I know where you went wrong, you must have listed the numbers in the wrong position:

在代码中列出数字的方式是水平的,例如Coordinate(x,y,z),但是在矩阵中,这些数字会移动到垂直位置.

The way you list the number in code is horizontal e.g Coordinate(x,y,z) but in a Matrix, these numbers get moved to vertical positions.

因此,例如[X Y Z W]应该垂直:

So for example, [ X Y Z W ] should become vertically:

现在如果,我们将在错误的位置列出您的数字,并将矩阵a与矩阵b相乘,我们得到的答案与您的答案"矩阵相同:

Now IF we were to list the your numbers in the wrong position and multiply Matrix a with Matrix b, we get the same answer as your "ANSWER" matrix:

这篇关于iOS:据我所知,GLKit矩阵乘法已中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆