Browse Source

Merge pull request #135 from AndrzejOran/master

Added Color Lerp Function
Marko Pintera 8 years ago
parent
commit
17fb3ddbd9
2 changed files with 15 additions and 0 deletions
  1. 9 0
      Source/BansheeUtility/Image/BsColor.cpp
  2. 6 0
      Source/BansheeUtility/Image/BsColor.h

+ 9 - 0
Source/BansheeUtility/Image/BsColor.cpp

@@ -335,5 +335,14 @@ namespace bs
 				*hue -= 1.0f;
 		}
 	}
+
+	Color Color::lerp(float t, const Color& a, const Color& b)
+	{
+		t = Math::clamp01(t);
+		return Color(a.r + (b.r - a.r) * t,
+					 a.g + (b.g - a.g) * t,
+					 a.b + (b.b - a.b) * t,
+					 a.a + (b.a - a.a) * t);
+	}
 }
 

+ 6 - 0
Source/BansheeUtility/Image/BsColor.h

@@ -254,6 +254,12 @@ namespace bs
 		 */
 		void getHSB(float* hue, float* saturation, float* brightness) const;
 
+        /**
+        * Linearly interpolates between the two colors using @p t. t should be in [0, 1] range, where t = 0 corresponds
+        * to the left color, while t = 1 corresponds to the right color.
+        */
+        static Color lerp(float t, const Color& a, const Color& b);
+
 		float r, g, b, a;
     };