如何在转换中使用枢轴点 [英] How to use Pivot Point in Transformations

查看:130
本文介绍了如何在转换中使用枢轴点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用中心点平移对象

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.

如果我在modelView矩阵中旋转之前有多个位置

if i multyply position before rotation in the modelView matrix

ModelViewMatrix = Rotation * Scaling * Position

假设我要翻译.

1)将矩形位置平移x = 10个单位.

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

1)将矩形以其中心为中心旋转35度.

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

2)将矩形位置平移x = 10个单位.

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

3)将中心点的x位置更改10个单位(矩形不应受中心点位置的影响)

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)

4)现在,使用新的中心点旋转矩形.

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

如果有人可以指导我,我们如何在转换中使用中心点. 如果我使用中心点,如何通过ModelView Matrix进行构建.

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.

推荐答案

如果必须跟随矩形,其中红色十字是世界的中心,并且您希望围绕绿色轴旋转

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:

  • 以这种方式平移矩形,使枢轴位于世界的原点上.这是由向量到原点的转换.

  • 旋转矩形

  • 以枢轴返回其原始位置的方式平移矩形.这是由向量到枢轴的原点进行的平移.

下面的transPivot是一个平移矩阵,该平移矩阵由从原点(0,0)到枢轴点(pivotPos)的向量定义.枢轴以绿色十字标记.
rotation是绕z轴的旋转矩阵:

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

-transPivotinverse(transPivot)矩阵,在这种情况下等于-pivotPos的转换矩阵.

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

这篇关于如何在转换中使用枢轴点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆