protected virtual void OnSceneGUI()
        {
            BallAndSocketJoint ballAndSocket = (BallAndSocketJoint)target;

            EditorGUI.BeginChangeCheck();

            EditorUtilities.EditPivot(ballAndSocket.worldFromA, ballAndSocket.worldFromB, ballAndSocket.AutoSetConnected,
                                      ref ballAndSocket.PositionLocal, ref ballAndSocket.PositionInConnectedEntity, ballAndSocket);
        }
示例#2
0
        /// <summary>
        /// Creates a rope-like object by connecting several ball and socket joints.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="parentTrans"></param>
        public static void AddRope(Scene scene, TransformNode parentTrans)
        {
            Vector3 size     = new Vector3(1.5f, 0.25f, 0.25f);
            Vector3 location = new Vector3(0, 9, 0);

            IPhysicsObject link0 = null;

            Color[] colors = { Color.Red,    Color.Orange, Color.Yellow, Color.Green, Color.Blue,
                               Color.Indigo, Color.Violet };

            PrimitiveModel capsule = new Capsule(size.Y, size.X, 12);

            for (int i = 0; i < 7; i++)
            {
                TransformNode pileTrans = new TransformNode();
                pileTrans.Translation = location;

                Material linkMat = new Material();
                linkMat.Diffuse       = colors[i].ToVector4();
                linkMat.Specular      = Color.White.ToVector4();
                linkMat.SpecularPower = 10;

                GeometryNode link1 = new GeometryNode("Link " + i);
                link1.Model = capsule;
                link1.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;
                link1.Material = linkMat;

                link1.AddToPhysicsEngine     = true;
                link1.Physics.Interactable   = true;
                link1.Physics.Collidable     = true;
                link1.Physics.Shape          = ShapeType.Capsule;
                link1.Physics.Mass           = 2.0f;
                link1.Physics.LinearDamping  = 1f;
                link1.Physics.AngularDamping = new Vector3(1f, 1f, 1f);

                parentTrans.AddChild(pileTrans);
                pileTrans.AddChild(link1);

                Vector3 pivot = location + parentTrans.Translation;
                pivot.Y += (size.X - size.Y) * 0.5f;

                BallAndSocketJoint joint = new BallAndSocketJoint(pivot);
                joint.Pin           = -Vector3.UnitY;
                joint.MaxConeAngle  = 0.0f;
                joint.MaxTwistAngle = 10.0f * MathHelper.Pi / 180;

                ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(link1.Physics, link0, joint);

                link0    = link1.Physics;
                location = new Vector3(location.X, location.Y
                                       - (size.X - size.Y), location.Z);
            }
        }
        private ICollisionJoint[] GetBridgeConstraints(List <ICollisionShape> shape)
        {
            ICollisionJoint[] constraints = new ICollisionJoint[30];

            int    idx    = 0;
            double zValue = -1.8;
            double yValue = 1.2;

            for (int i = 0; i < 10; i++)
            {
                constraints[idx] = new BallAndSocketJoint(
                    shape[i],
                    shape[i + 1],
                    new Vector3d(0.5, yValue, zValue),
                    0.9,
                    0.00016);
                idx++;

                constraints[idx] = new BallAndSocketJoint(
                    shape[i],
                    shape[i + 1],
                    new Vector3d(-0.5, yValue, zValue),
                    0.9,
                    0.00016);
                idx++;

                constraints[idx] = new AngularJoint(
                    shape[i],
                    shape[i + 1],
                    new Vector3d(-0.5, yValue, zValue),
                    new Vector3d(1.0, 0.0, 0.0),
                    new Vector3d(0.0, 1.0, 0.0),
                    0.5,
                    0.008,
                    0.008);
                idx++;

                zValue = -1.25;
                yValue = 0.0;
            }

            return(constraints);
        }
示例#4
0
        public ICollisionJoint[] LoadSimulationJoints(
            ICollisionShape[] objects)
        {
            var xmlDoc = new XmlDocument();

            xmlDoc.Load(FileNameObjectProperties);

            XmlNodeList xmlList = xmlDoc.SelectNodes(nodePathJoints);

            ICollisionJoint[] joints = new ICollisionJoint[xmlList.Count];

            for (int i = 0; i < xmlList.Count; i++)
            {
                //Object index A
                int indexA = Convert.ToInt32(xmlList[i][objectIndexAAttribute].InnerText);

                //Object index B
                int indexB = Convert.ToInt32(xmlList[i][objectIndexBAttribute].InnerText);

                XmlNodeList jointPropertiesList = xmlList[i].SelectNodes(jointProperties);

                ICollisionJoint[] joint = new ICollisionJoint[jointPropertiesList.Count];

                for (int j = 0; j < jointPropertiesList.Count; j++)
                {
                    //Joint type
                    var jointType = (JointType)Convert.ToInt32(jointPropertiesList[j][this.jointType].InnerText);

                    //Restore coefficient
                    double K = Convert.ToDouble(jointPropertiesList[j][restoreCoeffAttribute].InnerText);

                    //Stretch coefficient
                    double C = Convert.ToDouble(jointPropertiesList[j][stretchCoeffAttribute].InnerText);

                    //Position
                    var startAnchorPosition = new Vector3d(
                        Convert.ToDouble(jointPropertiesList[j][positionJointAttribute].Attributes["x"].Value),
                        Convert.ToDouble(jointPropertiesList[j][positionJointAttribute].Attributes["y"].Value),
                        Convert.ToDouble(jointPropertiesList[j][positionJointAttribute].Attributes["z"].Value));

                    //Action Axis
                    var actionAxis = new Vector3d(
                        Convert.ToDouble(jointPropertiesList[j][this.actionAxis].Attributes["x"].Value),
                        Convert.ToDouble(jointPropertiesList[j][this.actionAxis].Attributes["y"].Value),
                        Convert.ToDouble(jointPropertiesList[j][this.actionAxis].Attributes["z"].Value));

                    switch (jointType)
                    {
                    case JointType.Fixed:
                        joint [j] = new FixedJoint(
                            objects[indexA],
                            objects[indexB],
                            K,
                            C);
                        break;

                    case JointType.BallAndSocket:
                        joint[j] = new BallAndSocketJoint(
                            objects[indexA],
                            objects[indexB],
                            startAnchorPosition,
                            K,
                            C);
                        break;

                    case JointType.Slider:
                        joint[j] = new SliderJoint(
                            objects[indexA],
                            objects[indexB],
                            startAnchorPosition,
                            actionAxis,
                            K,
                            C);

                        joint[j].SetLinearLimit(Convert.ToDouble(jointPropertiesList[j][linearLimitMin].InnerText), Convert.ToDouble(jointPropertiesList[j][linearLimitMax].InnerText));

                        break;

                    case JointType.Piston:
                        joint[j] = new PistonJoint(
                            objects[indexA],
                            objects[indexB],
                            startAnchorPosition,
                            actionAxis,
                            K,
                            C);

                        joint[j].SetAxis1AngularLimit(
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMin].InnerText),
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMax].InnerText));

                        joint[j].SetLinearLimit(
                            Convert.ToDouble(jointPropertiesList[j][linearLimitMin].InnerText),
                            Convert.ToDouble(jointPropertiesList[j][linearLimitMax].InnerText));

                        break;

                    case JointType.Hinge:
                        joint[j] = new HingeJoint(
                            objects[indexA],
                            objects[indexB],
                            startAnchorPosition,
                            actionAxis,
                            K,
                            C);

                        joint[j].SetAxis1AngularLimit(
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMin].InnerText),
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMax].InnerText));

                        joint[j].SetAxis1Motor(3.0, 0.15);
                        break;

                    case JointType.Universal:
                        joint[j] = new UniversalJoint(
                            objects[indexA],
                            objects[indexB],
                            startAnchorPosition,
                            actionAxis,
                            new Vector3d(1.0, 0.0, 0.0),
                            K,
                            C);

                        joint[j].SetAxis1AngularLimit(
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMin].InnerText),
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMax].InnerText));
                        joint[j].SetAxis2AngularLimit(
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMin].InnerText),
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMax].InnerText));
                        break;

                    case JointType.Hinge2:
                        joint[j] = new Hinge2Joint(
                            objects[indexA],
                            objects[indexB],
                            startAnchorPosition,
                            actionAxis,
                            new Vector3d(1.0, 0.0, 0.0),
                            K,
                            1.0,
                            C);

                        joint[j].SetAxis1AngularLimit(
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMin].InnerText),
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMax].InnerText));

                        //joint[j].SetAxis2Motor(4.0, 3.0);

                        break;

                    case JointType.Angular:
                        joint[j] = new AngularJoint(
                            objects[indexA],
                            objects[indexB],
                            startAnchorPosition,
                            new Vector3d(1.0, 0.0, 0.0),
                            new Vector3d(0.0, 1.0, 0.0),
                            0.16,
                            0.008,
                            0.008);

                        break;
                    }
                    joints[i] = joint[j];
                }
            }

            return(joints);
        }