2010-10-04 57 views
0

我有一个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。

我想这些功能需要包括任何以前的对象翻译,但我不知道如何。

请帮助我!

非常感谢提前,

卡洛斯。

回答

0

我通过重新计算枢轴点固定此:

QPointF枢轴= PivotPoint-POS();

另外通过计算一个新的矩阵和mutiply前面*新的。

QTransform tmpTransform = QTransform().translate(pivot.x(), pivot.y()) 
       .rotate(rotation) 
       .scale(xFactor, yFactor) 
       .translate(-pivot.x(), -pivot.y()); 


    tmpPolygon->setTransform(this->transform() * tmpTransform); //Multiplies the previous matrix * the temporary 

卡洛斯