コード例 #1
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
        void InitClusterCollide1()
        {
            const float s   = 8;
            SoftBody    psb = SoftBodyHelpers.CreatePatch(softBodyWorldInfo, new Vector3(-s, 0, -s),
                                                          new Vector3(+s, 0, -s),
                                                          new Vector3(-s, 0, +s),
                                                          new Vector3(+s, 0, +s),
                                                          17, 17,//9,9,//31,31,
                                                          1 + 2 + 4 + 8,
                                                          true);
            Material pm = psb.AppendMaterial();

            pm.Lst             = 0.4f;
            pm.Flags          -= FMaterial.DebugDraw;
            psb.Cfg.DF         = 1;
            psb.Cfg.SrhrCl     = 1;
            psb.Cfg.SRSplitCl  = 0;
            psb.Cfg.Collisions = FCollisions.CLSS | FCollisions.CLRS;
            psb.GenerateBendingConstraints(2, pm);

            psb.CollisionShape.Margin = 0.05f;
            psb.SetTotalMass(50);

            // pass zero in generateClusters to create  cluster for each tetrahedron or triangle
            psb.GenerateClusters(0);
            //psb.GenerateClusters(64);

            SoftWorld.AddSoftBody(psb);

            CreateRigidBodyStack(10);

            CullingEnabled = false;
        }
コード例 #2
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
 void InitClusterCollide2()
 {
     for (int i = 0; i < 3; ++i)
     {
         SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, TorusMesh.Vertices, TorusMesh.Indices);
         Material pm  = psb.AppendMaterial();
         pm.Flags -= FMaterial.DebugDraw;
         psb.GenerateBendingConstraints(2, pm);
         psb.Cfg.PIterations = 2;
         psb.Cfg.DF          = 1;
         psb.Cfg.SshrCl      = 1;
         psb.Cfg.SSSplitCl   = 0;
         psb.Cfg.SkhrCl      = 0.1f;
         psb.Cfg.SKSplitCl   = 1;
         psb.Cfg.Collisions  = FCollisions.CLSS | FCollisions.CLRS;
         psb.RandomizeConstraints();
         Matrix m = Matrix.RotationYawPitchRoll((float)Math.PI / 2 * (i & 1), (float)Math.PI / 2 * (1 - (i & 1)), 0)
                    * Matrix.Translation(3 * i, 2, 0);
         psb.Transform(m);
         psb.Scale(new Vector3(2, 2, 2));
         psb.SetTotalMass(50, true);
         psb.GenerateClusters(16);
         SoftWorld.AddSoftBody(psb);
     }
 }
コード例 #3
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
        void InitSticks()
        {
            const int   n   = 16;
            const int   sg  = 4;
            const float sz  = 5;
            const float hg  = 4;
            const float inf = 1 / (float)(n - 1);

            for (int y = 0; y < n; ++y)
            {
                for (int x = 0; x < n; ++x)
                {
                    Vector3 org = new Vector3(-sz + sz * 2 * x * inf,
                                              -10, -sz + sz * 2 * y * inf);

                    SoftBody psb = SoftBodyHelpers.CreateRope(softBodyWorldInfo, org,
                                                              org + new Vector3(hg * 0.001f, hg, 0), sg, 1);

                    psb.Cfg.DP  = 0.005f;
                    psb.Cfg.Chr = 0.1f;
                    for (int i = 0; i < 3; ++i)
                    {
                        psb.GenerateBendingConstraints(2 + i);
                    }
                    psb.SetMass(1, 0);
                    psb.SetTotalMass(0.01f);
                    SoftWorld.AddSoftBody(psb);
                }
            }
            CreateBigBall(new Vector3(0, 13, 0));
        }
コード例 #4
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
        void InitCloth()
        {
            float    s   = 8;
            SoftBody psb = SoftBodyHelpers.CreatePatch(softBodyWorldInfo,
                                                       new Vector3(-s, 0, -s),
                                                       new Vector3(+s, 0, -s),
                                                       new Vector3(-s, 0, +s),
                                                       new Vector3(+s, 0, +s),
                                                       31, 31,
                                                       1 + 2 + 4 + 8, true);

            psb.CollisionShape.Margin = 0.5f;
            Material pm = psb.AppendMaterial();

            pm.Lst    = 0.4f;
            pm.Flags -= FMaterial.DebugDraw;
            psb.GenerateBendingConstraints(2, pm);
            psb.TotalMass = 150;
            SoftWorld.AddSoftBody(psb);

            CreateRigidBodyStack(10);
            cutting = true;

            CullingEnabled = false;
        }
コード例 #5
0
        protected void SetConfig(SoftBody sb)
        {
            sb.Cfg.AeroModel   = this.AeroModel;
            sb.Cfg.DF          = this.DynamicFrictionCoefficient;
            sb.Cfg.DP          = this.DampingCoefficient;
            sb.Cfg.PR          = this.PressureCoefficient;
            sb.Cfg.LF          = this.LiftCoefficient;
            sb.Cfg.VC          = this.VolumeConservation;
            sb.Cfg.Collisions |= FCollisions.VFSS;

            sb.Cfg.Chr = this.RigidContactHardness;
            sb.Cfg.Shr = this.SoftContactHardness;


            sb.Cfg.DG  = this.DragCoefficient;
            sb.Cfg.Ahr = this.AnchorHardness;
            if (this.IsVolumeMass)
            {
                sb.SetVolumeMass(this.Mass);
            }
            else
            {
                sb.SetTotalMass(this.Mass, false);
            }

            if (this.GenerateBendingConstraints)
            {
                sb.GenerateBendingConstraints(this.BendingDistance);
            }
        }
コード例 #6
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
        // Aerodynamic forces, 50x1g flyers
        void InitAero()
        {
            const float s        = 2;
            const int   segments = 6;
            const int   count    = 50;
            Random      random   = new Random();

            for (int i = 0; i < count; ++i)
            {
                SoftBody psb = SoftBodyHelpers.CreatePatch(softBodyWorldInfo,
                                                           new Vector3(-s, 0, -s), new Vector3(+s, 0, -s),
                                                           new Vector3(-s, 0, +s), new Vector3(+s, 0, +s),
                                                           segments, segments, 0, true);
                Material pm = psb.AppendMaterial();
                pm.Flags -= FMaterial.DebugDraw;
                psb.GenerateBendingConstraints(2, pm);
                psb.Cfg.LF        = 0.004f;
                psb.Cfg.DG        = 0.0003f;
                psb.Cfg.AeroModel = AeroModel.VTwoSided;
                Matrix     trans = Matrix.Identity;
                Vector3    ra    = 0.1f * GetRandomVector(random);
                Vector3    rp    = 75 * GetRandomVector(random) + new Vector3(-50, 15, 0);
                Quaternion rot   = Quaternion.RotationYawPitchRoll(
                    (float)Math.PI / 8 + ra.X, (float)-Math.PI / 7 + ra.Y, ra.Z);
                trans *= Matrix.RotationQuaternion(rot);
                trans *= Matrix.Translation(rp);
                psb.Transform(trans);
                psb.TotalMass = 0.1f;
                psb.AddForce(new Vector3(0, (float)random.NextDouble(), 0), 0);
                SoftWorld.AddSoftBody(psb);
            }

            CullingEnabled = false;
        }
コード例 #7
0
ファイル: Physics.cs プロジェクト: diqost/bullet
 void Init_Collide3()
 {
     {
         const float s   = 8;
         SoftBody    psb = SoftBodyHelpers.CreatePatch(softBodyWorldInfo, new Vector3(-s, 0, -s),
                                                       new Vector3(+s, 0, -s),
                                                       new Vector3(-s, 0, +s),
                                                       new Vector3(+s, 0, +s),
                                                       15, 15, 1 + 2 + 4 + 8, true);
         psb.Materials[0].Lst = 0.4f;
         psb.Cfg.Collisions  |= FCollisions.VFSS;
         psb.TotalMass        = 150;
         SoftWorld.AddSoftBody(psb);
     }
     {
         const float s   = 4;
         Vector3     o   = new Vector3(5, 10, 0);
         SoftBody    psb = SoftBodyHelpers.CreatePatch(softBodyWorldInfo,
                                                       new Vector3(-s, 0, -s) + o,
                                                       new Vector3(+s, 0, -s) + o,
                                                       new Vector3(-s, 0, +s) + o,
                                                       new Vector3(+s, 0, +s) + o,
                                                       7, 7, 0, true);
         Material pm = psb.AppendMaterial();
         pm.Lst    = 0.1f;
         pm.Flags -= FMaterial.DebugDraw;
         psb.GenerateBendingConstraints(2, pm);
         psb.Materials[0].Lst = 0.5f;
         psb.Cfg.Collisions  |= FCollisions.VFSS;
         psb.TotalMass        = 150;
         SoftWorld.AddSoftBody(psb);
         cutting = true;
     }
 }
コード例 #8
0
        /// <summary>
        /// Apply these SoftBody settings to this SoftBody
        /// </summary>
        /// <param name="softBody"></param>
        public void ConfigureSoftBody(SoftBody softBody)
        {
            softBody.Scale(scale.ToBullet());

            BulletSharp.SoftBody.Material pm = softBody.Materials[0];

            sBMaterial.SetSBMaterial(pm);

            config.CopyToBulletSBConfig(softBody.Cfg);

            if (allNodeBendingConstraints)
            {
                for (int i = 0; i < softBody.Nodes.Count - 1; ++i)
                {
                    softBody.GenerateBendingConstraints(1 + i);
                }
            }
            else
            {
                softBody.GenerateBendingConstraints(bendingConstraintDistance, pm);
            }

            if (randomizeConstraints)
            {
                softBody.RandomizeConstraints();
            }

            if (generateClusters)
            {
                softBody.GenerateClusters(0);
            }

            softBody.SetTotalMass(totalMass, fromFaces);

            softBody.SetPose(bvolume, bframe);
        }
コード例 #9
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
        void InitTorus()
        {
            SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, TorusMesh.Vertices, TorusMesh.Indices);

            psb.GenerateBendingConstraints(2);
            psb.Cfg.PIterations = 2;
            psb.RandomizeConstraints();
            Matrix m = Matrix.RotationYawPitchRoll(0, (float)Math.PI / 2, 0) *
                       Matrix.Translation(0, 4, 0);

            psb.Transform(m);
            psb.Scale(new Vector3(2, 2, 2));
            psb.SetTotalMass(50, true);
            SoftWorld.AddSoftBody(psb);
            cutting = true;
        }
コード例 #10
0
        void Init_Aero2()
        {
            const float s        = 5;
            const int   segments = 10;
            const int   count    = 5;
            Vector3     pos      = new Vector3(-s * segments, 0, 0);
            float       gap      = 0.5f;

            for (int i = 0; i < count; ++i)
            {
                SoftBody psb = SoftBodyHelpers.CreatePatch(softBodyWorldInfo, new Vector3(-s, 0, -s * 3),
                                                           new Vector3(+s, 0, -s * 3),
                                                           new Vector3(-s, 0, +s),
                                                           new Vector3(+s, 0, +s),
                                                           segments, segments * 3,
                                                           1 + 2, true);

                psb.CollisionShape.Margin = 0.5f;
                Material pm = psb.AppendMaterial();
                pm.Lst    = 0.0004f;
                pm.Flags -= FMaterial.DebugDraw;
                psb.GenerateBendingConstraints(2, pm);

                psb.Cfg.LF = 0.05f;
                psb.Cfg.DG = 0.01f;

                //psb.Cfg.LF = 0.004f;
                //psb.Cfg.DG = 0.0003f;

                psb.Cfg.PIterations = 2;
                psb.Cfg.AeroModel   = AeroModel.VTwoSidedLiftDrag;


                psb.WindVelocity = new Vector3(4, -12.0f, -25.0f);

                pos += new Vector3(s * 2 + gap, 0, 0);
                Matrix trs = Matrix.RotationX((float)Math.PI / 2) * Matrix.Translation(pos);
                psb.Transform(trs);
                psb.TotalMass = 2.0f;

                SoftBodyHelpers.ReoptimizeLinkOrder(psb);

                SoftWorld.AddSoftBody(psb);
            }

            Graphics.CullingEnabled = false;
        }
コード例 #11
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
 void InitCollide()
 {
     for (int i = 0; i < 3; ++i)
     {
         SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, TorusMesh.Vertices, TorusMesh.Indices);
         psb.GenerateBendingConstraints(2);
         psb.Cfg.PIterations = 2;
         psb.Cfg.Collisions |= FCollisions.VFSS;
         psb.RandomizeConstraints();
         Matrix m = Matrix.RotationYawPitchRoll((float)Math.PI / 2 * (i & 1), (float)Math.PI / 2 * (1 - (i & 1)), 0) *
                    Matrix.Translation(3 * i, 2, 0);
         psb.Transform(m);
         psb.Scale(new Vector3(2, 2, 2));
         psb.SetTotalMass(50, true);
         SoftWorld.AddSoftBody(psb);
     }
     cutting = true;
 }
コード例 #12
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
        SoftBody CreateSoftBoulder(Vector3 p, Vector3 s, int np)
        {
            Random random = new Random();

            Vector3[] pts = new Vector3[np];
            for (int i = 0; i < np; ++i)
            {
                pts[i] = GetRandomVector(random) * s;
            }

            SoftBody psb = SoftBodyHelpers.CreateFromConvexHull(softBodyWorldInfo, pts);

            psb.GenerateBendingConstraints(2);
            psb.Translate(p);
            SoftWorld.AddSoftBody(psb);

            return(psb);
        }
コード例 #13
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
        void InitBunny()
        {
            SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, BunnyMesh.Vertices, BunnyMesh.Indices);
            Material pm  = psb.AppendMaterial();

            pm.Lst    = 0.5f;
            pm.Flags -= FMaterial.DebugDraw;
            psb.GenerateBendingConstraints(2, pm);
            psb.Cfg.PIterations = 2;
            psb.Cfg.DF          = 0.5f;
            psb.RandomizeConstraints();
            Matrix m = Matrix.RotationYawPitchRoll(0, (float)Math.PI / 2, 0) *
                       Matrix.Translation(0, 4, 0);

            psb.Transform(m);
            psb.Scale(new Vector3(6, 6, 6));
            psb.SetTotalMass(100, true);
            SoftWorld.AddSoftBody(psb);
            cutting = true;
        }
コード例 #14
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
        SoftBody CreateClusterTorus(Vector3 x, Vector3 a, Vector3 s)
        {
            SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, TorusMesh.Vertices, TorusMesh.Indices);
            Material pm  = psb.AppendMaterial();

            pm.Lst    = 1;
            pm.Flags -= FMaterial.DebugDraw;
            psb.GenerateBendingConstraints(2, pm);
            psb.Cfg.PIterations = 2;
            psb.Cfg.Collisions  = FCollisions.CLSS | FCollisions.CLRS;
            psb.RandomizeConstraints();
            psb.Scale(s);
            Matrix m = Matrix.RotationYawPitchRoll(a.X, a.Y, a.Z) * Matrix.Translation(x);

            psb.Transform(m);
            psb.SetTotalMass(50, true);
            psb.GenerateClusters(64);
            SoftWorld.AddSoftBody(psb);
            return(psb);
        }
コード例 #15
0
        SoftBody Create_SoftBox(Vector3 p, Vector3 s)
        {
            Vector3 h = s * 0.5f;

            Vector3[] c = new Vector3[] {
                h *new Vector3(-1, -1, -1),
                h *new Vector3(+1, -1, -1),
                h *new Vector3(-1, +1, -1),
                h *new Vector3(+1, +1, -1),
                h *new Vector3(-1, -1, +1),
                h *new Vector3(+1, -1, +1),
                h *new Vector3(-1, +1, +1),
                h *new Vector3(+1, +1, +1)
            };
            SoftBody psb = SoftBodyHelpers.CreateFromConvexHull(softBodyWorldInfo, c);

            psb.GenerateBendingConstraints(2);
            psb.Translate(p);
            SoftWorld.AddSoftBody(psb);

            return(psb);
        }