1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| function drawScene() {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
parametre();
if(lumiere) {
gl.uniform3f(
shaderProgram.ambientColorUniform,
parseFloat(document.getElementById("ambientR").value),
parseFloat(document.getElementById("ambientG").value),
parseFloat(document.getElementById("ambientB").value)
);
gl.uniform3f(
shaderProgram.pointLightingLocationUniform,
parseFloat(document.getElementById("lightPositionX").value),
parseFloat(document.getElementById("lightPositionY").value),
parseFloat(document.getElementById("lightPositionZ").value)
);
gl.uniform3f(
shaderProgram.pointLightingSpecularColorUniform,
parseFloat(document.getElementById("specularR").value),
parseFloat(document.getElementById("specularG").value),
parseFloat(document.getElementById("specularB").value)
);
gl.uniform3f(
shaderProgram.pointLightingDiffuseColorUniform,
parseFloat(document.getElementById("diffuseR").value),
parseFloat(document.getElementById("diffuseG").value),
parseFloat(document.getElementById("diffuseB").value)
);
}
// Gestion de la transparence
if(blending) {
gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
gl.enable(gl.BLEND);
gl.disable(gl.DEPTH_TEST);
gl.uniform1f(shaderProgram.alphaUniform, parseFloat(document.getElementById("alpha").value));
}
else {
gl.disable(gl.BLEND);
gl.enable(gl.DEPTH_TEST);
}
mat4.identity(mvMatrix);
// Déplacement sur chaque axe
mat4.translate(mvMatrix, [0, 0, z]);
mat4.translate(mvMatrix, [0, y_t, 0]);
mat4.translate(mvMatrix, [x_t, 0, 0]);
// Rotation de l'objet
mat4.multiply(mvMatrix, rotationMatrix);
if(tourner) {
mat4.rotate(mvMatrix, degToRad(rCube), [1, 0, -1]);
}
// Le dessin
mvPushMatrix();
// Permet de dessiner un cube
if(cube) {
Objet3D.webGLCube();
var mvPickMatrix = Matrix.create([
[mvMatrix[0],mvMatrix[4],mvMatrix[8],mvMatrix[12]],
[mvMatrix[1],mvMatrix[5],mvMatrix[9],mvMatrix[13]],
[mvMatrix[2],mvMatrix[6],mvMatrix[10],mvMatrix[14]],
[mvMatrix[3],mvMatrix[7],mvMatrix[11],mvMatrix[15]],
]);
// Sélection d'un objet
if(doPick) {
pick = picking(mvPickMatrix);
if(pick == true) {
alert("cube cliqué !");
}
}
}
// Permet de dessiner une sphere
if(sphere) {
Objet3D.webGLSphere();
}
// Dessiner un objet quelconque
if(objet) {
Objet3D.webGLObj();
}
// Dessiner une theire
if(theiere) {
Objet3D.webGLTeapot();
}
mvPopMatrix();
doPick = false;
// Afficher le nombre d'images/sec
// framerate.snapshot();
if (current_time < 0)
last_time = new Date().getTime();
last_time = current_time;
current_time = new Date().getTime();
var fps = 1000.0 / (current_time - last_time);
fps = Math.round(fps);
tab[i] = fps;
i++;
} |
Partager