#define DALI_MATRIX_H
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
class DALI_CORE_API Matrix
{
public:
-
- friend DALI_CORE_API std::ostream& operator<< (std::ostream& o, const Matrix& matrix);
+ friend DALI_CORE_API std::ostream& operator<<(std::ostream& o, const Matrix& matrix);
/**
* @brief Constructor.
* @SINCE_1_0.0
* @param[in] initialize True for initialization by zero or otherwise
*/
- explicit Matrix( bool initialize );
+ explicit Matrix(bool initialize);
/**
* @brief Constructor.
* @SINCE_1_0.0
* @param rotation Rotation as quaternion
*/
- explicit Matrix( const Quaternion& rotation );
+ explicit Matrix(const Quaternion& rotation);
/**
* @brief Copy constructor.
* @SINCE_1_0.0
* @param[in] matrix A reference to the copied matrix
*/
- Matrix( const Matrix& matrix );
+ Matrix(const Matrix& matrix);
/**
* @brief Assignment operator.
* @param[in] matrix A reference to the copied matrix
* @return A reference to this
*/
- Matrix& operator=( const Matrix& matrix );
+ Matrix& operator=(const Matrix& matrix);
/**
* @brief Move constructor.
* @SINCE_1_9.21
* @param[in] matrix A reference to the moved matrix
*/
- Matrix( Matrix&& matrix );
+ Matrix(Matrix&& matrix) noexcept;
/**
* @brief Move assignment operator.
* @param[in] matrix A reference to the moved matrix
* @return A reference to this
*/
- Matrix& operator=( Matrix&& matrix );
+ Matrix& operator=(Matrix&& matrix) noexcept;
/**
* @brief The identity matrix.
* @SINCE_1_0.0
* @param[in] scale Scale to set on top of identity matrix
*/
- void SetIdentityAndScale( const Vector3& scale );
+ void SetIdentityAndScale(const Vector3& scale);
/**
* @brief Inverts a transform Matrix.
* @return The translation
* @note inlined for performance reasons (generates less code than a function call)
*/
- const Vector4& GetTranslation() const { return reinterpret_cast<const Vector4&>(mMatrix[12]); }
+ const Vector4& GetTranslation() const
+ {
+ return reinterpret_cast<const Vector4&>(mMatrix[12]);
+ }
/**
* @brief Gets the x,y and z components of the translation as a Vector3.
* @return The translation
* @note inlined for performance reasons (generates less code than a function call)
*/
- const Vector3& GetTranslation3() const { return reinterpret_cast<const Vector3&>(mMatrix[12]); }
+ const Vector3& GetTranslation3() const
+ {
+ return reinterpret_cast<const Vector3&>(mMatrix[12]);
+ }
+
+ /**
+ * @brief Gets the x,y and z components of the scale as a Vector3.
+ * Note that transform scale always has positive components.
+ *
+ * This assumes the matrix is a transform matrix.
+ * @SINCE_2_2.17
+ * @return The scale
+ */
+ Vector3 GetScale() const;
/**
* @brief Sets the translation.
* @return The matrix contents as an array of 16 floats
* @note inlined for performance reasons (generates less code than a function call)
*/
- const float* AsFloat() const {return mMatrix;}
+ const float* AsFloat() const
+ {
+ return mMatrix;
+ }
/**
* @brief Returns the contents of the matrix as an array of 16 floats.
* @return The matrix contents as an array of 16 floats
* @note inlined for performance reasons (generates less code than a function call)
*/
- float* AsFloat() {return mMatrix;}
-
+ float* AsFloat()
+ {
+ return mMatrix;
+ }
/**
* @brief Function to multiply two matrices and store the result onto third.
*
* @param[in] lhs Matrix, this can be same matrix as result
* @param[in] rhs Matrix, this cannot be same matrix as result
*/
- static void Multiply( Matrix& result, const Matrix& lhs, const Matrix& rhs );
+ static void Multiply(Matrix& result, const Matrix& lhs, const Matrix& rhs);
/**
* @brief Function to multiply a matrix and quaternion and store the result onto third.
* @param[in] lhs Matrix, this can be same matrix as result
* @param[in] rhs Quaternion
*/
- static void Multiply( Matrix& result, const Matrix& lhs, const Quaternion& rhs );
+ static void Multiply(Matrix& result, const Matrix& lhs, const Quaternion& rhs);
+
+ /**
+ * @brief Multiplication operator.
+ *
+ * Returned Matrix = This Matrix * rhs
+ *
+ * @note It makes some memory allocate & copy internally.
+ * Use Matrix::Multiply API for time critical path.
+ *
+ * @SINCE_2_1.44
+ * @param[in] rhs The Matrix to multiply this by
+ * @return A Matrix containing the result
+ */
+ Matrix operator*(const Matrix& rhs) const;
+
+ /**
+ * @brief Multiplication assignment operator.
+ *
+ * This Matrix *= rhs
+ *
+ * @note It makes some memory allocate & copy internally.
+ *
+ * @SINCE_2_1.46
+ * @param[in] rhs The Matrix to multiply this by
+ * @return Itself
+ */
+ Matrix& operator*=(const Matrix& rhs);
/**
* @brief The multiplication operator.
* @param[in] rhs The Matrix to compare this to
* @return true if the matrices are equal
*/
- bool operator==(const Matrix & rhs) const;
+ bool operator==(const Matrix& rhs) const;
/**
* @brief The inequality operator.
* @param[in] rhs The Matrix to compare this to
* @return true if the matrices are not equal.
*/
- bool operator!=(const Matrix & rhs) const;
+ bool operator!=(const Matrix& rhs) const;
/**
* @brief Sets this matrix to contain the position, scale and rotation components.
* @param[in] rotation Rotation to apply
* @param[in] translation Translation to apply
*/
- void SetTransformComponents(const Vector3& scale,
+ void SetTransformComponents(const Vector3& scale,
const Quaternion& rotation,
- const Vector3& translation );
+ const Vector3& translation);
/**
* @brief Sets this matrix to contain the inverse of the position, scale and rotation components.
*/
void SetInverseTransformComponents(const Vector3& scale,
const Quaternion& rotation,
- const Vector3& translation );
-
+ const Vector3& translation);
/**
* @brief Sets this matrix to contain the inverse of the orthonormal basis and position components.
* @param[in] zAxis The Z axis of the basis
* @param[in] translation Translation to apply
*/
- void SetInverseTransformComponents(const Vector3& xAxis,
- const Vector3& yAxis,
- const Vector3& zAxis,
- const Vector3& translation );
+ void SetInverseTransformComponents(const Vector3& xAxis,
+ const Vector3& yAxis,
+ const Vector3& zAxis,
+ const Vector3& translation);
/**
* @brief Gets the position, scale and rotation components from the given transform matrix.
* @param[out] scale Scale to set - only valid if the transform matrix has not been skewed or sheared
* @pre This matrix must not contain skews or shears.
*/
- void GetTransformComponents(Vector3& position,
+ void GetTransformComponents(Vector3& position,
Quaternion& rotation,
- Vector3& scale) const;
+ Vector3& scale) const;
private:
-
float mMatrix[16]; ///< The elements of the matrix
};
* @param[in] matrix The matrix to print
* @return The output stream operator
*/
-DALI_CORE_API std::ostream& operator<< (std::ostream& o, const Matrix& matrix);
+DALI_CORE_API std::ostream& operator<<(std::ostream& o, const Matrix& matrix);
// Allow Matrix to be treated as a POD type
-template <> struct TypeTraits< Matrix > : public BasicTypes< Matrix > { enum { IS_TRIVIAL_TYPE = true }; };
+template<>
+struct TypeTraits<Matrix> : public BasicTypes<Matrix>
+{
+ enum
+ {
+ IS_TRIVIAL_TYPE = true
+ };
+};
/**
* @}