Advertisement
Guest User

Render

a guest
Apr 24th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var renderLeft = function () {
  2.     gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
  3.  
  4.     const width = gl.canvas.width;
  5.     const height = gl.canvas.height;
  6.     const displayWidth = gl.canvas.clientWidth;
  7.     const displayHeight = gl.canvas.clientHeight;
  8.  
  9.     const dispWidth = displayWidth / 2;
  10.     const dispHeight = displayHeight;
  11.     const aspect = dispWidth / dispHeight;
  12.     const top = 1;
  13.     const bottom = -top;
  14.     const right = top * aspect;
  15.     const left = -right;
  16.  
  17.     pMatrix = ortho(left, right, bottom, ytop, near, far);
  18.     gl.clearColor(0.2, 0.2, 0.2, 1);
  19.  
  20.     gl.viewport(0, 0, width / 2, height, pMatrix);
  21.     gl.scissor(0, 0, width / 2, height, pMatrix);
  22.  
  23.     gl.uniformMatrix4fv(projection, false, flatten(pMatrix));
  24.  
  25.  
  26.     // pMatrix = ortho(left, right, bottom, ytop, near, far);
  27.     eye = vec3(radius * Math.sin(phi), radius * Math.sin(theta), radius * Math.cos(phi));
  28.  
  29.     mvMatrix = lookAt(eye, at, up);
  30.  
  31.     translationMatrix = translate(translateX, translateY, translateZ);
  32.     mvMatrix = mult(mvMatrix, translationMatrix);
  33.  
  34.     scalingMatrix = scalem(scale, scale, scale);
  35.     mvMatrix = mult(mvMatrix, scalingMatrix);
  36.  
  37.     if (flag) thetaR[axis] += 2.0;
  38.     mvMatrix = mult(mvMatrix, rotate(thetaR[xAxis], [1, 0, 0]));
  39.     mvMatrix = mult(mvMatrix, rotate(thetaR[yAxis], [0, 1, 0]));
  40.     mvMatrix = mult(mvMatrix, rotate(thetaR[zAxis], [0, 0, 1]));
  41.  
  42.  
  43.     // gl.uniformMatrix4fv(projection, false, flatten(pMatrix));
  44.     gl.uniformMatrix4fv(modelView, false, flatten(mvMatrix));
  45.  
  46.  
  47.     gl.drawArrays(gl.TRIANGLES, 0, numVertices);
  48.  
  49.     renderRight();
  50.     requestAnimFrame(renderLeft);
  51. }
  52.  
  53. var renderRight = function () {
  54.     gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
  55.  
  56.     const width = gl.canvas.width;
  57.     const height = gl.canvas.height;
  58.     const displayWidth = gl.canvas.clientWidth;
  59.     const displayHeight = gl.canvas.clientHeight;
  60.  
  61.     const dispWidthP = displayWidth / 2;
  62.     const dispHeightP = displayHeight;
  63.     const aspectP = dispWidthP / dispHeightP;
  64.     const pMatrix = perspective(fovy, aspectP, near, far);
  65.     gl.clearColor(0.1, 0.1, 0.1, 1);
  66.  
  67.     gl.viewport(width / 2, 0, width / 2, height, pMatrix);
  68.     gl.scissor(width / 2, 0, width / 2, height, pMatrix);
  69.  
  70.     gl.uniformMatrix4fv(projection, false, flatten(pMatrix));
  71.  
  72.  
  73.     eye = vec3(radius * Math.sin(phi), radius * Math.sin(theta), radius * Math.cos(phi));
  74.  
  75.     mvMatrix = lookAt(eye, at, up);
  76.  
  77.     translationMatrix = translate(translateX, translateY, translateZ);
  78.     mvMatrix = mult(mvMatrix, translationMatrix);
  79.  
  80.     scalingMatrix = scalem(scale, scale, scale);
  81.     mvMatrix = mult(mvMatrix, scalingMatrix);
  82.  
  83.     if (flag) thetaR[axis] += 2.0;
  84.     mvMatrix = mult(mvMatrix, rotate(thetaR[xAxis], [1, 0, 0]));
  85.     mvMatrix = mult(mvMatrix, rotate(thetaR[yAxis], [0, 1, 0]));
  86.     mvMatrix = mult(mvMatrix, rotate(thetaR[zAxis], [0, 0, 1]));
  87.  
  88.  
  89.     // gl.uniformMatrix4fv(projection, false, flatten(pMatrix));
  90.     gl.uniformMatrix4fv(modelView, false, flatten(mvMatrix));
  91.  
  92.  
  93.     gl.drawArrays(gl.TRIANGLES, 0, numVertices);
  94.  
  95.     renderLeft();
  96.     requestAnimFrame(renderRight);
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement