Exemple #1
0
        /// <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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
 public Vector3D(Vector3D vector)
 {
     this.X = vector.X;
     this.Y = vector.Y;
     this.Z = vector.Z;
 }
Exemple #4
0
 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);
 }
Exemple #5
0
        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;
        }
Exemple #6
0
        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;
        }
Exemple #7
0
 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));
 }
Exemple #8
0
        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);
        }