Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Classe MyTriangle que cria primitivas do tipo triangle
- function MyTriangle(scene, values) {
- CGFobject.call(this, scene);
- //p1, p2 e p3 são os pontos que simbolizam cada vértice do triangulo
- var p1 = [values['x1'], values['y1'], values['z1']];
- var p2 = [values['x2'], values['y2'], values['z2']];
- var p3 = [values['x3'], values['y3'], values['z3']];
- this.indices = [0, 1, 2];
- this.vertices = [].concat.apply([], [p1, p2, p3]);
- this.a = Math.sqrt((p3[0] - p2[0]) * (p3[0] - p2[0]) +
- (p3[1] - p2[1]) * (p3[1] - p2[1]) +
- (p3[2] - p2[2]) * (p3[2] - p2[2]));
- this.b = Math.sqrt((p1[0] - p3[0]) * (p1[0] - p3[0]) +
- (p1[1] - p3[1]) * (p1[1] - p3[1]) +
- (p1[2] - p3[2]) * (p1[2] - p3[2]));
- this.c = Math.sqrt((p2[0] - p1[0]) * (p2[0] - p1[0]) +
- (p2[1] - p1[1]) * (p2[1] - p1[1]) +
- (p2[2] - p1[2]) * (p2[2] - p1[2]));
- var diffBA = vec3.create(); //cria array de tres elementos
- var diffCA = vec3.create();
- var normal = vec3.create();
- vec3.subtract(diffBA, p2, p1);
- vec3.subtract(diffCA, p3, p1);
- vec3.cross(normal, diffBA, diffCA); // produto vetorial, retorna array []
- vec3.normalize(normal, normal);
- this.normals = [
- normal[0], normal[1], normal[2],
- normal[0], normal[1], normal[2],
- normal[0], normal[1], normal[2]
- ];
- this.beta = Math.acos((this.a * this.a - this.b * this.b + this.c * this.c) / (2 * this.a * this.c));
- this.primitiveType = this.scene.gl.TRIANGLES;
- this.initGLBuffers();
- };
- MyTriangle.prototype = Object.create(CGFobject.prototype);
- MyTriangle.prototype.constructor = MyTriangle;
- //Função que atualiza as coordenadas de textura com base nos amplification factors
- MyTriangle.prototype.updateTexCoords = function (s, t) {
- this.texCoords = [
- 0.0, 0.0,
- this.c / s, 0.0,
- (this.c - this.a * Math.cos(this.beta)) / s, -(this.a * Math.sin(this.beta)) / t,
- ];
- this.updateTexCoordsGLBuffers();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement