Merge branch 'baseball' of https://github.com/Atlante45/hifi into baseball

This commit is contained in:
Stephen Birarda 2015-11-13 14:48:15 -08:00
commit 666c76073a
4 changed files with 29 additions and 36 deletions

View file

@ -52,9 +52,9 @@
grabbableKey: {
spatialKey: {
relativePosition: { x: 0.9, y: 0, z: 0 },
relativeRotation: Quat.fromPitchYawRollDegrees(0, 90, 0),
perHandRelativePosition: { x: 0.0808223, y: 0.134704, z: 0.0381 },
perHandRelativeRotation: Quat.fromPitchYawRollDegrees(-180, 90, 45)
relativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 45),
perHandRelativePosition: { x: 0.0, y: -0.05, z: -0.04 },
perHandRelativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 0)
}
}
}

View file

@ -35,8 +35,8 @@ AvatarActionHold::~AvatarActionHold() {
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
bool gotLock = false;
glm::quat rotation;
glm::vec3 position;
glm::quat rotation { Quaternions::IDENTITY };
glm::vec3 position { Vectors::ZERO };
std::shared_ptr<Avatar> holdingAvatar = nullptr;
gotLock = withTryReadLock([&]{
@ -46,9 +46,11 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
if (holdingAvatar) {
bool isRightHand = (_hand == "right");
glm::vec3 palmPosition;
glm::quat palmRotation;
glm::vec3 palmPosition { Vectors::ZERO };
glm::quat palmRotation { Quaternions::IDENTITY };
static const glm::quat yFlip = glm::angleAxis(PI, Vectors::UNIT_Y);
if (_ignoreIK && holdingAvatar->isMyAvatar()) {
// We cannot ignore other avatars IK and this is not the point of this option
// This is meant to make the grabbing behavior more reactive.
@ -58,6 +60,7 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
} else {
palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getPosition();
palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getRotation();
palmRotation *= yFlip; // Match right hand frame of reference
}
} else {
if (isRightHand) {
@ -66,28 +69,31 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
} else {
palmPosition = holdingAvatar->getLeftPalmPosition();
palmRotation = holdingAvatar->getLeftPalmRotation();
palmRotation *= yFlip; // Match right hand frame of reference
}
}
rotation = palmRotation * _relativeRotation;
position = palmPosition + rotation * _relativePosition;
if (isRightHand) {
rotation = palmRotation * _perHandRelativeRotation;
position = palmPosition + rotation * _perHandRelativePosition;
rotation *= _perHandRelativeRotation;
position += rotation * _perHandRelativePosition;
} else {
auto mirroredRotation = _perHandRelativeRotation;
auto mirroredPosition = _perHandRelativePosition;
// Mirror along x axis
mirroredRotation.x *= -1;
mirroredRotation.w *= -1;
// Mirror along z axis
auto eulerAngles = safeEulerAngles(mirroredRotation);
eulerAngles.x *= -1;
eulerAngles.y *= -1;
mirroredRotation = glm::quat(eulerAngles);
mirroredPosition.x *= -1;
mirroredPosition.z *= -1;
rotation = palmRotation * mirroredRotation;
position = palmPosition + rotation * mirroredPosition;
rotation *= mirroredRotation;
position += rotation * mirroredPosition;
}
rotation = rotation * _relativeRotation;
position = position + rotation * _relativePosition;
}
});

View file

@ -206,16 +206,6 @@ void ViveControllerManager::renderHand(const controller::Pose& pose, gpu::Batch&
batch.drawIndexed(gpu::TRIANGLES, mesh->getNumIndices(), 0);
}
#ifdef Q_OS_WIN
glm::vec3 ViveControllerManager::getPosition(int hand) const {
const mat4& mat = _trackedDevicePoseMat4[hand ? 3 : 4];
return extractTranslation(mat);
}
glm::quat ViveControllerManager::getRotation(int hand) const {
const mat4& mat = _trackedDevicePoseMat4[hand ? 3 : 4];
return glm::quat_cast(mat);
}
#endif
void ViveControllerManager::pluginUpdate(float deltaTime, bool jointsCaptured) {
_inputDevice->update(deltaTime, jointsCaptured);
@ -263,7 +253,7 @@ void ViveControllerManager::InputDevice::update(float deltaTime, bool jointsCapt
bool left = numTrackedControllers == 2;
const mat4& mat = _trackedDevicePoseMat4[device];
if (!jointsCaptured) {
handlePoseEvent(mat, numTrackedControllers - 1);
}

View file

@ -31,7 +31,6 @@ namespace vr {
class ViveControllerManager : public InputPlugin {
Q_OBJECT
public:
static const QString NAME;
// Plugin functions
virtual bool isSupported() const override;
@ -47,12 +46,6 @@ public:
void updateRendering(RenderArgs* args, render::ScenePointer scene, render::PendingChanges pendingChanges);
void setRenderControllers(bool renderControllers) { _renderControllers = renderControllers; }
#ifdef Q_OS_WIN
glm::vec3 getPosition(int device) const;
glm::quat getRotation(int device) const;
#endif
private:
class InputDevice : public controller::InputDevice {
@ -89,6 +82,10 @@ private:
bool _renderControllers { false };
vr::IVRSystem* _hmd { nullptr };
std::shared_ptr<InputDevice> _inputDevice { std::make_shared<InputDevice>(_hmd) };
static const QString NAME;
};
#endif // hifi__ViveControllerManager