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


C# Geom.GetNearestDistance方法代码示例

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


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

示例1: CreateDistanceGrid

        /// <summary>
        /// Computes the grid.
        /// </summary>
        /// <param name="geom">The geometry.</param>
        /// <exception cref="ArgumentNullException"><c>geometry</c> is null.</exception>
        public void CreateDistanceGrid(Geom geom)
        {
            if (geom == null)
                throw new ArgumentNullException("geom", "Geometry can't be null");

            //Don't create distancegrid for geometry that already have one.
            //NOTE: This should be used to -update- the geometry's distance grid (if grid cell size has changed).
            if (_distanceGrids.ContainsKey(geom.id))
                return;

            //By default, calculate the gridcellsize from the AABB
            if (geom.GridCellSize <= 0)
                geom.GridCellSize = CalculateGridCellSizeFromAABB(ref geom.AABB);

            //Prepare the geometry. Reset the geometry matrix
            Matrix old = geom.Matrix;
            geom.Matrix = Matrix.Identity;

            //Create data needed for gridcalculations
            AABB aabb = new AABB(ref geom.AABB);
            float gridCellSizeInv = 1 / geom.GridCellSize;

            //Note: Physics2d have +2
            int xSize = (int)Math.Ceiling((double)(aabb.Max.X - aabb.Min.X) * gridCellSizeInv) + 1;
            int ySize = (int)Math.Ceiling((double)(aabb.Max.Y - aabb.Min.Y) * gridCellSizeInv) + 1;

            float[,] nodes = new float[xSize, ySize];
            Vector2 vector = aabb.Min;
            for (int x = 0; x < xSize; ++x, vector.X += geom.GridCellSize)
            {
                vector.Y = aabb.Min.Y;
                for (int y = 0; y < ySize; ++y, vector.Y += geom.GridCellSize)
                {
                    nodes[x, y] = geom.GetNearestDistance(ref vector); // shape.GetDistance(vector);
                }
            }
            //restore the geometry
            geom.Matrix = old;

            DistanceGridData distanceGridData = new DistanceGridData();
            distanceGridData.AABB = aabb;
            distanceGridData.GridCellSize = geom.GridCellSize;
            distanceGridData.GridCellSizeInv = gridCellSizeInv;
            distanceGridData.Nodes = nodes;

            _distanceGrids.Add(geom.id, distanceGridData);
        }
开发者ID:akipponn,项目名称:FriendsOnDesktop,代码行数:52,代码来源:DistanceGrid.cs

示例2: ComputeGrid

        /// <summary>
        /// Computes the grid.
        /// </summary>
        /// <param name="geometry">The geometry.</param>
        /// <param name="gridCellSize">Size of the grid cell.</param>
        public void ComputeGrid(Geom geometry, float gridCellSize)
        {
            //Prepare the geometry.
            Matrix old = geometry.Matrix;

            //TODO: Assign geometry.Matrix to Matrix.Identity directly
            Matrix identity = Matrix.Identity;
            geometry.Matrix = identity;

            //Copy the AABB to the grid field
            _aabb = new AABB(geometry.AABB);
            _gridCellSize = gridCellSize;
            _gridCellSizeInv = 1/gridCellSize;

            //NOTE: Using double cast instead of converting.
            int xSize = (int) Math.Ceiling((double) (_aabb.Max.X - _aabb.Min.X)*_gridCellSizeInv) + 1;
            int ySize = (int) Math.Ceiling((double) (_aabb.Max.Y - _aabb.Min.Y)*_gridCellSizeInv) + 1;

            //TODO: Possible optimization (normal)! If the shape is symmetric in X and Y axis, don't calculate the points, replicate them.
            _nodes = new float[xSize,ySize];
            _points = new Vector2[xSize*ySize];
            int i = 0;
            Vector2 vector = _aabb.Min;
            for (int x = 0; x < xSize; ++x, vector.X += gridCellSize)
            {
                vector.Y = _aabb.Min.Y;
                for (int y = 0; y < ySize; ++y, vector.Y += gridCellSize)
                {
                    _nodes[x, y] = geometry.GetNearestDistance(vector); // shape.GetDistance(vector);
                    _points[i] = vector;
                    i += 1;
                }
            }
            //restore the geometry
            geometry.Matrix = old;
        }
开发者ID:amwaterston,项目名称:paradux,代码行数:41,代码来源:Grid.cs


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