diff --git a/examples/pointer.js b/examples/pointer.js index 2d7b601baa..d4348e19aa 100644 --- a/examples/pointer.js +++ b/examples/pointer.js @@ -24,23 +24,28 @@ function removeLine() { function createOrUpdateLine(event) { var pickRay = Camera.computePickRay(event.x, event.y); var intersection = Entities.findRayIntersection(pickRay, true); // accurate picking + var props = Entities.getEntityProperties(intersection.entityID); - if (lineIsRezzed) { - Entities.editEntity(lineEntityID, { - position: nearLinePoint(intersection.intersection), - dimensions: Vec3.subtract(intersection.intersection, nearLinePoint(intersection.intersection)), - lifetime: 30 // renew lifetime - }); - + if (intersection.intersects) { + var dim = Vec3.subtract(intersection.intersection, nearLinePoint(intersection.intersection)); + if (lineIsRezzed) { + Entities.editEntity(lineEntityID, { + position: nearLinePoint(intersection.intersection), + dimensions: dim, + lifetime: 60 + props.lifespan // renew lifetime + }); + } else { + lineIsRezzed = true; + lineEntityID = Entities.addEntity({ + type: "Line", + position: nearLinePoint(intersection.intersection), + dimensions: dim, + color: { red: 255, green: 255, blue: 255 }, + lifetime: 60 // if someone crashes while pointing, don't leave the line there forever. + }); + } } else { - lineIsRezzed = true; - lineEntityID = Entities.addEntity({ - type: "Line", - position: nearLinePoint(intersection.intersection), - dimensions: Vec3.subtract(intersection.intersection, nearLinePoint(intersection.intersection)), - color: { red: 255, green: 255, blue: 255 }, - lifetime: 30 // if someone crashes while pointing, don't leave the line there forever. - }); + removeLine(); } } diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h index a834fee816..a8bc867bdd 100644 --- a/libraries/entities/src/LineEntityItem.h +++ b/libraries/entities/src/LineEntityItem.h @@ -53,6 +53,12 @@ class LineEntityItem : public EntityItem { virtual ShapeType getShapeType() const { return SHAPE_TYPE_LINE; } + // never have a ray intersection pick a LineEntityItem. + virtual bool supportsDetailedRayIntersection() const { return true; } + virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, + bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, + void** intersectedObject, bool precisionPicking) const { return false; } + virtual void debugDump() const; protected: