1
\$\begingroup\$

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.

enter image description here

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.

\$\endgroup\$
0
\$\begingroup\$

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);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.