mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 05:52:38 +02:00
Merge pull request #10538 from ctrlaltdavid/21345
Position tablet relative to hand
This commit is contained in:
commit
8e62bdea40
1 changed files with 24 additions and 19 deletions
|
@ -43,7 +43,7 @@ var LOCAL_TABLET_MODEL_PATH = Script.resourcesPath() + "meshes/tablet-with-home-
|
|||
// returns object with two fields:
|
||||
// * position - position in front of the user
|
||||
// * rotation - rotation of entity so it faces the user.
|
||||
function calcSpawnInfo(hand, height) {
|
||||
function calcSpawnInfo(hand, tabletHeight) {
|
||||
var finalPosition;
|
||||
|
||||
var headPos = (HMD.active && Camera.mode === "first person") ? HMD.position : Camera.position;
|
||||
|
@ -53,30 +53,35 @@ function calcSpawnInfo(hand, height) {
|
|||
hand = NO_HANDS;
|
||||
}
|
||||
|
||||
var handController = null;
|
||||
if (HMD.active && hand !== NO_HANDS) {
|
||||
var handController = getControllerWorldLocation(hand, true);
|
||||
handController = getControllerWorldLocation(hand, true);
|
||||
}
|
||||
|
||||
var TABLET_UP_OFFSET = 0.1;
|
||||
var TABLET_FORWARD_OFFSET = 0.1;
|
||||
var normal = Vec3.multiplyQbyV(handController.rotation, {x: 0, y: -1, z: 0});
|
||||
var pitch = Math.asin(normal.y);
|
||||
var MAX_PITCH = Math.PI / 4;
|
||||
if (pitch < -MAX_PITCH) {
|
||||
pitch = -MAX_PITCH;
|
||||
} else if (pitch > MAX_PITCH) {
|
||||
pitch = MAX_PITCH;
|
||||
if (handController && handController.valid) {
|
||||
// Orient tablet per hand pitch and yaw.
|
||||
// Angle it back similar to holding it like a book.
|
||||
// Move tablet up so that hand is at bottom.
|
||||
// Move tablet back so that hand is in front.
|
||||
|
||||
var position = handController.position;
|
||||
var rotation = handController.rotation;
|
||||
|
||||
if (hand === Controller.Standard.LeftHand) {
|
||||
rotation = Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(0, 90, 0));
|
||||
} else {
|
||||
rotation = Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(0, -90, 0));
|
||||
}
|
||||
var normal = Vec3.multiplyQbyV(rotation, Vec3.UNIT_NEG_Y);
|
||||
var lookAt = Quat.lookAt(Vec3.ZERO, normal, Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.UNIT_Y));
|
||||
var TABLET_RAKE_ANGLE = 30;
|
||||
rotation = Quat.multiply(Quat.angleAxis(TABLET_RAKE_ANGLE, Vec3.multiplyQbyV(lookAt, Vec3.UNIT_X)), lookAt);
|
||||
|
||||
// rebuild normal from pitch and heading.
|
||||
var heading = Math.atan2(normal.z, normal.x);
|
||||
normal = {x: Math.cos(heading), y: Math.sin(pitch), z: Math.sin(heading)};
|
||||
|
||||
var position = Vec3.sum(handController.position, {x: 0, y: TABLET_UP_OFFSET, z: 0});
|
||||
var rotation = Quat.lookAt({x: 0, y: 0, z: 0}, normal, Y_AXIS);
|
||||
var offset = Vec3.multiplyQbyV(rotation, {x: 0, y: height / 2, z: TABLET_FORWARD_OFFSET});
|
||||
var RELATIVE_SPAWN_OFFSET = { x: 0, y: 0.4, z: 0.05 };
|
||||
position = Vec3.sum(position, Vec3.multiplyQbyV(rotation, Vec3.multiply(tabletHeight, RELATIVE_SPAWN_OFFSET)));
|
||||
|
||||
return {
|
||||
position: Vec3.sum(offset, position),
|
||||
position: position,
|
||||
rotation: rotation
|
||||
};
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue