forked from edwardsjohnmartin/MagPhyx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomain.js
56 lines (51 loc) · 1.64 KB
/
domain.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
var Domain = function(gl_) {
// Set up vertices, normals and texture coords
var pointsArray = [];
const inc = 1;
for (var i = 0; i <= 360; i += inc) {
var theta = i * Math.PI / 180.0;
// y=0 means inner ring
// y=1 means outer ring
pointsArray.push(vec4(theta, 0.0, 0.0, 1.0));
pointsArray.push(vec4(theta, 1.0, 0.0, 1.0));
}
this.n = pointsArray.length;
this.vertexBuffer = gl_.createBuffer();
gl_.bindBuffer(gl_.ARRAY_BUFFER, this.vertexBuffer);
gl_.bufferData(gl_.ARRAY_BUFFER, flatten(pointsArray), gl_.STATIC_DRAW);
this.outlineColor = vec4(0, 0, 1, 1);
this.fillColor = vec4(0.95, 0.95, 1.0, 1.0);
}
Domain.prototype.segments = function(theta) {
var n = (theta/(2*Math.PI)) * 360 * 2;
var ret = [];
ret.push({ start:0, count:n });
ret.push({ start:180*2-n, count:n*2 });
ret.push({ start:361*2-n, count:(n+1) });
return ret;
}
Domain.prototype.wrappedSegments = function(theta_c, E_negative) {
var n = (theta_c/(2*Math.PI)) * 360 * 2;
var ret = [];
if (E_negative) {
ret.push({ start:0, count:n+4 });
ret.push({ start:180*2-n, count:n });
ret.push({ start:180*2+2, count:n+2 });
ret.push({ start:361*2-n-2, count:(n+1) });
} else {
ret.push({ start:0, count:n });
ret.push({ start:180*2-n+2, count:n });
ret.push({ start:180*2+2, count:n-2 });
ret.push({ start:361*2-n, count:(n+1) });
}
return ret;
}
Domain.prototype.unboundedSegments = function(theta_c, E_negative) {
var n = (theta_c/(2*Math.PI)) * 360 * 2;
var ret = [];
if (!E_negative) {
ret.push({ start:n-2, count:180*2-2*n+6 });
ret.push({ start:180*2+n-2, count:180*2-2*n+6 });
}
return ret;
}