public PlaneNode(ARPlaneAnchor planeAnchor) { Geometry = (planeGeometry = CreateGeometry(planeAnchor)); Position = new SCNVector3(0, -PlaneHeight / 2, 0); PhysicsBody = SCNPhysicsBody.CreateKinematicBody(); }
public override void PresentStep(int index, PresentationViewController presentationViewController) { Step = index; switch (index) { case 0: break; case 1: TextManager.FlipOutText(SlideTextManager.TextType.Bullet); TextManager.SetSubtitle("SCNPhysicsBody"); TextManager.FlipInText(SlideTextManager.TextType.Subtitle); TextManager.AddBulletAtLevel("Dynamic Bodies", 0); // Add some code TextManager.AddCode("#// Make a node dynamic\n" + "aNode.#physicsBody# = [SCNPhysicsBody #dynamicBody#];#"); TextManager.FlipInText(SlideTextManager.TextType.Bullet); TextManager.FlipInText(SlideTextManager.TextType.Code); break; case 2: //add a cube var worldPos = GroundNode.ConvertPositionToNode(new SCNVector3(0, 12, 2), null); var dice = CreateBlock(worldPos, new SCNVector3(1.5f, 1.5f, 1.5f)); dice.PhysicsBody = null; //wait! dice.Rotation = new SCNVector4(0, 0, 1, (float)(Math.PI / 4) * 0.5f); dice.Scale = new SCNVector3(0.001f, 0.001f, 0.001f); ((SCNView)presentationViewController.View).Scene.RootNode.AddChildNode(dice); SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 0.75f; dice.Scale = new SCNVector3(2, 2, 2); SCNTransaction.Commit(); Dices.Add(dice); break; case 3: foreach (var node in Dices) { node.PhysicsBody = SCNPhysicsBody.CreateDynamicBody(); } break; case 4: PresentDices(presentationViewController); break; case 5: TextManager.FlipOutText(SlideTextManager.TextType.Bullet); TextManager.FlipOutText(SlideTextManager.TextType.Code); TextManager.AddBulletAtLevel("Manipulate with forces", 0); // Add some code TextManager.AddCode("#// Apply an impulse\n" + "[aNode.physicsBody #applyForce:#aVector3 #atPosition:#aVector3 #impulse:#YES];#"); TextManager.FlipInText(SlideTextManager.TextType.Bullet); TextManager.FlipInText(SlideTextManager.TextType.Code); break; case 6: // remove dices var center = new SCNVector3(0, -5, 20); center = GroundNode.ConvertPositionToNode(center, null); Explosion(center, Dices); var popTime = new DispatchTime(DispatchTime.Now, (long)(1 * Utils.NSEC_PER_SEC)); DispatchQueue.MainQueue.DispatchAfter(popTime, () => { TextManager.FlipOutText(SlideTextManager.TextType.Code); TextManager.FlipOutText(SlideTextManager.TextType.Bullet); TextManager.AddBulletAtLevel("Static Bodies", 0); TextManager.AddCode("#// Make a node static\n" + "aNode.#physicsBody# = [SCNPhysicsBody #staticBody#];#"); TextManager.FlipInText(SlideTextManager.TextType.Bullet); TextManager.FlipInText(SlideTextManager.TextType.Code); }); break; case 7: PresentWalls(presentationViewController); break; case 8: PresentBalls(presentationViewController); break; case 9: //remove walls var walls = new List <SCNNode> (); GroundNode.EnumerateChildNodes(delegate(SCNNode node, out bool stop) { stop = false; if (node.Name == "container-wall") { node.RunAction(SCNAction.Sequence(new SCNAction [] { SCNAction.MoveBy(new SCNVector3(0, -2, 0), 0.5), SCNAction.RemoveFromParentNode() })); walls.Add(node); } return(stop); }); break; case 10: // remove balls center = new SCNVector3(0, -5, 5); center = GroundNode.ConvertPositionToNode(center, null); Explosion(center, Balls); popTime = new DispatchTime(DispatchTime.Now, (long)(0.5 * Utils.NSEC_PER_SEC)); DispatchQueue.MainQueue.DispatchAfter(popTime, () => { TextManager.FlipOutText(SlideTextManager.TextType.Code); TextManager.FlipOutText(SlideTextManager.TextType.Bullet); TextManager.AddBulletAtLevel("Kinematic Bodies", 0); TextManager.AddCode("#// Make a node kinematic\n" + "aNode.#physicsBody# = [SCNPhysicsBody #kinematicBody#];#"); TextManager.FlipInText(SlideTextManager.TextType.Bullet); TextManager.FlipInText(SlideTextManager.TextType.Code); }); break; case 11: var boxNode = SCNNode.Create(); boxNode.Geometry = SCNBox.Create(10, 0.2f, 10, 0); boxNode.Position = new SCNVector3(0, 5, MIDDLE_Z); boxNode.Geometry.FirstMaterial.Emission.Contents = NSColor.DarkGray; boxNode.PhysicsBody = SCNPhysicsBody.CreateKinematicBody(); boxNode.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 0, NMath.PI * 2, 2.0))); GroundNode.AddChildNode(boxNode); KinematicItems.Add(boxNode); var invisibleWall = SCNNode.Create(); invisibleWall.Geometry = SCNBox.Create(4, 40, 10, 0); invisibleWall.Position = new SCNVector3(-7, 0, MIDDLE_Z); invisibleWall.Geometry.FirstMaterial.Transparency = 0; invisibleWall.PhysicsBody = SCNPhysicsBody.CreateStaticBody(); GroundNode.AddChildNode(invisibleWall); KinematicItems.Add(invisibleWall); invisibleWall = (SCNNode)invisibleWall.Copy(); invisibleWall.Position = new SCNVector3(7, 0, MIDDLE_Z); GroundNode.AddChildNode(invisibleWall); KinematicItems.Add(invisibleWall); invisibleWall = (SCNNode)invisibleWall.Copy(); invisibleWall.Geometry = SCNBox.Create(10, 40, 4, 0); invisibleWall.Geometry.FirstMaterial.Transparency = 0; invisibleWall.Position = new SCNVector3(0, 0, MIDDLE_Z - 7); invisibleWall.PhysicsBody = SCNPhysicsBody.CreateStaticBody(); GroundNode.AddChildNode(invisibleWall); KinematicItems.Add(invisibleWall); invisibleWall = (SCNNode)invisibleWall.Copy(); invisibleWall.Position = new SCNVector3(0, 0, MIDDLE_Z + 7); GroundNode.AddChildNode(invisibleWall); KinematicItems.Add(invisibleWall); for (int i = 0; i < 100; i++) { var ball = SCNNode.Create(); worldPos = boxNode.ConvertPositionToNode(new SCNVector3(RandFloat(-4, 4), RandFloat(10, 30), RandFloat(-1, 4)), null); ball.Position = worldPos; ball.Geometry = SCNSphere.Create(0.5f); ball.Geometry.FirstMaterial.Diffuse.Contents = NSColor.Cyan; ball.PhysicsBody = SCNPhysicsBody.CreateDynamicBody(); ((SCNView)presentationViewController.View).Scene.RootNode.AddChildNode(ball); KinematicItems.Add(ball); } break; case 12: TextManager.FlipOutText(SlideTextManager.TextType.Code); TextManager.FlipOutText(SlideTextManager.TextType.Bullet); TextManager.FlipOutText(SlideTextManager.TextType.Subtitle); TextManager.SetSubtitle("SCNPhysicsShape"); TextManager.AddCode("#// Configure the physics shape\n\n" + "aNode.physicsBody.#physicsShape# = \n\t[#SCNPhysicsShape# shapeWithGeometry:aGeometry options:options];#"); TextManager.FlipInText(SlideTextManager.TextType.Bullet); TextManager.FlipInText(SlideTextManager.TextType.Code); KinematicItems[0].RunAction(SCNAction.Sequence(new SCNAction[] { SCNAction.FadeOut(0.5), SCNAction.RemoveFromParentNode() })); for (int i = 1; i < 5; i++) { KinematicItems[i].RemoveFromParentNode(); } KinematicItems = null; break; case 13: //add meshes PresentMeshes(presentationViewController); break; case 14: // remove meshes center = new SCNVector3(0, -5, 20); center = GroundNode.ConvertPositionToNode(center, null); Explosion(center, Meshes); break; case 15: // add shapes PresentPrimitives(presentationViewController); break; case 16: // remove shapes center = new SCNVector3(0, -5, 20); center = GroundNode.ConvertPositionToNode(center, null); Explosion(center, Shapes); popTime = new DispatchTime(DispatchTime.Now, (long)(0.5 * Utils.NSEC_PER_SEC)); DispatchQueue.MainQueue.DispatchAfter(popTime, () => { TextManager.FlipOutText(SlideTextManager.TextType.Code); TextManager.FlipOutText(SlideTextManager.TextType.Bullet); TextManager.FlipOutText(SlideTextManager.TextType.Subtitle); TextManager.SetSubtitle("SCNPhysicsBehavior"); TextManager.AddCode("#// setup a physics behavior\n\n" + "#SCNPhysicsHingeJoint# *joint = [SCNPhysicsHingeJoint\n\n" + "jointWithBodyA:#nodeA.physicsBody# axisA:[...] anchorA:[...]\n\n" + "bodyB:#nodeB.physicsBody# axisB:[...] anchorB:[...]];\n\n\n" + "[scene.#physicsWorld# addBehavior:joint];#"); TextManager.FlipInText(SlideTextManager.TextType.Bullet); TextManager.FlipInText(SlideTextManager.TextType.Subtitle); TextManager.FlipInText(SlideTextManager.TextType.Code); }); break; case 17: //add meshes PresentHinge(presentationViewController); break; case 18: //remove constraints ((SCNView)presentationViewController.View).Scene.PhysicsWorld.RemoveAllBehaviors(); foreach (var node in Hinges) { node.RunAction(SCNAction.Sequence(new SCNAction[] { SCNAction.Wait(3.0), SCNAction.FadeOut(0.5), SCNAction.RemoveFromParentNode() })); } break; case 19: TextManager.FlipOutText(SlideTextManager.TextType.Bullet); TextManager.FlipOutText(SlideTextManager.TextType.Subtitle); TextManager.FlipOutText(SlideTextManager.TextType.Code); TextManager.SetSubtitle("More..."); TextManager.FlipInText(SlideTextManager.TextType.Subtitle); TextManager.AddBulletAtLevel("SCNPhysicsField", 0); TextManager.AddBulletAtLevel("SCNPhysicsVehicle", 0); TextManager.FlipInText(SlideTextManager.TextType.Bullet); TextManager.FlipInText(SlideTextManager.TextType.Code); break; } }