mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
more fixes to third person tablet usage.
This commit is contained in:
parent
008a58f9d7
commit
3c04f54e75
1 changed files with 15 additions and 16 deletions
|
@ -24,6 +24,7 @@ var CAMERA_MATRIX = -7;
|
|||
var ROT_Y_180 = {x: 0, y: 1, z: 0, w: 0};
|
||||
var TABLET_TEXTURE_RESOLUTION = { x: 480, y: 706 };
|
||||
var INCHES_TO_METERS = 1 / 39.3701;
|
||||
var NO_HANDS = -1;
|
||||
|
||||
var TABLET_URL = Script.resourcesPath() + "meshes/tablet-with-home-button.fbx";
|
||||
|
||||
|
@ -35,18 +36,21 @@ var TABLET_MODEL_PATH = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-wi
|
|||
// * position - position in front of the user
|
||||
// * rotation - rotation of entity so it faces the user.
|
||||
function calcSpawnInfo(hand, height) {
|
||||
var noHands = -1;
|
||||
var finalPosition;
|
||||
if (HMD.active && hand !== noHands) {
|
||||
|
||||
var headPos = (HMD.active && Camera.mode === "first person") ? HMD.position : Camera.position;
|
||||
var headRot = (HMD.active && Camera.mode === "first person") ? HMD.orientation : Camera.orientation;
|
||||
|
||||
if (HMD.active && hand !== NO_HANDS) {
|
||||
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(HMD.position, controllerPosition)));
|
||||
var theta = Math.asin(height / (2 * Vec3.distance(headPos, controllerPosition)));
|
||||
|
||||
// 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 d = Vec3.normalize(Vec3.subtract(headPos, 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);
|
||||
|
@ -64,8 +68,8 @@ function calcSpawnInfo(hand, height) {
|
|||
rotation: lookAtRot
|
||||
};
|
||||
} else {
|
||||
var front = Quat.getFront(Camera.orientation);
|
||||
finalPosition = Vec3.sum(Camera.position, Vec3.multiply(0.6, front));
|
||||
var front = Quat.getFront(headRot);
|
||||
finalPosition = Vec3.sum(headPos, Vec3.multiply(0.6, front));
|
||||
var orientation = Quat.lookAt({x: 0, y: 0, z: 0}, front, {x: 0, y: 1, z: 0});
|
||||
return {
|
||||
position: finalPosition,
|
||||
|
@ -238,7 +242,6 @@ WebTablet.prototype.destroy = function () {
|
|||
|
||||
WebTablet.prototype.geometryChanged = function (geometry) {
|
||||
if (!HMD.active) {
|
||||
var NO_HANDS = -1;
|
||||
var tabletProperties = {};
|
||||
// compute position, rotation & parentJointIndex of the tablet
|
||||
this.calculateTabletAttachmentProperties(NO_HANDS, tabletProperties);
|
||||
|
@ -294,7 +297,6 @@ WebTablet.prototype.onHmdChanged = function () {
|
|||
Controller.mouseReleaseEvent.connect(this.myMouseReleaseEvent);
|
||||
}
|
||||
|
||||
var NO_HANDS = -1;
|
||||
var tabletProperties = {};
|
||||
// compute position, rotation & parentJointIndex of the tablet
|
||||
this.calculateTabletAttachmentProperties(NO_HANDS, tabletProperties);
|
||||
|
@ -377,17 +379,14 @@ WebTablet.prototype.mousePressEvent = function (event) {
|
|||
};
|
||||
|
||||
WebTablet.prototype.cameraModeChanged = function (newMode) {
|
||||
// reposition the tablet, after a small delay.
|
||||
// reposition the tablet.
|
||||
// This allows HMD.position to reflect the new camera mode.
|
||||
if (HMD.active) {
|
||||
var self = this;
|
||||
Script.setTimeout(function () {
|
||||
var NO_HANDS = -1;
|
||||
var tabletProperties = {};
|
||||
// compute position, rotation & parentJointIndex of the tablet
|
||||
self.calculateTabletAttachmentProperties(NO_HANDS, tabletProperties);
|
||||
Entities.editEntity(self.tabletEntityID, tabletProperties);
|
||||
}, 10);
|
||||
var tabletProperties = {};
|
||||
// compute position, rotation & parentJointIndex of the tablet
|
||||
self.calculateTabletAttachmentProperties(NO_HANDS, tabletProperties);
|
||||
Entities.editEntity(self.tabletEntityID, tabletProperties);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue