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


C# IContact.ContactMade方法代码示例

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


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

示例1: Collide

        public void Collide(ref Vector3 position, float radius, IContact contact, int loopCount = 5)
        {
            trianglesTested = 0;
            this.loopCount = 0;

            foreach (ITriangleSelector triangleSelector in selectors)
            {
                BoundingBox bounds;

                bounds.Min.X = position.X - radius * 1.25f;
                bounds.Min.Y = position.Y - radius * 1.25f;
                bounds.Min.Z = position.Z - radius * 1.25f;
                bounds.Max.X = position.X + radius * 1.25f;
                bounds.Max.Y = position.Y + radius * 1.25f;
                bounds.Max.Z = position.Z + radius * 1.25f;
                triangleSelector.Select(bounds, triangles);

                for (int i = 0; i != loopCount; i++, this.loopCount++)
                {
                    Vector3 resolvedPosition = Vector3.Zero;
                    Vector3 iPoint = Vector3.Zero;
                    Triangle iTriangle;
                    int iEdge = -1;
                    float iMin = float.MaxValue;
                    bool collided = false;

                    iTriangle.A = Vector3.Zero;
                    iTriangle.B = Vector3.Zero;
                    iTriangle.C = Vector3.Zero;
                    iTriangle.Normal = Vector3.Zero;
                    iTriangle.Dist = 0;

                    for (int j = 0; j != triangles.Count; j++)
                    {
                        Triangle triangle = triangles[j];
                        Vector3 point;
                        Nullable<float> t = triangle.Intersect(position, -triangle.Normal, out point);
                        bool hit = false;

                        trianglesTested++;

                        if (t.HasValue)
                        {
                            if (t.Value > 0 && t.Value < iMin && t.Value < radius)
                            {
                                resolvedPosition = point + triangle.Normal * radius;
                                iTriangle = triangle;
                                iPoint = point;
                                iEdge = -1;
                                iMin = t.Value;
                                collided = true;
                                hit = true;
                            }
                        }
                        if (!hit)
                        {
                            for (int k = 0; k != 3; k++)
                            {
                                Vector3 a = triangle[k];
                                Vector3 b = triangle[(k + 1) % 3];
                                Vector3 a2b = b - a;
                                Vector3 a2p = position - a;
                                Vector3 c = a;
                                float s = Vector3.Dot(a2b, a2p);

                                if (s > 0)
                                {
                                    s /= a2b.LengthSquared();
                                    if (s < 1)
                                    {
                                        c = a + s * a2b;
                                    }
                                    else
                                    {
                                        c = b;
                                    }
                                }

                                Vector3 d = position - c;
                                float len = d.Length();

                                if (len < radius && len < iMin)
                                {
                                    resolvedPosition = c + Vector3.Normalize(d) * radius;
                                    iTriangle = triangle;
                                    iPoint = c;
                                    iEdge = k;
                                    iMin = len;
                                    collided = true;
                                }
                            }
                        }
                    }
                    if (collided)
                    {
                        if (contact.ContactMade(triangleSelector, iTriangle, iPoint, iEdge))
                        {
                            position = resolvedPosition;
                        }
                    }
//.........这里部分代码省略.........
开发者ID:djmacgames,项目名称:MonoCollisionFramework,代码行数:101,代码来源:Collider.cs


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