如何在Matrix中添加相机剪辑视锥?

时间:2019-04-20 04:59:26

标签: webgl frustum

如何将“平截头体”剪切平面添加到“相机视图矩阵”中?我对如何将其添加到“相机矩阵”感到困惑,因此它会修剪正交视图的边缘。该javascript是从更大的应用程序中提取的,因此实际上并未在沙盒中运行。我很抱歉。如果有人可以提供一个可以转换为代码的沙盒示例,我将不胜感激,因为在网上搜索m4.frustum信息返回的结果很少。

var m4 = twgl.m4;
var zoom = 1;
var gridW = 17;
var gridH = 13;
var tilesize = 16;
var webglwidth = this.webgl.canvas.width / zoom;
var webglheight = this.webgl.canvas.height / zoom;

var screenW = gridW -2;
var screenH = gridH -2;

this.orthMatrix2 = m4.ortho(
0, 1, 
0, 1,
0, -1);

var cameraMatrix = m4.rotationY(Math.PI);
cameraMatrix = m4.rotateZ(cameraMatrix, Math.PI);

var clipCameraW = -2;
var clipCameraH = -2;

cameraMatrix = m4.scale(cameraMatrix, [1/screenW, 1/screenH, 1]);

// Some Camera Translation shifting code here removed for readability.

cameraMatrix = m4.scale(cameraMatrix, [screenW, screenH, 1]);

// Here I want to make the Camera Frustum clip the edges so scrolling will be smooth.
//cameraFrustum = m4.frustum(1/this.camera.gridW,(screenW)/this.camera.gridW,
//                         1/this.camera.gridH,(screenH)/this.camera.gridH,0,1); // ?
// cameraMatrix = m4.multiply(cameraMatrix, cameraFrustum); // ?

webgl.viewport(0,0, webgl.canvas.width, webgl.canvas.height);

var viewProjectionMatrix = m4.multiply(this.orthMatrix2, cameraMatrix);

// Final viewProjectionMatrix for webgl's uniformMatrix4fv.
// Call DrawArrays etc.

0 个答案:

没有答案