void QGLBezierPatchesPrivate::subdivide(QGLBuilder *list) const { QGeometryData prim; int count = positions.size(); for (int posn = 0; (posn + 15) < count; posn += 16) { // Construct a QGLBezierPatch object from the next high-level patch. QGLBezierPatch patch; int vertex; for (int vertex = 0; vertex < 16; ++vertex) patch.points[vertex] = positions[posn + vertex]; QVector2D tex1, tex2; if (!textureCoords.isEmpty()) { tex1 = textureCoords[(posn / 16) * 2]; tex2 = textureCoords[(posn / 16) * 2 + 1]; } else { tex1 = QVector2D(0.0f, 0.0f); tex2 = QVector2D(1.0f, 1.0f); } qreal xtex = tex1.x(); qreal ytex = tex1.y(); qreal wtex = tex2.x() - xtex; qreal htex = tex2.y() - ytex; for (int corner = 0; corner < 4; ++corner) { vertex = posn + cornerOffsets[corner]; QVector3D n = patch.normal(cornerS[corner], cornerT[corner]); patch.indices[corner] = prim.count(); prim.appendVertex(patch.points[cornerOffsets[corner]]); prim.appendNormal(n); prim.appendTexCoord (QVector2D(xtex + wtex * cornerS[corner], ytex + htex * cornerT[corner])); } // Subdivide the patch and generate the final triangles. patch.recursiveSubDivide(&prim, subdivisionDepth, xtex, ytex, wtex, htex); } list->addTriangles(prim); }
void tst_QVectorArray::create2DArray() { QVector2DArray array; QVERIFY(array.isEmpty()); array.append(1.0f, 2.0f); array.append(3.0f, 4.0f); array.append(QVector2D(5.0f, 6.0f)); array.append(QPointF(7.0f, 8.0f)); array.append(QPoint(9, 10)); QCOMPARE(array.size(), 5); QVERIFY(array[0] == QVector2D(1.0f, 2.0f)); QVERIFY(array[1] == QVector2D(3.0f, 4.0f)); QVERIFY(array[2] == QVector2D(5.0f, 6.0f)); QVERIFY(array[3] == QVector2D(7.0f, 8.0f)); QVERIFY(array[4] == QVector2D(9.0f, 10.0f)); array.append(QVector2D(11.0f, 12.0f), QVector2D(13.0f, 14.0f)); array.append(QVector2D(15.0f, 16.0f), QVector2D(17.0f, 18.0f), QVector2D(19.0f, 20.0f)); array.append(QVector2D(21.0f, 22.0f), QVector2D(23.0f, 24.0f), QVector2D(25.0f, 26.0f)); for (int index = 0; index < array.size(); ++index) QVERIFY(array[index] == QVector2D(index * 2 + 1, index * 2 + 2)); QVector2DArray array2(34); QCOMPARE(array2.size(), 34); for (int index = 0; index < array2.size(); ++index) QCOMPARE(array2[index], QVector2D(0.0f, 0.0f)); QVector2DArray array3(15, QVector2D(1.0f, 2.0f)); QCOMPARE(array3.size(), 15); for (int index = 0; index < array3.size(); ++index) QCOMPARE(array3[index], QVector2D(1.0f, 2.0f)); }
qreal QGLBezierPatchesPrivate::intersection (const QRay3D &ray, bool anyIntersection, QVector2D *texCoord, int *bestPatch) const { int count = positions.size(); qreal result = qSNaN(); QVector2D tc; if (bestPatch) *bestPatch = -1; for (int posn = 0; (posn + 15) < count; posn += 16) { QGLBezierPatch patch; for (int vertex = 0; vertex < 16; ++vertex) patch.points[vertex] = positions[posn + vertex]; QVector2D tex1, tex2; if (!textureCoords.isEmpty()) { tex1 = textureCoords[(posn / 16) * 2]; tex2 = textureCoords[(posn / 16) * 2 + 1]; } else { tex1 = QVector2D(0.0f, 0.0f); tex2 = QVector2D(1.0f, 1.0f); } qreal xtex = tex1.x(); qreal ytex = tex1.y(); qreal wtex = tex2.x() - xtex; qreal htex = tex2.y() - ytex; qreal prev = result; result = patch.intersection (result, subdivisionDepth, ray, anyIntersection, xtex, ytex, wtex, htex, &tc); if (bestPatch && result != prev) *bestPatch = posn / 16; if (anyIntersection && !qIsNaN(result)) break; } if (texCoord && !qIsNaN(result)) *texCoord = tc; return result; }
void tst_QVectorArray::vector2DArray() { QVector2DArray array; QVERIFY(array.isEmpty()); array.append(1.0f, 2.0f); array.append(3.0f, 4.0f); array.append(QVector2D(5.0f, 6.0f)); array.append(QPointF(7.0f, 8.0f)); array.append(QPoint(9, 10)); QCOMPARE(array.size(), 5); QVERIFY(array[0] == QVector2D(1.0f, 2.0f)); QVERIFY(array[1] == QVector2D(3.0f, 4.0f)); QVERIFY(array[2] == QVector2D(5.0f, 6.0f)); QVERIFY(array[3] == QVector2D(7.0f, 8.0f)); QVERIFY(array[4] == QVector2D(9.0f, 10.0f)); array.append(QVector2D(11.0f, 12.0f), QVector2D(13.0f, 14.0f)); array.append(QVector2D(15.0f, 16.0f), QVector2D(17.0f, 18.0f), QVector2D(19.0f, 20.0f)); array.append(QVector2D(21.0f, 22.0f), QVector2D(23.0f, 24.0f), QVector2D(25.0f, 26.0f)); for (int index = 0; index < array.size(); ++index) QVERIFY(array[index] == QVector2D(index * 2 + 1, index * 2 + 2)); int size = array.size(); QVector2DArray result = array.scaled(1.0); // check did not change the original QCOMPARE(array.size(), size); QVERIFY(array[0] == QVector2D(1.0f, 2.0f)); QVERIFY(array[4] == QVector2D(9.0f, 10.0f)); // result should be copy - mult by 1.0 costs nothing QVERIFY(!result.isDetached()); QCOMPARE(result.size(), size); QCOMPARE(result[0], QVector2D(1.0f, 2.0f)); QCOMPARE(result[4], QVector2D(9.0f, 10.0f)); QCOMPARE(result[12], QVector2D(25.0f, 26.0f)); // now actually do a scale result = array.scaled(2.0); QCOMPARE(result.size(), size); QCOMPARE(array.size(), size); QCOMPARE(array[0], QVector2D(1.0f, 2.0f)); QCOMPARE(array[4], QVector2D(9.0f, 10.0f)); QCOMPARE(result[0], QVector2D(2.0f, 4.0f)); QCOMPARE(result[4], QVector2D(18.0f, 20.0f)); QCOMPARE(result[12], QVector2D(50.0f, 52.0f)); array.scale(1.0); QCOMPARE(array.size(), size); // should all be the same QCOMPARE(array[0], QVector2D(1.0f, 2.0f)); QCOMPARE(array[4], QVector2D(9.0f, 10.0f)); QCOMPARE(array[12], QVector2D(25.0f, 26.0f)); array.scale(2.0); QCOMPARE(array.size(), size); // size should be the same QCOMPARE(array[0], QVector2D(2.0f, 4.0f)); QCOMPARE(array[4], QVector2D(18.0f, 20.0f)); QCOMPARE(array[12], QVector2D(50.0f, 52.0f)); }