-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgIShape.js
81 lines (66 loc) · 2.01 KB
/
cgIShape.js
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
class cgIShape {
constructor () {
this.points = [];
this.bary = [];
this.normals = [];
this.indices = [];
this.uv = [];
}
addTriangle (x0,y0,z0,x1,y1,z1,x2,y2,z2) {
var nverts = this.points.length / 3;
// push first vertex
this.points.push(x0); this.bary.push (1.0);
this.points.push(y0); this.bary.push (0.0);
this.points.push(z0); this.bary.push (0.0);
//this.points.push(1.0);
this.indices.push(nverts);
nverts++;
// push second vertex
this.points.push(x1); this.bary.push (0.0);
this.points.push(y1); this.bary.push (1.0);
this.points.push(z1); this.bary.push (0.0);
//this.points.push(1.0);
this.indices.push(nverts);
nverts++
// push third vertex
this.points.push(x2); this.bary.push (0.0);
this.points.push(y2); this.bary.push (0.0);
this.points.push(z2); this.bary.push (1.0);
//this.points.push(1.0);
this.indices.push(nverts);
nverts++;
}
addNormal (x0,y0,z0,x1,y1,z1,x2,y2,z2) {
// push first normal
this.normals.push(x0);
this.normals.push(y0);
this.normals.push(z0);
//this.normals.push(1.0);
// push second normal
this.normals.push(x1);
this.normals.push(y1);
this.normals.push(z1);
//this.normals.push(1.0);
// push third normal
this.normals.push(x2);
this.normals.push(y2);
this.normals.push(z2);
//this.normals.push(1.0);
}
adduv (u0, v0, u1, v1, u2, v2) {
// push first uv
this.uv.push(u0);
this.uv.push(v0);
// push second uv
this.uv.push(u1);
this.uv.push(v1);
// push third uv
this.uv.push(u2);
this.uv.push(v2);
}
}
function radians(degrees)
{
var pi = Math.PI;
return degrees * (pi/180);
}