Files

25 lines
5.7 KiB
C++

#include "../native/launcher_input.h"
#include <chrono>
#include <iostream>
#include <thread>
int main(int argc,char** argv){if(argc!=2)return 2;vr::EVRInitError error;auto* system=vr::VR_Init(&error,vr::VRApplication_Overlay);if(error){std::cerr<<"VR_Init: "<<error<<"\n";return 3;}auto* input=vr::VRInput();auto result=input->SetActionManifestPath(argv[1]);std::cout<<"manifest="<<result<<"\n";vr::VRActionSetHandle_t set=0;vr::VRActionHandle_t primary=0,upper=0,aim=0;bool ok=result==vr::VRInputError_None&&input->GetActionSetHandle("/actions/entry",&set)==vr::VRInputError_None&&input->GetActionHandle("/actions/entry/in/primary",&primary)==vr::VRInputError_None&&input->GetActionHandle("/actions/entry/in/upper",&upper)==vr::VRInputError_None&&input->GetActionHandle("/actions/entry/in/aim",&aim)==vr::VRInputError_None;
for(int i=0;i<20&&ok;i++){vr::VRActiveActionSet_t active{};active.ulActionSet=set;result=input->UpdateActionState(&active,sizeof(active),1);if(result!=vr::VRInputError_None){std::cerr<<"update="<<result<<"\n";ok=false;break;}std::this_thread::sleep_for(std::chrono::milliseconds(100));}
for(auto path:{"/user/hand/left","/user/hand/right"}){vr::VRInputValueHandle_t hand=0;input->GetInputSourceHandle(path,&hand);vr::InputDigitalActionData_t a{},b{};vr::InputPoseActionData_t pose{};auto e1=input->GetDigitalActionData(primary,&a,sizeof(a),hand),e2=input->GetDigitalActionData(upper,&b,sizeof(b),hand),e3=input->GetPoseActionDataRelativeToNow(aim,vr::TrackingUniverseStanding,0,&pose,sizeof(pose),hand);std::cout<<path<<" primary="<<e1<<"/"<<a.bActive<<" upper="<<e2<<"/"<<b.bActive<<" pose="<<e3<<"/"<<pose.bActive<<"/"<<pose.pose.bPoseIsValid<<" state="<<a.bState<<"/"<<b.bState<<"\n";
vr::VROverlayHandle_t button=0;auto* overlays=vr::VROverlay();if(!overlays->FindOverlay("framely.dock.button",&button)){
vr::VROverlayIntersectionParams_t ray{};ray.eOrigin=vr::TrackingUniverseStanding;for(int r=0;r<3;r++){ray.vSource.v[r]=pose.pose.mDeviceToAbsoluteTracking.m[r][3];ray.vDirection.v[r]=-pose.pose.mDeviceToAbsoluteTracking.m[r][2];}vr::VROverlayIntersectionResults_t hit{};bool intersects=overlays->ComputeOverlayIntersection(button,&ray,&hit);std::cout<<"dock visible="<<overlays->IsOverlayVisible(button)<<" hover="<<overlays->IsHoverTargetOverlay(button)<<" intersection="<<intersects<<" uv="<<hit.vUVs.v[0]<<","<<hit.vUVs.v[1]<<"\n";
}}
for(unsigned i=0;i<vr::k_unMaxTrackedDeviceCount;i++){if(system->GetTrackedDeviceClass(i)!=vr::TrackedDeviceClass_Controller)continue;char type[256]{};system->GetStringTrackedDeviceProperty(i,vr::Prop_ControllerType_String,type,sizeof(type));std::cout<<"controller="<<i<<" type="<<type<<"\n";}
float previousPull[2]{-1,-1};
for(int tick=0;tick<2400&&ok;tick++){
vr::VRActiveActionSet_t active{};active.ulActionSet=set;input->UpdateActionState(&active,sizeof(active),1);
if(tick%80==0){vr::TrackedDevicePose_t poses[vr::k_unMaxTrackedDeviceCount]{};system->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseStanding,0,poses,vr::k_unMaxTrackedDeviceCount);std::cout<<"tracking";for(unsigned d=0;d<3;d++)std::cout<<" "<<d<<":"<<poses[d].bDeviceIsConnected<<"/"<<poses[d].bPoseIsValid;std::cout<<std::endl;}
for(auto path:{"/user/hand/left","/user/hand/right"}){vr::VRInputValueHandle_t hand=0;input->GetInputSourceHandle(path,&hand);vr::InputDigitalActionData_t a{},b{};input->GetDigitalActionData(primary,&a,sizeof(a),hand);input->GetDigitalActionData(upper,&b,sizeof(b),hand);
auto device=system->GetTrackedDeviceIndexForControllerRole(std::string(path).find("right")!=std::string::npos?vr::TrackedControllerRole_RightHand:vr::TrackedControllerRole_LeftHand);char model[256]{};system->GetStringTrackedDeviceProperty(device,vr::Prop_RenderModelName_String,model,sizeof(model));vr::RenderModel_ControllerMode_State_t mode{};vr::RenderModel_ComponentState_t primaryState{},upperState{};bool c1=vr::VRRenderModels()->GetComponentStateForDevicePath(model,"trigger",hand,&mode,&primaryState),c2=vr::VRRenderModels()->GetComponentStateForDevicePath(model,"bumper",hand,&mode,&upperState);vr::VRControllerState_t restInput{},fullInput{};fullInput.rAxis[1].x=1;vr::RenderModel_ComponentState_t rest{},full{};float pull=-1;bool calibrated=c1&&vr::VRRenderModels()->GetComponentState(model,"trigger",&restInput,&mode,&rest)&&vr::VRRenderModels()->GetComponentState(model,"trigger",&fullInput,&mode,&full)&&entry_trigger_pull(rest,full,primaryState,pull);int side=std::string(path).find("right")!=std::string::npos?1:0;bool changed=std::abs(pull-previousPull[side])>.05f;previousPull[side]=pull;
if(tick%80==0||changed)std::cout<<path<<" components="<<c1<<"/"<<c2<<" pressed="<<bool(primaryState.uProperties&vr::VRComponentProperty_IsPressed)<<"/"<<bool(upperState.uProperties&vr::VRComponentProperty_IsPressed)<<" calibrated="<<calibrated<<" pull="<<pull<<" actions="<<a.bActive<<"/"<<b.bActive<<"\n";
if(a.bChanged||b.bChanged){vr::InputPoseActionData_t pose{};input->GetPoseActionDataRelativeToNow(aim,vr::TrackingUniverseStanding,0,&pose,sizeof(pose),hand);std::cout<<path<<" primary="<<a.bState<<" upper="<<b.bState<<" pose="<<pose.pose.bPoseIsValid;
vr::VROverlayHandle_t overlay=0;auto* overlays=vr::VROverlay();if(!overlays->FindOverlay("framely.dock.button",&overlay)){vr::VROverlayIntersectionParams_t ray{};ray.eOrigin=vr::TrackingUniverseStanding;for(int r=0;r<3;r++){ray.vSource.v[r]=pose.pose.mDeviceToAbsoluteTracking.m[r][3];ray.vDirection.v[r]=-pose.pose.mDeviceToAbsoluteTracking.m[r][2];}vr::VROverlayIntersectionResults_t hit{};bool intersects=overlays->ComputeOverlayIntersection(overlay,&ray,&hit);std::cout<<" hover="<<overlays->IsHoverTargetOverlay(overlay)<<" intersection="<<intersects<<" uv="<<hit.vUVs.v[0]<<","<<hit.vUVs.v[1];}std::cout<<std::endl;}}
std::this_thread::sleep_for(std::chrono::milliseconds(25));
}
vr::VR_Shutdown();return ok?0:4;}