From e3d8fa809414d41da668585d85c7a1955e97f564 Mon Sep 17 00:00:00 2001 From: jrhodnik Date: Thu, 6 Jun 2019 19:46:30 -0400 Subject: [PATCH] First commit for sending out to Reddit testers. --- VRDash/Overlay/BrowserOverlay.xaml.cs | 10 +- VRDash/Overlay/Config/BrowserOverlayConfig.cs | 24 ++++ .../OverlayLocation/ControllerLocation.cs | 6 +- .../OverlayLocation/PlayspaceLocation.cs | 124 ++++++++++++++++++ VRDash/UI/BrowserOverlayEditor.xaml | 13 +- VRDash/Utilities/OpenTKExtensions.cs | 2 +- 6 files changed, 170 insertions(+), 9 deletions(-) create mode 100644 VRDash/Overlay/Config/OverlayLocation/PlayspaceLocation.cs diff --git a/VRDash/Overlay/BrowserOverlay.xaml.cs b/VRDash/Overlay/BrowserOverlay.xaml.cs index 1264ce3..52f3d97 100644 --- a/VRDash/Overlay/BrowserOverlay.xaml.cs +++ b/VRDash/Overlay/BrowserOverlay.xaml.cs @@ -54,7 +54,15 @@ namespace VRDash.Overlay Config = config; InitializeComponent(); this.Show(); - + Width = Config.Width; + Height = Config.Height; + Config.SizeUpdated += Config_SizeUpdated; + } + + private void Config_SizeUpdated(object sender, EventArgs e) + { + Width = Config.Width; + Height = Config.Height; } Factory1 m_Factory = null; diff --git a/VRDash/Overlay/Config/BrowserOverlayConfig.cs b/VRDash/Overlay/Config/BrowserOverlayConfig.cs index 1364e3c..3f1c3c7 100644 --- a/VRDash/Overlay/Config/BrowserOverlayConfig.cs +++ b/VRDash/Overlay/Config/BrowserOverlayConfig.cs @@ -16,6 +16,30 @@ namespace VRDash.Overlay.Config public string Content { get; set; } public BrowserOverlayContentType ContentType { get; set; } + public event EventHandler SizeUpdated; + + private int m_Width = 600; + public int Width + { + get { return m_Width; } + set + { + m_Width = value; + SizeUpdated?.Invoke(this, null); + } + } + + private int m_Height = 600; + public int Height + { + get { return m_Height; } + set + { + m_Height = value; + SizeUpdated?.Invoke(this, null); + } + } + public void Initialize(IOverlay overlay) { //Nothing needs to be done here diff --git a/VRDash/Overlay/Config/OverlayLocation/ControllerLocation.cs b/VRDash/Overlay/Config/OverlayLocation/ControllerLocation.cs index 358079f..e1d84fb 100644 --- a/VRDash/Overlay/Config/OverlayLocation/ControllerLocation.cs +++ b/VRDash/Overlay/Config/OverlayLocation/ControllerLocation.cs @@ -70,11 +70,7 @@ namespace VRDash.Overlay.Config.OverlayLocation 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); + if (m_Overlay.OverlayHandle == OpenVR.k_ulOverlayHandleInvalid) { return; } diff --git a/VRDash/Overlay/Config/OverlayLocation/PlayspaceLocation.cs b/VRDash/Overlay/Config/OverlayLocation/PlayspaceLocation.cs new file mode 100644 index 0000000..6412667 --- /dev/null +++ b/VRDash/Overlay/Config/OverlayLocation/PlayspaceLocation.cs @@ -0,0 +1,124 @@ +//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("Playspace", typeof(ControllerLocationEditor))] +// public class PlayspaceLocation : IOverlayLocation +// { +// public ControllerHand Controller { get; 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)); + +// 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; + +// DateTime m_LastCheck = DateTime.MinValue; + +// IOverlay m_Overlay = null; + +// public OverlayHandles CreateOverlay(string key, string name, IOverlay overlay) +// { +// ulong overlayHandle = 0; +// EVROverlayError err = OpenVR.Overlay.CreateOverlay(key, name, ref overlayHandle); + +// if (err != EVROverlayError.None){ +// throw new Exception($"Error creating overlay: {err}"); +// } + +// ETrackedDeviceClass type = OpenVR.System.GetTrackedDeviceClass(0); + +// overlay.Update += Overlay_Update; + +// m_Overlay = overlay; + + +// return new OverlayHandles(overlayHandle, 0); +// } + +// public void SetLocationBasedOnController() +// { +// uint controllerIndex = OpenVR.System.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.LeftHand); + +// TrackedDevicePose_t pose = new TrackedDevicePose_t(); +// TrackedDevicePose_t gamePose = new TrackedDevicePose_t(); +// var err = OpenVR.Compositor.GetLastPoseForTrackedDeviceIndex(controllerIndex, ref pose, ref gamePose); +// if(err != EVRCompositorError.None) +// { +// this.GetLogger(m_Overlay).Warn($"Unable to set location based on controller: {err}"); +// return; +// } + +// if(pose.eTrackingResult != ETrackingResult.Running_OK) +// { +// this.GetLogger(m_Overlay).Warn($"Unable to get reliable tracking: {pose.eTrackingResult}"); +// } + +// var matrix = pose.mDeviceToAbsoluteTracking.ToOpenTKMatrix(); + +// matrix +// } + +// private void Overlay_Update(object sender, EventArgs e) +// { +// if (DateTime.Now.Subtract(m_LastCheck).TotalSeconds >= 1) +// { + +// 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))); + + +// if (m_Overlay.OverlayHandle == OpenVR.k_ulOverlayHandleInvalid) { return; } + +// var matrix = Location.ToOpenVRMatrix(); + +// var err = OpenVR.Overlay.SetOverlayTransformAbsolute(m_Overlay.OverlayHandle, ETrackingUniverseOrigin.TrackingUniverseStanding, ref matrix); + +// //var err = OpenVR.Overlay.SetOverlayTransformTrackedDeviceRelative(m_Overlay.OverlayHandle, m_ControllerIndex, ref matrix); + +// if (err != EVROverlayError.None) +// { +// this.GetLogger(m_Overlay).Warn($"Error setting tracked device relative to {Controller} hand: {err}"); +// } +// else +// { +// this.GetLogger(m_Overlay).Info($"Controller index updated."); +// } + +// m_LastCheck = DateTime.Now; +// } +// } + +// public void ResetCheckTimer() +// { +// m_LastCheck = DateTime.MinValue; +// } + +// public enum ControllerHand +// { +// Left = 0, +// Right = 1 +// } +// } +//} diff --git a/VRDash/UI/BrowserOverlayEditor.xaml b/VRDash/UI/BrowserOverlayEditor.xaml index a7a42e1..31d2c06 100644 --- a/VRDash/UI/BrowserOverlayEditor.xaml +++ b/VRDash/UI/BrowserOverlayEditor.xaml @@ -8,6 +8,7 @@ d:DesignHeight="450" d:DesignWidth="800"> + @@ -23,7 +24,15 @@ Content Type: - Content: - + Size: + + Width: + + Height: + + + + Content: + diff --git a/VRDash/Utilities/OpenTKExtensions.cs b/VRDash/Utilities/OpenTKExtensions.cs index 817ca2e..dc993c9 100644 --- a/VRDash/Utilities/OpenTKExtensions.cs +++ b/VRDash/Utilities/OpenTKExtensions.cs @@ -32,7 +32,7 @@ namespace VRDash.Utilities return newmatrix; } - public static Matrix3x4 ToOpenVRMatrix(this HmdMatrix34_t matrix) + public static Matrix3x4 ToOpenTKMatrix(this HmdMatrix34_t matrix) { Matrix3x4 newmatrix = new Matrix3x4();