Grab includes rotation

This commit is contained in:
Philip Rosedale 2013-12-26 19:07:02 -08:00
parent 9b3973c2e4
commit 74380260b3
3 changed files with 25 additions and 3 deletions

View file

@ -52,6 +52,8 @@ Hand::Hand(Avatar* owningAvatar) :
_pitchUpdate(0), _pitchUpdate(0),
_grabDelta(0, 0, 0), _grabDelta(0, 0, 0),
_grabDeltaVelocity(0, 0, 0), _grabDeltaVelocity(0, 0, 0),
_grabStartRotation(0, 0, 0, 1),
_grabCurrentRotation(0, 0, 0, 1),
_throwInjector(QUrl("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/throw.raw")), _throwInjector(QUrl("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/throw.raw")),
_catchInjector(QUrl("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/catch.raw")) _catchInjector(QUrl("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/catch.raw"))
{ {
@ -227,7 +229,7 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
} }
glm::vec3 Hand::getAndResetGrabDelta() { glm::vec3 Hand::getAndResetGrabDelta() {
const float HAND_GRAB_SCALE_DISTANCE = 5.f; const float HAND_GRAB_SCALE_DISTANCE = 2.f;
glm::vec3 delta = _grabDelta * _owningAvatar->getScale() * HAND_GRAB_SCALE_DISTANCE; glm::vec3 delta = _grabDelta * _owningAvatar->getScale() * HAND_GRAB_SCALE_DISTANCE;
_grabDelta = glm::vec3(0,0,0); _grabDelta = glm::vec3(0,0,0);
glm::quat avatarRotation = _owningAvatar->getOrientation(); glm::quat avatarRotation = _owningAvatar->getOrientation();
@ -242,6 +244,11 @@ glm::vec3 Hand::getAndResetGrabDeltaVelocity() {
return avatarRotation * -delta; return avatarRotation * -delta;
} }
glm::quat Hand::getAndResetGrabRotation() {
glm::quat diff = _grabCurrentRotation * glm::inverse(_grabStartRotation);
_grabStartRotation = _grabCurrentRotation;
return diff;
}
void Hand::simulate(float deltaTime, bool isMine) { void Hand::simulate(float deltaTime, bool isMine) {
@ -275,10 +282,16 @@ void Hand::simulate(float deltaTime, bool isMine) {
if (palm.getControllerButtons() & BUTTON_4) { if (palm.getControllerButtons() & BUTTON_4) {
_grabDelta += palm.getRawVelocity() * deltaTime; _grabDelta += palm.getRawVelocity() * deltaTime;
_grabCurrentRotation = palm.getRawRotation();
} }
if ((palm.getLastControllerButtons() & BUTTON_4) && !(palm.getControllerButtons() & BUTTON_4)) { if ((palm.getLastControllerButtons() & BUTTON_4) && !(palm.getControllerButtons() & BUTTON_4)) {
// Just ending grab, capture velocity
_grabDeltaVelocity = palm.getRawVelocity(); _grabDeltaVelocity = palm.getRawVelocity();
} }
if (!(palm.getLastControllerButtons() & BUTTON_4) && (palm.getControllerButtons() & BUTTON_4)) {
// Just starting grab, capture starting rotation
_grabStartRotation = palm.getRawRotation();
}
if (palm.getControllerButtons() & BUTTON_1) { if (palm.getControllerButtons() & BUTTON_1) {
if (glm::length(fingerTipPosition - _lastFingerAddVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) { if (glm::length(fingerTipPosition - _lastFingerAddVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) {

View file

@ -64,6 +64,7 @@ public:
// Get the drag distance to move // Get the drag distance to move
glm::vec3 getAndResetGrabDelta(); glm::vec3 getAndResetGrabDelta();
glm::vec3 getAndResetGrabDeltaVelocity(); glm::vec3 getAndResetGrabDeltaVelocity();
glm::quat getAndResetGrabRotation();
private: private:
// disallow copies of the Hand, copy of owning Avatar is disallowed too // disallow copies of the Hand, copy of owning Avatar is disallowed too
@ -110,6 +111,8 @@ private:
glm::vec3 _grabDelta; glm::vec3 _grabDelta;
glm::vec3 _grabDeltaVelocity; glm::vec3 _grabDeltaVelocity;
glm::quat _grabStartRotation;
glm::quat _grabCurrentRotation;
AudioInjector _throwInjector; AudioInjector _throwInjector;
AudioInjector _catchInjector; AudioInjector _catchInjector;

View file

@ -258,14 +258,20 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
} }
updateChatCircle(deltaTime); updateChatCircle(deltaTime);
// Get any position or velocity update from Grab controller // Get any position, velocity, or rotation update from Grab Drag controller
glm::vec3 moveFromGrab = _hand.getAndResetGrabDelta(); glm::vec3 moveFromGrab = _hand.getAndResetGrabDelta();
if (glm::length(moveFromGrab) > EPSILON) { if (glm::length(moveFromGrab) > EPSILON) {
_position += moveFromGrab; _position += moveFromGrab;
_velocity = glm::vec3(0, 0, 0); _velocity = glm::vec3(0, 0, 0);
} }
_velocity += _hand.getAndResetGrabDeltaVelocity(); _velocity += _hand.getAndResetGrabDeltaVelocity();
glm::quat deltaRotation = _hand.getAndResetGrabRotation();
glm::vec3 euler = safeEulerAngles(deltaRotation);
// Adjust body yaw by yaw from controller
setOrientation(glm::angleAxis(euler.y, glm::vec3(0, 1, 0)) * getOrientation());
// Adjust head pitch from controller
getHead().setMousePitch(getHead().getMousePitch() + euler.x);
_position += _velocity * deltaTime; _position += _velocity * deltaTime;