• API
• FAQ
• Tools
• Archive
A Pastebin account makes a great Christmas gift
SHARE
TWEET

# Untitled

a guest Oct 22nd, 2017 74 Never
ENDING IN00days00hours00mins00secs

1. //Classe MyTriangle que cria primitivas do tipo triangle
2. function MyTriangle(scene, values) {
3.
4.     CGFobject.call(this, scene);
5.
6.     //p1, p2 e p3 são os pontos que simbolizam cada vértice do triangulo
7.     var p1 = [values['x1'], values['y1'], values['z1']];
8.     var p2 = [values['x2'], values['y2'], values['z2']];
9.     var p3 = [values['x3'], values['y3'], values['z3']];
10.
11.     this.indices = [0, 1, 2];
12.     this.vertices = [].concat.apply([], [p1, p2, p3]);
13.
14.     this.a = Math.sqrt((p3[0] - p2[0]) * (p3[0] - p2[0]) +
15.                        (p3[1] - p2[1]) * (p3[1] - p2[1]) +
16.                        (p3[2] - p2[2]) * (p3[2] - p2[2]));
17.
18.     this.b = Math.sqrt((p1[0] - p3[0]) * (p1[0] - p3[0]) +
19.                        (p1[1] - p3[1]) * (p1[1] - p3[1]) +
20.                        (p1[2] - p3[2]) * (p1[2] - p3[2]));
21.
22.     this.c = Math.sqrt((p2[0] - p1[0]) * (p2[0] - p1[0]) +
23.                        (p2[1] - p1[1]) * (p2[1] - p1[1]) +
24.                        (p2[2] - p1[2]) * (p2[2] - p1[2]));
25.
26.
27.
28.
29.     var diffBA = vec3.create(); //cria array de tres elementos
30.     var diffCA = vec3.create();
31.     var normal = vec3.create();
32.
33.     vec3.subtract(diffBA, p2, p1);
34.     vec3.subtract(diffCA, p3, p1);
35.     vec3.cross(normal, diffBA, diffCA); // produto vetorial, retorna array []
36.     vec3.normalize(normal, normal);
37.
38.
39.     this.normals = [
40.         normal[0], normal[1], normal[2],
41.         normal[0], normal[1], normal[2],
42.         normal[0], normal[1], normal[2]
43.     ];
44.
45.
46.     this.beta = Math.acos((this.a * this.a - this.b * this.b + this.c * this.c) / (2 * this.a * this.c));
47.     this.primitiveType = this.scene.gl.TRIANGLES;
48.     this.initGLBuffers();
49.  };
50.
51. MyTriangle.prototype = Object.create(CGFobject.prototype);
52. MyTriangle.prototype.constructor = MyTriangle;
53.
54. //Função que atualiza as coordenadas de textura com base nos amplification factors
55. MyTriangle.prototype.updateTexCoords = function (s, t) {
56.
57.     this.texCoords = [
58.         0.0, 0.0,
59.         this.c / s, 0.0,
60.         (this.c - this.a * Math.cos(this.beta)) / s, -(this.a * Math.sin(this.beta)) / t,
61.     ];
62.
63.     this.updateTexCoordsGLBuffers();
64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top