[GameplayKit] Use the new Simd-compatible matrix types, and deprecate the old API.

This commit is contained in:
Rolf Bjarne Kvinge 2017-08-31 12:18:04 +02:00
Родитель 788cd94355
Коммит 5303155836
3 изменённых файлов: 80 добавлений и 0 удалений

Просмотреть файл

@ -18,6 +18,7 @@ using Vector2i = global::OpenTK.Vector2i;
using Vector3 = global::OpenTK.Vector3;
using Vector3d = global::OpenTK.Vector3d;
using Matrix3 = global::OpenTK.Matrix3;
using Simd;
#if MONOMAC
using SKColor = XamCore.AppKit.NSColor;
@ -132,6 +133,8 @@ namespace XamCore.GameplayKit {
[Export ("rightHanded")]
bool RightHanded { get; set; }
#if !XAMCORE_4_0
[Obsolete ("Use 'Rotation3x3' instead.")]
[Export ("rotation", ArgumentSemantic.Assign)]
Matrix3 Rotation {
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")]
@ -139,6 +142,20 @@ namespace XamCore.GameplayKit {
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")]
set;
}
#endif
[Export ("rotation", ArgumentSemantic.Assign)]
#if XAMCORE_4_0
MatrixFloat3x3 Rotation {
#else
[Sealed]
MatrixFloat3x3 Rotation3x3 {
#endif
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")]
get;
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")]
set;
}
[Export ("updateWithDeltaTime:")]
void Update (double deltaTimeInSeconds);

Просмотреть файл

@ -0,0 +1,62 @@
//
// Unit tests for GKAgent3D
//
// Authors:
// Rolf Bjarne Kvinge <rolf@xamarin.com>
//
//
// Copyright 2017 Microsoft Inc. All rights reserved.
//
#if !__WATCHOS__
using System;
using OpenTK;
#if XAMCORE_2_0
using Foundation;
using GameplayKit;
#else
using MonoTouch.Foundation;
using MonoTouch.GameplayKit;
#endif
using Simd;
using Bindings.Test;
using NUnit.Framework;
namespace MonoTouchFixtures.GamePlayKit
{
[TestFixture]
[Preserve (AllMembers = true)]
public class GKAgent3DTest
{
[Test]
public void RotationTest ()
{
using (var obj = new GKAgent3D ()) {
var initial = new Matrix3 (0, 0, 1,
0, 1, 0,
1, 0, 0);
Asserts.AreEqual (initial, obj.Rotation, "Rotation");
Asserts.AreEqual ((MatrixFloat3x3) initial, obj.Rotation3x3, "Rotation3x3");
var mat = new Matrix3 (1, 2, 3,
4, 5, 6,
7, 8, 9);
var mat3x3 = (MatrixFloat3x3) mat;
obj.Rotation = mat;
Asserts.AreEqual (mat, obj.Rotation, "Rotation after setter");
var transposed3x3 = MatrixFloat3x3.Transpose ((MatrixFloat3x3) mat);
Asserts.AreEqual (transposed3x3, obj.Rotation3x3, "Rotation3x3 after setter");
Asserts.AreEqual (transposed3x3, CFunctions.GetMatrixFloat3x3 (obj, "rotation"), "Rotation3x3 after setter native");
obj.Rotation3x3 = mat3x3;
Asserts.AreEqual (mat3x3, obj.Rotation3x3, "Rotation3x3 after setter 3x3");
Asserts.AreEqual (mat3x3, CFunctions.GetMatrixFloat3x3 (obj, "rotation"), "Rotation3x3 after setter native 3x3");
}
}
}
}
#endif // __WATCHOS__

Просмотреть файл

@ -635,6 +635,7 @@
<Compile Include="UIKit\GraphicsRendererTest.cs" />
<Compile Include="Intents\INIntentResolutionResultTests.cs" />
<Compile Include="MessageUI\MessageComposeViewControllerTest.cs" />
<Compile Include="GameplayKit\GKAgent3DTest.cs" />
<Compile Include="GameplayKit\GKOctreeTests.cs" />
<Compile Include="GameplayKit\GKQuadTreeTests.cs" />
<Compile Include="GameplayKit\GKMeshGraphTests.cs" />