mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 01:56:54 +02:00
teleportr
This commit is contained in:
parent
4762091aaf
commit
ffbfc89e99
1 changed files with 51 additions and 78 deletions
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
|
|
||||||
// alternate notes for philip:
|
// alternate notes for philip:
|
||||||
// try just thumb to teleport
|
// try just thumb to teleport xxx
|
||||||
// cancel if destination is within ~1m of current location
|
// cancel if destination is within ~1m of current location
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,6 +23,13 @@ var inTeleportMode = false;
|
||||||
|
|
||||||
var easyMode = true;
|
var easyMode = true;
|
||||||
|
|
||||||
|
var TARGET_MODEL_URL = 'http://hifi-production.s3.amazonaws.com/DomainContent/Toybox/potted_plant/potted_plant.fbx';
|
||||||
|
var TARGET_MODEL_DIMENSIONS = {
|
||||||
|
x: 1.1005,
|
||||||
|
y: 2.1773,
|
||||||
|
z: 1.0739
|
||||||
|
};
|
||||||
|
|
||||||
function ThumbPad(hand) {
|
function ThumbPad(hand) {
|
||||||
this.hand = hand;
|
this.hand = hand;
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
@ -62,24 +69,22 @@ function Teleporter() {
|
||||||
print('jbp initialize')
|
print('jbp initialize')
|
||||||
this.createMappings();
|
this.createMappings();
|
||||||
this.disableGrab();
|
this.disableGrab();
|
||||||
_this.targetEntity = Entities.addEntity({
|
|
||||||
name: 'Hifi-Teleporter-Target-Entity',
|
var cameraEuler = Quat.safeEulerAngles(Camera.orientation);
|
||||||
position: MyAvatar.position,
|
var towardsMe = Quat.angleAxis(cameraEuler.y + 180, {
|
||||||
type: 'Sphere',
|
x: 0,
|
||||||
dimensions: {
|
y: 1,
|
||||||
x: 0.2,
|
z: 0
|
||||||
y: 0.2,
|
|
||||||
z: 0.2
|
|
||||||
},
|
|
||||||
color: {
|
|
||||||
red: 255,
|
|
||||||
green: 255,
|
|
||||||
blue: 255
|
|
||||||
},
|
|
||||||
collisionless: true,
|
|
||||||
collidesWith: '',
|
|
||||||
visible: true
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var targetOverlayProps = {
|
||||||
|
url: TARGET_MODEL_URL,
|
||||||
|
position: MyAvatar.position,
|
||||||
|
rotation: towardsMe,
|
||||||
|
dimensions: TARGET_MODEL_DIMENSIONS
|
||||||
|
};
|
||||||
|
|
||||||
|
_this.targetOverlay = Overlays.addOverlay("model", targetOverlayProps);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,59 +111,28 @@ function Teleporter() {
|
||||||
this.teleportHand = hand;
|
this.teleportHand = hand;
|
||||||
this.initialize();
|
this.initialize();
|
||||||
this.updateConnected = true;
|
this.updateConnected = true;
|
||||||
if (easyMode !== true) {
|
Script.update.connect(this.update);
|
||||||
Script.update.connect(this.update);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Script.update.connect(this.updateEasy);
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.exitTeleportMode = function(value) {
|
this.exitTeleportMode = function(value) {
|
||||||
print('jbp value on exit: ' + value);
|
print('jbp value on exit: ' + value);
|
||||||
|
Script.update.disconnect(this.update);
|
||||||
this.disableMappings();
|
this.disableMappings();
|
||||||
this.rightOverlayOff();
|
this.rightOverlayOff();
|
||||||
this.leftOverlayOff();
|
this.leftOverlayOff();
|
||||||
Entities.deleteEntity(_this.targetEntity);
|
// Entities.deleteEntity(_this.targetEntity);
|
||||||
|
Overlays.deleteOverlay(_this.targetOverlay);
|
||||||
this.enableGrab();
|
this.enableGrab();
|
||||||
if (easyMode !== true) {
|
|
||||||
Script.update.disconnect(this.update);
|
|
||||||
} else {
|
|
||||||
Script.update.disconnect(this.updateEasy);
|
|
||||||
}
|
|
||||||
this.updateConnected = false;
|
this.updateConnected = false;
|
||||||
inTeleportMode = false;
|
Script.setTimeout(function() {
|
||||||
|
inTeleportMode = false;
|
||||||
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
this.update = function() {
|
this.update = function() {
|
||||||
//print('in teleporter update')
|
|
||||||
|
|
||||||
if (teleporter.teleportHand === 'left') {
|
|
||||||
teleporter.leftRay();
|
|
||||||
if (leftPad.buttonValue === 0) {
|
|
||||||
_this.exitTeleportMode();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (leftTrigger.buttonValue === 0) {
|
|
||||||
_this.teleport();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
teleporter.rightRay();
|
|
||||||
if (rightPad.buttonValue === 0) {
|
|
||||||
_this.exitTeleportMode();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (rightTrigger.buttonValue === 0) {
|
|
||||||
_this.teleport();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
this.updateEasy = function() {
|
|
||||||
|
|
||||||
if (teleporter.teleportHand === 'left') {
|
if (teleporter.teleportHand === 'left') {
|
||||||
teleporter.leftRay();
|
teleporter.leftRay();
|
||||||
|
@ -199,7 +173,8 @@ function Teleporter() {
|
||||||
var rightIntersection = Entities.findRayIntersection(teleporter.rightPickRay, true, [], [this.targetEntity]);
|
var rightIntersection = Entities.findRayIntersection(teleporter.rightPickRay, true, [], [this.targetEntity]);
|
||||||
|
|
||||||
if (rightIntersection.intersects) {
|
if (rightIntersection.intersects) {
|
||||||
this.updateTargetEntity(rightIntersection);
|
this.updateTargetOverlay(rightIntersection);
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -221,10 +196,10 @@ function Teleporter() {
|
||||||
green: 255,
|
green: 255,
|
||||||
blue: 0
|
blue: 0
|
||||||
});
|
});
|
||||||
var leftIntersection = Entities.findRayIntersection(teleporter.leftPickRay, true, [], [this.targetEntity]);
|
var leftIntersection = Entities.findRayIntersection(teleporter.leftPickRay, true, [], []);
|
||||||
|
|
||||||
if (leftIntersection.intersects) {
|
if (leftIntersection.intersects) {
|
||||||
this.updateTargetEntity(leftIntersection);
|
this.updateTargetOverlay(leftIntersection);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -298,18 +273,17 @@ function Teleporter() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.updateTargetEntity = function(intersection) {
|
this.updateTargetOverlay = function(intersection) {
|
||||||
var targetProps = Entities.getEntityProperties(this.targetEntity);
|
this.intersection=intersection;
|
||||||
var position = {
|
var position = {
|
||||||
x: intersection.intersection.x,
|
x: intersection.intersection.x,
|
||||||
y: intersection.intersection.y + targetProps.dimensions.y / 2,
|
y: intersection.intersection.y+TARGET_MODEL_DIMENSIONS.y,
|
||||||
z: intersection.intersection.z
|
z: intersection.intersection.z
|
||||||
}
|
}
|
||||||
Entities.editEntity(this.targetEntity, {
|
Overlays.editOverlay(this.targetOverlay, {
|
||||||
position: position
|
position: position
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.disableGrab = function() {
|
this.disableGrab = function() {
|
||||||
|
@ -321,17 +295,16 @@ function Teleporter() {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.teleport = function(value) {
|
this.teleport = function(value) {
|
||||||
//todo
|
|
||||||
//get the y position of the teleport landing spot
|
print('TELEPORT CALLED');
|
||||||
print('value on teleport: ' + value)
|
|
||||||
var properties = Entities.getEntityProperties(teleporter.targetEntity);
|
|
||||||
var offset = getAvatarFootOffset();
|
var offset = getAvatarFootOffset();
|
||||||
properties.position.y += offset;
|
|
||||||
|
// _this.intersectionPosition.y+=offset;
|
||||||
print('OFFSET IS::: ' + JSON.stringify(offset))
|
// print('OFFSET IS::: ' + JSON.stringify(offset))
|
||||||
print('TELEPORT POSITION IS:: ' + JSON.stringify(properties.position));
|
// print('TELEPORT POSITION IS:: ' + JSON.stringify(_this.intersectionPosition));
|
||||||
MyAvatar.position = properties.position;
|
_this.intersection.intersection.y+=offset;
|
||||||
|
MyAvatar.position = _this.intersection.intersection;
|
||||||
this.exitTeleportMode();
|
this.exitTeleportMode();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -438,7 +411,7 @@ function cleanup() {
|
||||||
teleporter.disableMappings();
|
teleporter.disableMappings();
|
||||||
teleporter.rightOverlayOff();
|
teleporter.rightOverlayOff();
|
||||||
teleporter.leftOverlayOff();
|
teleporter.leftOverlayOff();
|
||||||
Entities.deleteEntity(teleporter.targetEntity);
|
Overlays.deleteOverlay(teleporter.targetOverlay);
|
||||||
if (teleporter.updateConnected !== null) {
|
if (teleporter.updateConnected !== null) {
|
||||||
Script.update.disconnect(teleporter.update);
|
Script.update.disconnect(teleporter.update);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue