void Start()
        {
            Matrix4x4d T, R;

            double spacing = 0.125;
            double radius  = spacing;
            double mass    = 1.0;

            System.Random rnd = new System.Random(0);

            Vector3 min    = new Vector3(-1, -1, -1);
            Vector3 max    = new Vector3(1, 1, 1);
            Box3d   bounds = new Box3d(min, max);

            ParticlesFromBounds source = new ParticlesFromBounds(spacing, bounds);

            T = Matrix4x4d.Translate(new Vector3d(0.0, 4.0, 0.0));
            R = Matrix4x4d.Rotate(new Vector3d(0.0, 0.0, 25.0));

            RidgidBody3d body = new RidgidBody3d(source, radius, mass, T * R);

            body.Dampning = 1.0;
            body.RandomizePositions(rnd, radius * 0.01);

            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;

            CreateSpheres();
        }
Exemple #2
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();
        }
Exemple #3
0
        void Start()
        {
            Matrix4x4d T  = Matrix4x4d.Translate(new Vector3d(0.0, 6.0, 0.0));
            Matrix4x4d R  = Matrix4x4d.Rotate(new Vector3d(0.0, 0.0, 0.0));
            Matrix4x4d TR = T * R;

            double radius    = 0.25;
            double stiffness = 0.2;
            double mass      = 1.0;

            System.Random rnd = new System.Random(0);

            Vector3d min    = new Vector3d(-5.0, -1.0, -0.5);
            Vector3d max    = new Vector3d(5.0, 1.0, 0.5);
            Box3d    bounds = new Box3d(min, max);
            TetrahedronsFromBounds source = new TetrahedronsFromBounds(radius, bounds);

            Body          = new DeformableBody3d(source, radius, mass, stiffness, TR);
            Body.Dampning = 1.0;
            Body.RandomizePositions(rnd, radius * 0.01);
            Body.RandomizeConstraintOrder(rnd);

            Vector3d smin = new Vector3d(min.x, min.y + 6.0, min.z - 0.1);
            Vector3d smax = new Vector3d(min.x + 0.5, max.y + 6.0, max.z + 0.1);

            StaticBounds = new Box3d(smin, smax);
            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();
        }
Exemple #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();
        }