Exemple #1
0
        public Basis(Basis parent, Hinge hinge, int DataSetRows)
        {
            if (parent != null)
            {
                Hinges.AddRange(parent.Hinges);
            }

            Parent = parent;
            ht     = new double[DataSetRows];
            for (int h = 0; h < ht.Length; h++)
            {
                ht[h] = 1.0;
            }
            htExists = new bool[DataSetRows];

            Hinges.Add(hinge);
        }
        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;
            }
        }