mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
atlernate fix for selected entities
This commit is contained in:
parent
197662fd5e
commit
c99676b510
5 changed files with 53 additions and 27 deletions
|
@ -81,6 +81,50 @@ void LaserPointer::editRenderState(const std::string& state, const QVariant& sta
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PickResultPointer LaserPointer::getVisualPickResult(const PickResultPointer& pickResult) {
|
||||||
|
PickResultPointer visualPickResult = pickResult;
|
||||||
|
auto rayPickResult = std::static_pointer_cast<RayPickResult>(visualPickResult);
|
||||||
|
IntersectionType type = rayPickResult ? rayPickResult->type : IntersectionType::NONE;
|
||||||
|
|
||||||
|
if (type != IntersectionType::HUD) {
|
||||||
|
if (!_lockEndObject.id.isNull()) {
|
||||||
|
PickRay pickRay = rayPickResult ? PickRay(rayPickResult->pickVariant) : PickRay();
|
||||||
|
glm::vec3 endVec;
|
||||||
|
glm::vec3 pos;
|
||||||
|
glm::quat rot;
|
||||||
|
glm::vec3 dim;
|
||||||
|
glm::vec3 registrationPoint;
|
||||||
|
if (_lockEndObject.isOverlay) {
|
||||||
|
pos = vec3FromVariant(qApp->getOverlays().getProperty(_lockEndObject.id, "position").value);
|
||||||
|
rot = quatFromVariant(qApp->getOverlays().getProperty(_lockEndObject.id, "rotation").value);
|
||||||
|
dim = vec3FromVariant(qApp->getOverlays().getProperty(_lockEndObject.id, "dimensions").value);
|
||||||
|
registrationPoint = glm::vec3(0.5f);
|
||||||
|
} else {
|
||||||
|
EntityItemProperties props = DependencyManager::get<EntityScriptingInterface>()->getEntityProperties(_lockEndObject.id);
|
||||||
|
glm::mat4 entityMat = createMatFromQuatAndPos(props.getRotation(), props.getPosition());
|
||||||
|
glm::mat4 finalPosAndRotMat = entityMat * _lockEndObject.offsetMat;
|
||||||
|
pos = extractTranslation(finalPosAndRotMat);
|
||||||
|
rot = glmExtractRotation(finalPosAndRotMat);
|
||||||
|
dim = props.getDimensions();
|
||||||
|
registrationPoint = props.getRegistrationPoint();
|
||||||
|
}
|
||||||
|
const glm::vec3 DEFAULT_REGISTRATION_POINT = glm::vec3(0.5f);
|
||||||
|
endVec = pos + rot * (dim * (DEFAULT_REGISTRATION_POINT - registrationPoint));
|
||||||
|
glm::vec3 direction = endVec - pickRay.origin;
|
||||||
|
float distance = glm::distance(pickRay.origin, endVec);
|
||||||
|
glm::vec3 normalizedDirection = glm::normalize(direction);
|
||||||
|
|
||||||
|
rayPickResult->type = _lockEndObject.isOverlay ? IntersectionType::OVERLAY : IntersectionType::ENTITY;
|
||||||
|
rayPickResult->objectID = _lockEndObject.id;
|
||||||
|
rayPickResult->intersection = endVec;
|
||||||
|
rayPickResult->distance = distance;
|
||||||
|
rayPickResult->surfaceNormal = -normalizedDirection;
|
||||||
|
rayPickResult->pickVariant["direction"] = vec3toVariant(normalizedDirection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return visualPickResult;
|
||||||
|
}
|
||||||
|
|
||||||
void LaserPointer::updateRenderStateOverlay(const OverlayID& id, const QVariant& props) {
|
void LaserPointer::updateRenderStateOverlay(const OverlayID& id, const QVariant& props) {
|
||||||
if (!id.isNull() && props.isValid()) {
|
if (!id.isNull() && props.isValid()) {
|
||||||
QVariantMap propMap = props.toMap();
|
QVariantMap propMap = props.toMap();
|
||||||
|
@ -102,26 +146,7 @@ void LaserPointer::updateRenderState(const RenderState& renderState, const Inter
|
||||||
endVec = pickRay.origin + pickRay.direction * distance;
|
endVec = pickRay.origin + pickRay.direction * distance;
|
||||||
} else {
|
} else {
|
||||||
if (!_lockEndObject.id.isNull()) {
|
if (!_lockEndObject.id.isNull()) {
|
||||||
glm::vec3 pos;
|
endVec = pickRay.origin + pickRay.direction * distance;
|
||||||
glm::quat rot;
|
|
||||||
glm::vec3 dim;
|
|
||||||
glm::vec3 registrationPoint;
|
|
||||||
if (_lockEndObject.isOverlay) {
|
|
||||||
pos = vec3FromVariant(qApp->getOverlays().getProperty(_lockEndObject.id, "position").value);
|
|
||||||
rot = quatFromVariant(qApp->getOverlays().getProperty(_lockEndObject.id, "rotation").value);
|
|
||||||
dim = vec3FromVariant(qApp->getOverlays().getProperty(_lockEndObject.id, "dimensions").value);
|
|
||||||
registrationPoint = glm::vec3(0.5f);
|
|
||||||
} else {
|
|
||||||
EntityItemProperties props = DependencyManager::get<EntityScriptingInterface>()->getEntityProperties(_lockEndObject.id);
|
|
||||||
glm::mat4 entityMat = createMatFromQuatAndPos(props.getRotation(), props.getPosition());
|
|
||||||
glm::mat4 finalPosAndRotMat = entityMat * _lockEndObject.offsetMat;
|
|
||||||
pos = extractTranslation(finalPosAndRotMat);
|
|
||||||
rot = glmExtractRotation(finalPosAndRotMat);
|
|
||||||
dim = props.getDimensions();
|
|
||||||
registrationPoint = props.getRegistrationPoint();
|
|
||||||
}
|
|
||||||
const glm::vec3 DEFAULT_REGISTRATION_POINT = glm::vec3(0.5f);
|
|
||||||
endVec = pos + rot * (dim * (DEFAULT_REGISTRATION_POINT - registrationPoint));
|
|
||||||
} else {
|
} else {
|
||||||
if (type == IntersectionType::ENTITY) {
|
if (type == IntersectionType::ENTITY) {
|
||||||
endVec = DependencyManager::get<EntityScriptingInterface>()->getEntityTransform(objectID)[3];
|
endVec = DependencyManager::get<EntityScriptingInterface>()->getEntityTransform(objectID)[3];
|
||||||
|
@ -132,7 +157,6 @@ void LaserPointer::updateRenderState(const RenderState& renderState, const Inter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant end = vec3toVariant(endVec);
|
QVariant end = vec3toVariant(endVec);
|
||||||
if (!renderState.getPathID().isNull()) {
|
if (!renderState.getPathID().isNull()) {
|
||||||
QVariantMap pathProps;
|
QVariantMap pathProps;
|
||||||
|
@ -195,7 +219,7 @@ void LaserPointer::updateVisuals(const PickResultPointer& pickResult) {
|
||||||
IntersectionType type = rayPickResult ? rayPickResult->type : IntersectionType::NONE;
|
IntersectionType type = rayPickResult ? rayPickResult->type : IntersectionType::NONE;
|
||||||
if (_enabled && !_currentRenderState.empty() && _renderStates.find(_currentRenderState) != _renderStates.end() &&
|
if (_enabled && !_currentRenderState.empty() && _renderStates.find(_currentRenderState) != _renderStates.end() &&
|
||||||
(type != IntersectionType::NONE || _laserLength > 0.0f || !_lockEndObject.id.isNull())) {
|
(type != IntersectionType::NONE || _laserLength > 0.0f || !_lockEndObject.id.isNull())) {
|
||||||
PickRay pickRay(rayPickResult->pickVariant);
|
PickRay pickRay = rayPickResult ? PickRay(rayPickResult->pickVariant): PickRay();
|
||||||
QUuid uid = rayPickResult->objectID;
|
QUuid uid = rayPickResult->objectID;
|
||||||
float distance = _laserLength > 0.0f ? _laserLength : rayPickResult->distance;
|
float distance = _laserLength > 0.0f ? _laserLength : rayPickResult->distance;
|
||||||
updateRenderState(_renderStates[_currentRenderState], type, distance, uid, pickRay, false);
|
updateRenderState(_renderStates[_currentRenderState], type, distance, uid, pickRay, false);
|
||||||
|
@ -386,4 +410,4 @@ glm::vec2 LaserPointer::findPos2D(const PickedObject& pickedObject, const glm::v
|
||||||
default:
|
default:
|
||||||
return glm::vec2(NAN);
|
return glm::vec2(NAN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
PointerEvent buildPointerEvent(const PickedObject& target, const PickResultPointer& pickResult, const std::string& button = "", bool hover = true) override;
|
PointerEvent buildPointerEvent(const PickedObject& target, const PickResultPointer& pickResult, const std::string& button = "", bool hover = true) override;
|
||||||
|
|
||||||
|
PickResultPointer getVisualPickResult(const PickResultPointer& pickResult) override;
|
||||||
PickedObject getHoveredObject(const PickResultPointer& pickResult) override;
|
PickedObject getHoveredObject(const PickResultPointer& pickResult) override;
|
||||||
Pointer::Buttons getPressedButtons(const PickResultPointer& pickResult) override;
|
Pointer::Buttons getPressedButtons(const PickResultPointer& pickResult) override;
|
||||||
|
|
||||||
|
|
|
@ -254,8 +254,7 @@ void ContextOverlayInterface::contextOverlays_hoverLeaveOverlay(const OverlayID&
|
||||||
|
|
||||||
void ContextOverlayInterface::contextOverlays_hoverEnterEntity(const EntityItemID& entityID, const PointerEvent& event) {
|
void ContextOverlayInterface::contextOverlays_hoverEnterEntity(const EntityItemID& entityID, const PointerEvent& event) {
|
||||||
bool isMouse = event.getID() == PointerManager::MOUSE_POINTER_ID || DependencyManager::get<PointerManager>()->isMouse(event.getID());
|
bool isMouse = event.getID() == PointerManager::MOUSE_POINTER_ID || DependencyManager::get<PointerManager>()->isMouse(event.getID());
|
||||||
if (_currentEntityWithContextOverlay == entityID && contextOverlayFilterPassed(entityID)
|
if (contextOverlayFilterPassed(entityID) && _enabled && !isMouse) {
|
||||||
&& _enabled && !isMouse) {
|
|
||||||
enableEntityHighlight(entityID);
|
enableEntityHighlight(entityID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,8 +68,9 @@ void Pointer::update(unsigned int pointerID) {
|
||||||
// This only needs to be a read lock because update won't change any of the properties that can be modified from scripts
|
// This only needs to be a read lock because update won't change any of the properties that can be modified from scripts
|
||||||
withReadLock([&] {
|
withReadLock([&] {
|
||||||
auto pickResult = getPrevPickResult();
|
auto pickResult = getPrevPickResult();
|
||||||
updateVisuals(pickResult);
|
auto visualPickResult = getVisualPickResult(pickResult);
|
||||||
generatePointerEvents(pointerID, pickResult);
|
updateVisuals(visualPickResult);
|
||||||
|
generatePointerEvents(pointerID, visualPickResult);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,7 @@ protected:
|
||||||
|
|
||||||
virtual bool shouldHover(const PickResultPointer& pickResult) { return true; }
|
virtual bool shouldHover(const PickResultPointer& pickResult) { return true; }
|
||||||
virtual bool shouldTrigger(const PickResultPointer& pickResult) { return true; }
|
virtual bool shouldTrigger(const PickResultPointer& pickResult) { return true; }
|
||||||
|
virtual PickResultPointer getVisualPickResult(const PickResultPointer& pickResult) { return pickResult; };
|
||||||
|
|
||||||
static const float POINTER_MOVE_DELAY;
|
static const float POINTER_MOVE_DELAY;
|
||||||
static const float TOUCH_PRESS_TO_MOVE_DEADSPOT_SQUARED;
|
static const float TOUCH_PRESS_TO_MOVE_DEADSPOT_SQUARED;
|
||||||
|
|
Loading…
Reference in a new issue