Skip to content

Commit

Permalink
winds.
Browse files Browse the repository at this point in the history
  • Loading branch information
philogb committed Feb 24, 2012
1 parent 14edfaf commit 7177cca
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -4,4 +4,4 @@
*.rar
TODO
_docs
data/*.html
examples/winds/data/*.html
Binary file modified examples/winds/data/weather.bin
Binary file not shown.
11 changes: 7 additions & 4 deletions examples/winds/data/weather_data.py
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
26 changes: 17 additions & 9 deletions examples/winds/index.js
Expand Up @@ -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,
Expand All @@ -221,6 +225,10 @@ function init() {

gl.drawElements(TRIANGLES, indicesLength, UNSIGNED_SHORT, 0);
}

//disable blend
gl.disable(gl.BLEND);
gl.enable(gl.DEPTH_TEST);
}
});
}
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 13 additions & 5 deletions examples/winds/shaders/markers.fs.glsl
Expand Up @@ -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);
}
}

35 changes: 33 additions & 2 deletions examples/winds/shaders/markers.vs.glsl
Expand Up @@ -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;
Expand All @@ -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.;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 7177cca

Please sign in to comment.