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
[在固定點OpenGL上旋轉]的可能重複(http://stackoverflow.com/questions/8360107/rotating-on-a-fixed-point-opengl) –