Skip to content

Commit

Permalink
Depth adjustment key combo; WIP Convergence
Browse files Browse the repository at this point in the history
  • Loading branch information
oneup03 committed Jun 11, 2024
1 parent e8ed33c commit a5c3e84
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 35 deletions.
30 changes: 30 additions & 0 deletions vrto3d/room_setup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <openvr.h>
#include "driverlog.h"

void SetStandingPose(float userHeight) {
vr::IVRChaperoneSetup* chaperoneSetup = vr::VRChaperoneSetup();

if (!chaperoneSetup) {
DriverLog("Unable to get ChaperoneSetup interface.");
return;
}

// Define the standing center matrix (4x4 identity matrix with translation for user height)
vr::HmdMatrix34_t standingCenter = {
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, userHeight,
0.0f, 0.0f, 1.0f, 0.0f
};

// Set the working standing zero pose to the new height
chaperoneSetup->SetWorkingStandingZeroPoseToRawTrackingPose(&standingCenter);

// Commit the changes
bool success = chaperoneSetup->CommitWorkingCopy(vr::EChaperoneConfigFile_Live);
if (!success) {
DriverLog("Failed to commit Chaperone setup.");
}
else {
DriverLog("Standing pose set to user height: ", userHeight, " meters.");
}
}
5 changes: 0 additions & 5 deletions vrto3d/src/device_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ bool MyDeviceProvider::ShouldBlockStandbyMode()
//-----------------------------------------------------------------------------
void MyDeviceProvider::RunFrame()
{
// call our devices to run a frame
if (my_hmd_device_ != nullptr)
{
my_hmd_device_->MyRunFrame();
}
}

//-----------------------------------------------------------------------------
Expand Down
103 changes: 74 additions & 29 deletions vrto3d/src/hmd_device_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <sstream>
#include <ctime>
#include <iomanip>
#include <windows.h>

// Load settings from default.vrsettings
static const char *stereo_main_settings_section = "driver_vrto3d";
Expand Down Expand Up @@ -212,6 +213,7 @@ void MockControllerDeviceDriver::DebugRequest( const char *pchRequest, char *pch
pchResponseBuffer[ 0 ] = 0;
}


//-----------------------------------------------------------------------------
// Purpose: Center position for Stereo 3D
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -243,18 +245,26 @@ void MockControllerDeviceDriver::PoseUpdateThread()
{
// Inform the vrserver that our tracked device's pose has updated, giving it the pose returned by our GetPose().
vr::VRServerDriverHost()->TrackedDevicePoseUpdated( device_index_, GetPose(), sizeof( vr::DriverPose_t ) );

// Ctrl+F3 Decrease Depth
if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) && (GetAsyncKeyState(VK_F3) & 0x8000)) {
stereo_display_component_->AdjustDepth(-0.001f, device_index_);
}
// Ctrl+F4 Increase Depth
if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) && (GetAsyncKeyState(VK_F4) & 0x8000)) {
stereo_display_component_->AdjustDepth(0.001f, device_index_);
}
// Ctrl+F5 Decrease Convergence
if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) && (GetAsyncKeyState(VK_F5) & 0x8000)) {
stereo_display_component_->AdjustConvergence(-0.001f);
}
// Ctrl+F6 Increase Convergence
if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) && (GetAsyncKeyState(VK_F6) & 0x8000)) {
stereo_display_component_->AdjustConvergence(0.001f);
}

vr::PropertyContainerHandle_t container = vr::VRProperties()->TrackedDeviceToPropertyContainer(device_index_);
//vr::VRProperties()->SetFloatProperty(container, vr::Prop_UserIpdMeters_Float, sin(frame_number_ * 0.01) * 0.1f + 1.0f);

//vr::VRProperties()->SetFloatProperty(container, vr::Prop_UserHeadToEyeDepthMeters_Float, sin(frame_number_ * 0.01) * 0.1f + 1.0f);


//vr::VRSettings()->SetFloat(vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_WorldScale_Float, sin(frame_number_ * 0.1) * 1.0f + 1.0f);

// Update our pose every five milliseconds.
// In reality, you should update the pose whenever you have new data from your device.
std::this_thread::sleep_for( std::chrono::milliseconds( 5 ) );
// Update our pose every 30 milliseconds.
std::this_thread::sleep_for( std::chrono::milliseconds( 30 ) );
}
}

Expand All @@ -276,30 +286,20 @@ void MockControllerDeviceDriver::Deactivate()
pose_update_thread_.join();
}

vr::VRSettings()->SetFloat(stereo_display_settings_section, "depth", stereo_display_component_.get()->GetDepth());
vr::VRSettings()->SetFloat(stereo_display_settings_section, "convergence", stereo_display_component_.get()->GetConvergence());

// unassign our controller index (we don't want to be calling vrserver anymore after Deactivate() has been called
device_index_ = vr::k_unTrackedDeviceIndexInvalid;
}


//-----------------------------------------------------------------------------
// Purpose: This is called by our IServerTrackedDeviceProvider when its RunFrame() method gets called.
// It's not part of the ITrackedDeviceServerDriver interface, we created it ourselves.
//-----------------------------------------------------------------------------
void MockControllerDeviceDriver::MyRunFrame()
{
frame_number_++;


// update our inputs here
}


//-----------------------------------------------------------------------------
// DISPLAY DRIVER METHOD DEFINITIONS
//-----------------------------------------------------------------------------

StereoDisplayComponent::StereoDisplayComponent( const StereoDisplayDriverConfiguration &config )
: config_( config )
: config_( config ), depth_(config.depth), convergence_(config.convergence)
{
}

Expand Down Expand Up @@ -385,18 +385,21 @@ void StereoDisplayComponent::GetProjectionRaw( vr::EVREye eEye, float *pfLeft, f
// Calculate the vertical FOV in radians
float verFovRadians = tan(atan(horFovRadians / config_.aspect_ratio));

// Get convergence value
float convergence = GetConvergence();

// Calculate the raw projection values
*pfTop = -verFovRadians;
*pfBottom = verFovRadians;

// Adjust the frustum based on the eye
if (eEye == vr::Eye_Left) {
*pfLeft = -horFovRadians + config_.convergence;
*pfRight = horFovRadians + config_.convergence;
*pfLeft = -horFovRadians + convergence;
*pfRight = horFovRadians + convergence;
}
else {
*pfLeft = -horFovRadians - config_.convergence;
*pfRight = horFovRadians - config_.convergence;
*pfLeft = -horFovRadians - convergence;
*pfRight = horFovRadians - convergence;
}
}

Expand Down Expand Up @@ -437,3 +440,45 @@ StereoDisplayDriverConfiguration StereoDisplayComponent::GetConfig()
{
return config_;
}


//-----------------------------------------------------------------------------
// Purpose: To update the Depth value
//-----------------------------------------------------------------------------
void StereoDisplayComponent::AdjustDepth(float delta, uint32_t device_index)
{
float cur_depth = GetDepth();
float new_depth = cur_depth + delta;
while (!depth_.compare_exchange_weak(cur_depth, new_depth, std::memory_order_relaxed));
vr::PropertyContainerHandle_t container = vr::VRProperties()->TrackedDeviceToPropertyContainer(device_index);
vr::VRProperties()->SetFloatProperty(container, vr::Prop_UserIpdMeters_Float, new_depth);
}


//-----------------------------------------------------------------------------
// Purpose: To update the Convergence value
//-----------------------------------------------------------------------------
void StereoDisplayComponent::AdjustConvergence(float delta)
{
float cur_conv = GetConvergence();
float new_conv = cur_conv + delta;
while (!convergence_.compare_exchange_weak(cur_conv, new_conv, std::memory_order_relaxed));
}


//-----------------------------------------------------------------------------
// Purpose: Get Depth value
//-----------------------------------------------------------------------------
float StereoDisplayComponent::GetDepth()
{
return depth_.load(std::memory_order_relaxed);
}


//-----------------------------------------------------------------------------
// Purpose: Get Convergence value
//-----------------------------------------------------------------------------
float StereoDisplayComponent::GetConvergence()
{
return convergence_.load(std::memory_order_relaxed);
}
7 changes: 6 additions & 1 deletion vrto3d/src/hmd_device_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ class StereoDisplayComponent : public vr::IVRDisplayComponent
bool ComputeInverseDistortion(vr::HmdVector2_t* pResult, vr::EVREye eEye, uint32_t unChannel, float fU, float fV) override;
void GetWindowBounds( int32_t *pnX, int32_t *pnY, uint32_t *pnWidth, uint32_t *pnHeight ) override;
StereoDisplayDriverConfiguration GetConfig();
void AdjustDepth(float delta, uint32_t device_index);
void AdjustConvergence(float delta);
float GetDepth();
float GetConvergence();

private:
StereoDisplayDriverConfiguration config_;
std::atomic< float > depth_;
std::atomic< float > convergence_;
};

//-----------------------------------------------------------------------------
Expand All @@ -76,7 +82,6 @@ class MockControllerDeviceDriver : public vr::ITrackedDeviceServerDriver
vr::DriverPose_t GetPose() override;
void Deactivate() override;

void MyRunFrame();
void PoseUpdateThread();

private:
Expand Down

0 comments on commit a5c3e84

Please sign in to comment.