コード例 #1
0
ファイル: Helper.cs プロジェクト: DarkLotus/TD
        /// <summary>
        /// Calculates the distance squared from this vector to another.
        /// </summary>
        /// <param name="point">the second <see cref="Vector3" /></param>
        /// <returns>the distance squared between the vectors</returns>
        public float DistanceSquared(ref Vector3D point)
        {
            float x = point.X - X;
            float y = point.Y - Y;
            float z = point.Z - Z;

            return ((x * x) + (y * y)) + (z * z);
        }
コード例 #2
0
ファイル: Helper.cs プロジェクト: DarkLotus/TD
        public static Vector3D VectorRotateZ(Vector3D v, float radians)
        {
            float cosRad = (float)Math.Cos(radians);
            float sinRad = (float)Math.Sin(radians);

            return new Vector3D(v.X * cosRad - v.Y * sinRad,
                                v.X * sinRad + v.Y * cosRad,
                                v.Z);
        }
コード例 #3
0
ファイル: Helper.cs プロジェクト: DarkLotus/TD
 public Vector3D(Vector3D vector)
 {
     this.X = vector.X;
     this.Y = vector.Y;
     this.Z = vector.Z;
 }
コード例 #4
0
ファイル: Helper.cs プロジェクト: DarkLotus/TD
 public static Vector3D TranslateDirection2D(Vector3D source, Vector3D destination, Vector3D point, float amount)
 {
     Vector3D norm = Normalize(new Vector3D(destination.X - source.X, destination.Y - source.Y, 0f));
     return new Vector3D(point.X + norm.X * amount,
                         point.Y + norm.Y * amount,
                         point.Z);
 }
コード例 #5
0
ファイル: Helper.cs プロジェクト: DarkLotus/TD
        public static Vector3D Normalize(Vector3D v)
        {
            float mag = v.X * v.X + v.Y * v.Y + v.Z * v.Z;
            if (mag == 0)
                return new Vector3D(0, 0, 0);

            Vector3D r = new Vector3D(v);
            float len = 1f / (float)Math.Sqrt(mag);
            r.X *= len;
            r.Y *= len;
            r.Z *= len;
            return r;
        }
コード例 #6
0
ファイル: Helper.cs プロジェクト: DarkLotus/TD
        public static Vector3D[] GenerateSpreadPositions(Vector3D center, Vector3D targetPosition, float spacingDegrees, int count)
        {
            Vector3D baseRotation = targetPosition - center;
            float spacing = spacingDegrees * DegreesToRadians;
            float median = count % 2 == 0 ? spacing * (count + 1) / 2.0f : spacing * (float)Math.Ceiling(count / 2.0f);
            Vector3D[] output = new Vector3D[count];

            float offset = 1f;
            for (int i = 0; i < count; ++i)
            {
                output[i] = center + VectorRotateZ(baseRotation, offset * spacing - median);
                offset += 1f;
            }

            return output;
        }
コード例 #7
0
ファイル: Helper.cs プロジェクト: DarkLotus/TD
 public static float Distance2D(Vector3D a, Vector3D b)
 {
     return (float)Math.Sqrt(Math.Pow(a.X - b.X, 2) +
                             Math.Pow(a.Y - b.Y, 2));
 }
コード例 #8
0
ファイル: Monster.cs プロジェクト: DarkLotus/TD
        private void Move(float _velocity)
        {
            var nextpath = path.Last();
            Vector3D dest = new Vector3D(nextpath.X, nextpath.Y,0);
            Vector3D ourloc = new Vector3D(WorldX, WorldY,0);
            Vector3D movepos = PowerMath.TranslateDirection2D(ourloc, dest, ourloc, this._velocity);

            if (this.WorldX < nextpath.X)
            {
                //WorldX += _velocity;
                Direction = 2;
            }
            else if (this.WorldX > nextpath.X)
            {
                //WorldX -= _velocity;
                Direction = 1;
            }
            else if (this.WorldY < nextpath.Y)
            {
                //WorldY += _velocity;
                Direction = 0;
            }
            WorldX = movepos.X;
            WorldY = movepos.Y;

            if (GetDistance(WorldX, WorldY, nextpath.X, nextpath.Y) < 0.3f)
                path.RemoveAt(path.Count - 1);
            else if(new System.Drawing.Rectangle(nextpath.X,nextpath.Y,1,1).Contains((int)WorldX,(int)WorldY))
                path.RemoveAt(path.Count - 1);
            this.ScreenSprite = new SharpDX.RectangleF(ViewX, ViewY, ViewX + Width, ViewY + Height);
        }