Пример #1
0
        private void CreateHingeJoint(SCNPhysicsBody source,
                                      SCNVector3 sourceAxis,
                                      SCNVector3 sourceAnchor,
                                      SCNPhysicsBody dest,
                                      SCNVector3 destAxis,
                                      SCNVector3 destAnchor)
        {
            var joint = SCNPhysicsHingeJoint.Create(source, sourceAxis, sourceAnchor, dest, destAxis, destAnchor);

            this.joints.Add(joint);
        }
Пример #2
0
        private void PresentHinge(PresentationViewController presentationViewController)
        {
            var count = 10.0f;

            var material = SCNMaterial.Create();

            material.Diffuse.Contents        = NSColor.White;
            material.Specular.Contents       = NSColor.White;
            material.LocksAmbientWithDiffuse = true;

            var cubeWidth  = 10.0f / count;
            var cubeHeight = 0.2f;
            var cubeLength = 5.0f;
            var offset     = 0;
            var height     = 5 + count * cubeWidth;

            SCNNode oldModel = null;

            for (int i = 0; i < count; ++i)
            {
                var model = SCNNode.Create();

                var worldtr = GroundNode.ConvertTransformToNode(SCNMatrix4.CreateTranslation(-offset + cubeWidth * i, height, 5), null);

                model.Transform = worldtr;

                model.Geometry = SCNBox.Create(cubeWidth, cubeHeight, cubeLength, 0);
                model.Geometry.FirstMaterial = material;

                var body = SCNPhysicsBody.CreateDynamicBody();
                body.Restitution  = 0.6f;
                model.PhysicsBody = body;

                ((SCNView)presentationViewController.View).Scene.RootNode.AddChildNode(model);

                var joint = SCNPhysicsHingeJoint.Create(model.PhysicsBody, new SCNVector3(0, 0, 1), new SCNVector3(-cubeWidth * 0.5f, 0, 0), (oldModel != null ? oldModel.PhysicsBody : null), new SCNVector3(0, 0, 1), new SCNVector3(cubeWidth * 0.5f, 0, 0));
                ((SCNView)presentationViewController.View).Scene.PhysicsWorld.AddBehavior(joint);

                Hinges.Add(model);

                oldModel = model;
            }
        }