Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SceneKit] Make SCNMatrix4 column-major in .NET. Fixes #4652. #13695

Merged
merged 4 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dotnet/BreakingChanges.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,14 @@ These APIs are used to determine whether we're executing in the simulator or
on a device. Neither apply to a Mac Catalyst app, so they've been removed.

Any code that these APIs will have to be ported to not use these APIs.

## The SceneKit.SCNMatrix4 matrix is transposed in memory.

The managed SCNMatrix4 struct used to be a row-major matrix, while the native
SCNMatrix4 struct is a column-major matrix. This difference in the memory
representation meant that matrices would often have to be transposed when
interacting with the platform.

In .NET, we've changed the managed SCNMatrix4 to be a column-major matrix, to
match the native version. This means that any transposing that's currently
done when accessing Apple APIs has to be undone.
52 changes: 52 additions & 0 deletions src/SceneKit/SCNMatrix4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

*/

#if !NET

using System;
using System.Runtime.InteropServices;
using Foundation;
Expand Down Expand Up @@ -170,6 +172,12 @@ public pfloat Determinant
public SCNVector4 Column0
{
get { return new SCNVector4(Row0.X, Row1.X, Row2.X, Row3.X); }
set {
M11 = value.X;
M21 = value.Y;
M31 = value.Z;
M41 = value.W;
}
}

/// <summary>
Expand All @@ -178,6 +186,12 @@ public SCNVector4 Column0
public SCNVector4 Column1
{
get { return new SCNVector4(Row0.Y, Row1.Y, Row2.Y, Row3.Y); }
set {
M12 = value.X;
M22 = value.Y;
M32 = value.Z;
M42 = value.W;
}
}

/// <summary>
Expand All @@ -186,6 +200,12 @@ public SCNVector4 Column1
public SCNVector4 Column2
{
get { return new SCNVector4(Row0.Z, Row1.Z, Row2.Z, Row3.Z); }
set {
M13 = value.X;
M23 = value.Y;
M33 = value.Z;
M43 = value.W;
}
}

/// <summary>
Expand All @@ -194,6 +214,12 @@ public SCNVector4 Column2
public SCNVector4 Column3
{
get { return new SCNVector4(Row0.W, Row1.W, Row2.W, Row3.W); }
set {
M14 = value.X;
M24 = value.Y;
M34 = value.Z;
M44 = value.W;
}
}

/// <summary>
Expand Down Expand Up @@ -307,6 +333,29 @@ public void Transpose()
#endregion

#region Static

#region CreateFromColumns

public static SCNMatrix4 CreateFromColumns (SCNVector4 column0, SCNVector4 column1, SCNVector4 column2, SCNVector4 column3)
{
var result = new SCNMatrix4 ();
result.Column0 = column0;
result.Column1 = column1;
result.Column2 = column2;
result.Column3 = column3;
return result;
}

public static void CreateFromColumns (SCNVector4 column0, SCNVector4 column1, SCNVector4 column2, SCNVector4 column3, out SCNMatrix4 result)
{
result = new SCNMatrix4 ();
result.Column0 = column0;
result.Column1 = column1;
result.Column2 = column2;
result.Column3 = column3;
}

#endregion

#region CreateFromAxisAngle

Expand Down Expand Up @@ -1176,3 +1225,6 @@ public static implicit operator CoreAnimation.CATransform3D (SCNMatrix4 source)
#endif
}
}

#endif // !NET

Loading