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


C# AABB.Union方法代码示例

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


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

示例1: WorldBound

 public AABB WorldBound(Point[] vertices)
 {
     var pts = vertices;
     var res = new AABB(pts[this.v0.VertexIndex], pts[this.v1.VertexIndex]);
     res.Union(pts[v2.VertexIndex]);
     return res;
 }
开发者ID:HungryBear,项目名称:rayden,代码行数:7,代码来源:TriangleDataInfo.cs

示例2: WorldBound

 public AABB WorldBound(Point[] vertices)
 {
     var pts = vertices;
     var res = new AABB(pts[this.v0], pts[this.v1]);
     res.Union(pts[v2]);
     return res;
 }
开发者ID:HungryBear,项目名称:rayden,代码行数:7,代码来源:TriangleInfo.cs

示例3: BoundingBox

 public AABB BoundingBox()
 {
     var bbox = new AABB();
     foreach (var vertex in Vertices)
     {
         bbox.Union(vertex);
     }
     return bbox;
 }
开发者ID:HungryBear,项目名称:rayden,代码行数:9,代码来源:SceneGeometryInfo.cs

示例4: FindBestSplit

        private void FindBestSplit(List<Triangle> list, int begin, int end, out float splitValue, out int bestAxis)
        {
            splitValue = 0;
            if (end - begin == 2)
            {
                splitValue = (list[begin].WorldBound(sceneVertices).Max[0] + list[begin].WorldBound(sceneVertices).Min[0] + list[end - 1].WorldBound(sceneVertices).Max[0] + list[end - 1]
                    .WorldBound(sceneVertices).Min[0]) / 2f;
                bestAxis = 0;
            }
            else
            {
                Point mean2 = new Point(), var = new Point();

                for (int i = begin; i < end; i++)
                    mean2 += list[i].WorldBound(sceneVertices).Max + list[i].WorldBound(sceneVertices).Min;
                mean2 /= end - begin;

                for (int i = begin; i < end; i++)
                {
                    Vector v = list[i].WorldBound(sceneVertices).Max + list[i].WorldBound(sceneVertices).Min - mean2;
                    v.x *= v.x;
                    v.y *= v.y;
                    v.z *= v.z;
                    var += v;
                }
                // Select axis with more variance
                if (var.x > var.y && var.x > var.z)
                    bestAxis = 0;
                else if (var.y > var.z)
                    bestAxis = 1;
                else
                    bestAxis = 2;

                if (costSamples > 1)
                {
                    AABB nodeBounds = new AABB();//!!!!
                    for (int i = begin; i < end; i++)
                        nodeBounds = nodeBounds.Union(list[i].WorldBound(sceneVertices));

                    Vector d = nodeBounds.Max - nodeBounds.Min;
                    float totalSA = (2f * (d.x * d.y + d.y * d.z + d.z * d.x));
                    float invTotalSA = 1f / totalSA;

                    // Sample cost for split at some points
                    float increment = 2f * d[bestAxis] / (costSamples + 1);
                    float bestCost = float.PositiveInfinity;
                    for (float splitVal = 2f * nodeBounds.Min[bestAxis] + increment; splitVal < 2f * nodeBounds.Max[bestAxis]; splitVal += increment)
                    {
                        int nBelow = 0, nAbove = 0;
                        AABB bbBelow = new AABB(Point.Zero), bbAbove = new AABB(Point.Zero);
                        for (int j = begin; j < end; j++)
                        {
                            if ((list[j].WorldBound(sceneVertices).Max[bestAxis] + list[j].WorldBound(sceneVertices).Min[bestAxis]) < splitVal)
                            {
                                nBelow++;
                                bbBelow = bbBelow.Union(list[j].WorldBound(sceneVertices));
                            }
                            else
                            {
                                nAbove++;
                                bbAbove = bbAbove.Union(list[j].WorldBound(sceneVertices));
                            }
                        }
                        Vector dBelow = bbBelow.Max - bbBelow.Min;
                        Vector dAbove = bbAbove.Max - bbAbove.Min;
                        float belowSA = 2f * ((dBelow.x * dBelow.y + dBelow.x * dBelow.z + dBelow.y * dBelow.z));
                        float aboveSA = 2f * ((dAbove.x * dAbove.y + dAbove.x * dAbove.z + dAbove.y * dAbove.z));
                        float pBelow = belowSA * invTotalSA;
                        float pAbove = aboveSA * invTotalSA;
                        float eb = (nAbove == 0 || nBelow == 0) ? emptyBonus : 0;
                        float cost = traversalCost + isectCost * (1f - eb) * (pBelow * nBelow + pAbove * nAbove);
                        // Update best split if this is lowest cost so far
                        if (cost < bestCost)
                        {
                            bestCost = cost;
                            splitValue = splitVal;
                        }
                    }
                }
                else
                {
                    // Split in half around the mean center
                    splitValue = mean2[bestAxis];
                }
            }
        }
开发者ID:HungryBear,项目名称:rayden,代码行数:86,代码来源:BvhDataAdapter.cs

示例5: CalcBound

 internal void CalcBound()
 {
     bounds = new AABB();
     foreach (var extTriangle in triangles)
     {
         bounds = bounds.Union(scene.Vertices[extTriangle.v0]).Union(scene.Vertices[extTriangle.v1]).Union(scene.Vertices[extTriangle.v2]);
     }
 }
开发者ID:HungryBear,项目名称:rayden,代码行数:8,代码来源:TriangleMesh.cs

示例6: Point

        public static AABB operator &(Transform tr, AABB b) {
            Transform M = tr;
            Point pt = new Point(b.Min.x, b.Min.y, b.Min.z);
            AABB ret = new AABB((tr & pt));


            ret.Union(tr & new Point(b.Max.x, b.Min.y, b.Min.z));
            ret.Union(tr & new Point(b.Min.x, b.Max.y, b.Min.z));
            ret.Union(tr & new Point(b.Min.x, b.Min.y, b.Max.z));
            ret.Union(tr & new Point(b.Min.x, b.Max.y, b.Max.z));
            ret.Union(tr & new Point(b.Max.x, b.Max.y, b.Min.z));
            ret.Union(tr & new Point(b.Max.x, b.Min.y, b.Max.z));
            ret.Union(tr & new Point(b.Max.x, b.Max.y, b.Max.z));
            return ret;
        }
开发者ID:HungryBear,项目名称:rayden,代码行数:15,代码来源:Transform.cs

示例7: BuildSubTree

        private Node BuildSubTree(List<Triangle> primitives, int start, int end)
        {
            if (start - end == 0)
                return null;
            AABB bound = primitives.GetRange(start, end - start).Select(prim => prim.WorldBound(sceneVertices)).Aggregate((b1, b2) => b1.Union(b2));
            var node = new Node() { Bound = bound, Primitives =  new List<TriangleDataInfo>()};
            bvhNodesCount++;
            if ((end - start) <= PrimitivesInNode)
            {

                var firstOffset = sortedPrims.Count;
                for (var i = start; i < end; ++i)
                {
                    var primNum = i;
                    sortedPrims.Add(triangles[primNum]);
                }
                node.PrimitiveIndexStart = firstOffset;
                node.Primitives = primitives.GetRange(start, end - start);
                return node;
            }
            var centroidBounds = new AABB();
            for (var i = start; i < end; ++i)
                centroidBounds = centroidBounds.Union(primitives[i].WorldBound(sceneVertices).Center);
            int dim = centroidBounds.MaximumExtent();

            if ((MathLab.SmallEnough(centroidBounds.Min[dim], centroidBounds.Max[dim])))
            {
                var firstOffset = start;
                for (int i = start, ii = 0; i < end; ++i, ii++)
                {
                    var primNum = i;
                    sortedPrims.Add(triangles[primNum]);
                }

                node.PrimitiveIndexStart = firstOffset;
                node.Primitives = primitives.GetRange(start, end - start);

                return node;
            }

            var mid = (start + end) / 2;
            node.Left = this.BuildSubTree(primitives, start, mid);
            node.Right = this.BuildSubTree(primitives, mid+1, end);
            return node;
        }
开发者ID:HungryBear,项目名称:rayden,代码行数:45,代码来源:TopDownBvhAccell.cs


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