mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 20:36:38 +02:00
Drive avatar with Sixense joysticks and triggers.
This commit is contained in:
parent
83d89cdc30
commit
f59b403103
4 changed files with 41 additions and 16 deletions
|
@ -100,7 +100,9 @@ enum DriveKeys {
|
||||||
UP,
|
UP,
|
||||||
DOWN,
|
DOWN,
|
||||||
ROT_LEFT,
|
ROT_LEFT,
|
||||||
ROT_RIGHT,
|
ROT_RIGHT,
|
||||||
|
ROT_UP,
|
||||||
|
ROT_DOWN,
|
||||||
MAX_DRIVE_KEYS
|
MAX_DRIVE_KEYS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ using namespace std;
|
||||||
|
|
||||||
const glm::vec3 DEFAULT_UP_DIRECTION(0.0f, 1.0f, 0.0f);
|
const glm::vec3 DEFAULT_UP_DIRECTION(0.0f, 1.0f, 0.0f);
|
||||||
const float YAW_MAG = 500.0;
|
const float YAW_MAG = 500.0;
|
||||||
|
const float PITCH_MAG = 100.0f;
|
||||||
const float COLLISION_RADIUS_SCALAR = 1.2; // pertains to avatar-to-avatar collisions
|
const float COLLISION_RADIUS_SCALAR = 1.2; // pertains to avatar-to-avatar collisions
|
||||||
const float COLLISION_BALL_FORCE = 200.0; // pertains to avatar-to-avatar collisions
|
const float COLLISION_BALL_FORCE = 200.0; // pertains to avatar-to-avatar collisions
|
||||||
const float COLLISION_BODY_FORCE = 30.0; // pertains to avatar-to-avatar collisions
|
const float COLLISION_BODY_FORCE = 30.0; // pertains to avatar-to-avatar collisions
|
||||||
|
@ -42,6 +43,7 @@ MyAvatar::MyAvatar(Node* owningNode) :
|
||||||
_mousePressed(false),
|
_mousePressed(false),
|
||||||
_bodyPitchDelta(0.0f),
|
_bodyPitchDelta(0.0f),
|
||||||
_bodyRollDelta(0.0f),
|
_bodyRollDelta(0.0f),
|
||||||
|
_mousePitchDelta(0.0f),
|
||||||
_shouldJump(false),
|
_shouldJump(false),
|
||||||
_gravity(0.0f, -1.0f, 0.0f),
|
_gravity(0.0f, -1.0f, 0.0f),
|
||||||
_distanceToNearestAvatar(std::numeric_limits<float>::max()),
|
_distanceToNearestAvatar(std::numeric_limits<float>::max()),
|
||||||
|
@ -57,7 +59,7 @@ MyAvatar::MyAvatar(Node* owningNode) :
|
||||||
_moveTargetStepCounter(0)
|
_moveTargetStepCounter(0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_DRIVE_KEYS; i++) {
|
for (int i = 0; i < MAX_DRIVE_KEYS; i++) {
|
||||||
_driveKeys[i] = false;
|
_driveKeys[i] = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
_collisionRadius = _height * COLLISION_RADIUS_SCALE;
|
_collisionRadius = _height * COLLISION_RADIUS_SCALE;
|
||||||
|
@ -395,8 +397,8 @@ void MyAvatar::updateFromGyrosAndOrWebcam(float pitchFromTouch, bool turnWithHea
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!_leadingAvatar) {
|
if (!_leadingAvatar) {
|
||||||
_head.setMousePitch(pitchFromTouch);
|
_head.setMousePitch(pitchFromTouch + _mousePitchDelta);
|
||||||
_head.setPitch(pitchFromTouch);
|
_head.setPitch(pitchFromTouch + _mousePitchDelta);
|
||||||
}
|
}
|
||||||
_head.getVideoFace().clearFrame();
|
_head.getVideoFace().clearFrame();
|
||||||
|
|
||||||
|
@ -408,7 +410,7 @@ void MyAvatar::updateFromGyrosAndOrWebcam(float pitchFromTouch, bool turnWithHea
|
||||||
_head.setLeanForward(glm::mix(_head.getLeanForward(), 0.0f, RESTORE_RATE));
|
_head.setLeanForward(glm::mix(_head.getLeanForward(), 0.0f, RESTORE_RATE));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_head.setMousePitch(pitchFromTouch);
|
_head.setMousePitch(pitchFromTouch + _mousePitchDelta);
|
||||||
|
|
||||||
if (webcam->isActive()) {
|
if (webcam->isActive()) {
|
||||||
estimatedPosition = webcam->getEstimatedPosition();
|
estimatedPosition = webcam->getEstimatedPosition();
|
||||||
|
@ -707,14 +709,17 @@ void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) {
|
||||||
const float THRUST_JUMP = 120.f;
|
const float THRUST_JUMP = 120.f;
|
||||||
|
|
||||||
// Add Thrusts from keyboard
|
// Add Thrusts from keyboard
|
||||||
if (_driveKeys[FWD]) {_thrust += _scale * THRUST_MAG_FWD * _thrustMultiplier * deltaTime * front;}
|
_thrust += _driveKeys[FWD] * _scale * THRUST_MAG_FWD * _thrustMultiplier * deltaTime * front;
|
||||||
if (_driveKeys[BACK]) {_thrust -= _scale * THRUST_MAG_BACK * _thrustMultiplier * deltaTime * front;}
|
_thrust -= _driveKeys[BACK] * _scale * THRUST_MAG_BACK * _thrustMultiplier * deltaTime * front;
|
||||||
if (_driveKeys[RIGHT]) {_thrust += _scale * THRUST_MAG_LATERAL * _thrustMultiplier * deltaTime * right;}
|
_thrust += _driveKeys[RIGHT] * _scale * THRUST_MAG_LATERAL * _thrustMultiplier * deltaTime * right;
|
||||||
if (_driveKeys[LEFT]) {_thrust -= _scale * THRUST_MAG_LATERAL * _thrustMultiplier * deltaTime * right;}
|
_thrust -= _driveKeys[LEFT] * _scale * THRUST_MAG_LATERAL * _thrustMultiplier * deltaTime * right;
|
||||||
if (_driveKeys[UP]) {_thrust += _scale * THRUST_MAG_UP * _thrustMultiplier * deltaTime * up;}
|
_thrust += _driveKeys[UP] * _scale * THRUST_MAG_UP * _thrustMultiplier * deltaTime * up;
|
||||||
if (_driveKeys[DOWN]) {_thrust -= _scale * THRUST_MAG_DOWN * _thrustMultiplier * deltaTime * up;}
|
_thrust -= _driveKeys[DOWN] * _scale * THRUST_MAG_DOWN * _thrustMultiplier * deltaTime * up;
|
||||||
if (_driveKeys[ROT_RIGHT]) {_bodyYawDelta -= YAW_MAG * deltaTime;}
|
_bodyYawDelta -= _driveKeys[ROT_RIGHT] * YAW_MAG * deltaTime;
|
||||||
if (_driveKeys[ROT_LEFT]) {_bodyYawDelta += YAW_MAG * deltaTime;}
|
_bodyYawDelta += _driveKeys[ROT_LEFT] * YAW_MAG * deltaTime;
|
||||||
|
const float MAX_PITCH = 90.0f;
|
||||||
|
_mousePitchDelta = min(_mousePitchDelta + _driveKeys[ROT_UP] * PITCH_MAG * deltaTime, MAX_PITCH);
|
||||||
|
_mousePitchDelta = max(_mousePitchDelta - _driveKeys[ROT_DOWN] * PITCH_MAG * deltaTime, -MAX_PITCH);
|
||||||
|
|
||||||
// If thrust keys are being held down, slowly increase thrust to allow reaching great speeds
|
// If thrust keys are being held down, slowly increase thrust to allow reaching great speeds
|
||||||
if (_driveKeys[FWD] || _driveKeys[BACK] || _driveKeys[RIGHT] || _driveKeys[LEFT] || _driveKeys[UP] || _driveKeys[DOWN]) {
|
if (_driveKeys[FWD] || _driveKeys[BACK] || _driveKeys[RIGHT] || _driveKeys[LEFT] || _driveKeys[UP] || _driveKeys[DOWN]) {
|
||||||
|
|
|
@ -54,7 +54,7 @@ public:
|
||||||
void loadData(QSettings* settings);
|
void loadData(QSettings* settings);
|
||||||
|
|
||||||
// Set what driving keys are being pressed to control thrust levels
|
// Set what driving keys are being pressed to control thrust levels
|
||||||
void setDriveKeys(int key, bool val) { _driveKeys[key] = val; };
|
void setDriveKeys(int key, float val) { _driveKeys[key] = val; };
|
||||||
bool getDriveKeys(int key) { return _driveKeys[key]; };
|
bool getDriveKeys(int key) { return _driveKeys[key]; };
|
||||||
void jump() { _shouldJump = true; };
|
void jump() { _shouldJump = true; };
|
||||||
|
|
||||||
|
@ -66,8 +66,9 @@ private:
|
||||||
bool _mousePressed;
|
bool _mousePressed;
|
||||||
float _bodyPitchDelta;
|
float _bodyPitchDelta;
|
||||||
float _bodyRollDelta;
|
float _bodyRollDelta;
|
||||||
|
float _mousePitchDelta;
|
||||||
bool _shouldJump;
|
bool _shouldJump;
|
||||||
int _driveKeys[MAX_DRIVE_KEYS];
|
float _driveKeys[MAX_DRIVE_KEYS];
|
||||||
glm::vec3 _gravity;
|
glm::vec3 _gravity;
|
||||||
float _distanceToNearestAvatar; // How close is the nearest avatar?
|
float _distanceToNearestAvatar; // How close is the nearest avatar?
|
||||||
Avatar* _interactingOther;
|
Avatar* _interactingOther;
|
||||||
|
|
|
@ -30,7 +30,8 @@ void SixenseManager::update() {
|
||||||
if (sixenseGetNumActiveControllers() == 0) {
|
if (sixenseGetNumActiveControllers() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Hand& hand = Application::getInstance()->getAvatar()->getHand();
|
MyAvatar* avatar = Application::getInstance()->getAvatar();
|
||||||
|
Hand& hand = avatar->getHand();
|
||||||
hand.getPalms().clear();
|
hand.getPalms().clear();
|
||||||
|
|
||||||
int maxControllers = sixenseGetMaxControllers();
|
int maxControllers = sixenseGetMaxControllers();
|
||||||
|
@ -41,6 +42,22 @@ void SixenseManager::update() {
|
||||||
sixenseControllerData data;
|
sixenseControllerData data;
|
||||||
sixenseGetNewestData(i, &data);
|
sixenseGetNewestData(i, &data);
|
||||||
|
|
||||||
|
// drive avatar with joystick and triggers
|
||||||
|
if (data.controller_index) {
|
||||||
|
avatar->setDriveKeys(ROT_LEFT, qMax(0.0f, -data.joystick_x));
|
||||||
|
avatar->setDriveKeys(ROT_RIGHT, qMax(0.0f, data.joystick_x));
|
||||||
|
avatar->setDriveKeys(ROT_UP, qMax(0.0f, data.joystick_y));
|
||||||
|
avatar->setDriveKeys(ROT_DOWN, qMax(0.0f, -data.joystick_y));
|
||||||
|
avatar->setDriveKeys(UP, data.trigger);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
avatar->setDriveKeys(FWD, qMax(0.0f, data.joystick_y));
|
||||||
|
avatar->setDriveKeys(BACK, qMax(0.0f, -data.joystick_y));
|
||||||
|
avatar->setDriveKeys(LEFT, qMax(0.0f, -data.joystick_x));
|
||||||
|
avatar->setDriveKeys(RIGHT, qMax(0.0f, data.joystick_x));
|
||||||
|
avatar->setDriveKeys(DOWN, data.trigger);
|
||||||
|
}
|
||||||
|
|
||||||
// set palm position and normal based on Hydra position/orientation
|
// set palm position and normal based on Hydra position/orientation
|
||||||
PalmData palm(&hand);
|
PalmData palm(&hand);
|
||||||
palm.setActive(true);
|
palm.setActive(true);
|
||||||
|
|
Loading…
Reference in a new issue