Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
942 views
in Technique[技术] by (71.8m points)

opengl - 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 here4) 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you have to following rectangle, where the red cross is the center of the world and you want to rotate it around the green pivot

then you've to do the following steps:

  • Translate the rectangle in that way that way, that the pivot is on the origin of the world. This is a translation by the vector form the pivot to the origin.

  • Rotate the rectangle

  • Translate the rectangle in that way that the pivot is back at its original position. This is a translation by the vector form the origin to the pivot.

In the following transPivot is a translation matrix, which is defined by the vector from the origin (0, 0) to the pivot point (pivotPos). The pivot is marked by the green cross.
rotation is the rotation matrix around the z-axis:

ModelViewMatrix = transPivot * rotation * -transPivot

-transPivot is the inverse(transPivot) matrix, which is equal the translation matrix by -pivotPos in this case.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...