Ignoring unknown types in collision

This commit is contained in:
ericrius1 2015-10-14 11:15:49 -07:00
parent caacbcbe78
commit 20d1a2440c
3 changed files with 47 additions and 18 deletions

View file

@ -67,7 +67,7 @@ var MSEC_PER_SEC = 1000.0;
var startTime = Date.now();
var LIFETIME = 10;
var ACTION_LIFETIME = 10; // seconds
var PICKS_PER_SECOND_PER_HAND = 5;
var PICKS_PER_SECOND_PER_HAND = 60;
var MSECS_PER_SEC = 1000.0;
// states for the state machine
@ -177,6 +177,7 @@ function MyController(hand, triggerAction) {
this.continueFarGrabbingNonColliding();
break;
case STATE_RELEASE:
print("TRIGGER VALUE " + this.triggerValue);
this.release();
break;
}

View file

@ -20,8 +20,6 @@
var _this;
var RIGHT_HAND = 1;
var LEFT_HAND = 0;
var SPATIAL_CONTROLLERS_PER_PALM = 2;
var TIP_CONTROLLER_OFFSET = 1;
var MIN_POINT_DISTANCE = 0.02;
var MAX_POINT_DISTANCE = 0.5;
var MAX_POINTS_PER_LINE = 40;
@ -58,7 +56,9 @@
this.getHandRotation = MyAvatar.getLeftPalmRotation;
this.triggerAction = Controller.findAction("LEFT_HAND_CLICK");
}
Overlays.editOverlay(this.laserPointer, {visible: true});
Overlays.editOverlay(this.laserPointer, {
visible: true
});
},
continueFarGrabbingNonColliding: function() {
@ -69,13 +69,14 @@
};
this.intersection = Entities.findRayIntersection(pickRay, true, this.whitelist);
if (this.intersection.intersects) {
var distance = Vec3.distance(handPosition, this.intersection.intersection);
if (distance < MAX_DISTANCE) {
this.triggerValue = Controller.getActionValue(this.triggerAction);
this.currentStrokeWidth = map(this.triggerValue, 0, 1, MIN_STROKE_WIDTH, MAX_STROKE_WIDTH);
var displayPoint = this.intersection.intersection;
displayPoint = Vec3.sum(displayPoint, Vec3.multiply(this.intersection.surfaceNormal, -.01));
displayPoint = Vec3.sum(displayPoint, Vec3.multiply(this.intersection.surfaceNormal, -0.01));
Overlays.editOverlay(this.laserPointer, {
position: displayPoint,
size: {
@ -90,11 +91,22 @@
this.oldPosition = null;
}
}
} else {
this.releaseGrab();
} else if(this.intersection.properties.type !== "Unknown") {
//If type is unknown, ignore
print("entity name " + this.intersection.properties.type);
this.stopPainting();
}
},
stopPainting: function() {
this.painting = false;
Overlays.editOverlay(this.laserPointer, {
visible: false
});
this.oldPosition = null;
print("STOP PAINTING");
},
paint: function(position, normal) {
if (this.painting === false) {
if (this.oldPosition) {
@ -108,11 +120,12 @@
var localPoint = Vec3.subtract(position, this.strokeBasePosition);
//Move stroke a bit forward along normal so it doesnt zfight with mesh its drawing on
localPoint = Vec3.sum(localPoint, Vec3.multiply(this.normal, 0.001 + Math.random() * .001)); //rand avoid z fighting
localPoint = Vec3.sum(localPoint, Vec3.multiply(this.normal, 0.001 + Math.random() * 0.001)); //rand avoid z fighting
this.oldPosition = position;
var distance = Vec3.distance(localPoint, this.strokePoints[this.strokePoints.length - 1]);
if (this.strokePoints.length > 0 && distance < MIN_POINT_DISTANCE) {
//need a minimum distance to avoid binormal NANs
return;
}
if (this.strokePoints.length > 0 && distance > MAX_POINT_DISTANCE) {
@ -140,7 +153,6 @@
this.painting = false;
return;
}
this.oldPosition = position;
},
@ -168,9 +180,9 @@
},
releaseGrab: function() {
this.painting = false;
Overlays.editOverlay(this.laserPointer, {visible: false});
this.oldPosition = null;
print("RELEASE");
this.stopPainting();
},
changeColor: function() {
@ -184,7 +196,7 @@
var entities = Entities.findEntities(this.position, 5);
entities.forEach(function(entity) {
var name = Entities.getEntityProperties(entity, "name").name;
if(name === "paintStroke") {
if (name === "paintStroke") {
Entities.deleteEntity(entity);
}
});

View file

@ -11,8 +11,8 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
/*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */
// Script specific
/*global hexToRgb */
Script.include("../../libraries/utils.js");
var scriptURL = Script.resolvePath("whiteBoardEntityScript.js?v2");
@ -38,6 +38,7 @@ var colors = [
];
var whiteboard = Entities.addEntity({
type: "Box",
name: "whiteboard",
position: center,
rotation: rotation,
script: scriptURL,
@ -61,7 +62,7 @@ var colorBoxes = [];
var colorSquareDimensions = {
x: (whiteboardDimensions.x / 2) / (colors.length - 1),
y: .1,
y: 0.1,
z: 0.05
};
colorBoxPosition.y += whiteboardDimensions.y / 2 + colorSquareDimensions.y / 2 - 0.01;
@ -76,7 +77,6 @@ for (var i = 0; i < colors.length; i++) {
color: colors[i],
script: scriptURL,
userData: JSON.stringify({
colorPalette: true,
whiteboard: whiteboard
})
});
@ -84,6 +84,21 @@ for (var i = 0; i < colors.length; i++) {
colorBoxPosition = Vec3.sum(colorBoxPosition, spaceBetweenColorBoxes);
}
var blackBoxDimensions = {x: .2, y: .2, z: 0.05};
colorBoxPosition = Vec3.subtract(center, Vec3.multiply(direction, whiteboardDimensions.x / 2 + blackBoxDimensions.x/2 - 0.01));
colorBoxPosition.y += 0.3;
var blackBox = Entities.addEntity({
type: 'Box',
position: colorBoxPosition,
dimensions: blackBoxDimensions,
rotation: rotation,
color: {red: 0, green: 0, blue: 0},
script: scriptURL,
userData: JSON.stringify({
whiteboard: whiteboard
})
})
var eraseBoxDimensions = {
x: 0.5,
@ -124,6 +139,7 @@ print(JSON.stringify(Entities.getEntityProperties(eraseAllText)))
function cleanup() {
Entities.deleteEntity(whiteboard);
Entities.deleteEntity(eraseAllText);
Entities.deleteEntity(blackBox);
colorBoxes.forEach(function(colorBox) {
Entities.deleteEntity(colorBox);
});