Grab and move with button 4

This commit is contained in:
Philip Rosedale 2013-12-13 21:59:19 -08:00
parent a04c544c17
commit 21d7fe1277
4 changed files with 49 additions and 2 deletions

View file

@ -48,7 +48,9 @@ Hand::Hand(Avatar* owningAvatar) :
_collisionCenter(0,0,0),
_collisionAge(0),
_collisionDuration(0),
_pitchUpdate(0)
_pitchUpdate(0),
_grabDelta(0, 0, 0),
_grabDeltaVelocity(0, 0, 0)
{
for (int i = 0; i < MAX_HANDS; i++) {
_toyBallInHand[i] = false;
@ -167,6 +169,23 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
}
}
glm::vec3 Hand::getAndResetGrabDelta() {
const float HAND_GRAB_SCALE_DISTANCE = 5.f;
glm::vec3 delta = _grabDelta * _owningAvatar->getScale() * HAND_GRAB_SCALE_DISTANCE;
_grabDelta = glm::vec3(0,0,0);
glm::quat avatarRotation = _owningAvatar->getOrientation();
return avatarRotation * -delta;
}
glm::vec3 Hand::getAndResetGrabDeltaVelocity() {
const float HAND_GRAB_SCALE_VELOCITY = 5.f;
glm::vec3 delta = _grabDeltaVelocity * _owningAvatar->getScale() * HAND_GRAB_SCALE_VELOCITY;
_grabDeltaVelocity = glm::vec3(0,0,0);
glm::quat avatarRotation = _owningAvatar->getOrientation();
return avatarRotation * -delta;
}
void Hand::simulate(float deltaTime, bool isMine) {
if (_collisionAge > 0.f) {
@ -197,6 +216,13 @@ void Hand::simulate(float deltaTime, bool isMine) {
simulateToyBall(palm, fingerTipPosition, deltaTime);
if (palm.getControllerButtons() & BUTTON_4) {
_grabDelta += palm.getRawVelocity() * deltaTime;
}
if ((palm.getLastControllerButtons() & BUTTON_4) && !(palm.getControllerButtons() & BUTTON_4)) {
_grabDeltaVelocity = palm.getRawVelocity();
}
if (palm.getControllerButtons() & BUTTON_1) {
if (glm::length(fingerTipPosition - _lastFingerAddVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) {
QColor paintColor = Menu::getInstance()->getActionForOption(MenuOption::VoxelPaintColor)->data().value<QColor>();
@ -243,6 +269,7 @@ void Hand::simulate(float deltaTime, bool isMine) {
}
}
}
palm.setLastControllerButtons(palm.getControllerButtons());
}
}
}

View file

@ -61,6 +61,10 @@ public:
const float getPitchUpdate() const { return _pitchUpdate; }
void setPitchUpdate(float pitchUpdate) { _pitchUpdate = pitchUpdate; }
// Get the drag distance to move
glm::vec3 getAndResetGrabDelta();
glm::vec3 getAndResetGrabDeltaVelocity();
private:
// disallow copies of the Hand, copy of owning Avatar is disallowed too
Hand(const Hand&);
@ -95,6 +99,7 @@ private:
void handleVoxelCollision(PalmData* palm, const glm::vec3& fingerTipPosition, VoxelTreeElement* voxel, float deltaTime);
void simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime);
#define MAX_HANDS 2
bool _toyBallInHand[MAX_HANDS];
@ -103,6 +108,9 @@ private:
int _lastControllerButtons;
float _pitchUpdate;
glm::vec3 _grabDelta;
glm::vec3 _grabDeltaVelocity;
};

View file

@ -271,6 +271,14 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
updateChatCircle(deltaTime);
// Get any position or velocity update from Grab controller
glm::vec3 moveFromGrab = _hand.getAndResetGrabDelta();
if (glm::length(moveFromGrab) > EPSILON) {
_position += moveFromGrab;
_velocity = glm::vec3(0, 0, 0);
}
_velocity += _hand.getAndResetGrabDeltaVelocity();
_position += _velocity * deltaTime;
// update avatar skeleton and simulate hand and head

View file

@ -158,8 +158,11 @@ public:
// Controller buttons
void setControllerButtons(int controllerButtons) { _controllerButtons = controllerButtons; }
int getControllerButtons() { return _controllerButtons; }
void setLastControllerButtons(int controllerButtons) { _lastControllerButtons = controllerButtons; }
int getControllerButtons() { return _controllerButtons; }
int getLastControllerButtons() { return _lastControllerButtons; }
void setTrigger(float trigger) { _trigger = trigger; }
float getTrigger() { return _trigger; }
void setJoystick(float joystickX, float joystickY) { _joystickX = joystickX; _joystickY = joystickY; }
@ -181,6 +184,7 @@ private:
glm::vec3 _tipPosition;
glm::vec3 _tipVelocity;
int _controllerButtons;
int _lastControllerButtons;
float _trigger;
float _joystickX, _joystickY;