Skip to content

Commit

Permalink
Merge pull request #1 from Flutterish/fixes
Browse files Browse the repository at this point in the history
Overhaul the codebase
  • Loading branch information
Flutterish authored May 22, 2022
2 parents a2919c5 + ffab087 commit be6021b
Show file tree
Hide file tree
Showing 60 changed files with 10,049 additions and 8,379 deletions.
26 changes: 19 additions & 7 deletions OpenVR.NET.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30907.101
# Visual Studio Version 17
VisualStudioVersion = 17.2.32210.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenVR.NET", "OpenVR.NET\OpenVR.NET.csproj", "{D4884028-3692-4714-AE17-0743F7A03628}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenVR.NET", "OpenVR.NET\OpenVR.NET.csproj", "{B0E89979-0436-4A4D-9195-1A5A96148057}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{B5BFC04A-389E-408C-87F5-9BA8276F127A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisualTests", "VisualTests\VisualTests.csproj", "{6C12C228-7E1D-4871-8F7E-0A81BB4D5960}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D4884028-3692-4714-AE17-0743F7A03628}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4884028-3692-4714-AE17-0743F7A03628}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4884028-3692-4714-AE17-0743F7A03628}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4884028-3692-4714-AE17-0743F7A03628}.Release|Any CPU.Build.0 = Release|Any CPU
{B0E89979-0436-4A4D-9195-1A5A96148057}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0E89979-0436-4A4D-9195-1A5A96148057}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0E89979-0436-4A4D-9195-1A5A96148057}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0E89979-0436-4A4D-9195-1A5A96148057}.Release|Any CPU.Build.0 = Release|Any CPU
{B5BFC04A-389E-408C-87F5-9BA8276F127A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5BFC04A-389E-408C-87F5-9BA8276F127A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5BFC04A-389E-408C-87F5-9BA8276F127A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5BFC04A-389E-408C-87F5-9BA8276F127A}.Release|Any CPU.Build.0 = Release|Any CPU
{6C12C228-7E1D-4871-8F7E-0A81BB4D5960}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C12C228-7E1D-4871-8F7E-0A81BB4D5960}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C12C228-7E1D-4871-8F7E-0A81BB4D5960}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C12C228-7E1D-4871-8F7E-0A81BB4D5960}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
103 changes: 103 additions & 0 deletions OpenVR.NET/Chaperone.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using SixLabors.ImageSharp.PixelFormats;
using System.Numerics;
using Valve.VR;

namespace OpenVR.NET;

/// <summary>
/// Playfeld bounds and tracking safety
/// </summary>
public interface IChaperone {
ChaperoneCalibrationState State { get; }
event Action<ChaperoneCalibrationState>? StateChanged;

/// <summary>
/// Playfield size in meters
/// </summary>
Vector2? PlayfieldSize { get; }
/// <summary>
/// Playfield bounds in meters, where (0,0) is the playfield centre
/// </summary>
(Vector2 topLeft, Vector2 topRight, Vector2 bottomLeft, Vector2 bottomRight)? PlayfieldBounds { get; }
/// <summary>
/// Hints the scene ambience to the system to better match the system-rendered parts of the scene
/// such as playfield bounds or the freeze-limbo
/// </summary>
void SetSceneColourHint ( Rgba32 colour );
/// <summary>
/// Whether the system is rendering playfield bounds
/// </summary>
bool AreBoundsVisible { get; }
/// <summary>
/// Force the system to draw playfield bounds
/// </summary>
bool ForceBoundsVisible { get; set; }
}

class Chaperone : IChaperone {
protected VR VR;
public Chaperone ( VR vr ) {
VR = vr;
}

/// <summary>
/// Update on the update thread.
/// </summary>
public void Update () {
State = Valve.VR.OpenVR.Chaperone.GetCalibrationState();
}

ChaperoneCalibrationState state = 0;
public ChaperoneCalibrationState State {
get => state;
private set {
if ( value == state )
return;

state = value;
StateChanged?.Invoke( value );
}
}

public event Action<ChaperoneCalibrationState>? StateChanged;

public Vector2? PlayfieldSize {
get {
float x = 0, z = 0;
if ( Valve.VR.OpenVR.Chaperone.GetPlayAreaSize( ref x, ref z ) )
return new( x, z );
return null;
}
}

public (Vector2 topLeft, Vector2 topRight, Vector2 bottomLeft, Vector2 bottomRight)? PlayfieldBounds {
get {
HmdQuad_t quad = default;
if ( Valve.VR.OpenVR.Chaperone.GetPlayAreaRect( ref quad ) ) {
return (
new( quad.vCorners1.v0, -quad.vCorners1.v2 ),
new( quad.vCorners0.v0, -quad.vCorners0.v2 ),
new( quad.vCorners2.v0, -quad.vCorners2.v2 ),
new( quad.vCorners3.v0, -quad.vCorners3.v2 )
);
}
return null;
}
}

public void SetSceneColourHint ( Rgba32 colour ) {
var v = colour.ToScaledVector4();
Valve.VR.OpenVR.Chaperone.SetSceneColor( new() { r = v.X, g = v.Y, b = v.Z, a = v.W } );
}

public bool AreBoundsVisible => Valve.VR.OpenVR.Chaperone.AreBoundsVisible();

bool forceBoundsVisible = false;
public bool ForceBoundsVisible {
get => forceBoundsVisible;
set {
Valve.VR.OpenVR.Chaperone.ForceBoundsVisible( value );
forceBoundsVisible = value;
}
}
}
34 changes: 0 additions & 34 deletions OpenVR.NET/Components/Component.cs

This file was deleted.

56 changes: 0 additions & 56 deletions OpenVR.NET/Components/Controller.cs

This file was deleted.

9 changes: 0 additions & 9 deletions OpenVR.NET/Components/Headset.cs

This file was deleted.

68 changes: 0 additions & 68 deletions OpenVR.NET/Components/Model.cs

This file was deleted.

Loading

0 comments on commit be6021b

Please sign in to comment.