Esempio n. 1
0
 /// <summary>
 /// Constructs a plane with another specified <see cref="PlaneF"/> object.
 /// </summary>
 /// <param name="source">A specified plane.</param>
 public PlaneF(PlaneF source)
 {
     this.A = source.A;
     this.B = source.B;
     this.C = source.C;
     this.D = source.D;
 }
Esempio n. 2
0
 /// <summary>
 /// Constructs a plane with the specified <see cref="PlaneF"/> object.
 /// </summary>
 /// <param name="source">A specified plane.</param>
 public Plane(PlaneF source)
 {
     A = source.A;
     B = source.B;
     C = source.C;
     D = source.D;
 }
Esempio n. 3
0
 /// <summary>
 /// Subtracts two planes.
 /// </summary>
 /// <param name="p0">The plane to subtract from.</param>
 /// <param name="p1">The plane to be subtracted from another plane.</param>
 /// <param name="result">When the method completes, contains the resulting plane.</param>
 public static void Subtract(ref PlaneF p0, ref PlaneF p1, out PlaneF result)
 {
     result.A = p0.A - p1.A;
     result.B = p0.B - p1.B;
     result.C = p0.C - p1.C;
     result.D = p0.D - p1.D;
 }
Esempio n. 4
0
 /// <summary>
 /// Reverses the direction of a given plane.
 /// </summary>
 /// <param name="p">The plane to negate.</param>
 /// <param name="result">When the method completes, contains the plane facing in the opposite direction.</param>
 public static void Negate(ref PlaneF p, out PlaneF result)
 {
     result.A = -p.A;
     result.B = -p.B;
     result.C = -p.C;
     result.D = -p.D;
 }
Esempio n. 5
0
 /// <summary>
 /// Adds two planes.
 /// </summary>
 /// <param name="p0">The first plane to add.</param>
 /// <param name="p1">The second plane to add.</param>
 /// <param name="result">When the method completes, contains the resulting plane.</param>
 public static void Add(ref PlaneF p0, ref PlaneF p1, out PlaneF result)
 {
     result.A = p0.A + p1.A;
     result.B = p0.B + p1.B;
     result.C = p0.C + p1.C;
     result.D = p0.D + p1.D;
 }
Esempio n. 6
0
        /// <summary>
        /// Determines whether the specified plane is equal to the current instance of <see cref="PlaneF"/>
        /// with the given normal and distance precisions.
        /// </summary>
        /// <param name="p">The plane to compare.</param>
        /// <param name="normalEpsilon">The precision value for the plane normal.</param>
        /// <param name="distanceEpsilon">The precision value for the distance component of the plane.</param>
        /// <returns>True if the specified plane is equal to the current instance of <see cref="PlaneF"/>; False otherwise.</returns>
        public bool Equals(ref PlaneF p, float normalEpsilon, float distanceEpsilon)
        {
            if (Math.Abs(D - p.D) > distanceEpsilon)
            {
                return(false);
            }
            Vector3F n  = Normal;
            Vector3F pn = p.Normal;

            if (!n.Equals(ref pn, normalEpsilon))
            {
                return(false);
            }
            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Creates an instance of <see cref="PlaneF"/> that contains the three given points.
        /// </summary>
        /// <param name="point0">The first point defining the plane.</param>
        /// <param name="point1">The second point defining the plane.</param>
        /// <param name="point2">The third point defining the plane.</param>
        /// <param name="result">When the method completes, contains the resulting plane.</param>
        public static void FromPoints(ref Vector3F point0, ref Vector3F point1, ref Vector3F point2,
                                      out PlaneF result)
        {
            Vector3F edge1;

            Vector3F.Subtract(ref point1, ref point0, out edge1);
            Vector3F edge2;

            Vector3F.Subtract(ref point2, ref point0, out edge2);

            Vector3F normal;

            Vector3F.Cross(ref edge1, ref edge2, out normal);
            normal.Normalize();
            result.A = normal.X;
            result.B = normal.Y;
            result.C = normal.Z;
            result.D = -(normal.X * point0.X + normal.Y * point0.Y + normal.Z * point0.Z);
        }
Esempio n. 8
0
 /// <summary>
 /// Determines whether the specified plane is equal to the current instance of <see cref="PlaneF"/>
 /// with a given precision.
 /// </summary>
 /// <param name="p">The plane to compare.</param>
 /// <param name="epsilon">The precision value.</param>
 /// <returns>True if the specified plane is equal to the current instance of <see cref="PlaneF"/>; False otherwise.</returns>
 public bool Equals(ref PlaneF p, float epsilon)
 {
     if (Math.Abs(A - p.A) > epsilon)
     {
         return(false);
     }
     if (Math.Abs(B - p.B) > epsilon)
     {
         return(false);
     }
     if (Math.Abs(C - p.C) > epsilon)
     {
         return(false);
     }
     if (Math.Abs(D - p.D) > epsilon)
     {
         return(false);
     }
     return(true);
 }
Esempio n. 9
0
        public float GetPlaneDistance(ref PlaneF plane)
        {
            Vector3F center;

            GetCenter(out center);

            float d1 = plane.GetDistance(ref center);
            float d2 = Math.Abs((Maximum.X - center.X) * plane.Normal.X) +
                       Math.Abs((Maximum.Y - center.Y) * plane.Normal.Y) +
                       Math.Abs((Maximum.Z - center.Z) * plane.Normal.Z);

            if (d1 - d2 > 0.0f)
            {
                return(d1 - d2);
            }
            if (d1 + d2 < 0.0f)
            {
                return(d1 + d2);
            }
            return(0.0f);
        }
Esempio n. 10
0
        public PlaneF.Side GetPlaneSide(ref PlaneF plane)
        {
            Vector3F center;

            GetCenter(out center);

            float d1 = plane.GetDistance(ref center);
            float d2 = Math.Abs((Maximum.X - center.X) * plane.A) +
                       Math.Abs((Maximum.Y - center.Y) * plane.B) +
                       Math.Abs((Maximum.Z - center.Z) * plane.C);

            if (d1 - d2 > 0)
            {
                return(PlaneF.Side.Positive);
            }
            if (d1 + d2 < 0)
            {
                return(PlaneF.Side.Negative);
            }
            return(PlaneF.Side.No);
        }
Esempio n. 11
0
        //

        static SimpleTypes()
        {
            //string
            RegisterType(typeof(string), delegate(string value)
            {
                if (value == null)
                {
                    return("");
                    //throw new Exception( "GetSimpleTypeValue: string type, value = null" );
                }
                return(value);
            }, "");

            //bool
            RegisterType(typeof(bool), delegate(string value)
            {
                string lower = value.ToLower();
                if (value == "1" || lower == "yes" || lower == "true")
                {
                    return(true);
                }
                else if (value == "0" || lower == "no" || lower == "false")
                {
                    return(false);
                }
                else
                {
                    return(bool.Parse(value));
                }
            }, false);

            //sbyte
            RegisterType(typeof(sbyte), delegate(string value) { return(sbyte.Parse(value)); }, 0);

            //byte
            RegisterType(typeof(byte), delegate(string value) { return(byte.Parse(value)); }, 0);

            //char
            RegisterType(typeof(char), delegate(string value) { return(char.Parse(value)); }, 0);

            //short
            RegisterType(typeof(short), delegate(string value) { return(short.Parse(value)); }, 0);

            //ushort
            RegisterType(typeof(ushort), delegate(string value) { return(ushort.Parse(value)); }, 0);

            //int
            RegisterType(typeof(int), delegate(string value) { return(int.Parse(value)); }, 0);

            //uint
            RegisterType(typeof(uint), delegate(string value) { return(uint.Parse(value)); }, (uint)0);

            //long
            RegisterType(typeof(long), delegate(string value) { return(long.Parse(value)); }, (long)0);

            //ulong
            RegisterType(typeof(ulong), delegate(string value) { return(ulong.Parse(value)); }, (ulong)0);

            //float
            RegisterType(typeof(float), delegate(string value) { return(float.Parse(value)); }, 0.0f);

            //double
            RegisterType(typeof(double), delegate(string value) { return(double.Parse(value)); }, 0.0);

            //decimal
            RegisterType(typeof(decimal), delegate(string value) { return(decimal.Parse(value)); }, (decimal)0.0);

            //Vec2
            RegisterType(typeof(Vector2F), delegate(string value) { return(Vector2F.Parse(value)); }, Vector2F.Zero);

            //Range
            RegisterType(typeof(RangeF), delegate(string value) { return(RangeF.Parse(value)); }, RangeF.Zero);

            //Vec3
            RegisterType(typeof(Vector3F), delegate(string value) { return(Vector3F.Parse(value)); }, Vector3F.Zero);

            //Vec4
            RegisterType(typeof(Vector4F), delegate(string value) { return(Vector4F.Parse(value)); }, Vector4F.Zero);

            //Bounds
            RegisterType(typeof(BoundsF), delegate(string value) { return(BoundsF.Parse(value)); }, BoundsF.Zero);

            //Quat
            RegisterType(typeof(QuaternionF), delegate(string value) { return(QuaternionF.Parse(value)); }, QuaternionF.Identity);

            //ColorValue
            RegisterType(typeof(ColorValue), delegate(string value) { return(ColorValue.Parse(value)); }, ColorValue.Zero);

            //ColorValuePowered
            RegisterType(typeof(ColorValuePowered), delegate(string value) { return(ColorValuePowered.Parse(value)); }, ColorValuePowered.Zero);

            //ColorPacked
            RegisterType(typeof(ColorByte), delegate(string value) { return(ColorByte.Parse(value)); }, ColorByte.Zero);

            //SphereDir
            RegisterType(typeof(SphericalDirectionF), delegate(string value) { return(SphericalDirectionF.Parse(value)); }, SphericalDirectionF.Zero);

            //Vec2I
            RegisterType(typeof(Vector2I), delegate(string value) { return(Vector2I.Parse(value)); }, Vector2I.Zero);

            //Vec3I
            RegisterType(typeof(Vector3I), delegate(string value) { return(Vector3I.Parse(value)); }, Vector3I.Zero);

            //Vec4I
            RegisterType(typeof(Vector4I), delegate(string value) { return(Vector4I.Parse(value)); }, Vector4I.Zero);

            //Rect
            RegisterType(typeof(RectangleF), delegate(string value) { return(RectangleF.Parse(value)); }, RectangleF.Zero);

            //RectI
            RegisterType(typeof(RectangleI), delegate(string value) { return(RectangleI.Parse(value)); }, RectangleI.Zero);

            //Degree
            RegisterType(typeof(DegreeF), delegate(string value) { return(DegreeF.Parse(value)); }, DegreeF.Zero);

            //Radian
            RegisterType(typeof(RadianF), delegate(string value) { return(RadianF.Parse(value)); }, RadianF.Zero);

            //Vec2D
            RegisterType(typeof(Vector2), delegate(string value) { return(Vector2.Parse(value)); }, Vector2.Zero);

            //RangeD
            RegisterType(typeof(Range), delegate(string value) { return(Range.Parse(value)); }, Range.Zero);

            //RangeI
            RegisterType(typeof(RangeI), delegate(string value) { return(RangeI.Parse(value)); }, RangeI.Zero);

            //Vec3D
            RegisterType(typeof(Vector3), delegate(string value) { return(Vector3.Parse(value)); }, Vector3.Zero);

            //Vec4D
            RegisterType(typeof(Vector4), delegate(string value) { return(Vector4.Parse(value)); }, Vector4.Zero);

            //BoundsD
            RegisterType(typeof(Bounds), delegate(string value) { return(Bounds.Parse(value)); }, Bounds.Zero);

            //QuatD
            RegisterType(typeof(Quaternion), delegate(string value) { return(Quaternion.Parse(value)); }, Quaternion.Identity);

            //SphereDirD
            RegisterType(typeof(SphericalDirection), delegate(string value) { return(SphericalDirection.Parse(value)); }, SphericalDirection.Zero);

            //RectD
            RegisterType(typeof(Rectangle), delegate(string value) { return(Rectangle.Parse(value)); }, Rectangle.Zero);

            //DegreeD
            RegisterType(typeof(Degree), delegate(string value) { return(Degree.Parse(value)); }, Degree.Zero);

            //RadianD
            RegisterType(typeof(Radian), delegate(string value) { return(Radian.Parse(value)); }, Radian.Zero);

            //Angles
            RegisterType(typeof(AnglesF), delegate(string value) { return(AnglesF.Parse(value)); }, AnglesF.Zero);

            //AnglesD
            RegisterType(typeof(Angles), delegate(string value) { return(Angles.Parse(value)); }, Angles.Zero);

            //Mat2F
            RegisterType(typeof(Matrix2F), delegate(string value) { return(Matrix2F.Parse(value)); }, Matrix2F.Zero);

            //Mat2D
            RegisterType(typeof(Matrix2), delegate(string value) { return(Matrix2.Parse(value)); }, Matrix2.Zero);

            //Mat3F
            RegisterType(typeof(Matrix3F), delegate(string value) { return(Matrix3F.Parse(value)); }, Matrix3F.Zero);

            //Mat3D
            RegisterType(typeof(Matrix3), delegate(string value) { return(Matrix3.Parse(value)); }, Matrix3.Zero);

            //Mat4F
            RegisterType(typeof(Matrix4F), delegate(string value) { return(Matrix4F.Parse(value)); }, Matrix4F.Zero);

            //Mat4D
            RegisterType(typeof(Matrix4), delegate(string value) { return(Matrix4.Parse(value)); }, Matrix4.Zero);

            //PlaneF
            RegisterType(typeof(PlaneF), delegate(string value) { return(PlaneF.Parse(value)); }, PlaneF.Zero);

            //PlaneD
            RegisterType(typeof(Plane), delegate(string value) { return(Plane.Parse(value)); }, Plane.Zero);

            //Transform
            RegisterType(typeof(Transform), delegate(string value) { return(Transform.Parse(value)); }, Transform.Identity);

            //UIMeasureValueDouble
            RegisterType(typeof(UIMeasureValueDouble), delegate(string value) { return(UIMeasureValueDouble.Parse(value)); }, new UIMeasureValueDouble());

            //UIMeasureValueVec2
            RegisterType(typeof(UIMeasureValueVector2), delegate(string value) { return(UIMeasureValueVector2.Parse(value)); }, new UIMeasureValueVector2());

            //UIMeasureValueRect
            RegisterType(typeof(UIMeasureValueRectangle), delegate(string value) { return(UIMeasureValueRectangle.Parse(value)); }, new UIMeasureValueRectangle());

            RegisterType(typeof(RangeVector3F), delegate(string value) { return(RangeVector3F.Parse(value)); }, RangeVector3F.Zero);
            RegisterType(typeof(RangeColorValue), delegate(string value) { return(RangeColorValue.Parse(value)); }, RangeColorValue.Zero);

            //no Parse methods. This is complex structures. This is not simple types? or just can't parse?
            //Box
            //Capsule
            //Cone
            //Line3
            //Line2
            //Ray
            //Frustum?

            RegisterConvertDoubleToFloatTypes();
        }
Esempio n. 12
0
        /// <summary>
        /// Creates an instance of <see cref="PlaneF"/> with the normal and the point.
        /// </summary>
        /// <param name="point">Any point that lies along the plane.</param>
        /// <param name="normal">The normal vector to the plane.</param>
        /// <param name="plane">When the method completes, contains the resulting plane.</param>
        public static void FromPointAndNormal(ref Vector3F point, ref Vector3F normal, out PlaneF plane)
        {
            float distance = Vector3F.Dot(ref point, ref normal);

            plane = new PlaneF(normal, distance);
        }
Esempio n. 13
0
        /// <summary>
        /// Creates an instance of <see cref="PlaneF"/> with point and two direction vectors.
        /// </summary>
        /// <param name="dir1">The first direction vector.</param>
        /// <param name="dir2">The second direction vector.</param>
        /// <param name="p">The point that is the start of direction vectors.</param>
        /// <param name="result">When the method completes, contains the resulting plane.</param>
        public static void FromVectors(ref Vector3F dir1, ref Vector3F dir2, ref Vector3F p, out PlaneF result)
        {
            Vector3F normal;

            Vector3F.Cross(ref dir1, ref dir2, out normal);
            normal.Normalize();
            result.A = normal.X;
            result.B = normal.Y;
            result.C = normal.Z;
            result.D = -(normal.X * p.X + normal.Y * p.Y + normal.Z * p.Z);
        }
Esempio n. 14
0
 public float GetPlaneDistance(PlaneF plane)
 {
     return(GetPlaneDistance(ref plane));
 }
Esempio n. 15
0
 public PlaneF.Side GetPlaneSide(PlaneF plane)
 {
     return(GetPlaneSide(ref plane));
 }