Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
969 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...