Skip to content

Commit 131095b

Browse files
Add screentop tracking mode support. (#319)
* Add screentop tracking mode support. * Fix swapping between HMD and screentop tracking modes. Adding example.
1 parent 5a89a25 commit 131095b

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

examples/optimizeHMDScreentop.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<html>
2+
<head>
3+
<title>HMD/Screentop Optimization - Leap</title>
4+
<script src="../leap-1.1.1.js"></script>
5+
<script>
6+
var controller = new Leap.Controller({optimizeScreentop: true}).connect();
7+
</script>
8+
</head>
9+
<body>
10+
<button onclick="controller.setOptimizeHMD(true);">controller.setOptimizeHMD(true);</button>
11+
<button onclick="controller.setOptimizeHMD(false);">controller.setOptimizeHMD(false);</button>
12+
<br/>
13+
<br/>
14+
<button onclick="controller.setOptimizeScreentop(true);">controller.setOptimizeScreentop(true);</button>
15+
<button onclick="controller.setOptimizeScreentop(false);">controller.setOptimizeScreentop(false);</button>
16+
<pre>
17+
<div id="out"></div>
18+
</pre>
19+
</body>
20+
</html>

leap-1.1.1.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ var BaseConnection = module.exports = function(opts) {
200200
port: this.getPort(),
201201
background: false,
202202
optimizeHMD: false,
203+
optimizeScreentop: false,
203204
requestProtocolVersion: BaseConnection.defaultProtocolVersion
204205
}, opts || {});
205206
this.host = this.opts.host;
@@ -208,12 +209,16 @@ var BaseConnection = module.exports = function(opts) {
208209
this.protocolVersionVerified = false;
209210
this.background = null;
210211
this.optimizeHMD = null;
212+
this.optimizeScreentop = null;
211213
this.on('ready', function() {
212214
this.setBackground(this.opts.background);
213215
this.setOptimizeHMD(this.opts.optimizeHMD);
216+
this.setOptimizeScreentop(this.opts.optimizeScreentop);
214217

215218
if (this.opts.optimizeHMD){
216219
console.log("Optimized for head mounted display usage.");
220+
}else if (this.opts.optimizeScreentop){
221+
console.log("Optimized for screentop usage.");
217222
}else {
218223
console.log("Optimized for desktop usage.");
219224
}
@@ -249,11 +254,21 @@ BaseConnection.prototype.setBackground = function(state) {
249254
BaseConnection.prototype.setOptimizeHMD = function(state) {
250255
this.opts.optimizeHMD = state;
251256
if (this.protocol && this.protocol.sendOptimizeHMD && this.optimizeHMD !== this.opts.optimizeHMD) {
257+
if (state === true) this.optimizeScreentop = false;
252258
this.optimizeHMD = this.opts.optimizeHMD;
253259
this.protocol.sendOptimizeHMD(this, this.opts.optimizeHMD);
254260
}
255261
}
256262

263+
BaseConnection.prototype.setOptimizeScreentop = function(state) {
264+
this.opts.optimizeScreentop = state;
265+
if (this.protocol && this.protocol.sendOptimizeScreentop && this.optimizeScreentop !== this.opts.optimizeScreentop) {
266+
if (state === true) this.optimizeHMD = false;
267+
this.optimizeScreentop = this.opts.optimizeScreentop;
268+
this.protocol.sendOptimizeScreentop(this, this.opts.optimizeScreentop);
269+
}
270+
}
271+
257272
BaseConnection.prototype.handleOpen = function() {
258273
if (!this.connected) {
259274
this.connected = true;
@@ -298,6 +313,7 @@ BaseConnection.prototype.disconnect = function(allowReconnect) {
298313
delete this.protocol;
299314
delete this.background; // This is not persisted when reconnecting to the web socket server
300315
delete this.optimizeHMD;
316+
delete this.optimizeScreentop;
301317
delete this.focusedState;
302318
if (this.connected) {
303319
this.connected = false;
@@ -590,6 +606,11 @@ Controller.prototype.setOptimizeHMD = function(state) {
590606
return this;
591607
}
592608

609+
Controller.prototype.setOptimizeScreentop = function(state) {
610+
this.connection.setOptimizeScreentop(state);
611+
return this;
612+
}
613+
593614
Controller.prototype.inBrowser = function() {
594615
return !this.inNode;
595616
}
@@ -2954,6 +2975,9 @@ exports.chooseProtocol = function(header) {
29542975
protocol.sendOptimizeHMD = function(connection, state) {
29552976
connection.send(protocol.encode({optimizeHMD: state}));
29562977
}
2978+
protocol.sendOptimizeScreentop = function(connection, state) {
2979+
connection.send(protocol.encode({optimizeScreentop: state}));
2980+
}
29572981
break;
29582982
default:
29592983
throw "unrecognized version";

leap-1.1.1.min.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)