mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-30 13:43:01 +02:00
Basically, when using the third person camera in HMD mode. If the controllers are shown. They should be shown in front of the users camera, not in front of the users avatar. To accomplish this, two new faux joint indices are introduced. CAMERA_RELATIVE_CONTROLLER_RIGHTHAND_INDEX and CAMERA_RELATIVE_CONTROLLER_LEFTHAND_INDEX. These joint indices can be used for Overlay parenting. (But not for entity parenting because they are not transmitted over the network). They can also be queried for by using the MyAvatar.getAbsoluteJointRotationInObjectFrame() call. These new indices are now used by the controllerDisplay.js for the hand controller rendering. They are also used by system/libraries/controllers.js as the origin for hand controller grabbing and interaction lasers.
65 lines
2.7 KiB
JavaScript
65 lines
2.7 KiB
JavaScript
// handControllerGrab.js
|
|
//
|
|
// Created by Seth Alves on 2016-9-7
|
|
// Copyright 2016 High Fidelity, Inc.
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
/* global MyAvatar, Vec3, Controller, Quat */
|
|
|
|
var GRAB_COMMUNICATIONS_SETTING = "io.highfidelity.isFarGrabbing";
|
|
setGrabCommunications = function setFarGrabCommunications(on) {
|
|
Settings.setValue(GRAB_COMMUNICATIONS_SETTING, on ? "on" : "");
|
|
}
|
|
getGrabCommunications = function getFarGrabCommunications() {
|
|
return !!Settings.getValue(GRAB_COMMUNICATIONS_SETTING, "");
|
|
}
|
|
|
|
// this offset needs to match the one in libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp:378
|
|
var GRAB_POINT_SPHERE_OFFSET = { x: 0.04, y: 0.13, z: 0.039 }; // x = upward, y = forward, z = lateral
|
|
|
|
getGrabPointSphereOffset = function(handController) {
|
|
if (handController === Controller.Standard.RightHand) {
|
|
return GRAB_POINT_SPHERE_OFFSET;
|
|
}
|
|
return {
|
|
x: GRAB_POINT_SPHERE_OFFSET.x * -1,
|
|
y: GRAB_POINT_SPHERE_OFFSET.y,
|
|
z: GRAB_POINT_SPHERE_OFFSET.z
|
|
};
|
|
};
|
|
|
|
// controllerWorldLocation is where the controller would be, in-world, with an added offset
|
|
getControllerWorldLocation = function (handController, doOffset) {
|
|
var orientation;
|
|
var position;
|
|
var pose = Controller.getPoseValue(handController);
|
|
var valid = pose.valid;
|
|
var controllerJointIndex;
|
|
if (pose.valid) {
|
|
if (handController === Controller.Standard.RightHand) {
|
|
controllerJointIndex = MyAvatar.getJointIndex("_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND");
|
|
} else {
|
|
controllerJointIndex = MyAvatar.getJointIndex("_CAMERA_RELATIVE_CONTROLLER_LEFTHAND");
|
|
}
|
|
orientation = Quat.multiply(MyAvatar.orientation, MyAvatar.getAbsoluteJointRotationInObjectFrame(controllerJointIndex));
|
|
position = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, MyAvatar.getAbsoluteJointTranslationInObjectFrame(controllerJointIndex)));
|
|
|
|
// add to the real position so the grab-point is out in front of the hand, a bit
|
|
if (doOffset) {
|
|
var offset = getGrabPointSphereOffset(handController);
|
|
position = Vec3.sum(position, Vec3.multiplyQbyV(orientation, offset));
|
|
}
|
|
|
|
} else if (!HMD.isHandControllerAvailable()) {
|
|
position = MyAvatar.getHeadPosition();
|
|
orientation = Quat.multiply(MyAvatar.headOrientation, Quat.angleAxis(-90, { x: 1, y: 0, z: 0 }));
|
|
valid = true;
|
|
}
|
|
|
|
return {position: position,
|
|
translation: position,
|
|
orientation: orientation,
|
|
rotation: orientation,
|
|
valid: valid};
|
|
};
|