Example #1
0
        public void ToAngles(out AnglesF result)
        {
            Matrix3F mat;

            ToMatrix3(out mat);
            mat.ToAngles(out result);
        }
Example #2
0
        //public static AnglesF operator *( float a, AnglesF b )
        //{
        //	float inva = 1.0f / a;
        //	return new AnglesF( b.Roll * inva, b.Pitch * inva, b.Yaw * inva );
        //}

        /// <summary>
        /// Restricts the current instance of <see cref="AnglesF"/> to be within a specified range.
        /// </summary>
        /// <param name="min">The minimum value.</param>
        /// <param name="max">The maximum value.</param>
        public void Clamp(AnglesF min, AnglesF max)
        {
            if (Roll < min.Roll)
            {
                Roll = min.Roll;
            }
            else if (Roll > max.Roll)
            {
                Roll = max.Roll;
            }
            if (Pitch < min.Pitch)
            {
                Pitch = min.Pitch;
            }
            else if (Pitch > max.Pitch)
            {
                Pitch = max.Pitch;
            }
            if (Yaw < min.Yaw)
            {
                Yaw = min.Yaw;
            }
            else if (Yaw > max.Yaw)
            {
                Yaw = max.Yaw;
            }
        }
Example #3
0
        public static QuaternionF Parse(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException("The text parameter cannot be null or zero length.");
            }

            string[] vals = text.Split(new char[] { ' ' },
                                       StringSplitOptions.RemoveEmptyEntries);

            //parse from Angles (special case).
            if (vals.Length == 3)
            {
                return(AnglesF.Parse(text).ToQuaternion());
            }

            if (vals.Length != 4)
            {
                throw new FormatException(string.Format("Cannot parse the text '{0}' because it does not have 4 parts separated by spaces in the form (x y z w).", text));
            }

            try
            {
                return(new QuaternionF(
                           float.Parse(vals[0]),
                           float.Parse(vals[1]),
                           float.Parse(vals[2]),
                           float.Parse(vals[3])));
            }
            catch (Exception)
            {
                throw new FormatException("The parts of the vectors must be decimal numbers.");
            }
        }
Example #4
0
 public static AnglesF Generate(AnglesF minValue, AnglesF maxValue)
 {
     lock (_static)
         return(new AnglesF(
                    _static.Next(minValue.Roll, maxValue.Roll),
                    _static.Next(minValue.Pitch, maxValue.Pitch),
                    _static.Next(minValue.Yaw, maxValue.Yaw)));
 }
Example #5
0
 /// <summary>
 /// Determines whether the specified Euler angles are equal to the current instance of <see cref="AnglesF"/>
 /// with a given precision.
 /// </summary>
 /// <param name="a">The Euler angles to compare.</param>
 /// <param name="epsilon">The precision value.</param>
 /// <returns>True if the specified Euler angles are equal to the current instance of <see cref="AnglesF"/>; False otherwise.</returns>
 public bool Equals(AnglesF a, float epsilon)
 {
     if (Math.Abs(Roll - a.Roll) > epsilon)
     {
         return(false);
     }
     if (Math.Abs(Pitch - a.Pitch) > epsilon)
     {
         return(false);
     }
     if (Math.Abs(Yaw - a.Yaw) > epsilon)
     {
         return(false);
     }
     return(true);
 }
Example #6
0
 /// <summary>
 /// Constructs Euler angles with another specified <see cref="AnglesF"/> object.
 /// </summary>
 /// <param name="source">Euler angles of <see cref="AnglesF"/> format.</param>
 public AnglesF(AnglesF source)
 {
     this.Roll  = source.Roll;
     this.Pitch = source.Pitch;
     this.Yaw   = source.Yaw;
 }
Example #7
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();
        }
        void ProcessVertex(ref Vector3F position, out Vector3F result)
        {
            Matrix4? nullable = new Matrix4?(PosCenter.Value.ToMatrix4());
            Matrix4  matrix4  = nullable ?? Matrix4.Identity;
            Matrix4F matrix4f = matrix4.ToMatrix4F();
            bool     inv      = matrix4f.Inverse();

            MatrixInv = inv;

            ResPosVec1 = matrix4f * Pos1n.Value.Position.ToVector3F();

            result = position;
            var sc        = new Vector3F(0.2f, 0.2f, 0.2f);
            var rposition = position * sc;

            var   l_r01   = (float)Pos01n.Value.Scale.X;
            var   relp01  = (Pos01n.Value.Position).ToVector3F();
            var   l_dist1 = (rposition - relp01);
            float l_l01   = l_dist1.Length();

            var   l_r02   = (float)Pos02n.Value.Scale.X;
            var   relp02  = (Pos02n.Value.Position).ToVector3F();
            var   l_dist2 = (rposition - relp02);
            float l_l02   = l_dist2.Length();

            var   l_r03   = (float)Pos03n.Value.Scale.X;
            var   relp03  = (Pos03n.Value.Position).ToVector3F();
            var   l_dist3 = (rposition - relp03);
            float l_l03   = l_dist3.Length();

            var   l_r04   = (float)Pos04n.Value.Scale.X;
            var   relp04  = (Pos04n.Value.Position).ToVector3F();
            var   l_dist4 = (rposition - relp04);
            float l_l04   = l_dist4.Length();

            var f = ((ResPos1.Value.Position - PosCenter.Value.Position) / sc).ToVector3F().GetNormalize();
            SphericalDirectionF sd = new SphericalDirectionF(f.X, f.Y);
            float       ax         = MathEx.Acos(f.X);
            float       ay         = MathEx.Asin(f.X);
            QuaternionF q          = new AnglesF().ToQuaternion();


            if (l_l01 <= l_r01)
            {
                var relp1 = matrix4f * Pos1n.Value.Position.ToVector3F();
                result = relp1;
            }
            if (l_l02 <= l_r02)
            {
                var relp2 = matrix4f * Pos2n.Value.Position.ToVector3F();;
                result = relp2;
            }
            if (l_l03 <= l_r03)
            {
                var relp3 = matrix4f * Pos3n.Value.Position.ToVector3F();;
                result = relp3;
            }
            if (l_l04 <= l_r04)
            {
                var relp4 = matrix4f * Pos4n.Value.Position.ToVector3F();;
                result = relp4;
            }
        }