From 811be6f81b2e8c4d9d23cff5b4287c8a5dc86fc3 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 6 Feb 2014 14:00:25 +0200 Subject: Change rotations to use angle and vector in APIs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Quaternions are pain in the behind to use, especially in QML, so change them to angle + vector combinations. Change-Id: I25eb5ea92deaf3a079e2e193cce2e8de89f3c3c4 Reviewed-by: Tomi Korpipää --- tests/barstest/chart.cpp | 6 ++-- tests/directional/main.cpp | 16 +-------- tests/directional/scatterdatamodifier.cpp | 13 ++++--- tests/qmlcamera/qml/qmlcamera/Data.qml | 2 +- tests/qmldynamicdata/qml/qmldynamicdata/main.qml | 43 +++++++++++++++++------- 5 files changed, 40 insertions(+), 40 deletions(-) (limited to 'tests') diff --git a/tests/barstest/chart.cpp b/tests/barstest/chart.cpp index 8ab619ec..df71a0ed 100644 --- a/tests/barstest/chart.cpp +++ b/tests/barstest/chart.cpp @@ -1095,10 +1095,8 @@ void GraphModifier::triggerRotation() } else { // Rotate the first series instead static float seriesAngle = 0.0f; - if (m_graph->seriesList().size()) { - QQuaternion rotation = QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, seriesAngle++); - m_graph->seriesList().at(0)->setMeshRotation(rotation); - } + if (m_graph->seriesList().size()) + m_graph->seriesList().at(0)->setMeshRotationAngle(seriesAngle++); } } diff --git a/tests/directional/main.cpp b/tests/directional/main.cpp index f4871a70..2b077b97 100644 --- a/tests/directional/main.cpp +++ b/tests/directional/main.cpp @@ -32,11 +32,9 @@ int main(int argc, char **argv) { - //! [0] QApplication app(argc, argv); Q3DScatter *graph = new Q3DScatter(); QWidget *container = QWidget::createWindowContainer(graph); - //! [0] QSize screenSize = graph->screen()->size(); container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.5)); @@ -44,17 +42,14 @@ int main(int argc, char **argv) container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); container->setFocusPolicy(Qt::StrongFocus); - //! [1] QWidget *widget = new QWidget; QHBoxLayout *hLayout = new QHBoxLayout(widget); QVBoxLayout *vLayout = new QVBoxLayout(); hLayout->addWidget(container, 1); hLayout->addLayout(vLayout); - //! [1] widget->setWindowTitle(QStringLiteral("Directional scatter")); - //! [4] QComboBox *themeList = new QComboBox(widget); themeList->addItem(QStringLiteral("Qt")); themeList->addItem(QStringLiteral("Primary Colors")); @@ -79,7 +74,7 @@ int main(int argc, char **argv) cameraButton->setText(QStringLiteral("Change camera preset")); QPushButton *toggleRotationButton = new QPushButton(widget); - toggleRotationButton->setText(QStringLiteral("Toggle rotation")); + toggleRotationButton->setText(QStringLiteral("Toggle animation")); QCheckBox *backgroundCheckBox = new QCheckBox(widget); backgroundCheckBox->setText(QStringLiteral("Show background")); @@ -101,9 +96,7 @@ int main(int argc, char **argv) QFontComboBox *fontList = new QFontComboBox(widget); fontList->setCurrentFont(QFont("Arial")); - //! [4] - //! [5] vLayout->addWidget(labelButton, 0, Qt::AlignTop); vLayout->addWidget(cameraButton, 0, Qt::AlignTop); vLayout->addWidget(toggleRotationButton, 0, Qt::AlignTop); @@ -117,13 +110,9 @@ int main(int argc, char **argv) vLayout->addWidget(shadowQuality); vLayout->addWidget(new QLabel(QStringLiteral("Change font"))); vLayout->addWidget(fontList, 1, Qt::AlignTop); - //! [5] - //! [2] ScatterDataModifier *modifier = new ScatterDataModifier(graph); - //! [2] - //! [6] QObject::connect(cameraButton, &QPushButton::clicked, modifier, &ScatterDataModifier::changePresetCamera); QObject::connect(toggleRotationButton, &QPushButton::clicked, modifier, @@ -159,12 +148,9 @@ int main(int argc, char **argv) QObject::connect(modifier, &ScatterDataModifier::fontChanged, fontList, &QFontComboBox::setCurrentFont); - //! [6] itemStyleList->setCurrentIndex(0); - //! [3] widget->show(); return app.exec(); - //! [3] } diff --git a/tests/directional/scatterdatamodifier.cpp b/tests/directional/scatterdatamodifier.cpp index 96a7b975..3735e14c 100644 --- a/tests/directional/scatterdatamodifier.cpp +++ b/tests/directional/scatterdatamodifier.cpp @@ -32,7 +32,7 @@ const int numberOfCols = 8; const int numberOfRows = 8; const float limit = 8.0f; const float PI = 3.14159f; -//#define HEDGEHOG +#define HEDGEHOG ScatterDataModifier::ScatterDataModifier(Q3DScatter *scatter) : m_graph(scatter), @@ -111,7 +111,8 @@ void ScatterDataModifier::addData() #endif ptrToDataArray->setPosition(QVector3D(x, y, z)); - ptrToDataArray->setRotation(rotation); + ptrToDataArray->setRotationAxis(rotation.vector()); + ptrToDataArray->setRotationAngle(qAcos(rotation.scalar()) * 360.0f / M_PI); ptrToDataArray++; } } @@ -172,15 +173,13 @@ void ScatterDataModifier::triggerRotation() if (m_graph->seriesList().size()) { int selectedIndex = m_graph->seriesList().at(0)->selectedItem(); if (selectedIndex != QScatter3DSeries::invalidSelectionIndex()) { - static float itemAngle = 0.0f; QScatterDataItem item(*(m_graph->seriesList().at(0)->dataProxy()->itemAt(selectedIndex))); - QQuaternion itemRotation = QQuaternion::fromAxisAndAngle(0.0f, 0.0f, 1.0f, itemAngle++); - item.setRotation(itemRotation); + item.setRotationAngle(item.rotationAngle() + 1); m_graph->seriesList().at(0)->dataProxy()->setItem(selectedIndex, item); } else { static float seriesAngle = 0.0f; - QQuaternion rotation = QQuaternion::fromAxisAndAngle(1.0f, 1.0f, 1.0f, seriesAngle++); - m_graph->seriesList().at(0)->setMeshRotation(rotation); + m_graph->seriesList().at(0)->setMeshRotationAxis(QVector3D(1.0f, 1.0f, 1.0f)); + m_graph->seriesList().at(0)->setMeshRotationAngle(seriesAngle++); } } } diff --git a/tests/qmlcamera/qml/qmlcamera/Data.qml b/tests/qmlcamera/qml/qmlcamera/Data.qml index bab6bf78..ba920ef9 100644 --- a/tests/qmlcamera/qml/qmlcamera/Data.qml +++ b/tests/qmlcamera/qml/qmlcamera/Data.qml @@ -38,7 +38,7 @@ Item { dataProxy: modelProxy itemLabelFormat: "@valueTitle for @colLabel, @rowLabel: @valueLabel" - onMeshAngleChanged: console.log("angle changed:", angle) + onMeshRotationAngleChanged: console.log("angle changed:", angle) } ListModel { diff --git a/tests/qmldynamicdata/qml/qmldynamicdata/main.qml b/tests/qmldynamicdata/qml/qmldynamicdata/main.qml index d384c3ee..03bf4b2d 100644 --- a/tests/qmldynamicdata/qml/qmldynamicdata/main.qml +++ b/tests/qmldynamicdata/qml/qmldynamicdata/main.qml @@ -28,8 +28,8 @@ Item { ListModel { id: graphModel - ListElement{ xPos: 0.0; yPos: 0.0; zPos: 0.0; rotation: "0.92388, 0.220942, 0.220942, 0.220942"} - ListElement{ xPos: 1.0; yPos: 1.0; zPos: 1.0; rotation: "0.953717, 0.173613, 0.173613, 0.173613"} + ListElement{ xPos: 0.0; yPos: 0.0; zPos: 0.0; rotationAxis: "1.0,1.0,1.0"; rotationAngle: 45 } + ListElement{ xPos: 1.0; yPos: 1.0; zPos: 1.0; rotationAxis: "1.0,1.0,1.0"; rotationAngle: 45 } } Timer { @@ -39,18 +39,34 @@ Item { repeat: true property bool isIncreasing: true + function generateAngle() { + return Math.random() * 360 + } + + function generateAxis() { + return Math.random() + "," + Math.random() + "," + Math.random() + } + + function appendRow() { + graphModel.append({"xPos": Math.random(), + "yPos": Math.random(), + "zPos": Math.random(), + "rotationAxis": generateAxis(), + "rotationAngle": generateAngle()}); + } + onTriggered: { if (isIncreasing) { - graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); - graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); - graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); - graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); - graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); - graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); - graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); - graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); - graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); - graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); + appendRow() + appendRow() + appendRow() + appendRow() + appendRow() + appendRow() + appendRow() + appendRow() + appendRow() + appendRow() if (graphModel.count > 5000) { scatterGraph.theme.type = Theme3D.ThemeIsabelle; isIncreasing = false; @@ -114,7 +130,8 @@ Item { xPosRole: "xPos" yPosRole: "yPos" zPosRole: "zPos" - rotationRole: "rotation" + rotationAxisRole: "rotationAxis" + rotationAngleRole: "rotationAngle" } } } -- cgit v1.2.3