Ejemplo n.º 1
0
        public static XMVector RotationAxis(XMVector axis, float angle)
        {
            Debug.Assert(!XMVector3.Equal(axis, XMGlobalConstants.Zero), "Reviewed");
            Debug.Assert(!XMVector3.IsInfinite(axis), "Reviewed");

            XMVector normal = XMVector3.Normalize(axis);

            return(XMQuaternion.RotationNormal(normal, angle));
        }
Ejemplo n.º 2
0
        public static XMVector RgbToHsv(XMVector rgb)
        {
            XMVector r = XMVector.SplatX(rgb);
            XMVector g = XMVector.SplatY(rgb);
            XMVector b = XMVector.SplatZ(rgb);

            XMVector min = XMVector.Min(r, XMVector.Min(g, b));
            XMVector v   = XMVector.Max(r, XMVector.Max(g, b));

            XMVector d = XMVector.Subtract(v, min);
            XMVector s = XMVector3.NearEqual(v, XMGlobalConstants.Zero, XMGlobalConstants.Epsilon) ?
                         XMGlobalConstants.Zero :
                         XMVector.Divide(d, v);

            if (XMVector3.Less(d, XMGlobalConstants.Epsilon))
            {
                // Achromatic, assume H of 0
                XMVector hv  = XMVector.Select(v, XMGlobalConstants.Zero, XMGlobalConstants.Select1000);
                XMVector hva = XMVector.Select(rgb, hv, XMGlobalConstants.Select1110);
                return(XMVector.Select(s, hva, XMGlobalConstants.Select1011));
            }
            else
            {
                XMVector h;

                if (XMVector3.Equal(r, v))
                {
                    // Red is max
                    h = XMVector.Divide(XMVector.Subtract(g, b), d);

                    if (XMVector3.Less(g, b))
                    {
                        h = XMVector.Add(h, XMGlobalConstants.Six);
                    }
                }
                else if (XMVector3.Equal(g, v))
                {
                    // Green is max
                    h = XMVector.Divide(XMVector.Subtract(b, r), d);
                    h = XMVector.Add(h, XMGlobalConstants.Two);
                }
                else
                {
                    // Blue is max
                    h = XMVector.Divide(XMVector.Subtract(r, g), d);
                    h = XMVector.Add(h, XMGlobalConstants.Four);
                }

                h = XMVector.Divide(h, XMGlobalConstants.Six);

                XMVector hv  = XMVector.Select(v, h, XMGlobalConstants.Select1000);
                XMVector hva = XMVector.Select(rgb, hv, XMGlobalConstants.Select1110);
                return(XMVector.Select(s, hva, XMGlobalConstants.Select1011));
            }
        }
Ejemplo n.º 3
0
        public static XMVector RgbToHsl(XMVector rgb)
        {
            XMVector r = XMVector.SplatX(rgb);
            XMVector g = XMVector.SplatY(rgb);
            XMVector b = XMVector.SplatZ(rgb);

            XMVector min = XMVector.Min(r, XMVector.Min(g, b));
            XMVector max = XMVector.Max(r, XMVector.Max(g, b));

            XMVector l  = XMVector.Multiply(XMVector.Add(min, max), XMGlobalConstants.OneHalf);
            XMVector d  = XMVector.Subtract(max, min);
            XMVector la = XMVector.Select(rgb, l, XMGlobalConstants.Select1110);

            if (XMVector3.Less(d, XMGlobalConstants.Epsilon))
            {
                // Achromatic, assume H and S of 0
                return(XMVector.Select(la, XMGlobalConstants.Zero, XMGlobalConstants.Select1100));
            }
            else
            {
                XMVector s;
                XMVector h;

                XMVector d2 = XMVector.Add(min, max);

                if (XMVector3.Greater(l, XMGlobalConstants.OneHalf))
                {
                    // d / (2-max-min)
                    s = XMVector.Divide(d, XMVector.Subtract(XMGlobalConstants.Two, d2));
                }
                else
                {
                    // d / (max+min)
                    s = XMVector.Divide(d, d2);
                }

                if (XMVector3.Equal(r, max))
                {
                    // Red is max
                    h = XMVector.Divide(XMVector.Subtract(g, b), d);
                }
                else if (XMVector3.Equal(g, max))
                {
                    // Green is max
                    h = XMVector.Divide(XMVector.Subtract(b, r), d);
                    h = XMVector.Add(h, XMGlobalConstants.Two);
                }
                else
                {
                    // Blue is max
                    h = XMVector.Divide(XMVector.Subtract(r, g), d);
                    h = XMVector.Add(h, XMGlobalConstants.Four);
                }

                h = XMVector.Divide(h, XMGlobalConstants.Six);

                if (XMVector3.Less(h, XMGlobalConstants.Zero))
                {
                    h = XMVector.Add(h, XMGlobalConstants.One);
                }

                XMVector lha = XMVector.Select(la, h, XMGlobalConstants.Select1100);
                return(XMVector.Select(s, lha, XMGlobalConstants.Select1011));
            }
        }