mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-10 02:08:23 +02:00
Grab and move with button 4
This commit is contained in:
parent
a04c544c17
commit
21d7fe1277
4 changed files with 49 additions and 2 deletions
|
@ -48,7 +48,9 @@ Hand::Hand(Avatar* owningAvatar) :
|
||||||
_collisionCenter(0,0,0),
|
_collisionCenter(0,0,0),
|
||||||
_collisionAge(0),
|
_collisionAge(0),
|
||||||
_collisionDuration(0),
|
_collisionDuration(0),
|
||||||
_pitchUpdate(0)
|
_pitchUpdate(0),
|
||||||
|
_grabDelta(0, 0, 0),
|
||||||
|
_grabDeltaVelocity(0, 0, 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_HANDS; i++) {
|
for (int i = 0; i < MAX_HANDS; i++) {
|
||||||
_toyBallInHand[i] = false;
|
_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) {
|
void Hand::simulate(float deltaTime, bool isMine) {
|
||||||
|
|
||||||
if (_collisionAge > 0.f) {
|
if (_collisionAge > 0.f) {
|
||||||
|
@ -197,6 +216,13 @@ void Hand::simulate(float deltaTime, bool isMine) {
|
||||||
|
|
||||||
simulateToyBall(palm, fingerTipPosition, deltaTime);
|
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 (palm.getControllerButtons() & BUTTON_1) {
|
||||||
if (glm::length(fingerTipPosition - _lastFingerAddVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) {
|
if (glm::length(fingerTipPosition - _lastFingerAddVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) {
|
||||||
QColor paintColor = Menu::getInstance()->getActionForOption(MenuOption::VoxelPaintColor)->data().value<QColor>();
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,10 @@ public:
|
||||||
const float getPitchUpdate() const { return _pitchUpdate; }
|
const float getPitchUpdate() const { return _pitchUpdate; }
|
||||||
void setPitchUpdate(float pitchUpdate) { _pitchUpdate = pitchUpdate; }
|
void setPitchUpdate(float pitchUpdate) { _pitchUpdate = pitchUpdate; }
|
||||||
|
|
||||||
|
// Get the drag distance to move
|
||||||
|
glm::vec3 getAndResetGrabDelta();
|
||||||
|
glm::vec3 getAndResetGrabDeltaVelocity();
|
||||||
|
|
||||||
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
|
||||||
Hand(const Hand&);
|
Hand(const Hand&);
|
||||||
|
@ -95,6 +99,7 @@ private:
|
||||||
void handleVoxelCollision(PalmData* palm, const glm::vec3& fingerTipPosition, VoxelTreeElement* voxel, float deltaTime);
|
void handleVoxelCollision(PalmData* palm, const glm::vec3& fingerTipPosition, VoxelTreeElement* voxel, float deltaTime);
|
||||||
|
|
||||||
void simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime);
|
void simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime);
|
||||||
|
|
||||||
|
|
||||||
#define MAX_HANDS 2
|
#define MAX_HANDS 2
|
||||||
bool _toyBallInHand[MAX_HANDS];
|
bool _toyBallInHand[MAX_HANDS];
|
||||||
|
@ -103,6 +108,9 @@ private:
|
||||||
int _lastControllerButtons;
|
int _lastControllerButtons;
|
||||||
|
|
||||||
float _pitchUpdate;
|
float _pitchUpdate;
|
||||||
|
|
||||||
|
glm::vec3 _grabDelta;
|
||||||
|
glm::vec3 _grabDeltaVelocity;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -271,6 +271,14 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||||
|
|
||||||
updateChatCircle(deltaTime);
|
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;
|
_position += _velocity * deltaTime;
|
||||||
|
|
||||||
// update avatar skeleton and simulate hand and head
|
// update avatar skeleton and simulate hand and head
|
||||||
|
|
|
@ -158,8 +158,11 @@ public:
|
||||||
|
|
||||||
// Controller buttons
|
// Controller buttons
|
||||||
void setControllerButtons(int controllerButtons) { _controllerButtons = controllerButtons; }
|
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; }
|
void setTrigger(float trigger) { _trigger = trigger; }
|
||||||
float getTrigger() { return _trigger; }
|
float getTrigger() { return _trigger; }
|
||||||
void setJoystick(float joystickX, float joystickY) { _joystickX = joystickX; _joystickY = joystickY; }
|
void setJoystick(float joystickX, float joystickY) { _joystickX = joystickX; _joystickY = joystickY; }
|
||||||
|
@ -181,6 +184,7 @@ private:
|
||||||
glm::vec3 _tipPosition;
|
glm::vec3 _tipPosition;
|
||||||
glm::vec3 _tipVelocity;
|
glm::vec3 _tipVelocity;
|
||||||
int _controllerButtons;
|
int _controllerButtons;
|
||||||
|
int _lastControllerButtons;
|
||||||
float _trigger;
|
float _trigger;
|
||||||
float _joystickX, _joystickY;
|
float _joystickX, _joystickY;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue