@@ -40,6 +40,23 @@ void main() {
40
40
// get start and end positions
41
41
vec2 startPos = aPositions.xy;
42
42
vec2 endPos = aPositions.zw;
43
+ // get signed horizontal distance between start and end positions
44
+ float a = endPos.x - startPos.x;
45
+ // determine if the path the particle takes should wrap around the
46
+ // pacific ocean
47
+ if (startPos.x < 0.5 && endPos.x > 0.5 ) {
48
+ float b = (1.0 - endPos.x) + startPos.x;
49
+ if (a > b) {
50
+ // wrap endpoint west around the pacific
51
+ endPos.x -= 1.0 ;
52
+ }
53
+ } else if (startPos.x > 0.5 && endPos.x < 0.5 ) {
54
+ float b = startPos.x - (1.0 + endPos.x);
55
+ if (a < b) {
56
+ // wrap endpoint east around the pacific
57
+ endPos.x += 1.0 ;
58
+ }
59
+ }
43
60
// get difference vector and distance
44
61
vec2 diff = endPos - startPos;
45
62
float dist = length ( diff );
@@ -62,6 +79,9 @@ void main() {
62
79
float t = mod ( uTime + tOffset, nSpeed ) / nSpeed;
63
80
// set point size
64
81
gl_PointSize = uPointSize;
65
- // set position
66
- gl_Position = uProjectionMatrix * vec4 ( getBezier(t, startPos, p1, p2, endPos), 0.0 , 1.0 );
82
+ // get position along the curve
83
+ vec2 pos = getBezier(t, startPos, p1, p2, endPos);
84
+ // set position, be sure to modulos it so that it does not extent beyond
85
+ // the bounds of the map.
86
+ gl_Position = uProjectionMatrix * vec4 ( mod (pos.x, 1.0 ), pos.y, 0.0 , 1.0 );
67
87
}
0 commit comments