handControllerMouse.js: transform hand controllers into sensor frame

This commit is contained in:
Anthony J. Thibault 2016-03-07 18:42:52 -08:00
parent 3d71226f72
commit 26b4c904f3

View file

@ -57,6 +57,7 @@ var filteredRotatedRight = Vec3.UNIT_NEG_Y;
Script.update.connect(function(deltaTime) {
// avatar frame
var poseRight = Controller.getPoseValue(Controller.Standard.RightHand);
var poseLeft = Controller.getPoseValue(Controller.Standard.LeftHand);
@ -65,12 +66,13 @@ Script.update.connect(function(deltaTime) {
var screenSizeX = screenSize.x;
var screenSizeY = screenSize.y;
var rotatedRight = Vec3.multiplyQbyV(poseRight.rotation, Vec3.UNIT_NEG_Y);
var rotatedLeft = Vec3.multiplyQbyV(poseLeft.rotation, Vec3.UNIT_NEG_Y);
// transform hand facing vectors from avatar frame into sensor frame.
var worldToSensorMatrix = Mat4.inverse(MyAvatar.sensorToWorldMatrix);
var rotatedRight = Mat4.transformVector(worldToSensorMatrix, Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.multiplyQbyV(poseRight.rotation, Vec3.UNIT_NEG_Y)));
var rotatedLeft = Mat4.transformVector(worldToSensorMatrix, Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.multiplyQbyV(poseLeft.rotation, Vec3.UNIT_NEG_Y)));
lastRotatedRight = rotatedRight;
// Decide which hand should be controlling the pointer
// by comparing which one is moving more, and by
// tending to stay with the one moving more.
@ -121,5 +123,3 @@ Script.update.connect(function(deltaTime) {
Script.scriptEnding.connect(function(){
mapping.disable();
});