我已经实现了一个简单版本的相机。它的唯一目的是环顾场景(这意味着只有旋转)。我更新的每一帧都是mat4.lookAt
and mat4.perspective
(javascript数学库),但在移动设备(fe android)上,移动感觉很迟钝。这就是我计算的方式yaw
和pitch
:
rotate(ev) {
let xOffSet = ev.center.x - this._lastX;
let YOffSet = this._lastY - ev.center.y;
this._lastX = ev.center.x;
this._lastY = ev.center.y;
let sensitivity = 0.005;
xOffSet *= sensitivity;
YOffSet *= sensitivity;
this._yaw += xOffSet;
this._pitch += YOffSet;
}
并随着更新yaw
,pitch
我重新计算matrices
:
updateViewProjMatrix() {
let gl = Core.mGetGL();
this._frontVector[0] = Math.cos(this._yaw) * Math.cos(this._pitch);
this._frontVector[1] = Math.sin(this._pitch);
this._frontVector[2] = Math.sin(this._yaw) * Math.cos(this._pitch);
vec3.normalize(this._lookAtVector, this._frontVector);
vec3.add(this._lookAtVector, this._lookAtVector, this._positionVector);
mat4.lookAt(this._viewMatrix, this._positionVector, this._lookAtVector, this._upVector);
mat4.perspective(this._projMatrix, this._fov * Math.PI / 180, gl.canvas.clientWidth / gl.canvas.clientHeight, this._nearPlane, this._farPlane);
mat4.multiply(this._vpMatrix, this._projMatrix, this._viewMatrix);
}
有什么方法可以改进我的相机吗?或者你会做一些完全不同的事情吗?如果是这样,你会改变什么?