How to use Pivot Point in Transformations

How to translate object using Center point

I have a rectangle which has a center point away from the position of rectangle.

when i rotate rectangle it rotates around its center axis.

if i multyply position before rotation in the modelView matrix

ModelViewMatrix = Rotation * Scaling * Position


Suppose if i want to do these translations.

1) Translate the rectangle position by x = 10 units.

1) Rotate the rectangle by 35 degree with the center point at the center of the rectangle.

2) Translate the rectangle position by x = 10 units.

3) change the x position of the center point by 10 units( rectangle should not be affected by the change in the center point position)

enter image description here

4) Now rotate the rectangle using the new center point.

If someone could please guide me how do we use Center point in transformations. How do i build by ModelView Matrix if i am using a center Point.

To make a pivoted transformation, you need to transform the matrix with a pivot space matrix, apply pivoted transformation, and then remove pivot space transformation.

//final transformation matrix
mat4x4 m_transform = identity();
//pivot matrix
mat4x4 m_pivot_transform = translation(...);
//desired transformation
mat4x4 m_rotation = rotation(...);
//apply pivot transformation
m_transform = m_transform * m_pivot_transform;
//apply transformation
m_transform = m_transform * m_rotation;
//cancel out pivot transformation
m_transform = m_transform * inverse(m_pivot_transform);