mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
Added tablet shell around web-buddy
This commit is contained in:
parent
d607abc8f7
commit
eafae1fcf3
1 changed files with 65 additions and 19 deletions
|
@ -7,44 +7,89 @@
|
|||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var NEGATIVE_ONE = 65535;
|
||||
|
||||
var RAD_TO_DEG = 180 / Math.PI;
|
||||
var X_AXIS = {x: 1, y: 0, z: 0};
|
||||
var Y_AXIS = {x: 0, y: 1, z: 0};
|
||||
|
||||
var TABLET_URL = "https://s3.amazonaws.com/hifi-public/tony/tablet.fbx";
|
||||
|
||||
// returns object with two fields:
|
||||
// * position - position in front of the user
|
||||
// * rotation - rotation of entity so it faces the user.
|
||||
function calcSpawnInfo() {
|
||||
var front;
|
||||
var pitchBackRotation = Quat.angleAxis(20.0, X_AXIS);
|
||||
if (HMD.active) {
|
||||
front = Quat.getFront(HMD.orientation);
|
||||
var yawOnlyRotation = Quat.angleAxis(Math.atan2(front.x, front.z) * RAD_TO_DEG, Y_AXIS);
|
||||
return {
|
||||
position: Vec3.sum(Vec3.sum(HMD.position, Vec3.multiply(0.6, front)), Vec3.multiply(-0.5, Y_AXIS)),
|
||||
rotation: Quat.multiply(yawOnlyRotation, pitchBackRotation)
|
||||
};
|
||||
} else {
|
||||
front = Quat.getFront(MyAvatar.orientation);
|
||||
return {
|
||||
position: Vec3.sum(Vec3.sum(MyAvatar.position, Vec3.multiply(0.6, front)), {x: 0, y: 0.6, z: 0}),
|
||||
rotation: Quat.multiply(MyAvatar.orientation, pitchBackRotation)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// ctor
|
||||
WebBuddy = function (url) {
|
||||
|
||||
var ASPECT = 4.0 / 3.0;
|
||||
var WIDTH = 0.4;
|
||||
var HEIGHT = WIDTH * ASPECT;
|
||||
var DEPTH = 0.025;
|
||||
|
||||
var spawnPoint = Vec3.sum(Vec3.sum(MyAvatar.position, Vec3.multiply(1.0, Quat.getFront(MyAvatar.orientation))),
|
||||
{x: 0, y: 0.5, z: 0});
|
||||
var spawnInfo = calcSpawnInfo();
|
||||
|
||||
var tabletEntityPosition = spawnInfo.position;
|
||||
var tabletEntityRotation = spawnInfo.rotation;
|
||||
this.tabletEntityID = Entities.addEntity({
|
||||
name: "tablet",
|
||||
type: "Model",
|
||||
modelURL: TABLET_URL,
|
||||
position: tabletEntityPosition,
|
||||
rotation: tabletEntityRotation,
|
||||
userData: JSON.stringify({
|
||||
"grabbableKey": {"grabbable": true}
|
||||
}),
|
||||
dimensions: {x: WIDTH, y: HEIGHT, z: DEPTH},
|
||||
parentID: MyAvatar.sessionUUID,
|
||||
parentJointIndex: NEGATIVE_ONE
|
||||
});
|
||||
|
||||
var WEB_ENTITY_REDUCTION_FACTOR = {x: 0.78, y: 0.85};
|
||||
var WEB_ENTITY_Z_OFFSET = -0.01;
|
||||
|
||||
var webEntityRotation = Quat.multiply(spawnInfo.rotation, Quat.angleAxis(180, Y_AXIS));
|
||||
var webEntityPosition = Vec3.sum(spawnInfo.position, Vec3.multiply(WEB_ENTITY_Z_OFFSET, Quat.getFront(webEntityRotation)));
|
||||
|
||||
var webEntityPosition = spawnPoint;
|
||||
var webEntityRotation = MyAvatar.orientation;
|
||||
this.webEntityID = Entities.addEntity({
|
||||
name: "web",
|
||||
type: "Web",
|
||||
sourceUrl: url,
|
||||
dimensions: {x: WIDTH, y: WIDTH * ASPECT, z: 0.1},
|
||||
dimensions: {x: WIDTH * WEB_ENTITY_REDUCTION_FACTOR.x,
|
||||
y: HEIGHT * WEB_ENTITY_REDUCTION_FACTOR.y,
|
||||
z: 0.1},
|
||||
position: webEntityPosition,
|
||||
rotation: webEntityRotation,
|
||||
name: "web",
|
||||
dynamic: true,
|
||||
angularDamping: 0.9,
|
||||
damping: 0.9,
|
||||
gravity: {x: 0, y: 0, z: 0},
|
||||
shapeType: "box",
|
||||
userData: JSON.stringify({
|
||||
"grabbableKey": {"grabbable": true},
|
||||
}),
|
||||
parentID: MyAvatar.sessionUUID,
|
||||
parentJointIndex: NEGATIVE_ONE,
|
||||
dpi: 45
|
||||
dpi: 45,
|
||||
parentID: this.tabletEntityID,
|
||||
parentJointIndex: NEGATIVE_ONE
|
||||
});
|
||||
|
||||
this.state = "idle";
|
||||
|
||||
// compute the room/sensor matrix of the entity.
|
||||
var invRoomMat = Mat4.inverse(MyAvatar.sensorToWorldMatrix);
|
||||
var entityWorldMat = Mat4.createFromRotAndTrans(webEntityRotation, webEntityPosition);
|
||||
var entityWorldMat = Mat4.createFromRotAndTrans(tabletEntityRotation, tabletEntityPosition);
|
||||
this.entityRoomMat = Mat4.multiply(invRoomMat, entityWorldMat);
|
||||
|
||||
var _this = this;
|
||||
|
@ -56,12 +101,13 @@ WebBuddy = function (url) {
|
|||
|
||||
WebBuddy.prototype.destroy = function () {
|
||||
Entities.deleteEntity(this.webEntityID);
|
||||
Entities.deleteEntity(this.tabletEntityID);
|
||||
Script.update.disconnect(this.updateFunc);
|
||||
};
|
||||
|
||||
WebBuddy.prototype.update = function (dt) {
|
||||
|
||||
var props = Entities.getEntityProperties(this.webEntityID, ["position", "rotation", "parentID", "parentJointIndex"]);
|
||||
var props = Entities.getEntityProperties(this.tabletEntityID, ["position", "rotation", "parentID", "parentJointIndex"]);
|
||||
var entityWorldMat;
|
||||
|
||||
if (this.state === "idle") {
|
||||
|
@ -76,7 +122,7 @@ WebBuddy.prototype.update = function (dt) {
|
|||
entityWorldMat = Mat4.multiply(roomMat, this.entityRoomMat);
|
||||
|
||||
// slam the world space position and orientation
|
||||
Entities.editEntity(this.webEntityID, {
|
||||
Entities.editEntity(this.tabletEntityID, {
|
||||
position: Mat4.extractTranslation(entityWorldMat),
|
||||
rotation: Mat4.extractRotation(entityWorldMat)
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue