mirror of https://github.com/bjornbytes/lovr.git
Finalize skeletal input API;
This commit is contained in:
parent
6c130ebd86
commit
f82bcb703b
|
@ -66,14 +66,15 @@ extern const char* BlockTypes[];
|
|||
extern const char* BufferUsages[];
|
||||
extern const char* CompareModes[];
|
||||
extern const char* CoordinateSpaces[];
|
||||
extern const char* Devices[];
|
||||
extern const char* DeviceAxes[];
|
||||
extern const char* DeviceButtons[];
|
||||
extern const char* DrawModes[];
|
||||
extern const char* DrawStyles[];
|
||||
extern const char* EventTypes[];
|
||||
extern const char* FilterModes[];
|
||||
extern const char* HeadsetDrivers[];
|
||||
extern const char* HeadsetEyes[];
|
||||
extern const char* HeadsetOrigins[];
|
||||
extern const char* HeadsetTypes[];
|
||||
extern const char* HorizontalAligns[];
|
||||
extern const char* JointTypes[];
|
||||
extern const char* MaterialColors[];
|
||||
|
|
|
@ -33,8 +33,6 @@ const char* Devices[] = {
|
|||
[DEVICE_HEAD] = "head",
|
||||
[DEVICE_HAND_LEFT] = "hand/left",
|
||||
[DEVICE_HAND_RIGHT] = "hand/right",
|
||||
[DEVICE_EYE_LEFT] = "eye/left",
|
||||
[DEVICE_EYE_RIGHT] = "eye/right",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -56,40 +54,10 @@ const char* DeviceAxes[] = {
|
|||
[AXIS_TRIGGER] = "trigger",
|
||||
[AXIS_THUMBSTICK] = "thumbstick",
|
||||
[AXIS_TOUCHPAD] = "touchpad",
|
||||
[AXIS_PINCH] = "pinch",
|
||||
[AXIS_GRIP] = "grip",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char* DeviceBones[] = {
|
||||
[BONE_THUMB] = "thumb",
|
||||
[BONE_INDEX] = "index",
|
||||
[BONE_MIDDLE] = "middle",
|
||||
[BONE_RING] = "ring",
|
||||
[BONE_PINKY] = "pinky",
|
||||
[BONE_THUMB_NULL] = "thumb/null",
|
||||
[BONE_THUMB_1] = "thumb/1",
|
||||
[BONE_THUMB_2] = "thumb/2",
|
||||
[BONE_THUMB_3] = "thumb/3",
|
||||
[BONE_INDEX_1] = "index/1",
|
||||
[BONE_INDEX_2] = "index/2",
|
||||
[BONE_INDEX_3] = "index/3",
|
||||
[BONE_INDEX_4] = "index/4",
|
||||
[BONE_MIDDLE_1] = "middle/1",
|
||||
[BONE_MIDDLE_2] = "middle/2",
|
||||
[BONE_MIDDLE_3] = "middle/3",
|
||||
[BONE_MIDDLE_4] = "middle/4",
|
||||
[BONE_RING_1] = "ring/1",
|
||||
[BONE_RING_2] = "ring/2",
|
||||
[BONE_RING_3] = "ring/3",
|
||||
[BONE_RING_4] = "ring/4",
|
||||
[BONE_PINKY_1] = "pinky/1",
|
||||
[BONE_PINKY_2] = "pinky/2",
|
||||
[BONE_PINKY_3] = "pinky/3",
|
||||
[BONE_PINKY_4] = "pinky/4",
|
||||
NULL
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
lua_State* L;
|
||||
int ref;
|
||||
|
@ -406,10 +374,9 @@ int l_lovrHeadsetIsTouched(lua_State* L) {
|
|||
|
||||
static const int axisCounts[MAX_AXES] = {
|
||||
[AXIS_TRIGGER] = 1,
|
||||
[AXIS_PINCH] = 1,
|
||||
[AXIS_GRIP] = 1,
|
||||
[AXIS_THUMBSTICK] = 2,
|
||||
[AXIS_TOUCHPAD] = 2
|
||||
[AXIS_TOUCHPAD] = 2,
|
||||
[AXIS_GRIP] = 1
|
||||
};
|
||||
|
||||
int l_lovrHeadsetGetAxis(lua_State* L) {
|
||||
|
@ -467,30 +434,6 @@ int l_lovrHeadsetNewModel(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrHeadsetGetBonePose(lua_State* L) {
|
||||
Device device = luax_optdevice(L, 1);
|
||||
DeviceBone bone = luaL_checkoption(L, 2, NULL, DeviceBones);
|
||||
float position[4], orientation[4];
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->getBonePose(device, bone, position, orientation)) {
|
||||
float angle, ax, ay, az;
|
||||
quat_getAngleAxis(orientation, &angle, &ax, &ay, &az);
|
||||
lua_pushnumber(L, position[0]);
|
||||
lua_pushnumber(L, position[1]);
|
||||
lua_pushnumber(L, position[2]);
|
||||
lua_pushnumber(L, angle);
|
||||
lua_pushnumber(L, ax);
|
||||
lua_pushnumber(L, ay);
|
||||
lua_pushnumber(L, az);
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 7; i++) {
|
||||
lua_pushnumber(L, 0.);
|
||||
}
|
||||
return 7;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetRenderTo(lua_State* L) {
|
||||
lua_settop(L, 1);
|
||||
luaL_checktype(L, 1, LUA_TFUNCTION);
|
||||
|
@ -584,7 +527,6 @@ static const luaL_Reg lovrHeadset[] = {
|
|||
{ "getAxis", l_lovrHeadsetGetAxis },
|
||||
{ "vibrate", l_lovrHeadsetVibrate },
|
||||
{ "newModel", l_lovrHeadsetNewModel },
|
||||
{ "getBonePose", l_lovrHeadsetGetBonePose },
|
||||
{ "renderTo", l_lovrHeadsetRenderTo },
|
||||
{ "update", l_lovrHeadsetUpdate },
|
||||
{ "getMirrorTexture", l_lovrHeadsetGetMirrorTexture },
|
||||
|
|
|
@ -97,10 +97,6 @@ static bool desktop_getPose(Device device, vec3 position, quat orientation) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool desktop_getBonePose(Device device, DeviceBone bone, vec3 position, quat orientation) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool desktop_getVelocity(Device device, vec3 velocity, vec3 angularVelocity) {
|
||||
if (device != DEVICE_HEAD) {
|
||||
return false;
|
||||
|
@ -227,7 +223,6 @@ HeadsetInterface lovrHeadsetDesktopDriver = {
|
|||
.getBoundsDimensions = desktop_getBoundsDimensions,
|
||||
.getBoundsGeometry = desktop_getBoundsGeometry,
|
||||
.getPose = desktop_getPose,
|
||||
.getBonePose = desktop_getBonePose,
|
||||
.getVelocity = desktop_getVelocity,
|
||||
.isDown = desktop_isDown,
|
||||
.isTouched = desktop_isTouched,
|
||||
|
|
|
@ -26,8 +26,6 @@ typedef enum {
|
|||
DEVICE_HEAD,
|
||||
DEVICE_HAND_LEFT,
|
||||
DEVICE_HAND_RIGHT,
|
||||
DEVICE_EYE_LEFT,
|
||||
DEVICE_EYE_RIGHT,
|
||||
MAX_DEVICES
|
||||
} Device;
|
||||
|
||||
|
@ -49,39 +47,10 @@ typedef enum {
|
|||
AXIS_TRIGGER,
|
||||
AXIS_THUMBSTICK,
|
||||
AXIS_TOUCHPAD,
|
||||
AXIS_PINCH,
|
||||
AXIS_GRIP,
|
||||
MAX_AXES
|
||||
} DeviceAxis;
|
||||
|
||||
typedef enum {
|
||||
BONE_THUMB,
|
||||
BONE_INDEX,
|
||||
BONE_MIDDLE,
|
||||
BONE_RING,
|
||||
BONE_PINKY,
|
||||
BONE_THUMB_NULL,
|
||||
BONE_THUMB_1,
|
||||
BONE_THUMB_2,
|
||||
BONE_THUMB_3,
|
||||
BONE_INDEX_1,
|
||||
BONE_INDEX_2,
|
||||
BONE_INDEX_3,
|
||||
BONE_INDEX_4,
|
||||
BONE_MIDDLE_1,
|
||||
BONE_MIDDLE_2,
|
||||
BONE_MIDDLE_3,
|
||||
BONE_MIDDLE_4,
|
||||
BONE_RING_1,
|
||||
BONE_RING_2,
|
||||
BONE_RING_3,
|
||||
BONE_RING_4,
|
||||
BONE_PINKY_1,
|
||||
BONE_PINKY_2,
|
||||
BONE_PINKY_3,
|
||||
BONE_PINKY_4
|
||||
} DeviceBone;
|
||||
|
||||
typedef struct HeadsetInterface {
|
||||
struct HeadsetInterface* next;
|
||||
HeadsetDriver driverType;
|
||||
|
@ -97,7 +66,6 @@ typedef struct HeadsetInterface {
|
|||
void (*getBoundsDimensions)(float* width, float* depth);
|
||||
const float* (*getBoundsGeometry)(uint32_t* count);
|
||||
bool (*getPose)(Device device, float* position, float* orientation);
|
||||
bool (*getBonePose)(Device device, DeviceBone bone, float* position, float* orientation);
|
||||
bool (*getVelocity)(Device device, float* velocity, float* angularVelocity);
|
||||
bool (*isDown)(Device device, DeviceButton button, bool* down);
|
||||
bool (*isTouched)(Device device, DeviceButton button, bool* touched);
|
||||
|
|
|
@ -10,8 +10,7 @@ static struct {
|
|||
LEAP_CONNECTION connection;
|
||||
LEAP_CLOCK_REBASER clock;
|
||||
LEAP_TRACKING_EVENT* frame;
|
||||
LEAP_HAND* leftHand;
|
||||
LEAP_HAND* rightHand;
|
||||
LEAP_HAND* hands[2];
|
||||
uint64_t frameSize;
|
||||
float headPose[16];
|
||||
thrd_t thread;
|
||||
|
@ -84,19 +83,12 @@ static void adjustPose(vec3 position, vec3 direction) {
|
|||
}
|
||||
|
||||
static bool leap_getPose(Device device, vec3 position, quat orientation) {
|
||||
LEAP_HAND* hand;
|
||||
|
||||
switch (device) {
|
||||
case DEVICE_HAND_LEFT: hand = state.leftHand; break;
|
||||
case DEVICE_HAND_RIGHT: hand = state.rightHand; break;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
if (!hand) {
|
||||
if ((device != DEVICE_HAND_LEFT && device != DEVICE_HAND_RIGHT) || !state.hands[device - DEVICE_HAND_LEFT]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
float direction[4];
|
||||
LEAP_HAND* hand = state.hands[device - DEVICE_HAND_LEFT];
|
||||
vec3_init(position, hand->palm.position.v);
|
||||
vec3_init(direction, hand->palm.normal.v);
|
||||
adjustPose(position, direction);
|
||||
|
@ -104,57 +96,13 @@ static bool leap_getPose(Device device, vec3 position, quat orientation) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool leap_getBonePose(Device device, DeviceBone bone, vec3 position, quat orientation) {
|
||||
LEAP_HAND* hand;
|
||||
|
||||
switch (device) {
|
||||
case DEVICE_HAND_LEFT: hand = state.leftHand; break;
|
||||
case DEVICE_HAND_RIGHT: hand = state.rightHand; break;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
if (!hand) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Assumes that enum values for non-tip bones are grouped by finger, and start after BONE_PINKY,
|
||||
// could be less clever and use a switch if needed
|
||||
float direction[4];
|
||||
if (bone <= BONE_PINKY) {
|
||||
LEAP_DIGIT* finger = &hand->digits[bone];
|
||||
vec3 base = finger->distal.prev_joint.v;
|
||||
vec3 tip = finger->distal.next_joint.v;
|
||||
vec3_sub(vec3_init(direction, tip), base);
|
||||
vec3_init(position, tip);
|
||||
} else {
|
||||
bone -= BONE_PINKY + 1;
|
||||
LEAP_DIGIT* finger = &hand->digits[bone / 4];
|
||||
LEAP_BONE* leapBone = &finger->bones[bone % 4];
|
||||
vec3 base = leapBone->prev_joint.v;
|
||||
vec3 tip = leapBone->next_joint.v;
|
||||
vec3_sub(vec3_init(direction, tip), base);
|
||||
vec3_init(position, base);
|
||||
}
|
||||
|
||||
adjustPose(position, direction);
|
||||
quat_between(orientation, (float[4]) { 0.f, 0.f, -1.f }, direction);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool leap_getVelocity(Device device, vec3 velocity, vec3 angularVelocity) {
|
||||
LEAP_HAND* hand;
|
||||
|
||||
switch (device) {
|
||||
case DEVICE_HAND_LEFT: hand = state.leftHand; break;
|
||||
case DEVICE_HAND_RIGHT: hand = state.rightHand; break;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
if (!hand) {
|
||||
if ((device != DEVICE_HAND_LEFT && device != DEVICE_HAND_RIGHT) || !state.hands[device - DEVICE_HAND_LEFT]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
vec3_set(velocity, hand->palm.velocity.x, hand->palm.velocity.z, hand->palm.velocity.y);
|
||||
LEAP_HAND* hand = state.hands[device - DEVICE_HAND_LEFT];
|
||||
vec3_set(velocity, hand->palm.velocity.x, hand->palm.velocity.z, hand->palm.velocity.y); // Swap z and y
|
||||
vec3_scale(velocity, -.001f);
|
||||
mat4_transformDirection(state.headPose, velocity);
|
||||
vec3_set(angularVelocity, 0.f, 0.f, 0.f);
|
||||
|
@ -162,7 +110,17 @@ static bool leap_getVelocity(Device device, vec3 velocity, vec3 angularVelocity)
|
|||
}
|
||||
|
||||
static bool leap_isDown(Device device, DeviceButton button, bool* down) {
|
||||
return false;
|
||||
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];
|
||||
|
||||
switch (button) {
|
||||
case BUTTON_TRIGGER: *down = hand->pinch_strength > .5f; return true;
|
||||
case BUTTON_GRIP: *down = hand->grab_strength > .5f; return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool leap_isTouched(Device device, DeviceButton button, bool* touched) {
|
||||
|
@ -170,20 +128,14 @@ static bool leap_isTouched(Device device, DeviceButton button, bool* touched) {
|
|||
}
|
||||
|
||||
static bool leap_getAxis(Device device, DeviceAxis axis, float* value) {
|
||||
LEAP_HAND* hand;
|
||||
|
||||
switch (device) {
|
||||
case DEVICE_HAND_LEFT: hand = state.leftHand; break;
|
||||
case DEVICE_HAND_RIGHT: hand = state.rightHand; break;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
if (!hand) {
|
||||
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];
|
||||
|
||||
switch (axis) {
|
||||
case AXIS_PINCH: *value = hand->pinch_strength; return true;
|
||||
case AXIS_TRIGGER: *value = hand->pinch_strength; return true;
|
||||
case AXIS_GRIP: *value = hand->grab_strength; return true;
|
||||
default: return false;
|
||||
}
|
||||
|
@ -221,13 +173,10 @@ static void leap_update(float dt) {
|
|||
|
||||
LeapInterpolateFrame(state.connection, targetTime, state.frame, size);
|
||||
|
||||
state.leftHand = state.rightHand = NULL;
|
||||
state.hands[0] = state.hands[1] = NULL;
|
||||
for (uint32_t i = 0; i < state.frame->nHands; i++) {
|
||||
if (!state.leftHand && state.frame->pHands[i].type == eLeapHandType_Left) {
|
||||
state.leftHand = &state.frame->pHands[i];
|
||||
} else if (!state.rightHand && state.frame->pHands[i].type == eLeapHandType_Right) {
|
||||
state.rightHand = &state.frame->pHands[i];
|
||||
}
|
||||
LEAP_HAND* hand = &state.frame->pHands[i];
|
||||
state.hands[hand->type == eLeapHandType_Right] = hand;
|
||||
}
|
||||
|
||||
float position[4], orientation[4];
|
||||
|
@ -245,7 +194,6 @@ HeadsetInterface lovrHeadsetLeapMotionDriver = {
|
|||
.init = leap_init,
|
||||
.destroy = leap_destroy,
|
||||
.getPose = leap_getPose,
|
||||
.getBonePose = leap_getBonePose,
|
||||
.getVelocity = leap_getVelocity,
|
||||
.isDown = leap_isDown,
|
||||
.isTouched = leap_isTouched,
|
||||
|
|
|
@ -186,10 +186,6 @@ static bool oculus_getPose(Device device, vec3 position, quat orientation) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool oculus_getBonePose(Device device, DeviceBone bone, vec3 position, quat orientation) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool oculus_getVelocity(Device device, vec3 velocity, vec3 angularVelocity) {
|
||||
ovrPoseStatef* pose = getPose(device);
|
||||
if (!pose) return false;
|
||||
|
@ -407,7 +403,6 @@ HeadsetInterface lovrHeadsetOculusDriver = {
|
|||
.getBoundsDimensions = oculus_getBoundsDimensions,
|
||||
.getBoundsGeometry = oculus_getBoundsGeometry,
|
||||
.getPose = oculus_getPose,
|
||||
.getBonePose = oculus_getBonePose,
|
||||
.getVelocity = oculus_getVelocity,
|
||||
.isDown = oculus_isDown,
|
||||
.isTouched = oculus_isTouched,
|
||||
|
|
|
@ -118,10 +118,6 @@ static bool vrapi_getPose(Device device, vec3 position, quat orientation) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool vrapi_getBonePose(Device device, DeviceBone bone, vec3 position, quat orientation) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool vrapi_getVelocity(Device device, vec3 velocity, vec3 angularVelocity) {
|
||||
BridgeLovrAngularVector* v;
|
||||
|
||||
|
@ -260,7 +256,6 @@ HeadsetInterface lovrHeadsetOculusMobileDriver = {
|
|||
.getBoundsDimensions = vrapi_getBoundsDimensions,
|
||||
.getBoundsGeometry = vrapi_getBoundsGeometry,
|
||||
.getPose = vrapi_getPose,
|
||||
.getBonePose = vrapi_getBonePose,
|
||||
.getVelocity = vrapi_getVelocity,
|
||||
.isDown = vrapi_isDown,
|
||||
.isTouched = vrapi_isTouched,
|
||||
|
|
|
@ -31,41 +31,6 @@ extern bool VR_IsHmdPresent();
|
|||
extern intptr_t VR_GetGenericInterface(const char* pchInterfaceVersion, EVRInitError* peError);
|
||||
extern bool VR_IsRuntimeInstalled();
|
||||
|
||||
typedef enum {
|
||||
eBone_Root = 0,
|
||||
eBone_Wrist,
|
||||
eBone_Thumb0,
|
||||
eBone_Thumb1,
|
||||
eBone_Thumb2,
|
||||
eBone_Thumb3,
|
||||
eBone_IndexFinger0,
|
||||
eBone_IndexFinger1,
|
||||
eBone_IndexFinger2,
|
||||
eBone_IndexFinger3,
|
||||
eBone_IndexFinger4,
|
||||
eBone_MiddleFinger0,
|
||||
eBone_MiddleFinger1,
|
||||
eBone_MiddleFinger2,
|
||||
eBone_MiddleFinger3,
|
||||
eBone_MiddleFinger4,
|
||||
eBone_RingFinger0,
|
||||
eBone_RingFinger1,
|
||||
eBone_RingFinger2,
|
||||
eBone_RingFinger3,
|
||||
eBone_RingFinger4,
|
||||
eBone_PinkyFinger0,
|
||||
eBone_PinkyFinger1,
|
||||
eBone_PinkyFinger2,
|
||||
eBone_PinkyFinger3,
|
||||
eBone_PinkyFinger4,
|
||||
eBone_Aux_Thumb,
|
||||
eBone_Aux_IndexFinger,
|
||||
eBone_Aux_MiddleFinger,
|
||||
eBone_Aux_RingFinger,
|
||||
eBone_Aux_PinkyFinger,
|
||||
eBone_Count
|
||||
} OpenVRBone;
|
||||
|
||||
#define HEADSET k_unTrackedDeviceIndex_Hmd
|
||||
#define INVALID_DEVICE k_unTrackedDeviceIndexInvalid
|
||||
|
||||
|
@ -310,103 +275,43 @@ static const float* openvr_getBoundsGeometry(uint32_t* count) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static bool getTransform(Device device, mat4 transform) {
|
||||
if (device == DEVICE_HEAD) {
|
||||
mat4_fromMat34(transform, state.headPose.mDeviceToAbsoluteTracking.m);
|
||||
transform[13] += state.offset;
|
||||
return state.headPose.bPoseIsValid;
|
||||
}
|
||||
|
||||
if (!state.poseActions[device]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
InputPoseActionData_t actionData;
|
||||
state.input->GetPoseActionData(state.poseActions[device], state.compositor->GetTrackingSpace(), 0.f, &actionData, sizeof(actionData), 0);
|
||||
mat4_fromMat34(transform, actionData.pose.mDeviceToAbsoluteTracking.m);
|
||||
transform[13] += state.offset;
|
||||
return actionData.bActive;
|
||||
}
|
||||
|
||||
static bool openvr_getPose(Device device, vec3 position, quat orientation) {
|
||||
float transform[16];
|
||||
if (getTransform(device, transform)) {
|
||||
mat4_getPosition(transform, position);
|
||||
mat4_getOrientation(transform, orientation);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
InputPoseActionData_t actionData;
|
||||
TrackedDevicePose_t* pose;
|
||||
|
||||
static bool openvr_getBonePose(Device device, DeviceBone bone, vec3 position, quat orientation) {
|
||||
if (device != DEVICE_HAND_LEFT && device != DEVICE_HAND_RIGHT) {
|
||||
if (device == DEVICE_HEAD) {
|
||||
pose = &state.headPose;
|
||||
} else if (device == DEVICE_HAND_LEFT || device == DEVICE_HAND_RIGHT) {
|
||||
state.input->GetPoseActionData(state.poseActions[device], state.compositor->GetTrackingSpace(), 0.f, &actionData, sizeof(actionData), 0);
|
||||
pose = &actionData.pose;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
float transform[16];
|
||||
if (!getTransform(device, transform)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
InputSkeletalActionData_t actionData;
|
||||
state.input->GetSkeletalActionData(state.skeletonActions[device - DEVICE_HAND_LEFT], &actionData, sizeof(actionData));
|
||||
|
||||
if (!actionData.bActive) {
|
||||
return false;
|
||||
}
|
||||
|
||||
VRBoneTransform_t bones[31];
|
||||
EVRSkeletalTransformSpace transformSpace = EVRSkeletalTransformSpace_VRSkeletalTransformSpace_Model;
|
||||
EVRSkeletalMotionRange motionRange = EVRSkeletalMotionRange_VRSkeletalMotionRange_WithController;
|
||||
state.input->GetSkeletalBoneData(state.skeletonActions[device - DEVICE_HAND_LEFT], transformSpace, motionRange, bones, sizeof(bones) / sizeof(bones[0]));
|
||||
|
||||
int index;
|
||||
switch (bone) {
|
||||
case BONE_THUMB_1: index = eBone_Thumb0; break;
|
||||
case BONE_THUMB_2: index = eBone_Thumb1; break;
|
||||
case BONE_THUMB_3: index = eBone_Thumb2; break;
|
||||
case BONE_THUMB: index = eBone_Thumb3; break;
|
||||
case BONE_INDEX_1: index = eBone_IndexFinger0; break;
|
||||
case BONE_INDEX_2: index = eBone_IndexFinger1; break;
|
||||
case BONE_INDEX_3: index = eBone_IndexFinger2; break;
|
||||
case BONE_INDEX_4: index = eBone_IndexFinger3; break;
|
||||
case BONE_INDEX: index = eBone_IndexFinger4; break;
|
||||
case BONE_MIDDLE_1: index = eBone_MiddleFinger0; break;
|
||||
case BONE_MIDDLE_2: index = eBone_MiddleFinger1; break;
|
||||
case BONE_MIDDLE_3: index = eBone_MiddleFinger2; break;
|
||||
case BONE_MIDDLE_4: index = eBone_MiddleFinger3; break;
|
||||
case BONE_MIDDLE: index = eBone_MiddleFinger4; break;
|
||||
case BONE_RING_1: index = eBone_RingFinger0; break;
|
||||
case BONE_RING_2: index = eBone_RingFinger1; break;
|
||||
case BONE_RING_3: index = eBone_RingFinger2; break;
|
||||
case BONE_RING_4: index = eBone_RingFinger3; break;
|
||||
case BONE_RING: index = eBone_RingFinger4; break;
|
||||
case BONE_PINKY_1: index = eBone_PinkyFinger0; break;
|
||||
case BONE_PINKY_2: index = eBone_PinkyFinger1; break;
|
||||
case BONE_PINKY_3: index = eBone_PinkyFinger2; break;
|
||||
case BONE_PINKY_4: index = eBone_PinkyFinger3; break;
|
||||
case BONE_PINKY: index = eBone_PinkyFinger4; break;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
VRBoneTransform_t* b = &bones[index];
|
||||
mat4_translate(transform, b->position.v[0], b->position.v[1], b->position.v[2]);
|
||||
mat4_rotateQuat(transform, (float[4]) { b->orientation.x, b->orientation.y, b->orientation.z, b->orientation.w });
|
||||
mat4_fromMat34(transform, pose->mDeviceToAbsoluteTracking.m);
|
||||
mat4_getPosition(transform, position);
|
||||
mat4_getOrientation(transform, orientation);
|
||||
return true;
|
||||
transform[13] += state.offset;
|
||||
return pose->bPoseIsValid;
|
||||
}
|
||||
|
||||
static bool openvr_getVelocity(Device device, vec3 velocity, vec3 angularVelocity) {
|
||||
if (!state.poseActions[device]) {
|
||||
InputPoseActionData_t actionData;
|
||||
TrackedDevicePose_t* pose;
|
||||
|
||||
if (device == DEVICE_HEAD) {
|
||||
pose = &state.headPose;
|
||||
} else if (device == DEVICE_HAND_LEFT || device == DEVICE_HAND_RIGHT) {
|
||||
state.input->GetPoseActionData(state.poseActions[device], state.compositor->GetTrackingSpace(), 0.f, &actionData, sizeof(actionData), 0);
|
||||
pose = &actionData.pose;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
InputPoseActionData_t actionData;
|
||||
state.input->GetPoseActionData(state.poseActions[device], state.compositor->GetTrackingSpace(), 0.f, &actionData, sizeof(actionData), 0);
|
||||
vec3_init(velocity, actionData.pose.vVelocity.v);
|
||||
vec3_init(angularVelocity, actionData.pose.vAngularVelocity.v);
|
||||
return actionData.bActive;
|
||||
vec3_init(velocity, pose->vVelocity.v);
|
||||
vec3_init(angularVelocity, pose->vAngularVelocity.v);
|
||||
return pose->bPoseIsValid;
|
||||
}
|
||||
|
||||
static bool getButtonState(Device device, DeviceButton button, VRActionHandle_t actions[2][MAX_BUTTONS], bool* value) {
|
||||
|
@ -638,7 +543,6 @@ HeadsetInterface lovrHeadsetOpenVRDriver = {
|
|||
.getBoundsDimensions = openvr_getBoundsDimensions,
|
||||
.getBoundsGeometry = openvr_getBoundsGeometry,
|
||||
.getPose = openvr_getPose,
|
||||
.getBonePose = openvr_getBonePose,
|
||||
.getVelocity = openvr_getVelocity,
|
||||
.isDown = openvr_isDown,
|
||||
.isTouched = openvr_isTouched,
|
||||
|
|
|
@ -496,10 +496,6 @@ static bool openxr_getPose(Device device, vec3 position, quat orientation) {
|
|||
return location.locationFlags & (XR_SPACE_LOCATION_POSITION_VALID_BIT | XR_SPACE_LOCATION_ORIENTATION_VALID_BIT);
|
||||
}
|
||||
|
||||
static bool openxr_getBonePose(Device device, DeviceBone bone, vec3 position, quat orientation) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool openxr_getVelocity(Device device, vec3 linearVelocity, vec3 angularVelocity) {
|
||||
if (!state.spaces[device]) {
|
||||
return false;
|
||||
|
@ -750,7 +746,6 @@ HeadsetInterface lovrHeadsetOpenXRDriver = {
|
|||
.getBoundsDimensions = openxr_getBoundsDimensions,
|
||||
.getBoundsGeometry = openxr_getBoundsGeometry,
|
||||
.getPose = openxr_getPose,
|
||||
.getBonePose = openxr_getBonePose,
|
||||
.getVelocity = openxr_getVelocity,
|
||||
.isDown = openxr_isDown,
|
||||
.isTouched = openxr_isTouched,
|
||||
|
|
|
@ -15,7 +15,6 @@ extern void webvr_setClipDistance(float near, float far);
|
|||
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_getBonePose(Device device, DeviceBone bone, 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_isTouched(Device device, DeviceButton button, bool* touched);
|
||||
|
@ -59,7 +58,6 @@ HeadsetInterface lovrHeadsetWebVRDriver = {
|
|||
.getBoundsDimensions = webvr_getBoundsDimensions,
|
||||
.getBoundsGeometry = webvr_getBoundsGeometry,
|
||||
.getPose = webvr_getPose,
|
||||
.getBonePose = webvr_getBonePose,
|
||||
.getVelocity = webvr_getVelocity,
|
||||
.isDown = webvr_isDown,
|
||||
.isTouched = webvr_isTouched,
|
||||
|
|
|
@ -184,10 +184,6 @@ var LibraryLOVR = {
|
|||
return true;
|
||||
},
|
||||
|
||||
webvr_getBonePose: function(device, bone, position, orientation) {
|
||||
return false;
|
||||
},
|
||||
|
||||
webvr_getVelocity: function(device, velocity, angularVelocity) {
|
||||
var pose = webvr.poses[device];
|
||||
if (!pose) { return false; }
|
||||
|
|
Loading…
Reference in New Issue