mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:47:30 +02:00
fix ray-pick results on entities with non-default registration point. clean up grab scripts to correctly use this fix.
This commit is contained in:
parent
657373d02f
commit
52bbb4d2ab
5 changed files with 45 additions and 44 deletions
|
@ -105,7 +105,7 @@ PickResultPointer PathPointer::getVisualPickResult(const PickResultPointer& pick
|
|||
glm::mat4 entityMat = createMatFromQuatAndPos(props.getRotation(), props.getPosition());
|
||||
glm::mat4 finalPosAndRotMat = entityMat * _lockEndObject.offsetMat;
|
||||
pos = extractTranslation(finalPosAndRotMat);
|
||||
rot = glmExtractRotation(finalPosAndRotMat);
|
||||
rot = props.getRotation();
|
||||
dim = props.getDimensions();
|
||||
registrationPoint = props.getRegistrationPoint();
|
||||
}
|
||||
|
@ -350,4 +350,4 @@ glm::vec2 PathPointer::findPos2D(const PickedObject& pickedObject, const glm::ve
|
|||
default:
|
||||
return glm::vec2(NAN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD,
|
||||
DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_OFF_VALUE, TRIGGER_ON_VALUE, ZERO_VEC, ensureDynamic,
|
||||
getControllerWorldLocation, projectOntoEntityXYPlane, ContextOverlay, HMD, Reticle, Overlays, isPointingAtUI
|
||||
Picks, makeLaserLockInfo Xform, makeLaserParams, AddressManager, getEntityParents, Selection, DISPATCHER_HOVERING_LIST
|
||||
Picks, makeLaserLockInfo Xform, makeLaserParams, AddressManager, getEntityParents, Selection, DISPATCHER_HOVERING_LIST,
|
||||
worldPositionToRegistrationFrameMatrix
|
||||
*/
|
||||
|
||||
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
||||
|
@ -593,18 +594,9 @@ Script.include("/~/system/libraries/Xform.js");
|
|||
|
||||
this.calculateOffset = function(controllerData) {
|
||||
if (this.distanceHolding || this.distanceRotating) {
|
||||
var targetProps = Entities.getEntityProperties(this.targetObject.entityID, [
|
||||
"position",
|
||||
"rotation"
|
||||
]);
|
||||
var zeroVector = { x: 0, y: 0, z:0, w: 0 };
|
||||
var intersection = controllerData.rayPicks[this.hand].intersection;
|
||||
var intersectionMat = new Xform(zeroVector, intersection);
|
||||
var modelMat = new Xform(targetProps.rotation, targetProps.position);
|
||||
var modelMatInv = modelMat.inv();
|
||||
var xformMat = Xform.mul(modelMatInv, intersectionMat);
|
||||
var offsetMat = Mat4.createFromRotAndTrans(xformMat.rot, xformMat.pos);
|
||||
return offsetMat;
|
||||
var targetProps = Entities.getEntityProperties(this.targetObject.entityID,
|
||||
[ "position", "rotation", "registrationPoint", "dimensions" ]);
|
||||
return worldPositionToRegistrationFrameMatrix(targetProps, controllerData.rayPicks[this.hand].intersection);
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
makeDispatcherModuleParameters, MSECS_PER_SEC, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, TRIGGER_OFF_VALUE,
|
||||
TRIGGER_ON_VALUE, ZERO_VEC, getControllerWorldLocation, projectOntoEntityXYPlane, ContextOverlay, HMD,
|
||||
Picks, makeLaserLockInfo, Xform, makeLaserParams, AddressManager, getEntityParents, Selection, DISPATCHER_HOVERING_LIST,
|
||||
Uuid
|
||||
Uuid, worldPositionToRegistrationFrameMatrix
|
||||
*/
|
||||
|
||||
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
||||
|
@ -572,18 +572,9 @@ Script.include("/~/system/libraries/Xform.js");
|
|||
|
||||
this.calculateOffset = function(controllerData) {
|
||||
if (this.distanceHolding || this.distanceRotating) {
|
||||
var targetProps = Entities.getEntityProperties(this.targetObject.entityID, [
|
||||
"position",
|
||||
"rotation"
|
||||
]);
|
||||
var zeroVector = { x: 0, y: 0, z:0, w: 0 };
|
||||
var intersection = controllerData.rayPicks[this.hand].intersection;
|
||||
var intersectionMat = new Xform(zeroVector, intersection);
|
||||
var modelMat = new Xform(targetProps.rotation, targetProps.position);
|
||||
var modelMatInv = modelMat.inv();
|
||||
var xformMat = Xform.mul(modelMatInv, intersectionMat);
|
||||
var offsetMat = Mat4.createFromRotAndTrans(xformMat.rot, xformMat.pos);
|
||||
return offsetMat;
|
||||
var targetProps = Entities.getEntityProperties(this.targetObject.entityID,
|
||||
[ "position", "rotation", "registrationPoint", "dimensions" ]);
|
||||
return worldPositionToRegistrationFrameMatrix(targetProps, controllerData.rayPicks[this.hand].intersection);
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
Entities, enableDispatcherModule, disableDispatcherModule, entityIsGrabbable, makeDispatcherModuleParameters, MSECS_PER_SEC,
|
||||
HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, TRIGGER_OFF_VALUE, TRIGGER_ON_VALUE, ZERO_VEC, getControllerWorldLocation,
|
||||
projectOntoEntityXYPlane, ContextOverlay, HMD, Picks, makeLaserLockInfo, Xform, makeLaserParams, AddressManager,
|
||||
getEntityParents, Selection, DISPATCHER_HOVERING_LIST, unhighlightTargetEntity, Messages, Uuid, findGroupParent
|
||||
getEntityParents, Selection, DISPATCHER_HOVERING_LIST, unhighlightTargetEntity, Messages, Uuid, findGroupParent,
|
||||
worldPositionToRegistrationFrameMatrix
|
||||
*/
|
||||
|
||||
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
||||
|
@ -615,18 +616,9 @@ Script.include("/~/system/libraries/Xform.js");
|
|||
|
||||
this.calculateOffset = function(controllerData) {
|
||||
if (this.distanceHolding || this.distanceRotating) {
|
||||
var targetProps = Entities.getEntityProperties(this.targetObject.entityID, [
|
||||
"position",
|
||||
"rotation"
|
||||
]);
|
||||
var zeroVector = { x: 0, y: 0, z:0, w: 0 };
|
||||
var intersection = controllerData.rayPicks[this.hand].intersection;
|
||||
var intersectionMat = new Xform(zeroVector, intersection);
|
||||
var modelMat = new Xform(targetProps.rotation, targetProps.position);
|
||||
var modelMatInv = modelMat.inv();
|
||||
var xformMat = Xform.mul(modelMatInv, intersectionMat);
|
||||
var offsetMat = Mat4.createFromRotAndTrans(xformMat.rot, xformMat.pos);
|
||||
return offsetMat;
|
||||
var targetProps = Entities.getEntityProperties(this.targetObject.entityID,
|
||||
[ "position", "rotation", "registrationPoint", "dimensions" ]);
|
||||
return worldPositionToRegistrationFrameMatrix(targetProps, controllerData.rayPicks[this.hand].intersection);
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
/* global module, Camera, HMD, MyAvatar, controllerDispatcherPlugins:true, Quat, Vec3, Overlays, Xform,
|
||||
/* global module, Camera, HMD, MyAvatar, controllerDispatcherPlugins:true, Quat, Vec3, Overlays, Xform, Mat4,
|
||||
Selection, Uuid,
|
||||
MSECS_PER_SEC:true , LEFT_HAND:true, RIGHT_HAND:true, FORBIDDEN_GRAB_TYPES:true,
|
||||
HAPTIC_PULSE_STRENGTH:true, HAPTIC_PULSE_DURATION:true, ZERO_VEC:true, ONE_VEC:true,
|
||||
|
@ -58,7 +58,8 @@
|
|||
highlightTargetEntity:true,
|
||||
clearHighlightedEntities:true,
|
||||
unhighlightTargetEntity:true,
|
||||
distanceBetweenEntityLocalPositionAndBoundingBox: true
|
||||
distanceBetweenEntityLocalPositionAndBoundingBox: true,
|
||||
worldPositionToRegistrationFrameMatrix: true
|
||||
*/
|
||||
|
||||
MSECS_PER_SEC = 1000.0;
|
||||
|
@ -487,6 +488,30 @@ entityIsFarGrabbedByOther = function(entityID) {
|
|||
return false;
|
||||
};
|
||||
|
||||
|
||||
worldPositionToRegistrationFrameMatrix = function(wptrProps, pos) {
|
||||
// get world matrix for intersection point
|
||||
var intersectionMat = new Xform({ x: 0, y: 0, z:0, w: 1 }, pos);
|
||||
|
||||
// calculate world matrix for registrationPoint addjusted entity
|
||||
var DEFAULT_REGISTRATION_POINT = { x: 0.5, y: 0.5, z: 0.5 };
|
||||
var regRatio = Vec3.subtract(DEFAULT_REGISTRATION_POINT, wptrProps.registrationPoint);
|
||||
var regOffset = Vec3.multiplyVbyV(regRatio, wptrProps.dimensions);
|
||||
var regOffsetRot = Vec3.multiplyQbyV(wptrProps.rotation, regOffset);
|
||||
var modelMat = new Xform(wptrProps.rotation, Vec3.sum(wptrProps.position, regOffsetRot));
|
||||
|
||||
// get inverse of model matrix
|
||||
var modelMatInv = modelMat.inv();
|
||||
|
||||
// transform world intersection point into object's registrationPoint frame
|
||||
var xformMat = Xform.mul(modelMatInv, intersectionMat);
|
||||
|
||||
// convert to Mat4
|
||||
var offsetMat = Mat4.createFromRotAndTrans(xformMat.rot, xformMat.pos);
|
||||
return offsetMat;
|
||||
};
|
||||
|
||||
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = {
|
||||
makeDispatcherModuleParameters: makeDispatcherModuleParameters,
|
||||
|
@ -508,6 +533,7 @@ if (typeof module !== 'undefined') {
|
|||
projectOntoEntityXYPlane: projectOntoEntityXYPlane,
|
||||
TRIGGER_OFF_VALUE: TRIGGER_OFF_VALUE,
|
||||
TRIGGER_ON_VALUE: TRIGGER_ON_VALUE,
|
||||
DISPATCHER_HOVERING_LIST: DISPATCHER_HOVERING_LIST
|
||||
DISPATCHER_HOVERING_LIST: DISPATCHER_HOVERING_LIST,
|
||||
worldPositionToRegistrationFrameMatrix: worldPositionToRegistrationFrameMatrix
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue