Beispiel #1
0
        /// <summary>
        /// Returns a TColorValue that is interpolated between two TColorValues by the given amound (0.0-1.0).
        /// </summary>
        /// <param Name_="start"></param>
        /// <param Name_="end"></param>
        /// <param Name_="percent"></param>
        /// <returns></returns>
        public static TColor Interpolate(TColor start, TColor end, float percent)
        {
            TColor r = new TColor();

            r.R = start.R + (percent * (end.R - start.R));
            r.G = start.G + (percent * (end.G - start.G));
            r.B = start.B + (percent * (end.B - start.B));
            r.A = start.A + (percent * (end.A - start.A));
            return(r);
        }
        public void Write(T valor)
        {
            // is this._data still null?
            if (this._data == null)
            {
                throw new ArgumentNullException();
            }

            Object data = valor;

            try
            {
                if (valor is Vector2f)
                {
                    int      floatindex = CurrentOffset_ * 2;
                    Vector2f v          = (Vector2f)data;
                    this._data[floatindex]     = v.X;
                    this._data[floatindex + 1] = v.Y;
                }
                if (valor is Vector3f)
                {
                    int      floatindex = CurrentOffset_ * 3;
                    Vector3f v          = (Vector3f)data;
                    this._data[floatindex]     = v.X;
                    this._data[floatindex + 1] = v.Y;
                    this._data[floatindex + 2] = v.Z;
                }
                if (valor is Vector4f)
                {
                    int      floatindex = CurrentOffset_ * 4;
                    Vector4f v          = (Vector4f)data;
                    this._data[floatindex]     = v.X;
                    this._data[floatindex + 1] = v.Y;
                    this._data[floatindex + 2] = v.Z;
                    this._data[floatindex + 3] = v.W;
                }
                if (valor is TColor)
                {
                    int    floatindex = CurrentOffset_ * 4;
                    TColor v          = (TColor)data;
                    this._data[floatindex]     = v.R;
                    this._data[floatindex + 1] = v.G;
                    this._data[floatindex + 2] = v.B;
                    this._data[floatindex + 3] = v.A;
                }
                CurrentOffset_++;
            }
            catch (Exception e)
            {
                if (e is IndexOutOfRangeException)
                {
                    throw new IndexOutOfRangeException();
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Returns a TColorValue that is interpolated between two TColorValues by the given amound (0.0-1.0).
 /// </summary>
 /// <param Name_="start"></param>
 /// <param Name_="end"></param>
 /// <param Name_="percent"></param>
 /// <returns></returns>
 public static TColor Interpolate( TColor start, TColor end, float percent )
 {
     TColor r = new TColor();
     r.R = start.R + (percent * (end.R - start.R));
     r.G = start.G + (percent * (end.G - start.G));
     r.B = start.B + (percent * (end.B - start.B));
     r.A = start.A + (percent * (end.A - start.A));
     return r;
 }
        /// <summary>
        /// <para>Get: Devuelve una nueva instanacia de tipo T, segun el indice index</para>
        /// <para>Set: Establece el valor de tipo T en el índice index especificado</para>
        /// </summary>
        /// <param Name_="index"></param>
        /// <returns></returns>
        public T this[int index]
        {
            get
            {
                if (this._data == null)
                {
                    throw new ArgumentNullException();
                }

                Type vectorType = typeof(T);

                try
                {
                    if (vectorType == typeof(Vector2f))
                    {
                        int      floatindex = index * 2;
                        Vector2f vector     = new Vector2f();
                        vector.X = this._data[floatindex];
                        vector.Y = this._data[floatindex + 1];
                        return((T)Convert.ChangeType(vector, typeof(T)));
                    }
                    if (vectorType == typeof(Vector3f))
                    {
                        int      floatindex = index * 3;
                        Vector3f v          = new Vector3f();
                        v.X = this._data[floatindex];
                        v.Y = this._data[floatindex + 1];
                        v.Z = this._data[floatindex + 2];
                        return((T)Convert.ChangeType(v, typeof(T)));
                    }
                    if (vectorType == typeof(Vector4f))
                    {
                        int      floatindex = index * 4;
                        Vector4f v          = new Vector4f();
                        v.X = this._data[floatindex];
                        v.Y = this._data[floatindex + 1];
                        v.Z = this._data[floatindex + 2];
                        v.W = this._data[floatindex + 3];
                        return((T)Convert.ChangeType(v, typeof(T)));
                    }
                    if (vectorType == typeof(TColor))
                    {
                        int  floatindex = index * 4;
                        byte r, g, b, a;
                        r = (byte)this._data[floatindex];
                        g = (byte)this._data[floatindex + 1];
                        b = (byte)this._data[floatindex + 2];
                        a = (byte)this._data[floatindex + 3];
                        TColor v = new TColor(Color.FromArgb(a, r, g, b));
                        return((T)Convert.ChangeType(v, typeof(T)));
                    }
                }
                catch (Exception e)
                {
                    if (e is IndexOutOfRangeException)
                    {
                        throw new IndexOutOfRangeException();
                    }
                }
                return(null);
            }
            set
            {
                // is this._data still null?
                if (this._data == null)
                {
                    throw new ArgumentNullException();
                }

                Object data = value;

                try
                {
                    if (value is Vector2f)
                    {
                        int      floatindex = index * 2;
                        Vector2f v          = (Vector2f)data;
                        this._data[floatindex]     = v.X;
                        this._data[floatindex + 1] = v.Y;
                    }
                    if (value is Vector3f)
                    {
                        int      floatindex = index * 3;
                        Vector3f v          = (Vector3f)data;
                        this._data[floatindex]     = v.X;
                        this._data[floatindex + 1] = v.Y;
                        this._data[floatindex + 2] = v.Z;
                    }
                    if (value is Vector4f)
                    {
                        int      floatindex = index * 4;
                        Vector4f v          = (Vector4f)data;
                        this._data[floatindex]     = v.X;
                        this._data[floatindex + 1] = v.Y;
                        this._data[floatindex + 2] = v.Z;
                        this._data[floatindex + 3] = v.W;
                    }
                    if (value is TColor)
                    {
                        int    floatindex = index * 4;
                        TColor v          = (TColor)data;
                        this._data[floatindex]     = v.R;
                        this._data[floatindex + 1] = v.G;
                        this._data[floatindex + 2] = v.B;
                        this._data[floatindex + 3] = v.A;
                    }
                }
                catch (Exception e)
                {
                    if (e is IndexOutOfRangeException)
                    {
                        throw new IndexOutOfRangeException();
                    }
                }
            }
        }