Exemplo n.º 1
0
inline void AssimpScene::retrieveColor(
    const aiMaterial * mtl
,   const char * pKey
,   const unsigned int type
,   const unsigned int index
,   QVector4D & color
,   const float r
,   const float g
,   const float b
,   const float a) 
{
    aiColor4D acolor;
    if (AI_SUCCESS == aiGetMaterialColor(mtl, pKey, type, index, &acolor))
    {
        color.setX(acolor.r);
        color.setY(acolor.g);
        color.setZ(acolor.b);
        color.setW(acolor.a);
    }
    else
    {
        color.setX(r);
        color.setY(g);
        color.setZ(b);
        color.setW(a);
    }
}
Exemplo n.º 2
0
void PropertyGroup::getValue(QVector4D & v)
{
	v.setX(properties.at(0)->getValue());
	v.setY(properties.at(1)->getValue());
	v.setZ(properties.at(2)->getValue());
	v.setW(properties.at(3)->getValue());
}
Exemplo n.º 3
0
QVector4D GLScene::unproject(const QVector3D & screen){
    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport);

    const qreal xNorm = (2.0f * ((screen.x() - viewport[0]) / (viewport[2] - viewport[0]))) - 1.0f;
    const qreal yNorm = 1.0f - (2.0f * ((screen.y() - viewport[1]) / (viewport[3] - viewport[1])));

    QMatrix4x4 pvMatrixInv = camera().projViewProduct().inverted();
    QVector4D worldPoint = pvMatrixInv * QVector4D(xNorm, yNorm, screen.z(), 1);

    if (worldPoint.w() == 0){
        return QVector4D(0,0,0,0);
    }

    worldPoint.setW(1 / worldPoint.w());
    worldPoint.setX(worldPoint.x() * worldPoint.w());
    worldPoint.setY(worldPoint.y() * worldPoint.w());

    return worldPoint;
}
Exemplo n.º 4
0
bool PropertyMatrixModel::setData(const QModelIndex &index, const QVariant &data, int role)
{
  if (!index.isValid())
    return false;

  if (role != Qt::EditRole)
    return false;

  bool ok = false;
  float floatData = data.toFloat(&ok);

  if (!ok)
    return false;

  switch (m_matrix.type()) {
    case QVariant::Vector2D: {
      QVector2D value = m_matrix.value<QVector2D>();
      switch (index.row()) {
        case 0: value.setX(floatData); break;
        case 1: value.setY(floatData); break;
      }

      m_matrix = value;
      break;
    }

    case QVariant::Vector3D: {
      QVector3D value = m_matrix.value<QVector3D>();
      switch (index.row()) {
        case 0: value.setX(floatData); break;
        case 1: value.setY(floatData); break;
        case 2: value.setZ(floatData); break;
      }

      m_matrix = value;
      break;
    }

    case QVariant::Vector4D: {
      QVector4D value = m_matrix.value<QVector4D>();
      switch (index.row()) {
        case 0: value.setX(floatData); break;
        case 1: value.setY(floatData); break;
        case 2: value.setZ(floatData); break;
        case 3: value.setW(floatData); break;
      }

      m_matrix = value;
      break;
    }

#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
    case QVariant::Quaternion: {
      float pitch, yaw, roll;

      const QQuaternion value = m_matrix.value<QQuaternion>();
      value.getEulerAngles(&pitch, &yaw, &roll);
      switch (index.row()) {
        case 0: pitch = floatData; break;
        case 1: yaw = floatData; break;
        case 2: roll = floatData; break;
      }

      m_matrix = QQuaternion::fromEulerAngles(pitch, yaw, roll);
      break;
    }
#endif

    case QVariant::Matrix: {
      QMatrix value = m_matrix.value<QMatrix>();

      switch (index.row() << 4 | index.column()) {
        case 0x00: value.setMatrix(floatData, value.m12(), value.m21(), value.m22(), value.dx(), value.dy()); break;
        case 0x01: value.setMatrix(value.m11(), floatData, value.m21(), value.m22(), value.dx(), value.dy()); break;
        case 0x10: value.setMatrix(value.m11(), value.m12(), floatData, value.m22(), value.dx(), value.dy()); break;
        case 0x11: value.setMatrix(value.m11(), value.m12(), value.m21(), floatData, value.dx(), value.dy()); break;
        case 0x20: value.setMatrix(value.m11(), value.m12(), value.m21(), value.m22(), floatData, value.dy()); break;
        case 0x21: value.setMatrix(value.m11(), value.m12(), value.m21(), value.m22(), value.dx(), floatData); break;
      }

      m_matrix = value;
      break;
    }

    case QVariant::Transform: {
      QTransform value = m_matrix.value<QTransform>();

      switch (index.row() << 4 | index.column()) {
        case 0x00: value.setMatrix(floatData, value.m12(), value.m13(), value.m21(), value.m22(), value.m23(), value.m31(), value.m32(), value.m33()); break;
        case 0x01: value.setMatrix(value.m11(), floatData, value.m13(), value.m21(), value.m22(), value.m23(), value.m31(), value.m32(), value.m33()); break;
        case 0x02: value.setMatrix(value.m11(), value.m12(), floatData, value.m21(), value.m22(), value.m23(), value.m31(), value.m32(), value.m33()); break;
        case 0x10: value.setMatrix(value.m11(), value.m12(), value.m13(), floatData, value.m22(), value.m23(), value.m31(), value.m32(), value.m33()); break;
        case 0x11: value.setMatrix(value.m11(), value.m12(), value.m13(), value.m21(), floatData, value.m23(), value.m31(), value.m32(), value.m33()); break;
        case 0x12: value.setMatrix(value.m11(), value.m12(), value.m13(), value.m21(), value.m22(), floatData, value.m31(), value.m32(), value.m33()); break;
        case 0x20: value.setMatrix(value.m11(), value.m12(), value.m13(), value.m21(), value.m22(), value.m23(), floatData, value.m32(), value.m33()); break;
        case 0x21: value.setMatrix(value.m11(), value.m12(), value.m13(), value.m21(), value.m22(), value.m23(), value.m31(), floatData, value.m33()); break;
        case 0x22: value.setMatrix(value.m11(), value.m12(), value.m13(), value.m21(), value.m22(), value.m23(), value.m31(), value.m32(), floatData); break;
      }

      m_matrix = value;
      break;
    }

    case QVariant::Matrix4x4: {
      QMatrix4x4 value = m_matrix.value<QMatrix4x4>();

      value(index.row(), index.column()) = floatData;

      m_matrix = value;
      break;
    }
  }

  emit dataChanged(index, index);

  return true;
}
void CombinedNavRenderer::leftMouseDown( int x, int y )
{
    float xf = static_cast<float>( x );
    float yf = static_cast<float>( m_height - y );

    QVector4D test;
    test.setX( ( 2 * xf ) / m_width - 1 );
    test.setY( ( 2 * yf ) / m_height - 1 );
    test.setZ( 1 );
    test.setW( 1 );

    int xout;
    int yout;

    QVector4D out = m_mvpMatrix.inverted() * test;
    QModelIndex mi;
    if ( m_ratio > 1.5 )
    {
        xout = out.x() / m_dx;
        if ( ( (float)out.x()  / m_dx ) < m_nx )
        {
            xout = qMax( 0, qMin( xout, static_cast<int>( m_nx - 1.0 ) ) );
            yout = out.y() / m_dy;
            yout = qMax( 0, qMin( yout, static_cast<int>( m_ny - 1.0 ) ) );
            mi = model()->index( (int)Fn::Global::SAGITTAL_CORONAL, 0 );
        }
        else if ( ( (float)out.x() / m_dx ) < m_nx * 2  )
        {
            xout = xout - m_nx;
            xout = qMax( 0, qMin( xout, static_cast<int>( m_nx - 1.0 ) ) );
            yout = out.y() / m_dz;
            yout = qMax( 0, qMin( yout, static_cast<int>( m_nz - 1.0 ) ) );
            mi = model()->index( (int)Fn::Global::SAGITTAL_AXIAL, 0 );
        }
        else
        {
            xout = xout - ( 2 * m_nx );
            xout = qMax( 0, qMin( m_ny - xout - 1, static_cast<int>( m_ny - 1.0 ) ) );
            yout = out.y() / m_dz;
            yout = qMax( 0, qMin( yout, static_cast<int>( m_nz - 1.0 ) ) );
            mi = model()->index( (int)Fn::Global::CORONAL_AXIAL, 0 );
        }
    }
    else if ( m_ratio < 0.66 )
    {
        yout = out.y() / m_dz;
        if ( ( (float)out.y() / m_dz ) < m_nz )
        {
            xout = out.x() / m_dy;
            xout = qMax( 0, qMin( m_ny - xout - 1, static_cast<int>( m_ny - 1.0 ) ) );
            yout = qMax( 0, qMin( yout, static_cast<int>( m_nz - 1.0 ) ) );
            mi = model()->index( (int)Fn::Global::CORONAL_AXIAL, 0 );
        }
        else if ( ( (float)out.y() / m_dz ) < m_nz * 2  )
        {
            xout = out.x() / m_dx;
            xout = qMax( 0, qMin( xout, static_cast<int>( m_nx - 1.0 ) ) );
            yout = yout - m_nz;
            yout = qMax( 0, qMin( yout, static_cast<int>( m_nz - 1.0 ) ) );
            mi = model()->index( (int)Fn::Global::SAGITTAL_AXIAL, 0 );
        }
        else
        {
            xout = out.x() / m_dx;
            xout = qMax( 0, qMin( xout, static_cast<int>( m_nx - 1.0 ) ) );
            yout = yout - ( 2 * m_nz );
            yout = qMax( 0, qMin( yout, static_cast<int>( m_ny - 1.0 ) ) );
            mi = model()->index( (int)Fn::Global::SAGITTAL_CORONAL, 0 );
        }
    }
    else
    {
        xout = out.x() / m_dx;
        yout = out.y() / m_dy;
        if ( ( (float)out.x()  / m_dx ) < m_nx )
        {
            if ( ( (float)out.y() / m_dy ) < m_nz )
            {
                xout = qMax( 0, qMin( xout, static_cast<int>( m_nx - 1.0 ) ) );
                yout = qMax( 0, qMin( yout, static_cast<int>( m_ny - 1.0 ) ) );
                mi = model()->index( (int)Fn::Global::SAGITTAL_CORONAL, 0 );
            }
            else
            {
                xout = qMax( 0, qMin( xout, static_cast<int>( m_nx - 1.0 ) ) );
                yout = yout - m_ny;
                yout = qMax( 0, qMin( yout, static_cast<int>( m_nz - 1.0 ) ) );
                mi = model()->index( (int)Fn::Global::SAGITTAL_AXIAL, 0 );
            }
        }
        else
        {
            xout = xout - m_nx;
            xout = qMax( 0, qMin( m_ny - xout- 1, static_cast<int>( m_ny - 1.0 ) ) );
            yout = yout - m_ny;
            yout = qMax( 0, qMin( yout, static_cast<int>( m_nz - 1.0 ) ) );
            mi = model()->index( (int)Fn::Global::CORONAL_AXIAL, 0 );
        }
    }
    QPoint p( xout, yout );

    if ( mi.isValid() )
    {
        model()->setData( mi, p );
    }
}