当前位置: 首页>>代码示例>>C#>>正文


C# SoftBody.SetMass方法代码示例

本文整理汇总了C#中BulletSharp.SoftBody.SoftBody.SetMass方法的典型用法代码示例。如果您正苦于以下问题:C# SoftBody.SetMass方法的具体用法?C# SoftBody.SetMass怎么用?C# SoftBody.SetMass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BulletSharp.SoftBody.SoftBody的用法示例。


在下文中一共展示了SoftBody.SetMass方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateRope

		public static SoftBody CreateRope(SoftBodyWorldInfo worldInfo, Vector3 from, Vector3 to, int res, int fixeds)
		{
            // Create nodes
            int r = res + 2;
            Vector3[] x = new Vector3[r];
            float[] m = new float[r];

            for (int i = 0; i < r; i++)
            {
                Vector3.Lerp(ref from, ref to, i / (float)(r - 1), out x[i]);
                m[i] = 1;
            }

            SoftBody psb = new SoftBody(worldInfo, r, x, m);
            if ((fixeds & 1) != 0)
                psb.SetMass(0, 0);
            if ((fixeds & 2) != 0)
                psb.SetMass(r - 1, 0);

            // Create links
            for (int i = 1; i < r; i++)
            {
                psb.AppendLink(i - 1, i);
            }

            return psb;
		}
开发者ID:sinkingsugar,项目名称:BulletSharpPInvoke,代码行数:27,代码来源:SoftBodyHelpers.cs

示例2: CreatePatch

		public static SoftBody CreatePatch(SoftBodyWorldInfo worldInfo, Vector3 corner00, Vector3 corner10, Vector3 corner01, Vector3 corner11, int resx, int resy, int fixeds, bool gendiags)
		{
            // Create nodes
            if ((resx < 2) || (resy < 2))
                return null;

            int rx = resx;
            int ry = resy;
            int tot = rx * ry;
            Vector3[] x = new Vector3[tot];
            float[] m = new float[tot];

            for (int iy = 0; iy < ry; iy++)
            {
                float ty = iy / (float)(ry - 1);
                Vector3 py0, py1;
                Vector3.Lerp(ref corner00, ref corner01, ty, out py0);
                Vector3.Lerp(ref corner10, ref corner11, ty, out py1);
                for (int ix = 0; ix < rx; ix++)
                {
                    float tx = ix / (float)(rx - 1);
                    int index = rx * iy + ix;
                    Vector3.Lerp(ref py0, ref py1, tx, out x[index]);
                    m[index] = 1;
                }
            }

            SoftBody psb = new SoftBody(worldInfo, tot, x, m);

            if ((fixeds & 1) != 0)
                psb.SetMass(0, 0);
            if ((fixeds & 2) != 0)
                psb.SetMass(rx - 1, 0);
            if ((fixeds & 4) != 0)
                psb.SetMass(rx * (ry - 1), 0);
            if ((fixeds & 8) != 0)
                psb.SetMass(rx * (ry - 1) + rx - 1, 0);

            // Create links and faces
            for (int iy = 0; iy < ry; ++iy)
            {
                for (int ix = 0; ix < rx; ++ix)
                {
                    int ixy = rx * iy + ix;
                    int ix1y = ixy + 1;
                    int ixy1 = rx * (iy + 1) + ix;

                    bool mdx = (ix + 1) < rx;
                    bool mdy = (iy + 1) < ry;
                    if (mdx)
                        psb.AppendLink(ixy, ix1y);
                    if (mdy)
                        psb.AppendLink(ixy, ixy1);
                    if (mdx && mdy)
                    {
                        int ix1y1 = ixy1 + 1;
                        if (((ix + iy) & 1) != 0)
                        {
                            psb.AppendFace(ixy, ix1y, ix1y1);
                            psb.AppendFace(ixy, ix1y1, ixy1);
                            if (gendiags)
                            {
                                psb.AppendLink(ixy, ix1y1);
                            }
                        }
                        else
                        {
                            psb.AppendFace(ixy1, ixy, ix1y);
                            psb.AppendFace(ixy1, ix1y, ix1y1);
                            if (gendiags)
                            {
                                psb.AppendLink(ix1y, ixy1);
                            }
                        }
                    }
                }
            }

            return psb;
		}
开发者ID:sinkingsugar,项目名称:BulletSharpPInvoke,代码行数:80,代码来源:SoftBodyHelpers.cs


注:本文中的BulletSharp.SoftBody.SoftBody.SetMass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。