#include "recording_region_depth.h" #include #include #include using namespace recording_region_depth_detail; static vr::HmdMatrix34_t pose(double yaw=0,double pitch=0,double roll=0,Point t={0,0,0}){ const double cy=cos(yaw),sy=sin(yaw),cp=cos(pitch),sp=sin(pitch),cr=cos(roll),sr=sin(roll); vr::HmdMatrix34_t m{{ {float(cy*cr+sy*sp*sr),float(-cy*sr+sy*sp*cr),float(sy*cp),float(t[0])}, {float(cp*sr),float(cp*cr),float(-sp),float(t[1])}, {float(-sy*cr+cy*sp*sr),float(sy*sr+cy*sp*cr),float(cy*cp),float(t[2])}}};return m; } static vr::HmdMatrix34_t multiply(const vr::HmdMatrix34_t& a,const vr::HmdMatrix34_t& b){ vr::HmdMatrix34_t m{};for(int i=0;i<3;i++){ for(int j=0;j<3;j++)for(int k=0;k<3;k++)m.m[i][j]+=a.m[i][k]*b.m[k][j]; m.m[i][3]=a.m[i][3];for(int k=0;k<3;k++)m.m[i][3]+=a.m[i][k]*b.m[k][3]; }return m; } static void near(double a,double b,double tolerance=1e-5){assert(std::abs(a-b)0.001); } } // Changing IPD refreshes a stale exported origin without altering ray basis. auto stale=pose(0,0,0,{0.032,0,0}); assert(recording_region_refresh_eye_origin(vr::Eye_Right,pose(0,0,0,{-0.0375,0,0}),pose(0,0,0,{0.0375,0,0}),stale)); near(stale.m[0][3],0.0375); const auto identity=pose(),left=pose(0,0,0,{-0.032,0,0}),right=pose(0,0,0,{0.032,0,0}); auto unchanged=identity; assert(!recording_region_refresh_eye_origin(vr::Eye_Right,pose(0,0,0,{-0.1,0,0}),pose(0,0,0,{0.1,0,0}),unchanged)); assert(!recording_region_refresh_eye_origin(vr::Eye_Right,right,left,unchanged)); assert(unchanged.m[0][3]==0); auto invalid=identity;invalid.m[0][0]=std::numeric_limits::quiet_NaN(); assert(!recording_region_refresh_eye_origin(vr::Eye_Right,invalid,right,unchanged)); assert(!recording_region_window_depth(invalid,pose(0,0,0,{0,0,-2}),identity,0,0)); assert(!recording_region_window_depth(vr::HmdMatrix34_t{},pose(0,0,0,{0,0,-2}),identity,0,0)); assert(!recording_region_window_depth(identity,pose(acos(-1.)/2,0,0,{0,0,-2}),identity,0,0)); for(double z:{-0.1,-8.,1.})assert(!recording_region_window_depth(identity,pose(0,0,0,{0,0,z}),identity,0,0)); assert(!recording_region_window_depth(identity,pose(0,0,0,{0,0,-2}),identity,std::numeric_limits::infinity(),0)); // Eye Z matters: head-relative depth alone would return 2, but D=2.012. const auto zdepth=recording_region_window_depth(identity,pose(0,0,0,{0,0,-2}),right,0,0); assert(zdepth);near(*zdepth,2.0); // This fixture's right eye has Z=0. const auto elevated=pose(0,0,0,{0.032,0,0.012}); const auto exact=recording_region_window_depth(identity,pose(0,0,0,{0,0,-2}),elevated,0,0); assert(exact);near(*exact,2.012); for(double depth:{0.25,0.5,1.,2.,4.,6.}){ const vr::HmdVector3_t hit{{0,0,float(-depth)}}; const auto result=recording_region_hit_depth(identity,identity,0,0,hit);assert(result);near(*result,depth); } for(const auto& hit:std::array{{{{0.02f,0,-2}},{{0,0,2}},{{0,0,-8}},{{std::numeric_limits::quiet_NaN(),0,-2}}}}) assert(!recording_region_hit_depth(identity,identity,0,0,hit)); assert(!recording_region_hit_depth(invalid,identity,0,0,vr::HmdVector3_t{{0,0,-2}})); std::cout<<"PASS: current eye origin, exact center-ray UI depth, both-eye parallax and invalid-pose guards\n"; }