mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:21:16 +02:00
working teleporter in huffmans build
This commit is contained in:
parent
b0494ec9d5
commit
2d073cc99c
1 changed files with 45 additions and 134 deletions
|
@ -104,17 +104,10 @@ function Teleporter() {
|
||||||
|
|
||||||
this.createTargetOverlay = function() {
|
this.createTargetOverlay = function() {
|
||||||
print('creating target overlay')
|
print('creating target overlay')
|
||||||
var cameraEuler = Quat.safeEulerAngles(Camera.orientation);
|
|
||||||
var towardsMe = Quat.angleAxis(cameraEuler.y + 180, {
|
|
||||||
x: 0,
|
|
||||||
y: 1,
|
|
||||||
z: 0
|
|
||||||
});
|
|
||||||
|
|
||||||
var targetOverlayProps = {
|
var targetOverlayProps = {
|
||||||
url: TARGET_MODEL_URL,
|
url: TARGET_MODEL_URL,
|
||||||
position: MyAvatar.position,
|
|
||||||
rotation: towardsMe,
|
|
||||||
dimensions: TARGET_MODEL_DIMENSIONS,
|
dimensions: TARGET_MODEL_DIMENSIONS,
|
||||||
visible: true,
|
visible: true,
|
||||||
};
|
};
|
||||||
|
@ -122,6 +115,15 @@ function Teleporter() {
|
||||||
_this.targetOverlay = Overlays.addOverlay("model", targetOverlayProps);
|
_this.targetOverlay = Overlays.addOverlay("model", targetOverlayProps);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.rotateTargetTorwardMe = function() {
|
||||||
|
var cameraEuler = Quat.safeEulerAngles(Camera.orientation);
|
||||||
|
var towardsMe = Quat.angleAxis(cameraEuler.y + 180, {
|
||||||
|
x: 0,
|
||||||
|
y: 1,
|
||||||
|
z: 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
this.createMappings = function() {
|
this.createMappings = function() {
|
||||||
print('jbp create mappings internal');
|
print('jbp create mappings internal');
|
||||||
|
@ -157,37 +159,45 @@ function Teleporter() {
|
||||||
return midpoint
|
return midpoint
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.updateOrCreateStretchyBeam = function(handPosition, intersection, rotation, direction, noIntersection) {
|
||||||
|
|
||||||
this.createStretchyBeam = function(handPosition, intersection, rotation) {
|
if (_this.stretchyBeam === null) {
|
||||||
|
var beamProps = {
|
||||||
|
url: BEAM_MODEL_URL,
|
||||||
|
position: MyAvatar.position,
|
||||||
|
|
||||||
var beamProps = {
|
};
|
||||||
url: BEAM_MODEL_URL,
|
|
||||||
position: _this.findMidpoint(handPosition, intersection),
|
|
||||||
dimensions: {
|
|
||||||
x: STRETCHY_BEAM_DIMENSIONS_X,
|
|
||||||
y: STRETCHY_BEAM_DIMENSIONS_Y,
|
|
||||||
z: 0.1
|
|
||||||
},
|
|
||||||
ignoreRayIntersection: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
_this.stretchyBeam = Overlays.addOverlay("model", beamProps);
|
_this.stretchyBeam = Overlays.addOverlay("model", beamProps);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
this.updateStretchyBeam = function(handPosition, intersection, rotation) {
|
|
||||||
var dimensions = {
|
var dimensions = {
|
||||||
x: STRETCHY_BEAM_DIMENSIONS_X,
|
x: STRETCHY_BEAM_DIMENSIONS_X,
|
||||||
y: STRETCHY_BEAM_DIMENSIONS_Y,
|
y: STRETCHY_BEAM_DIMENSIONS_Y,
|
||||||
z: Vec3.distance(handPosition, intersection.intersection)
|
z: intersection !== null ? Vec3.distance(handPosition, intersection.intersection) : STRETCHY_BEAM_DIMENSIONS_Z_NO_INTESECTION
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var position;
|
||||||
|
if (noIntersection === true) {
|
||||||
|
this.deleteTargetOverlay();
|
||||||
|
print('no intersection')
|
||||||
|
position = Vec3.sum(handPosition, Vec3.multiply(STRETCHY_BEAM_DIMENSIONS_Z_NO_INTESECTION/2 , direction));
|
||||||
|
} else {
|
||||||
|
print('intersection, find midpoint')
|
||||||
|
position = _this.findMidpoint(handPosition, intersection);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
print('rotation: ' + JSON.stringify(rotation));
|
||||||
|
print('position: ' + JSON.stringify(position));
|
||||||
|
print('dimensions: ' + JSON.stringify(dimensions));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var position = _this.findMidpoint(handPosition, intersection);
|
|
||||||
Overlays.editOverlay(_this.stretchyBeam, {
|
Overlays.editOverlay(_this.stretchyBeam, {
|
||||||
dimensions: dimensions,
|
dimensions: dimensions,
|
||||||
position: position,
|
position: position,
|
||||||
rotation: Quat.multiply(rotation, Quat.angleAxis(180, {
|
rotation: Quat.multiply(rotation, Quat.angleAxis(180, {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 1,
|
y: 1,
|
||||||
z: 0
|
z: 0
|
||||||
|
@ -203,82 +213,6 @@ function Teleporter() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.createNoIntersectionStretchyBeam = function(handPosition, direction, rotation) {
|
|
||||||
|
|
||||||
var howBig = STRETCHY_BEAM_DIMENSIONS_Z_NO_INTESECTION;
|
|
||||||
|
|
||||||
var ahead = Vec3.sum(handPosition, Vec3.multiply(howBig, direction));
|
|
||||||
|
|
||||||
var midpoint = this.findMidpoint(handPosition, {
|
|
||||||
intersection: ahead
|
|
||||||
});
|
|
||||||
|
|
||||||
var dimensions = {
|
|
||||||
x: 0.04,
|
|
||||||
y: 0.04,
|
|
||||||
z: 0.1
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var finalRotation = Quat.multiply(rotation, Quat.angleAxis(180, {
|
|
||||||
x: 0,
|
|
||||||
y: 1,
|
|
||||||
z: 0
|
|
||||||
}));
|
|
||||||
|
|
||||||
var beamProps = {
|
|
||||||
// dimensions: dimensions,
|
|
||||||
url: BEAM_MODEL_URL_NO_INTERSECTION,
|
|
||||||
position: midpoint,
|
|
||||||
rotation: finalRotation,
|
|
||||||
ignoreRayIntersection: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
this.noIntersectionStretchyBeam = Overlays.addOverlay("model", beamProps);
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
this.updateNoIntersectionStretchyBeam = function(handPosition, direction, rotation) {
|
|
||||||
|
|
||||||
var howBig = STRETCHY_BEAM_DIMENSIONS_Z_NO_INTESECTION;
|
|
||||||
|
|
||||||
var ahead = Vec3.sum(handPosition, Vec3.multiply(howBig, direction));
|
|
||||||
|
|
||||||
var midpoint = this.findMidpoint(handPosition, {
|
|
||||||
intersection: ahead
|
|
||||||
});
|
|
||||||
|
|
||||||
var dimensions = {
|
|
||||||
x: STRETCHY_BEAM_DIMENSIONS_X,
|
|
||||||
y: STRETCHY_BEAM_DIMENSIONS_Y,
|
|
||||||
z: Vec3.distance(handPosition, ahead)
|
|
||||||
};
|
|
||||||
dimensions = Vec3.multiply(10, dimensions)
|
|
||||||
print('dimensions in update:: ' + JSON.stringify(dimensions));
|
|
||||||
|
|
||||||
|
|
||||||
var finalRotation = Quat.multiply(rotation, Quat.angleAxis(180, {
|
|
||||||
x: 0,
|
|
||||||
y: 1,
|
|
||||||
z: 0
|
|
||||||
}));
|
|
||||||
|
|
||||||
var goodEdit = Overlays.editOverlay(_this.noIntersectionStretchyBeam, {
|
|
||||||
dimensions: dimensions,
|
|
||||||
position: midpoint,
|
|
||||||
rotation: rotation
|
|
||||||
})
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
this.deleteNoIntersectionStretchyBeam = function() {
|
|
||||||
if (_this.noIntersectionStretchyBeam !== null) {
|
|
||||||
Overlays.deleteOverlay(_this.noIntersectionStretchyBeam);
|
|
||||||
_this.noIntersectionStretchyBeam = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.createFadeSphere = function(avatarHead) {
|
this.createFadeSphere = function(avatarHead) {
|
||||||
var sphereProps = {
|
var sphereProps = {
|
||||||
|
@ -364,7 +298,6 @@ function Teleporter() {
|
||||||
this.updateConnected = null;
|
this.updateConnected = null;
|
||||||
this.disableMappings();
|
this.disableMappings();
|
||||||
this.deleteStretchyBeam();
|
this.deleteStretchyBeam();
|
||||||
this.deleteNoIntersectionStretchyBeam();
|
|
||||||
this.deleteTargetOverlay();
|
this.deleteTargetOverlay();
|
||||||
this.enableGrab();
|
this.enableGrab();
|
||||||
Script.setTimeout(function() {
|
Script.setTimeout(function() {
|
||||||
|
@ -417,27 +350,17 @@ 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.deleteNoIntersectionStretchyBeam();
|
|
||||||
|
|
||||||
if (this.targetOverlay !== null) {
|
if (this.targetOverlay !== null) {
|
||||||
this.updateTargetOverlay(rightIntersection);
|
this.updateTargetOverlay(rightIntersection);
|
||||||
} else {
|
} else {
|
||||||
this.createTargetOverlay();
|
this.createTargetOverlay();
|
||||||
}
|
}
|
||||||
if (this.stretchyBeam !== null) {
|
this.updateOrCreateStretchyBeam(rightPickRay.origin, rightIntersection, rightFinal, rightPickRay.direction, false);
|
||||||
this.updateStretchyBeam(rightPickRay.origin, rightIntersection, rightFinal);
|
|
||||||
} else {
|
|
||||||
this.createStretchyBeam(rightPickRay.origin, rightIntersection, rightFinal);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this.deleteTargetOverlay();
|
|
||||||
this.deleteStretchyBeam();
|
|
||||||
if (this.noIntersectionStretchyBeam !== null) {
|
|
||||||
this.updateNoIntersectionStretchyBeam(rightPickRay.origin, rightPickRay.direction, rightFinal);
|
|
||||||
|
|
||||||
} else {
|
this.updateOrCreateStretchyBeam(rightPickRay.origin, null, rightFinal, rightPickRay.direction, true);
|
||||||
this.createNoIntersectionStretchyBeam(rightPickRay.origin, rightPickRay.direction, rightFinal);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,7 +375,6 @@ function Teleporter() {
|
||||||
direction: Quat.getUp(leftRotation),
|
direction: Quat.getUp(leftRotation),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var leftFinal = Quat.multiply(leftRotation, Quat.angleAxis(90, {
|
var leftFinal = Quat.multiply(leftRotation, Quat.angleAxis(90, {
|
||||||
x: 1,
|
x: 1,
|
||||||
y: 0,
|
y: 0,
|
||||||
|
@ -466,28 +388,18 @@ function Teleporter() {
|
||||||
var leftIntersection = Entities.findRayIntersection(teleporter.leftPickRay, true, [], [this.targetEntity]);
|
var leftIntersection = Entities.findRayIntersection(teleporter.leftPickRay, true, [], [this.targetEntity]);
|
||||||
|
|
||||||
if (leftIntersection.intersects) {
|
if (leftIntersection.intersects) {
|
||||||
this.deleteNoIntersectionStretchyBeam();
|
|
||||||
if (this.targetOverlay !== null) {
|
if (this.targetOverlay !== null) {
|
||||||
this.updateTargetOverlay(leftIntersection);
|
this.updateTargetOverlay(leftIntersection);
|
||||||
} else {
|
} else {
|
||||||
this.createTargetOverlay();
|
this.createTargetOverlay();
|
||||||
}
|
}
|
||||||
|
this.updateOrCreateStretchyBeam(leftPickRay.origin, leftIntersection, leftFinal, leftPickRay.direction, false);
|
||||||
if (this.stretchyBeam !== null) {
|
|
||||||
this.updateStretchyBeam(leftPickRay.origin, leftIntersection, leftFinal);
|
|
||||||
} else {
|
|
||||||
this.createStretchyBeam(leftPickRay.origin, leftIntersection, leftFinal);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.deleteTargetOverlay();
|
|
||||||
this.deleteStretchyBeam();
|
this.updateOrCreateStretchyBeam(leftPickRay.origin, null, leftFinal, leftPickRay.direction, true);
|
||||||
if (this.noIntersectionStretchyBeam !== null) {
|
|
||||||
this.updateNoIntersectionStretchyBeam(leftPickRay.origin, leftPickRay.direction, leftFinal);
|
|
||||||
} else {
|
|
||||||
this.createNoIntersectionStretchyBeam(leftPickRay.origin, leftPickRay.direction, leftFinal);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -496,7 +408,7 @@ function Teleporter() {
|
||||||
this.intersection = intersection;
|
this.intersection = intersection;
|
||||||
var position = {
|
var position = {
|
||||||
x: intersection.intersection.x,
|
x: intersection.intersection.x,
|
||||||
y: intersection.intersection.y + TARGET_MODEL_DIMENSIONS.y + 0.1,
|
y: intersection.intersection.y + TARGET_MODEL_DIMENSIONS.y/2,
|
||||||
z: intersection.intersection.z
|
z: intersection.intersection.z
|
||||||
}
|
}
|
||||||
Overlays.editOverlay(this.targetOverlay, {
|
Overlays.editOverlay(this.targetOverlay, {
|
||||||
|
@ -611,7 +523,6 @@ function cleanup() {
|
||||||
teleporter.disableMappings();
|
teleporter.disableMappings();
|
||||||
teleporter.deleteStretchyBeam();
|
teleporter.deleteStretchyBeam();
|
||||||
teleporter.deleteTargetOverlay();
|
teleporter.deleteTargetOverlay();
|
||||||
teleporter.deleteNoIntersectionStretchyBeam();
|
|
||||||
if (teleporter.updateConnected !== null) {
|
if (teleporter.updateConnected !== null) {
|
||||||
Script.update.disconnect(teleporter.update);
|
Script.update.disconnect(teleporter.update);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue