Exemple #1
0
        public float GetDistanceSqTo(FVec2 pt)
        {
            float dx = pt.x - mX;
            float dz = pt.z - mZ;

            return(dx * dx + dz * dz);
        }
Exemple #2
0
 public void MoveAbs(FVec2 center)
 {
     x1 = center.x - Width / 2;
     x2 = center.x + Width / 2;
     y1 = center.z - Height / 2;
     y2 = center.z + Height / 2;
 }
Exemple #3
0
        public float GetDistanceTo(FVec2 pt)
        {
            float dx = pt.x - mX;
            float dz = pt.z - mZ;

            return((float)System.Math.Sqrt(dx * dx + dz * dz));
        }
        public List <IAgent> QueryRadius(Rectangle queryArea, float radius)
        {
            List <IAgent> results = new List <IAgent>();
            //Fame.Fame.Singleton.UnityPrint(String.Format("{0} {1}", thisIndex,contents.Count));

            //Fame.Fame.Singleton.UnityPrint(String.Format("Checking:{0} ", thisIndex));
            //List<IAgent> cloneContents;
            //lock (thisLock)
            //{
            //    cloneContents = new List<IAgent>(contents);
            //}
            FVec2 rectCenter = queryArea.Center;
            float radiusSq   = radius * radius;

            foreach (IAgent item in this.contents)
            {
                FVec2 agentPos = new FVec2(rectCenter.x - item.Position.x, rectCenter.z - item.Position.z);
                if (agentPos.SquaredLength < radiusSq)
                {
                    results.Add(item);
                }
            }

            foreach (QuadTreeNode node in subNodes)
            {
                //if(node.IsEmpty){
                //    Fame.Fame.Singleton.UnityPrint(String.Format("skipping:{0} ", node.thisIndex));
                //    continue;
                //}
                //case 1: search area completely contained by sub-quad
                //if a node completely contains the query area, go down that branch
                //and skip the remaining node (break this loop)
                if (node.Bounds.Contains(queryArea))
                {
                    results.AddRange(node.QueryRadius(queryArea, radius));
                    break;
                }

                //case 2: sub-quad completely contained by search area
                //if the query area completely contains a sub-quad,
                //just add all the contents of that quad and its children
                //to the result set. You need to continue the loop to test
                //the other quads
                if (queryArea.Contains(node.Bounds))
                {
                    results.AddRange(node.SubTreeContents);
                    continue;
                }

                //case 3: search area intersects with sub-quad
                //traverse into this quad, continue the loop to
                //search other quads
                if (node.Bounds.IntersectsWith(queryArea))
                {
                    results.AddRange(node.QueryRadius(queryArea, radius));
                }
            }

            return(results);
        }
Exemple #5
0
        public static FVec2 operator +(FVec2 lhs, FVec2 rhs)
        {
            FVec2 result = lhs.Clone();

            result.x += rhs.x;
            result.z += rhs.z;
            return(result);
        }
Exemple #6
0
        public static FVec2 operator *(float scale, FVec2 rhs)
        {
            FVec2 result = rhs.Clone();

            result.x *= scale;
            result.z *= scale;
            return(result);
        }
Exemple #7
0
        public static FVec2 operator *(FVec2 lhs, float scale)
        {
            FVec2 result = lhs.Clone();

            result.x *= scale;
            result.z *= scale;
            return(result);
        }
Exemple #8
0
        public static FVec2 operator -(FVec2 lhs)
        {
            FVec2 result = lhs.Clone();

            result.x *= -1;
            result.z *= -1;
            return(result);
        }
Exemple #9
0
 public FVec2 Assign(FVec2 rhs)
 {
     if (this == rhs)
     {
         return(this);
     }
     x = rhs.x;
     z = rhs.z;
     return(this);
 }
Exemple #10
0
        public FVec2 Rotate(float radian)
        {
            double cosine = System.Math.Cos(radian);
            double sine   = System.Math.Sin(radian);
            FVec2  result = new FVec2();

            result.x = (float)(x * cosine - z * sine);
            result.z = (float)(x * sine + z * cosine);

            return(result);
        }
Exemple #11
0
        public static int SidenessTest(FVec2 A, FVec2 B, FVec2 C)
        {
            float result = (B.x - A.x) * (C.z - A.z) - (B.z - A.z) * (C.x - A.x);

            if (result == 0)
            {
                return(0);
            }
            else if (result > 0)
            {
                return(1);
            }
            else
            {
                return(-1);
            }
        }
Exemple #12
0
 public void Assign(FVec2 vect2)
 {
     this.x = vect2.x;
     this.z = vect2.z;
 }
Exemple #13
0
 public float CrossLength(FVec2 v)
 {
     return(Math.Abs(x * v.z - z * v.x));
 }
Exemple #14
0
 public static float dotProduct(FVec2 lhs, FVec2 rhs)
 {
     return(lhs.x * rhs.x + lhs.z * rhs.z);
 }
Exemple #15
0
 public float dotProduct(FVec2 rhs)
 {
     return(mX * rhs.x + mZ * rhs.z);
 }