Just showing you guys something cool I whipped up for fun. Enjoy ;D:
https://dl.dropbox.com/u/28109593/model-spin-test/webgl.html
Looking for some help with this. It’s easy code to understand.
My makeshift push/pop matrix code seems to have no effect at all, the model doesn’t translate to it’s position.
var savedMat = mat4.create();
savedMat.set(mvMatrix);
mat4.translate(mvMatrix, [model.x, model.y, model.z]);
gl.drawArrays(gl.TRIANGLES, 0, model.VertexPositionBuffer.numItems);
mvMatrix.set(savedMat);
I want the models to be drawn at their position/ and later on rotation, and not affect the mvMatrix (modelview matrix).
sudocode
create temp matrix
set temp matrix to modelview matrix
translate modelview matrix to model position
draw model
set modelview matrix to temp matrix
I have never worked with WebGL, but I googled 5 minutes.
var savedMat = mat4.create();
savedMat.set(mvMatrix);
mat4.translate(mvMatrix, [model.x, model.y, model.z]);
+ gl.uniformMatrix4fv(shaderProgram.pMatrixUniform, false, pMatrix);
+ gl.uniformMatrix4fv(shaderProgram.mvMatrixUniform, false, mvMatrix);
gl.drawArrays(gl.TRIANGLES, 0, model.VertexPositionBuffer.numItems);
mvMatrix.set(savedMat);
if it doesn’t work, switch the user!
Awesome, Riven! Thank you so much! ;D ;D ;D ;D
Edit: added in another model, and made it so you can rotate the camera with left and right arrows.
Runs smoothly on my computer with Chrome 20. Really nice! However, I do see some visual glitches like flickering :S
Flickering just looks like z-fighting on two or more overlapping identical polygons to me.
Cas
And now time for something a little different: http://pso2u.com/webgl.php (It’s a MS3d viewer, it will be animated later. if you get the error about DataView it means your browser don’t support it yet.)
Chrome 20 on Windows 7, all I see is a black box. Opening up the Chrome console, I see this error:
DataView is not supported in Firefox 13. Is the only browser you can view that in Chrome? Talk about bleeding edge.
I broke it :<