【发布时间】:2010-10-04 12:49:01
【问题描述】:
我有一个 QGraphicsPolygonItem 定义为:
myShape << QPointF(-50, -50) << QPointF(50, -50)
<< QPointF(50, 50) << QPointF(-50, 50)
<< QPointF(-50, -50);
mypolygon.setPolygon(myShape);
它的起始矩阵是恒等:
|---|---|---|
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
|---|---|---|
当我使用 TransformationPivotVector = (-50,0) 将形状扩大一倍时,我得到以下矩阵:
缩放后的矩阵:
|----|---|---|
| 2 | 0 | 0 |
| 0 | 1 | 0 |
| 50 | 0 | 1 |
|----|---|---|
这意味着形状的中心已沿 X 轴平移了 50 个单位。
现在,假设形状当前具有缩放后的矩阵,当我打算使用 TransformationPivotVector = (50,0) 收缩形状时,平移会自动变为负数,例如,当我只收缩形状的 0.01 时:
|-------|---|---|
| 1.99 | 0 | 0 |
| 0 | 1 | 0 |
| -49.5 | 0 | 1 |
|-------|---|---|
我使用下面的函数得到一个整体的变换矩阵:
myShape->setTransform(QTransform().translate(transPivotVector.x(), transPivotVector.y()).rotate(rotation).scale(xFactor, yFactor).translate(-transPivotVector.x(),-transPivotVector.y()));
该函数基本上从以下位置获取最终矩阵:translate * rotate * scale * -translate。
我猜这些函数需要包含对象的任何先前翻译,但我不知道如何。
请帮帮我!!
非常感谢,
卡洛斯。
【问题讨论】:
标签: qt matrix translation transformation