示例#1
0
        private void AddTrainToScene(SCNScene scene, SCNVector3 position)
        {
            var max        = SCNVector3.Zero;
            var min        = SCNVector3.Zero;
            var trainScene = SCNScene.FromFile("train_flat", ResourceManager.ResourceFolder, (NSDictionary)null);

            foreach (var node in trainScene.RootNode.ChildNodes)
            {
                if (node.Geometry != null)
                {
                    node.Position = new SCNVector3(
                        node.Position.X + position.X,
                        node.Position.Y + position.Y,
                        node.Position.Z + position.Z
                        );

                    max = SCNVector3.Zero;
                    min = SCNVector3.Zero;

                    node.GetBoundingBox(ref min, ref max);

                    var body     = SCNPhysicsBody.CreateDynamicBody();
                    var boxShape = new SCNBox {
                        Width         = max.X - min.X,
                        Height        = max.Y - min.Y,
                        Length        = max.Z - min.Z,
                        ChamferRadius = 0f
                    };

                    body.PhysicsShape = SCNPhysicsShape.Create(boxShape, (NSDictionary)null);
                    node.Pivot        = SCNMatrix4.CreateTranslation(0f, -min.Y, 0f);
                    node.PhysicsBody  = body;
                    scene.RootNode.AddChildNode(node);
                }
            }

            var smokeHandle         = scene.RootNode.FindChildNode("Smoke", true);
            var smokeParticleSystem = SCNParticleSystem.Create("smoke", ResourceManager.ResourceFolder);

            smokeParticleSystem.ParticleImage = ResourceManager.GetResourcePath("smoke.png");
            smokeHandle.AddParticleSystem(smokeParticleSystem);

            var engineCar = scene.RootNode.FindChildNode("EngineCar", false);
            var wagon1    = scene.RootNode.FindChildNode("Wagon1", false);
            var wagon2    = scene.RootNode.FindChildNode("Wagon2", false);

            max = SCNVector3.Zero;
            min = SCNVector3.Zero;
            engineCar.GetBoundingBox(ref min, ref max);

            var wmax = SCNVector3.Zero;
            var wmin = SCNVector3.Zero;

            wagon1.GetBoundingBox(ref wmin, ref wmax);

            var anchorA = new SCNVector3(max.X, min.Y, 0f);
            var anchorB = new SCNVector3(wmin.X, wmin.Y, 0f);

            var joint = SCNPhysicsBallSocketJoint.Create(engineCar.PhysicsBody, anchorA, wagon1.PhysicsBody, anchorB);

            scene.PhysicsWorld.AddBehavior(joint);

            joint = SCNPhysicsBallSocketJoint.Create(wagon1.PhysicsBody,
                                                     new SCNVector3(wmax.X + 0.1f, wmin.Y, 0f),
                                                     wagon2.PhysicsBody,
                                                     new SCNVector3(wmin.X - 0.1f, wmin.Y, 0f)
                                                     );

            scene.PhysicsWorld.AddBehavior(joint);
        }
示例#2
0
        private void CreateBallJoint(SCNPhysicsBody source, SCNVector3 sourceOffset, SCNPhysicsBody dest, SCNVector3 destOffset)
        {
            var joint = SCNPhysicsBallSocketJoint.Create(source, sourceOffset, dest, destOffset);

            this.joints.Add(joint);
        }