From 2179625b3b6efeb5b81190d9949b2e09a716932a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 5 Jun 2017 18:09:08 +1000 Subject: [PATCH 1/7] Directly expose the xyz and w fields of Quarternion and Quaterniond This addresses github issue #501. They replace the Xyz and W properties, which breaks backwards binary compatibility. --- src/OpenTK/Math/Quaternion.cs | 82 ++++++++++++++++------------------ src/OpenTK/Math/Quaterniond.cs | 81 ++++++++++++++++----------------- 2 files changed, 78 insertions(+), 85 deletions(-) diff --git a/src/OpenTK/Math/Quaternion.cs b/src/OpenTK/Math/Quaternion.cs index 9f6f724a..14bb5089 100644 --- a/src/OpenTK/Math/Quaternion.cs +++ b/src/OpenTK/Math/Quaternion.cs @@ -38,8 +38,15 @@ namespace OpenTK { #region Fields - Vector3 xyz; - float w; + /// + /// The X, Y and Z components of this instance. + /// + public Vector3 Xyz; + + /// + /// The W component of this instance. + /// + public float W; #endregion @@ -52,8 +59,8 @@ namespace OpenTK /// The w part public Quaternion(Vector3 v, float w) { - this.xyz = v; - this.w = w; + Xyz = v; + W = w; } /// @@ -86,10 +93,10 @@ namespace OpenTK float s2 = (float)Math.Sin(pitch); float s3 = (float)Math.Sin(roll); - this.w = c1 * c2 * c3 - s1 * s2 * s3; - this.xyz.X = s1 * s2 * c3 + c1 * c2 * s3; - this.xyz.Y = s1 * c2 * c3 + c1 * s2 * s3; - this.xyz.Z = c1 * s2 * c3 - s1 * c2 * s3; + W = c1 * c2 * c3 - s1 * s2 * s3; + Xyz.X = s1 * s2 * c3 + c1 * c2 * s3; + Xyz.Y = s1 * c2 * c3 + c1 * s2 * s3; + Xyz.Z = c1 * s2 * c3 - s1 * c2 * s3; } /// @@ -117,36 +124,25 @@ namespace OpenTK [CLSCompliant(false)] public Vector3 XYZ { get { return Xyz; } set { Xyz = value; } } - /// - /// Gets or sets an OpenTK.Vector3 with the X, Y and Z components of this instance. - /// - [CLSCompliant(false)] - public Vector3 Xyz { get { return xyz; } set { xyz = value; } } - #pragma warning restore 3005 /// /// Gets or sets the X component of this instance. /// [XmlIgnore] - public float X { get { return xyz.X; } set { xyz.X = value; } } + public float X { get { return Xyz.X; } set { Xyz.X = value; } } /// /// Gets or sets the Y component of this instance. /// [XmlIgnore] - public float Y { get { return xyz.Y; } set { xyz.Y = value; } } + public float Y { get { return Xyz.Y; } set { Xyz.Y = value; } } /// /// Gets or sets the Z component of this instance. /// [XmlIgnore] - public float Z { get { return xyz.Z; } set { xyz.Z = value; } } - - /// - /// Gets or sets the W component of this instance. - /// - public float W { get { return w; } set { w = value; } } + public float Z { get { return Xyz.Z; } set { Xyz.Z = value; } } #endregion @@ -583,10 +579,10 @@ namespace OpenTK float s2 = (float)Math.Sin(eulerAngles.X * 0.5f); float s3 = (float)Math.Sin(eulerAngles.Z * 0.5f); - result.w = c1 * c2 * c3 - s1 * s2 * s3; - result.xyz.X = s1 * s2 * c3 + c1 * c2 * s3; - result.xyz.Y = s1 * c2 * c3 + c1 * s2 * s3; - result.xyz.Z = c1 * s2 * c3 - s1 * c2 * s3; + result.W = c1 * c2 * c3 - s1 * s2 * s3; + result.Xyz.X = s1 * s2 * c3 + c1 * c2 * s3; + result.Xyz.Y = s1 * c2 * c3 + c1 * s2 * s3; + result.Xyz.Z = c1 * s2 * c3 - s1 * c2 * s3; } #endregion @@ -619,10 +615,10 @@ namespace OpenTK float s = (float)Math.Sqrt(trace + 1) * 2; float invS = 1f / s; - result.w = s * 0.25f; - result.xyz.X = (matrix.Row2.Y - matrix.Row1.Z) * invS; - result.xyz.Y = (matrix.Row0.Z - matrix.Row2.X) * invS; - result.xyz.Z = (matrix.Row1.X - matrix.Row0.Y) * invS; + result.W = s * 0.25f; + result.Xyz.X = (matrix.Row2.Y - matrix.Row1.Z) * invS; + result.Xyz.Y = (matrix.Row0.Z - matrix.Row2.X) * invS; + result.Xyz.Z = (matrix.Row1.X - matrix.Row0.Y) * invS; } else { @@ -633,30 +629,30 @@ namespace OpenTK float s = (float)Math.Sqrt(1 + m00 - m11 - m22) * 2; float invS = 1f / s; - result.w = (matrix.Row2.Y - matrix.Row1.Z) * invS; - result.xyz.X = s * 0.25f; - result.xyz.Y = (matrix.Row0.Y + matrix.Row1.X) * invS; - result.xyz.Z = (matrix.Row0.Z + matrix.Row2.X) * invS; + result.W = (matrix.Row2.Y - matrix.Row1.Z) * invS; + result.Xyz.X = s * 0.25f; + result.Xyz.Y = (matrix.Row0.Y + matrix.Row1.X) * invS; + result.Xyz.Z = (matrix.Row0.Z + matrix.Row2.X) * invS; } else if (m11 > m22) { float s = (float)Math.Sqrt(1 + m11 - m00 - m22) * 2; float invS = 1f / s; - result.w = (matrix.Row0.Z - matrix.Row2.X) * invS; - result.xyz.X = (matrix.Row0.Y + matrix.Row1.X) * invS; - result.xyz.Y = s * 0.25f; - result.xyz.Z = (matrix.Row1.Z + matrix.Row2.Y) * invS; + result.W = (matrix.Row0.Z - matrix.Row2.X) * invS; + result.Xyz.X = (matrix.Row0.Y + matrix.Row1.X) * invS; + result.Xyz.Y = s * 0.25f; + result.Xyz.Z = (matrix.Row1.Z + matrix.Row2.Y) * invS; } else { float s = (float)Math.Sqrt(1 + m22 - m00 - m11) * 2; float invS = 1f / s; - result.w = (matrix.Row1.X - matrix.Row0.Y) * invS; - result.xyz.X = (matrix.Row0.Z + matrix.Row2.X) * invS; - result.xyz.Y = (matrix.Row1.Z + matrix.Row2.Y) * invS; - result.xyz.Z = s * 0.25f; + result.W = (matrix.Row1.X - matrix.Row0.Y) * invS; + result.Xyz.X = (matrix.Row0.Z + matrix.Row2.X) * invS; + result.Xyz.Y = (matrix.Row1.Z + matrix.Row2.Y) * invS; + result.Xyz.Z = s * 0.25f; } } } @@ -859,7 +855,7 @@ namespace OpenTK { unchecked { - return (this.xyz.GetHashCode() * 397) ^ this.w.GetHashCode(); + return (this.Xyz.GetHashCode() * 397) ^ this.W.GetHashCode(); } } diff --git a/src/OpenTK/Math/Quaterniond.cs b/src/OpenTK/Math/Quaterniond.cs index de3160d2..08636e23 100644 --- a/src/OpenTK/Math/Quaterniond.cs +++ b/src/OpenTK/Math/Quaterniond.cs @@ -38,8 +38,15 @@ namespace OpenTK { #region Fields - Vector3d xyz; - double w; + /// + /// The X, Y and Z components of this instance. + /// + public Vector3d Xyz; + + /// + /// The W component of this instance. + /// + public double W; #endregion @@ -52,8 +59,8 @@ namespace OpenTK /// The w part public Quaterniond(Vector3d v, double w) { - this.xyz = v; - this.w = w; + Xyz = v; + W = w; } /// @@ -86,10 +93,10 @@ namespace OpenTK double s2 = Math.Sin(pitch); double s3 = Math.Sin(roll); - this.w = c1 * c2 * c3 - s1 * s2 * s3; - this.xyz.X = s1 * s2 * c3 + c1 * c2 * s3; - this.xyz.Y = s1 * c2 * c3 + c1 * s2 * s3; - this.xyz.Z = c1 * s2 * c3 - s1 * c2 * s3; + W = c1 * c2 * c3 - s1 * s2 * s3; + Xyz.X = s1 * s2 * c3 + c1 * c2 * s3; + Xyz.Y = s1 * c2 * c3 + c1 * s2 * s3; + Xyz.Z = c1 * s2 * c3 - s1 * c2 * s3; } /// @@ -117,35 +124,25 @@ namespace OpenTK [XmlIgnore] public Vector3d XYZ { get { return Xyz; } set { Xyz = value; } } - /// - /// Gets or sets an OpenTK.Vector3d with the X, Y and Z components of this instance. - /// - public Vector3d Xyz { get { return xyz; } set { xyz = value; } } - #pragma warning restore 3005 /// /// Gets or sets the X component of this instance. /// [XmlIgnore] - public double X { get { return xyz.X; } set { xyz.X = value; } } + public double X { get { return Xyz.X; } set { Xyz.X = value; } } /// /// Gets or sets the Y component of this instance. /// [XmlIgnore] - public double Y { get { return xyz.Y; } set { xyz.Y = value; } } + public double Y { get { return Xyz.Y; } set { Xyz.Y = value; } } /// /// Gets or sets the Z component of this instance. /// [XmlIgnore] - public double Z { get { return xyz.Z; } set { xyz.Z = value; } } - - /// - /// Gets or sets the W component of this instance. - /// - public double W { get { return w; } set { w = value; } } + public double Z { get { return Xyz.Z; } set { Xyz.Z = value; } } #endregion @@ -582,10 +579,10 @@ namespace OpenTK double s2 = Math.Sin(eulerAngles.X * 0.5); double s3 = Math.Sin(eulerAngles.Z * 0.5); - result.w = c1 * c2 * c3 - s1 * s2 * s3; - result.xyz.X = s1 * s2 * c3 + c1 * c2 * s3; - result.xyz.Y = s1 * c2 * c3 + c1 * s2 * s3; - result.xyz.Z = c1 * s2 * c3 - s1 * c2 * s3; + result.W = c1 * c2 * c3 - s1 * s2 * s3; + result.Xyz.X = s1 * s2 * c3 + c1 * c2 * s3; + result.Xyz.Y = s1 * c2 * c3 + c1 * s2 * s3; + result.Xyz.Z = c1 * s2 * c3 - s1 * c2 * s3; } #endregion @@ -618,10 +615,10 @@ namespace OpenTK double s = Math.Sqrt(trace + 1) * 2; double invS = 1.0 / s; - result.w = s * 0.25; - result.xyz.X = (matrix.Row2.Y - matrix.Row1.Z) * invS; - result.xyz.Y = (matrix.Row0.Z - matrix.Row2.X) * invS; - result.xyz.Z = (matrix.Row1.X - matrix.Row0.Y) * invS; + result.W = s * 0.25; + result.Xyz.X = (matrix.Row2.Y - matrix.Row1.Z) * invS; + result.Xyz.Y = (matrix.Row0.Z - matrix.Row2.X) * invS; + result.Xyz.Z = (matrix.Row1.X - matrix.Row0.Y) * invS; } else { @@ -632,30 +629,30 @@ namespace OpenTK double s = Math.Sqrt(1 + m00 - m11 - m22) * 2; double invS = 1.0 / s; - result.w = (matrix.Row2.Y - matrix.Row1.Z) * invS; - result.xyz.X = s * 0.25; - result.xyz.Y = (matrix.Row0.Y + matrix.Row1.X) * invS; - result.xyz.Z = (matrix.Row0.Z + matrix.Row2.X) * invS; + result.W = (matrix.Row2.Y - matrix.Row1.Z) * invS; + result.Xyz.X = s * 0.25; + result.Xyz.Y = (matrix.Row0.Y + matrix.Row1.X) * invS; + result.Xyz.Z = (matrix.Row0.Z + matrix.Row2.X) * invS; } else if (m11 > m22) { double s = Math.Sqrt(1 + m11 - m00 - m22) * 2; double invS = 1.0 / s; - result.w = (matrix.Row0.Z - matrix.Row2.X) * invS; - result.xyz.X = (matrix.Row0.Y + matrix.Row1.X) * invS; - result.xyz.Y = s * 0.25; - result.xyz.Z = (matrix.Row1.Z + matrix.Row2.Y) * invS; + result.W = (matrix.Row0.Z - matrix.Row2.X) * invS; + result.Xyz.X = (matrix.Row0.Y + matrix.Row1.X) * invS; + result.Xyz.Y = s * 0.25; + result.Xyz.Z = (matrix.Row1.Z + matrix.Row2.Y) * invS; } else { double s = Math.Sqrt(1 + m22 - m00 - m11) * 2; double invS = 1.0 / s; - result.w = (matrix.Row1.X - matrix.Row0.Y) * invS; - result.xyz.X = (matrix.Row0.Z + matrix.Row2.X) * invS; - result.xyz.Y = (matrix.Row1.Z + matrix.Row2.Y) * invS; - result.xyz.Z = s * 0.25; + result.W = (matrix.Row1.X - matrix.Row0.Y) * invS; + result.Xyz.X = (matrix.Row0.Z + matrix.Row2.X) * invS; + result.Xyz.Y = (matrix.Row1.Z + matrix.Row2.Y) * invS; + result.Xyz.Z = s * 0.25; } } } @@ -859,7 +856,7 @@ namespace OpenTK { unchecked { - return (this.xyz.GetHashCode() * 397) ^ this.w.GetHashCode(); + return (this.Xyz.GetHashCode() * 397) ^ this.W.GetHashCode(); } } From 9ef456bf9a9ae61e66559ce79927605fb7fe3fdc Mon Sep 17 00:00:00 2001 From: varon Date: Mon, 12 Jun 2017 00:19:39 +0200 Subject: [PATCH 2/7] Fix duplicate scroll input on windows 10 --- src/OpenTK/Platform/Windows/WinGLNative.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/OpenTK/Platform/Windows/WinGLNative.cs b/src/OpenTK/Platform/Windows/WinGLNative.cs index f486d896..df106aa2 100644 --- a/src/OpenTK/Platform/Windows/WinGLNative.cs +++ b/src/OpenTK/Platform/Windows/WinGLNative.cs @@ -97,6 +97,9 @@ namespace OpenTK.Platform.Windows IntPtr cursor_handle = Functions.LoadCursor(CursorName.Arrow); int cursor_visible_count = 0; + // tracking for w10 duplicate scroll inputs. + IntPtr scrollHandle; + static readonly object SyncRoot = new object(); #endregion @@ -534,7 +537,12 @@ namespace OpenTK.Platform.Windows { // This is due to inconsistent behavior of the WParam value on 64bit arch, whese // wparam = 0xffffffffff880000 or wparam = 0x00000000ff100000 - OnMouseWheel(0, ((long)wParam << 32 >> 48) / 120.0f); + if (scrollHandle == IntPtr.Zero) { + scrollHandle = handle; + } + if (handle == scrollHandle) { + OnMouseWheel(0, ((long)wParam << 32 >> 48) / 120.0f); + } } void HandleMouseHWheel(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) From 45d032da52c58c96f08cff42b9332832a0d70b6a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 12 Jun 2017 09:10:09 +1000 Subject: [PATCH 3/7] Fix a nameof() using wrong variable in GeneratedVariableIdentifier --- src/Generator.Rewrite/GeneratedVariableIdentifier.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generator.Rewrite/GeneratedVariableIdentifier.cs b/src/Generator.Rewrite/GeneratedVariableIdentifier.cs index ec3389e5..f8bbe332 100644 --- a/src/Generator.Rewrite/GeneratedVariableIdentifier.cs +++ b/src/Generator.Rewrite/GeneratedVariableIdentifier.cs @@ -40,7 +40,7 @@ namespace OpenTK.Rewrite if (definition == null) { - throw new ArgumentException("The definition argument cannot be null.", nameof(body)); + throw new ArgumentException("The definition argument cannot be null.", nameof(definition)); } if (string.IsNullOrEmpty(name)) @@ -53,4 +53,4 @@ namespace OpenTK.Rewrite this.Name = name; } } -} \ No newline at end of file +} From 2865cd8f451f5df4d2b6d92efa9c001a4a58e502 Mon Sep 17 00:00:00 2001 From: varon Date: Mon, 12 Jun 2017 01:14:07 +0200 Subject: [PATCH 4/7] Add pdb to nuget package --- src/OpenTK/OpenTK.csproj.paket.template | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenTK/OpenTK.csproj.paket.template b/src/OpenTK/OpenTK.csproj.paket.template index 3d26a796..bc216381 100644 --- a/src/OpenTK/OpenTK.csproj.paket.template +++ b/src/OpenTK/OpenTK.csproj.paket.template @@ -23,3 +23,4 @@ description OpenTK provides several utility libraries, including a math/linear algebra package, a windowing system, and input handling. files OpenTK.dll.config => content/ + ../../bin/OpenTK/OpenTK.pdb => lib/net20/ From d5b43fb33c00bd6034c3b2e92f1c8cc64bd7a298 Mon Sep 17 00:00:00 2001 From: David Jeske Date: Sun, 11 Jun 2017 18:36:32 -0700 Subject: [PATCH 5/7] treat MouseMove events as handled by returning zero instead of calling DefWindowProc --- src/OpenTK/Platform/Windows/WinGLNative.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTK/Platform/Windows/WinGLNative.cs b/src/OpenTK/Platform/Windows/WinGLNative.cs index f486d896..ef437d3c 100644 --- a/src/OpenTK/Platform/Windows/WinGLNative.cs +++ b/src/OpenTK/Platform/Windows/WinGLNative.cs @@ -747,11 +747,11 @@ namespace OpenTK.Platform.Windows case WindowMessage.MOUSEWHEEL: HandleMouseWheel(handle, message, wParam, lParam); - break; + return IntPtr.Zero; case WindowMessage.MOUSEHWHEEL: HandleMouseHWheel(handle, message, wParam, lParam); - break; + return IntPtr.Zero; case WindowMessage.LBUTTONDOWN: HandleLButtonDown(handle, message, wParam, lParam); From 3bbd31d66b1f34c4f19846484e0c62748350950d Mon Sep 17 00:00:00 2001 From: David Jeske Date: Sun, 11 Jun 2017 19:09:50 -0700 Subject: [PATCH 6/7] Fix SetCapture() to use child_window instead of window. As using window was causing spurious WM_MOUSELEAVE events. Also change other mouse events to return IntPtr.Zero when handled --- src/OpenTK/Platform/Windows/WinGLNative.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/OpenTK/Platform/Windows/WinGLNative.cs b/src/OpenTK/Platform/Windows/WinGLNative.cs index ef437d3c..234c68ac 100644 --- a/src/OpenTK/Platform/Windows/WinGLNative.cs +++ b/src/OpenTK/Platform/Windows/WinGLNative.cs @@ -755,35 +755,35 @@ namespace OpenTK.Platform.Windows case WindowMessage.LBUTTONDOWN: HandleLButtonDown(handle, message, wParam, lParam); - break; + return IntPtr.Zero; case WindowMessage.MBUTTONDOWN: HandleMButtonDown(handle, message, wParam, lParam); - break; + return IntPtr.Zero; case WindowMessage.RBUTTONDOWN: HandleRButtonDown(handle, message, wParam, lParam); - break; + return IntPtr.Zero; case WindowMessage.XBUTTONDOWN: HandleXButtonDown(handle, message, wParam, lParam); - break; + return IntPtr.Zero; case WindowMessage.LBUTTONUP: HandleLButtonUp(handle, message, wParam, lParam); - break; + return IntPtr.Zero; case WindowMessage.MBUTTONUP: HandleMButtonUp(handle, message, wParam, lParam); - break; + return IntPtr.Zero; case WindowMessage.RBUTTONUP: HandleRButtonUp(handle, message, wParam, lParam); - break; + return IntPtr.Zero; case WindowMessage.XBUTTONUP: HandleXButtonUp(handle, message, wParam, lParam); - break; + return IntPtr.Zero; // Keyboard events: case WindowMessage.KEYDOWN: @@ -833,7 +833,7 @@ namespace OpenTK.Platform.Windows { if (mouse_capture_count == 0) { - Functions.SetCapture(window.Handle); + Functions.SetCapture(child_window.Handle); } mouse_capture_count++; } From 6afb2ad58feba0e319e7e36205567697a55d6e1b Mon Sep 17 00:00:00 2001 From: David Jeske Date: Mon, 12 Jun 2017 09:16:32 -0700 Subject: [PATCH 7/7] Revert "Fix duplicate scroll input on windows 10" This reverts commit 9ef456bf9a9ae61e66559ce79927605fb7fe3fdc. --- src/OpenTK/Platform/Windows/WinGLNative.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/OpenTK/Platform/Windows/WinGLNative.cs b/src/OpenTK/Platform/Windows/WinGLNative.cs index c5919b51..234c68ac 100644 --- a/src/OpenTK/Platform/Windows/WinGLNative.cs +++ b/src/OpenTK/Platform/Windows/WinGLNative.cs @@ -97,9 +97,6 @@ namespace OpenTK.Platform.Windows IntPtr cursor_handle = Functions.LoadCursor(CursorName.Arrow); int cursor_visible_count = 0; - // tracking for w10 duplicate scroll inputs. - IntPtr scrollHandle; - static readonly object SyncRoot = new object(); #endregion @@ -537,12 +534,7 @@ namespace OpenTK.Platform.Windows { // This is due to inconsistent behavior of the WParam value on 64bit arch, whese // wparam = 0xffffffffff880000 or wparam = 0x00000000ff100000 - if (scrollHandle == IntPtr.Zero) { - scrollHandle = handle; - } - if (handle == scrollHandle) { - OnMouseWheel(0, ((long)wParam << 32 >> 48) / 120.0f); - } + OnMouseWheel(0, ((long)wParam << 32 >> 48) / 120.0f); } void HandleMouseHWheel(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)