Skip to content

Instantly share code, notes, and snippets.

@SamGondelman
Last active September 22, 2017 23:14
Show Gist options
  • Save SamGondelman/26abff5da64503df321254c8a846536b to your computer and use it in GitHub Desktop.
Save SamGondelman/26abff5da64503df321254c8a846536b to your computer and use it in GitHub Desktop.
"use strict";
// Created by Sam Gondelman on 9/22/2017
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
(function() { // BEGIN LOCAL_SCOPE
var END_DIMENSIONS = {
x: 0.5,
y: 0.5,
z: 0.5
};
var COLOR = {red: 97, green: 247, blue: 255};
var end = {
type: "sphere",
dimensions: END_DIMENSIONS,
color: COLOR,
ignoreRayIntersection: true,
alpha: 1.0,
visible: true
}
var COLOR2 = {red: 247, green: 97, blue: 255};
var end2 = {
type: "sphere",
dimensions: END_DIMENSIONS,
color: COLOR2,
ignoreRayIntersection: true,
alpha: 1.0,
visible: true
}
var renderStates = [{name: "test", end: end}];
var defaultRenderStates = [{name: "test", distance: 20.0, end: end2}];
var ray = LaserPointers.createLaserPointer({
joint: "Mouse",
filter: RayPick.PICK_ENTITIES | RayPick.PICK_OVERLAYS | RayPick.PICK_AVATARS | RayPick.PICK_INCLUDE_INVISIBLE | RayPick.PICK_INCLUDE_NONCOLLIDABLE,
renderStates: renderStates,
defaultRenderStates: defaultRenderStates,
enabled: true
});
var precisionPicking = true;
var lengthMode = false;
var lockedMode = false;
LaserPointers.setRenderState(ray, "test");
function cleanup() {
LaserPointers.removeLaserPointer(ray);
}
Script.scriptEnding.connect(cleanup);
var time = 0;
function update(dt) {
time = time + dt;
var result = LaserPointers.getPrevRayPickResult(ray);
var dirColor = Vec3.multiply(255, Vec3.multiply(0.5, Vec3.sum({x:1, y:1, z:1}, Vec3.normalize(result.searchRay.direction))));
end.color.red = dirColor.x;
end.color.blue = dirColor.y;
end.color.green = dirColor.z;
LaserPointers.editRenderState(ray, "test", {end: end});
if (lengthMode) {
LaserPointers.setLaserLength(ray, 4.0 + 2.0 * Math.cos(time));
}
}
Script.update.connect(update);
function keyPressEvent(event) {
if (event.text === '1') {
precisionPicking = !precisionPicking;
LaserPointers.setPrecisionPicking(ray, precisionPicking);
}
if (event.text === '2') {
lengthMode = !lengthMode;
if (!lengthMode) {
LaserPointers.setLaserLength(ray, 0.0);
}
}
if (event.text === '3') {
if (!lockedMode) {
var result = LaserPointers.getPrevRayPickResult(ray);
if (result.type == RayPick.INTERSECTED_ENTITY) {
LaserPointers.setLockEndUUID(ray, result.objectID, false);
lockedMode = !lockedMode;
}
} else {
LaserPointers.setLockEndUUID(ray, null, false);
lockedMode = !lockedMode;
}
}
}
Controller.keyPressEvent.connect(keyPressEvent);
}()); // END LOCAL_SCOPE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment