void ViewportView::drawAxes(QPainter* painter) const
{
    // First, draw the axes.
    auto m = getMatrix();
    QVector3D o = m * QVector3D(0, 0, 0);
    QVector3D x = m * QVector3D(1, 0, 0);
    QVector3D y = m * QVector3D(0, 1, 0);
    QVector3D z = m * QVector3D(0, 0, 1);

    QList<QPair<QVector3D, QColor>> pts = {
        {x, Colors::red},
        {y, Colors::green},
        {z, Colors::blue}};

    // Sort the axes to fake proper z clipping
    std::sort(pts.begin(), pts.end(),
            [](QPair<QVector3D, QColor> a, QPair<QVector3D, QColor> b)
            { return a.first.z() < b.first.z(); });

    for (auto p : pts)
    {
        painter->setPen(QPen(p.second, 2));
        painter->drawLine(o.toPointF(), p.first.toPointF());
    }
}
Exemple #2
0
void TutorialUnit::rcSetPosition(const QVariant &var)
{
    if(var.canConvert(QVariant::Vector3D))
    {
        QVector3D vec = var.value<QVector3D>();
        setPosition(vec.toPointF());
        setRotation(vec.z());
    }
}
/**
  \brief When a station has been selected, this updates the shot lines

  This shows the shot lines from the selected station.  If no station is
  currently selected, this will hide the lines
  */
void cwScrapStationView::updateShotLines() {
    if(scrap() == nullptr) { return; }
    if(scrap()->parentNote() == nullptr) { return; }
    if(scrap()->parentNote()->parentTrip() == nullptr) { return; }
    if(transformUpdater() == nullptr) { return; }

    cwNoteStation noteStation = scrap()->station(selectedItemIndex());
    //Get the current trip
    cwNote* note = scrap()->parentNote();
    cwTrip* trip = note->parentTrip();
    cwCave* cave = trip->parentCave();
    cwStationPositionLookup stationPositionLookup = cave->stationPositionLookup();

    //Clear all the lines
    ShotLines.clear();

    if(noteStation.isValid() && stationPositionLookup.hasPosition(noteStation.name())) {
        QString stationName = noteStation.name();
        QSet<cwStation> neighboringStations = trip->neighboringStations(stationName);

        //The position of the selected station
        QVector3D selectedStationPos = stationPositionLookup.position(noteStation.name());

        //Create the matrix to covert global position into note position
        QMatrix4x4 noteTransformMatrix = scrap()->noteTransformation()->matrix(); //Matrix from page coordinates to cave coordinates
        noteTransformMatrix = noteTransformMatrix.inverted(); //From cave coordinates to page coordinates

        QMatrix4x4 notePageAspect = note->scaleMatrix().inverted(); //The note's aspect ratio

        QMatrix4x4 offsetMatrix;
        offsetMatrix.translate(-selectedStationPos);

        QMatrix4x4 dotPerMeter;
        dotPerMeter.scale(note->dotPerMeter(), note->dotPerMeter(), 1.0);

        QMatrix4x4 noteStationOffset;
        noteStationOffset.translate(QVector3D(noteStation.positionOnNote()));

        QMatrix4x4 toNormalizedNote = noteStationOffset *
                dotPerMeter *
                notePageAspect *
                noteTransformMatrix *
                offsetMatrix;

        //Go through all the neighboring stations and add the position to the line
        foreach(cwStation station, neighboringStations) {

            QVector3D currentPos = stationPositionLookup.position(station.name());
            QVector3D normalizeNotePos = toNormalizedNote.map(currentPos);

            ShotLines.append(QLineF(noteStation.positionOnNote(), normalizeNotePos.toPointF()));
        }
Exemple #4
0
QPointF GLScene::mapToScene(const QPointF &p){
//  Code below will work OK while projection is ortogonal
//  For some reason in perspective projection everything is flipped and not accurate
    QVector4D rNear = unproject(QVector3D(p.x(), p.y(), -1));
    QVector4D rFar =  unproject(QVector3D(p.x(), p.y(),  1));

    QVector<QVector3D> triangle;
    triangle << QVector3D(0, 0, 0) << QVector3D(0, 1, 0) << QVector3D(1, 0, 0);
    QVector3D normal = QVector3D::normal(triangle.at(0), triangle.at(1), triangle.at(2));

    qreal d1 = QVector3D::dotProduct(rNear.toVector3D() - triangle.at(0), normal);
    qreal d2 = QVector3D::dotProduct(rFar.toVector3D() - triangle.at(0), normal);

    QVector3D point = rNear.toVector3D() + (rFar.toVector3D() - rNear.toVector3D()) * (-d2 / (d2 - d1));
    return point.toPointF();
}
Exemple #5
0
 void CreatorItem::setPos(const QVector3D& pos)
 {
   QGraphicsItem::setPos(pos.toPointF());
   QGraphicsItem::setZValue(pos.z());
 }
                //Caluclate the running profile rotation based on the stations
                QMatrix4x4 toProfileRotation = cwScrap::toProfileRotation(selectedStationPos, currentPos);

                toNormalizedNote = noteStationOffset *
                        dotPerMeter *
                        notePageAspect *
                        noteTransformMatrix *
                        profileDirection *
                        toProfileRotation *
                        offsetMatrix;
            }

            QVector3D normalizeNotePos = toNormalizedNote.map(currentPos);

            ShotLines.append(QLineF(noteStation.positionOnNote(), normalizeNotePos.toPointF()));
        }
    }

    LineDataDirty = true;

    //Update the node geometry
    update();
}

/**
 * @brief cwScrapStationView::updateTransformUpdate
 *
 * Called when the transform update has changed
 */
void cwScrapStationView::updateTransformUpdate() {