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


C# BoundingBox.GetCornersUnsafe方法代码示例

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


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

示例1: IntersectLine

        public unsafe bool IntersectLine(ref LineD ll, out double startOffset, out double endOffset)
        {
            var box = new BoundingBox(ll.From, ll.From);
            box.Include(ll.To);

            int firstFace = -1;
            uint faces = 0;
            bool complicated = false;

            Vector3* corners = stackalloc Vector3[8];

            box.GetCornersUnsafe(corners);

            for (int i = 0; i < 8; ++i)
            {
                int face;
                MyCubemapHelpers.GetCubeFace(ref corners[i], out face);

                if (firstFace == -1)
                    firstFace = face;
                else if (firstFace != face) complicated = true;

                faces |= (uint)(1 << face);
            }

            if (complicated)
                return IntersectLineCornerCase(ref ll, faces, out startOffset, out endOffset);

            // Later on we will have split the line per sextant already.

            // From here on I calculate how many times to split the line to account for the surface curvature.
            // 

            return IntersectLineFace(ref ll, firstFace, out startOffset, out endOffset);
        }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:35,代码来源:MyPlanetShapeProvider.cs

示例2: IntersectBoundingBoxInternal

        protected unsafe ContainmentType IntersectBoundingBoxInternal(ref BoundingBox box, float lodLevel)
        {
            int firstFace = -1;
            uint faces = 0;
            bool complicated = false;

            float minHeight;
            float maxHeight;

            Vector3* corners = stackalloc Vector3[8];

            box.GetCornersUnsafe(corners);

            for (int i = 0; i < 8; ++i)
            {
                int face;
                MyCubemapHelpers.GetCubeFace(ref corners[i], out face);

                if (firstFace == -1)
                    firstFace = face;
                else if (firstFace != face) complicated = true;

                faces |= (uint)(1 << face);
            }

            if (Vector3.Zero.IsInsideInclusive(ref box.Min, ref box.Max))
            {
                minHeight = 0;
            }
            else
            {
                var clamp = Vector3.Clamp(Vector3.Zero, box.Min, box.Max);
                minHeight = clamp.Length();
            }

            { // Calculate furthest point in BB
                Vector3 end;
                Vector3 c = box.Center;

                if (c.X < 0)
                    end.X = box.Min.X;
                else
                    end.X = box.Max.X;

                if (c.Y < 0)
                    end.Y = box.Min.Y;
                else
                    end.Y = box.Max.Y;

                if (c.Z < 0)
                    end.Z = box.Min.Z;
                else
                    end.Z = box.Max.Z;

                maxHeight = end.Length();
            }

            if (complicated)
                return IntersectBoundingBoxCornerCase(ref box, faces, corners, minHeight, maxHeight);

            BoundingBox query = new BoundingBox(new Vector3(float.PositiveInfinity, float.PositiveInfinity, minHeight), new Vector3(float.NegativeInfinity, float.NegativeInfinity, maxHeight));

            for (int i = 0; i < 8; ++i)
            {
                Vector2 tex;
                MyCubemapHelpers.CalculateTexcoordForFace(ref corners[i], firstFace, out tex);

                if (tex.X < query.Min.X) query.Min.X = tex.X;
                if (tex.X > query.Max.X) query.Max.X = tex.X;
                if (tex.Y < query.Min.Y) query.Min.Y = tex.Y;
                if (tex.Y > query.Max.Y) query.Max.Y = tex.Y;
            }

            query.Min.Z = ((query.Min.Z - m_radius - m_detailScale) - m_minHillHeight) * m_heightRatioRecip;
            query.Max.Z = ((query.Max.Z - m_radius) - m_minHillHeight) * m_heightRatioRecip;

            return m_heightmap.Faces[firstFace].QueryHeight(ref query);
        }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:78,代码来源:MyPlanetShapeProvider.cs

示例3: GetBounds

        /**
         * Takes the x and y bounds of the box and queries the heightmap for the minimum and maximum height in the box.
         *
         * The values are returned in the query box itself as the Z bounds.
         *
         * This only works if all vertices of the box are in the same face.
         */
        public unsafe void GetBounds(ref BoundingBox box)
        {
            int firstFace = -1;
            Vector3* corners = stackalloc Vector3[8];

            box.GetCornersUnsafe(corners);

            for (int i = 0; i < 8; ++i)
            {
                int face;
                MyCubemapHelpers.GetCubeFace(ref corners[i], out face);

                if (firstFace == -1)
                    firstFace = face;
            }

            BoundingBox query = new BoundingBox(new Vector3(float.PositiveInfinity, float.PositiveInfinity, 0), new Vector3(float.NegativeInfinity, float.NegativeInfinity, 0));

            for (int i = 0; i < 8; ++i)
            {
                Vector2 tex;
                MyCubemapHelpers.CalculateTexcoordForFace(ref corners[i], firstFace, out tex);

                if (tex.X < query.Min.X) query.Min.X = tex.X;
                if (tex.X > query.Max.X) query.Max.X = tex.X;
                if (tex.Y < query.Min.Y) query.Min.Y = tex.Y;
                if (tex.Y > query.Max.Y) query.Max.Y = tex.Y;
            }

            m_heightmap.Faces[firstFace].GetBounds(ref query);

            box.Min.Z = query.Min.Z * m_heightRatio + InnerRadius;
            box.Max.Z = query.Max.Z * m_heightRatio + InnerRadius;
        }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:41,代码来源:MyPlanetShapeProvider.cs

示例4: GetRuleBounds

        private unsafe void GetRuleBounds(ref BoundingBox request, out BoundingBox ruleBounds)
        {
            Vector3* vertices = stackalloc Vector3[8];

            ruleBounds.Min = new Vector3(float.PositiveInfinity);
            ruleBounds.Max = new Vector3(float.NegativeInfinity);

            request.GetCornersUnsafe(vertices);

            float latitude, longitude;

            if (Vector3.Zero.IsInsideInclusive(ref request.Min, ref request.Max))
            {
                ruleBounds.Min.X = 0;
            }
            else
            {
                var clamp = Vector3.Clamp(Vector3.Zero, request.Min, request.Max);
                ruleBounds.Min.X = m_planetShape.DistanceToRatio(clamp.Length());
            }

            { // Calculate furthest point in BB
                Vector3 end;
                Vector3 c = request.Center;

                if (c.X < 0)
                    end.X = request.Min.X;
                else
                    end.X = request.Max.X;

                if (c.Y < 0)
                    end.Y = request.Min.Y;
                else
                    end.Y = request.Max.Y;

                if (c.Z < 0)
                    end.Z = request.Min.Z;
                else
                    end.Z = request.Max.Z;

                ruleBounds.Max.X = m_planetShape.DistanceToRatio(end.Length());
            }

            // If box intercepts Y axis (north south axis).
            if (request.Min.X < 0 && request.Min.Z < 0 && request.Max.X > 0 && request.Max.Z > 0)
            {
                ruleBounds.Min.Z = -1;
                ruleBounds.Max.Z = 3;

                for (int i = 0; i < 8; i++)
                {
                    float len = vertices[i].Length();
                    latitude = vertices[i].Y / len;
                    if (ruleBounds.Min.Y > latitude) ruleBounds.Min.Y = latitude;
                    if (ruleBounds.Max.Y < latitude) ruleBounds.Max.Y = latitude;
                }
            }
            else
            {
                for (int i = 0; i < 8; i++)
                {
                    float len = vertices[i].Length();

                    vertices[i] /= len;
                    latitude = vertices[i].Y;

                    Vector2 lon = new Vector2(-vertices[i].X, -vertices[i].Z);
                    lon.Normalize();

                    longitude = lon.Y;
                    if (lon.X > 0)
                    {
                        longitude = 2 - longitude;
                    }

                    if (ruleBounds.Min.Y > latitude) ruleBounds.Min.Y = latitude;
                    if (ruleBounds.Max.Y < latitude) ruleBounds.Max.Y = latitude;

                    if (ruleBounds.Min.Z > longitude) ruleBounds.Min.Z = longitude;
                    if (ruleBounds.Max.Z < longitude) ruleBounds.Max.Z = longitude;
                }
            }
        }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:83,代码来源:MyPlanetMaterialProvider.cs

示例5: GetBounds

        /**
         * Takes the x and y bounds of the box and queries the heightmap for the minimum and maximum height in the box.
         *
         * The values are returned in the query box itself as the Z bounds.
         *
         * This only works if all vertices of the box are in the same face.
         */
        public unsafe void GetBounds(ref BoundingBox box)
        {
            Vector3* corners = stackalloc Vector3[8];

            box.GetCornersUnsafe(corners);

            GetBounds(corners, 8, out box.Min.Z, out box.Max.Z);
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:15,代码来源:MyPlanetShapeProvider.cs

示例6: Contains

        internal override ContainmentType Contains(ref BoundingBox queryAabb, ref BoundingSphere querySphere, float lodVoxelSize)
        {
            ContainmentType outerContainment, innerContainment;

            BoundingSphere sphere = new BoundingSphere(
                m_translation,
                m_outerRadius + lodVoxelSize);

            sphere.Contains(ref queryAabb, out outerContainment);
            if (outerContainment == ContainmentType.Disjoint)
                return ContainmentType.Disjoint;

            sphere.Radius = m_innerRadius - lodVoxelSize;
            sphere.Contains(ref queryAabb, out innerContainment);
            if (innerContainment == ContainmentType.Contains)
                return ContainmentType.Contains;

            if (m_cachedNoise != null)
            {
                float minDistance = m_canyonHalfDeviation;
                float maxDistance = -m_hillHalfDeviation;

                unsafe
                {
                    const int cornersLength = 8;
                    Vector3* corners = stackalloc Vector3[cornersLength];
                    queryAabb.GetCornersUnsafe(corners);
                    bool first = true;

                    for (int i = 0; i < cornersLength; ++i)
                    {
                        Vector3 localPosition = corners[i] - m_translation;
                        float distanceMin = localPosition.Length();

                        localPosition.Normalize();

                        Vector2 encodedPosition = Vector2.Zero;

                        Encode(ref localPosition, ref encodedPosition);

                        Vector2 samplePosition = encodedPosition * NOISE_RESOLUTION;
                        Vector2I position = Vector2I.Floor(samplePosition);

                        Vector2 unpackedValue = m_cachedNoise[position.X*(NOISE_RESOLUTION + 1)+position.Y].ToVector2();
                        if (first)
                        {
                            minDistance = unpackedValue.Y;
                            maxDistance = unpackedValue.X;
                            first = false;
                        }
                        else
                        {
                            minDistance = MathHelper.Max(minDistance, unpackedValue.Y);
                            maxDistance = MathHelper.Min(maxDistance, unpackedValue.X);
                        }
                    }
                }
       
                sphere.Radius = m_shapeAttributes.Radius - maxDistance + lodVoxelSize;

                sphere.Contains(ref queryAabb, out outerContainment);
                if (outerContainment == ContainmentType.Disjoint)
                    return ContainmentType.Disjoint;

                sphere.Radius = m_shapeAttributes.Radius - minDistance - lodVoxelSize;
                sphere.Contains(ref queryAabb, out innerContainment);
                if (innerContainment == ContainmentType.Contains)
                    return ContainmentType.Contains;
            }

            return ContainmentType.Intersects;
        }
开发者ID:avivbeeri,项目名称:SpaceEngineers,代码行数:72,代码来源:MyCsgShapePlanet.cs


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