public void SCNView_TechniqueSetterTest() { SCNView v = new SCNView(new CGRect(), (NSDictionary)null); SCNTechnique t = SCNTechnique.Create(new NSDictionary()); v.Technique = t; }
void HandleTapGesture(UITapGestureRecognizer sender) { SCNView areaPanned = sender.View as SCNView; CGPoint point = sender.LocationInView(areaPanned); SCNHitTestResult[] hitResults = areaPanned.HitTest(point, new SCNHitTestOptions()); SCNHitTestResult hit = hitResults.FirstOrDefault(); if (hit != null) { SCNNode node = hit.Node; if (node != null) { if (!isAnimating) { node.AddRotationAction(SCNActionTimingMode.Linear, 3, true); isAnimating = true; } else { node.RemoveAction("rotation"); isAnimating = false; } } } }
public override void ViewDidLoad() { base.ViewDidLoad(); GoalSelector = new UISegmentedControl($"{ARCoachingGoal.Tracking}", $"{ARCoachingGoal.HorizontalPlane}", $"{ARCoachingGoal.VerticalPlane}") { TranslatesAutoresizingMaskIntoConstraints = false } ; Coach = new ARCoachingOverlayView { ActivatesAutomatically = true, Delegate = new CoachingDelegate(this), Session = SCNView.Session }; BlurView = new UIView { BackgroundColor = UIColor.Black.ColorWithAlpha(.65f), Alpha = 0 }; SCNView.FillWith(BlurView); SCNView.FillWith(Coach, 200, 400); View.AddSubviews(GoalSelector); View.AddConstraints(new[] { NSLayoutConstraint.Create(GoalSelector, NSLayoutAttribute.Top, NSLayoutRelation.Equal, View, NSLayoutAttribute.TopMargin, 1, 10), NSLayoutConstraint.Create(GoalSelector, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, View, NSLayoutAttribute.CenterX, 1, 0) }); GoalSelector.ValueChanged += GoalChanged; }
private async void HandleTap(UITapGestureRecognizer sender) { if (isHandlingTap) { return; } try { isHandlingTap = true; SCNView sceneViewTappedOn = sender.View as SCNView; CoreGraphics.CGPoint touchCoordinates = sender.LocationInView(sceneViewTappedOn); SCNHitTestResult[] hitTest = sceneViewTappedOn.HitTest(touchCoordinates, new SCNHitTestOptions()); if (!hitTest.Any()) { return; } SCNNode pressedNode = hitTest.FirstOrDefault().Node; await AnimateNode(pressedNode); RemoveAllNodes(); AddNode(); } finally { isHandlingTap = false; } }
public void NullOverlaySceneTest() { // Issue: https://github.com/xamarin/xamarin-macios/issues/3392 TestRuntime.AssertXcodeVersion(7, 0); var view = new SCNView(new CGRect(), (NSDictionary)null); Assert.NotNull(view, "View not null"); Assert.DoesNotThrow(() => view.OverlayScene = null, "Should not throw"); }
void HandleRotateGesture(UIRotationGestureRecognizer sender) { SCNView areaPanned = sender.View as SCNView; CGPoint point = sender.LocationInView(areaPanned); SCNHitTestResult[] hitResults = areaPanned.HitTest(point, new SCNHitTestOptions()); SCNHitTestResult hit = hitResults.FirstOrDefault(); if (hit != null) { SCNNode node = hit.Node; zAngle += (float)(-sender.Rotation); node.EulerAngles = new SCNVector3(node.EulerAngles.X, node.EulerAngles.Y, zAngle); } }
public override void OnFrameUpdate(ARSession session, ARFrame frame) { base.OnFrameUpdate(session, frame); if (adding) { return; } var results = SCNView.HitTest(View.Center, new SCNHitTestOptions { SortResults = true, BackFaceCulling = false, SearchMode = SCNHitTestSearchMode.All, FirstFoundOnly = false }); SCNNode newNode = null; var match = results.FirstOrDefault(r => NodeLookup.ContainsKey(r.Node)); if (match != null) { newNode = match.Node; } var changed = newNode != SelectedNode; var oldNode = SelectedNode; SelectedNode = newNode; if (changed) { var panelTransform = SelectedNode != null ? CGAffineTransform.MakeIdentity() : CGAffineTransform.MakeTranslation(0, 1000); if (SelectedNode != null) { var content = _contentFor[NodeLookup[match.Node].Name]; InfoDialog.Label.Text = content.Description; TitleDialog.Label.Text = content.Name; } UIView.Animate(.2, 0, UIViewAnimationOptions.CurveEaseOut, () => { InfoDialog.View.Transform = panelTransform; TitleDialog.View.Transform = panelTransform; }, null); } }
public override void DidFinishLaunching(NSNotification notification) { window = new NSWindow(new CGRect(0, 0, 300, 300), NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Resizable | NSWindowStyle.Titled, NSBackingStore.Retained, false); SCNScene scene = SCNScene.FromFile("art.scnassets/scene.scn"); SCNView scnView = new SCNView(window.ContentView.Bounds); scnView.Scene = scene; window.ContentView.AddSubview(scnView); var size = window.Frame.Size; var loc = new CGPoint((NSScreen.MainScreen.Frame.Width - size.Width) / 2, (NSScreen.MainScreen.Frame.Height - size.Height) / 2); window.SetFrameOrigin(loc); window.MakeKeyAndOrderFront(null); }
void HandleTapGesture(UITapGestureRecognizer sender) { SCNView areaPanned = sender.View as SCNView; CGPoint point = sender.LocationInView(areaPanned); SCNHitTestResult[] hitResults = areaPanned.HitTest(point, new SCNHitTestOptions()); SCNHitTestResult hit = hitResults.FirstOrDefault(); if (hit != null) { SCNNode node = hit.Node; if (node != null) { node.RemoveFromParentNode(); } } }
void HandlePinchGesture(UIPinchGestureRecognizer sender) { SCNView areaPanned = sender.View as SCNView; CGPoint point = sender.LocationInView(areaPanned); SCNHitTestResult[] hitResults = areaPanned.HitTest(point, new SCNHitTestOptions()); SCNHitTestResult hit = hitResults.FirstOrDefault(); if (hit != null) { SCNNode node = hit.Node; float scaleX = (float)sender.Scale * node.Scale.X; float scaleY = (float)sender.Scale * node.Scale.Y; node.Scale = new SCNVector3(scaleX, scaleY, zPosition / 2); sender.Scale = 1; // Reset the node scale value } }
public override void OnFrameUpdate(ARSession session, ARFrame frame) { base.OnFrameUpdate(session, frame); var results = SCNView.HitTest(View.Center, new SCNHitTestOptions { SortResults = true, BackFaceCulling = false, SearchMode = SCNHitTestSearchMode.All, FirstFoundOnly = false }); SCNNode newNode = null; T newItem = default(T); var match = results.FirstOrDefault(r => NodeLookup.ContainsKey(r.Node)); if (match != null) { newNode = match.Node; newItem = NodeLookup[newNode].ItemData; } var changed = newNode != SelectedNode; var oldNode = SelectedNode; var oldItem = SelectedItem; SelectedNode = newNode; SelectedItem = newItem; if (changed) { SelectionChanged(oldNode, oldItem, SelectedNode, SelectedItem); } Crosshair.BackgroundColor = SelectedNode != null ? UIColor.Green : UIColor.Gray; }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. var scene = new SCNScene(); var rnd = new Random(); Func <int, int, bool, float> random = (min, max, clamp) => { float num = (float)((double)rnd.Next(min, max) * rnd.NextDouble()); if (!clamp) { return(num); } else if (num < 1.0f) { return(1.0f); } else { return(num); } }; Enumerable.Range(0, 200).Select <int, int> ((i) => Building( random(2, 5, true), random(2, 5, true), random(2, 10, true), random(-20, 20, false), random(-20, 20, false), scene, rnd )).ToArray(); //Lights! var lightNode = new SCNNode() { Light = new SCNLight(), Position = new SCNVector3(30.0F, 20.0F, 60.0F) }; lightNode.Light.LightType = SCNLightType.Omni; scene.RootNode.AddChildNode(lightNode); var ambientLightNode = new SCNNode() { Light = new SCNLight() }; ambientLightNode.Light.LightType = SCNLightType.Ambient; ambientLightNode.Light.Color = UIColor.DarkGray; scene.RootNode.AddChildNode(ambientLightNode); //Camera! var cameraNode = new SCNNode() { Camera = new SCNCamera() }; scene.RootNode.AddChildNode(cameraNode); cameraNode.Position = new SCNVector3(0.0F, 10.0F, 20.0F); var targetNode = new SCNNode() { Position = new SCNVector3(00.0F, 1.5F, 0.0F) }; scene.RootNode.AddChildNode(targetNode); var lc = SCNLookAtConstraint.Create(targetNode); cameraNode.Constraints = new[] { lc }; var scnView = new SCNView(UIScreen.MainScreen.Bounds) { Scene = scene, AllowsCameraControl = true, ShowsStatistics = true, BackgroundColor = UIColor.FromRGB(52, 152, 219) }; var floorNode = new SCNNode { Geometry = new SCNPlane { Height = 40.0F, Width = 40.0F }, Position = SCNVector3.Zero }; var pi2 = Math.PI / 2.0; floorNode.Orientation = SCNQuaternion.FromAxisAngle(SCNVector3.UnitX, (float)(0.0 - pi2)); scene.RootNode.AddChildNode(floorNode); var material = new SCNMaterial(); material.Diffuse.Contents = UIImage.FromFile("Content/road.jpg"); material.Diffuse.ContentsTransform = SCNMatrix4.Scale(new SCNVector3(10.0f, 10.0f, 1.0f)); material.Diffuse.MinificationFilter = SCNFilterMode.Linear; material.Diffuse.MagnificationFilter = SCNFilterMode.Linear; material.Diffuse.MipFilter = SCNFilterMode.Linear; material.Diffuse.WrapS = SCNWrapMode.Repeat; material.Diffuse.WrapT = SCNWrapMode.Repeat; material.Specular.Contents = UIColor.Gray; floorNode.Geometry.FirstMaterial = material; this.View = scnView; }
public void InitView() { gameView = View as SCNView; gameView.AutoenablesDefaultLighting = true; }
void Setup () { SceneView = (SCNView)this.View; SceneView.BackgroundColor = SKColor.Black; //setup ivars Boxes = new List<SCNNode> (); //setup the scene SetupScene (); //present it SceneView.Scene = Scene; //tweak physics SceneView.Scene.PhysicsWorld.Speed = 2.0f; //let's be the delegate of the SCNView SceneView.WeakSceneRendererDelegate = this; SceneView.JitteringEnabled = true; //initial point of view SceneView.PointOfView = CameraNode; //setup overlays var overlay = new SpriteKitOverlayScene (SceneView.Bounds.Size); SceneView.OverlayScene = overlay; #if __IOS__ var gestureRecognizers = new List<UIGestureRecognizer> (); if (SceneView.GestureRecognizers != null) gestureRecognizers.AddRange (SceneView.GestureRecognizers); // add a tap gesture recognizer UITapGestureRecognizer tapGesture = new UITapGestureRecognizer (HandleTouch); // add a pan gesture recognizer UIPanGestureRecognizer panGesture = new UIPanGestureRecognizer (HandleTouchPan); // add a double tap gesture recognizer UITapGestureRecognizer doubleTapGesture = new UITapGestureRecognizer (HandleDoubleTouch); doubleTapGesture.NumberOfTapsRequired = 2; tapGesture.RequireGestureRecognizerToFail (panGesture); gestureRecognizers.Add (doubleTapGesture); gestureRecognizers.Add (tapGesture); gestureRecognizers.Add (panGesture); //register gesture recognizers SceneView.GestureRecognizers = gestureRecognizers.ToArray (); #endif }
public override void ViewDidLoad () { base.ViewDidLoad (); // Perform any additional setup after loading the view, typically from a nib. var scene = new SCNScene (); var rnd = new Random (); Func<int, int, bool, float> random = (min, max, clamp) => { float num = (float)((double)rnd.Next(min, max) * rnd.NextDouble ()); if (!clamp) return num; else if (num < 1.0f) return 1.0f; else return num; }; Enumerable.Range (0, 200).Select<int, int> ((i) => Building ( random (2,5, true), random (2,5, true), random (2,10, true), random (-20, 20, false), random (-20, 20, false), scene, rnd )).ToArray (); //Lights! var lightNode = new SCNNode() { Light = new SCNLight (), Position = new SCNVector3 (30.0F, 20.0F, 60.0F) }; lightNode.Light.LightType = SCNLightType.Omni; scene.RootNode.AddChildNode (lightNode); var ambientLightNode = new SCNNode () { Light = new SCNLight () }; ambientLightNode.Light.LightType = SCNLightType.Ambient; ambientLightNode.Light.Color = UIColor.DarkGray; scene.RootNode.AddChildNode (ambientLightNode); //Camera! var cameraNode = new SCNNode () { Camera = new SCNCamera () }; scene.RootNode.AddChildNode (cameraNode); cameraNode.Position = new SCNVector3 (0.0F, 10.0F, 20.0F); var targetNode = new SCNNode () { Position = new SCNVector3 (00.0F, 1.5F, 0.0F) }; scene.RootNode.AddChildNode (targetNode); var lc = SCNLookAtConstraint.Create (targetNode); cameraNode.Constraints = new[] { lc }; var scnView = new SCNView(UIScreen.MainScreen.Bounds) { Scene = scene, AllowsCameraControl = true, ShowsStatistics = true, BackgroundColor = UIColor.FromRGB (52, 152, 219) }; var floorNode = new SCNNode { Geometry = new SCNPlane { Height = 40.0F, Width = 40.0F }, Position = SCNVector3.Zero }; var pi2 = Math.PI / 2.0; floorNode.Orientation = SCNQuaternion.FromAxisAngle (SCNVector3.UnitX, (float)(0.0 - pi2)); scene.RootNode.AddChildNode (floorNode); var material = new SCNMaterial (); material.Diffuse.Contents = UIImage.FromFile ("Content/road.jpg"); material.Diffuse.ContentsTransform = SCNMatrix4.Scale (new SCNVector3 (10.0f, 10.0f, 1.0f)); material.Diffuse.MinificationFilter = SCNFilterMode.Linear; material.Diffuse.MagnificationFilter = SCNFilterMode.Linear; material.Diffuse.MipFilter = SCNFilterMode.Linear; material.Diffuse.WrapS = SCNWrapMode.Repeat; material.Diffuse.WrapT = SCNWrapMode.Repeat; material.Specular.Contents = UIColor.Gray; floorNode.Geometry.FirstMaterial = material; this.View = scnView; }