mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 15:20:08 +02:00
awesome stuff
This commit is contained in:
parent
3b6cd4c2d1
commit
1f2d726211
1 changed files with 65 additions and 45 deletions
|
@ -1,44 +1,49 @@
|
||||||
//earthquakes_live.js
|
// earthquakes_live.js
|
||||||
//created by james b. pollack @imgntn on 12/5/2015
|
// exploratory implementation in prep for abstract latlong to earth graphing tool for VR
|
||||||
|
// shows all of the quakes in the past 24 hours reported by the USGS
|
||||||
|
// created by james b. pollack @imgntn on 12/5/2015
|
||||||
|
// working notes: maybe try doing markers as boxes,rotated to the sphere normal, and with the height representing some value
|
||||||
|
|
||||||
Script.include('../libraries/promise.js');
|
Script.include('../libraries/promise.js');
|
||||||
var Promise = loadPromise();
|
var Promise = loadPromise();
|
||||||
|
|
||||||
Script.include('../libraries/tinyColor.js');
|
Script.include('../libraries/tinyColor.js');
|
||||||
var tinyColor = loadTinyColor();
|
var tinyColor = loadTinyColor();
|
||||||
|
|
||||||
var EARTH_SPHERE_RADIUS = 5;
|
//you could make it the size of the actual earth.
|
||||||
|
var EARTH_SPHERE_RADIUS = 6371;
|
||||||
|
var EARTH_SPHERE_RADIUS = 2;
|
||||||
|
|
||||||
var EARTH_CENTER_POSITION = Vec3.sum(MyAvatar.position, {
|
var EARTH_CENTER_POSITION = Vec3.sum(MyAvatar.position, {
|
||||||
x: 5,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
z: 0
|
z: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
var EARTH_MODEL_URL='http://public.highfidelity.io/marketplace/hificontent/Scripts/planets/planets/earth.fbx';
|
var EARTH_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/earthquakes_live/models/earth-noclouds.fbx';
|
||||||
|
|
||||||
|
var POLL_FOR_CHANGES = false;
|
||||||
//USGS updates the data every five minutes
|
//USGS updates the data every five minutes
|
||||||
var CHECK_QUAKE_FREQUENCY = 300 * 1000;
|
var CHECK_QUAKE_FREQUENCY = 5 * 60 * 1000;
|
||||||
|
|
||||||
var QUAKE_MARKER_DIMENSIONS = {
|
var QUAKE_MARKER_DIMENSIONS = {
|
||||||
x: 0.1,
|
x: 0.01,
|
||||||
y: 0.1,
|
y: 0.01,
|
||||||
z: 0.1
|
z: 0.01
|
||||||
};
|
};
|
||||||
|
|
||||||
function createEarth() {
|
function createEarth() {
|
||||||
var earthProperties = {
|
var earthProperties = {
|
||||||
name: 'Earth',
|
name: 'Earth',
|
||||||
type: 'Model',
|
type: 'Model',
|
||||||
modelURL:EARTH_MODEL_URL,
|
modelURL: EARTH_MODEL_URL,
|
||||||
position: EARTH_CENTER_POSITION,
|
position: EARTH_CENTER_POSITION,
|
||||||
dimensions: {
|
dimensions: {
|
||||||
x: EARTH_SPHERE_RADIUS,
|
x: EARTH_SPHERE_RADIUS,
|
||||||
y: EARTH_SPHERE_RADIUS,
|
y: EARTH_SPHERE_RADIUS,
|
||||||
z: EARTH_SPHERE_RADIUS
|
z: EARTH_SPHERE_RADIUS
|
||||||
},
|
},
|
||||||
// color: {
|
rotation: Quat.fromPitchYawRollDegrees(0, 90, 0),
|
||||||
// red: 0,
|
|
||||||
// green: 100,
|
|
||||||
// blue: 150
|
|
||||||
// },
|
|
||||||
collisionsWillMove: false,
|
collisionsWillMove: false,
|
||||||
userData: JSON.stringify({
|
userData: JSON.stringify({
|
||||||
grabbableKey: {
|
grabbableKey: {
|
||||||
|
@ -50,26 +55,32 @@ function createEarth() {
|
||||||
return Entities.addEntity(earthProperties)
|
return Entities.addEntity(earthProperties)
|
||||||
}
|
}
|
||||||
|
|
||||||
function plotLatitudeLongitude(radiusOfSphere, latitude, longitude) {
|
function latLongToVector3(lat, lon, radius, height) {
|
||||||
var tx = radiusOfSphere * Math.cos(latitude) * Math.cos(longitude);
|
var phi = (lat) * Math.PI / 180;
|
||||||
var ty = radiusOfSphere * -Math.sin(latitude);
|
var theta = (lon - 180) * Math.PI / 180;
|
||||||
var tz = radiusOfSphere * Math.cos(latitude) * Math.sin(longitude);
|
|
||||||
|
var x = -(radius + height) * Math.cos(phi) * Math.cos(theta);
|
||||||
|
var y = (radius + height) * Math.sin(phi);
|
||||||
|
var z = (radius + height) * Math.cos(phi) * Math.sin(theta);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
x: tx,
|
x: x,
|
||||||
y: ty,
|
y: y,
|
||||||
z: tz
|
z: z
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getQuakePosition(earthquake) {
|
function getQuakePosition(earthquake) {
|
||||||
var latitude = earthquake.geometry.coordinates[0];
|
var longitude = earthquake.geometry.coordinates[0];
|
||||||
var longitude = earthquake.geometry.coordinates[1];
|
var latitude = earthquake.geometry.coordinates[1];
|
||||||
var latlng = plotLatitudeLongitude(2.5, latitude, longitude);
|
var depth = earthquake.geometry.coordinates[2];
|
||||||
|
|
||||||
|
var latlng = latLongToVector3(latitude, longitude, EARTH_SPHERE_RADIUS / 2, 0);
|
||||||
|
|
||||||
var position = EARTH_CENTER_POSITION;
|
var position = EARTH_CENTER_POSITION;
|
||||||
var finalPosition = Vec3.sum(position, latlng);
|
var finalPosition = Vec3.sum(position, latlng);
|
||||||
|
|
||||||
// print('finalpos::' + JSON.stringify(finalPosition))
|
print('finalpos::' + JSON.stringify(finalPosition))
|
||||||
return finalPosition
|
return finalPosition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,14 +106,9 @@ function get(url) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function showEarthquake(snapshot) {
|
|
||||||
var earthquake = snapshot.val();
|
|
||||||
print("Mag " + earthquake.mag + " at " + earthquake.place);
|
|
||||||
}
|
|
||||||
|
|
||||||
function createQuakeMarker(earthquake) {
|
function createQuakeMarker(earthquake) {
|
||||||
var markerProperties = {
|
var markerProperties = {
|
||||||
name: 'Marker',
|
name: earthquake.properties.place,
|
||||||
type: 'Sphere',
|
type: 'Sphere',
|
||||||
dimensions: QUAKE_MARKER_DIMENSIONS,
|
dimensions: QUAKE_MARKER_DIMENSIONS,
|
||||||
position: getQuakePosition(earthquake),
|
position: getQuakePosition(earthquake),
|
||||||
|
@ -110,7 +116,7 @@ function createQuakeMarker(earthquake) {
|
||||||
color: getQuakeMarkerColor(earthquake)
|
color: getQuakeMarkerColor(earthquake)
|
||||||
}
|
}
|
||||||
|
|
||||||
//print('marker properties::' + JSON.stringify(markerProperties))
|
print('marker properties::' + JSON.stringify(markerProperties))
|
||||||
return Entities.addEntity(markerProperties);
|
return Entities.addEntity(markerProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +143,7 @@ function scale(value, min1, max1, min2, max2) {
|
||||||
function processQuakes(earthquakes) {
|
function processQuakes(earthquakes) {
|
||||||
print('quakers length' + earthquakes.length)
|
print('quakers length' + earthquakes.length)
|
||||||
earthquakes.forEach(function(quake) {
|
earthquakes.forEach(function(quake) {
|
||||||
// print('PROCESSING A QUAKE')
|
// print('PROCESSING A QUAKE')
|
||||||
var marker = createQuakeMarker(quake);
|
var marker = createQuakeMarker(quake);
|
||||||
markers.push(marker);
|
markers.push(marker);
|
||||||
})
|
})
|
||||||
|
@ -147,16 +153,18 @@ function processQuakes(earthquakes) {
|
||||||
var quakea;
|
var quakea;
|
||||||
var markers = [];
|
var markers = [];
|
||||||
|
|
||||||
var earth = createEarth();
|
var earth = createEarth();
|
||||||
|
|
||||||
get(QUAKE_URL).then(function(response) {
|
function getThenProcessQuakes() {
|
||||||
print('got it::' + response.features.length)
|
get(QUAKE_URL).then(function(response) {
|
||||||
quakes = response.features;
|
print('got it::' + response.features.length)
|
||||||
processQuakes(quakes);
|
quakes = response.features;
|
||||||
//print("Success!" + JSON.stringify(response));
|
processQuakes(quakes);
|
||||||
}, function(error) {
|
//print("Success!" + JSON.stringify(response));
|
||||||
print('error getting quakes')
|
}, function(error) {
|
||||||
});
|
print('error getting quakes')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function cleanupMarkers() {
|
function cleanupMarkers() {
|
||||||
print('CLEANING UP MARKERS')
|
print('CLEANING UP MARKERS')
|
||||||
|
@ -170,4 +178,16 @@ function cleanupEarth() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.scriptEnding.connect(cleanupMarkers);
|
Script.scriptEnding.connect(cleanupMarkers);
|
||||||
Script.scriptEnding.connect(cleanupEarth);
|
Script.scriptEnding.connect(cleanupEarth);
|
||||||
|
|
||||||
|
//first draw
|
||||||
|
getThenProcessQuakes();
|
||||||
|
|
||||||
|
|
||||||
|
var pollingInterval;
|
||||||
|
if (POLL_FOR_CHANGES === true) {
|
||||||
|
pollingInterval = Script.setInterval(function() {
|
||||||
|
cleanupMarkers();
|
||||||
|
getThenProcessQuakes()
|
||||||
|
}, CHECK_QUAKE_FREQUENCY)
|
||||||
|
}
|
Loading…
Reference in a new issue