mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +02:00
Add leveled controller-relative movement option.
This commit is contained in:
parent
7092513b7d
commit
a3c4747290
3 changed files with 56 additions and 18 deletions
|
@ -169,7 +169,7 @@ MyAvatar::MyAvatar(QThread* thread) :
|
|||
_useSnapTurnSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "useSnapTurn", _useSnapTurn),
|
||||
_userHeightSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "userHeight", DEFAULT_AVATAR_HEIGHT),
|
||||
_flyingHMDSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "flyingHMD", _flyingPrefHMD),
|
||||
_handRelativeMovementSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "handRelativeMovement", _handRelativeMovement),
|
||||
_movementReferenceSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "movementReference", _movementReference),
|
||||
_avatarEntityCountSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "avatarEntityData" << "size", 0),
|
||||
_userRecenterModelSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "userRecenterModel", USER_RECENTER_MODEL_AUTO),
|
||||
_driveGear1Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear1", _driveGear1),
|
||||
|
@ -1283,7 +1283,7 @@ void MyAvatar::saveData() {
|
|||
_useSnapTurnSetting.set(_useSnapTurn);
|
||||
_userHeightSetting.set(getUserHeight());
|
||||
_flyingHMDSetting.set(getFlyingHMDPref());
|
||||
_handRelativeMovementSetting.set(getHandRelativeMovement());
|
||||
_movementReferenceSetting.set(getMovementReference());
|
||||
_driveGear1Setting.set(getDriveGear1());
|
||||
_driveGear2Setting.set(getDriveGear2());
|
||||
_driveGear3Setting.set(getDriveGear3());
|
||||
|
@ -1867,7 +1867,7 @@ void MyAvatar::loadData() {
|
|||
// Flying preferences must be loaded before calling setFlyingEnabled()
|
||||
Setting::Handle<bool> firstRunVal { Settings::firstRun, true };
|
||||
setFlyingHMDPref(firstRunVal.get() ? false : _flyingHMDSetting.get());
|
||||
setHandRelativeMovement(firstRunVal.get() ? false : _handRelativeMovementSetting.get());
|
||||
setMovementReference(firstRunVal.get() ? false : _movementReferenceSetting.get());
|
||||
setDriveGear1(firstRunVal.get() ? DEFAULT_GEAR_1 : _driveGear1Setting.get());
|
||||
setDriveGear2(firstRunVal.get() ? DEFAULT_GEAR_2 : _driveGear2Setting.get());
|
||||
setDriveGear3(firstRunVal.get() ? DEFAULT_GEAR_3 : _driveGear3Setting.get());
|
||||
|
@ -3354,7 +3354,36 @@ glm::vec3 MyAvatar::calculateScaledDirection(){
|
|||
// compute action input
|
||||
// Determine if we're head or controller relative...
|
||||
glm::vec3 forward, right;
|
||||
if (getHandRelativeMovement() && qApp->isHMDMode()) {
|
||||
|
||||
if (qApp->isHMDMode()) {
|
||||
auto handRotation = getDominantHandRotation();
|
||||
glm::vec3 controllerForward(0.0f, 1.0f, 0.0f);
|
||||
glm::vec3 controllerRight(0.0f, 0.0f, (getDominantHand() == DOMINANT_RIGHT_HAND ? -1.0f : 1.0f));
|
||||
// Do shit here.
|
||||
switch (getMovementReference()) {
|
||||
case MOVEMENT_HAND_RELATIVE:
|
||||
forward = (handRotation * controllerForward);
|
||||
right = (handRotation * controllerRight);
|
||||
break;
|
||||
case MOVEMENT_HAND_RELATIVE_LEVELED:
|
||||
forward = (handRotation * controllerForward);
|
||||
forward.y = 0.0f;
|
||||
forward /= forward.length();
|
||||
right = (handRotation * controllerRight);
|
||||
right.y = 0.0f;
|
||||
right /= right.length();
|
||||
break;
|
||||
case MOVEMENT_HMD_RELATIVE:
|
||||
default:
|
||||
forward = IDENTITY_FORWARD;
|
||||
right = IDENTITY_RIGHT;
|
||||
}
|
||||
} else {
|
||||
forward = IDENTITY_FORWARD;
|
||||
right = IDENTITY_RIGHT;
|
||||
}
|
||||
|
||||
if (getMovementReference() && qApp->isHMDMode()) {
|
||||
// Here we have to get the rotation of the dominant hand and apply that to the direction vector.
|
||||
// If we're on the right hand, we have to flip the x-axis.
|
||||
auto handRotation = getDominantHandRotation();
|
||||
|
@ -3923,16 +3952,16 @@ void MyAvatar::setFlyingHMDPref(bool enabled) {
|
|||
_flyingPrefHMD = enabled;
|
||||
}
|
||||
|
||||
void MyAvatar::setHandRelativeMovement(bool enabled) {
|
||||
void MyAvatar::setMovementReference(int enabled) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "setHandRelativeMovement", Q_ARG(bool, enabled));
|
||||
QMetaObject::invokeMethod(this, "setMovementReference", Q_ARG(bool, enabled));
|
||||
return;
|
||||
}
|
||||
_handRelativeMovement = enabled;
|
||||
_movementReference = enabled;
|
||||
}
|
||||
|
||||
bool MyAvatar::getHandRelativeMovement() {
|
||||
return _handRelativeMovement;
|
||||
int MyAvatar::getMovementReference() {
|
||||
return _movementReference;
|
||||
}
|
||||
|
||||
void MyAvatar::setControlSchemeIndex(int index){
|
||||
|
|
|
@ -43,6 +43,10 @@ const int CONTROLS_DEFAULT = 0;
|
|||
const int CONTROLS_ANALOG = 1;
|
||||
const int CONTROLS_ANALOG_PLUS = 2;
|
||||
|
||||
const int MOVEMENT_HMD_RELATIVE = 0;
|
||||
const int MOVEMENT_HAND_RELATIVE = 1;
|
||||
const int MOVEMENT_HAND_RELATIVE_LEVELED = 2;
|
||||
|
||||
enum eyeContactTarget {
|
||||
LEFT_EYE,
|
||||
RIGHT_EYE,
|
||||
|
@ -1036,18 +1040,18 @@ public:
|
|||
/**jsdoc
|
||||
* Set your preference for hand-relative movement.
|
||||
* @function MyAvatar.setHandRelativeMovement
|
||||
* @param {boolean} enabled - Set <code>true</code> if you want to enable hand-relative movement, otherwise set to <code>false</code>.
|
||||
* @param {number} enabled - Set <code>true</code> if you want to enable hand-relative movement, otherwise set to <code>false</code>.
|
||||
*
|
||||
*/
|
||||
Q_INVOKABLE void setHandRelativeMovement(bool enabled);
|
||||
Q_INVOKABLE void setMovementReference(int enabled);
|
||||
|
||||
/**jsdoc
|
||||
* Get your preference for hand-relative movement.
|
||||
* @function MyAvatar.getHandRelativeMovement
|
||||
* @returns {boolean} <code>true</code> if your preference is for user locomotion to be relative to the direction your
|
||||
* @returns {number} <code>true</code> if your preference is for user locomotion to be relative to the direction your
|
||||
* controller is pointing, otherwise <code>false</code>.
|
||||
*/
|
||||
Q_INVOKABLE bool getHandRelativeMovement();
|
||||
Q_INVOKABLE int getMovementReference();
|
||||
|
||||
/**jsdoc
|
||||
* Set the first 'shifting point' for acceleration step function.
|
||||
|
@ -1802,7 +1806,6 @@ private:
|
|||
bool _enableFlying { false };
|
||||
bool _flyingPrefDesktop { true };
|
||||
bool _flyingPrefHMD { false };
|
||||
bool _handRelativeMovement{ false };
|
||||
bool _wasPushing { false };
|
||||
bool _isPushing { false };
|
||||
bool _isBeingPushed { false };
|
||||
|
@ -1818,6 +1821,7 @@ private:
|
|||
float _driveGear4 { DEFAULT_GEAR_4 };
|
||||
float _driveGear5 { DEFAULT_GEAR_5 };
|
||||
int _controlSchemeIndex { CONTROLS_DEFAULT };
|
||||
int _movementReference{ 0 };
|
||||
|
||||
glm::vec3 _thrust { 0.0f }; // impulse accumulator for outside sources
|
||||
|
||||
|
@ -2069,7 +2073,7 @@ private:
|
|||
Setting::Handle<bool> _useSnapTurnSetting;
|
||||
Setting::Handle<float> _userHeightSetting;
|
||||
Setting::Handle<bool> _flyingHMDSetting;
|
||||
Setting::Handle<bool> _handRelativeMovementSetting;
|
||||
Setting::Handle<int> _movementReferenceSetting;
|
||||
Setting::Handle<int> _avatarEntityCountSetting;
|
||||
Setting::Handle<bool> _allowTeleportingSetting { "allowTeleporting", true };
|
||||
Setting::Handle<float> _driveGear1Setting;
|
||||
|
|
|
@ -273,9 +273,14 @@ void setupPreferences() {
|
|||
preferences->addPreference(preference);
|
||||
}
|
||||
{
|
||||
auto getter = [myAvatar]()->bool { return myAvatar->getHandRelativeMovement(); };
|
||||
auto setter = [myAvatar](bool value) { myAvatar->setHandRelativeMovement(value); };
|
||||
auto preference = new CheckPreference(VR_MOVEMENT, "Hand-Relative Movement", getter, setter);
|
||||
auto getter = [myAvatar]()->int { return myAvatar->getMovementReference(); };
|
||||
auto setter = [myAvatar](int value) { myAvatar->setMovementReference(value); };
|
||||
//auto preference = new CheckPreference(VR_MOVEMENT, "Hand-Relative Movement", getter, setter);
|
||||
auto preference = new RadioButtonsPreference(VR_MOVEMENT, "Movement Direction", getter, setter);
|
||||
QStringList items;
|
||||
items << "HMD-Relative" << "Hand-Relative" << "Hand-Relative (Leveled)";
|
||||
preference->setHeading("Movement Direction");
|
||||
preference->setItems(items);
|
||||
preferences->addPreference(preference);
|
||||
}
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue