first version of pointing reticle

This commit is contained in:
RebeccaStankus 2019-08-19 13:19:01 -07:00
parent 44d0e0ba1a
commit 4787785660

View file

@ -159,8 +159,10 @@ function toggleReaction(reaction) {
}
}
var UPDATE_POINT_EMOTE_MS = 1000;
var reactionsBegun = [];
var pointReticle = null;
var mouseMoveEventsConnected = false;
function beginReactionWrapper(reaction) {
reactionsBegun.forEach(function(react) {
endReactionWrapper(react);
@ -175,9 +177,74 @@ function beginReactionWrapper(reaction) {
case ("applaud"):
startClappingSounds();
break;
case ("point"):
if (pointReticle) {
Entities.deleteEntity(pointReticle);
pointReticle = null;
}
Controller.mouseMoveEvent.connect(mouseMoveEvent);
mouseMoveEventsConnected = true;
}
}
var intersectedEntityOrAvatarID = null;
function mouseMoveEvent(event) {
var pickRay = Camera.computePickRay(event.x, event.y);
var avatarIntersectionData = AvatarManager.findRayIntersection(pickRay);
var entityIntersectionData = Entities.findRayIntersection(pickRay, true);
var avatarIntersectionDistanceM = avatarIntersectionData.intersects ? avatarIntersectionData.distance : null;
var entityIntersectionDistanceM = entityIntersectionData.intersects ? entityIntersectionData.distance : null;
var reticlePosition;
if (avatarIntersectionDistanceM && entityIntersectionDistanceM) {
if (avatarIntersectionDistanceM < entityIntersectionDistanceM) {
intersectedEntityOrAvatarID = avatarIntersectionData.avatarID;
reticlePosition = avatarIntersectionData.intersection;
} else {
intersectedEntityOrAvatarID = entityIntersectionData.entityID;
reticlePosition = entityIntersectionData.intersection;
}
} else if (avatarIntersectionDistanceM) {
intersectedEntityOrAvatarID = avatarIntersectionData.avatarID;
reticlePosition = avatarIntersectionData.intersection;
} else if (entityIntersectionDistanceM) {
intersectedEntityOrAvatarID = entityIntersectionData.entityID;
reticlePosition = entityIntersectionData.intersection;
} else {
print("ERROR: No intersected avatar or entity found.");
return;
}
//if (intersectedEntityOrAvatarID === avatarIntersectionData.intersects) {
// print("PICKRAY INTERSECTS AVATAR: ", intersectedEntityOrAvatarID);
//} else {
// print("PICKRAY INTERSECTS ENTITY: ", intersectedEntityOrAvatarID);
//}
if (pointReticle) {
Entities.editEntity(pointReticle, { position: reticlePosition });
} else {
// make dimensions scale to distance
pointReticle = Entities.addEntity({
type: "Sphere",
name: "Point Reticle",
position: reticlePosition,
dimensions: { x: 0.1, y: 0.1, z: 0.1 },
color: { red: 255, green: 0, blue: 0 },
collisionless: true,
ignorePickIntersection: true
}, true);
}
// cast ray from camera to 3d cursor position
// get intersection of ray
// if intersects with entity, move back along normal 1/2 depth of the entity to get reticle position or maybe just SubmeshIntersection.worldIntersectionPoint
// if intersects avatar, move backward 0.5m or maybe just SubmeshIntersection.worldIntersectionPoint
// create reticle at the position
// make avatar point at the reticle
}
function triggerReactionWrapper(reaction) {
reactionsBegun.forEach(function(react) {
@ -202,6 +269,16 @@ function endReactionWrapper(reaction) {
case ("applaud"):
maybeClearClapSoundInterval();
break;
case ("point"):
if (mouseMoveEventsConnected) {
Controller.mouseMoveEvent.disconnect(mouseMoveEvent);
}
intersectedEntityOrAvatarID = null;
if (pointReticle) {
Entities.deleteEntity(pointReticle);
pointReticle = null;
}
break;
}
}
@ -500,6 +577,9 @@ function onEmojiAppClosed() {
emojiAppWindow.fromQml.disconnect(onMessageFromEmojiApp);
emojiAppWindow.closed.disconnect(onEmojiAppClosed);
}
if (mouseMoveEventsConnected) {
Controller.mouseMoveEvent.disconnect(mouseMoveEvent);
}
emojiAppWindow = false;
}