90 lines
2.9 KiB
JavaScript
90 lines
2.9 KiB
JavaScript
|
|
// viveTouchpadTest.js
|
|
//
|
|
// Anthony J. Thibault
|
|
// Copyright 2016 High Fidelity, Inc.
|
|
//
|
|
// An example of reading touch and move events from the vive controller touch pad.
|
|
//
|
|
// It will spawn a gray cube in front of you, then as you use the right touch pad,
|
|
// the cube should turn green and respond to the motion of your thumb on the pad.
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
|
|
|
|
var prevThumbDown_R = false;
|
|
var prevThumbDown_L = false;
|
|
|
|
function init() {
|
|
|
|
}
|
|
|
|
function shutdown() {
|
|
}
|
|
Script.scriptEnding.connect(shutdown);
|
|
|
|
function viveIsConnected() {
|
|
return Controller.Hardware.Vive;
|
|
}
|
|
|
|
function update(dt) {
|
|
if (viveIsConnected()) {
|
|
|
|
// Right controller
|
|
var thumbDown_R = Controller.getValue(Controller.Hardware.Vive.RSTouch);
|
|
if (thumbDown_R) {
|
|
var x_r = Controller.getValue(Controller.Hardware.Vive.RX);
|
|
var y_r = Controller.getValue(Controller.Hardware.Vive.RY);
|
|
var angle_r = Math.Atan2(x_r, y_r) * 180 / Math.PI;
|
|
console.log("Right controller angle: " + angle_r);
|
|
}
|
|
if (thumbDown_R && !prevThumbDown_R) {
|
|
console.log("Right controller thumbdown && !prevThumbDown");
|
|
}
|
|
if (!thumbDown_R && prevThumbDown_R) {
|
|
console.log("Right controller thumbdown && prevThumbDown");
|
|
}
|
|
prevThumbDown_R = thumbDown_R;
|
|
|
|
|
|
// LEFT CONTROLLER
|
|
var thumbDown_L = Controller.getValue(Controller.Hardware.Vive.LSTouch);
|
|
if (thumbDown_L) {
|
|
let x_l = Controller.getValue(Controller.Hardware.Vive.LX);
|
|
var y_l = Controller.getValue(Controller.Hardware.Vive.LY);
|
|
var angle_l = Math.Atan2(x_l, y_l) * 180 / Math.PI;
|
|
console.log("Left controller angle: " + angle_l);
|
|
}
|
|
if (thumbDown_L && !prevThumbDown_L) {
|
|
console.log("Left controller thumbdown && !prevThumbDown");
|
|
}
|
|
if (!thumbDown_L && prevThumbDown_L) {
|
|
console.log("Left controller thumbdown && prevThumbDown");
|
|
}
|
|
|
|
// 5 sectors numbered 0-4
|
|
var sector_r = 0;
|
|
if (angle_r > 72) {sector_r = 1;}
|
|
if (angle_r > 72*2) {sector_r = 2;}
|
|
if (angle_r > 72*3) {sector_r = 3;}
|
|
if (angle_r > 72*4) {sector_r = 4;}
|
|
|
|
|
|
// 5 sectors numbered 0-4
|
|
var sector_l = 0;
|
|
if (angle_l > 72) {sector_l = 1;}
|
|
if (angle_l > 72*2) {sector_l = 2;}
|
|
if (angle_l > 72*3) {sector_l = 3;}
|
|
if (angle_l > 72*4) {sector_l = 4;}
|
|
|
|
console.log("Sector_L "+sector_l+", Sector_R "+sector_r);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
Script.update.connect(update);
|
|
|
|
init();
|