mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-19 13:44:20 +02:00
Merge pull request #7573 from sethalves/update-collision-hulls-of-avatar-children
Update collision hulls of avatar children
This commit is contained in:
commit
e7d75cb22e
5 changed files with 59 additions and 14 deletions
|
@ -12,7 +12,7 @@
|
|||
// 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, randFloat, randInt, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */
|
||||
|
||||
Script.include("../libraries/utils.js");
|
||||
Script.include("/~/libraries/utils.js");
|
||||
|
||||
|
||||
//
|
||||
|
@ -79,6 +79,7 @@ var NEAR_PICK_MAX_DISTANCE = 0.3; // max length of pick-ray for close grabbing t
|
|||
var PICK_BACKOFF_DISTANCE = 0.2; // helps when hand is intersecting the grabble object
|
||||
var NEAR_GRABBING_KINEMATIC = true; // force objects to be kinematic when near-grabbed
|
||||
var SHOW_GRAB_SPHERE = false; // draw a green sphere to show the grab search position and size
|
||||
var CHECK_TOO_FAR_UNEQUIP_TIME = 1.0; // seconds
|
||||
|
||||
//
|
||||
// equip
|
||||
|
@ -290,11 +291,13 @@ function MyController(hand) {
|
|||
this.intersectionDistance = 0.0;
|
||||
this.searchSphereDistance = DEFAULT_SEARCH_SPHERE_DISTANCE;
|
||||
|
||||
|
||||
this.ignoreIK = false;
|
||||
this.offsetPosition = Vec3.ZERO;
|
||||
this.offsetRotation = Quat.IDENTITY;
|
||||
|
||||
this.lastPickTime = 0;
|
||||
this.lastUnequipCheckTime = 0;
|
||||
|
||||
var _this = this;
|
||||
|
||||
this.update = function() {
|
||||
|
@ -1523,18 +1526,30 @@ function MyController(hand) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (props.parentID == MyAvatar.sessionUUID &&
|
||||
Vec3.length(props.localPosition) > NEAR_PICK_MAX_DISTANCE * 2.0) {
|
||||
// for whatever reason, the held/equipped entity has been pulled away. ungrab or unequip.
|
||||
print("handControllerGrab -- autoreleasing held or equipped item because it is far from hand." +
|
||||
props.parentID + " " + vec3toStr(props.position));
|
||||
this.setState(STATE_RELEASE);
|
||||
if (this.state == STATE_CONTINUE_NEAR_GRABBING) {
|
||||
this.callEntityMethodOnGrabbed("releaseGrab");
|
||||
} else { // (this.state == STATE_CONTINUE_EQUIP || this.state == STATE_CONTINUE_HOLD)
|
||||
this.callEntityMethodOnGrabbed("releaseEquip");
|
||||
|
||||
var now = Date.now();
|
||||
if (now - this.lastUnequipCheckTime > MSECS_PER_SEC * CHECK_TOO_FAR_UNEQUIP_TIME) {
|
||||
this.lastUnequipCheckTime = now;
|
||||
|
||||
if (props.parentID == MyAvatar.sessionUUID &&
|
||||
Vec3.length(props.localPosition) > NEAR_PICK_MAX_DISTANCE * 2.0) {
|
||||
var handPosition = this.getHandPosition();
|
||||
// the center of the equipped object being far from the hand isn't enough to autoequip -- we also
|
||||
// need to fail the findEntities test.
|
||||
nearPickedCandidateEntities = Entities.findEntities(handPosition, GRAB_RADIUS);
|
||||
if (nearPickedCandidateEntities.indexOf(this.grabbedEntity) == -1) {
|
||||
// for whatever reason, the held/equipped entity has been pulled away. ungrab or unequip.
|
||||
print("handControllerGrab -- autoreleasing held or equipped item because it is far from hand." +
|
||||
props.parentID + " " + vec3toStr(props.position));
|
||||
this.setState(STATE_RELEASE);
|
||||
if (this.state == STATE_CONTINUE_NEAR_GRABBING) {
|
||||
this.callEntityMethodOnGrabbed("releaseGrab");
|
||||
} else { // (this.state == STATE_CONTINUE_EQUIP || this.state == STATE_CONTINUE_HOLD)
|
||||
this.callEntityMethodOnGrabbed("releaseEquip");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Keep track of the fingertip velocity to impart when we release the object.
|
||||
|
|
|
@ -888,6 +888,9 @@ void EntityItem::simulateKinematicMotion(float timeElapsed, bool setFlags) {
|
|||
if (hasActions()) {
|
||||
return;
|
||||
}
|
||||
if (!_parentID.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasLocalAngularVelocity()) {
|
||||
glm::vec3 localAngularVelocity = getLocalAngularVelocity();
|
||||
|
@ -1975,6 +1978,11 @@ QList<EntityActionPointer> EntityItem::getActionsOfType(EntityActionType typeToG
|
|||
|
||||
void EntityItem::locationChanged() {
|
||||
requiresRecalcBoxes();
|
||||
_dirtyFlags |= Simulation::DIRTY_TRANSFORM;
|
||||
EntityTreePointer tree = getTree();
|
||||
if (tree) {
|
||||
tree->entityChanged(getThisPointer());
|
||||
}
|
||||
SpatiallyNestable::locationChanged(); // tell all the children, also
|
||||
}
|
||||
|
||||
|
@ -1984,6 +1992,7 @@ void EntityItem::dimensionsChanged() {
|
|||
}
|
||||
|
||||
void EntityItem::globalizeProperties(EntityItemProperties& properties, const QString& messageTemplate, const glm::vec3& offset) const {
|
||||
// TODO -- combine this with convertLocationToScriptSemantics
|
||||
bool success;
|
||||
auto globalPosition = getPosition(success);
|
||||
if (success) {
|
||||
|
|
|
@ -161,7 +161,12 @@ PhysicsMotionType EntityMotionState::computePhysicsMotionType() const {
|
|||
}
|
||||
return MOTION_TYPE_DYNAMIC;
|
||||
}
|
||||
return (_entity->isMovingRelativeToParent() || _entity->hasActions()) ? MOTION_TYPE_KINEMATIC : MOTION_TYPE_STATIC;
|
||||
if (_entity->isMovingRelativeToParent() ||
|
||||
_entity->hasActions() ||
|
||||
_entity->hasAncestorOfType(NestableType::Avatar)) {
|
||||
return MOTION_TYPE_KINEMATIC;
|
||||
}
|
||||
return MOTION_TYPE_STATIC;
|
||||
}
|
||||
|
||||
bool EntityMotionState::isMoving() const {
|
||||
|
|
|
@ -849,3 +849,17 @@ AACube SpatiallyNestable::getQueryAACube() const {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SpatiallyNestable::hasAncestorOfType(NestableType nestableType) {
|
||||
bool success;
|
||||
SpatiallyNestablePointer parent = getParentPointer(success);
|
||||
if (!success || !parent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (parent->_nestableType == nestableType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return parent->hasAncestorOfType(nestableType);
|
||||
}
|
||||
|
|
|
@ -142,6 +142,8 @@ public:
|
|||
bool isParentIDValid() const { bool success = false; getParentPointer(success); return success; }
|
||||
virtual SpatialParentTree* getParentTree() const { return nullptr; }
|
||||
|
||||
bool hasAncestorOfType(NestableType nestableType);
|
||||
|
||||
protected:
|
||||
const NestableType _nestableType; // EntityItem or an AvatarData
|
||||
QUuid _id;
|
||||
|
|
Loading…
Reference in a new issue