mirror of
https://github.com/overte-org/overte.git
synced 2025-06-21 20:41:52 +02:00
Adjusted tablet spawn position and orientation to be more natural
This commit is contained in:
parent
c8382e6853
commit
c6f3eb138a
1 changed files with 30 additions and 12 deletions
|
@ -29,20 +29,36 @@ var HOME_BUTTON_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-home
|
||||||
// * rotation - rotation of entity so it faces the user.
|
// * rotation - rotation of entity so it faces the user.
|
||||||
function calcSpawnInfo(hand, height) {
|
function calcSpawnInfo(hand, height) {
|
||||||
var noHands = -1;
|
var noHands = -1;
|
||||||
if (HMD.active && hand != noHands) {
|
var finalPosition;
|
||||||
var handController = getControllerWorldLocation(hand, false);
|
if (HMD.active && hand !== noHands) {
|
||||||
|
var handController = getControllerWorldLocation(hand, true);
|
||||||
var controllerPosition = handController.position;
|
var controllerPosition = handController.position;
|
||||||
var originalOrientation = Quat.lookAt(controllerPosition, HMD.position, Y_AXIS);
|
|
||||||
var yDisplacement = (height/2) + 0.2;
|
// compute the angle of the chord with length (height / 2)
|
||||||
var tabletOffset = Vec3.multiplyQbyV(Quat.lookAt(controllerPosition, HMD.position, Y_AXIS), {x: 0, y: yDisplacement, z: -0.2});
|
var theta = Math.asin(height / (2 * Vec3.distance(HMD.position, controllerPosition)));
|
||||||
var finalPosition = Vec3.sum(controllerPosition, tabletOffset);
|
|
||||||
|
// then we can use this angle to rotate the vector between the HMD position and the center of the tablet.
|
||||||
|
// this vector, u, will become our new look at direction.
|
||||||
|
var d = Vec3.normalize(Vec3.subtract(HMD.position, controllerPosition));
|
||||||
|
var w = Vec3.normalize(Vec3.cross(Y_AXIS, d));
|
||||||
|
var q = Quat.angleAxis(theta * (180 / Math.PI), w);
|
||||||
|
var u = Vec3.multiplyQbyV(q, d);
|
||||||
|
|
||||||
|
// use u to compute a full lookAt quaternion.
|
||||||
|
var lookAtRot = Quat.lookAt(controllerPosition, Vec3.sum(controllerPosition, u), Y_AXIS);
|
||||||
|
|
||||||
|
// adjust the tablet position by a small amount.
|
||||||
|
var yDisplacement = (height / 2) + 0.1;
|
||||||
|
var zDisplacement = 0.05;
|
||||||
|
var tabletOffset = Vec3.multiplyQbyV(lookAtRot, {x: 0, y: yDisplacement, z: zDisplacement});
|
||||||
|
finalPosition = Vec3.sum(controllerPosition, tabletOffset);
|
||||||
return {
|
return {
|
||||||
position: finalPosition,
|
position: finalPosition,
|
||||||
rotation: Quat.lookAt(finalPosition, HMD.position, Y_AXIS)
|
rotation: lookAtRot
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
var front = Quat.getFront(MyAvatar.orientation);
|
var front = Quat.getFront(MyAvatar.orientation);
|
||||||
var finalPosition = Vec3.sum(Vec3.sum(MyAvatar.position, Vec3.multiply(0.6, front)), {x: 0, y: 0.6, z: 0});
|
finalPosition = Vec3.sum(Vec3.sum(MyAvatar.position, Vec3.multiply(0.6, front)), {x: 0, y: 0.6, z: 0});
|
||||||
return {
|
return {
|
||||||
position: finalPosition,
|
position: finalPosition,
|
||||||
rotation: Quat.lookAt(finalPosition, MyAvatar.getHeadPosition(), Y_AXIS)
|
rotation: Quat.lookAt(finalPosition, MyAvatar.getHeadPosition(), Y_AXIS)
|
||||||
|
@ -111,7 +127,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly) {
|
||||||
setEntityCustomData('grabbableKey', this.homeButtonEntity, {wantsTrigger: true});
|
setEntityCustomData('grabbableKey', this.homeButtonEntity, {wantsTrigger: true});
|
||||||
|
|
||||||
this.receive = function (channel, senderID, senderUUID, localOnly) {
|
this.receive = function (channel, senderID, senderUUID, localOnly) {
|
||||||
if (_this.homeButtonEntity == senderID) {
|
if (_this.homeButtonEntity === senderID) {
|
||||||
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
tablet.gotoHomeScreen();
|
tablet.gotoHomeScreen();
|
||||||
}
|
}
|
||||||
|
@ -128,7 +144,9 @@ WebTablet = function (url, width, dpi, hand, clientOnly) {
|
||||||
};
|
};
|
||||||
this.clicked = false;
|
this.clicked = false;
|
||||||
|
|
||||||
this.myOnHmdChanged = function () { _this.onHmdChanged(); };
|
this.myOnHmdChanged = function () {
|
||||||
|
_this.onHmdChanged();
|
||||||
|
};
|
||||||
HMD.displayModeChanged.connect(this.myOnHmdChanged);
|
HMD.displayModeChanged.connect(this.myOnHmdChanged);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue