Browse Source

Some transform fixes: Fix conversion to generic type (for interpolation), and add ToString() for decomposed matrix.

Michael Ragazzon 6 years ago
parent
commit
7a0c4df49f

+ 11 - 2
Include/RmlUi/Core/PropertyIdSet.h

@@ -35,10 +35,19 @@
 namespace Rml {
 namespace Rml {
 namespace Core {
 namespace Core {
 
 
-
 class PropertyIdSetIterator;
 class PropertyIdSetIterator;
 
 
 
 
+/*
+	PropertyIdSet is a 'set'-like container for PropertyIds. 
+	
+	It is quite cheap to construct and use, requiring no dynamic allocation for the library-defined IDs as they are based around a bitset.
+	Custom IDs on the other hand need to use a more trafitional set, and are thus more expensive to insert. 
+
+	Supports union and intersection operations between two sets, as well as iteration through the IDs that are inserted.
+*/
+
+
 class RMLUICORE_API PropertyIdSet {
 class RMLUICORE_API PropertyIdSet {
 private:
 private:
 	static constexpr size_t N = (size_t)PropertyId::NumDefinedIds;
 	static constexpr size_t N = (size_t)PropertyId::NumDefinedIds;
@@ -129,7 +138,7 @@ public:
 		return result;
 		return result;
 	}
 	}
 
 
-	// Iterator support
+	// Iterator support. Iterates through all the PropertyIds that are set (contained).
 	// @note: Modifying the container invalidates the iterators. Only const_iterators are provided.
 	// @note: Modifying the container invalidates the iterators. Only const_iterators are provided.
 	inline PropertyIdSetIterator begin() const;
 	inline PropertyIdSetIterator begin() const;
 	inline PropertyIdSetIterator end() const;
 	inline PropertyIdSetIterator end() const;

+ 1 - 1
Include/RmlUi/Core/TypeConverter.inl

@@ -37,7 +37,7 @@ bool TypeConverter<SourceType, DestType>::Convert(const SourceType& /*src*/, Des
 }
 }
 
 
 ///
 ///
-/// Partial specialisations at the top, as they full specialisations should be prefered.
+/// Partial specialisations at the top, as the full specialisations should be preferred.
 ///
 ///
 template< typename T >
 template< typename T >
 class TypeConverter< T, Stream >
 class TypeConverter< T, Stream >

+ 6 - 4
Samples/basic/animation/data/animation.rml

@@ -74,15 +74,17 @@
 		
 		
 		/* -- TRANSFORM TESTS */
 		/* -- TRANSFORM TESTS */
 		#generic {
 		#generic {
-			transform: translateX(100px) rotate3d(1.0, 0, 1.0, 0deg);
+			/* Note the translateX vs translateY in animation target, and scaleX vs scaleY. In 
+			   order to match, they are converted to their generic forms, translate3d and scale3d. */
+			transform: translateX(100px) rotateZ(70deg) scaleX(1.3);
 		}
 		}
 		#combine {
 		#combine {
 			transform: rotate(45deg);
 			transform: rotate(45deg);
 		}
 		}
 		#decomposition {
 		#decomposition {
-			/* The scale(1.0) should force a full matrix recomposition when interpolating,
-			   then, the information about multiple turns get lost and it only turns 45deg. */
-			transform: rotate(45deg) scale(1.0);
+			/* To interpolate the rotate3d transforms, we need to decompose the matrix, 
+			   see the element info in the debugger for the resulting matrix. */
+			transform: translateX(100px) rotate3d(1.0, 0, 1.0, 0deg);
 		}
 		}
 		
 		
 		/* -- MIXED UNITS TESTS */
 		/* -- MIXED UNITS TESTS */

+ 4 - 4
Samples/basic/animation/src/main.cpp

@@ -88,8 +88,8 @@ public:
 			// Transform tests
 			// Transform tests
 			{
 			{
 				auto el = document->GetElementById("generic");
 				auto el = document->GetElementById("generic");
-				auto p = Transform::MakeProperty({ Transforms::TranslateY{50, Property::PX}, Transforms::Rotate3D{0.8f, 0, 1, 110, Property::DEG}});
-				el->Animate("transform", p, 1.3f, Tween{Tween::Quadratic, Tween::InOut}, -1, true);
+				auto p = Transform::MakeProperty({ Transforms::TranslateY{50, Property::PX}, Transforms::RotateZ{-90, Property::DEG}, Transforms::ScaleY{0.8} });
+				el->Animate("transform", p, 1.5f, Tween{Tween::Sine, Tween::InOut}, -1, true);
 			}
 			}
 			{
 			{
 				auto el = document->GetElementById("combine");
 				auto el = document->GetElementById("combine");
@@ -98,8 +98,8 @@ public:
 			}
 			}
 			{
 			{
 				auto el = document->GetElementById("decomposition");
 				auto el = document->GetElementById("decomposition");
-				auto p = Transform::MakeProperty({ Transforms::Translate2D{50, 50, Property::PX}, Transforms::Rotate2D(1215) });
-				el->Animate("transform", p, 8.0f, Tween{}, -1, true);
+				auto p = Transform::MakeProperty({ Transforms::TranslateY{50, Property::PX}, Transforms::Rotate3D{0.8f, 0, 1, 110, Property::DEG} });
+				el->Animate("transform", p, 1.3f, Tween{ Tween::Quadratic, Tween::InOut }, -1, true);
 			}
 			}
 
 
 			// Mixed units tests
 			// Mixed units tests

+ 37 - 9
Source/Core/TransformPrimitive.cpp

@@ -611,14 +611,14 @@ struct ConvertToGenericTypeVisitor
 		PrimitiveVariant result = primitive;
 		PrimitiveVariant result = primitive;
 		switch (primitive.type)
 		switch (primitive.type)
 		{
 		{
-		case PrimitiveVariant::TRANSLATEX: result.translate_3d = this->operator()(primitive.translate_x); break;
-		case PrimitiveVariant::TRANSLATEY: result.translate_3d = this->operator()(primitive.translate_y); break;
-		case PrimitiveVariant::TRANSLATEZ: result.translate_3d = this->operator()(primitive.translate_z); break;
-		case PrimitiveVariant::TRANSLATE2D: result.translate_3d = this->operator()(primitive.translate_2d); break;
-		case PrimitiveVariant::SCALEX: result.scale_3d = this->operator()(primitive.scale_x); break;
-		case PrimitiveVariant::SCALEY: result.scale_3d = this->operator()(primitive.scale_y); break;
-		case PrimitiveVariant::SCALEZ: result.scale_3d = this->operator()(primitive.scale_z); break;
-		case PrimitiveVariant::SCALE2D: result.scale_3d = this->operator()(primitive.scale_2d); break;
+		case PrimitiveVariant::TRANSLATEX:  result.type = PrimitiveVariant::TRANSLATE3D; result.translate_3d = this->operator()(primitive.translate_x);  break;
+		case PrimitiveVariant::TRANSLATEY:  result.type = PrimitiveVariant::TRANSLATE3D; result.translate_3d = this->operator()(primitive.translate_y);  break;
+		case PrimitiveVariant::TRANSLATEZ:  result.type = PrimitiveVariant::TRANSLATE3D; result.translate_3d = this->operator()(primitive.translate_z);  break;
+		case PrimitiveVariant::TRANSLATE2D: result.type = PrimitiveVariant::TRANSLATE3D; result.translate_3d = this->operator()(primitive.translate_2d); break;
+		case PrimitiveVariant::SCALEX:      result.type = PrimitiveVariant::SCALE3D;     result.scale_3d     = this->operator()(primitive.scale_x);      break;
+		case PrimitiveVariant::SCALEY:      result.type = PrimitiveVariant::SCALE3D;     result.scale_3d     = this->operator()(primitive.scale_y);      break;
+		case PrimitiveVariant::SCALEZ:      result.type = PrimitiveVariant::SCALE3D;     result.scale_3d     = this->operator()(primitive.scale_z);      break;
+		case PrimitiveVariant::SCALE2D:     result.type = PrimitiveVariant::SCALE3D;     result.scale_3d     = this->operator()(primitive.scale_2d);     break;
 		default:
 		default:
 			RMLUI_ASSERT(false);
 			RMLUI_ASSERT(false);
 			break;
 			break;
@@ -778,6 +778,35 @@ static inline String ToString(const Transforms::UnresolvedPrimitive<N> & p) noex
 	return result;
 	return result;
 }
 }
 
 
+static inline String ToString(const Transforms::DecomposedMatrix4& p) noexcept {
+	static const DecomposedMatrix4 d{
+		Vector4f(0, 0, 0, 1),
+		Vector4f(0, 0, 0, 1),
+		Vector3f(0, 0, 0),
+		Vector3f(1, 1, 1),
+		Vector3f(0, 0, 0)
+	}; 
+	String tmp;
+	String result;
+	
+	if(p.perspective != d.perspective && TypeConverter< Vector4f, String >::Convert(p.perspective, tmp))
+		result += "perspective(" + tmp + "), ";
+	if (p.quaternion != d.quaternion && TypeConverter< Vector4f, String >::Convert(p.quaternion, tmp))
+		result += "quaternion(" + tmp + "), ";
+	if (p.translation != d.translation && TypeConverter< Vector3f, String >::Convert(p.translation, tmp))
+		result += "translation(" + tmp + "), ";
+	if (p.scale != d.scale && TypeConverter< Vector3f, String >::Convert(p.scale, tmp))
+		result += "scale(" + tmp + "), ";
+	if (p.skew != d.skew && TypeConverter< Vector3f, String >::Convert(p.skew, tmp))
+		result += "skew(" + tmp + "), ";
+
+	if (result.size() > 2)
+		result.resize(result.size() - 2);
+
+	result = "decomposedMatrix3d{ " + result + " }";
+
+	return result;
+}
 
 
 
 
 String ToString(const Transforms::Matrix2D & p) noexcept { return "matrix" + ToString(static_cast<const Transforms::ResolvedPrimitive< 6 >&>(p), ""); }
 String ToString(const Transforms::Matrix2D & p) noexcept { return "matrix" + ToString(static_cast<const Transforms::ResolvedPrimitive< 6 >&>(p), ""); }
@@ -801,7 +830,6 @@ String ToString(const Transforms::SkewX & p) noexcept { return "skewX" + ToStrin
 String ToString(const Transforms::SkewY & p) noexcept { return "skewY" + ToString(static_cast<const Transforms::ResolvedPrimitive< 1 >&>(p), "deg", true); }
 String ToString(const Transforms::SkewY & p) noexcept { return "skewY" + ToString(static_cast<const Transforms::ResolvedPrimitive< 1 >&>(p), "deg", true); }
 String ToString(const Transforms::Skew2D & p) noexcept { return "skew" + ToString(static_cast<const Transforms::ResolvedPrimitive< 2 >&>(p), "deg", true); }
 String ToString(const Transforms::Skew2D & p) noexcept { return "skew" + ToString(static_cast<const Transforms::ResolvedPrimitive< 2 >&>(p), "deg", true); }
 String ToString(const Transforms::Perspective & p) noexcept { return "perspective" + ToString(static_cast<const Transforms::UnresolvedPrimitive< 1 >&>(p)); }
 String ToString(const Transforms::Perspective & p) noexcept { return "perspective" + ToString(static_cast<const Transforms::UnresolvedPrimitive< 1 >&>(p)); }
-String ToString(const Transforms::DecomposedMatrix4& p) noexcept { return "decomposedMatrix3d"; }
 
 
 
 
 struct ToStringVisitor
 struct ToStringVisitor