diff --git a/.gitignore b/.gitignore index 7a7e2caa..e3a13231 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ *.rar TODO _docs -data/*.html +examples/winds/data/*.html diff --git a/examples/winds/data/weather.bin b/examples/winds/data/weather.bin index ad8668ad..5401ddb9 100644 Binary files a/examples/winds/data/weather.bin and b/examples/winds/data/weather.bin differ diff --git a/examples/winds/data/weather_data.py b/examples/winds/data/weather_data.py index 02a572e0..dc10e35f 100644 --- a/examples/winds/data/weather_data.py +++ b/examples/winds/data/weather_data.py @@ -64,8 +64,6 @@ def parsefiles(): with open('weather.bin', 'w') as fout: for entry in entries: code = entry['icao'] - - print code #read html file for station with open(code + '.html', 'r') as fentry: @@ -74,16 +72,21 @@ def parsefiles(): trs = soup.findAll('tr', align='center', valign='top') ln = len(trs) counter = 0 + count = 0 if ln == 0: step = 1 ln = samples empty = True else: - step = samples / float(ln) + step = ln / float(samples) empty = False - while counter < ln: + print code, counter, ln, step + + while count < samples: + count += 1 + if empty: dat = struct.pack('HHH', 0, 0, 0) fout.write(dat) diff --git a/examples/winds/index.js b/examples/winds/index.js index 9722cd0e..3dddc186 100644 --- a/examples/winds/index.js +++ b/examples/winds/index.js @@ -196,16 +196,20 @@ function init() { weather = data.hour[hour], l = stations.length; - O3D.Plane.call(this, { type: 'x,y', xlen: 1, ylen: 1, offset: 0, - program: 'marker', + program: 'markers', textures: ['img/elevation_3764_2048_post.jpg'], render: function(gl, program, camera) { + //enable blend + gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); + gl.enable(gl.BLEND); + gl.disable(gl.DEPTH_TEST); + for (var i = 0, TRIANGLES = gl.TRIANGLES, indicesLength = this.$indicesLength, @@ -221,6 +225,10 @@ function init() { gl.drawElements(TRIANGLES, indicesLength, UNSIGNED_SHORT, 0); } + + //disable blend + gl.disable(gl.BLEND); + gl.enable(gl.DEPTH_TEST); } }); } @@ -254,14 +262,14 @@ function init() { } }).send(); - function createHourlyData(data, i, l, hours, components) { - var len = data.length, + function createHourlyData(bufferData, i, l, hours, components) { + var len = bufferData.length, array = Array(l); - - for (var j = i, singleCount = 0; j < len; j += (hours * components)) { - array[count] = new Float32Array([data[j ], - data[j + 1], - data[j + 2]]); + + for (var j = i, count = 0; j < len; j += (hours * components)) { + array[count++] = new Float32Array([bufferData[j ], + bufferData[j + 1], + bufferData[j + 2]]); } return array; diff --git a/examples/winds/shaders/markers.fs.glsl b/examples/winds/shaders/markers.fs.glsl index f7a7769d..76ac26ce 100644 --- a/examples/winds/shaders/markers.fs.glsl +++ b/examples/winds/shaders/markers.fs.glsl @@ -2,13 +2,21 @@ precision highp float; #endif -uniform vec3 data; +#define PI 3.1415926535 + +varying vec2 vTexCoord; +varying vec3 vColor; void main(void) { - /* float angle = data.x * PI2;*/ - /* float windSpeed = data.y * delta / 5.;*/ + /* float angle = data.x * PI / 2.;*/ + /* float windSpeed = data.y * .2 / 5.;*/ /* float temp = data.z;*/ - - gl_FragColor = vec4(.2, 1, .2, 1); + + float dist = distance(vTexCoord, vec2(.5, .5)); + if (dist <= .5) { + gl_FragColor = vec4(vColor, dist * dist + .2); + } else { + gl_FragColor = vec4(0, 0, 0, 0); + } } diff --git a/examples/winds/shaders/markers.vs.glsl b/examples/winds/shaders/markers.vs.glsl index 783076b5..b98a2f32 100644 --- a/examples/winds/shaders/markers.vs.glsl +++ b/examples/winds/shaders/markers.vs.glsl @@ -11,6 +11,9 @@ uniform float lat; uniform float lon; uniform vec3 data; +varying vec2 vTexCoord; +varying vec3 vColor; + float getHue(vec4 sampling) { float r = sampling.r; float g = sampling.g; @@ -34,10 +37,36 @@ float getHue(vec4 sampling) { return hue; } +vec3 getRGB(float h, float s, float v) { + float c = v * s; + float hp = h / 60.; + float x = c * (1. - abs( mod(hp, 2.) - 1. )); + vec3 rgbp; + + if (h < 1.) { + rgbp = vec3(c, x, 0); + } else if (h < 2.) { + rgbp = vec3(x, c, 0); + } else if (h < 3.) { + rgbp = vec3(0, c, x); + } else if (h < 4.) { + rgbp = vec3(0, x, c); + } else if (h < 5.) { + rgbp = vec3(x, 0, c); + } else { + rgbp = vec3(c, 0, x); + } + + float m = v - c; + + return rgbp + vec3(m); +} + void main(void) { - vec3 pos = vec3(lat, lon, 0); + vec3 pos = vec3(lon, lat, 0); - const float scale = 0.02; + float scale = data.y / 300.; + float h = data.z / 250.; const float offset = (4096. - 3764.) / 2. * (1. / 4096.); const float fromy = 25.; @@ -75,6 +104,8 @@ void main(void) { pos = vec3(position.xy * scale, 0) + pos; + vTexCoord = texCoord1; + vColor = getRGB((1. - h) * 360., .8, .8); gl_Position = projectionMatrix * worldMatrix * vec4(pos, 1); }