通过修改相机窗口进行放大

时间:2016-10-02 16:07:57

标签: webgl

我正在进行一项工作,我需要实现一个放大按钮。以下是初始化场景的代码:

// select the viewport
gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);

// reset the modelview matrix
mvMatrix.setIdentity(); // erase all prior transformations

// select the view window (projection camera)
var left=-boardW/2.0, right=boardW/2.0, bottom=-boardH/2.0, top=boardH/2.0, near=0, far=10;
pMatrix.setIdentity();
pMatrix.ortho(left,right,bottom,top,near,far);
mvMatrix.multiply(pMatrix);

// set the camera position and orientation (viewing transformation)
var eyeX=0, eyeY=0, eyeZ=10;
var centerX=0, centerY=0, centerZ=0;
var upX=0, upY=1, upZ=0;
mvMatrix.lookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);

教授说应该通过改变相机窗口来完成缩放,这样如果窗口较小,图像就会显得更大。

这是我在缩放功能中所做的:

function zoomIn() {

var eyeX=0, eyeY=0, eyeZ=(10 * (scaleFactor + 0.1));
var centerX=0, centerY=0, centerZ=0;
var upX=0, upY=1, upZ=0;
mvMatrix.lookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);

}

scaleFactor的初始值为1.但是,当我单击缩放按钮时,我的图像会消失。有谁知道我做错了什么?这不是在改变相机窗口吗?

0 个答案:

没有答案