Esempio n. 1
0
        public CurveKey this[int index]
        {
            get
            {
                return(innerlist[index]);
            }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }

                if (index >= innerlist.Count)
                {
                    throw new IndexOutOfRangeException();
                }

                if (MathHelper.WithinEpsilon(innerlist[index].Position, value.Position))
                {
                    innerlist[index] = value;
                }
                else
                {
                    innerlist.RemoveAt(index);
                    innerlist.Add(value);
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Compares whether current instance is equal to specified <see cref="Quaternion"/>.
 /// </summary>
 /// <param name="other">The <see cref="Quaternion"/> to compare.</param>
 /// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
 public bool Equals(Quaternion other)
 {
     return((MathHelper.WithinEpsilon(this.X, other.X)) &&
            (MathHelper.WithinEpsilon(this.Y, other.Y)) &&
            (MathHelper.WithinEpsilon(this.Z, other.Z)) &&
            (MathHelper.WithinEpsilon(this.W, other.W)));
 }
Esempio n. 3
0
 public void Contains(ref Vector3 point, out ContainmentType result)
 {
     // First determine if point is outside of this box.
     if (point.X < this.Min.X ||
         point.X > this.Max.X ||
         point.Y < this.Min.Y ||
         point.Y > this.Max.Y ||
         point.Z < this.Min.Z ||
         point.Z > this.Max.Z)
     {
         result = ContainmentType.Disjoint;
     }
     // Or, if the point is on box because coordinate is less than or equal.
     else if (MathHelper.WithinEpsilon(point.X, this.Min.X) ||
              MathHelper.WithinEpsilon(point.X, this.Max.X) ||
              MathHelper.WithinEpsilon(point.Y, this.Min.Y) ||
              MathHelper.WithinEpsilon(point.Y, this.Max.Y) ||
              MathHelper.WithinEpsilon(point.Z, this.Min.Z) ||
              MathHelper.WithinEpsilon(point.Z, this.Max.Z))
     {
         result = ContainmentType.Intersects;
     }
     else
     {
         result = ContainmentType.Contains;
     }
 }
Esempio n. 4
0
 public void Contains(ref Vector3 point, out ContainmentType result)
 {
     // first we get if point is out of box
     if (point.X < this.Min.X ||
         point.X > this.Max.X ||
         point.Y < this.Min.Y ||
         point.Y > this.Max.Y ||
         point.Z < this.Min.Z ||
         point.Z > this.Max.Z)
     {
         result = ContainmentType.Disjoint;
     }
     // or if point is on box because coordonate of point is lesser or equal
     else if (MathHelper.WithinEpsilon(point.X, this.Min.X) ||
              MathHelper.WithinEpsilon(point.X, this.Max.X) ||
              MathHelper.WithinEpsilon(point.Y, this.Min.Y) ||
              MathHelper.WithinEpsilon(point.Y, this.Max.Y) ||
              MathHelper.WithinEpsilon(point.Z, this.Min.Z) ||
              MathHelper.WithinEpsilon(point.Z, this.Max.Z))
     {
         result = ContainmentType.Intersects;
     }
     else
     {
         result = ContainmentType.Contains;
     }
 }
Esempio n. 5
0
 public static bool operator ==(Vector4 value1, Vector4 value2)
 {
     return((MathHelper.WithinEpsilon(value1.W, value2.W)) &&
            (MathHelper.WithinEpsilon(value1.X, value2.X)) &&
            (MathHelper.WithinEpsilon(value1.Y, value2.Y)) &&
            (MathHelper.WithinEpsilon(value1.Z, value2.Z)));
 }
Esempio n. 6
0
        public override bool Equals(object obj)
        {
            if (!(obj is Vector3))
            {
                return(false);
            }

            Vector3 other = (Vector3)obj;

            return((MathHelper.WithinEpsilon(X, other.X)) &&
                   (MathHelper.WithinEpsilon(Y, other.Y)) &&
                   (MathHelper.WithinEpsilon(Z, other.Z)));
        }
Esempio n. 7
0
        // Adapted from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
        public float?Intersects(BoundingBox box)
        {
            float?tMin = null, tMax = null;

            if (MathHelper.WithinEpsilon(Direction.X, 0.0f))
            {
                if (Position.X < box.Min.X || Position.X > box.Max.X)
                {
                    return(null);
                }
            }
            else
            {
                tMin = (box.Min.X - Position.X) / Direction.X;
                tMax = (box.Max.X - Position.X) / Direction.X;

                if (tMin > tMax)
                {
                    float?temp = tMin;
                    tMin = tMax;
                    tMax = temp;
                }
            }

            if (MathHelper.WithinEpsilon(Direction.Y, 0.0f))
            {
                if (Position.Y < box.Min.Y || Position.Y > box.Max.Y)
                {
                    return(null);
                }
            }
            else
            {
                float tMinY = (box.Min.Y - Position.Y) / Direction.Y;
                float tMaxY = (box.Max.Y - Position.Y) / Direction.Y;

                if (tMinY > tMaxY)
                {
                    float temp = tMinY;
                    tMinY = tMaxY;
                    tMaxY = temp;
                }

                if ((tMin.HasValue && tMin > tMaxY) ||
                    (tMax.HasValue && tMinY > tMax))
                {
                    return(null);
                }

                if (!tMin.HasValue || tMinY > tMin)
                {
                    tMin = tMinY;
                }
                if (!tMax.HasValue || tMaxY < tMax)
                {
                    tMax = tMaxY;
                }
            }

            if (MathHelper.WithinEpsilon(Direction.Z, 0.0f))
            {
                if (Position.Z < box.Min.Z || Position.Z > box.Max.Z)
                {
                    return(null);
                }
            }
            else
            {
                float tMinZ = (box.Min.Z - Position.Z) / Direction.Z;
                float tMaxZ = (box.Max.Z - Position.Z) / Direction.Z;

                if (tMinZ > tMaxZ)
                {
                    float temp = tMinZ;
                    tMinZ = tMaxZ;
                    tMaxZ = temp;
                }

                if ((tMin.HasValue && tMin > tMaxZ) ||
                    (tMax.HasValue && tMinZ > tMax))
                {
                    return(null);
                }

                if (!tMin.HasValue || tMinZ > tMin)
                {
                    tMin = tMinZ;
                }
                if (!tMax.HasValue || tMaxZ < tMax)
                {
                    tMax = tMaxZ;
                }
            }

            /* Having a positive tMin and a negative tMax means the ray is inside the
             * box we expect the intesection distance to be 0 in that case.
             */
            if ((tMin.HasValue && tMin < 0) && tMax > 0)
            {
                return(0);
            }

            /* A negative tMin means that the intersection point is behind the ray's
             * origin. We discard these as not hitting the AABB.
             */
            if (tMin < 0)
            {
                return(null);
            }

            return(tMin);
        }
Esempio n. 8
0
 /// <summary>
 /// Compares whether current instance is equal to specified <see cref="BoundingSphere"/>.
 /// </summary>
 /// <param name="other">The <see cref="BoundingSphere"/> to compare.</param>
 /// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
 public bool Equals(BoundingSphere other)
 {
     return(this.Center == other.Center &&
            MathHelper.WithinEpsilon(this.Radius, other.Radius));
 }
Esempio n. 9
0
        /// <summary>
        /// Computes tangent for the specific key in the collection.
        /// </summary>
        /// <param name="keyIndex">The index of key in the collection.</param>
        /// <param name="tangentInType">The tangent in-type. <see cref="CurveKey.TangentIn"/> for more details.</param>
        /// <param name="tangentOutType">The tangent out-type. <see cref="CurveKey.TangentOut"/> for more details.</param>
        public void ComputeTangent(
            int keyIndex,
            CurveTangent tangentInType,
            CurveTangent tangentOutType
            )
        {
            // See http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.curvetangent.aspx

            CurveKey key = Keys[keyIndex];

            float p0, p, p1;

            p0 = p = p1 = key.Position;

            float v0, v, v1;

            v0 = v = v1 = key.Value;

            if (keyIndex > 0)
            {
                p0 = Keys[keyIndex - 1].Position;
                v0 = Keys[keyIndex - 1].Value;
            }

            if (keyIndex < Keys.Count - 1)
            {
                p1 = Keys[keyIndex + 1].Position;
                v1 = Keys[keyIndex + 1].Value;
            }

            switch (tangentInType)
            {
            case CurveTangent.Flat:
                key.TangentIn = 0;
                break;

            case CurveTangent.Linear:
                key.TangentIn = v - v0;
                break;

            case CurveTangent.Smooth:
                float pn = p1 - p0;
                if (MathHelper.WithinEpsilon(pn, 0.0f))
                {
                    key.TangentIn = 0;
                }
                else
                {
                    key.TangentIn = (v1 - v0) * ((p - p0) / pn);
                }
                break;
            }

            switch (tangentOutType)
            {
            case CurveTangent.Flat:
                key.TangentOut = 0;
                break;

            case CurveTangent.Linear:
                key.TangentOut = v1 - v;
                break;

            case CurveTangent.Smooth:
                float pn = p1 - p0;
                if (Math.Abs(pn) < float.Epsilon)
                {
                    key.TangentOut = 0;
                }
                else
                {
                    key.TangentOut = (v1 - v0) * ((p1 - p) / pn);
                }
                break;
            }
        }
Esempio n. 10
0
File: Plane.cs Progetto: zwcloud/FNA
 public bool Equals(Plane other)
 {
     return((Normal == other.Normal) && (MathHelper.WithinEpsilon(D, other.D)));
 }
Esempio n. 11
0
 /// <summary>
 /// Compares whether current instance is equal to specified <see cref="Vector2"/>.
 /// </summary>
 /// <param name="other">The <see cref="Vector2"/> to compare.</param>
 /// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
 public bool Equals(Vector2 other)
 {
     return((MathHelper.WithinEpsilon(X, other.X)) &&
            (MathHelper.WithinEpsilon(Y, other.Y)));
 }