Last active
May 2, 2019 01:56
-
-
Save SamGondelman/9c64fbcd3cc87e1c27785d4ec4c6cf05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { // BEGIN LOCAL_SCOPE | |
var entities = []; | |
function getPos(x, y) { | |
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(6, Quat.getFront(MyAvatar.orientation))); | |
return Vec3.sum(Vec3.sum(center, Vec3.multiply(Quat.getRight(MyAvatar.orientation), x)), Vec3.multiply(Quat.getUp(MyAvatar.orientation), y)); | |
} | |
entities.push(Entities.addEntity({ | |
type: "Grid", | |
position: getPos(-1.5, 1), | |
rotation: MyAvatar.orientation, | |
grab: { grabbable: false }, | |
dimensions: 1.0, | |
followCamera: false, | |
minorGridEvery: 0.1, | |
majorGridEvery: 5, | |
ignorePickIntersection: false | |
})); | |
entities.push(Entities.addEntity({ | |
type: "Grid", | |
position: getPos(-0.5, 1), | |
rotation: MyAvatar.orientation, | |
grab: { grabbable: false }, | |
dimensions: 1.0, | |
followCamera: false, | |
minorGridEvery: 0.1, | |
majorGridEvery: 5, | |
ignorePickIntersection: true | |
})); | |
entities.push(Overlays.addOverlay("cube", { | |
position: getPos(0.5, 1), | |
rotation: MyAvatar.orientation, | |
grab: { grabbable: false }, | |
dimensions: 1.0, | |
ignorePickIntersection: false, | |
solid: true | |
})); | |
entities.push(Overlays.addOverlay("cube", { | |
position: getPos(1.5, 1), | |
rotation: MyAvatar.orientation, | |
grab: { grabbable: false }, | |
dimensions: 1.0, | |
ignorePickIntersection: true, | |
solid: true | |
})); | |
function mousePressOnEntity(id, event) { | |
print("clicked on " + JSON.stringify(id)); | |
} | |
Entities.mousePressOnEntity.connect(mousePressOnEntity); | |
function mousePressEvent(event) { | |
var result = Entities.findRayIntersection(Camera.computePickRay(event.x, event.y), true); | |
if (result.intersects) { | |
print("intersected " + JSON.stringify(result.entityID)); | |
} | |
} | |
Controller.mousePressEvent.connect(mousePressEvent); | |
function cleanup() { | |
for (var i = 0; i < entities.length; i++) { | |
Entities.deleteEntity(entities[i]); | |
} | |
} | |
Script.scriptEnding.connect(cleanup); | |
}()); // END LOCAL_SCOPE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment