added shift action, added timers and fast mode to hmdControls.js

This commit is contained in:
Sam Gondelman 2015-06-18 13:59:37 -07:00
parent f752534f7c
commit fd0efd91ff
6 changed files with 81 additions and 13 deletions

View file

@ -9,73 +9,129 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
var MOVE_DISTANCE = 0.5; var MOVE_DISTANCE = 0.3;
var PITCH_INCREMENT = Math.PI / 8; var PITCH_INCREMENT = 0.5; // degrees
var YAW_INCREMENT = Math.PI / 8; var VR_PITCH_INCREMENT = 15.0; // degrees
var YAW_INCREMENT = 0.5; // degrees
var VR_YAW_INCREMENT = 15.0; // degrees
var BOOM_SPEED = 0.5; var BOOM_SPEED = 0.5;
var THRESHOLD = 0.2; var THRESHOLD = 0.2;
var CAMERA_UPDATE_TIME = 0.5;
var pitchTimer = CAMERA_UPDATE_TIME;
var yawTimer = CAMERA_UPDATE_TIME;
var shifted = false;
var SHIFT_UPDATE_TIME = 0.5;
var shiftTimer = SHIFT_UPDATE_TIME;
var SHIFT_MAG = 4.0;
var hmdControls = (function () { var hmdControls = (function () {
function onActionEvent(action, state) { function onActionEvent(action, state) {
if (state < THRESHOLD) { if (state < THRESHOLD) {
if (action == 6 || action == 7) {
yawTimer = CAMERA_UPDATE_TIME;
} else if (action == 8 || action == 9) {
pitchTimer = CAMERA_UPDATE_TIME;
}
return; return;
} }
switch (action) { switch (action) {
case 0: // backward case 0: // backward
var direction = Quat.getFront(Camera.getOrientation()); var direction = Quat.getFront(Camera.getOrientation());
direction = Vec3.multiply(-1, direction); direction = Vec3.multiply(-1, direction);
direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE);
MyAvatar.position = Vec3.sum(MyAvatar.position, direction); MyAvatar.position = Vec3.sum(MyAvatar.position, direction);
break; break;
case 1: // forward case 1: // forward
var direction = Quat.getFront(Camera.getOrientation()); var direction = Quat.getFront(Camera.getOrientation());
direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE);
MyAvatar.position = Vec3.sum(MyAvatar.position, direction); MyAvatar.position = Vec3.sum(MyAvatar.position, direction);
break; break;
case 2: // left case 2: // left
var direction = Quat.getRight(Camera.getOrientation()); var direction = Quat.getRight(Camera.getOrientation());
direction = Vec3.multiply(-1, direction); direction = Vec3.multiply(-1, direction);
direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE);
MyAvatar.position = Vec3.sum(MyAvatar.position, direction); MyAvatar.position = Vec3.sum(MyAvatar.position, direction);
break; break;
case 3: // right case 3: // right
var direction = Quat.getRight(Camera.getOrientation()); var direction = Quat.getRight(Camera.getOrientation());
direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE);
MyAvatar.position = Vec3.sum(MyAvatar.position, direction); MyAvatar.position = Vec3.sum(MyAvatar.position, direction);
break; break;
case 4: // down case 4: // down
var direction = Quat.getUp(Camera.getOrientation()); var direction = Quat.getUp(Camera.getOrientation());
direction = Vec3.multiply(-1, direction); direction = Vec3.multiply(-1, direction);
direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE);
MyAvatar.position = Vec3.sum(MyAvatar.position, direction); MyAvatar.position = Vec3.sum(MyAvatar.position, direction);
break; break;
case 5: // up case 5: // up
var direction = Quat.getUp(Camera.getOrientation()); var direction = Quat.getUp(Camera.getOrientation());
direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE);
MyAvatar.position = Vec3.sum(MyAvatar.position, direction); MyAvatar.position = Vec3.sum(MyAvatar.position, direction);
break; break;
case 6: // yaw left case 6: // yaw left
MyAvatar.bodyYaw = MyAvatar.bodyYaw + YAW_INCREMENT; if (yawTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) {
MyAvatar.bodyYaw = MyAvatar.bodyYaw + (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT);
yawTimer = CAMERA_UPDATE_TIME;
} else if (!Menu.isOptionChecked("Enable VR Mode")) {
MyAvatar.bodyYaw = MyAvatar.bodyYaw + (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT);
}
break; break;
case 7: // yaw right case 7: // yaw right
MyAvatar.bodyYaw = MyAvatar.bodyYaw - YAW_INCREMENT; if (yawTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) {
MyAvatar.bodyYaw = MyAvatar.bodyYaw - (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT);
yawTimer = CAMERA_UPDATE_TIME;
} else if (!Menu.isOptionChecked("Enable VR Mode")) {
MyAvatar.bodyYaw = MyAvatar.bodyYaw - (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT);
}
break; break;
case 8: // pitch down case 8: // pitch down
MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch - PITCH_INCREMENT)); if (pitchTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) {
MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch - (shifted ? SHIFT_MAG * VR_PITCH_INCREMENT : VR_PITCH_INCREMENT)));
pitchTimer = CAMERA_UPDATE_TIME;
} else if (!Menu.isOptionChecked("Enable VR Mode")) {
MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch - (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT)));
}
break; break;
case 9: // pitch up case 9: // pitch up
MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch + PITCH_INCREMENT)); if (pitchTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) {
MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch + (shifted ? SHIFT_MAG * VR_PITCH_INCREMENT : VR_PITCH_INCREMENT)));
pitchTimer = CAMERA_UPDATE_TIME;
} else if (!Menu.isOptionChecked("Enable VR Mode")) {
MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch + (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT)));
}
break;
case 12: // shift
if (shiftTimer < 0.0) {
shifted = !shifted;
shiftTimer = SHIFT_UPDATE_TIME;
}
break; break;
default: default:
break; break;
} }
} }
function update(dt) {
if (yawTimer >= 0.0) {
yawTimer = yawTimer - dt;
}
if (pitchTimer >= 0.0) {
pitchTimer = pitchTimer - dt;
}
if (shiftTimer >= 0.0) {
shiftTimer = shiftTimer - dt;
}
}
function setUp() { function setUp() {
Controller.captureActionEvents(); Controller.captureActionEvents();
Controller.actionEvent.connect(onActionEvent); Controller.actionEvent.connect(onActionEvent);
Script.update.connect(update);
} }
function tearDown() { function tearDown() {

View file

@ -210,6 +210,8 @@ void Joystick::assignDefaultInputMapping(UserInputMapper& mapper) {
// Zoom // Zoom
mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(RIGHT_SHOULDER), makeInput(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), BOOM_SPEED/2.0f); mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(RIGHT_SHOULDER), makeInput(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), BOOM_SPEED/2.0f);
mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(LEFT_SHOULDER), makeInput(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), BOOM_SPEED/2.0f); mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(LEFT_SHOULDER), makeInput(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), BOOM_SPEED/2.0f);
mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(SDL_CONTROLLER_BUTTON_LEFTSHOULDER));
#endif #endif
} }

View file

@ -277,6 +277,8 @@ void KeyboardMouseDevice::assignDefaultInputMapping(UserInputMapper& mapper) {
#endif #endif
mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(Qt::Key_Space));
} }
float KeyboardMouseDevice::getButton(int channel) const { float KeyboardMouseDevice::getButton(int channel) const {

View file

@ -724,6 +724,10 @@ void SixenseManager::assignDefaultInputMapping(UserInputMapper& mapper) {
mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(BUTTON_3, 1), BUTTON_MOVE_SPEED); mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(BUTTON_3, 1), BUTTON_MOVE_SPEED);
mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(BUTTON_1, 1), BUTTON_MOVE_SPEED); mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(BUTTON_1, 1), BUTTON_MOVE_SPEED);
mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(BUTTON_2, 0));
mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(BUTTON_2, 1));
} }
float SixenseManager::getButton(int channel) const { float SixenseManager::getButton(int channel) const {

View file

@ -247,6 +247,7 @@ void UserInputMapper::assignDefaulActionScales() {
_actionScales[PITCH_UP] = 1.0f; // 1 degree per unit _actionScales[PITCH_UP] = 1.0f; // 1 degree per unit
_actionScales[BOOM_IN] = 1.0f; // 1m per unit _actionScales[BOOM_IN] = 1.0f; // 1m per unit
_actionScales[BOOM_OUT] = 1.0f; // 1m per unit _actionScales[BOOM_OUT] = 1.0f; // 1m per unit
_actionStates[SHIFT] = 1.0f; // on
} }
// This is only necessary as long as the actions are hardcoded // This is only necessary as long as the actions are hardcoded
@ -264,4 +265,5 @@ void UserInputMapper::createActionNames() {
_actionNames[PITCH_UP] = "PITCH_UP"; _actionNames[PITCH_UP] = "PITCH_UP";
_actionNames[BOOM_IN] = "BOOM_IN"; _actionNames[BOOM_IN] = "BOOM_IN";
_actionNames[BOOM_OUT] = "BOOM_OUT"; _actionNames[BOOM_OUT] = "BOOM_OUT";
_actionNames[SHIFT] = "SHIFT";
} }

View file

@ -140,6 +140,8 @@ public:
BOOM_IN, BOOM_IN,
BOOM_OUT, BOOM_OUT,
SHIFT,
NUM_ACTIONS, NUM_ACTIONS,
}; };