Beispiel #1
0
    private void OnTriggerEnter(Collider other)
    {
        Obstacle obstacle = other.GetComponent <Obstacle>();

        //не виконувати далі, якщо на об'єкті other немає скрипта Obstacle
        if (obstacle == null)
        {
            return;
        }

        //
        List <int> playerKeys         = PlayerData.Keys;
        List <int> obstacleKeysOrigin = obstacle.Keys;
        List <int> obstacleKeys       = PrepareForComparison(obstacleKeysOrigin);

        //спрацює якщо ключі збігаються
        if (SomeMath.ComparisonLists(playerKeys, obstacleKeys))
        {
            OnOvercameObstacle?.Invoke();
        }
        //спрацює якщо ключі не збігаються
        else
        {
            OnDidNotOvercameObstacle?.Invoke();
            OnDidNotOvercameObstacleWithList?.Invoke(SomeMath.CommonListItems(playerKeys, obstacleKeysOrigin));
        }
    }
Beispiel #2
0
            public void SetCellToEdge(GenerationCellInfo cell)
            {
                Vector3 closest;

                SomeMath.ClosestToSegmentTopProjection(data.leftV3, data.rightV3, cell.centerV2, out closest);

                if (SomeMath.LinePointSideMathf(data.leftV2, data.rightV2, cell.centerV2) > 0)
                {
                    //Debuger_K.AddLine(closest, cell.centerV3, Color.white);
                    //Debuger_K.AddLabel(SomeMath.MidPoint(closest, cell.centerV3), "Up");
                    upCell = cell;
                }
                else
                {
                    //Debuger_K.AddLine(closest, cell.centerV3, Color.white);
                    //Debuger_K.AddLabel(SomeMath.MidPoint(closest, cell.centerV3), "Down");
                    downCell = cell;
                }

                if (upCell != null & downCell != null)
                {
                    Vector3 intersection;
                    SomeMath.ClampedRayIntersectXZ(upCell.centerV3, downCell.centerV3 - upCell.centerV3, data.leftV3, data.rightV3, out intersection);
                    float upCellCost   = Vector3.Distance(upCell.centerV3, intersection) * upCell.cell.area.cost;
                    float downCellCost = Vector3.Distance(downCell.centerV3, intersection) * downCell.cell.area.cost;

                    downCell.SetConnection(new CellContentData(data.leftV3, data.rightV3), upCell.cell, downCellCost, upCellCost, intersection);
                    upCell.SetConnection(new CellContentData(data.rightV3, data.leftV3), downCell.cell, upCellCost, downCellCost, intersection);
                }
            }
        private bool IsVisible(int a, int b, TriangulatorDataSet ds)
        {
            Vector2 aPos       = ds.NodePosV2(a);
            Vector2 bPos       = ds.NodePosV2(b);
            Vector2 dir        = bPos - aPos;
            float   curSqrDist = SomeMath.SqrDistance(aPos, bPos);

            foreach (var edge in ds.edges)
            {
                if (edge.Contains(a, b))
                {
                    continue;
                }

                Vector2 intersection;
                if (SomeMath.RayIntersectXZ(
                        aPos, dir,                                  //from, direction
                        ds.NodePosV2(edge.a), ds.NodePosV2(edge.b), //a, b
                        out intersection) &&
                    SomeMath.SqrDistance(aPos, intersection) < curSqrDist)
                {
                    //Debuger3.AddRay(new Vector3(intersection.x, 0, intersection.y), Vector3.up, Color.magenta);
                    //Debuger3.AddLine(ds.NodePosV3(a), new Vector3(intersection.x, 0, intersection.y), Color.magenta);
                    //Debuger3.AddLine(ds.NodePosV3(b), new Vector3(intersection.x, 0, intersection.y), Color.magenta);
                    return(false);
                }
            }

            return(true);
        }
Beispiel #4
0
        public static bool Project(CellContentData data_A, CellContentData data_B, float maxDist, Axis axis, out CellContentData intersection)
        {
            Vector2 a1 = new Vector2(axis == Axis.x ? data_A.a.x : data_A.a.z, data_A.a.y);
            Vector2 a2 = new Vector2(axis == Axis.x ? data_A.b.x : data_A.b.z, data_A.b.y);

            Vector2 b1 = new Vector2(axis == Axis.x ? data_B.a.x : data_B.a.z, data_B.a.y);
            Vector2 b2 = new Vector2(axis == Axis.x ? data_B.b.x : data_B.b.z, data_B.b.y);

            Vector2 i1, i2;

            if (SomeMath.TwoLinesProjectionByX(a1, a2, b1, b2, maxDist, out i1, out i2))
            {
                if (axis == Axis.x)
                {
                    intersection = new CellContentData(new Vector3(i1.x, i1.y, data_A.a.z), new Vector3(i2.x, i2.y, data_A.a.z));
                }
                else
                {
                    intersection = new CellContentData(new Vector3(data_A.a.x, i1.y, i1.x), new Vector3(data_A.a.x, i2.y, i2.x));
                }
                return(true);
            }
            else
            {
                intersection = new CellContentData(Vector3.zero);
                return(false);
            }
        }
Beispiel #5
0
        public static void DoSomething()
        {
            SomeMath math = new SomeMath(Square);

            Console.WriteLine(math(8));


            math = new SomeMath(TimesTen);
            Console.WriteLine(math(8));

            List <int> list = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };
            List <int> evenNumbers = list.FindAll(delegate(int i)
            {
                return(i % 2 == 0);
            });

            foreach (int even in evenNumbers)
            {
                Console.WriteLine(even + " is an even number");
            }

            List <int> oddNumbers = list.FindAll(delegate(int i)
            {
                return(i % 2 == 1);
            });

            foreach (int odd in oddNumbers)
            {
                Console.WriteLine(odd + " is an odd number");
            }



            Console.WriteLine("Lambda Expression Below: \n");

            List <int> oddNumbers2 = list.FindAll(i => i % 2 == 1);

            oddNumbers2.ForEach(i => Console.WriteLine(i));

            List <int> evenNumbers2 = list.FindAll(i => i % 2 == 0);

            evenNumbers2.ForEach(i =>
            {
                Console.WriteLine("Even Number");
                Console.WriteLine(i);
            }

                                 );

            math = new SomeMath(x => x * x);
            Console.WriteLine(math(10));

            Compare comp = (a, number) => a == number.n;

            Console.WriteLine(comp(5, new Number {
                n = 5
            }));
        }
Beispiel #6
0
        public static bool Project2(EdgeAbstract edge_A, EdgeAbstract edge_B, float maxDist, Axis axis, out Vector3 intersectionA, out Vector3 intersectionB)
        {
            Vector2 a1 = new Vector2(axis == Axis.x ? edge_A.a.x : edge_A.a.z, edge_A.a.y);
            Vector2 a2 = new Vector2(axis == Axis.x ? edge_A.b.x : edge_A.b.z, edge_A.b.y);

            Vector2 b1 = new Vector2(axis == Axis.x ? edge_B.a.x : edge_B.a.z, edge_B.a.y);
            Vector2 b2 = new Vector2(axis == Axis.x ? edge_B.b.x : edge_B.b.z, edge_B.b.y);

            Vector2 i1, i2;

            if (SomeMath.TwoLinesProjectionByX(a1, a2, b1, b2, maxDist, out i1, out i2))
            {
                if (axis == Axis.x)
                {
                    intersectionA = new Vector3(i1.x, i1.y, edge_A.a.z);
                    intersectionB = new Vector3(i2.x, i2.y, edge_A.a.z);
                }
                else
                {
                    intersectionA = new Vector3(edge_A.a.x, i1.y, i1.x);
                    intersectionB = new Vector3(edge_A.a.x, i2.y, i2.x);
                }

                return(true);
            }
            else
            {
                intersectionA = Vector3.zero;
                intersectionB = Vector3.zero;
                return(false);
            }
        }
Beispiel #7
0
        public static void DoSomething()
        {
            SomeMath math = new SomeMath(Square);

            Console.WriteLine(math(8));

            List <int> list = new List <int> {
                1, 2, 3, 4, 5, 6, 7
            };
            List <int> evenNumbers = list.FindAll(delegate(int i)
            {
                return(i % 2 == 0);
            });

            foreach (int even in evenNumbers)
            {
                Console.WriteLine(even);
            }
            List <int> oddNumbers = list.FindAll(i => i % 2 == 1);

            oddNumbers.ForEach(i => Console.WriteLine(i));


            math = new SomeMath(x => x * x * x);
            Console.WriteLine(math(8));

            Compare comp = (a, number) => a == number.n;

            Console.WriteLine(comp(5, new Number {
                n = 5
            }));
        }
Beispiel #8
0
        public bool GetClosestToHull(float x, float y, float z, out Cell cell, out Vector3 closestToOutlinePos)
        {
            cell = null;
            closestToOutlinePos = new Vector3();

            if (empty || _mapCell == null)
            {
                return(false);
            }

            float sqrDist = float.MaxValue;

            foreach (var pair in _contourLib)
            {
                CellContentData val        = pair.Key;
                Vector3         curNearest = pair.Key.NearestPoint(x, y, z);
                float           curSqrDist = SomeMath.SqrDistance(curNearest.x, curNearest.y, curNearest.z, x, y, z);

                if (curSqrDist < sqrDist)
                {
                    sqrDist             = curSqrDist;
                    cell                = pair.Value;
                    closestToOutlinePos = curNearest;
                }
            }
            return(true);
        }
Beispiel #9
0
        private void RemoveEdgeFromMapDelegate(int x, int z)
        {
            x = SomeMath.Clamp(0, PathFinder.CELL_GRID_SIZE - 1, x);
            z = SomeMath.Clamp(0, PathFinder.CELL_GRID_SIZE - 1, z);
            //var list = dataMap[SomeMath.Clamp(0, PathFinder.CELL_GRID_SIZE - 1, x)][SomeMath.Clamp(0, PathFinder.CELL_GRID_SIZE - 1, z)];
            //Debug.Log(x + ":"+ z);
            //Debug.Log(dataMap == null);
            //Debug.Log(dataMap[x] == null);
            //Debug.Log(dataMap[x][z] == null);

            List <CellDataMapValue> tempList = new List <CellDataMapValue>(dataMap[x][z]);

            for (int i = tempList.Count - 1; i >= 0; i--)
            {
                if (tempList[i].connection == tempCellConnection)
                {
                    tempList.RemoveAt(i);
                }
            }
            dataMap[x][z] = tempList.ToArray();

            //for (int i = list.Count - 1; i >= 0; i--) {
            //    if(list[i].connection == tempCellConnection)
            //        list.RemoveAt(i);
            //}
        }
Beispiel #10
0
        //Vector2
        public void GetClosestPointToCell(Vector2 targetPos, out Vector3 closestPoint, out bool isOutsideCell)
        {
            float closestSqrDistance = float.MaxValue;

            closestPoint = Vector3.zero;

            foreach (var edgeData in _contentDictionary.Keys)
            {
                if (SomeMath.PointInTriangle(edgeData.leftV2, edgeData.rightV2, centerVector2, targetPos))
                {
                    closestPoint  = new Vector3(targetPos.x, SomeMath.CalculateHeight(edgeData.leftV3, edgeData.rightV3, centerVector3, targetPos.x, targetPos.y), targetPos.y);
                    isOutsideCell = false;
                    return;
                }
                else
                {
                    Vector3 curInte;
                    SomeMath.ClosestToSegmentTopProjection(edgeData.leftV3, edgeData.rightV3, targetPos, true, out curInte);
                    float curSqrDist = SomeMath.SqrDistance(targetPos.x, targetPos.y, curInte.x, curInte.z);

                    if (curSqrDist < closestSqrDistance)
                    {
                        closestSqrDistance = curSqrDist;
                        closestPoint       = curInte;
                    }
                }
            }
            isOutsideCell = true;
            return;
        }
Beispiel #11
0
        /// <summary>
        /// return ray intersection by top projection (if it occured)
        /// </summary>
        public bool RayIntersectXZ(float rayOriginX, float rayOriginY, float rayDirectionX, float rayDirectionZ, out Vector3 result)
        {
            float Rx, Ry, Rz;
            bool  Rb = SomeMath.RayIntersectXZ(rayOriginX, rayOriginY, rayDirectionX, rayDirectionZ, xLeft, yLeft, zLeft, xRight, yRight, zRight, out Rx, out Ry, out Rz);

            result = new Vector3(Rx, Ry, Rz);
            return(Rb);
        }
Beispiel #12
0
 //метод, що "ламає" всі активні елементи тіла гравця
 private void DestroyActiveElements(List <int> list)
 {
     if (SomeMath.WhetherItIsContained(list, _buttonKey))
     {
         _bodyElementObject.SetActive(false);
         _destroyBodyElementObject.SetActive(true);
         OnButtonDestroyed?.Invoke();
     }
 }
Beispiel #13
0
        private bool IsVisible(int a, int b)
        {
            float ax      = _nodes[a].x;
            float ay      = _nodes[a].z;
            float bx      = _nodes[b].x;
            float by      = _nodes[b].z;
            float abx     = bx - ax;
            float aby     = by - ay;
            float sqrDist = SomeMath.SqrDistance(ax, ay, bx, by);

            isVisibleTemp.Clear();

            DDARasterization.DrawLine(ax - chunkPos.x, ay - chunkPos.y, bx - chunkPos.x, by - chunkPos.y, edgeMapPiselSize, IsVisibleDelegate);

            foreach (var edge in isVisibleTemp)
            {
                if (edge.Contains(a, b))
                {
                    continue;
                }

                float ix, iy;
                if (SomeMath.RayIntersect(ax, ay, abx, aby, _nodes[edge.a].x, _nodes[edge.a].z, _nodes[edge.b].x, _nodes[edge.b].z, out ix, out iy) && SomeMath.SqrDistance(ax, ay, ix, iy) < sqrDist)
                {
                    return(false);
                }
            }
            return(true);

            //Vector2 aPos = _nodes[a].positionV2;
            //Vector2 bPos = _nodes[b].positionV2;
            //Vector2 dir = bPos - aPos;
            //float curSqrDist = SomeMath.SqrDistance(aPos, bPos);


            //foreach (var edge in edges) {
            //    if (edge.Contains(a, b))
            //        continue;

            //    Vector2 intersection;
            //    if (SomeMath.RayIntersectXZ(
            //        aPos, dir, //from, direction
            //        NodePosV2(edge.a), NodePosV2(edge.b), //a, b
            //        out intersection)
            //        && SomeMath.SqrDistance(aPos, intersection) < curSqrDist) {

            //        //Debuger3.AddRay(new Vector3(intersection.x, 0, intersection.y), Vector3.up, Color.magenta);
            //        //Debuger3.AddLine(ds.NodePosV3(a), new Vector3(intersection.x, 0, intersection.y), Color.magenta);
            //        //Debuger3.AddLine(ds.NodePosV3(b), new Vector3(intersection.x, 0, intersection.y), Color.magenta);
            //        return false;
            //    }
            //}

            //return true;
        }
        public override ShapeDataAbstract ReturnShapeConstructor(Vector3 worldPos, Vector3 worldScale)
        {
            Matrix4x4 treeMatrix = Matrix4x4.TRS(worldPos, Quaternion.identity, worldScale);
            Matrix4x4 matrix     = treeMatrix * local2world * sphereMatrix;
            Vector3   pos        = matrix.MultiplyPoint3x4(Vector3.zero);
            Vector3   size       = matrix.MultiplyPoint3x4(Vector3.one) - pos;
            float     radius     = SomeMath.Max(size.x, size.y, size.z);
            Bounds    bounds     = new Bounds(pos, new Vector3(radius, radius, radius) * 2);

            return(new ShapeDataSphere(bounds, PathFinder.getUnwalkableArea));
        }
        public void RasterizeTriangle(Vector3 A, Vector3 B, Vector3 C, float voxelSize, int startX, int endX, int startZ, int endZ, Collector3.ShapeCollector volume, sbyte pass, byte area)
        {
            int minX = Mathf.Clamp(Mathf.RoundToInt(SomeMath.Min(A.x, B.x, C.x) / voxelSize) - 1, startX, endX);
            int minZ = Mathf.Clamp(Mathf.RoundToInt(SomeMath.Min(A.z, B.z, C.z) / voxelSize) - 1, startZ, endZ);
            int maxX = Mathf.Clamp(Mathf.RoundToInt(SomeMath.Max(A.x, B.x, C.x) / voxelSize) + 1, startX, endX);
            int maxZ = Mathf.Clamp(Mathf.RoundToInt(SomeMath.Max(A.z, B.z, C.z) / voxelSize) + 1, startZ, endZ);

            if (minX == maxX || minZ == maxZ)
            {
                return; //if too small return
            }
            Vector3[] vectorsStart = new Vector3[3] {
                A, B, C
            };

            for (int x = minX; x < maxX; ++x)
            {
                int vertsInLength1 = ClipPolyToPlane(1f, 0.0f, -x * voxelSize, vectorsStart, 3, ref _polyListXTemp);

                if (vertsInLength1 >= 3)
                {
                    int vertsInLength2 = ClipPolyToPlane(-1f, 0.0f, (x + 1) * voxelSize, _polyListXTemp, vertsInLength1, ref _polyListXFinal);

                    if (vertsInLength2 >= 3)
                    {
                        for (int z = minZ; z < maxZ; ++z)
                        {
                            int vertsInLength3 = ClipPolyToPlane(0.0f, 1f, -z * voxelSize, _polyListXFinal, vertsInLength2, ref _polyListZTemp);

                            if (vertsInLength3 >= 3)
                            {
                                int vertsInLength4 = ClipPolyToPlane(0.0f, -1f, (z + 1) * voxelSize, _polyListZTemp, vertsInLength3, ref _polyListZFinal);
                                if (vertsInLength4 >= 3)
                                {
                                    float min = _polyListZFinal[0].y;
                                    float max = _polyListZFinal[0].y;

                                    for (int index = 1; index < vertsInLength4; ++index)
                                    {
                                        min = Mathf.Min(min, _polyListZFinal[index].y);
                                        max = Mathf.Max(max, _polyListZFinal[index].y);
                                    }

                                    volume.SetVoxel(
                                        Mathf.Abs(x - startX),
                                        Mathf.Abs(z - startZ),
                                        min, max, pass, area);
                                }
                            }
                        }
                    }
                }
            }
        }
        public void AddCover(NodeCoverTemp coverInfo)
        {
            Cover cover = new Cover(coverInfo.positionV3, coverInfo.connection.positionV3, coverInfo.connectionType, coverInfo.normal);

            Vector3 agentNormalPoint = coverInfo.normal * properties.radius;

            foreach (var coverPoint in coverInfo.points)
            {
                Vector3        pointPlusAgentOffset = coverPoint.positionV3 + agentNormalPoint;
                HashSet <Cell> nearbyCells          = new HashSet <Cell>();

                foreach (var edge in coverPoint.edges)
                {
                    CellContentData data = new CellContentData(edge);
                    foreach (var cell in _cells)
                    {
                        if (cell.Contains(data))
                        {
                            nearbyCells.Add(cell);
                        }
                    }
                }

                float   closestSqrDistance = float.MaxValue;
                Cell    closestCell        = null;
                Vector3 closestPoint       = Vector3.zero;

                foreach (var cell in nearbyCells)
                {
                    bool    isOutside;
                    Vector3 currentPoint;
                    cell.GetClosestPointToCell(pointPlusAgentOffset, out currentPoint, out isOutside);

                    float curSqrDistance = SomeMath.SqrDistance(pointPlusAgentOffset, currentPoint);
                    if (curSqrDistance < closestSqrDistance)
                    {
                        closestCell        = cell;
                        closestPoint       = currentPoint;
                        closestSqrDistance = curSqrDistance;
                    }
                }

                if (closestCell == null)
                {
                    //Debuger3.AddDot(coverPoint.positionV3, Color.red);
                    continue;
                }

                NodeCoverPoint coverNode = new NodeCoverPoint(coverPoint.positionV3, closestPoint, closestCell, cover);
                cover.AddCoverPoint(coverNode);
            }

            covers.Add(cover);
        }
Beispiel #17
0
        public void FindNearest(T target)
        {
            target.neighbourAgents.Clear();
            target.neighbourSqrDistances.Clear();
            float    radius       = target.maxRadius;
            float    radisuSqr    = SomeMath.Sqr(radius);
            Vector2  pos          = target.position;
            Bounds2D targetBounds = new Bounds2D(pos.x, pos.y, radius);

            SearchRecursive(target, targetBounds, pos, radisuSqr, root);
        }
 //Vector2
 public bool GetPointInsideCell(Vector2 targetPos, out Vector3 result)
 {
     foreach (var edgeData in _contentDictionary.Keys)
     {
         if (SomeMath.PointInTriangle(edgeData.leftV2, edgeData.rightV2, centerV2, targetPos))
         {
             result = new Vector3(targetPos.x, SomeMath.CalculateHeight(edgeData.leftV3, edgeData.rightV3, centerV3, targetPos.x, targetPos.y), targetPos.y);
             return(true);
         }
     }
     result = Vector3.zero;
     return(false);
 }
Beispiel #19
0
    private void Awake()
    {
        _usedRooms = new List <GameObject>();

        GameObject newRoom;

        _startPosition.z = -_distanceBetweenRooms * _numberOfRoomsToStart;
        Vector3 newPosition = _startPosition;

        List <int> roomIndexes = SomeMath.CreateRandomUniqueIndexes(_numberOfRooms - _numberOfDuplicatedRooms, 0, _rooms.Length);

        for (int i = 0; i < _numberOfRooms - _numberOfDuplicatedRooms; i++)
        {
            newRoom = Instantiate(_rooms[roomIndexes[i]]);
            _usedRooms.Add(newRoom);
        }
        for (int i = 0; i < _numberOfDuplicatedRooms; i++)
        {
            newRoom = Instantiate(_usedRooms[i + _numberOfRoomsToStart]);
            _usedRooms.Add(newRoom);
        }

        for (int i = 0; i < _usedRooms.Count; i++)
        {
            newPosition.z = i * _distanceBetweenRooms;
            _usedRooms[i].transform.position = _startPosition + newPosition;
            _usedRooms[i].transform.parent   = gameObject.transform;

            _usedRooms[i].AddComponent <Room>();
            _usedRooms[i].GetComponent <Room>().RoomNumber = i;
        }

        if (_teleport != null)
        {
            newPosition   = _teleport.transform.position;
            newPosition.z = _usedRooms[_numberOfRooms - _numberOfDuplicatedRooms].transform.position.z + 0.5f;
            _teleport.transform.position = newPosition;
        }

        //ObjectPool
        for (int i = 0; i < _usedRooms.Count; i++)
        {
            _usedRooms[i].SetActive(false);
        }

        for (int i = 0; i < _numberOfRoomsVisibleToPlayer; i++)
        {
            _usedRooms[i].SetActive(true);
        }
    }
Beispiel #20
0
        public static void DoSomething()
        {
            ///////////////////////// TEST
            var numbers1 = new List <int>();
            var numbers  = new List <int> {
                1, 2, 3, 4, 5
            };

            numbers1.Add(8);
            numbers1.Remove(0);


            ///////////////////////// TEST


            SomeMath math = new SomeMath(TimesTen);

            Console.WriteLine(math(8));

            List <int> list = new List <int> {
                1, 2, 3, 4, 5, 6, 7
            };
            List <int> evenNumbers = list.FindAll(delegate(int i)
            {
                return(i % 2 == 0);
            });

            foreach (int even in evenNumbers)
            {
                Console.WriteLine(even);
            }

            List <int> oddNumbers = list.FindAll(i => i % 2 == 1);

            oddNumbers.ForEach(i =>
            {
                Console.WriteLine("Odd number:");
                Console.WriteLine(i);
            }
                               );

            math = new SomeMath(x => x * x * x);
            Console.WriteLine(math(8));

            Compare comp = (a, number) => a == number.n;

            Console.WriteLine(comp(5, new Number {
                n = 5
            }));
        }
Beispiel #21
0
    private void Start()
    {
        _indexes  = new List <int>();
        _bonfires = new List <GameObject>();
        _indexes  = SomeMath.CreateRandomUniqueIndexes(_numberOfBonfires, 0, _transforms.Length);

        for (int i = 0; i < _numberOfBonfires; i++)
        {
            GameObject newBonfire = Instantiate(_bonfirePrefab);
            newBonfire.transform.position = _transforms[_indexes[i]].position;
            newBonfire.transform.parent   = _parent.transform;

            _bonfires.Add(newBonfire);
        }
    }
            public ElipseLine(float Point1x, float Point1y, float Point2x, float Point2y, sbyte Passability)
            {
                point1x     = Point1x;
                point1y     = Point1y;
                point2x     = Point2x;
                point2y     = Point2y;
                passability = Passability;

                float dirX = Point2x - Point1x;
                float dirY = Point2y - Point1y;

                length      = SomeMath.Magnitude(dirX, dirY);
                normalizedX = dirX / length;
                normalizedY = dirY / length;
            }
Beispiel #23
0
        void AddGate(int startCycle, int endCycle, List <CellContentGenericConnection> gates, Vector3 startPos, Vector3 endPos)
        {
            for (int cycle = startCycle; cycle < endCycle; cycle++)
            {
                if (gates[cycle].from.passability == gates[cycle].connection.passability)
                {
                    continue;
                }

                Vector3 ccInt;
                SomeMath.LineIntersectXZ(gates[cycle].leftV3, gates[cycle].rightV3, startPos, endPos, out ccInt);

                AddMove(ccInt, gates[cycle].from);
            }
        }
Beispiel #24
0
        public static void DoSomething()
        {
            SomeMath calc = new SomeMath(Square);

            //(calc) becomes SomeMath(Square(int i))

            Console.WriteLine(calc(9));


            List <int> list = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            List <int> evenNumbers = list.FindAll(delegate(int i)
            {
                return(i % 2 == 0);
                // or for Oddnumbers = ( return (i % 2 == 1))
            });

            foreach (var item in evenNumbers)
            {
                Console.WriteLine(item);
            }


            //####Using Lamda functions

            List <int> oddNumbers = list.FindAll(i => i % 2 == 1);

            oddNumbers.ForEach(i =>
            {
                Console.WriteLine("Odd number is: ");
                Console.WriteLine(i);
            });



            calc = new SomeMath(x => x * x * x);

            Console.WriteLine(calc(8));


            //####Using Lamda functions
            Compare Grades = (a, number) => a == number.t;

            Console.WriteLine(Grades(6, new Number {
                t = 6
            }));
        }
            public CirclePattern(int radius)
            {
                this.radius = radius;
                size        = radius + radius - 1;
                int sqrRadius = (radius - 1) * (radius - 1);

                pattern = new bool[size * size];

                for (int x = 0; x < size; x++)
                {
                    for (int y = 0; y < size; y++)
                    {
                        pattern[(y * size) + x] = SomeMath.SqrDistance(x, y, radius - 1, radius - 1) <= sqrRadius;
                    }
                }
            }
Beispiel #26
0
        public static void FindNearestAgent(PathFinderAgent agent)
        {
            if (agent.updateNeighbourAgents == false)
            {
                return;
            }

            agent.neighbourAgents.Clear();
            agent.neighbourSqrDistances.Clear();
            float    radius       = agent.maxNeighbourDistance;
            float    radisuSqr    = SomeMath.Sqr(radius);
            Vector3  pos          = agent.positionVector3;
            Bounds2D targetBounds = new Bounds2D(pos.x, pos.z, radius);

            SearchRecursive(agent, targetBounds, pos, radisuSqr, root);
        }
Beispiel #27
0
        /// <summary>
        /// check all cell triangles and return Y position if point inside of any triangle
        /// </summary>
        /// <param name="y">result Y if point inside cell</param>
        /// <returns>true if point inside cell</returns>
        public bool GetPointInsideCell(float x, float z, out float y)
        {
            CellContentData edgeData;

            foreach (var pair in _contentDictionary)
            {
                edgeData = pair.Key;
                if (SomeMath.PointInTriangle(centerVector2.x, centerVector2.y, edgeData.xLeft, edgeData.zLeft, edgeData.xRight, edgeData.zRight, x, z))
                {
                    y = SomeMath.CalculateHeight(edgeData.leftV3, edgeData.rightV3, centerVector3, x, z);
                    return(true);
                }
            }
            y = 0;
            return(false);
        }
Beispiel #28
0
        private static void SetInterconnection(Graph graph1, Graph graph2, Cell cell1, Cell cell2, Vector3 node1, Vector3 node2)
        {
            Vector3 intersection;

            SomeMath.ClampedRayIntersectXZ(cell1.centerVector3, cell2.centerVector3 - cell1.centerVector3, node1, node2, out intersection);
            float cell1Cost = Vector3.Distance(cell1.centerVector3, intersection) * cell1.area.cost;
            float cell2Cost = Vector3.Distance(cell2.centerVector3, intersection) * cell2.area.cost;

            Vector3 leftPos, rightPos;

            if (SomeMath.LinePointSideMathf(new Vector2(node1.x, node1.z), new Vector2(node2.x, node2.z), cell1.centerVector2) > 0)
            {
                leftPos  = node2;
                rightPos = node1;
            }
            else
            {
                leftPos  = node1;
                rightPos = node2;
            }

            //Debuger_K.AddLabel(SomeMath.MidPoint(leftPos, cell1.centerV3), "L");
            //Debuger_K.AddLabel(SomeMath.MidPoint(rightPos, cell1.centerV3), "R");

            //Debuger_K.AddLabel(SomeMath.MidPoint(rightPos, cell2.centerV3), "L");
            //Debuger_K.AddLabel(SomeMath.MidPoint(leftPos, cell2.centerV3), "R");

            CellContentData C1C2data = new CellContentData(leftPos, rightPos);
            CellContentData C2C1data = new CellContentData(rightPos, leftPos);

            CellContentGenericConnection C1C2 = new CellContentGenericConnection(C1C2data, cell1, cell2, true, cell1Cost, cell2Cost, intersection);
            CellContentGenericConnection C2C1 = new CellContentGenericConnection(C2C1data, cell2, cell1, true, cell2Cost, cell1Cost, intersection);

            cell1.SetContent(C1C2);
            cell2.SetContent(C2C1);

            cell1.graph.AddEdgeToMap(cell1, cell2, C1C2data);
            cell2.graph.AddEdgeToMap(cell2, cell1, C2C1data);

#if UNITY_EDITOR
            if (Debuger_K.doDebug)
            {
                Debuger_K.AddEdgesInterconnected(graph1.x, graph1.z, graph1.properties, C1C2);
                Debuger_K.AddEdgesInterconnected(graph2.x, graph2.z, graph2.properties, C2C1);
            }
#endif
        }
Beispiel #29
0
        private float intX, intZ;     //intersection position

        public TempEdge(Cell from, Cell to, Vector3 a, Vector3 b)
        {
            this.from = from;
            this.to   = to;
            fromV2    = from.centerVector2;
            toV2      = to.centerVector2;

            Vector3 intersectionV3;

            SomeMath.LineLineIntersectXZ(from.centerVector3, to.centerVector3, a, b, out intersectionV3);
            intX = intersectionV3.x;
            intZ = intersectionV3.z;

            minus    = plus = a;
            minusVal = plusVal = GetSide(a);
            AddNodePos(b);
        }
Beispiel #30
0
        //2 versions for fast adding spheres
        public void AppendSphereWalkable(Vector3 spherePos, float sphereRadius, byte area)
        {
            float voxelSize       = template.voxelSize;
            float voxelSizeHalf   = voxelSize * 0.5f;
            float sphereRadiusSqr = sphereRadius * sphereRadius;
            float maxSlopeY       = Mathf.Sin(template.maxSlope * Mathf.PI / 180) * sphereRadius;

            Vector3 chunkReal   = template.realOffsetedPosition;
            Vector3 sphereLocal = spherePos - chunkReal;

            float sphereY      = spherePos.y;
            float sphereLocalX = sphereLocal.x;
            float sphereLocalZ = sphereLocal.z;

            int xMin = Mathf.Clamp((int)((sphereLocalX - sphereRadius) / voxelSize), 0, template.lengthX_extra);
            int xMax = Mathf.Clamp((int)((sphereLocalX + sphereRadius) / voxelSize) + 1, 0, template.lengthX_extra);
            int zMin = Mathf.Clamp((int)((sphereLocalZ - sphereRadius) / voxelSize), 0, template.lengthZ_extra);
            int zMax = Mathf.Clamp((int)((sphereLocalZ + sphereRadius) / voxelSize) + 1, 0, template.lengthZ_extra);

            for (int x = xMin; x < xMax; x++)
            {
                for (int z = zMin; z < zMax; z++)
                {
                    float distSqr = SomeMath.SqrMagnitude(
                        sphereLocalX - (x * voxelSize) - voxelSizeHalf,
                        sphereLocalZ - (z * voxelSize) - voxelSizeHalf);

                    if (distSqr < sphereRadiusSqr)
                    {
                        float height = Mathf.Sqrt(sphereRadiusSqr - distSqr);
                        sbyte pass   = height >= maxSlopeY ? (sbyte)Passability.Walkable : (sbyte)Passability.Slope;
                        SetVoxel(x, z, sphereY - height, sphereY + height, pass, area);
                    }
                }
            }


            int centerX = (int)(sphereLocalX / voxelSize);
            int centerZ = (int)(sphereLocalZ / voxelSize);

            if (SomeMath.InRangeArrayLike(centerX, 0, template.lengthX_extra) &&
                SomeMath.InRangeArrayLike(centerZ, 0, template.lengthZ_extra))
            {
                SetVoxel(centerX, centerX, sphereY - sphereRadius, sphereY + sphereRadius, (sbyte)Passability.Walkable, area);
            }
        }