opengl es - mat4.lookat webgl clips view -
mat4.lookat() below giving me unexpected results. please see images associated 3 test examples. first example "correct", , others seem clipped, cannot figure why. perspectives , distances camera seem correct on all, except first, not getting whole view want. can suggest need adjust this?
function draw() { gl.clearcolor(bgcolor[0],bgcolor[1],bgcolor[2],1); gl.clear(gl.color_buffer_bit | gl.depth_buffer_bit); if (document.getelementbyid("persproj").checked) { mat4.perspective(projection, math.pi/4, 1, 4, 8); } else { mat4.ortho(projection,-2.5, 2.5, -2.5, 2.5, 4, 8); } gl.uniformmatrix4fv(uprojection, false, projection ); mat4.lookat(modelview, [0,0,6], [0,0,0], [0,1,0]); // key line mat4.rotatex(modelview, modelview, rotatex); mat4.rotatey(modelview, modelview, rotatey); gl.uniformmatrix4fv(umodelview, false, modelview ); mat3.normalfrommat4(normalmatrix, modelview); gl.uniformmatrix3fv(unormalmatrix, false, normalmatrix); gl.uniform1i( ulit, 0 ); // lines representing coordinate axes not lit. gl.linewidth(4); drawprimitive( gl.lines, [1,0,0,1], [ -2,0,0, 2,0,0] ); drawprimitive( gl.lines, [0,1,0,1], [ 0,-2,0, 0,2,0] ); drawprimitive( gl.lines, [0,0,1,1], [ 0,0,-2, 0,0,2] ); gl.linewidth(1); if (leftcolors.length>0){ drawturtles(linecolors,moves,leftcolors,rightcolors,backcolors,bottoms,lefts,rights,backs,bottomns,leftns,rightns,backns); } } mat4.lookat(modelview, [0,0,6], [0,0,0], [0,1,0]) ![mat4.lookat(modelview, [0,0,6], [0,0,0], [0,1,0])](https://i.stack.imgur.com/cz89f.png)
mat4.lookat(modelview, [0,0,8], [0,0,0], [0,1,0]) ![mat4.lookat(modelview, [0,0,8], [0,0,0], [0,1,0])](https://i.stack.imgur.com/ka9oo.png)
mat4.lookat(modelview, [0,0,4], [0,0,0], [0,1,0]) ![mat4.lookat(modelview, [0,0,4], [0,0,0], [0,1,0])](https://i.stack.imgur.com/xuqcp.png)
the problem comes clipping distance set mat4.ortho:

mat4.lookat(modelview, [0,0,8], [0,0,0], [0,1,0])
this set eye position such far plane pass thru (0,0,0), limiting viewable content view plane on (0,0,0).
mat4.lookat(modelview, [0,0,4], [0,0,0], [0,1,0])
this set eye pos @ limit of near plane, giving unpredictable results when equal.
so solution adjust near , far clipping in mat4.ortho:
mat4.ortho(projection,-2.5, 2.5, -2.5, 2.5, 4 - x, 8 + x); where x minimal displacement.
Comments
Post a Comment