Permalink
Browse files

Committing all experimental AR features etc

  • Loading branch information...
1 parent ca0a44d commit 62cb0cbeaf58f3f5ff9e13b405e810ca48edb1ba @samluescher samluescher committed May 22, 2012
View
@@ -22,6 +22,7 @@ fps = 80.0
open_sockets = []
socket_options = {}
+min_dist = 0.025
if ARGV.length > 0:
@@ -36,11 +37,26 @@ if ARGV.length > 0:
end
end
+def vector_dist(v1, v2)
+ xd = v1[0] - v2[0]
+ yd = v1[1] - v2[1]
+ zd = v1[2] - v2[2]
+ return Math.sqrt(xd*xd + yd*yd + zd*zd)
+end
+def tag_different(tag1, tag2, min_dist)
+ for cmp in ['loc', 'norm', 'over']:
+ if vector_dist(tag1[cmp], tag2[cmp]) > min_dist:
+ return true
+ end
+ end
+ return false;
+end
Thread.abort_on_exception = true
ingests_tags = {}
ingests_tracks = {}
+sent_tags = {}
for pool in pools:
Thread.new do
@@ -67,29 +83,37 @@ Thread.new do
loop {
next_time = Time.now
timeDelta = next_time - prev_time
- if timeDelta >= targetTimeDelta
+ if min_dist != 0 or timeDelta >= targetTimeDelta
for socket in open_sockets
send_tags = nil
send_tracks = nil
if ingests_tags:
send_tags = {}
for tag in watch_tags[socket]
- if ingests_tags[tag]
- send_tags[tag] = ingests_tags[tag]
+ if ingests_tags[tag]:
+ if (not sent_tags[socket].include?(tag)) or tag_different(sent_tags[socket][tag], ingests_tags[tag], min_dist):
+ if sent_tags[socket].include?(tag):
+ #puts 'is different: '+(tag_different(sent_tags[socket][tag], ingests_tags[tag])
+ end
+ send_tags[tag] = ingests_tags[tag]
+ sent_tags[socket][tag] = ingests_tags[tag]
+ end
end
end
end
if track[socket]:
send_tracks = ingests_tracks
end
send_data = {}
- if send_tags:
+ if send_tags and send_tags.length > 0:
send_data['tags'] = send_tags
end
- if send_tracks:
+ if send_tracks and send_tracks.length > 0:
send_data['tracks'] = send_tracks
end
- socket.send(send_data.to_json)
+ if send_data.length > 0:
+ socket.send(send_data.to_json)
+ end
end
prev_time = next_time
end
@@ -104,6 +128,7 @@ EventMachine::WebSocket.start(:host => host, :port => port, :debug => debug) do
puts "WebSocket connected"
open_sockets.push(ws)
watch_tags[ws] = []
+ sent_tags[ws] = {}
}
ws.onclose {
EM.cancel_timer(timer)
@@ -15,6 +15,11 @@
var receivedMilli = [];
var sampleSize = 50;
+ var getMilli = function() {
+ d = new Date();
+ return Date.UTC(d.getYear(), d.getMonth(), d.getDay(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
+ };
+
var connect = function()
{
ws = new Socket("ws://18.85.58.62:8080/");
@@ -33,9 +38,7 @@
console.log('broadcast message received '+evt.data);
return;
}
- d = new Date();
- var ms = Date.UTC(d.getYear(), d.getMonth(), d.getDay(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
- receivedMilli.push(ms);
+ receivedMilli.push(getMilli());
if (receivedMilli.length > sampleSize) {
receivedMilli.shift();
}
@@ -64,7 +67,7 @@
connect();
var displayFps = function() {
if (receivedMilli.length > 1 ) {
- fps = receivedMilli.length / ((receivedMilli[receivedMilli.length - 1] - receivedMilli[0]) / 1000.0);
+ fps = receivedMilli.length / ((getMilli() - receivedMilli[0]) / 1000.0);
document.getElementById("fps").innerHTML = Math.round(fps) + ' fps';
}
setTimeout(displayFps, 500);
@@ -9,7 +9,6 @@
#import "ARViewController.h"
#import "WGLAppDelegate.h"
-
@interface ARViewController ()
@end
@@ -32,7 +31,7 @@ - (void)viewDidLoad
[super viewDidLoad];
webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;
- webView.scrollView.scrollEnabled = NO;
+ //webView.scrollView.scrollEnabled = NO;
webView.scrollView.bounces = NO;
id webDocumentView = [webView performSelector:@selector(_browserView)];
@@ -49,7 +48,9 @@ - (void)viewDidLoad
[backingWebView _setWebGLEnabled:YES];
- [self loadUrl:@"http://18.85.59.187:8124/hY0VgozaeoY4NQp/globe/?lens_tag=1" addToHistory:YES];
+ [self loadUrl:@"http://18.189.26.244:8124/Oeq6NkK0FTmkPRG/globe/?lens_tag=1" addToHistory:YES];
+ [self loadUrl:@"http://18.189.26.244:8124/Oeq6NkK0FTmkPRG/globe/?lens_tag=1&loupe=1" addToHistory:YES];
+ [self loadUrl:@"http://18.189.26.244:8124/" addToHistory:YES];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showUrlBar:)];
[tapRecognizer setNumberOfTapsRequired:3];
@@ -71,7 +72,6 @@ - (void)loadUrl:(NSString *)url addToHistory:(bool)addToHistory {
urlField.text = url;
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:10];
- webView.hidden = YES;
[webView loadRequest:request];
NSLog(@"load url %@", url);
@@ -90,7 +90,8 @@ - (IBAction)urlEntered {
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
- [hud show:YES];
+ //[hud show:YES];
+ //webView.hidden = YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
@@ -132,6 +133,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
+ if ([error code] == NSURLErrorCancelled) {
+ return;
+ }
[hud hide:YES];
NSString *message = [error.userInfo objectForKey:@"NSLocalizedDescription"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
Oops, something went wrong. Retry.

0 comments on commit 62cb0cb

Please sign in to comment.