public ClothSim(Game game, TexturedPlane clothPlane, float clothMass,
                        float structStiffness, float structDamping,
                        float shearStiffness, float shearDamping,
                        float bendStiffness, float bendDamping)
            : base(game)
        {
            this.clothPlane = clothPlane;

            //create sim data
            CreateSimVertices(clothPlane, clothMass);

            //connect springs and add constraints
            ConnectSprings(structStiffness, structDamping,
                           shearStiffness, shearDamping,
                           bendStiffness, bendDamping);
        }
Esempio n. 2
0
        private void InitClothScene()
        {
            //cloth attributes
            int length = 10;
            int width = 5;
            int lengthSegments = 20;
            int widthSegments = 15;

            //load in a plane
            clothPlane = new TexturedPlane(this, length, width, lengthSegments, widthSegments, @"checkerboard");
            clothPlane.Initialize();

            //create a cloth sim
            float clothMass = 2.0f;
            float structStiffness = 2.0f;
            float structDamping = 0.02f;
            float shearStiffness = 2.0f;
            float shearDamping = 0.02f;
            float bendStiffness = 2.0f;
            float bendDamping = 0.02f;
            clothSim = new ClothSim(this, clothPlane, clothMass, structStiffness, structDamping, shearStiffness, shearDamping, bendStiffness, bendDamping);
            clothSim.ConstraintIterations = 10;

            //add in a global forceGenerators: gravity
            Gravity gravity = new Gravity(new Vector3(0, -9.81f, 0));
            clothSim.AddGlobalForceGenerator(gravity);

            //constrain the two top corners of the cloth so that we can control it
            topLeftCorner = new PointConstraint(clothSim.SimVertices[0].CurrPosition, clothSim.SimVertices[0]);
            clothSim.Constraints.Add(topLeftCorner);
            topRightCorner = new PointConstraint(clothSim.SimVertices[lengthSegments].CurrPosition, clothSim.SimVertices[lengthSegments]);
            clothSim.Constraints.Add(topRightCorner);

            //create an integrator and assign it to the sim
            float drag = 0.01f;
            Integrator integrator = new VerletNoVelocityIntegrator(this, drag);
            clothSim.Integrator = integrator;
        }
 private void CreateSimVertices(TexturedPlane clothPlane, float clothMass)
 {
     int numVertices = clothPlane.NumVertices;
     float vertexMass = clothMass / numVertices;
     simVertices = new SimVertex[numVertices];
     for (int i = 0; i < numVertices; i++)
     {
         simVertices[i] = new SimVertex(vertexMass, SimObjectType.ACTIVE, i, clothPlane);
         this.AddSimObject(simVertices[i]);
     }
 }