void ParabolaPointer::RenderState::update(const glm::vec3& origin, const glm::vec3& end, const glm::vec3& surfaceNormal, float parentScale, bool distanceScaleEnd, bool centerEndY, bool faceAvatar, bool followNormal, float followNormalStrength, float distance, const PickResultPointer& pickResult) { StartEndRenderState::update(origin, end, surfaceNormal, parentScale, distanceScaleEnd, centerEndY, faceAvatar, followNormal, followNormalStrength, distance, pickResult); auto parabolaPickResult = std::static_pointer_cast<ParabolaPickResult>(pickResult); if (parabolaPickResult && render::Item::isValidID(_pathID)) { render::Transaction transaction; auto scene = qApp->getMain3DScene(); PickParabola parabola = PickParabola(parabolaPickResult->pickVariant); glm::vec3 velocity = parabola.velocity; glm::vec3 acceleration = parabola.acceleration; float parabolicDistance = distance > 0.0f ? distance : parabolaPickResult->parabolicDistance; float width = getPathWidth() * parentScale; transaction.updateItem<ParabolaRenderItem>(_pathID, [origin, velocity, acceleration, parabolicDistance, width](ParabolaRenderItem& item) { item.setVisible(true); item.setOrigin(origin); item.setVelocity(velocity); item.setAcceleration(acceleration); item.setParabolicDistance(parabolicDistance); item.setWidth(width); item.updateBounds(); }); scene->enqueueTransaction(transaction); } }
PickParabola ParabolaPick::getMathematicalPick() const { if (!parentTransform) { PickParabola mathPick = _mathPick; if (_rotateAccelerationWithAvatar) { mathPick.acceleration = DependencyManager::get<AvatarManager>()->getMyAvatar()->getWorldOrientation() * mathPick.acceleration; } return mathPick; } Transform currentParentTransform = parentTransform->getTransform(); glm::vec3 position = currentParentTransform.transform(_mathPick.origin); glm::vec3 velocity = _mathPick.velocity; if (_scaleWithParent) { velocity = currentParentTransform.transformDirection(velocity); } else { glm::vec3 transformedVelocity = currentParentTransform.transformDirection(velocity); velocity = glm::normalize(transformedVelocity) * _speed; } glm::vec3 acceleration = _mathPick.acceleration; if (_scaleWithParent) { acceleration *= currentParentTransform.getScale(); } if (_rotateAccelerationWithAvatar) { acceleration = DependencyManager::get<AvatarManager>()->getMyAvatar()->getWorldOrientation() * acceleration; } else if (_rotateAccelerationWithParent) { acceleration = currentParentTransform.getRotation() * acceleration; } return PickParabola(position, velocity, acceleration); }
ParabolaPick::ParabolaPick(const glm::vec3& position, const glm::vec3& direction, float speed, const glm::vec3& accelerationAxis, bool rotateAccelerationWithAvatar, bool rotateAccelerationWithParent, bool scaleWithParent, const PickFilter& filter, float maxDistance, bool enabled) : Pick(PickParabola(position, speed * direction, accelerationAxis), filter, maxDistance, enabled), _rotateAccelerationWithAvatar(rotateAccelerationWithAvatar), _rotateAccelerationWithParent(rotateAccelerationWithParent), _scaleWithParent(scaleWithParent), _speed(speed) { }
glm::vec3 ParabolaPointer::getPickEnd(const PickResultPointer& pickResult, float distance) const { auto parabolaPickResult = std::static_pointer_cast<ParabolaPickResult>(pickResult); if (!parabolaPickResult) { return glm::vec3(0.0f); } if (distance > 0.0f) { PickParabola pick = PickParabola(parabolaPickResult->pickVariant); return pick.origin + pick.velocity * distance + 0.5f * pick.acceleration * distance * distance; } else { return parabolaPickResult->intersection; } }
void ParabolaPointer::setVisualPickResultInternal(PickResultPointer pickResult, IntersectionType type, const QUuid& id, const glm::vec3& intersection, float distance, const glm::vec3& surfaceNormal) { auto parabolaPickResult = std::static_pointer_cast<ParabolaPickResult>(pickResult); if (parabolaPickResult) { parabolaPickResult->type = type; parabolaPickResult->objectID = id; parabolaPickResult->intersection = intersection; parabolaPickResult->distance = distance; parabolaPickResult->surfaceNormal = surfaceNormal; PickParabola parabola = PickParabola(parabolaPickResult->pickVariant); parabolaPickResult->pickVariant["velocity"] = vec3toVariant((intersection - parabola.origin - 0.5f * parabola.acceleration * parabolaPickResult->parabolicDistance * parabolaPickResult->parabolicDistance) / parabolaPickResult->parabolicDistance); } }