public static SCNMatrix4 ToSCNMatrix4(this NMatrix4 self) { var row0 = new SCNVector4(self.M11, self.M12, self.M13, self.M14); var row1 = new SCNVector4(self.M21, self.M22, self.M23, self.M24); var row2 = new SCNVector4(self.M31, self.M32, self.M33, self.M34); var row3 = new SCNVector4(self.M41, self.M42, self.M43, self.M44); return(new SCNMatrix4(row0, row1, row2, row3)); }
public static float[,] ToFloatMatrix4(this NMatrix4 self) { return(new float[4, 4] { { self.M11, self.M21, self.M31, self.M41 }, { self.M12, self.M22, self.M32, self.M42 }, { self.M13, self.M23, self.M33, self.M43 }, { self.M14, self.M24, self.M34, self.M44 }, }); }
private void AddSelectedItem(ARHitTestResult hitTestResult) { SCNNode node = GetSelectedNode(); NMatrix4 transform = hitTestResult.WorldTransform; Vector4 thirdColumn = transform.Column3; node.Position = new SCNVector3(thirdColumn.X, thirdColumn.Y, thirdColumn.Z); sceneView.Scene.RootNode.AddChildNode(node); }
public static SCNMatrix4 ToSCNMatrix4(this NMatrix4 self) { var newMatrix = new SCNMatrix4( self.M11, self.M21, self.M31, self.M41, self.M12, self.M22, self.M32, self.M42, self.M13, self.M23, self.M33, self.M43, self.M14, self.M24, self.M34, self.M44 ); return(newMatrix); }
public void ProjectionMatrix() { using (var obj = new MDLCamera()) { Assert.AreEqual(0.1f, obj.NearVisibilityDistance, 0.0001f, "NearVisibilityDistance"); Assert.AreEqual(1000f, obj.FarVisibilityDistance, 0.0001f, "FarVisibilityDistance"); Assert.AreEqual(54f, obj.FieldOfView, 0.0001f, "FieldOfView"); #if NET var initialProjectionMatrix = new NMatrix4( 1.308407f, 0, 0, 0, 0, 1.962611f, 0, 0, 0, 0, -1.0002f, -0.20002f, 0, 0, -1, 0 ); #else var initialProjectionMatrix = new Matrix4( 1.308407f, 0, 0, 0, 0, 1.962611f, 0, 0, 0, 0, -1.0002f, -1, 0, 0, -0.20002f, 0 ); #endif Asserts.AreEqual(initialProjectionMatrix, obj.ProjectionMatrix, 0.0001f, "Initial"); #if NET Asserts.AreEqual(initialProjectionMatrix, CFunctions.GetMatrixFloat4x4(obj, "projectionMatrix"), 0.0001f, "Initial native"); #else Asserts.AreEqual(MatrixFloat4x4.Transpose((MatrixFloat4x4)initialProjectionMatrix), obj.ProjectionMatrix4x4, 0.0001f, "Initial 4x4"); Asserts.AreEqual(MatrixFloat4x4.Transpose((MatrixFloat4x4)initialProjectionMatrix), CFunctions.GetMatrixFloat4x4(obj, "projectionMatrix"), 0.0001f, "Initial native"); #endif obj.NearVisibilityDistance = 1.0f; #if NET var modifiedProjectionMatrix = new NMatrix4( 1.308407f, 0, 0, 0, 0, 1.962611f, 0, 0, 0, 0, -1.002002f, -2.002002f, 0, 0, -1, 0 ); #else var modifiedProjectionMatrix = new Matrix4( 1.308407f, 0, 0, 0, 0, 1.962611f, 0, 0, 0, 0, -1.002002f, -1, 0, 0, -2.002002f, 0 ); #endif Asserts.AreEqual(modifiedProjectionMatrix, obj.ProjectionMatrix, 0.0001f, "Second"); #if NET Asserts.AreEqual(modifiedProjectionMatrix, CFunctions.GetMatrixFloat4x4(obj, "projectionMatrix"), 0.0001f, "Second native"); #else Asserts.AreEqual(MatrixFloat4x4.Transpose((MatrixFloat4x4)modifiedProjectionMatrix), obj.ProjectionMatrix4x4, 0.0001f, "Second 4x4"); Asserts.AreEqual(MatrixFloat4x4.Transpose((MatrixFloat4x4)modifiedProjectionMatrix), CFunctions.GetMatrixFloat4x4(obj, "projectionMatrix"), 0.0001f, "Second native"); #endif } }
private void SetNewVirtualObjectToAnchor(SCNNode node, ARAnchor anchor, NMatrix4 cameraTransform) { var cameraWorldPosition = cameraTransform.GetTranslation(); var cameraToPosition = anchor.Transform.GetTranslation() - cameraWorldPosition; // Limit the distance of the object from the camera to a maximum of 10 meters. if (cameraToPosition.Length > 10f) { cameraToPosition = Vector3.Normalize(cameraToPosition); cameraToPosition *= 10f; } node.Position = cameraWorldPosition + cameraToPosition; }
/// <summary> /// Hit test against existing anchors /// </summary> private bool TryHitTestFromTouchPoint(CGPoint pt, out NMatrix4 worldTransform) { ARHitTestResult[] hits = this.sceneView.HitTest(pt, ARHitTestResultType.FeaturePoint); if (hits != null && hits.Length > 0) { ARHitTestResult hit = hits.FirstOrDefault(); if (hit != null) { worldTransform = hit.WorldTransform; return(true); } } worldTransform = default; return(false); }
public void MatrixTest() { #if NET var m4 = new NMatrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); #else var m4 = new Matrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); var m4x4 = (MatrixFloat4x4)m4; #endif using (var obj = new MDLTransform()) { // identity Asserts.AreEqual(Matrix4.Identity, obj.Matrix, "Initial identity"); #if NET Asserts.AreEqual(MatrixFloat4x4.Identity, obj.Matrix, "Initial identity 4x4"); #else Asserts.AreEqual(MatrixFloat4x4.Identity, obj.GetMatrix4x4(), "Initial identity 4x4"); #endif Asserts.AreEqual(MatrixFloat4x4.Identity, CFunctions.GetMatrixFloat4x4(obj, "matrix"), "Initial identity native"); // translate the transform somewhere obj.SetTranslation(new Vector3(2, 2, 2), 0); // the matrix should now be a translation matrix like this: // 1 0 0 0 2 // 0 1 0 0 2 // 0 0 1 0 2 // 0 0 0 1 0 #if !NET // but since Matrix4 is transposed when compared to MatrixFloat4x4, we get this: Asserts.AreEqual(new Matrix4( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 2, 2, 1 ), obj.Matrix, "Translated"); // The 4x4 version is correct: #endif Asserts.AreEqual(new Matrix4( 1, 0, 0, 2, 0, 1, 0, 2, 0, 0, 1, 2, 0, 0, 0, 1 #if NET ), obj.Matrix, "Translated 4x4");
public void LoadVirtualObject(VirtualObject vo, SCNVector3 position, NMatrix4 cameraTransform) { VirtualObjects.Add(vo); if (Delegate != null) { Delegate.WillLoad(this, vo); } vo.Load(); // Immediately place the object in 3D space SetNewVirtualObjectPosition(vo, position, cameraTransform); lastUsedObject = vo; if (Delegate != null) { Delegate.DidLoad(this, vo); } }
public static void SetTransform(this IGazeSnapshot snapshot, NMatrix4 transformMatrix) { snapshot.M11 = transformMatrix.M11; snapshot.M12 = transformMatrix.M12; snapshot.M13 = transformMatrix.M13; snapshot.M14 = transformMatrix.M14; snapshot.M21 = transformMatrix.M21; snapshot.M22 = transformMatrix.M22; snapshot.M23 = transformMatrix.M23; snapshot.M24 = transformMatrix.M24; snapshot.M31 = transformMatrix.M31; snapshot.M32 = transformMatrix.M32; snapshot.M33 = transformMatrix.M33; snapshot.M34 = transformMatrix.M34; //snapshot.M41 = transformMatrix.M41; //snapshot.M42 = transformMatrix.M42; //snapshot.M43 = transformMatrix.M43; //snapshot.M44 = transformMatrix.M44; }
public void CreateLocalAnchor(ref NMatrix4 transform) { if (this.localAnchor != null) { return; } this.localAnchor = new ARAnchor(transform); this.sceneView.Session.AddAnchor(this.localAnchor); // Put the local anchor in the anchorVisuals list with a special key AnchorVisual visual = new AnchorVisual { identifier = this.unsavedAnchorId, localAnchor = this.localAnchor }; this.anchorVisuals[visual.identifier] = visual; this.PlaceCube(this.localAnchor); this.UpdateMainStatusTitle("Create Cloud Anchor (once at 100%)"); }
public SnapshotAnchor(NSData imageData, NMatrix4 transform) : base("snapshot", transform) { this.ImageData = imageData; }
private void SetNewVirtualObjectPosition(VirtualObject virtualObject, SCNVector3 position, NMatrix4 cameraTransform) { var cameraWorldPos = cameraTransform.Translation(); var cameraToPosition = position.Subtract(cameraWorldPos); // Limit the distance of the object from the camera to a maximum of 10m if (cameraToPosition.LengthFast > 10) { cameraToPosition = cameraToPosition.Normalized() * 10; } virtualObject.Position = cameraWorldPos + cameraToPosition; virtualObject.RecentVirtualObjectDistances.Clear(); }
public void Ctors() { #if NET var id = NMatrix4.Identity; #else Matrix4 id = Matrix4.Identity; #endif var V3 = new Vector3(1, 2, 3); using (var obj = new MDLTransform(id)) { Asserts.AreEqual(Vector3.Zero, obj.Translation, "Translation"); Asserts.AreEqual(Vector3.One, obj.Scale, "Scale"); Asserts.AreEqual(Vector3.Zero, obj.Rotation, "Rotation"); Asserts.AreEqual(id, obj.Matrix, "Matrix"); if (TestRuntime.CheckXcodeVersion(8, 0)) { Asserts.AreEqual(false, obj.ResetsTransform, "ResetsTransform"); } obj.Translation = V3; Asserts.AreEqual(V3, obj.Translation, "Translation 2"); } if (TestRuntime.CheckXcodeVersion(8, 0)) { using (var obj = new MDLTransform(id, true)) { Asserts.AreEqual(Vector3.Zero, obj.Translation, "Translation"); Asserts.AreEqual(Vector3.One, obj.Scale, "Scale"); Asserts.AreEqual(Vector3.Zero, obj.Rotation, "Rotation"); Asserts.AreEqual(id, obj.Matrix, "Matrix"); Asserts.AreEqual(true, obj.ResetsTransform, "ResetsTransform"); obj.Translation = V3; Asserts.AreEqual(V3, obj.Translation, "Translation 2"); } } using (var obj = new MDLTransform(id)) { V3 *= 2; obj.Scale = V3; Asserts.AreEqual(V3, obj.Scale, "Scale 2"); } using (var obj = new MDLTransform(id)) { V3 *= 2; obj.Rotation = V3; Asserts.AreEqual(V3, obj.Rotation, "Rotation 2"); } using (var obj = new MDLTransform(id)) { V3 *= 2; obj.Rotation = V3; Asserts.AreEqual(V3, obj.Rotation, "Rotation 2"); } #if NET var m4 = new NMatrix4( 4, 0, 0, 2, 0, 3, 0, 3, 0, 0, 2, 4, 0, 0, 0, 1); #else var m4 = new Matrix4( 4, 0, 0, 0, 0, 3, 0, 0, 0, 0, 2, 0, 2, 3, 4, 1); #endif using (var obj = new MDLTransform(m4)) { Asserts.AreEqual(Vector3.Zero, obj.Rotation, "Rotation 3"); Asserts.AreEqual(new Vector3(4, 3, 2), obj.Scale, "Scale 3"); Asserts.AreEqual(new Vector3(2, 3, 4), obj.Translation, "Translation 3"); Asserts.AreEqual(m4, obj.Matrix, 0.0001f, "Matrix 3"); } #if !NET var m4x4 = new MatrixFloat4x4( 4, 0, 0, 2, 0, 3, 0, 3, 0, 0, 2, 4, 0, 0, 0, 1); using (var obj = new MDLTransform(m4x4)) { Asserts.AreEqual(Vector3.Zero, obj.Rotation, "Rotation 4"); Asserts.AreEqual(new Vector3(4, 3, 2), obj.Scale, "Scale 4"); Asserts.AreEqual(new Vector3(2, 3, 4), obj.Translation, "Translation 4"); #if NET Asserts.AreEqual(m4x4, obj.Matrix, 0.0001f, "Matrix4x4 4"); #else Asserts.AreEqual(m4x4, obj.GetMatrix4x4(), 0.0001f, "Matrix4x4 4"); #endif Asserts.AreEqual(m4x4, CFunctions.GetMatrixFloat4x4(obj, "matrix"), 0.0001f, "Matrix4x4-native 4"); } #endif }
public void Properties() { using (var obj = new MDLStereoscopicCamera()) { Assert.AreEqual(63f, obj.InterPupillaryDistance, "InterPupillaryDistance"); Assert.AreEqual(0f, obj.LeftVergence, "LeftVergence"); Assert.AreEqual(0f, obj.RightVergence, "RightVergence"); Assert.AreEqual(0f, obj.Overlap, "Overlap"); #if NET var mat1 = new Matrix4( 1, 0, 0, -0.63f, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); #else var mat1 = new Matrix4( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -0.63f, 0, 0, 1); #endif Asserts.AreEqual(mat1, obj.LeftViewMatrix, "LeftViewMatrix"); #if NET Asserts.AreEqual(mat1, CFunctions.GetMatrixFloat4x4(obj, "leftViewMatrix"), "LeftViewMatrix4x4 native"); #else Asserts.AreEqual(MatrixFloat4x4.Transpose((MatrixFloat4x4)mat1), obj.LeftViewMatrix4x4, "LeftViewMatrix4x4"); Asserts.AreEqual(MatrixFloat4x4.Transpose((MatrixFloat4x4)mat1), CFunctions.GetMatrixFloat4x4(obj, "leftViewMatrix"), "LeftViewMatrix4x4 native"); #endif #if NET var mat2 = new NMatrix4( 1, 0, 0, 0.63f, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); #else var mat2 = new Matrix4( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.63f, 0, 0, 1); #endif Asserts.AreEqual(mat2, obj.RightViewMatrix, "RightViewMatrix"); #if NET Asserts.AreEqual(mat2, CFunctions.GetMatrixFloat4x4(obj, "rightViewMatrix"), "RightViewMatrix4x4 native"); #else Asserts.AreEqual(MatrixFloat4x4.Transpose((MatrixFloat4x4)mat2), obj.RightViewMatrix4x4, "RightViewMatrix4x4"); Asserts.AreEqual(MatrixFloat4x4.Transpose((MatrixFloat4x4)mat2), CFunctions.GetMatrixFloat4x4(obj, "rightViewMatrix"), "RightViewMatrix4x4 native"); #endif #if NET var mat3 = new Matrix4( 1.308407f, 0, 0, 0, 0, 1.962611f, 0, 0, 0, 0, -1.0002f, -0.20002f, 0, 0, -1, 0); #else var mat3 = new Matrix4( 1.308407f, 0, 0, 0, 0, 1.962611f, 0, 0, 0, 0, -1.0002f, -1, 0, 0, -0.20002f, 0); #endif Asserts.AreEqual(mat3, obj.LeftProjectionMatrix, 0.0001f, "LeftProjectionMatrix"); #if NET Asserts.AreEqual(mat3, CFunctions.GetMatrixFloat4x4(obj, "leftProjectionMatrix"), 0.0001f, "LeftProjectionMatrix4x4 native"); #else Asserts.AreEqual(MatrixFloat4x4.Transpose((MatrixFloat4x4)mat3), obj.LeftProjectionMatrix4x4, 0.0001f, "LeftProjectionMatrix4x4"); Asserts.AreEqual(MatrixFloat4x4.Transpose((MatrixFloat4x4)mat3), CFunctions.GetMatrixFloat4x4(obj, "leftProjectionMatrix"), 0.0001f, "LeftProjectionMatrix4x4 native"); #endif Asserts.AreEqual(mat3, obj.RightProjectionMatrix, 0.0001f, "RightProjectionMatrix"); #if NET Asserts.AreEqual(mat3, CFunctions.GetMatrixFloat4x4(obj, "rightProjectionMatrix"), 0.0001f, "RightProjectionMatrix4x4 native"); #else Asserts.AreEqual(MatrixFloat4x4.Transpose((MatrixFloat4x4)mat3), obj.RightProjectionMatrix4x4, 0.0001f, "RightProjectionMatrix4x4"); Asserts.AreEqual(MatrixFloat4x4.Transpose((MatrixFloat4x4)mat3), CFunctions.GetMatrixFloat4x4(obj, "rightProjectionMatrix"), 0.0001f, "RightProjectionMatrix4x4 native"); #endif } }
internal static SCNVector3?UnprojectPointLocal(this ARSCNView self, CGPoint point, NMatrix4 planeTransform) { var result = self.Unproject(point, planeTransform); // Convert the result into the plane's local coordinate system. var pt = new SCNVector4(result.X, result.Y, result.Z, 1); var invertedPlane = planeTransform.ToSCNMatrix4(); invertedPlane.Invert(); var localResult = invertedPlane.Times(pt); return(localResult.Xyz); }
private SCNVector3 PositionFromTransform(NMatrix4 xform) { return(new SCNVector3(xform.M14, xform.M24, xform.M34)); }
public static SCNVector3 Translation(this NMatrix4 self) { return(new SCNVector3(self.M14, self.M24, self.M34)); }
public void Ctors() { Vector2 V2; Vector3 V3; Vector4 V4; #if NET NMatrix4 M4; #else Matrix4 M4; MatrixFloat4x4 M4x4; #endif MDLTextureSampler tsv; NSUrl url; using (var obj = new MDLMaterialProperty("name", MDLMaterialSemantic.AmbientOcclusion)) { Assert.AreEqual(MDLMaterialSemantic.AmbientOcclusion, obj.Semantic, "1 Semantic"); Assert.IsNull(obj.Color, "1 Color"); Asserts.AreEqual(Vector2.Zero, obj.Float2Value, "1 Float2Value"); Asserts.AreEqual(Vector3.Zero, obj.Float3Value, "1 Float3Value"); Asserts.AreEqual(Vector4.Zero, obj.Float4Value, "1 Float4Value"); Assert.AreEqual(0.0f, obj.FloatValue, "1 FloatValue"); Asserts.AreEqual(Matrix4.Identity, obj.Matrix4x4, "1 Matrix4x4"); Assert.AreEqual("name", obj.Name, "1 Name"); Assert.IsNull(obj.StringValue, "1 StringValue"); Assert.IsNull(obj.TextureSamplerValue, "1 TextureSamplerValue"); Assert.AreEqual(MDLMaterialPropertyType.Float, obj.Type, "1 Type"); Assert.IsNull(obj.UrlValue, "1 UrlValue"); V2 = new Vector2(1, 2); V3 = new Vector3(3, 4, 5); V4 = new Vector4(6, 7, 8, 9); #if NET M4 = new NMatrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); #else M4 = new Matrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); M4x4 = new MatrixFloat4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); #endif tsv = new MDLTextureSampler(); url = new NSUrl("http://xamarin.com"); obj.Semantic = MDLMaterialSemantic.Anisotropic; Assert.AreEqual(MDLMaterialSemantic.Anisotropic, obj.Semantic, "2 Semantic"); obj.Color = UIColor.Blue.CGColor; Assert.AreEqual(UIColor.Blue.CGColor.ToString(), obj.Color.ToString(), "2 Color"); obj.Float2Value = V2; Asserts.AreEqual(V2, obj.Float2Value, "2 Float2Value"); obj.Float3Value = V3; Asserts.AreEqual(V3, obj.Float3Value, "2 Float3Value"); obj.Float4Value = V4; Asserts.AreEqual(V4, obj.Float4Value, "2 Float4Value"); obj.FloatValue = 3.14f; Assert.AreEqual(3.14f, obj.FloatValue, "2 FloatValue"); obj.Matrix4x4 = M4; // It looks like the Matrix4 setter is ignored, assigning a matrix // doesn't work in Xcode either. Asserts.AreEqual(Matrix4.Identity, obj.Matrix4x4, "2 Matrix4x4"); obj.Name = "new name"; Assert.AreEqual("new name", obj.Name, "2 Name"); obj.StringValue = "string value"; Assert.AreEqual("string value", obj.StringValue, "2 StringValue"); obj.TextureSamplerValue = tsv; Assert.AreEqual(tsv.Handle, obj.TextureSamplerValue.Handle, "2 TextureSamplerValue"); Assert.AreEqual(MDLMaterialPropertyType.Texture, obj.Type, "2 Type"); // Looks like the URLValue can't change after construction obj.UrlValue = url; if (TestRuntime.CheckXcodeVersion(9, 0)) { Assert.AreSame(url, obj.UrlValue, "2 UrlValue"); } else { Assert.IsNull(obj.UrlValue, "2 UrlValue"); } } using (var obj = new MDLMaterialProperty("name", MDLMaterialSemantic.AmbientOcclusion, url)) { Assert.AreEqual(url.Handle, obj.UrlValue.Handle, "3 UrlValue"); } using (var obj = new MDLMaterialProperty("name", MDLMaterialSemantic.AmbientOcclusion, V3)) { Asserts.AreEqual(V3, obj.Float3Value, "4 Float3Value"); } using (var obj = new MDLMaterialProperty("name", MDLMaterialSemantic.AmbientOcclusion, tsv)) { Assert.AreEqual(tsv.Handle, obj.TextureSamplerValue.Handle, "5 TextureSamplerValue"); } using (var obj = new MDLMaterialProperty("name", MDLMaterialSemantic.AmbientOcclusion, "string value")) { Assert.AreEqual("string value", obj.StringValue, "6 StringValue"); } using (var obj = new MDLMaterialProperty("name", MDLMaterialSemantic.AmbientOcclusion, M4)) { Asserts.AreEqual(M4, obj.Matrix4x4, "7 Matrix4x4"); #if NET Asserts.AreEqual(CFunctions.GetMatrixFloat4x4(obj, "matrix4x4"), obj.Matrix4x4, "7b MatrixFloat4x4"); Asserts.AreEqual(M4, obj.Matrix4x4, "7c MatrixFloat4x4"); #else Asserts.AreEqual(CFunctions.GetMatrixFloat4x4(obj, "matrix4x4"), obj.MatrixFloat4x4, "7b MatrixFloat4x4"); Asserts.AreEqual(MatrixFloat4x4.Transpose((MatrixFloat4x4)M4), obj.MatrixFloat4x4, "7c MatrixFloat4x4"); #endif } #if !NET using (var obj = new MDLMaterialProperty("name", MDLMaterialSemantic.AmbientOcclusion, M4x4)) { Asserts.AreEqual(CFunctions.GetMatrixFloat4x4(obj, "matrix4x4"), obj.MatrixFloat4x4, "7' MatrixFloat4x4"); Asserts.AreEqual(M4x4, obj.MatrixFloat4x4, "7'b MatrixFloat4x4"); } #endif using (var obj = new MDLMaterialProperty("name", MDLMaterialSemantic.AmbientOcclusion, V4)) { Asserts.AreEqual(V4, obj.Float4Value, "8 Float4Value"); } using (var obj = new MDLMaterialProperty("name", MDLMaterialSemantic.AmbientOcclusion, UIColor.Red.CGColor)) { Assert.AreEqual(UIColor.Blue.CGColor.ToString(), obj.Color.ToString(), "9 Color"); } using (var obj = new MDLMaterialProperty("name", MDLMaterialSemantic.AmbientOcclusion, V2)) { Asserts.AreEqual(V2, obj.Float2Value, "10 Float2Value"); } using (var obj = new MDLMaterialProperty("name", MDLMaterialSemantic.AmbientOcclusion, 3.1415f)) { Assert.AreEqual(3.1415f, obj.FloatValue, "11 FloatValue"); } }
// Important: This is transposed from SCNMatrix4! (See, for instance, Ray.DragPlaneTransform() functions) internal static Vector3 Position(this NMatrix4 self) => self.Column3.Xyz;
private void SetPosition(VirtualObject virtualObject, SCNVector3 position, bool instantly, bool filterPosition, NMatrix4 cameraTransform) { if (instantly) { SetNewVirtualObjectPosition(virtualObject, position, cameraTransform); } else { UpdateVirtualObjectPosition(virtualObject, position, filterPosition, cameraTransform); } }
public void UpdateVirtualObjectPosition(VirtualObject virtualObject, SCNVector3 position, bool filterPosition, NMatrix4 cameraTransform) { var cameraWorldPos = cameraTransform.Translation(); var cameraToPosition = position.Subtract(cameraWorldPos); // Limit the distance of the object from the camera to a maximum of 10m if (cameraToPosition.LengthFast > 10) { cameraToPosition = cameraToPosition.Normalized() * 10; } // Compute the average distance of the object from the camera over the last ten // updates. If filterPosition is true, compute a new position for the object // with this average. Notice that the distance is applied to the vector from // the camera to the content, so it only affects the percieved distance of the // object - the averaging does _not_ make the content "lag". var hitTestResultDistance = cameraToPosition.LengthFast; virtualObject.RecentVirtualObjectDistances.Add(hitTestResultDistance); virtualObject.RecentVirtualObjectDistances.KeepLast(10); if (filterPosition) { var averageDistance = virtualObject.RecentVirtualObjectDistances.Average(); var averagedDistancePos = cameraWorldPos + cameraToPosition.Normalized() * averageDistance; virtualObject.Position = averagedDistancePos; } else { virtualObject.Position = cameraWorldPos + cameraToPosition; } }
public static SCNVector3 ToPosition(this NMatrix4 transform) { return(new SCNVector3(transform.M14, transform.M24, transform.M34)); }
public static SCNVector3 PositionFromTransform(NMatrix4 transform) { var pFromComponents = new SCNVector3(transform.M14, transform.M24, transform.M34); return(pFromComponents); }
internal PlaneDrag(NMatrix4 planeTransform, NVector3 offset) { this.PlaneTransform = planeTransform; this.Offset = offset; }