mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
More consistent tablet angle when first creating the tablet.
The tablet should more constantly be placed above your hand, while facing your head. It fixes the issue where the tablet would appear almost horizontal when your hand was close to your HMD and at eye level.
This commit is contained in:
parent
5c782deb4d
commit
4866be1f52
1 changed files with 17 additions and 11 deletions
|
@ -49,24 +49,30 @@ function calcSpawnInfo(hand, height) {
|
|||
var handController = getControllerWorldLocation(hand, true);
|
||||
var controllerPosition = handController.position;
|
||||
|
||||
// compute the angle of the chord with length (height / 2)
|
||||
var theta = Math.asin(height / (2 * Vec3.distance(headPos, controllerPosition)));
|
||||
// base of the tablet is slightly above controller position
|
||||
var TABLET_BASE_DISPLACEMENT = {x: 0, y: 0.1, z: 0};
|
||||
var tabletBase = Vec3.sum(controllerPosition, TABLET_BASE_DISPLACEMENT);
|
||||
|
||||
// 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(headPos, controllerPosition));
|
||||
var d = Vec3.subtract(headPos, tabletBase);
|
||||
var theta = Math.acos(d.y / Vec3.length(d));
|
||||
d.y = 0;
|
||||
if (Vec3.length(d) < 0.0001) {
|
||||
d = {x: 1, y: 0, z: 0};
|
||||
} else {
|
||||
d = Vec3.normalize(d);
|
||||
}
|
||||
var w = Vec3.normalize(Vec3.cross(Y_AXIS, d));
|
||||
var q = Quat.angleAxis(theta * (180 / Math.PI), w);
|
||||
var ANGLE_OFFSET = 25;
|
||||
var q = Quat.angleAxis(theta * (180 / Math.PI) - (90 - ANGLE_OFFSET), 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 lookAtRot = Quat.lookAt(tabletBase, Vec3.sum(tabletBase, u), Y_AXIS);
|
||||
var yDisplacement = (height / 2);
|
||||
var zDisplacement = 0.05;
|
||||
var tabletOffset = Vec3.multiplyQbyV(lookAtRot, {x: 0, y: yDisplacement, z: zDisplacement});
|
||||
finalPosition = Vec3.sum(controllerPosition, tabletOffset);
|
||||
finalPosition = Vec3.sum(tabletBase, tabletOffset);
|
||||
|
||||
return {
|
||||
position: finalPosition,
|
||||
rotation: lookAtRot
|
||||
|
|
Loading…
Reference in a new issue