1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-01-16 20:38:55 +01:00

OpenVR simple input

This commit is contained in:
XProger 2019-07-25 04:28:54 +03:00
parent 754f08d486
commit 634b27bfd9
3 changed files with 75 additions and 279 deletions

View File

@ -1,75 +0,0 @@
{
"actions" : [
{
"name" : "/actions/demo/in/Left",
"type" : "boolean"
},
{
"name" : "/actions/demo/in/Right",
"type" : "boolean"
},
{
"name" : "/actions/demo/in/Up",
"type" : "boolean"
},
{
"name" : "/actions/demo/in/Down",
"type" : "boolean"
},
{
"name" : "/actions/demo/in/Jump",
"type" : "boolean"
},
{
"name" : "/actions/demo/in/Walk",
"type" : "boolean"
},
{
"name" : "/actions/demo/in/Action",
"type" : "boolean"
},
{
"name" : "/actions/demo/in/Weapon",
"type" : "boolean"
},
{
"name" : "/actions/demo/in/Roll",
"type" : "boolean"
},
{
"name" : "/actions/demo/in/Inventory",
"type" : "boolean"
},
{
"name" : "/actions/demo/in/Start",
"type" : "boolean"
}
],
"default_bindings" : [
{
"binding_url" : "system_generated_openlara_exe_binding_holographic_controller.json",
"controller_type" : "holographic_controller"
}
],
"localization" : [
{
"/actions/demo/in/Action" : "Action",
"/actions/demo/in/AnalogInput" : "Analog Input",
"/actions/demo/in/Down" : "MoveDown",
"/actions/demo/in/Hand_Left" : "Left Hand Pose",
"/actions/demo/in/Hand_Right" : "Right Hand Pose",
"/actions/demo/in/Inventory" : "Inventory",
"/actions/demo/in/Jump" : "Jump",
"/actions/demo/in/Left" : "MoveLeft",
"/actions/demo/in/Right" : "MoveRight",
"/actions/demo/in/Roll" : "Roll",
"/actions/demo/in/Start" : "Start",
"/actions/demo/in/Up" : "MoveUp",
"/actions/demo/in/Walk" : "Walk",
"/actions/demo/in/Weapon" : "Weapon",
"/actions/demo/out/haptic_left" : "Left Haptic Feedback",
"/actions/demo/out/haptic_right" : "Right Haptic Feedback",
"language_tag" : "en_US"
}
]
}

View File

@ -1,120 +0,0 @@
{
"alias_info" : {},
"app_key" : "system.generated.openlara.exe",
"bindings" : {
"/actions/demo" : {
"sources" : [
{
"inputs" : {
"east" : {
"output" : "/actions/demo/in/right"
},
"north" : {
"output" : "/actions/demo/in/up"
},
"south" : {
"output" : "/actions/demo/in/down"
},
"west" : {
"output" : "/actions/demo/in/left"
}
},
"mode" : "dpad",
"parameters" : {
"sub_mode" : "click"
},
"path" : "/user/hand/left/input/trackpad"
},
{
"inputs" : {
"east" : {
"output" : "/actions/demo/in/right"
},
"north" : {
"output" : "/actions/demo/in/up"
},
"south" : {
"output" : "/actions/demo/in/down"
},
"west" : {
"output" : "/actions/demo/in/left"
}
},
"mode" : "dpad",
"parameters" : {
"sub_mode" : "touch"
},
"path" : "/user/hand/left/input/joystick"
},
{
"inputs" : {
"click" : {
"output" : "/actions/demo/in/jump"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/trigger"
},
{
"inputs" : {
"click" : {
"output" : "/actions/demo/in/action"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/trigger"
},
{
"inputs" : {
"click" : {
"output" : "/actions/demo/in/walk"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/grip"
},
{
"inputs" : {
"click" : {
"output" : "/actions/demo/in/weapon"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/trackpad"
},
{
"inputs" : {
"click" : {
"output" : "/actions/demo/in/start"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/application_menu"
},
{
"inputs" : {
"click" : {
"output" : "/actions/demo/in/inventory"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/application_menu"
},
{
"inputs" : {
"click" : {
"output" : "/actions/demo/in/roll"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/grip"
}
]
}
},
"controller_type" : "holographic_controller",
"description" : "",
"name" : "OpenLaraTestWMRBinding",
"options" : {},
"simulated_actions" : []
}

View File

@ -723,29 +723,6 @@ void vrInit() {
LOG("! compositor initialization failed\n");
return;
}
//set manifest
vr::VRInput()->SetActionManifestPath("C:/Users/Austin/Desktop/OpenLaraGitTest2/OpenLara/bin/TombRaidervr_actions.json"); // needs absolutepath
// get action handles
vr::VRInput()->GetActionHandle("/actions/demo/in/Left", &VRcLeft);
vr::VRInput()->GetActionHandle("/actions/demo/in/Right", &VRcRight);
vr::VRInput()->GetActionHandle("/actions/demo/in/Up", &VRcUp);
vr::VRInput()->GetActionHandle("/actions/demo/in/Down", &VRcDown);
vr::VRInput()->GetActionHandle("/actions/demo/in/Jump", &VRcJump);
vr::VRInput()->GetActionHandle("/actions/demo/in/Walk", &VRcWalk);
vr::VRInput()->GetActionHandle("/actions/demo/in/Action", &VRcAction);
vr::VRInput()->GetActionHandle("/actions/demo/in/Weapon", &VRcWeapon);
vr::VRInput()->GetActionHandle("/actions/demo/in/Roll", &VRcRoll);
vr::VRInput()->GetActionHandle("/actions/demo/in/Inventory", &VRcInventory);
vr::VRInput()->GetActionHandle("/actions/demo/in/Start", &VRcStart);
//get actionsethandle
vr::VRInput()->GetActionSetHandle("/actions/demo", &m_actionsetDemo);
//get input source handles
vr::VRInput()->GetInputSourceHandle("/user/hand/left", &m_leftHand);
vr::VRInput()->GetInputSourceHandle("/user/hand/right", &m_rightHand);
// aren't using right now
//vr::VRInput()->GetActionHandle("/actions/demo/in/TriggerHaptic", &m_actionTriggerHaptic);
//vr::VRInput()->GetActionHandle("/actions/demo/in/AnalogInput", &m_actionAnalongInput);
}
void vrInitTargets() {
@ -796,76 +773,92 @@ bool GetDigitalActionState(vr::VRActionHandle_t action, vr::VRInputValueHandle_t
return actionData.bActive && actionData.bState;
}
void ProcessVREvent(const vr::VREvent_t &event) {
char buffer[1024] = "test";
switch (event.eventType) {
case vr::VREvent_TrackedDeviceActivated:
//SetupRenderModelForTrackedDevice( event.trackedDeviceIndex );
//vr::RenderModel_t ** controllerRender;
hmd->GetStringTrackedDeviceProperty(event.trackedDeviceIndex, vr::ETrackedDeviceProperty::Prop_RenderModelName_String, buffer, 1024); // can be filled with an error,but I can't find the right type
//rm->LoadRenderModel_Async(buffer, controllerRender);
// need to process render model?
LOG("Device %u attached. Setting up render model\n", event.trackedDeviceIndex);
break;
case vr::VREvent_TrackedDeviceDeactivated:
LOG("Device %u detached.\n", event.trackedDeviceIndex);
Input::reset();
break;
case vr::VREvent_TrackedDeviceUpdated: //not sure what to do here
LOG("Device %u updated.\n", event.trackedDeviceIndex);
break;
}
}
void vrUpdateInput() {
void vrUpdate() {
if (!hmd) return;
vr::VREvent_t event;
while (hmd->PollNextEvent(&event, sizeof(event))) {
ProcessVREvent(event);
switch (event.eventType) {
case vr::VREvent_TrackedDeviceActivated:
break;
case vr::VREvent_TrackedDeviceDeactivated:
Input::reset();
break;
case vr::VREvent_TrackedDeviceUpdated:
break;
}
}
vr::VRActiveActionSet_t actionSet = { 0 };
actionSet.ulActionSet = m_actionsetDemo;
vr::VRInput()->UpdateActionState(&actionSet, sizeof(actionSet), 1);
Input::hmd.state[cUp] = GetDigitalActionState(VRcUp);
Input::hmd.state[cDown] = GetDigitalActionState(VRcDown);
Input::hmd.state[cRight] = GetDigitalActionState(VRcRight);
Input::hmd.state[cLeft] = GetDigitalActionState(VRcLeft);
Input::hmd.state[cJump] = GetDigitalActionState(VRcJump);
Input::hmd.state[cWalk] = GetDigitalActionState(VRcWalk);
Input::hmd.state[cAction] = GetDigitalActionState(VRcAction);
Input::hmd.state[cWeapon] = GetDigitalActionState(VRcWeapon);
Input::hmd.state[cRoll] = GetDigitalActionState(VRcRoll);
Input::hmd.state[cStart] = GetDigitalActionState(VRcStart);
Input::hmd.state[cInventory] = GetDigitalActionState(VRcInventory);
}
void vrUpdateView() {
if (!hmd) return;
vr::VRCompositor()->WaitGetPoses(tPose, vr::k_unMaxTrackedDeviceCount, NULL, 0);
if (!tPose[vr::k_unTrackedDeviceIndex_Hmd].bPoseIsValid)
return;
for (int id = 0; id < vr::k_unMaxTrackedDeviceCount; id++) {
vr::TrackedDevicePose_t &pose = tPose[id];
mat4 pL = convToMat4(hmd->GetProjectionMatrix(vr::Eye_Left, 8.0f, 45.0f * 1024.0f));
mat4 pR = convToMat4(hmd->GetProjectionMatrix(vr::Eye_Right, 8.0f, 45.0f * 1024.0f));
if (!pose.bPoseIsValid) {
continue;
}
mat4 head = convToMat4(tPose[vr::k_unTrackedDeviceIndex_Hmd].mDeviceToAbsoluteTracking);
if (Input::hmd.zero.x == INF)
Input::hmd.zero = head.getPos();
head.setPos(head.getPos() - Input::hmd.zero);
switch (hmd->GetTrackedDeviceClass(id)) {
case vr::TrackedDeviceClass_HMD : {
mat4 pL = convToMat4(hmd->GetProjectionMatrix(vr::Eye_Left, 8.0f, 45.0f * 1024.0f));
mat4 pR = convToMat4(hmd->GetProjectionMatrix(vr::Eye_Right, 8.0f, 45.0f * 1024.0f));
mat4 vL = head * convToMat4(hmd->GetEyeToHeadTransform(vr::Eye_Left));
mat4 vR = head * convToMat4(hmd->GetEyeToHeadTransform(vr::Eye_Right));
mat4 head = convToMat4(pose.mDeviceToAbsoluteTracking);
if (Input::hmd.zero.x == INF) {
Input::hmd.zero = head.getPos();
}
head.setPos(head.getPos() - Input::hmd.zero);
vL.setPos(vL.getPos() * ONE_METER);
vR.setPos(vR.getPos() * ONE_METER);
Input::hmd.setView(pL, pR, vL, vR);
mat4 vL = head * convToMat4(hmd->GetEyeToHeadTransform(vr::Eye_Left));
mat4 vR = head * convToMat4(hmd->GetEyeToHeadTransform(vr::Eye_Right));
Input::hmd.head = head;
vL.setPos(vL.getPos() * ONE_METER);
vR.setPos(vR.getPos() * ONE_METER);
Input::hmd.setView(pL, pR, vL, vR);
Input::hmd.head = head;
break;
}
case vr::TrackedDeviceClass_Controller : {
vr::VRControllerState_t state;
hmd->GetControllerState(id, &state, sizeof(state));
#define IS_DOWN(btn) ((state.ulButtonPressed & vr::ButtonMaskFromId(btn)) != 0)
if (!state.ulButtonPressed) {
// continue;
}
Input::setJoyDown(0, jkLeft, IS_DOWN(vr::k_EButton_DPad_Left));
Input::setJoyDown(0, jkUp, IS_DOWN(vr::k_EButton_DPad_Up));
Input::setJoyDown(0, jkRight, IS_DOWN(vr::k_EButton_DPad_Right));
Input::setJoyDown(0, jkDown, IS_DOWN(vr::k_EButton_DPad_Down));
if (IS_DOWN(vr::k_EButton_Axis0)) {
Input::setJoyPos(0, jkL, vec2(state.rAxis[0].x, -state.rAxis[0].y));
}
Input::setJoyDown(0, jkA, IS_DOWN(vr::k_EButton_Axis1) ? (state.rAxis[1].x > 0.5) : false);
Input::setJoyDown(0, jkY, IS_DOWN(vr::k_EButton_Grip));
Input::setJoyDown(0, jkX, IS_DOWN(vr::k_EButton_ApplicationMenu));
// TODO
switch (hmd->GetControllerRoleForTrackedDeviceIndex(id)) {
case vr::TrackedControllerRole_LeftHand :
// TODO
break;
case vr::TrackedControllerRole_RightHand :
// TODO
break;
default : ;
}
break;
#undef IS_DOWN
}
}
}
}
void vrCompose() {
@ -895,8 +888,7 @@ void osToggleVR(bool enable) {
Core::settings.detail.stereo = Core::Settings::STEREO_OFF;
}
void vrUpdateInput() {}
void vrUpdateView() {}
void vrUpdate() {}
void vrCompose() {}
#endif // #ifdef VR_SUPPORT
@ -975,9 +967,8 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
Core::quit();
} else {
joyUpdate();
vrUpdateInput();
vrUpdate();
if (Game::update()) {
vrUpdateView();
Game::render();
vrCompose();
Core::waitVBlank();