base palm position on finger joint rather than an offset from hand joint. double size of near-grab sphere

This commit is contained in:
Seth Alves 2016-02-01 18:11:27 -08:00
parent 8d8e3520d5
commit 2501be16cb
4 changed files with 69 additions and 4 deletions

View file

@ -69,13 +69,14 @@ var PICK_MAX_DISTANCE = 500; // max length of pick-ray
// near grabbing
//
var GRAB_RADIUS = 0.03; // if the ray misses but an object is this close, it will still be selected
var GRAB_RADIUS = 0.06; // if the ray misses but an object is this close, it will still be selected
var NEAR_GRABBING_ACTION_TIMEFRAME = 0.05; // how quickly objects move to their new position
var NEAR_GRABBING_VELOCITY_SMOOTH_RATIO = 1.0; // adjust time-averaging of held object's velocity. 1.0 to disable.
var NEAR_PICK_MAX_DISTANCE = 0.3; // max length of pick-ray for close grabbing to be selected
var RELEASE_VELOCITY_MULTIPLIER = 1.5; // affects throwing things
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
//
// equip
@ -256,6 +257,7 @@ function MyController(hand) {
//for visualizations
this.overlayLine = null;
this.particleBeamObject = null;
this.grabSphere = null;
//for lights
this.spotlight = null;
@ -336,6 +338,7 @@ function MyController(hand) {
}
this.setState = function(newState) {
this.grabSphereOff();
if (WANT_DEBUG || WANT_DEBUG_STATE) {
print("STATE (" + this.hand + "): " + stateToName(this.state) + " --> " +
stateToName(newState) + ", hand: " + this.hand);
@ -416,6 +419,37 @@ function MyController(hand) {
}
}
this.grabSphereOn = function() {
var color = {red: 0, green: 255, blue: 0};
if (this.grabSphere === null) {
var sphereProperties = {
position: this.getHandPosition(),
size: GRAB_RADIUS*2,
color: color,
alpha: 0.1,
solid: true,
visible: true
}
this.grabSphere = Overlays.addOverlay("sphere", sphereProperties);
} else {
Overlays.editOverlay(this.grabSphere, {
position: this.getHandPosition(),
size: GRAB_RADIUS*2,
color: color,
alpha: 0.1,
solid: true,
visible: true
});
}
}
this.grabSphereOff = function() {
if (this.grabSphere !== null) {
Overlays.deleteOverlay(this.grabSphere);
this.grabSphere = null;
}
};
this.overlayLineOn = function(closePoint, farPoint, color) {
if (this.overlayLine === null) {
var lineProperties = {
@ -644,7 +678,6 @@ function MyController(hand) {
this.searchSphereDistance = DEFAULT_SEARCH_SPHERE_DISTANCE;
this.intersectionDistance = 0.0;
}
};
this.particleBeamOff = function() {
@ -749,6 +782,11 @@ function MyController(hand) {
// the trigger is being pressed, so do a ray test to see what we are hitting
var handPosition = this.getHandPosition();
if (SHOW_GRAB_SPHERE) {
this.grabSphereOn();
}
var controllerHandInput = (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
var currentHandRotation = Controller.getPoseValue(controllerHandInput).rotation;
var handDeltaRotation = Quat.multiply(currentHandRotation, Quat.inverse(this.startingHandRotation));

View file

@ -1132,8 +1132,12 @@ glm::quat Avatar::getRightPalmRotation() const {
glm::vec3 Avatar::getUncachedLeftPalmPosition() const {
assert(QThread::currentThread() == thread()); // main thread access only
glm::quat leftPalmRotation;
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getLeftHandJointIndex(), leftPalmRotation);
glm::vec3 leftPalmPosition;
if (_skeletonModel.getLeftGrabPosition(leftPalmPosition)) {
return leftPalmPosition;
}
// avatar didn't have a LeftHandMiddle1 joint, fall back on this:
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getLeftHandJointIndex(), leftPalmRotation);
getSkeletonModel().getLeftHandPosition(leftPalmPosition);
leftPalmPosition += HAND_TO_PALM_OFFSET * glm::inverse(leftPalmRotation);
return leftPalmPosition;
@ -1149,8 +1153,12 @@ glm::quat Avatar::getUncachedLeftPalmRotation() const {
glm::vec3 Avatar::getUncachedRightPalmPosition() const {
assert(QThread::currentThread() == thread()); // main thread access only
glm::quat rightPalmRotation;
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getRightHandJointIndex(), rightPalmRotation);
glm::vec3 rightPalmPosition;
if (_skeletonModel.getRightGrabPosition(rightPalmPosition)) {
return rightPalmPosition;
}
// avatar didn't have a RightHandMiddle1 joint, fall back on this:
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getRightHandJointIndex(), rightPalmRotation);
getSkeletonModel().getRightHandPosition(rightPalmPosition);
rightPalmPosition += HAND_TO_PALM_OFFSET * glm::inverse(rightPalmRotation);
return rightPalmPosition;

View file

@ -235,6 +235,22 @@ void SkeletonModel::applyPalmData(int jointIndex, const PalmData& palm) {
}
}
bool SkeletonModel::getLeftGrabPosition(glm::vec3& position) const {
int index = _rig->indexOfJoint("LeftHandMiddle1");
if (index >= 0) {
return getJointPositionInWorldFrame(index, position);
}
return false;
}
bool SkeletonModel::getRightGrabPosition(glm::vec3& position) const {
int index = _rig->indexOfJoint("RightHandMiddle1");
if (index >= 0) {
return getJointPositionInWorldFrame(index, position);
}
return false;
}
bool SkeletonModel::getLeftHandPosition(glm::vec3& position) const {
return getJointPositionInWorldFrame(getLeftHandJointIndex(), position);
}

View file

@ -39,6 +39,9 @@ public:
/// Returns the index of the right hand joint, or -1 if not found.
int getRightHandJointIndex() const { return isActive() ? _geometry->getFBXGeometry().rightHandJointIndex : -1; }
bool getLeftGrabPosition(glm::vec3& position) const;
bool getRightGrabPosition(glm::vec3& position) const;
/// Retrieve the position of the left hand
/// \return true whether or not the position was found
bool getLeftHandPosition(glm::vec3& position) const;