lovr.headset.wasPressed; lovr.headset.wasReleased;

This commit is contained in:
bjorn 2020-01-24 22:46:42 -08:00
parent 51afbd9fd4
commit 4f7bb9e53e
10 changed files with 64 additions and 19 deletions

View File

@ -347,9 +347,9 @@ static int l_lovrHeadsetGetAngularVelocity(lua_State* L) {
static int l_lovrHeadsetIsDown(lua_State* L) {
Device device = luax_optdevice(L, 1);
DeviceButton button = luaL_checkoption(L, 2, NULL, DeviceButtons);
bool down;
bool down, changed;
FOREACH_TRACKING_DRIVER(driver) {
if (driver->isDown(device, button, &down)) {
if (driver->isDown(device, button, &down, &changed)) {
lua_pushboolean(L, down);
return 1;
}
@ -358,6 +358,34 @@ static int l_lovrHeadsetIsDown(lua_State* L) {
return 1;
}
static int l_lovrHeadsetWasPressed(lua_State* L) {
Device device = luax_optdevice(L, 1);
DeviceButton button = luaL_checkoption(L, 2, NULL, DeviceButtons);
bool down, changed;
FOREACH_TRACKING_DRIVER(driver) {
if (driver->isDown(device, button, &down, &changed)) {
lua_pushboolean(L, down && changed);
return 1;
}
}
lua_pushboolean(L, false);
return 1;
}
static int l_lovrHeadsetWasReleased(lua_State* L) {
Device device = luax_optdevice(L, 1);
DeviceButton button = luaL_checkoption(L, 2, NULL, DeviceButtons);
bool down, changed;
FOREACH_TRACKING_DRIVER(driver) {
if (driver->isDown(device, button, &down, &changed)) {
lua_pushboolean(L, !down && changed);
return 1;
}
}
lua_pushboolean(L, false);
return 1;
}
static int l_lovrHeadsetIsTouched(lua_State* L) {
Device device = luax_optdevice(L, 1);
DeviceButton button = luaL_checkoption(L, 2, NULL, DeviceButtons);
@ -523,6 +551,8 @@ static const luaL_Reg lovrHeadset[] = {
{ "getVelocity", l_lovrHeadsetGetVelocity },
{ "getAngularVelocity", l_lovrHeadsetGetAngularVelocity },
{ "isDown", l_lovrHeadsetIsDown },
{ "wasPressed", l_lovrHeadsetWasPressed },
{ "wasReleased", l_lovrHeadsetWasReleased },
{ "isTouched", l_lovrHeadsetIsTouched },
{ "getAxis", l_lovrHeadsetGetAxis },
{ "vibrate", l_lovrHeadsetVibrate },

View File

@ -113,12 +113,13 @@ static bool desktop_getVelocity(Device device, vec3 velocity, vec3 angularVeloci
return true;
}
static bool desktop_isDown(Device device, DeviceButton button, bool* down) {
static bool desktop_isDown(Device device, DeviceButton button, bool* down, bool* changed) {
if (device != DEVICE_HAND_LEFT || button != BUTTON_TRIGGER) {
return false;
}
*down = lovrPlatformIsMouseDown(MOUSE_RIGHT);
*changed = false; // TODO
return true;
}

View File

@ -67,7 +67,7 @@ typedef struct HeadsetInterface {
const float* (*getBoundsGeometry)(uint32_t* count);
bool (*getPose)(Device device, float* position, float* orientation);
bool (*getVelocity)(Device device, float* velocity, float* angularVelocity);
bool (*isDown)(Device device, DeviceButton button, bool* down);
bool (*isDown)(Device device, DeviceButton button, bool* down, bool* changed);
bool (*isTouched)(Device device, DeviceButton button, bool* touched);
bool (*getAxis)(Device device, DeviceAxis axis, float* value);
bool (*vibrate)(Device device, float strength, float duration, float frequency);

View File

@ -109,13 +109,15 @@ static bool leap_getVelocity(Device device, vec3 velocity, vec3 angularVelocity)
return true;
}
static bool leap_isDown(Device device, DeviceButton button, bool* down) {
static bool leap_isDown(Device device, DeviceButton button, bool* down, bool* changed) {
if ((device != DEVICE_HAND_LEFT && device != DEVICE_HAND_RIGHT) || !state.hands[device - DEVICE_HAND_LEFT]) {
return false;
}
LEAP_HAND* hand = state.hands[device - DEVICE_HAND_LEFT];
*changed = false; // TODO
switch (button) {
case BUTTON_TRIGGER: *down = hand->pinch_strength > .5f; return true;
case BUTTON_GRIP: *down = hand->grab_strength > .5f; return true;

View File

@ -243,6 +243,10 @@ static bool oculus_isTouched(Device device, DeviceButton button, bool* touched)
}
}
static bool oculus_didChange(Device device, DeviceButton button, bool* changed) {
return false; // TODO
}
static bool oculus_getAxis(Device device, DeviceAxis axis, vec3 value) {
if (device != DEVICE_HAND_LEFT && device != DEVICE_HAND_RIGHT) {
return false;

View File

@ -181,11 +181,12 @@ static bool buttonTouch(BridgeLovrTouch field, DeviceButton button, bool *result
return true;
}
static bool vrapi_isDown(Device device, DeviceButton button, bool* down) {
static bool vrapi_isDown(Device device, DeviceButton button, bool* down, bool* changed) {
int idx = getHandIdx(device);
if (idx < 0)
return false;
*changed = false; // TODO
return buttonDown(bridgeLovrMobileData.updateData.controllers[idx].buttonDown, button, down);
}

View File

@ -307,23 +307,27 @@ static bool openvr_getVelocity(Device device, vec3 velocity, vec3 angularVelocit
return pose->bPoseIsValid;
}
static bool getButtonState(Device device, DeviceButton button, VRActionHandle_t actions[2][MAX_BUTTONS], bool* value) {
static bool openvr_isDown(Device device, DeviceButton button, bool* down, bool* changed) {
if (device != DEVICE_HAND_LEFT && device != DEVICE_HAND_RIGHT) {
return false;
}
InputDigitalActionData_t actionData;
state.input->GetDigitalActionData(actions[device - DEVICE_HAND_LEFT][button], &actionData, sizeof(actionData), 0);
*value = actionData.bState;
state.input->GetDigitalActionData(state.buttonActions[device - DEVICE_HAND_LEFT][button], &actionData, sizeof(actionData), 0);
*down = actionData.bState;
*changed = actionData.bChanged;
return actionData.bActive;
}
static bool openvr_isDown(Device device, DeviceButton button, bool* down) {
return getButtonState(device, button, state.buttonActions, down);
}
static bool openvr_isTouched(Device device, DeviceButton button, bool* touched) {
return getButtonState(device, button, state.touchActions, touched);
if (device != DEVICE_HAND_LEFT && device != DEVICE_HAND_RIGHT) {
return false;
}
InputDigitalActionData_t actionData;
state.input->GetDigitalActionData(state.touchActions[device - DEVICE_HAND_LEFT][button], &actionData, sizeof(actionData), 0);
*touched = actionData.bState;
return actionData.bActive;
}
static bool openvr_getAxis(Device device, DeviceAxis axis, vec3 value) {

View File

@ -554,15 +554,17 @@ static bool getButtonState(Device device, DeviceButton button, bool* value, bool
XrActionStateBoolean actionState;
XR(xrGetActionStateBoolean(state.session, &info, &actionState));
*value = actionState.currentState;
*changed = actionState.changedSinceLastSync;
return actionState.isActive;
}
static bool openxr_isDown(Device device, DeviceButton button, bool* down) {
return getButtonState(device, button, down, false);
static bool openxr_isDown(Device device, DeviceButton button, bool* down, bool* changed) {
return getButtonState(device, button, down, changed, false);
}
static bool openxr_isTouched(Device device, DeviceButton button, bool* touched) {
return getButtonState(device, button, touched, true);
bool unused;
return getButtonState(device, button, touched, &unused, true);
}
static bool openxr_getAxis(Device device, DeviceAxis axis, float* value) {

View File

@ -16,7 +16,7 @@ extern void webvr_getBoundsDimensions(float* width, float* depth);
extern const float* webvr_getBoundsGeometry(uint32_t* count);
extern bool webvr_getPose(Device device, float* position, float* orientation);
extern bool webvr_getVelocity(Device device, float* velocity, float* angularVelocity);
extern bool webvr_isDown(Device device, DeviceButton button, bool* down);
extern bool webvr_isDown(Device device, DeviceButton button, bool* down, bool* changed);
extern bool webvr_isTouched(Device device, DeviceButton button, bool* touched);
extern bool webvr_getAxis(Device device, DeviceAxis axis, float* value);
extern bool webvr_vibrate(Device device, float strength, float duration, float frequency);

View File

@ -209,7 +209,7 @@ var LibraryLOVR = {
return true;
},
webvr_isDown: function(device, button, down) {
webvr_isDown: function(device, button, down, changed) {
var gamepad = webvr.gamepads[device];
if (!gamepad || !gamepad.id || !webvr.buttonMap[gamepad.id] || !webvr.buttonMap[gamepad.id][button]) {
@ -217,6 +217,7 @@ var LibraryLOVR = {
}
HEAPF32[down >> 2] = gamepad.buttons[webvr.buttonMap[gamepad.id][button]].pressed;
HEAPF32[changed >> 2] = false; // TODO
return true;
},