diff --git a/VRDash/OpenTK.dll.config b/VRDash/OpenTK.dll.config
new file mode 100644
index 0000000..7098d39
--- /dev/null
+++ b/VRDash/OpenTK.dll.config
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/VRDash/Overlay/Config/OverlayLocation/ControllerLocation.cs b/VRDash/Overlay/Config/OverlayLocation/ControllerLocation.cs
index 8ffcfa3..0348542 100644
--- a/VRDash/Overlay/Config/OverlayLocation/ControllerLocation.cs
+++ b/VRDash/Overlay/Config/OverlayLocation/ControllerLocation.cs
@@ -1,18 +1,39 @@
-using System;
+using Newtonsoft.Json;
+using OpenTK;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Valve.VR;
+using VRDash.UI.LocationEditors;
+using VRDash.Utilities;
namespace VRDash.Overlay.Config.OverlayLocation
{
+ [OverlayLocationInfo("Controller", typeof(ControllerLocationEditor))]
public class ControllerLocation : IOverlayLocation
{
public ControllerHand Controller { get; private set; } = ControllerHand.Left;
+ [JsonIgnore]
+ public Matrix3x4 Location { get; private set; } = new Matrix3x4(new Vector4(1, 0, 0, 0),
+ new Vector4(0, 1, 0, 0),
+ new Vector4(0, 0, 1, 0));
- ulong m_ControllerIndex = OpenVR.k_unTrackedDeviceIndexInvalid;
+ public float PosX { get; set; } = 0;
+ public float PosY { get; set; } = 0;
+ public float PosZ { get; set; } = 0;
+
+ public float RotP { get; set; } = 0;
+ public float RotY { get; set; } = 0;
+ public float RotR { get; set; } = 0;
+
+ public float ScaleX { get; set; } = 1;
+ public float ScaleY { get; set; } = 1;
+ public float ScaleZ { get; set; } = 1;
+
+ uint m_ControllerIndex = OpenVR.k_unTrackedDeviceIndexInvalid;
DateTime m_LastCheck = DateTime.MinValue;
IOverlay m_Overlay = null;
@@ -32,29 +53,60 @@ namespace VRDash.Overlay.Config.OverlayLocation
m_Overlay = overlay;
+
return new OverlayHandles(overlayHandle, 0);
}
private void Overlay_Update(object sender, EventArgs e)
{
//Check if handle is invalid or if we should just refresh just in case.
- if(m_ControllerIndex == OpenVR.k_unTrackedDeviceIndexInvalid || DateTime.Now.Subtract(m_LastCheck).TotalSeconds >= 10)
+ if(m_ControllerIndex == OpenVR.k_unTrackedDeviceIndexInvalid || DateTime.Now.Subtract(m_LastCheck).TotalSeconds >= 1)
{
//Get proper hand
ETrackedControllerRole role = Controller == ControllerHand.Left ? ETrackedControllerRole.LeftHand : ETrackedControllerRole.RightHand;
- var controllerIndex = OpenVR.System.GetTrackedDeviceIndexForControllerRole(role);
+ uint controllerIndex = OpenVR.System.GetTrackedDeviceIndexForControllerRole(role);
+
+ MathHelper.DegreesToRadians(RotP);
+ var quat = Quaternion.FromEulerAngles(MathHelper.DegreesToRadians(RotP), MathHelper.DegreesToRadians(RotY), MathHelper.DegreesToRadians(RotR));
+ Location = Matrix3x4.Mult(Matrix3x4.CreateTranslation(PosX, PosY, PosZ), Matrix3x4.Mult(Matrix3x4.CreateFromQuaternion(quat), Matrix3x4.CreateScale(ScaleX, ScaleY, ScaleZ)));
+
+
+ //Location = Matrix3x4.CreateTranslation(PosX, PosY, PosZ);
+ //Location = Matrix3x4.Add(Matrix3x4.CreateFromQuaternion(quat), Location);
+ //Location = Matrix3x4.Add(Matrix3x4.CreateScale(ScaleX, ScaleY, ScaleZ), Location);
+
+
//Index changed, need to update the overlay
if (controllerIndex != m_ControllerIndex)
{
m_ControllerIndex = controllerIndex;
- HmdMatrix34_t matrix = new HmdMatrix34_t();
- var err = OpenVR.Overlay.SetOverlayTransformOverlayRelative(m_Overlay.OverlayHandle, m_ControllerIndex, ref matrix);
+
+ var matrix = Location.ToOpenVRMatrix();
+
+ var err = OpenVR.Overlay.SetOverlayTransformTrackedDeviceRelative(m_Overlay.OverlayHandle, m_ControllerIndex, ref matrix);
+
if (err != EVROverlayError.None)
{
- this.GetLogger().Warn($"Error setting tracked device relative to {Controller} hand: {err}");
+ this.GetLogger().Warn($"[{m_Overlay.OverlayConfig.Name}] Error setting tracked device relative to {Controller} hand: {err}");
}
+ else
+ {
+ this.GetLogger().Info($"[{m_Overlay.OverlayConfig.Name}] Controller index updated.");
+ }
+ }
+ else
+ {
+ //Update the location
+ var matrix = Location.ToOpenVRMatrix();
+
+ var err = OpenVR.Overlay.SetOverlayTransformTrackedDeviceRelative(m_Overlay.OverlayHandle, m_ControllerIndex, ref matrix);
+
+ if (err != EVROverlayError.None)
+ {
+ this.GetLogger().Warn($"[{m_Overlay.OverlayConfig.Name}] Error setting tracked device relative to {Controller} hand: {err}");
+ }
}
m_LastCheck = DateTime.Now;
diff --git a/VRDash/Overlay/MonitorOverlay.cs b/VRDash/Overlay/MonitorOverlay.cs
index 2d361d7..a4ad782 100644
--- a/VRDash/Overlay/MonitorOverlay.cs
+++ b/VRDash/Overlay/MonitorOverlay.cs
@@ -125,10 +125,10 @@ namespace VRDash.Overlay
var overlay = OpenVR.Overlay;
Config.OverlayLocation.OverlayHandles overlayHandles = Config.Location.CreateOverlay(Config.Key, Config.Name, this);
-
m_OverlayHandle = overlayHandles.OverlayHandle;
m_ThumbnailIcon = overlayHandles.ThumbnailHandle;
+ var tempError = OpenVR.Overlay.ShowOverlay(m_OverlayHandle);
//EVROverlayError err = overlay.CreateDashboardOverlay(Config.Key, Config.Name, ref m_OverlayHandle, ref m_ThumbnailIcon);
//if (err != EVROverlayError.None)
@@ -187,14 +187,15 @@ namespace VRDash.Overlay
//#endregion
//Skip rendering if overlay isn't visible
-//#if !DEBUG
- if ((m_OverlayHandle == OpenVR.k_ulOverlayHandleInvalid) || overlay == null || (!overlay.IsOverlayVisible(m_OverlayHandle)))
+ //#if !DEBUG
+ bool isVisible = overlay.IsOverlayVisible(m_OverlayHandle);
+ if ((m_OverlayHandle == OpenVR.k_ulOverlayHandleInvalid) || overlay == null || (!isVisible))
{
Thread.Sleep(100);
CurrentFPS = 0;
continue;
}
-//#endif
+ //#endif
diff --git a/VRDash/Overlay/WindowOverlay.cs b/VRDash/Overlay/WindowOverlay.cs
index 6ee7dbc..6a17b96 100644
--- a/VRDash/Overlay/WindowOverlay.cs
+++ b/VRDash/Overlay/WindowOverlay.cs
@@ -89,7 +89,7 @@ namespace VRDash.Overlay
m_OverlayHandle = overlayHandles.OverlayHandle;
m_ThumbnailIcon = overlayHandles.ThumbnailHandle;
-
+ OpenVR.Overlay.ShowOverlay(m_OverlayHandle);
m_Running = true;
m_EventPumpTask = Task.Factory.StartNew(() => { EventPump(); });
diff --git a/VRDash/UI/LocationEditors/ControllerLocationEditor.xaml b/VRDash/UI/LocationEditors/ControllerLocationEditor.xaml
new file mode 100644
index 0000000..ba01c2c
--- /dev/null
+++ b/VRDash/UI/LocationEditors/ControllerLocationEditor.xaml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/VRDash/UI/LocationEditors/ControllerLocationEditor.xaml.cs b/VRDash/UI/LocationEditors/ControllerLocationEditor.xaml.cs
new file mode 100644
index 0000000..ce0c7f7
--- /dev/null
+++ b/VRDash/UI/LocationEditors/ControllerLocationEditor.xaml.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using VRDash.Overlay.Config.OverlayLocation;
+
+namespace VRDash.UI.LocationEditors
+{
+ ///
+ /// Interaction logic for ControllerLocationEditor.xaml
+ ///
+ public partial class ControllerLocationEditor : UserControl
+ {
+ public ControllerLocation Location { get; set; } = null;
+ public ControllerLocationEditor(ControllerLocation loction)
+ {
+ Location = loction;
+ InitializeComponent();
+ DataContext = this;
+ }
+
+ private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ Location.ResetCheckTimer();
+ }
+ }
+}
diff --git a/VRDash/UI/OverlayEditor.xaml.cs b/VRDash/UI/OverlayEditor.xaml.cs
index beedcec..1baae24 100644
--- a/VRDash/UI/OverlayEditor.xaml.cs
+++ b/VRDash/UI/OverlayEditor.xaml.cs
@@ -37,7 +37,7 @@ namespace VRDash.UI
OverlayLocationInfo locationInfo = overlayLocationAttributes.Single(x => x.OverlayLocationType == Config.Location.GetType()).Info;
if (locationInfo.LocationEditorType != null)
{
- UserControl locationEditor = (UserControl)Activator.CreateInstance(locationInfo.LocationEditorType);
+ UserControl locationEditor = (UserControl)Activator.CreateInstance(locationInfo.LocationEditorType, new object[] { Config.Location });
bdrLocationEditor.Child = locationEditor;
}
#if DEBUG
diff --git a/VRDash/Utilities/OpenTKExtensions.cs b/VRDash/Utilities/OpenTKExtensions.cs
new file mode 100644
index 0000000..817ca2e
--- /dev/null
+++ b/VRDash/Utilities/OpenTKExtensions.cs
@@ -0,0 +1,57 @@
+using OpenTK;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Valve.VR;
+
+namespace VRDash.Utilities
+{
+ public static class OpenTKExtensions
+ {
+ public static HmdMatrix34_t ToOpenVRMatrix(this Matrix3x4 matrix)
+ {
+ var newmatrix = new HmdMatrix34_t();
+
+ newmatrix.m0 = matrix.M11;
+ newmatrix.m1 = matrix.M12;
+ newmatrix.m2 = matrix.M13;
+ newmatrix.m3 = matrix.M14;
+
+ newmatrix.m4 = matrix.M21;
+ newmatrix.m5 = matrix.M22;
+ newmatrix.m6 = matrix.M23;
+ newmatrix.m7 = matrix.M24;
+
+ newmatrix.m8 = matrix.M31;
+ newmatrix.m9 = matrix.M32;
+ newmatrix.m10 = matrix.M33;
+ newmatrix.m11 = matrix.M34;
+
+ return newmatrix;
+ }
+
+ public static Matrix3x4 ToOpenVRMatrix(this HmdMatrix34_t matrix)
+ {
+ Matrix3x4 newmatrix = new Matrix3x4();
+
+ newmatrix.M11 = matrix.m0;
+ newmatrix.M12 = matrix.m1;
+ newmatrix.M13 = matrix.m2;
+ newmatrix.M14 = matrix.m3;
+
+ newmatrix.M21 = matrix.m4;
+ newmatrix.M22 = matrix.m5;
+ newmatrix.M23 = matrix.m6;
+ newmatrix.M24 = matrix.m7;
+
+ newmatrix.M31 = matrix.m8;
+ newmatrix.M32 = matrix.m9;
+ newmatrix.M33 = matrix.m10;
+ newmatrix.M34 = matrix.m11;
+
+ return newmatrix;
+ }
+ }
+}
diff --git a/VRDash/VRDash.csproj b/VRDash/VRDash.csproj
index c56478c..8c09fc4 100644
--- a/VRDash/VRDash.csproj
+++ b/VRDash/VRDash.csproj
@@ -60,6 +60,9 @@
..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll
+
+ ..\packages\OpenTK.3.0.1\lib\net20\OpenTK.dll
+
..\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll
@@ -120,6 +123,9 @@
+
+ ControllerLocationEditor.xaml
+
MonitorOverlayEditor.xaml
@@ -141,6 +147,7 @@
WindowSelectorEditor.xaml
+
@@ -166,6 +173,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
@@ -215,6 +226,7 @@
ResXFileCodeGenerator
Resources.Designer.cs
+
SettingsSingleFileGenerator
diff --git a/VRDash/packages.config b/VRDash/packages.config
index 7d3f0fd..5e2960d 100644
--- a/VRDash/packages.config
+++ b/VRDash/packages.config
@@ -3,6 +3,7 @@
+