コード例 #1
0
 /// <summary>
 /// Determines whether the specified vector is equal to the current instance of <see cref="Vector4I"/> with a given precision.
 /// </summary>
 /// <param name="v">The vector to compare.</param>
 /// <param name="epsilon">The precision value.</param>
 /// <returns>True if the specified vector is equal to the current instance of <see cref="Vector4I"/>; False otherwise.</returns>
 public bool Equals(Vector4I v, int epsilon)
 {
     if (Math.Abs(X - v.X) > epsilon)
     {
         return(false);
     }
     if (Math.Abs(Y - v.Y) > epsilon)
     {
         return(false);
     }
     if (Math.Abs(Z - v.Z) > epsilon)
     {
         return(false);
     }
     if (Math.Abs(W - v.W) > epsilon)
     {
         return(false);
     }
     return(true);
 }
コード例 #2
0
        void Clamp(Vector4I min, Vector4I max)
        {
            if (X < min.X)
            {
                X = min.X;
            }
            else if (X > max.X)
            {
                X = max.X;
            }

            if (Y < min.Y)
            {
                Y = min.Y;
            }
            else if (Y > max.Y)
            {
                Y = max.Y;
            }

            if (Z < min.Z)
            {
                Z = min.Z;
            }
            else if (Z > max.Z)
            {
                Z = max.Z;
            }

            if (W < min.W)
            {
                W = min.W;
            }
            else if (W > max.W)
            {
                W = max.W;
            }
        }
コード例 #3
0
 /// <summary>
 /// Returns a vector containing the smallest components of the specified vectors.
 /// </summary>
 /// <param name="v1">The first vector.</param>
 /// <param name="v2">The second vector.</param>
 /// <returns>A vector containing the smallest components of the specified vectors.</returns>
 public static Vector4I Min(Vector4I v1, Vector4I v2)
 {
     return(new Vector4I(Math.Min(v1.X, v2.X), Math.Min(v1.Y, v2.Y), Math.Min(v1.Z, v2.Z), Math.Min(v1.W, v2.W)));
 }
コード例 #4
0
 /// <summary>
 /// Determines whether all components of a given vector are unequal to the zero.
 /// </summary>
 /// <param name="v">The vector to compare with the zero vector.</param>
 /// <returns>True if all components of the specified vector are unequal to the zero; otherwise, False.</returns>
 public static bool AllNonZero(Vector4I v)
 {
     return(v.X != 0 && v.Y != 0 && v.Z != 0 && v.W != 0);
 }
コード例 #5
0
 /// <summary>
 /// Determines whether any component of a given vector is unequal to the zero.
 /// </summary>
 /// <param name="v">The vector to compare with the zero vector.</param>
 /// <returns>True if any component of the specified vector is unequal to the zero; otherwise, False.</returns>
 public static bool AnyNonZero(Vector4I v)
 {
     return(v != Zero);
 }
コード例 #6
0
 /// <summary>
 /// Chooses one of two vectors depending on the <paramref name="pick1"/> value.
 /// </summary>
 /// <param name="v1">The first vector to choose.</param>
 /// <param name="v2">The second vector to choose.</param>
 /// <param name="pick1">If this value is true, the method chooses the virst vector, otherwise it chooses the second one.</param>
 /// <returns>The selected vector.</returns>
 public static Vector4I Select(Vector4I v1, Vector4I v2, bool pick1)
 {
     return(pick1 ? v1 : v2);
 }
コード例 #7
0
        ///////////////////////////////////////////

        /// <summary>
        /// The constructor of the vertex.
        /// </summary>
        /// <param name="position">The position of the vertex.</param>
        /// <param name="normal">The normal of the vertex.</param>
        /// <param name="tangent">The tangent vector of the vertex.</param>
        /// <param name="color">The color of the vertex.</param>
        /// <param name="texCoord0">The texture coordinate 0 of the vertex.</param>
        /// <param name="texCoord1">The texture coordinate 1 of the vertex.</param>
        /// <param name="texCoord2">The texture coordinate 2 of the vertex.</param>
        /// <param name="texCoord3">The texture coordinate 3 of the vertex.</param>
        public StandardVertex(Vector3F position, Vector3F normal, Vector4F tangent, ColorValue color, Vector2F texCoord0, Vector2F texCoord1, Vector2F texCoord2, Vector2F texCoord3, Vector4I blendIndices, Vector4F blendWeights)
        {
            this.Position     = position;
            this.Normal       = normal;
            this.Tangent      = Vector4F.Zero;
            this.Color        = color;
            this.TexCoord0    = texCoord0;
            this.TexCoord1    = texCoord1;
            this.TexCoord2    = texCoord2;
            this.TexCoord3    = texCoord3;
            this.BlendIndices = blendIndices;
            this.BlendWeights = blendWeights;
        }
コード例 #8
0
        public static object ExtractOneComponentArray(StandardVertex[] vertices, Components component)
        {
            switch (component)
            {
            case Components.Position:
            {
                Vector3F[] array = new Vector3F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].Position;
                }
                return(array);
            }

            case Components.Normal:
            {
                Vector3F[] array = new Vector3F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].Normal;
                }
                return(array);
            }

            case Components.Tangent:
            {
                Vector4F[] array = new Vector4F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].Tangent;
                }
                return(array);
            }

            case Components.Color:
            {
                ColorValue[] array = new ColorValue[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].Color;
                }
                return(array);
            }

            case Components.TexCoord0:
            {
                Vector2F[] array = new Vector2F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].TexCoord0;
                }
                return(array);
            }

            case Components.TexCoord1:
            {
                Vector2F[] array = new Vector2F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].TexCoord1;
                }
                return(array);
            }

            case Components.TexCoord2:
            {
                Vector2F[] array = new Vector2F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].TexCoord2;
                }
                return(array);
            }

            case Components.TexCoord3:
            {
                Vector2F[] array = new Vector2F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].TexCoord3;
                }
                return(array);
            }

            case Components.BlendIndices:
            {
                Vector4I[] array = new Vector4I[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].BlendIndices;
                }
                return(array);
            }

            case Components.BlendWeights:
            {
                Vector4F[] array = new Vector4F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].BlendWeights;
                }
                return(array);
            }
            }

            Log.Fatal("StandardVertex: ExtractOneComponentArray: Invalid requested component.");
            return(null);
        }
コード例 #9
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();
        }