예제 #1
0
 public void MultiplyTest()
 {
     var traits = ColorTraits.Instance;
       var value = new Color(0.1f, 0.2f, 0.3f, 1.0f);
       Assert.AreEqual(new Color(0, 0, 0, 0), traits.Multiply(value, 0));
       Assert.AreEqual(value, traits.Multiply(value, 1));
       Assert.AreEqual(new Color(value.ToVector4() + value.ToVector4()), traits.Multiply(value, 2));
       Assert.AreEqual(new Color(value.ToVector4() + value.ToVector4() + value.ToVector4()), traits.Multiply(value, 3));
 }
예제 #2
0
파일: Lerp.cs 프로젝트: vkd/Ctrl-Space
 public static Color OfColor(Color v1, Color v2, float t)
 {
     if (t <= 0f)
         return v1;
     if (t >= 1f)
         return v2;
     return new Color((1f - t) * v1.ToVector4() + t * v2.ToVector4());
 }
예제 #3
0
 public void InterpolationTest()
 {
     var traits = ColorTraits.Instance;
       var value0 = new Color(0.1f, 0.2f, 0.3f, 1.0f);
       var value1 = new Color(0.4f, 0.5f, 0.6f, 0.5f);
       Assert.AreEqual(value0, traits.Interpolate(value0, value1, 0.0f));
       Assert.AreEqual(value1, traits.Interpolate(value0, value1, 1.0f));
       Assert.AreEqual(new Color(0.25f * value0.ToVector4() + 0.75f * value1.ToVector4()), traits.Interpolate(value0, value1, 0.75f));
 }
예제 #4
0
 public void SetVector(string name, XNA.Color color, bool useAlpha)
 {
     if (useAlpha)
     {
         SetVector(name, color.ToVector4());
     }
     else
     {
         SetVector(name, color.ToVector3());
     }
 }
예제 #5
0
        public void FromByTest()
        {
            // IAnimationValueTraits<T> is used in a from-by animation to a add a relative offset to
              // the start value.

              var traits = ColorTraits.Instance;
              var from = new Color(0.1f, 0.2f, 0.3f, 1.0f);
              var by = new Color(0.4f, 0.5f, 0.6f, 0.5f);

              var to = traits.Add(from, by);
              Assert.AreEqual(new Color(by.ToVector4() + from.ToVector4()), to);
        }
예제 #6
0
        public static Texture2D CreateVertical(int height, Color top, Color bottom)
        {
            var texture = new Texture2D(CurrentGame.SpriteBatch.GraphicsDevice, 1, height);
            var bgc = new Color[height];

            for (var i = 0; i < bgc.Length; i++)
            {
                var amount = (float) i/height;
                bgc[i] = new Color(Vector4.Lerp(top.ToVector4(), bottom.ToVector4(), amount));
            }
            texture.SetData(bgc);
            return texture;
        }
예제 #7
0
        public static Texture2D CreateHorizontal(int width, Color left, Color right)
        {
            var texture = new Texture2D(CurrentGame.SpriteBatch.GraphicsDevice, width, 1);
            var bgc = new Color[width];

            for (var i = 0; i < bgc.Length; i++)
            {
                var amount = (float)i / width;
                bgc[i] = new Color(Vector4.Lerp(left.ToVector4(), right.ToVector4(), amount));
            }
            texture.SetData(bgc);
            return texture;
        }
예제 #8
0
        private void DrawString(string s, Rectangle rect, FontData fontData, Color tintColor)
        {
            if (fontData == null)
            {
                return;
            }
            Vector4 cl1 = fontData.TextColor.ToVector4();
            Vector4 cl2 = tintColor.ToVector4();
            Color   cl  = new Color(cl1.X * cl2.X, cl1.Y * cl2.Y, cl1.Z * cl2.Z, cl1.W * cl2.W);


            float      textScale = 0.7f;
            Vector2    position  = new Vector2();
            Vector2    origin    = new Vector2();
            SpriteFont font      = GetFont(fontData);
            Vector2    size      = font.MeasureString(s);

            size.X *= textScale;
            size.Y *= textScale;
            if (fontData.Anchor == Enums.Anchor.TopLeft || fontData.Anchor == Enums.Anchor.Left || fontData.Anchor == Enums.Anchor.BottomLeft)
            {
                position.X = rect.X;
            }
            else if (fontData.Anchor == Enums.Anchor.Top || fontData.Anchor == Enums.Anchor.Center || fontData.Anchor == Enums.Anchor.Bottom)
            {
                position.X = rect.X + (rect.Width - size.X) / 2;
            }
            else if (fontData.Anchor == Enums.Anchor.TopRight || fontData.Anchor == Enums.Anchor.Right || fontData.Anchor == Enums.Anchor.BottomRight)
            {
                position.X = rect.X + rect.Width - size.X;
            }
            if (fontData.Anchor == Enums.Anchor.TopLeft || fontData.Anchor == Enums.Anchor.Top || fontData.Anchor == Enums.Anchor.TopRight)
            {
                position.Y = rect.Y;
            }
            else if (fontData.Anchor == Enums.Anchor.Left || fontData.Anchor == Enums.Anchor.Center || fontData.Anchor == Enums.Anchor.Right)
            {
                position.Y = rect.Y + (rect.Height - size.Y) / 2;
            }
            else if (fontData.Anchor == Enums.Anchor.BottomLeft || fontData.Anchor == Enums.Anchor.Bottom || fontData.Anchor == Enums.Anchor.BottomRight)
            {
                position.Y = rect.Y + rect.Height - size.Y;
            }
            origin.X = (position.X - rect.X) / (rect.Width - size.X);
            origin.X = (position.X - rect.Y) / (rect.Width - size.Y);
            SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);
            SpriteBatch.DrawString(font, s, position, cl, 0, origin, textScale, SpriteEffects.None, 0);
            SpriteBatch.End();
        }
예제 #9
0
파일: ColorTintList.cs 프로젝트: tivtag/Fly
        /// <summary>
        /// Applies the combined color tinting of this ColorTintList to
        /// the given <paramref name="baseColor"/>.
        /// </summary>
        /// <param name="baseColor">
        /// The Xna.Color the tinting should be based on.
        /// </param>
        /// <returns>
        /// The tinted Xna.Color.
        /// </returns>
        public Xna.Color ApplyTinting(Xna.Color baseColor)
        {
            if (this.list.Count == 0)
            {
                return(baseColor);
            }

            Vector4 tintedColor = baseColor.ToVector4().ToAtom();

            for (int i = 0; i < this.list.Count; ++i)
            {
                tintedColor = this.list[i].Apply(tintedColor);
            }

            return(new Xna.Color(tintedColor.ToXna()));
        }
        /// <summary>
        ///   Creates a texture of the specified color.
        /// </summary>
        /// <param name="graphicsDevice"> The graphics device to use. </param>
        /// <param name="width"> The width of the texture. </param>
        /// <param name="height"> The height of the texture. </param>
        /// <param name="color"> The color to set the texture to. </param>
        /// <returns> The newly created texture. </returns>
        public static Texture2D Create(GraphicsDevice graphicsDevice, int width, int height, Color color)
        {
            // create the rectangle texture without colors
            var texture = new Texture2D(graphicsDevice, width, height);

            // Create a color array for the pixels
            var colors = new Color[width*height];
            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = new Color(color.ToVector4());
            }

            // Set the color data for the texture
            texture.SetData(colors);

            return texture;
        }
예제 #11
0
        private void DrawString(string s, Rectangle rect, FontData fontData, Color tintColor)
        {
            if (fontData == null)
            {
                return;
            }

            Vector4 cl1 = fontData.TextColor.ToVector4();
            Vector4 cl2 = tintColor.ToVector4();
            Color   cl  = new Color(cl1.X * cl2.X, cl1.Y * cl2.Y, cl1.Z * cl2.Z, cl1.W * cl2.W);


            float      textScale = 1.0f;// 0.7->1.0f to make it look the same as that in game
            Vector2    position  = new Vector2();
            Vector2    origin    = new Vector2();
            SpriteFont font      = GetFont(fontData);

            s = textsizefix(s, font, textScale, rect);
            Vector2 size    = font.MeasureString(s);
            Vector2 orgsize = font.MeasureString(s);

            //Vector2 scaleVect = new Vector2(textScale, textScale * 0.8f);
            //size bound check, if the text box is larger than the rect. replace the text by w..

            size.X *= textScale;
            size.Y *= textScale;
            if (fontData.Anchor == Enums.Anchor.TopLeft || fontData.Anchor == Enums.Anchor.Left || fontData.Anchor == Enums.Anchor.BottomLeft)
            {
                position.X = rect.X;
                origin.X   = position.X - rect.X;
            }
            else if (fontData.Anchor == Enums.Anchor.Top || fontData.Anchor == Enums.Anchor.Center || fontData.Anchor == Enums.Anchor.Bottom)
            {
                position.X = rect.X + rect.Width / 2;
                origin.X   = size.X / 2;
            }
            else if (fontData.Anchor == Enums.Anchor.TopRight || fontData.Anchor == Enums.Anchor.Right || fontData.Anchor == Enums.Anchor.BottomRight)
            {
                position.X = rect.X + rect.Width;
                origin.X   = size.X;
            }
            if (fontData.Anchor == Enums.Anchor.TopLeft || fontData.Anchor == Enums.Anchor.Top || fontData.Anchor == Enums.Anchor.TopRight)
            {
                position.Y = rect.Y;
                origin.Y   = position.Y - rect.Y;
            }
            else if (fontData.Anchor == Enums.Anchor.Left || fontData.Anchor == Enums.Anchor.Center || fontData.Anchor == Enums.Anchor.Right)
            {
                position.Y = rect.Y + rect.Height / 2;
                origin.Y   = size.Y / 2;
            }
            else if (fontData.Anchor == Enums.Anchor.BottomLeft || fontData.Anchor == Enums.Anchor.Bottom || fontData.Anchor == Enums.Anchor.BottomRight)
            {
                position.Y = rect.Y + rect.Height;
                origin.Y   = size.Y;
            }
            //origin.X = (position.X - rect.X) / (rect.Width - size.X);
            //origin.Y = (position.Y - rect.Y) / (rect.Height - size.Y);
            //position.X -= (orgsize.X - size.X)/2;
            //position.Y -= (orgsize.Y -size.Y)/2;
            // SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);
            SpriteBatch.Begin(SpriteSortMode.Immediate, XNA_BlendState.AlphaBlend);
            SpriteBatch.DrawString(font, s, position, cl, 0, origin, textScale, SpriteEffects.None, 0);
            SpriteBatch.End();
        }
예제 #12
0
        /// <summary>
        /// Draws a string on the screen according to absolute positioning.
        /// </summary>
        /// <param name="text">The text to be drawn.</param>
        /// <param name="position">The text's position.</param>
        /// <param name="color">The text's color.</param>
        public void DrawString(String text, XNAVector2 position, XNAColor color)
        {
            XNAVector4 c = color.ToVector4();

            Color4 drawcolor = new Color4(c.W, c.X, c.Y, c.Z);

            _font.DrawString(null, text, (int)position.X, (int)position.Y, drawcolor);
        }
예제 #13
0
    private MeshNode CreateMeshNode(IEnumerable<Submesh> submeshes, Color color)
    {
      var mesh = new Mesh();
      mesh.Submeshes.AddRange(submeshes);

      var material = new Material();
      BasicEffectBinding defaultEffectBinding = new BasicEffectBinding(GraphicsService, null)
      {
        LightingEnabled = true,
        TextureEnabled = false,
        VertexColorEnabled = false
      };
      defaultEffectBinding.Set("DiffuseColor", color.ToVector4());
      defaultEffectBinding.Set("SpecularColor", new Vector3(1, 1, 1));
      defaultEffectBinding.Set("SpecularPower", 100f);
      material.Add("Default", defaultEffectBinding);

      var triangleMesh = mesh.ToTriangleMesh();
      var shape = new TriangleMeshShape(triangleMesh);
      var aabb = shape.GetAabb();
      mesh.BoundingShape = new TransformedShape(
        new GeometricObject(
          new BoxShape(aabb.Extent),
          new Pose(aabb.Center)));

      mesh.Materials.Add(material);
      foreach (var submesh in mesh.Submeshes)
        submesh.MaterialIndex = 0;

      return new MeshNode(mesh);
    }
예제 #14
0
 /// <summary>
 /// Gets the color inbetween min and max at "distance". Black -> White would become gray.
 /// </summary>
 /// <param name="distance">0 = min, 1 = max. If null then it will be randomized.</param>
 public static Color GetColorGradient(Color min, Color max, float?distance)
 {
     return(new Color(Vector4.Lerp(min.ToVector4(), max.ToVector4(), distance ?? (float)Random.NextDouble())));
 }
예제 #15
0
 /// <summary>
 /// Gets the color inbetween min and max at "distance". Black -> White would become gray.
 /// </summary>
 /// <param name="distance">0 = min, 1 = max. If null then it will be randomized.</param>
 public static Color GetColorGradient(Color min, Color max, float? distance)
 {
     return new Color(Vector4.Lerp(min.ToVector4(), max.ToVector4(), distance ?? (float)Random.NextDouble()));
 }
 public void setMainColorShifting(Microsoft.Xna.Framework.Color _inColor_)
 {
     //ColorTransformEffect.Parameters["ShiftedColor"].SetValue(_inColor_.ToVector4());
     ColorTransformEffect.colorshiftMain = _inColor_.ToVector4();
 }
예제 #17
0
        public void ToVector4Tests()
        {
            Color c = new Color(0xFF, 0xBF, 0x7F, 0x00);
            Vector4 v = c.ToVector4();

            Assert.IsTrue(TestHelper.ApproximatelyEquals(1.0f, v.X), "Unexpected value for X");
            Assert.IsTrue(TestHelper.ApproximatelyEquals(0.75f, v.Y), "Unexpected value for Y");
            Assert.IsTrue(TestHelper.ApproximatelyEquals(0.5f, v.Z), "Unexpected value for Z");
            Assert.IsTrue(TestHelper.ApproximatelyEquals(0.0f, v.W), "Unexpected value for W");
        }
예제 #18
0
 public VertexPositionNormalColor(Vector3 position, Vector3 normal, Color color) {
     Position = position;
     Normal = normal;
     Color = color.ToVector4();
 }