3

我用这个做我的相机

library.Camera = function Camera(PosX, PosY, PosZ, Pitch, Yaw){
    this.x = PosX;
    this.y = PosY;
    this.z = PosZ;
    this.pitch = Pitch;
    this.yaw = Yaw;

    this.getCameraMatrix = function(ModelMatrix){

        var TMatrix = ModelMatrix;

        mat4.translate(TMatrix, TMatrix, [this.x, this.y, this.z]);

        mat4.rotateX(TMatrix, TMatrix, degToRad(this.pitch));
        mat4.rotateY(TMatrix, TMatrix, degToRad(this.yaw));
        return TMatrix;

    };
};

移动效果很好,即使旋转也有点效果。问题是鼠标的旋转总是围绕原点旋转。因此,如果我向左移动 (-x ) 并开始旋转,相机仍然围绕原点旋转,而不是围绕我当前所在的点旋转。

http://glmatrix.net/docs/2.2.0/symbols/mat4.html

4

1 回答 1

3

One should always remember that linear transformations are not commutative, this simply mean that if you rotate then translate you get different result then if you translate then rotate.

In your case putting rotation before translation should solve the problem.

于 2013-07-15T17:33:43.973 回答