void QSGAnimatorNode::preprocess()
{
    QSGNode::preprocess();
    if (m_controller->isInitialized()) {
        if (m_transformNode) {
            qreal x = m_controller->registeredProperty("x")->value().toReal();
            qreal y = m_controller->registeredProperty("y")->value().toReal();
            QMatrix4x4 m = m_controller->transformMatrix();
            QPointF transformOrigin = m_controller->registeredProperty("transformOriginPoint")->value().toPointF();
            qreal scale = m_controller->registeredProperty("scale")->value().toReal();
            qreal rotation = m_controller->registeredProperty("rotation")->value().toReal();
            m.translate(transformOrigin.x(), transformOrigin.y());
            m.translate(x, y);
            m.scale(scale);
            m.rotate(rotation, 0, 0, 1);
            m.translate(-transformOrigin.x(), -transformOrigin.y());
            m_transformNode->setMatrix(m);

            if (m_controller->isUpdating())
                m_transformNode->markDirty(QSGNode::DirtyMatrix);
        }

        if (m_opacityNode) {
            qreal opacity = m_controller->registeredProperty("opacity")->value().toReal();
            m_opacityNode->setOpacity(qMin(qreal(MAX_OPACITY), qMax(qreal(MIN_OPACITY), opacity)));

            if (m_controller->isUpdating())
                m_opacityNode->markDirty(QSGNode::DirtyOpacity);
        }
    }
}
示例#2
0
void SatHorizon::render(QMatrix4x4 projection, float distance, QQuaternion quat, QVector3D posnorm, float alt, QColor rendercolor)
{

    float radius = sqrt( alt * alt - 1 ) / alt;

    float theta = acos(QVector3D::dotProduct(QVector3D(0,0,1), posnorm));
    QVector3D vecnorm = QVector3D::crossProduct(QVector3D(0,0,1), posnorm);
    vecnorm.normalize();

    createCircleBuffer(radius, SEGMENTS);

    QMatrix4x4 modelview;
    modelview.translate(0.0, 0.0, distance);
    modelview.rotate(quat);

    modelview.translate(posnorm * (1/alt) * (alt > 1.5 ? 1.0015 : 1.0001));
    modelview.rotate(theta * 180.0f/ PI, vecnorm );

    posBuf.bind();
    posBuf.write(0, vertexData, SEGMENTS * sizeof(QVector3D));
    posBuf.release();

    program->bind();

    program->setUniformValue("MVP", projection * modelview);
    QMatrix3x3 norm = modelview.normalMatrix();
    program->setUniformValue("NormalMatrix", norm);

    program->setUniformValue("outcolor", QVector4D(rendercolor.redF(), rendercolor.greenF(), rendercolor.blueF(), 1.0f));
    QOpenGLVertexArrayObject::Binder vaoBinder(&vao);
    glDrawArrays(GL_LINE_LOOP, 0, SEGMENTS);

}
示例#3
0
void Navigation::rotate(
    float hAngle
,   float vAngle)
{
    static const QVector3D up(0.0, 1.0, 0.0);

    m_rotationHappened = true;

    const QVector3D ray((m_camera.center() - m_eye).normalized());
    const QVector3D rotAxis(QVector3D::crossProduct(ray, up));

    hAngle *= ROTATION_HOR_DOF;
    vAngle *= ROTATION_VER_DOF;

    enforceRotationConstraints(hAngle, vAngle);

    QVector3D t = m_i0Valid ? m_i0 : m_center;

    QMatrix4x4 transform;
    transform.translate( t);
    transform.rotate(hAngle, up);
    transform.rotate(vAngle, rotAxis);
    transform.translate(-t);

    m_camera.setEye(transform * m_eye);
    m_camera.setCenter(transform * m_center);

    m_camera.update();
}
示例#4
0
	template <typename R> void call(R *r) {
		using V = decltype(declval<typename R::Cell>().getPosition());
		const auto &view = r->getViewMatrix();
		const auto &projection = r->getProjectionMatrix();
		shader.bind();
		disk.vao.bind();
		QVector4D color(0.9f, 0.9f, 0.05f, 1.0f);
		shader.setUniformValue(shader.uniformLocation("color"), color);
		shader.setUniformValue(shader.uniformLocation("projection"), projection);
		shader.setUniformValue(shader.uniformLocation("view"), view);
		for (auto &con : r->getScenario().getWorld().cellCellConnections) {
			auto &cc = con.second;
			QMatrix4x4 model;
			model.translate(
			    toQV3D(cc.cells.first->getPosition() + cc.normal * cc.midpoint.first));
			auto rot = V::getRotation(V(0, 0, 1), cc.normal);
			model.rotate(rot.teta * 180.0 / M_PI, toQV3D(rot.n));
			float rad = static_cast<float>(sqrt(cc.sqradius));
			model.scale(rad, rad, rad);
			QMatrix4x4 nmatrix = (model).inverted().transposed();
			shader.setUniformValue(shader.uniformLocation("model"), model);
			shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
			GL->glDrawElements(GL_TRIANGLES, disk.indices.size(), GL_UNSIGNED_INT, 0);
		}
		color = QVector4D(0.1f, 0.7f, 0.f, 1.0f);
		shader.setUniformValue(shader.uniformLocation("color"), color);
		for (auto &con : r->getScenario().getWorld().cellCellConnections) {
			auto &cc = con.second;
			QMatrix4x4 model;
			model.translate(toQV3D(cc.cells.first->getPosition() +
			                       cc.icb.first.currentBasis.X * cc.midpoint.first));
			auto rot = V::getRotation(V(0, 0, 1), cc.icb.first.currentBasis.X);
			model.rotate(rot.teta * 180.0 / M_PI, toQV3D(rot.n));
			float rad = static_cast<float>(sqrt(cc.sqradius));
			model.scale(rad, rad, rad);
			QMatrix4x4 nmatrix = (model).inverted().transposed();
			shader.setUniformValue(shader.uniformLocation("model"), model);
			shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
			GL->glDrawElements(GL_TRIANGLES, disk.indices.size(), GL_UNSIGNED_INT, 0);
		}
		color = QVector4D(0.f, 0.1f, 0.7f, 1.0f);
		shader.setUniformValue(shader.uniformLocation("color"), color);
		for (auto &con : r->getScenario().getWorld().cellCellConnections) {
			auto &cc = con.second;
			QMatrix4x4 model;
			model.translate(toQV3D(cc.cells.second->getPosition() +
			                       cc.icb.second.currentBasis.X * cc.midpoint.second));
			auto rot = V::getRotation(V(0, 0, 1), cc.icb.second.currentBasis.X);
			model.rotate(rot.teta * 180.0 / M_PI, toQV3D(rot.n));
			float rad = static_cast<float>(sqrt(cc.sqradius));
			model.scale(rad, rad, rad);
			QMatrix4x4 nmatrix = (model).inverted().transposed();
			shader.setUniformValue(shader.uniformLocation("model"), model);
			shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
			GL->glDrawElements(GL_TRIANGLES, disk.indices.size(), GL_UNSIGNED_INT, 0);
		}
		disk.vao.release();
		shader.release();
	}
示例#5
0
/**
  \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()));
        }
示例#6
0
文件: Mesh.cpp 项目: jlerouge/glanc3d
/**
 * Homothétie sur le mesh, ayant pour centre le centre de gravité du
 * mesh.
 * @param x rapport de l'homothétie.
 */
void Mesh::homothetie(float x)
{
    QMatrix4x4 t;
    t.translate(centre_);
    t.scale(x);
    t.translate(-centre_);

    for (int i=0;i<nbVertices_;i++)
    {
        QVector3D &v=vertices_[i];
        setXYZ(i, (t*v));
    }
   octree_->changerTailleOctree(x-1);
}
示例#7
0
QMatrix4x4 Exercise12::rotateClockwise(int frame)
{
    /////////////////////////////////////////////////////////////////////////////////////////////////
    // TODO: Aufgabe 12
    // Apply correct transformations (rotate, translate, scale) with respect to the current frame
    /////////////////////////////////////////////////////////////////////////////////////////////////

    QMatrix4x4 transform;
    int degree = frame % 360;
    transform.setToIdentity();
    if(degree < 90) {
      transform.translate(0.5, 0.5, 0.0);
      transform.rotate(-2 * degree, 0.0, 0.0, 1.0);
      transform.translate(-0.5, 0.5, 0.0);
    } else if(degree < 180) {
      transform.translate(0.5, -0.5, 0.0);
      transform.rotate(-2 * degree, 0.0, 0.0, 1.0);
      transform.translate(-0.5, -0.5, 0.0);
    } else if(degree < 270) {
      transform.translate(-0.5, -0.5, 0.0);
      transform.rotate(-2 * degree, 0.0, 0.0, 1.0);
      transform.translate(0.5, -0.5, 0.0);
    } else if(degree < 360) {
      transform.translate(-0.5, 0.5, 0.0);
      transform.rotate(-2 * degree, 0.0, 0.0, 1.0);
      transform.translate(0.5, 0.5, 0.0);
    }
    return transform;
}
示例#8
0
	template <typename R> void call(R *r) {
		const auto &view = r->getViewMatrix();
		const auto &projection = r->getProjectionMatrix();
		for (auto &con : r->getScenario().getWorld().cellCellConnections) {
			auto &cc = con.second;
			shader.bind();
			cube.vao.bind();
			QColor color = QColor::fromHsvF(0.7, 0.7, 0.7);
			shader.setUniformValue(shader.uniformLocation("color"), color);
			shader.setUniformValue(shader.uniformLocation("projection"), projection);
			shader.setUniformValue(shader.uniformLocation("view"), view);
			// first
			QMatrix4x4 model;
			auto ab =
			    toQV3D(cc.targets.first.b.X.rotated(cc.cells.first->getOrientationRotation()) *
			           cc.targets.first.d);
			model.translate(toQV3D(cc.cells.first->getPosition()) + ab * 0.5);
			auto dp = ab.normalized().x();
			if (dp != 1 && dp != -1) {
				model.rotate(acos(dp) * 180.0 / M_PI,
				             QVector3D::crossProduct(QVector3D(1, 0, 0), ab));
				model.scale(ab.length() * 0.5, 1.0, 1.0);
				QMatrix4x4 nmatrix = (model).inverted().transposed();
				shader.setUniformValue(shader.uniformLocation("model"), model);
				shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
				GL->glDrawElements(GL_TRIANGLES, cube.indices.size(), GL_UNSIGNED_INT, 0);
			}
			// second
			color = QColor::fromHsvF(0.3, 0.7, 0.7);
			shader.setUniformValue(shader.uniformLocation("color"), color);
			model = QMatrix4x4();
			ab = toQV3D(
			    cc.targets.second.b.X.rotated(cc.cells.second->getOrientationRotation()) *
			    cc.targets.second.d);
			model.translate(toQV3D(cc.cells.second->getPosition()) + ab * 0.5);
			dp = ab.normalized().x();
			if (dp != 1 && dp != -1) {
				model.rotate(acos(dp) * 180.0 / M_PI,
				             QVector3D::crossProduct(QVector3D(1, 0, 0), ab));
				model.scale(ab.length() * 0.5, 1.0, 1.0);
				QMatrix4x4 nmatrix = (model).inverted().transposed();
				shader.setUniformValue(shader.uniformLocation("model"), model);
				shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
				GL->glDrawElements(GL_TRIANGLES, cube.indices.size(), GL_UNSIGNED_INT, 0);
			}
			cube.vao.release();
			shader.release();
		}
	}
void QQuickTransformAnimatorJob::Helper::apply()
{
    if (!wasChanged || !node)
        return;

    QMatrix4x4 m;
    m.translate(dx, dy);
    m.translate(ox, oy);
    m.scale(scale);
    m.rotate(rotation, 0, 0, 1);
    m.translate(-ox, -oy);
    node->setMatrix(m);

    wasChanged = false;
}
示例#10
0
void LogoRenderer::vao_vbo_glDrawArrays()
{
    // Render
    glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    // Draw our first triangle
    glUseProgram(shaderProgram);

    QMatrix4x4 modelview;
    modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
    modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
    modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
    modelview.scale(m_fScale);
    modelview.translate(0.0f, -0.2f, 0.0f);

    // Uniform offset
    // Get matrix's uniform location and set matrix
    GLint transformLoc = glGetUniformLocation(shaderProgram, "transform");
    glUniformMatrix4fv(transformLoc, 1, GL_FALSE, modelview.data());
    //            glUniform1f(glGetUniformLocation(ourShader.Program, "xOffset"), offset);

    glBindVertexArray(VAO);
    glDrawArrays(GL_TRIANGLES, 0, 3);
    glBindVertexArray(0);
}
void HgTransformedQuad::transformQuad(int index, const QMatrix4x4& projView, HgQuad* quad,
                                      qreal mirroringPlaneY, const QVector2D& translate, const QPointF& center,
                                      const QSizeF& windowSize)
{
    mIndex = index;
    mQuad = quad;

    QMatrix4x4 tm;
    tm.setToIdentity();
    tm.rotate(quad->outerRotation());

    if (mQuad->mirrorImageEnabled())
    {
        computeMirroredPoints(tm, projView, mirroringPlaneY, translate, center, windowSize);
    }

    tm.translate(quad->position());
    tm.rotate(quad->rotation());
    tm.scale(quad->scale().x(), quad->scale().y());

    tm = projView * tm;

    perspectiveTransformPoints(mTransformedPoints, tm, center, windowSize);

    for (int i = 0; i < 4; i++)
        mTransformedPoints[i] += translate;

}
示例#12
0
文件: data.cpp 项目: not-surt/SimPix
ImageData::ImageData(const QSize &size, const Format::Id format, const GLubyte *const data) :
    TextureData(size, format, data), rect(QPoint(0, 0), size),
    projectionMatrix([this]() {
        const float halfWidth = (float)this->size.width() / 2.f;
        const float halfHeight = (float)this->size.height() / 2.f;
        QMatrix4x4 temp;
        temp.scale(1.f / (float)halfWidth, 1.f / (float)halfHeight);
        temp.translate(-halfWidth, -halfHeight);
        return temp; }()),
    vertexArray([this](){
        GLuint vertexArray;
        glGenVertexArrays(1, &vertexArray);
        return vertexArray; }()),
    vertexBuffer([this](){
        GLuint vertexBuffer;
        glGenBuffers((GLsizei)1, &vertexBuffer);
        glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
        const GLfloat vertices[][2] = {
            {0.f, 0.f},
            {(GLfloat)this->size.width(), 0.f},
            {(GLfloat)this->size.width(), (GLfloat)this->size.height()},
            {0.f, (GLfloat)this->size.height()},
        };
        glBufferData(GL_ARRAY_BUFFER, 4 * 2 * sizeof(GLfloat), vertices, GL_STATIC_DRAW);
        return vertexBuffer; }())

{
}
示例#13
0
QMatrix4x4 ModelInterface::getMatrix(const aiMatrix4x4* m)
{
    QMatrix4x4 nodeMatrix;

    if(m->IsIdentity())
        return nodeMatrix;

    aiQuaternion rotation;
    aiVector3D   position;
    aiVector3D   scale;

    m->Decompose(scale, rotation, position);

    QVector3D   qscale(scale.x,scale.y, scale.z);
    QVector3D   qposition(position.x, position.y, position.z);
    QQuaternion qrotation(rotation.w, rotation.x, rotation.y, rotation.z);

    if(!qscale.isNull())
        nodeMatrix.scale(qscale);

    if(!qposition.isNull())
        nodeMatrix.translate(qposition);

    if(!qrotation.isNull())
        nodeMatrix.rotate(qrotation);

    return nodeMatrix;
}
void Visualizer::paintGL()
{
    // Clear color and depth buffer
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

       texture->bind();

       // Calculate model view transformation
       QMatrix4x4 matrix;
       matrix.translate(0.0, 0.0, -5.0);
       matrix.rotate(rotation);

       // Set modelview-projection matrix
       program.setUniformValue("mvp_matrix", projection * matrix);

       // Use texture unit 0 which contains cube.png
       program.setUniformValue("texture", 0);

       // Generate 2 VBOs
       arrayBuf.create();
       indexBuf.create();

       // Initializes cube geometry and transfers it to VBOs
       initCubeGeometry();
       drawCubeGeometry(&program);


}
示例#15
0
void MultiTrackPlotter::updateTransform()
{
    qreal y_scaling = 1.0;
    y_scaling *= m_height * 0.5;
    if (!m_overlay && m_channel_count > 1)
        y_scaling /= m_channel_count;

    qreal x_scaling = m_width;
    if (m_frame_count > 1)
        x_scaling /= (m_frame_count - 1);

    for (int idx = 0; idx < m_channel_count; ++idx)
    {
        qreal y_translation = 1.0;
        if (!m_overlay)
            y_translation += idx * 2.0;

        QMatrix4x4 matrix;
        matrix.scale(x_scaling, y_scaling);
        matrix.translate(0.0, y_translation);
        matrix.scale(1.0, -m_scaling); // flip y axis!

        QSGTransformNode *transformNode = static_cast<QSGTransformNode*>( childAtIndex(idx) );;
        transformNode->setMatrix(matrix);
    }
}
示例#16
0
	template <typename R> void call(R *r) {
		const auto &view = r->getViewMatrix();
		const auto &projection = r->getProjectionMatrix();
		shader.bind();
		sphere.vao.bind();
		texture->bind(0);
		shader.setUniformValue(shader.uniformLocation("projection"), projection);
		shader.setUniformValue(shader.uniformLocation("view"), view);
		for (auto &n : r->getScenario().nutrientSources) {
			QMatrix4x4 model;
			model.translate(n.pos.x(), n.pos.y(), n.pos.z());
			double c = n.content / n.initialcontent;
			double l = 15.0 + sqrt(n.sqradius * c) * 0.05;
			model.scale(l, l, l);
			QMatrix4x4 nmatrix = (model).inverted().transposed();
			shader.setUniformValue(shader.uniformLocation("model"), model);
			shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
			auto hsv = QColor::fromHsvF(c * 0.35, 0.9, 0.9);
			QVector4D col(hsv.redF(), hsv.greenF(), hsv.blueF(), 0.5);
			std::cerr << "c = " << c << ", r = " << col.x() << std::endl;
			shader.setUniformValue(shader.uniformLocation("color"), col);
			GL->glDrawElements(GL_TRIANGLES, sphere.indices.size(), GL_UNSIGNED_INT, 0);
		}
		sphere.vao.release();
		shader.release();
	}
void SurfaceGraph::paintGL()
{
    // Clear color and depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    texture->bind();

    // Calculate model view transformation
    QMatrix4x4 matrix;
    matrix.translate(0.0, 0.0, -5.0);
    matrix.rotate(rotation);
    matrix.scale(zoom,zoom,zoom);

    // Set modelview-projection matrix
    program.setUniformValue("mvp_matrix", projection * matrix);

    // Use texture unit 0 (which file to use)
    program.setUniformValue("texture", 0);

    // Draw geometry
    geometries->drawGeometry(&program);

    if (display_lines)
    {
        geometries->drawLineGeometry(&program);
        geometries->drawPointGeometry(&program);
    }
}
示例#18
0
QMatrix4x4 Transform3D::worldToLocalMatrix() const
{
    QMatrix4x4 wtl;
    wtl.rotate(m_orientation.conjugate());
    wtl.translate(-m_position);
    return wtl;
}
示例#19
0
QMatrix4x4 centerIn(const QRectF& content, const QRectF& frame)
{
    const qreal contentSize = std::max(content.width(), content.height());
    const qreal frameSize = std::min(frame.width(), frame.height());

    qreal scale{1};
    if (frameSize < contentSize)
    {
        scale = frameSize / contentSize;
    }

    const QSizeF scaledContentSize = QSizeF(content.size()) * scale;

    const qreal dx = (frame.width() - scaledContentSize.width()) / 2.0;
    const qreal dy = (frame.height() - scaledContentSize.height()) / 2.0;

    QPointF translate = QPointF(-content.topLeft());
    translate += (QPointF(dx, dy) * (1 / scale));

    QMatrix4x4 matrix;
    matrix.scale(scale);
    matrix.translate(translate.x(), translate.y());

    return matrix;
}
示例#20
0
void GLPointCloudViewer::renderCloud(QOpenGLShaderProgram* program, GLPointCloud* cloud)
{
    if (program == nullptr || !program->bind())
        return;

    // Calculate model view transformation
    QMatrix4x4 view;
    view.translate(0, 0, distance);
    view.rotate(rotation);

    int projection_matrix_location = program->uniformLocation("projectionMatrix");
    if (projection_matrix_location > -1)
        program->setUniformValue("projectionMatrix", projection);
    else
        std::cerr << "Error: Shader does not have attribute 'projectionMatrix'" << std::endl;


    int view_matrix_location = program->uniformLocation("viewMatrix");
    if (view_matrix_location > -1)
        program->setUniformValue("viewMatrix", view);
    else
        std::cerr << "Error: Shader does not have attribute 'viewMatrix'" << std::endl;


    int model_matrix_location = program->uniformLocation("modelMatrix");
    if (model_matrix_location > -1)
        program->setUniformValue("modelMatrix", cloud->transform());
    else
        std::cerr << "Error: Shader does not have attribute 'modelMatrix'" << std::endl;

    cloud->render(program);
}
示例#21
0
void MyWindow::CreateVertexBuffer()
{
    QMatrix4x4 transform;
    transform.translate(QVector3D(0.0f, 1.5f, 0.25f));
    mTeapot = new Teapot(13, transform);

    // Create and populate the buffer objects
    unsigned int handle[3];
    glGenBuffers(3, handle);        

    glBindBuffer(GL_ARRAY_BUFFER, handle[0]);
    glBufferData(GL_ARRAY_BUFFER, (3 * mTeapot->getnVerts()) * sizeof(float), mTeapot->getv(), GL_STATIC_DRAW);

    glBindBuffer(GL_ARRAY_BUFFER, handle[1]);
    glBufferData(GL_ARRAY_BUFFER, (3 * mTeapot->getnVerts()) * sizeof(float), mTeapot->getn(), GL_STATIC_DRAW);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, handle[2]);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * mTeapot->getnFaces() * sizeof(unsigned int), mTeapot->getelems(), GL_STATIC_DRAW);

    // Setup the VAO
    // Vertex positions
    mFuncs->glBindVertexBuffer(0, handle[0], 0, sizeof(GLfloat) * 3);
    mFuncs->glVertexAttribFormat(0, 3, GL_FLOAT, GL_FALSE, 0);
    mFuncs->glVertexAttribBinding(0, 0);

    // Vertex normals
    mFuncs->glBindVertexBuffer(1, handle[1], 0, sizeof(GLfloat) * 3);
    mFuncs->glVertexAttribFormat(1, 3, GL_FLOAT, GL_FALSE, 0);
    mFuncs->glVertexAttribBinding(1, 1);

    // Indices
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, handle[2]);

    mFuncs->glBindVertexArray(0);
}
示例#22
0
void ImagesDisplay::paint_3d_output()
{
    float                     val;
    QMatrix4x4             matrix;
    QGLShaderProgram *sel_program;

    // Calculate model view transformation
    matrix.translate(0.0, 0.0, -5.0);
    //matrix.rotate(rotation);

    if (ima_info.preview_mode == 0)
    {  sel_program = &program;  }
    else
    {  sel_program = &program_threshold;  }
    sel_program->bind();

    // Set modelview-projection matrix
    sel_program->setUniformValue("mvp_matrix", projection *matrix);

    // Default texture unit which contains the texture from resources or file
    sel_program->setUniformValue("texture", 0);

    val = threshold_val;
    sel_program->setUniformValue("threshold_val",val);

    if (ima_info.info_flag & INFO_FLAG_DRAW_IMAGE)
    {
      kernel.draw_image_to_screen(sel_program);
    }
}
示例#23
0
void Renderer::render()
{
    QMutexLocker locker(&m_windowLock);

    if (m_windows.isEmpty())
        return;

    HelloWindow *surface = m_windows.at(m_currentWindow);
    QColor color = surface->color();

    m_currentWindow = (m_currentWindow + 1) % m_windows.size();

    if (!m_context->makeCurrent(surface))
        return;

    QSize viewSize = surface->size();

    locker.unlock();

    if (!m_initialized) {
        initialize();
        m_initialized = true;
    }

    QOpenGLFunctions *f = m_context->functions();
    f->glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio());
    f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    f->glClearColor(m_backgroundColor.redF(), m_backgroundColor.greenF(), m_backgroundColor.blueF(), m_backgroundColor.alphaF());
    f->glFrontFace(GL_CW);
    f->glCullFace(GL_FRONT);
    f->glEnable(GL_CULL_FACE);
    f->glEnable(GL_DEPTH_TEST);

    m_program->bind();
    m_vbo.bind();

    m_program->enableAttributeArray(vertexAttr);
    m_program->enableAttributeArray(normalAttr);
    m_program->setAttributeBuffer(vertexAttr, GL_FLOAT, 0, 3);
    const int verticesSize = vertices.count() * 3 * sizeof(GLfloat);
    m_program->setAttributeBuffer(normalAttr, GL_FLOAT, verticesSize, 3);

    QMatrix4x4 modelview;
    modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
    modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
    modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
    modelview.translate(0.0f, -0.2f, 0.0f);

    m_program->setUniformValue(matrixUniform, modelview);
    m_program->setUniformValue(colorUniform, color);

    m_context->functions()->glDrawArrays(GL_TRIANGLES, 0, vertices.size());

    m_context->swapBuffers(surface);

    m_fAngle += 1.0f;

    QTimer::singleShot(0, this, SLOT(render()));
}
示例#24
0
void AvatarVoxelSystem::applyScaleAndBindProgram(bool texture) {
    _skinProgram.bind();
    
    // the base matrix includes centering and scale
    QMatrix4x4 baseMatrix;
    baseMatrix.scale(_treeScale);
    baseMatrix.translate(-0.5f, -0.5f, -0.5f);
    
    // bone matrices include joint transforms
    QMatrix4x4 boneMatrices[NUM_AVATAR_JOINTS];
    for (int i = 0; i < NUM_AVATAR_JOINTS; i++) {
        glm::vec3 position;
        glm::quat orientation;
        _avatar->getBodyBallTransform((AvatarJointID)i, position, orientation);
        boneMatrices[i].translate(position.x, position.y, position.z);
        orientation = orientation * glm::inverse(_avatar->getSkeleton().joint[i].absoluteBindPoseRotation);
        boneMatrices[i].rotate(QQuaternion(orientation.w, orientation.x, orientation.y, orientation.z));
        const glm::vec3& bindPosition = _avatar->getSkeleton().joint[i].absoluteBindPosePosition;
        boneMatrices[i].translate(-bindPosition.x, -bindPosition.y, -bindPosition.z);
        boneMatrices[i] *= baseMatrix;
    } 
    _skinProgram.setUniformValueArray(_boneMatricesLocation, boneMatrices, NUM_AVATAR_JOINTS);
    
    glBindBuffer(GL_ARRAY_BUFFER, _vboBoneIndicesID);
    glVertexAttribPointer(_boneIndicesLocation, BONE_ELEMENTS_PER_VERTEX, GL_UNSIGNED_BYTE, false, 0, 0);
    _skinProgram.enableAttributeArray(_boneIndicesLocation);
    
    glBindBuffer(GL_ARRAY_BUFFER, _vboBoneWeightsID);
    _skinProgram.setAttributeBuffer(_boneWeightsLocation, GL_FLOAT, 0, BONE_ELEMENTS_PER_VERTEX);
    _skinProgram.enableAttributeArray(_boneWeightsLocation);
}
示例#25
0
void QVRVNCViewer::createSceneGeometry(QVector<QVector3D>& positions,
        QVector<QVector2D>& texcoords, QVector<unsigned int>& indices)
{
    if (_screenType == screenTypeWall) {
        QVector3D bl(_screenWall[0], _screenWall[1], _screenWall[2]);
        QVector3D br(_screenWall[3], _screenWall[4], _screenWall[5]);
        QVector3D tl(_screenWall[6], _screenWall[7], _screenWall[8]);
        QVector3D tr = br + (tl - bl);
        positions.append(bl);
        positions.append(br);
        positions.append(tr);
        positions.append(tl);
        texcoords.append(QVector2D(0.0f, 1.0f));
        texcoords.append(QVector2D(1.0f, 1.0f));
        texcoords.append(QVector2D(1.0f, 0.0f));
        texcoords.append(QVector2D(0.0f, 0.0f));
        indices.append(0);
        indices.append(1);
        indices.append(3);
        indices.append(1);
        indices.append(2);
        indices.append(3);
    } else if (_screenType == screenTypeCylinder) {
        QVector3D center(_screenCylinder[0], _screenCylinder[1], _screenCylinder[2]);
        QVector3D up(_screenCylinder[3], _screenCylinder[4], _screenCylinder[5]);
        float radius = _screenCylinder[6];
        float phiCenter = _screenCylinder[7];
        float phiRange = _screenCylinder[8];
        float thetaRange = _screenCylinder[9];
        float py = radius * std::tan(thetaRange / 2.0f);
        QVector3D rotAxis = QVector3D::crossProduct(QVector3D(0.0f, 1.0f, 0.0f), up);
        float rotAngle = qRadiansToDegrees(
                std::acos(QVector3D::dotProduct(QVector3D(0.0f, 1.0f, 0.0f), up)
                    / std::sqrt(QVector3D::dotProduct(up, up))));
        QMatrix4x4 M;
        M.rotate(90.0f, 0.0f, 1.0f, 0.0f);
        M.rotate(rotAngle, rotAxis);
        M.translate(center);
        const int N = 1000;
        for (int x = 0; x <= N; x++) {
            float xf = x / static_cast<float>(N);
            float phi = phiCenter + (xf - 0.5f) * phiRange;
            float px = radius * std::cos(phi);
            float pz = radius * std::sin(phi);
            positions.append(M * QVector3D(px, py, pz));
            texcoords.append(QVector2D(xf, 0.0f));
            positions.append(M * QVector3D(px, -py, pz));
            texcoords.append(QVector2D(xf, 1.0f));
            if (x > 0) {
                indices.append(2 * (x - 1));
                indices.append(2 * (x - 1) + 1);
                indices.append(2 * x + 1);
                indices.append(2 * (x - 1));
                indices.append(2 * x + 1);
                indices.append(2 * x);
            }
        }
    }
}
void PhysicsTransform::updateMatrix(){
    QMatrix4x4 m;
    m.translate(m_translation);
    m.rotate(m_rotation);
    m.scale(m_scale);
    m_transformMatrix = m;
    m_dirty=true;
}
示例#27
0
文件: cell.cpp 项目: Snodig/Nagios
void rpnoc::ImageCell::draw( const QMatrix4x4& iProjection, const QMatrix4x4& iView, QMatrix4x4 iModel )
{
	mPanel->draw( iProjection, iView, iModel );
	iModel.translate( mPadding.x(), mPadding.y(), 0.0 );
	
	TextureManager::getInstance().bindTexture( mName );
	mSquare->draw( iProjection, iView, iModel );
}
示例#28
0
void BeamRendererComponent::draw( int /* timeLapse */ )
{
    QMatrix4x4 transform = gameObject()->transform();
    transform.translate( 0, 0, 0.01f );
    transform.scale( d->size.width() / 2, d->size.width() / 2 );
    d->baseItem->setTransform( transform );

    transform = gameObject()->transform();
    transform.translate( 0, d->size.height() / 2 );
    transform.scale( d->size.width() / 2, d->size.height() / 2 );
    d->beamItem->setTransform( transform );

    transform = gameObject()->transform();
    transform.translate( 0, d->size.height(), 0.01f );
    transform.scale( d->size.width() / 2, d->size.width() / 2 );
    d->tipItem->setTransform( transform );
}
示例#29
0
QMatrix4x4 moveTo(const QPoint& point, const QPoint& refPoint)
{
    QMatrix4x4 matrix;

    matrix.translate(refPoint.x() - point.x(), refPoint.y() - point.y());

    return matrix;
}
示例#30
0
QMatrix4x4 Transformable::modelMatrix() const {
    QMatrix4x4 mat;
    mat.translate(m_position);
    mat.scale(m_scale);
    //mat.rotate(m_rotation);
    mat.rotate(m_rotation.scalar(), m_rotation.x(), m_rotation.y(), m_rotation.z());
    return mat;
}