Ejemplo n.º 1
0
        public ClothBody3d(TrianglesFromGrid source, double radius, double mass, double stretchStiffness, double bendStiffness, Matrix4x4d RTS)
            : base(source.NumParticles, radius, mass)
        {
            StretchStiffness = stretchStiffness;
            BendStiffness    = bendStiffness;

            CreateParticles(source, RTS);
            CreateConstraints(source.Rows, source.Columns);
        }
Ejemplo n.º 2
0
        private void CreateParticles(TrianglesFromGrid source, Matrix4x4d RTS)
        {
            for (int i = 0; i < NumParticles; i++)
            {
                Vector4d pos = RTS * source.Positions[i].xyz1;
                Positions[i] = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
                Predicted[i] = Positions[i];
            }

            int numIndices = source.NumIndices;

            Indices = new int[numIndices];

            for (int i = 0; i < numIndices; i++)
            {
                Indices[i] = source.Indices[i];
            }
        }
Ejemplo n.º 3
0
        void Start()
        {
            TrianglesFromGrid source = new TrianglesFromGrid(radius, width, depth);

            Matrix4x4d T  = Matrix4x4d.Translate(new Vector3d(0.0, height, 0.0));
            Matrix4x4d R  = Matrix4x4d.Rotate(new Vector3d(0.0, 0.0, 0.0));
            Matrix4x4d RT = T * R;

            Body          = new ClothBody3d(source, radius, mass, stretchStiffness, bendStiffness, RT);
            Body.Dampning = 1.0;

            Vector3 min = new Vector3((float)(-width / 2 - 0.1),
                                      (float)(height - 0.1),
                                      (float)(-depth / 2 - 0.1));
            Vector3 max = new Vector3((float)(width / 2 + 0.1),
                                      (float)(height + 0.1),
                                      (float)(-depth / 2 + 0.1));

            StaticBounds = new Box3d(min, max);

            Body.MarkAsStatic(StaticBounds);

            Solver = new Solver3d();
            Solver.AddBody(Body);
            Solver.AddForce(new GravitationalForce3d());
            //Solver.AddCollision(new PlanarCollision3d(Vector3.up, 0));
            Solver.SolverIterations    = 2;
            Solver.CollisionIterations = 2;
            Solver.SleepThreshold      = 1;
            //setting compute shader of solver
            Solver.ApplyExternalForcesShader  = ApplyExternalForces;
            Solver.EstimatePositionsShader    = EstimatePositions;
            Solver.ResolveCollisionsShader    = ResolveCollisions;
            Solver.ConstraintPositionsShader  = ConstraintPositions;
            Solver.UpdateVelocitiesShader     = UpdateVelocities;
            Solver.ConstraintVelocitiesShader = ConstraintVelocities;
            Solver.UpdatePositionsShader      = UpdatePositions;
            Solver.GPUmode = GPUmode;
            Solver.init();

            CreateSpheres();
        }
Ejemplo n.º 4
0
        void Start()
        {
            double stretchStiffness = 0.25;
            double bendStiffness    = 0.5;
            double mass             = 1.0;
            double radius           = 0.125;

            double width  = 5.0;
            double height = 4.0;
            double depth  = 5.0;

            TrianglesFromGrid source = new TrianglesFromGrid(radius, width, depth);

            Matrix4x4d T  = Matrix4x4d.Translate(new Vector3d(0.0, height, 0.0));
            Matrix4x4d R  = Matrix4x4d.Rotate(new Vector3d(0.0, 0.0, 0.0));
            Matrix4x4d RT = T * R;

            Body          = new ClothBody3d(source, radius, mass, stretchStiffness, bendStiffness, RT);
            Body.Dampning = 1.0;

            Vector3d min = new Vector3d(-width / 2 - 0.1, height - 0.1, -depth / 2 - 0.1);
            Vector3d max = new Vector3d(width / 2 + 0.1, height + 0.1, -depth / 2 + 0.1);

            StaticBounds = new Box3d(min, max);

            Body.MarkAsStatic(StaticBounds);

            Solver = new Solver3d();
            Solver.AddBody(Body);
            Solver.AddForce(new GravitationalForce3d());
            Solver.AddCollision(new PlanarCollision3d(Vector3d.UnitY, 0));
            Solver.SolverIterations    = 2;
            Solver.CollisionIterations = 2;
            Solver.SleepThreshold      = 1;

            RenderEvent.AddRenderEvent(Camera.main, DrawOutline);

            CreateSpheres();
        }