mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +02:00
actionEvent signal, captureActions, began work on hmdControls.js
This commit is contained in:
parent
a37b089b33
commit
f752534f7c
6 changed files with 119 additions and 11 deletions
87
examples/hmdControls.js
Normal file
87
examples/hmdControls.js
Normal file
|
@ -0,0 +1,87 @@
|
|||
//
|
||||
// hmdControls.js
|
||||
// examples
|
||||
//
|
||||
// Created by Sam Gondelman on 6/17/15
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var MOVE_DISTANCE = 0.5;
|
||||
var PITCH_INCREMENT = Math.PI / 8;
|
||||
var YAW_INCREMENT = Math.PI / 8;
|
||||
var BOOM_SPEED = 0.5;
|
||||
var THRESHOLD = 0.2;
|
||||
|
||||
var hmdControls = (function () {
|
||||
|
||||
function onActionEvent(action, state) {
|
||||
if (state < THRESHOLD) {
|
||||
return;
|
||||
}
|
||||
switch (action) {
|
||||
case 0: // backward
|
||||
var direction = Quat.getFront(Camera.getOrientation());
|
||||
direction = Vec3.multiply(-1, direction);
|
||||
direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE);
|
||||
MyAvatar.position = Vec3.sum(MyAvatar.position, direction);
|
||||
break;
|
||||
case 1: // forward
|
||||
var direction = Quat.getFront(Camera.getOrientation());
|
||||
direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE);
|
||||
MyAvatar.position = Vec3.sum(MyAvatar.position, direction);
|
||||
break;
|
||||
case 2: // left
|
||||
var direction = Quat.getRight(Camera.getOrientation());
|
||||
direction = Vec3.multiply(-1, direction);
|
||||
direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE);
|
||||
MyAvatar.position = Vec3.sum(MyAvatar.position, direction);
|
||||
break;
|
||||
case 3: // right
|
||||
var direction = Quat.getRight(Camera.getOrientation());
|
||||
direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE);
|
||||
MyAvatar.position = Vec3.sum(MyAvatar.position, direction);
|
||||
break;
|
||||
case 4: // down
|
||||
var direction = Quat.getUp(Camera.getOrientation());
|
||||
direction = Vec3.multiply(-1, direction);
|
||||
direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE);
|
||||
MyAvatar.position = Vec3.sum(MyAvatar.position, direction);
|
||||
break;
|
||||
case 5: // up
|
||||
var direction = Quat.getUp(Camera.getOrientation());
|
||||
direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE);
|
||||
MyAvatar.position = Vec3.sum(MyAvatar.position, direction);
|
||||
break;
|
||||
case 6: // yaw left
|
||||
MyAvatar.bodyYaw = MyAvatar.bodyYaw + YAW_INCREMENT;
|
||||
break;
|
||||
case 7: // yaw right
|
||||
MyAvatar.bodyYaw = MyAvatar.bodyYaw - YAW_INCREMENT;
|
||||
break;
|
||||
case 8: // pitch down
|
||||
MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch - PITCH_INCREMENT));
|
||||
break;
|
||||
case 9: // pitch up
|
||||
MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch + PITCH_INCREMENT));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
Controller.captureActionEvents();
|
||||
|
||||
Controller.actionEvent.connect(onActionEvent);
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
Controller.releaseActionEvents();
|
||||
}
|
||||
|
||||
setUp();
|
||||
Script.scriptEnding.connect(tearDown);
|
||||
}());
|
|
@ -2505,16 +2505,18 @@ void Application::update(float deltaTime) {
|
|||
|
||||
// Transfer the user inputs to the driveKeys
|
||||
_myAvatar->clearDriveKeys();
|
||||
_myAvatar->setDriveKeys(FWD, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_FORWARD));
|
||||
_myAvatar->setDriveKeys(BACK, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_BACKWARD));
|
||||
_myAvatar->setDriveKeys(UP, _userInputMapper.getActionState(UserInputMapper::VERTICAL_UP));
|
||||
_myAvatar->setDriveKeys(DOWN, _userInputMapper.getActionState(UserInputMapper::VERTICAL_DOWN));
|
||||
_myAvatar->setDriveKeys(LEFT, _userInputMapper.getActionState(UserInputMapper::LATERAL_LEFT));
|
||||
_myAvatar->setDriveKeys(RIGHT, _userInputMapper.getActionState(UserInputMapper::LATERAL_RIGHT));
|
||||
_myAvatar->setDriveKeys(ROT_UP, _userInputMapper.getActionState(UserInputMapper::PITCH_UP));
|
||||
_myAvatar->setDriveKeys(ROT_DOWN, _userInputMapper.getActionState(UserInputMapper::PITCH_DOWN));
|
||||
_myAvatar->setDriveKeys(ROT_LEFT, _userInputMapper.getActionState(UserInputMapper::YAW_LEFT));
|
||||
_myAvatar->setDriveKeys(ROT_RIGHT, _userInputMapper.getActionState(UserInputMapper::YAW_RIGHT));
|
||||
if (!_controllerScriptingInterface.areActionsCaptured()) {
|
||||
_myAvatar->setDriveKeys(FWD, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_FORWARD));
|
||||
_myAvatar->setDriveKeys(BACK, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_BACKWARD));
|
||||
_myAvatar->setDriveKeys(UP, _userInputMapper.getActionState(UserInputMapper::VERTICAL_UP));
|
||||
_myAvatar->setDriveKeys(DOWN, _userInputMapper.getActionState(UserInputMapper::VERTICAL_DOWN));
|
||||
_myAvatar->setDriveKeys(LEFT, _userInputMapper.getActionState(UserInputMapper::LATERAL_LEFT));
|
||||
_myAvatar->setDriveKeys(RIGHT, _userInputMapper.getActionState(UserInputMapper::LATERAL_RIGHT));
|
||||
_myAvatar->setDriveKeys(ROT_UP, _userInputMapper.getActionState(UserInputMapper::PITCH_UP));
|
||||
_myAvatar->setDriveKeys(ROT_DOWN, _userInputMapper.getActionState(UserInputMapper::PITCH_DOWN));
|
||||
_myAvatar->setDriveKeys(ROT_LEFT, _userInputMapper.getActionState(UserInputMapper::YAW_LEFT));
|
||||
_myAvatar->setDriveKeys(ROT_RIGHT, _userInputMapper.getActionState(UserInputMapper::YAW_RIGHT));
|
||||
}
|
||||
_myAvatar->setDriveKeys(BOOM_IN, _userInputMapper.getActionState(UserInputMapper::BOOM_IN));
|
||||
_myAvatar->setDriveKeys(BOOM_OUT, _userInputMapper.getActionState(UserInputMapper::BOOM_OUT));
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ ControllerScriptingInterface::ControllerScriptingInterface() :
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
static int actionMetaTypeId = qRegisterMetaType<UserInputMapper::Action>();
|
||||
static int inputChannelMetaTypeId = qRegisterMetaType<UserInputMapper::InputChannel>();
|
||||
static int inputMetaTypeId = qRegisterMetaType<UserInputMapper::Input>();
|
||||
|
|
|
@ -72,12 +72,15 @@ public:
|
|||
void emitTouchUpdateEvent(const TouchEvent& event) { emit touchUpdateEvent(event); }
|
||||
|
||||
void emitWheelEvent(QWheelEvent* event) { emit wheelEvent(*event); }
|
||||
|
||||
void emitActionEvents();
|
||||
|
||||
bool isKeyCaptured(QKeyEvent* event) const;
|
||||
bool isKeyCaptured(const KeyEvent& event) const;
|
||||
bool isMouseCaptured() const { return _mouseCaptured; }
|
||||
bool isTouchCaptured() const { return _touchCaptured; }
|
||||
bool isWheelCaptured() const { return _wheelCaptured; }
|
||||
bool areActionsCaptured() const { return _actionsCaptured; }
|
||||
bool isJoystickCaptured(int joystickIndex) const;
|
||||
|
||||
void updateInputControllers();
|
||||
|
@ -122,6 +125,9 @@ public slots:
|
|||
|
||||
virtual void captureWheelEvents() { _wheelCaptured = true; }
|
||||
virtual void releaseWheelEvents() { _wheelCaptured = false; }
|
||||
|
||||
virtual void captureActionEvents() { _actionsCaptured = true; }
|
||||
virtual void releaseActionEvents() { _actionsCaptured = false; }
|
||||
|
||||
virtual void captureJoystick(int joystickIndex);
|
||||
virtual void releaseJoystick(int joystickIndex);
|
||||
|
@ -142,6 +148,7 @@ private:
|
|||
bool _mouseCaptured;
|
||||
bool _touchCaptured;
|
||||
bool _wheelCaptured;
|
||||
bool _actionsCaptured;
|
||||
QMultiMap<int,KeyEvent> _capturedKeys;
|
||||
QSet<int> _capturedJoysticks;
|
||||
|
||||
|
|
|
@ -8,9 +8,12 @@
|
|||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
#include "UserInputMapper.h"
|
||||
#include <algorithm>
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
#include "UserInputMapper.h"
|
||||
|
||||
|
||||
// UserInputMapper Class
|
||||
|
||||
|
@ -207,6 +210,9 @@ void UserInputMapper::update(float deltaTime) {
|
|||
// Scale all the channel step with the scale
|
||||
for (auto i = 0; i < NUM_ACTIONS; i++) {
|
||||
_actionStates[i] *= _actionScales[i];
|
||||
if (_actionStates[i] > 0) {
|
||||
emit Application::getInstance()->getControllerScriptingInterface()->actionEvent(i, _actionStates[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -83,6 +83,9 @@ public slots:
|
|||
|
||||
virtual void captureWheelEvents() = 0;
|
||||
virtual void releaseWheelEvents() = 0;
|
||||
|
||||
virtual void captureActionEvents() = 0;
|
||||
virtual void releaseActionEvents() = 0;
|
||||
|
||||
virtual void captureJoystick(int joystickIndex) = 0;
|
||||
virtual void releaseJoystick(int joystickIndex) = 0;
|
||||
|
@ -111,6 +114,8 @@ signals:
|
|||
void touchUpdateEvent(const TouchEvent& event);
|
||||
|
||||
void wheelEvent(const WheelEvent& event);
|
||||
|
||||
void actionEvent(int action, float state);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue