我用这个做我的相机
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 ) 并开始旋转,相机仍然围绕原点旋转,而不是围绕我当前所在的点旋转。