Skip to content

Commit

Permalink
Update globe tweeter with fake tweets
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedric Pinson committed Nov 3, 2011
1 parent 2828b18 commit 4712f24
Show file tree
Hide file tree
Showing 441 changed files with 2,804 additions and 960 deletions.
Binary file added img/tweet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 39 additions & 8 deletions js/app.js
Expand Up @@ -18,16 +18,18 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Authors:
* Cedric Pinson <cedric.pinson@plopbyte.net>
* Cedric Pinson <cedric.pinson@plopbyte.com>
*
*/

var FakeTweets;
var Socket;
var LastTweetReceived = new Date();
var ConnectionTimeoutCheck = 6;
var ConnectionTimeoutCheck = 10;
var CheckNetworkTimeout;
var NbCheckNetworkTimeout = 0;
var StreamConnected = 0;

function startNetwork() {
try {
jQuery('#connection').show();
Expand All @@ -44,17 +46,32 @@ function startNetwork() {
var elapsed = (now.getTime()-LastTweetReceived.getTime())/1000.0;
if (elapsed > ConnectionTimeoutCheck) {
//showConnection();
osg.log("no tweets received for " + ConnectionTimeoutCheck +" seconds, restart connection");
startNetwork();
return;
osg.log("no tweets received for " + ConnectionTimeoutCheck +" seconds");
if (NbCheckNetworkTimeout > 3) {
osg.log("no tweets received for " + ConnectionTimeoutCheck*3 +" seconds, restart connection");
if ( Socket !== undefined) {
Socket.connect();
} else {
startNetwork();
}
NbCheckNetworkTimeout = 0;
return;
} else {
showConnection();
}
NbCheckNetworkTimeout += 1;
//startNetwork();
//return;
} else {
NbCheckNetworkTimeout = 0;
}
CheckNetworkTimeout = setTimeout(checkNetwork, ConnectionTimeoutCheck*1000);
}
};

// change here to point to your socket.io server
var socket = new io.Socket("184.106.112.6",{ port: 22048 }, {transports:['websocket', 'htmlfile', 'xhr-polling']});
//var socket = new io.Socket(document.location.hostname);
//var socket = new io.Socket("184.106.112.6",{ port: 22048 });
var socket = new io.Socket(document.location.hostname, {transports:['websocket', 'flashsocket', 'htmlfile', 'xhr-polling']} );
Socket = socket;
socket.connect();
socket.on('message', function(message){
Expand All @@ -63,6 +80,7 @@ function startNetwork() {
processTweet(message);
});
socket.on('connect', function(message){
Connected = true;
StreamConnected += 1;
if (StreamConnected === 1) {
showInstructions();
Expand All @@ -73,10 +91,23 @@ function startNetwork() {
//checkNetwork();
});
socket.on('disconnect', function(message){
Socket = undefined;
if (DemoState.running === true) {
showConnection();
osg.log("disconnect, try to reconnect");

if ( Socket !== undefined) {
Socket.connect();
} else {
startNetwork();
}
}
});
socket.on('error', function(message) {
osg.log("error, try to reconnect");
showConnection();
if ( Socket !== undefined) {
Socket.connect();
} else {
startNetwork();
}
});
Expand Down
44 changes: 34 additions & 10 deletions js/demo2.js
Expand Up @@ -447,7 +447,7 @@ TweetDisplayCallback.prototype = {
var rr = 1.0 - (this.manipulator.height-this.limit) * 0.8/(2.5*this.WGS_84_RADIUS_EQUATOR-this.limit);
scale *= rr;
}
node.setMatrix(osg.Matrix.mult(osg.Matrix.makeScale(scale, scale, scale),node.originalMatrix));
node.setMatrix(osg.Matrix.mult(node.originalMatrix, osg.Matrix.makeScale(scale, scale, scale), []));
}

var value = (1.0 - osgAnimation.EaseInQuad(ratio));
Expand Down Expand Up @@ -520,7 +520,7 @@ YouAreHereDisplayCallback.prototype = {
var rr = 1.0 - (this.manipulator.height-this.limit) * 0.8/(2.5*this.WGS_84_RADIUS_EQUATOR-this.limit);
scale *= rr;
}
node.setMatrix(osg.Matrix.mult(osg.Matrix.makeScale(scale, scale, scale),node.originalMatrix));
node.setMatrix(osg.Matrix.mult(node.originalMatrix, osg.Matrix.makeScale(scale, scale, scale), []));

//var uniform = node.uniform;
//var value2 = 1.0 - osgAnimation.EaseInQuad(ratio);
Expand Down Expand Up @@ -761,12 +761,30 @@ function displayHtmlTweetContent(tweet)

function createScene()
{
var optionsURL = function() {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
};

var getHeightShader = getHeightShaderVolume;
var numTexturesAvailableInVertexShader = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS);
osg.log("Nb Texture Unit in vertex shader " + numTexturesAvailableInVertexShader);
if (numTexturesAvailableInVertexShader < 1) {
osg.log("VolumeWave disabled because your OpenGL implementation has " + numTexturesAvailableInVertexShader + " vertex texture units and wave option require at least 1");
var options = optionsURL();
if (options['WaveFlat'] === "1") {
getHeightShader = getHeightShaderFlat;
} else {

var numTexturesAvailableInVertexShader = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS);
osg.log("Nb Texture Unit in vertex shader " + numTexturesAvailableInVertexShader);
if (numTexturesAvailableInVertexShader < 1) {
osg.log("VolumeWave disabled because your OpenGL implementation has " + numTexturesAvailableInVertexShader + " vertex texture units and wave option require at least 1");
getHeightShader = getHeightShaderFlat;
}
}

jQuery("#background").val(num2hex([0,0,0,0]));
Expand All @@ -789,6 +807,7 @@ function createScene()
var country = osg.ParseSceneGraph(getCountry());
var coast = osg.ParseSceneGraph(getCoast());


world.setStateSet(getWorldShader());
world.setNodeMask(2);
world.getOrCreateStateSet().setAttributeAndMode(new osg.CullFace('FRONT'));
Expand Down Expand Up @@ -822,7 +841,7 @@ function createScene()
scene.addChild(world);
scene.addChild(world1);
scene.addChild(country);

// scene.addChild(frontTweets);


world.getOrCreateStateSet().setAttributeAndMode(new osg.BlendFunc('ONE', 'ONE_MINUS_SRC_ALPHA'));
Expand Down Expand Up @@ -1003,7 +1022,6 @@ function createScene()
var globalDuration = (new Date()).getTime()/1000.0;

var consumeTweet = function(tweet) {
//osg.log(tweet);
var displayTweet = function(location, tweet) {

if (numberOfTweets % 5 === 0) {
Expand Down Expand Up @@ -1095,8 +1113,14 @@ function createScene()
}
}
};
img.src = tweet.user.profile_image_url;
//img.src = "http://plopbyte.net/tmp/ff-demo/line.png";
//img.src = tweet.user.profile_image_url;
// temporary
var src = "img/tweet.png";
if (StreamConnected === 0) {
var basename = tweet.user.profile_image_url.split('/').pop();
src = "localtweets/" + basename;
}
img.src = src;
}
};

Expand Down
10 changes: 5 additions & 5 deletions js/manipulator.js
Expand Up @@ -90,14 +90,14 @@ osgGA.OrbitManipulator2.prototype = {
scale = this.scale;

var of = osg.Matrix.makeRotate(dx * scale, 0,0,1);
var r = osg.Matrix.mult(of, this.rotation);
var r = osg.Matrix.mult(this.rotation, of, []);

of = osg.Matrix.makeRotate(dy * scale/2.0, 1,0,0);
var r2 = osg.Matrix.mult(r, of);
var r2 = osg.Matrix.mult(of,r, []);

// test that the eye is not too up and not too down to not kill
// the rotation matrix
var eye = osg.Matrix.transformVec3([0, 0, this.distance], osg.Matrix.inverse(r2));
var eye = osg.Matrix.transformVec3(osg.Matrix.inverse(r2), [0, 0, this.distance]);
if (eye[2] > 0.99*this.distance || eye[2] < -0.99*this.distance) {
//discard rotation on y
this.rotation = r;
Expand Down Expand Up @@ -449,7 +449,7 @@ osgGA.OrbitManipulator2.prototype = {
distance = this.distance;
target = this.target;
var qCurrent = this.getGoToLocationQuaternion();
eye = osg.Matrix.transformVec3([0, 0, distance], osg.Matrix.makeRotateFromQuat(qCurrent));
eye = osg.Matrix.transformVec3(osg.Matrix.makeRotateFromQuat(qCurrent), [0, 0, distance]);
this.eye = eye;
inv = osg.Matrix.makeLookAt(osg.Vec3.add(target,eye), target, [0,0,1]);

Expand Down Expand Up @@ -485,7 +485,7 @@ osgGA.OrbitManipulator2.prototype = {
}

//this.targetMotion
eye = osg.Matrix.transformVec3([0, 0, distance], osg.Matrix.inverse(this.rotation));
eye = osg.Matrix.transformVec3(osg.Matrix.inverse(this.rotation), [0, 0, distance]);
this.eye = eye;
inv = osg.Matrix.makeLookAt(osg.Vec3.add(target,eye), target, [0,0,1]);
}
Expand Down

0 comments on commit 4712f24

Please sign in to comment.