mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
first version of pointing reticle
This commit is contained in:
parent
44d0e0ba1a
commit
4787785660
1 changed files with 81 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue