Пример #1
0
        public void AddConstraint(string name, IPhysicsObject physObj1, IPhysicsObject physObj2,
                                  CreateConstraintCallback callback)
        {
            ConstraintPair pair = new ConstraintPair();

            pair.Name           = name;
            pair.Callback       = callback;
            pair.PhysicsObject1 = physObj1;
            pair.PhysicsObject2 = physObj2;

            constraints.Add(pair);
        }
Пример #2
0
        private void ConstructClothParticles(List<Vector3> vertices, List<int> indices)
        {
            foreach (Vector3 vertex in vertices)
            {
                MataliObject particle = new MataliObject(null);
                particle.Copy(particleTemplate);
                particle.Collidable = true;
                particle.Interactable = true;
                particle.CompoundInitialWorldTransform =
                    particle.RelativeTransform * 
                    RelativeTransform *
                    Matrix.CreateTranslation(vertex);

                particles.Add(particle);
            }

            // use a hashmap to make sure that we don't create duplicate constraints between the same
            // two vertices
            Dictionary<string, bool> constraintTable = new Dictionary<string, bool>();
            int id0, id1, s, l;
            string key;
            float distance;
            Vector3 position1 = Vector3.Zero, position2 = Vector3.Zero;
            for (int i = 0; i < indices.Count; i += 3)
            {
                for (int j = 0; j < 3; ++j)
                {
                    id0 = indices[i + j];
                    id1 = indices[i + (j + 1) % 3];

                    s = Math.Min(id0, id1);
                    l = Math.Max(id0, id1);

                    key = s + "_" + l;
                    if (!constraintTable.ContainsKey(key))
                    {
                        constraintTable.Add(key, true);

                        ConstraintPair pair = new ConstraintPair();
                        pair.Name = uniqueName + " Point Cloth Constraint " + key;
                        pair.PhysicsObject1 = particles[s];
                        pair.PhysicsObject2 = particles[l];
                        pair.Callback = delegate(Constraint constraint)
                        {
                            constraint.PhysicsObject1.MainWorldTransform.GetPosition(ref position1);
                            constraint.PhysicsObject2.MainWorldTransform.GetPosition(ref position2);
                            constraint.SetAnchor1(position1);
                            constraint.SetAnchor2(position2);
                            distance = Vector3.Distance(position1, position2);
                            constraint.Distance = Streachable ? distance : -distance;
                            constraint.Force = Stiffness;
                            constraint.EnableBreak = Tearable;
                            constraint.MinBreakVelocity = MinTearVelocity;
                        };

                        constraints.Add(pair);
                    }
                }
            }

            constraintTable.Clear();
        }
Пример #3
0
        private void ConstructClothParticles(List <Vector3> vertices, List <int> indices)
        {
            foreach (Vector3 vertex in vertices)
            {
                MataliObject particle = new MataliObject(null);
                particle.Copy(particleTemplate);
                particle.Collidable   = true;
                particle.Interactable = true;
                particle.CompoundInitialWorldTransform =
                    particle.RelativeTransform *
                    RelativeTransform *
                    Matrix.CreateTranslation(vertex);

                particles.Add(particle);
            }

            // use a hashmap to make sure that we don't create duplicate constraints between the same
            // two vertices
            Dictionary <string, bool> constraintTable = new Dictionary <string, bool>();
            int     id0, id1, s, l;
            string  key;
            float   distance;
            Vector3 position1 = Vector3.Zero, position2 = Vector3.Zero;

            for (int i = 0; i < indices.Count; i += 3)
            {
                for (int j = 0; j < 3; ++j)
                {
                    id0 = indices[i + j];
                    id1 = indices[i + (j + 1) % 3];

                    s = Math.Min(id0, id1);
                    l = Math.Max(id0, id1);

                    key = s + "_" + l;
                    if (!constraintTable.ContainsKey(key))
                    {
                        constraintTable.Add(key, true);

                        ConstraintPair pair = new ConstraintPair();
                        pair.Name           = uniqueName + " Point Cloth Constraint " + key;
                        pair.PhysicsObject1 = particles[s];
                        pair.PhysicsObject2 = particles[l];
                        pair.Callback       = delegate(Constraint constraint)
                        {
                            constraint.PhysicsObject1.MainWorldTransform.GetPosition(ref position1);
                            constraint.PhysicsObject2.MainWorldTransform.GetPosition(ref position2);
                            constraint.SetAnchor1(position1);
                            constraint.SetAnchor2(position2);
                            distance                    = Vector3.Distance(position1, position2);
                            constraint.Distance         = Streachable ? distance : -distance;
                            constraint.Force            = Stiffness;
                            constraint.EnableBreak      = Tearable;
                            constraint.MinBreakVelocity = MinTearVelocity;
                        };

                        constraints.Add(pair);
                    }
                }
            }

            constraintTable.Clear();
        }
Пример #4
0
        /// <summary>
        /// Creates a constraint between two existing physical objects.
        /// </summary>
        /// <remarks>
        /// The constraints are not actually added at this stage, but in the Update method.
        /// </remarks>
        /// <param name="name"></param>
        /// <param name="physObj1"></param>
        /// <param name="physObj2"></param>
        /// <param name="callback"></param>
        public void CreateConstraint(string name, IPhysicsObject physObj1, IPhysicsObject physObj2, 
            CreateConstraintCallback callback)
        {
            ConstraintPair pair = new ConstraintPair();
            pair.Name = name;
            pair.Callback = callback;
            pair.PhysicsObject1 = physObj1;
            pair.PhysicsObject2 = physObj2;

            constraintsToBeAdded.Add(pair);
        }