Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript webgl中的相机平滑旋转_Javascript_Webgl_Gl Matrix - Fatal编程技术网

Javascript webgl中的相机平滑旋转

Javascript webgl中的相机平滑旋转,javascript,webgl,gl-matrix,Javascript,Webgl,Gl Matrix,我已经实现了一个简单版本的相机。它的唯一目的是环视场景(这意味着只有旋转)。 每一帧我都会更新mat4.lookAt和mat4.perspective(),但在移动设备(如android)上,移动感觉很慢。 这就是我如何计算横摆和俯仰: rotate(ev) { let xOffSet = ev.center.x - this._lastX; let YOffSet = this._lastY - ev.center.y; this._lastX = ev.center

我已经实现了一个简单版本的相机。它的唯一目的是环视场景(这意味着只有旋转)。 每一帧我都会更新
mat4.lookAt
mat4.perspective
(),但在移动设备(如android)上,移动感觉很慢。 这就是我如何计算横摆和俯仰:

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;
}
使用更新的
偏航
俯仰
我重新计算
矩阵

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);
}

有什么办法可以改进我的相机吗?或者你会做一些完全不同的事情?如果是,您会做什么更改?

是否更新requestAnimationFrame中的视图?是的,我有一个渲染函数,它调用requestAnimationFrame。请尝试将您的
偏移量
乘以从上一帧经过的时间。好的,我将尝试此操作。如果此工作方式是您应用程序的FPS,将更新我的问题?也许这就是问题所在。是否在requestAnimationFrame中更新视图?是的,我有一个渲染函数,它调用requestAnimationFrame。请尝试将您的
偏移量
乘以从上一帧经过的时间。好的,我将尝试此操作。如果此工作方式是您应用程序的FPS,将更新我的问题?也许这就是问题所在。