는 결과가
아주 잘 당신의 문제를 설명하지 않습니다 단지 잘못
작동 할 수 없습니다.
기본적으로 나는 연결/객체 저장소에서 행렬
의 곱셈의 관점에서 필요한 것을 모르는 :
1. 위치
2 회전
3. 규모
개체를 그리려면 다음 순서로 작업을 수행하십시오.
1. 저장 축척 계수
을 사용하여 축척 저장 각도
3. 사용 2 회전
감안할 때 규모 요인의 회전 각도 R, 임의의 점 (PX, PY)의 주위에/규모의 오브젝트 (포인트 배열, 또는 무엇이든)을 회전 수행이 위치를 번역 :
1. 개체를 -px, -py로 변환합니다. 나는. 모든 정점에 대해 정점 do - = p;
2. 개체 크기 조정. 모든 정점에 대해 정점 * = s를 수행합니다.
3. 개체를 회전합니다. 각도 r을 사용하여 점 0 주위의 모든 정점을 회전합니다.
4. 개체를 p.x, p.y로 변환합니다.
또한 Qt 4에서 "Affine Transformations" 데모를 살펴 보는 것이 좋습니다. 데모를 보려면 qtdemo를 실행하고 "Demonstrations-> Affine Transformations"를 선택하십시오.
기하학 교사를 고용하는 것이 좋습니다. '개월'이 너무 길어서 회전/크기 조정/번역 문제를 처리 할 수 없습니다.
는하지만, 내가 올바른 순서
당신이 회전과 같은 점을 중심으로 확장하는 경우에 이러한 기능의 결합 방법에 대한 단서가 없다, 작업의 순서는 중요하지 않습니다.
--EDIT--
라이브 예 :
포인트 변환의 피벗 변화의 시작과 종료를 나타낸다. 와이어 프레임 문자는 원본 이미지를 나타냅니다.
빨간색 문자는 "회전하고 균일하게 스케일링"변환을 나타냅니다.
녹색 글자는 "2D 스케일"변환을 나타냅니다.
두 가지 변형 모두 피벗이 필요하고 도형을 드래그하기 시작한 지점과 도형 드래그를 중단 한 지점을 가리켜 야합니다.
나는 이것을 다시는 설명하지 않을 것이다.
transformtest.pro :
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += MainWindow.h
SOURCES += main.cpp MainWindow.cpp
MAIN.CPP :
#include <QApplication>
#include "MainWindow.h"
int main(int argc, char** argv){
QApplication app(argc, argv);
MainWindow window;
window.show();
return app.exec();
}
MainWindow.h :
#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H
#include <QGLWidget>
class QPaintEvent;
class MainWindow: public QWidget{
Q_OBJECT
public:
MainWindow(QWidget* parent = 0);
protected slots:
void updateAngle();
protected:
void paintEvent(QPaintEvent* ev);
float angle;
float distAngle;
};
#endif
MainWindow를.cpp :
#include "MainWindow.h"
#include <QTimer>
#include <QPainter>
#include <QColor>
#include <QVector2D>
#include <math.h>
static const int timerMsec = 50;
static const float pi = 3.14159265f;
MainWindow::MainWindow(QWidget* parent)
:QWidget(parent), angle(0), distAngle(0){
QTimer* timer = new QTimer(this);
timer->start(timerMsec);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
connect(timer, SIGNAL(timeout()), this, SLOT(updateAngle()));
}
float randFloat(){
return (qrand()&0xFF)/255.0f;
}
float randFloat(float f){
return randFloat()*f;
}
inline QVector2D perp(const QVector2D v){
return QVector2D(-v.y(), v.x());
}
void MainWindow::updateAngle(){
angle = fmod(angle + pi*5.0f/180.0f, pi*2.0f);
distAngle = fmod(distAngle + pi*1.0f/180.0f, pi*2.0f);
}
QTransform buildRotateScale(QVector2D pivot, QVector2D start, QVector2D end){
QVector2D startDiff = start - pivot;
QVector2D endDiff = end - pivot;
float startLength = startDiff.length();
float endLength = endDiff.length();
if (startLength == 0)
return QTransform();
if (endLength == 0)
return QTransform();
float s = endLength/startLength;
startDiff.normalize();
endDiff.normalize();
QVector2D startPerp = perp(startDiff);
float rotationAngle = acos(QVector2D::dotProduct(startDiff, endDiff))*180.0f/pi;
if (QVector2D::dotProduct(startPerp, endDiff) < 0)
rotationAngle = -rotationAngle;
return QTransform().translate(pivot.x(), pivot.y()).rotate(rotationAngle).scale(s, s).translate(-pivot.x(), -pivot.y());
}
QTransform buildScale(QVector2D pivot, QVector2D start, QVector2D end){
QVector2D startDiff = start - pivot;
QVector2D endDiff = end - pivot;
float startLength = startDiff.length();
float endLength = endDiff.length();
if ((startDiff.x() == 0)||(startDiff.y() == 0))
return QTransform();
QVector2D s(endDiff.x()/startDiff.x(), endDiff.y()/startDiff.y());
return QTransform().translate(pivot.x(), pivot.y()).scale(s.x(), s.y()).translate(-pivot.x(), -pivot.y());
}
void MainWindow::paintEvent(QPaintEvent* ev){
QPainter painter(this);
QPointF pivot(width()/2, height()/2);
QPointF transformStart(pivot.x() + 100.0f, pivot.y() - 100.0f);
float r = sinf(distAngle)*100.0f + 150.0f;
QPointF transformEnd(pivot.x() + r*cosf(angle), pivot.y() - r*sinf(angle));
painter.fillRect(this->rect(), QBrush(QColor(Qt::white)));
QPainterPath path;
QString str(tr("This is a test!"));
QFont textFont("Arial", 40);
QFontMetrics metrics(textFont);
QRect rect = metrics.boundingRect(str);
path.addText(QPoint((width()-rect.width())/2, (height()-rect.height())/2), textFont, str);
painter.setPen(QColor(200, 200, 255));
painter.drawPath(path);
painter.setTransform(buildRotateScale(QVector2D(pivot), QVector2D(transformStart), QVector2D(transformEnd)));
painter.fillPath(path, QBrush(QColor(255, 100, 100)));
painter.setPen(QColor(100, 255, 100));
painter.setTransform(buildScale(QVector2D(pivot), QVector2D(transformStart), QVector2D(transformEnd)));
painter.fillPath(path, QBrush(QColor(100, 255, 100)));
painter.setTransform(QTransform());
QPainterPath coords;
r = 10.0f;
coords.addEllipse(pivot, r, r);
coords.addEllipse(transformStart, r, r);
coords.addEllipse(transformEnd, r, r);
painter.setPen(QPen(QBrush(Qt::red), 5.0f));
painter.setBrush(QBrush(QColor(127, 0, 0)));
painter.setPen(QPen(QBrush(Qt::green), 5.0f));
painter.drawLine(QLineF(pivot, transformStart));
painter.setPen(QPen(QBrush(Qt::blue), 5.0f));
painter.drawLine(QLineF(transformStart, transformEnd));
painter.setPen(Qt::red);
painter.drawPath(coords);
painter.end();
}
질문이 명확하지 않습니다. "결과가 잘못되었습니다"문제를 설명하지 않습니다. – SigTerm