markers and eraser reset to original positions after being dropped

This commit is contained in:
ericrius1 2016-02-26 14:49:48 -08:00
parent 48f03ba476
commit d0752143dc
3 changed files with 42 additions and 11 deletions

View file

@ -24,6 +24,7 @@
_this.ERASER_TRIGGER_THRESHOLD = 0.2;
_this.STROKE_NAME = "hifi-marker-stroke";
_this.ERASER_TO_STROKE_SEARCH_RADIUS = 0.7;
_this.ERASER_RESET_WAIT_TIME = 3000;
};
Eraser.prototype = {
@ -32,11 +33,15 @@
_this.equipped = true;
_this.hand = params[0] == "left" ? 0 : 1;
// We really only need to grab position of marker strokes once, and then just check to see if eraser comes near enough to those strokes
Overlays.editOverlay(_this.searchSphere, {visible: true});
Overlays.editOverlay(_this.searchSphere, {
visible: true
});
},
continueEquip: function() {
_this.eraserPosition = Entities.getEntityProperties(_this.entityID, "position").position;
Overlays.editOverlay(_this.searchSphere, {position: _this.eraserPosition});
_this.eraserPosition = Entities.getEntityProperties(_this.entityID, "position").position;
Overlays.editOverlay(_this.searchSphere, {
position: _this.eraserPosition
});
this.triggerValue = Controller.getValue(TRIGGER_CONTROLS[_this.hand]);
if (_this.triggerValue > _this.ERASER_TRIGGER_THRESHOLD) {
_this.continueHolding();
@ -57,14 +62,36 @@
},
releaseEquip: function() {
Overlays.editOverlay(_this.searchSphere, {visible: false});
Overlays.editOverlay(_this.searchSphere, {
visible: false
});
// Once user releases eraser, wait a bit then put marker back to its original position and rotation
Script.setTimeout(function() {
var userData = getEntityUserData(_this.entityID);
Entities.editEntity(_this.entityID, {
position: userData.originalPosition,
rotation: userData.originalRotation,
velocity: {
x: 0,
y: -0.01,
z: 0
}
});
}, _this.ERASER_RESET_WAIT_TIME);
},
preload: function(entityID) {
_this.entityID = entityID;
_this.searchSphere = Overlays.addOverlay('sphere', {
size: _this.ERASER_TO_STROKE_SEARCH_RADIUS,
color: {red: 200, green: 10, blue: 10},
color: {
red: 200,
green: 10,
blue: 10
},
alpha: 0.2,
solid: true,
visible: false

View file

@ -92,7 +92,8 @@
var intersection = Entities.findRayIntersectionBlocking(pickRay, true, _this.whiteboards);
if (intersection.intersects && Vec3.distance(intersection.intersection, markerProps.position) < _this.MAX_MARKER_TO_BOARD_DISTANCE) {
var whiteboardRotation = Entities.getEntityProperties(intersection.entityID, "rotation").rotation;
_this.currentWhiteboard = intersection.entityID;
var whiteboardRotation = Entities.getEntityProperties(_this.currentWhiteboard, "rotation").rotation;
_this.whiteboardNormal = Quat.getFront(whiteboardRotation);
Overlays.editOverlay(_this.laserPointer, {
visible: true,
@ -128,7 +129,8 @@
position: position,
textures: _this.MARKER_TEXTURE_URL,
color: _this.markerColor,
lifetime: 500
lifetime: 500,
// parentID: _this.currentWhiteboard
});
_this.linePoints = [];
@ -161,7 +163,6 @@
for (var i = 0; i < _this.linePoints.length; i++) {
// Create a temp array of stroke widths for calligraphy effect - start and end should be less wide
var pointsFromCenter = Math.abs(_this.linePoints.length / 2 - i);
print("EBL POINTS CENTER " + pointsFromCenter)
var pointWidth = map(pointsFromCenter, 0, this.linePoints.length / 2, _this.STROKE_WIDTH_RANGE.max, this.STROKE_WIDTH_RANGE.min);
strokeWidths.push(pointWidth);
}

View file

@ -80,15 +80,16 @@ var whiteboardFrontDrawingSurface = Entities.addEntity(whiteboardSurfaceSettings
whiteboardBackSurfacePosition = Vec3.sum(whiteboardSurfacePosition, Vec3.multiply(moveForwardDistance, Quat.getFront(whiteboardRotation)));
whiteboardSurfaceSettings.position = whiteboardBackSurfacePosition;
var whiteboardFrontDrawingSurface = Entities.addEntity(whiteboardSurfaceSettings);
var whiteboardBackDrawingSurface = Entities.addEntity(whiteboardSurfaceSettings);
var WHITEBOARD_RACK_DEPTH = 1.9;
var ERASER_MODEL_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/eraser-2.fbx";
var ERASER_SCRIPT_URL = Script.resolvePath("eraserEntityScript.js");
var ERASER_SCRIPT_URL = Script.resolvePath("eraserEntityScript.js?v43");
var eraserPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(WHITEBOARD_RACK_DEPTH, Quat.getFront(whiteboardRotation)));
eraserPosition = Vec3.sum(eraserPosition, Vec3.multiply(-0.5, Quat.getRight(whiteboardRotation)));
var eraserRotation = markerRotation;
var eraser = Entities.addEntity({
type: "Model",
@ -101,7 +102,7 @@ var eraser = Entities.addEntity({
y: 0.0393,
z: 0.2083
},
rotation: markerRotation,
rotation: eraserRotation,
dynamic: true,
gravity: {
x: 0,
@ -114,6 +115,8 @@ var eraser = Entities.addEntity({
z: 0
},
userData: JSON.stringify({
originalPosition: eraserPosition,
originalRotation: eraserRotation,
wearable: {
joints: {
RightHand: [{