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


C# Vector2.getScaled方法代码示例

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


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

示例1: findNearestPositionWhereMapIs

        //
        //     Zzzzz
        //     zYyyz
        //     zyXyz
        //     zyyyz
        //     zzzzz
        //
        public static Vector2<int> findNearestPositionWhereMapIs(bool value, Vector2<int> position, Map2d<bool> image, uint radius, out bool found)
        {
            Vector2<int> outwardIteratorOffsetUnbound;
            Vector2<int> borderMin;
            Vector2<int> borderMax;
            Vector2<int> one;
            Vector2<int> positionAsInt;

            found = false;

            outwardIteratorOffsetUnbound = new Vector2<int>();
            outwardIteratorOffsetUnbound.x = 0;
            outwardIteratorOffsetUnbound.y = 0;

            borderMin = new Vector2<int>();
            borderMin.x = 0;
            borderMin.y = 0;

            borderMax = new Vector2<int>();
            borderMax.x = (int)image.getWidth();
            borderMax.y = (int)image.getLength();

            positionAsInt = new Vector2<int>();
            positionAsInt.x = (int)position.x;
            positionAsInt.y = (int)position.y;

            one = new Vector2<int>();
            one.x = 1;
            one.y = 1;

            for(;;)
            {
                Vector2<int> iteratorOffsetBoundMin;
                Vector2<int> iteratorOffsetBoundMax;
                int x, y;

                if (-outwardIteratorOffsetUnbound.x > radius)
                {
                    break;
                }

                iteratorOffsetBoundMin = Vector2<int>.max(borderMin, outwardIteratorOffsetUnbound + positionAsInt, outwardIteratorOffsetUnbound + positionAsInt, outwardIteratorOffsetUnbound + positionAsInt);
                iteratorOffsetBoundMax = Vector2<int>.min(borderMax, outwardIteratorOffsetUnbound.getScaled(-1) + one + positionAsInt, borderMax, borderMax);

                for (y = (int)(iteratorOffsetBoundMin.y); y < iteratorOffsetBoundMax.y; y++ )
                {
                    for( x = (int)(iteratorOffsetBoundMin.x); x < iteratorOffsetBoundMax.x; x++ )
                    {
                        // just find at the border
                        if (y == (int)(iteratorOffsetBoundMin.y) || y == iteratorOffsetBoundMax.y - 1 || x == (int)(iteratorOffsetBoundMin.x) || x == iteratorOffsetBoundMax.x - 1)
                        {
                            bool valueAtPoint;

                            valueAtPoint = image.readAt(x, y);

                            if (valueAtPoint == value)
                            {
                                found = true;

                                Vector2<int> result;

                                result = new Vector2<int>();
                                result.x = x;
                                result.y = y;

                                return result;
                            }
                        }
                    }
                }

                outwardIteratorOffsetUnbound.x--;
                outwardIteratorOffsetUnbound.y--;
            }

            found = false;

            return new Vector2<int>();
        }
开发者ID:PtrMan,项目名称:ai2,代码行数:86,代码来源:Find.cs

示例2: calculateRelativePositionsForRadius

        //
        //     Zzzzz
        //     zYyyz
        //     zyXyz
        //     zyyyz
        //     zzzzz
        //
        private static List<Vector2<int>> calculateRelativePositionsForRadius(int radius)
        {
            List<Vector2<int>> resultOffsets;

            Vector2<int> outwardIteratorOffsetUnbound;
            Vector2<int> one;

            outwardIteratorOffsetUnbound = new Vector2<int>();
            outwardIteratorOffsetUnbound.x = 0;
            outwardIteratorOffsetUnbound.y = 0;

            one = new Vector2<int>();
            one.x = 1;
            one.y = 1;

            resultOffsets = new List<Vector2<int>>();

            for (; ; )
            {
                Vector2<int> iteratorOffsetBoundMin;
                Vector2<int> iteratorOffsetBoundMax;
                int x, y;

                if (-outwardIteratorOffsetUnbound.x > radius)
                {
                    break;
                }

                iteratorOffsetBoundMin = outwardIteratorOffsetUnbound;
                iteratorOffsetBoundMax = outwardIteratorOffsetUnbound.getScaled(-1) + one;

                for (y = (int)(iteratorOffsetBoundMin.y); y < iteratorOffsetBoundMax.y; y++)
                {
                    for (x = (int)(iteratorOffsetBoundMin.x); x < iteratorOffsetBoundMax.x; x++)
                    {
                        // just add the border
                        if( y == (int)(iteratorOffsetBoundMin.y) || y == iteratorOffsetBoundMax.y - 1 || x ==  (int)(iteratorOffsetBoundMin.x) || x == iteratorOffsetBoundMax.x - 1 )
                        {
                            Vector2<int> newOffset;

                            newOffset = new Vector2<int>();
                            newOffset.x = x;
                            newOffset.y = y;

                            resultOffsets.Add(newOffset);
                        }

                    }
                }

                outwardIteratorOffsetUnbound.x--;
                outwardIteratorOffsetUnbound.y--;
            }

            return resultOffsets;
        }
开发者ID:PtrMan,项目名称:ai2,代码行数:63,代码来源:OperatorFindNearestPosition.cs


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