0

好的,所以我在 0,0,0 处绘制了一个块,并且我有这个 glulookat

function ugluLookAtf(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz){
        var forward = new Array(3); 
        var side = new Array(3); 
        var up = new Array(3);
        var m = new Array(4);
        for(var i = 0; i < m.length; i++){
            m[i] = new Array(m.length)
        }

        forward[0] = centerx - eyex;
        forward[1] = centery - eyey;
        forward[2] = centerz - eyez;

        var f = Math.sqrt(forward[0]*forward[0]+forward[1]*forward[1]+forward[2]*forward[2]);

        forward[0] =  forward[0]/f;
        forward[1] =  forward[1]/f;
        forward[2] =  forward[2]/f;

        up[0] = upx;
        up[1] = upy;
        up[2] = upz;

        side[0] = forward[1] * up[2] - up[1] * forward[2];
        side[1] = forward[2] * up[0] - up[2] * forward[0];
        side[2] = forward[0] * up[1] - up[0] * forward[1];

        var f = Math.sqrt(side[0]*side[0]+side[1]*side[1]+side[2]*side[2]);

        side[0] =  side[0]/f;
        side[1] =  side[1]/f;
        side[2] =  side[2]/f;

        up[0] = forward[1] * side[2] - side[1] * forward[2];
        up[1] = forward[2] * side[0] - side[2] * forward[0];
        up[2] = forward[0] * side[1] - side[0] * forward[1];

        __identf(m[0][0]);
        m[0][0] = side[0];
        m[1][0] = side[1];
        m[2][0] = side[2];

        m[0][1] = up[0];
        m[1][1] = up[1];
        m[2][1] = up[2];

        m[0][2] = -forward[0];
        m[1][2] = -forward[1];
        m[2][2] = -forward[2];

        glMultMatrixf(m[0][0]);
        glTranslatef(-eyex, -eyey, -eyez);
    }

被调用:ugluLookAtf(0,0,-10,0,0,0,0,1,0);

然而我什么也没看到,所以我认为这是我的 glulookat 函数。

我的问题是,我是否正确地为 glulookat 做数学?

4

1 回答 1

1

由于这是javascript,glMultMatrixf(m[0][0])没有意义。glMultMatrixf只使用左上角的数字会做什么?

C 版本接受一个指针,它可以增加它以获取矩阵的其他元素。在 Javascript 中,这是行不通的。

于 2012-06-27T15:29:31.887 回答