Merge pull request #1372 from PhilipRosedale/grabStepping

Grab and move yourself around with button 4
This commit is contained in:
ZappoMan 2013-12-14 11:36:46 -08:00
commit 6af9ae0e82
10 changed files with 83 additions and 11 deletions

View file

@ -240,6 +240,9 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
// probably not the right long term solution. But for now, we're going to do this to
// allow you to move a particle around in your hand
_particleEditSender.setPacketsPerSecond(3000); // super high!!
// Set the sixense filtering
_sixenseManager.setFilter(Menu::getInstance()->isOptionChecked(MenuOption::FilterSixense));
}
Application::~Application() {

View file

@ -151,6 +151,7 @@ public:
SerialInterface* getSerialHeadSensor() { return &_serialHeadSensor; }
Webcam* getWebcam() { return &_webcam; }
Faceshift* getFaceshift() { return &_faceshift; }
SixenseManager* getSixenseManager() { return &_sixenseManager; }
BandwidthMeter* getBandwidthMeter() { return &_bandwidthMeter; }
QSettings* getSettings() { return _settings; }
Swatch* getSwatch() { return &_swatch; }

View file

@ -357,11 +357,17 @@ Menu::Menu() :
appInstance->getWebcam()->getGrabber(),
SLOT(setDepthOnly(bool)));
QMenu* raveGloveOptionsMenu = developerMenu->addMenu("Hand Options");
QMenu* handOptionsMenu = developerMenu->addMenu("Hand Options");
addCheckableActionToQMenuAndActionHash(raveGloveOptionsMenu, MenuOption::SimulateLeapHand);
addCheckableActionToQMenuAndActionHash(raveGloveOptionsMenu, MenuOption::DisplayLeapHands, 0, true);
addCheckableActionToQMenuAndActionHash(raveGloveOptionsMenu, MenuOption::LeapDrive, 0, false);
addCheckableActionToQMenuAndActionHash(handOptionsMenu,
MenuOption::FilterSixense,
0,
true,
appInstance->getSixenseManager(),
SLOT(setFilter(bool)));
addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::SimulateLeapHand);
addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::DisplayLeapHands, 0, true);
addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::LeapDrive, 0, false);
QMenu* trackingOptionsMenu = developerMenu->addMenu("Tracking Options");

View file

@ -167,6 +167,7 @@ namespace MenuOption {
const QString DisableLowRes = "Disable Lower Resolution While Moving";
const QString DisplayFrustum = "Display Frustum";
const QString DisplayLeapHands = "Display Leap Hands";
const QString FilterSixense = "Smooth Sixense Movement";
const QString DontRenderVoxels = "Don't call _voxels.render()";
const QString DontCallOpenGLForVoxels = "Don't call glDrawRangeElementsEXT() for Voxels";
const QString EnableOcclusionCulling = "Enable Occlusion Culling";

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;
@ -72,7 +74,6 @@ void Hand::reset() {
}
void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime) {
glm::vec3 targetPosition = fingerTipPosition / (float)TREE_SCALE;
float targetRadius = (TOY_BALL_RADIUS * 2.0f) / (float)TREE_SCALE;
const Particle* closestParticle = Application::getInstance()->getParticles()
@ -101,8 +102,6 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
// Is the controller button being held down....
if (palm.getControllerButtons() & BUTTON_FWD) {
// If grabbing toy ball, add forces to it.
// If we don't currently have a ball in hand, then create it...
if (!_toyBallInHand[handID]) {
// Test for whether close enough to catch and catch....
@ -170,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) {
@ -200,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>();
@ -246,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

@ -16,7 +16,6 @@
SixenseManager::SixenseManager() {
#ifdef HAVE_SIXENSE
sixenseInit();
sixenseSetFilterEnabled(1);
#endif
}
@ -26,6 +25,18 @@ SixenseManager::~SixenseManager() {
#endif
}
void SixenseManager::setFilter(bool filter) {
#ifdef HAVE_SIXENSE
if (filter) {
qDebug("Sixense Filter ON\n");
sixenseSetFilterEnabled(1);
} else {
qDebug("Sixense Filter OFF\n");
sixenseSetFilterEnabled(0);
}
#endif
}
void SixenseManager::update(float deltaTime) {
#ifdef HAVE_SIXENSE
if (sixenseGetNumActiveControllers() == 0) {

View file

@ -10,13 +10,19 @@
#define __interface__SixenseManager__
/// Handles interaction with the Sixense SDK (e.g., Razer Hydra).
class SixenseManager {
class SixenseManager : public QObject {
Q_OBJECT
public:
SixenseManager();
~SixenseManager();
void update(float deltaTime);
public slots:
void setFilter(bool filter);
};
#endif /* defined(__interface__SixenseManager__) */

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;