当前位置: 首页>>代码示例>>C++>>正文


C++ QVector4D函数代码示例

本文整理汇总了C++中QVector4D函数的典型用法代码示例。如果您正苦于以下问题:C++ QVector4D函数的具体用法?C++ QVector4D怎么用?C++ QVector4D使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了QVector4D函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: QVector4D

void Exercise20::setupMaterialUniforms(QGLShaderProgram* prog)
{
    prog->setUniformValue("material_ambient", QVector4D(m_materials[m_materialMode].m_kAmbient[0], m_materials[m_materialMode].m_kAmbient[1], m_materials[m_materialMode].m_kAmbient[2], m_materials[m_materialMode].m_kAmbient[3]));
    prog->setUniformValue("material_diffuse", QVector4D(m_materials[m_materialMode].m_kDiffuse[0], m_materials[m_materialMode].m_kDiffuse[1], m_materials[m_materialMode].m_kDiffuse[2], m_materials[m_materialMode].m_kDiffuse[3]));
    prog->setUniformValue("material_specular", QVector4D(m_materials[m_materialMode].m_kSpecular[0], m_materials[m_materialMode].m_kSpecular[1], m_materials[m_materialMode].m_kSpecular[2], m_materials[m_materialMode].m_kSpecular[3]));
    prog->setUniformValue("material_emission", QVector4D(m_materials[m_materialMode].m_kEmission[0], m_materials[m_materialMode].m_kEmission[1], m_materials[m_materialMode].m_kEmission[2], m_materials[m_materialMode].m_kEmission[3]));
    prog->setUniformValue("material_shininess", m_materials[m_materialMode].m_shininess);
}
开发者ID:ThomasGoerttler,项目名称:Graphics,代码行数:8,代码来源:exercise20.cpp

示例2: direction

/*!
    Returns the position of this light after transforming it from
    world co-ordinates to eye co-ordinates using \a transform.

    If the light is Directional, then direction() will be transformed,
    after setting the w co-ordinate to 0.  If the light is Positional,
    then position() will be transformed after setting the w co-ordinate
    to 1.

    The returned result is suitable to be applied to the GL_POSITION
    property of \c{glLight()}, assuming that the modelview transformation
    in the GL context is set to the identity.

    \sa eyeSpotDirection()
*/
QVector4D QGLLightParameters::eyePosition(const QMatrix4x4& transform) const
{
    Q_D(const QGLLightParameters);
    if (d->type == Directional)
        return transform * QVector4D(d->position, 0.0f);
    else
        return transform * QVector4D(d->position, 1.0f);
}
开发者ID:Haider-BA,项目名称:walberla,代码行数:23,代码来源:qgllightparameters.cpp

示例3: Light

Light :: Light ()
{
    position = QVector4D (1 , 1.0 , 30.0 , 0.0) ;
    ambient = QVector4D (0.4 , 0.4 , 0.4 , 1.0) ;
    diffuse = QVector4D (1 , 1, 1, 1.0) ;
    specular = QVector4D (1 , 1, 1, 1.0) ;
    intensity = QVector3D (1, 1, 1.0) ;
}
开发者ID:allrod5,项目名称:Computer-Graphics,代码行数:8,代码来源:light.cpp

示例4: QVector4D

// Pitch +ve up, yaw +ve right, Roll +ve right
void Camera::setRotation( float pitch, float yaw, float roll )
{
    m_cameraUpVector = QVector4D(0.0, 1.0, 0.0, 0.0 );
    m_cameraForwardVector = QVector4D(0.0, 0.0, -1.0, 0.0 );
    m_cameraRightVector = QVector4D(1.0, 0.0, 0.0, 0.0 );

    updateRotation( pitch, yaw, roll );
}
开发者ID:geefr,项目名称:oglExperiments,代码行数:9,代码来源:camera.cpp

示例5: generateTerrain

void TriangleWindow::initialize()
{
    generateTerrain();
    initFall();

    m_program = new QOpenGLShaderProgram(this);
    m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/map.vert");
    m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/map.frag");
    m_program->link();
    m_posAttr = m_program->attributeLocation("posAttr");
    m_colAttr = m_program->attributeLocation("colAttr");
    m_normal = m_program->attributeLocation("normal");
    m_texCoord = m_program->attributeLocation("texCoord");
    m_matrixUniform = m_program->uniformLocation("matrix");
    m_texAttr = glGetUniformLocation(m_program->programId(), "texture");
    glUniform1i(m_texAttr, 0);

    size_t verticesSize = _map.size()*sizeof(QVector3D), colorsSize = _color.size()*sizeof(QVector3D),
            normalSize = _normal.size()*sizeof(QVector3D), texCoordSize = _texture.size()*sizeof(GLfloat);

    vao.create();

    vao.bind();

    vbo.create();
    vbo.setUsagePattern(QOpenGLBuffer::StaticDraw);
    vbo.bind();

    vbo.allocate(verticesSize + colorsSize + normalSize + texCoordSize);

    vbo.bind();
    vbo.write(0, _map.constData(), verticesSize);
    vbo.write(verticesSize, _color.constData(), colorsSize);
    vbo.write(verticesSize + colorsSize, _normal.constData(), normalSize);
    vbo.write(verticesSize + colorsSize + normalSize, _texture.constData(), texCoordSize);

    m_program->setAttributeBuffer(m_posAttr, GL_FLOAT, 0, 3, 0);
    m_program->setAttributeBuffer(m_colAttr, GL_FLOAT, verticesSize, 3, 0);
    m_program->setAttributeBuffer(m_normal, GL_FLOAT, verticesSize + colorsSize, 3, 0);
    m_program->setAttributeBuffer(m_texCoord, GL_FLOAT, verticesSize + colorsSize + normalSize, 2, 0);

    m_program->enableAttributeArray(m_posAttr);
    m_program->enableAttributeArray(m_colAttr);
    m_program->enableAttributeArray(m_normal);
    m_program->enableAttributeArray(m_texCoord);

    vao.release();

    QImage image(QString(":/heightmap-2.png"));
    texture = new QOpenGLTexture(image);

    m_program->bind();
    m_program->setUniformValue("ambiant_color", QVector4D(0.7, 0.7, 0.7, 1.0));
    m_program->setUniformValue("light_direction", QVector4D(0.0, 0.0, 1.0, 1.0));
    m_program->release();

    glEnable(GL_DEPTH_TEST);
}
开发者ID:Arihy,项目名称:MoteurDeJeuTP5,代码行数:58,代码来源:trianglewindow.cpp

示例6: glBindBuffer

//-----------------------------------------------------------------------------
void GeometryEngine::drawGridGeometry(QGLShaderProgram *program)
{
	/*
	glBindBuffer(GL_ARRAY_BUFFER, vboIds[2]);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIds[3]);

	int vertexLocation = program->attributeLocation("a_position");
	program->enableAttributeArray(vertexLocation);
	glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, sizeof(QVector3D), (const void *)0);

	glDrawElements(GL_LINES, 10*2, GL_UNSIGNED_SHORT, 0);

	*/

	program->setUniformValue("a_colour", QVector4D(0.3f, 0.3f, 0.3f, 0.5f));
	glBegin(GL_LINES);
	const int grid_size = 20;
	for ( int i = 3 ; i <= grid_size ; i++ )
	{
		glVertex3f((float)-grid_size, 0.0f, (float)i);
		glVertex3f((float) grid_size, 0.0f, (float)i);
		glVertex3f((float)i, 0.0f, (float)-grid_size);
		glVertex3f((float)i, 0.0f, (float) grid_size);

		glVertex3f((float)-grid_size, 0.0f, (float)-i);
		glVertex3f((float) grid_size, 0.0f, (float)-i);
		glVertex3f((float)-i, 0.0f, (float)-grid_size);
		glVertex3f((float)-i, 0.0f, (float) grid_size);
	}
	for ( int i = -2 ; i <= 2 ; i++ )
	{
		glVertex3f((float)i, 0.0f, 3.0f);
		glVertex3f((float)i, 0.0f, (float)grid_size);

		glVertex3f((float)i, 0.0f, -3.0f);
		glVertex3f((float)i, 0.0f, -(float)grid_size);

		glVertex3f( 3.0f,             0.0f, (float)i);
		glVertex3f( (float)grid_size, 0.0f, (float)i);

		glVertex3f(-3.0f,             0.0f, (float)i);
		glVertex3f(-(float)grid_size, 0.0f, (float)i);
	}
	glEnd();

	program->setUniformValue("a_colour", QVector4D(0.3f, 0.3f, 0.75f, 0.75f));
	glBegin(GL_LINE_STRIP);
	glVertex3f( 0.0f, 0.0f,  3.0f);
	glVertex3f( 3.0f, 0.0f,  0.0f);
	glVertex3f( 1.0f, 0.0f,  0.0f);
	glVertex3f( 1.0f, 0.0f, -2.9f);
	glVertex3f(-1.0f, 0.0f, -2.9f);
	glVertex3f(-1.0f, 0.0f,  0.0f);
	glVertex3f(-3.0f, 0.0f,  0.0f);
	glVertex3f( 0.0f, 0.0f,  3.0f);
	glEnd();
}
开发者ID:naniBox,项目名称:kuroBox,代码行数:58,代码来源:GeometryEngine.cpp

示例7: QVector4D

void TexturedRectangle::Node::updateGeometry(const TexturedRectangle* item) {
  QRectF trect = item->textureRect();
  QVector4D* array = m_geometry.vertexData<QVector4D>();

  array[0] = QVector4D(0, 0, trect.left(), trect.top());
  array[1] = QVector4D(1, 0, trect.right(), trect.top());
  array[2] = QVector4D(0, 1, trect.left(), trect.bottom());
  array[3] = QVector4D(1, 1, trect.right(), trect.bottom());
  m_geometry.updateVertexData();
}
开发者ID:Hakiko,项目名称:GameEngine,代码行数:10,代码来源:TexturedRectangle.cpp

示例8: QVector4D

QVector4D SceneParser::strtoV4D(const char *str)
{
  if(!str) {
    return QVector4D();
  }

  float x, y, z, w;
  sscanf(str, "%f %f %f %f", &x, &y, &z, &w);
  return QVector4D(x, y, z, w);
}
开发者ID:JulioC,项目名称:Scene-Renderer,代码行数:10,代码来源:sceneparser.cpp

示例9: QVector4D

void Material::loadTestMaterial()
{
    this->ambient = QVector4D(0.4f, 0.4f, 0.4f, 1.0f);
    this->specular = QVector4D(0.4f, 0.4f, 0.4f, 1.0f);
    this->diffuse = QVector4D(0.8f, 0.8f, 0.8f, 1.0f);
    this->emission = QVector4D(0.8f, 0.8f, 0.8f, 1.0f);
    this->shininess = 40.0f;

    this->textureId = 0;
}
开发者ID:tv,项目名称:cg,代码行数:10,代码来源:material.cpp

示例10: QVector4D

void GLWidget::checkClick(QMouseEvent *event)
{

    QMatrix4x4 view = this->camera->getMatrix();
    QMatrix4x4 perspective = this->camera->projection;

    GLfloat zNear = 0.0f,
            zFar  = 50.0f;

    qreal w = this->_screenWidth,
          h = this->_screenHeight,
          X = (event->x()-w/2)/(w/2),
          Y = -(event->y()-h/2)/(h/2);


    QVector3D rayVector;
    QVector4D nearPoint, farPoint;


    QMatrix4x4 invPV = (view*perspective).inverted();
    QVector4D  out = QVector4D(X, Y, zNear, 1.0);

    nearPoint = invPV * out;

    out = QVector4D(X, Y, zFar, 1.0);

    farPoint = invPV * out;

    rayVector = farPoint.toVector3D() - nearPoint.toVector3D();

    rayVector.normalize();

    qreal minZ = 100.0f, z;

    for (int i = 0, length = this->_objects.size(); i < length; i++) {
        QLObject* object = this->_objects.at(i);
        z = object->isHit(rayVector, minZ);
        if (z < minZ) {

            qDebug() << z << i;
            minZ = z;
            this->selectedIndex = i;

        }
    }

    if (minZ < 100.0f &&event->buttons() & Qt::LeftButton) {
        this->_objects.at(this->selectedIndex)->clicked();
    } else {
        qDebug() << "NO HIT :/!!" << nearPoint;
    }


    return;
}
开发者ID:tv,项目名称:cg,代码行数:55,代码来源:glwidget.cpp

示例11: fabs

QVector4D Cone::surfaceNormal(const QVector4D &p, const Ray &ray)
{
    QVector4D objectP = m_worldToObject * p;

    QVector4D n = fabs(objectP.y()) < MathUtils::dEpsilon ? QVector4D(0.0, -1.0, 0.0, 0.0) :  // We're on the base disc
                                                            QVector4D(objectP.x(), 1.0 - objectP.y(), objectP.z(), 0.0);
    QMatrix4x4 a = m_worldToObject.transposed();
    a.setRow(3, QVector4D(0.0, 0.0, 0.0, 1.0));
    n = a * n;
    return n.normalized();
}
开发者ID:elpuri,项目名称:reijo,代码行数:11,代码来源:cone.cpp

示例12: getMatrix

void CubeObj::drawgl(GLWidget &gl, QMatrix4x4 & cameramat  ) {

    QMatrix4x4 mobj = cameramat;

    mobj *= getMatrix();
    mobj.scale(scale);

    static  QColor color ( 1.0f, 0, 0.5f, 1 );

    QGLShaderProgram * sp = gl.program;

    if ( pro.actualobject == this ) {
        sp = gl.program2;
    }

    for ( int i=0; i <6; i++) {

        sp->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE);
        sp->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE);
        sp->setAttributeArray   (PROGRAM_VERTEX_ATTRIBUTE, vertices.constData());
        sp->setAttributeArray   (PROGRAM_TEXCOORD_ATTRIBUTE, texCoords.constData());
        sp->bind();
        sp->setUniformValue("matrix", mobj);
        sp->setUniformValue("color", QVector4D (1,0,0,0.2f));
        gl.glBindTexture(GL_TEXTURE_2D, this->textureIDs[i] );
        gl.glDrawArrays(GL_QUADS, i*4, 4 );
    }


    if ( pro.getManger().edges ) {
        gl.glDisable(GL_CULL_FACE);
        sp = gl.solidcolorp;

        sp->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE);
        sp->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE);
        sp->setAttributeArray   (PROGRAM_VERTEX_ATTRIBUTE, vertices.constData());
        sp->setAttributeArray   (PROGRAM_TEXCOORD_ATTRIBUTE, texCoords.constData());
        sp->bind();
        sp->setUniformValue("matrix", mobj);
        sp->setUniformValue("color", QVector4D (0,1,0,0.8f));

        if ( pro.actualobject == this ) {
            sp->setUniformValue("color", QVector4D (1,0.8f,1,0.8f));
        }
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
        gl.glLineWidth(2);
        gl.glDrawArrays(GL_QUADS, 0, 24 );
        gl.glEnable(GL_CULL_FACE);
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    }

}
开发者ID:Nand-e,项目名称:2to3d,代码行数:52,代码来源:cubeObj.cpp

示例13: cos

void AwesomeCamera::rotateView(float z_angle,float x_angle){

//    rotM.setToIdentity();


    double cosPhi = cos(mouse_sens*(-z_angle)/180*M_PI);
    double sinPhi = sin(mouse_sens*(-z_angle)/180*M_PI);


    direction      = QVector3D(cosPhi*direction.x()+sinPhi*direction.z(),direction.y(),
                               cosPhi*direction.z()-sinPhi*direction.x());

    QMatrix4x4 rotMat;
    rotMat.setToIdentity();
    rotMat.rotate(mouse_sens*(-x_angle),QVector3D::crossProduct(direction,QVector3D(0,1,0)));
    QVector3D tmpVec = (rotMat*QVector4D(direction)).toVector3D();
    tmpVec.normalize();
    double angleTheta = QVector3D::dotProduct(tmpVec,QVector3D(0,1,0));
    if(qAbs(angleTheta) < 0.9){
        rotMat.setToIdentity();
        rotMat.rotate(mouse_sens*(-x_angle)*(1-qAbs(angleTheta)),QVector3D::crossProduct(direction,QVector3D(0,1,0)));
        QVector3D tmpVec = (rotMat*QVector4D(direction)).toVector3D();
        tmpVec.normalize();
        direction = tmpVec;
    }

    side_direction = QVector3D(cosPhi*side_direction.x()+sinPhi*side_direction.z(),0,
                               cosPhi*side_direction.z()-sinPhi*side_direction.x());

    updown_direction = QVector3D::crossProduct(direction,side_direction);



/*
    rot_angles[0] += mouse_sens*(z_angle);//przesuniecie X
    rot_angles[1] -= mouse_sens*(x_angle);//przesuniecie Y
    if(rot_angles[1] > 90) rot_angles[1] = 90;
    if(rot_angles[1] <-90) rot_angles[1] = -90;
//    przesuniecie do przodu
    direction = QVector3D(-sin(rot_angles[0]/180*M_PI),sin(rot_angles[1]/180*M_PI),cos(rot_angles[0]/180*M_PI));
//    przesuniece na boki
    side_direction = QVector3D(sin((rot_angles[0]+90)/180*M_PI),0,-cos((rot_angles[0]+90)/180*M_PI));
//    przesuwanie gora dol
    updown_direction = QVector3D::crossProduct(direction,side_direction);
*/

    direction.normalize();
    side_direction.normalize();
    updown_direction.normalize();

}
开发者ID:Calinou,项目名称:AwesomeBump,代码行数:51,代码来源:camera.cpp

示例14: QVector4D

//////////////////////////////////////////////////////////////////////
// Private slots Functions
//////////////////////////////////////////////////////////////////////
void ModelViewGadgetWidget::updateAttitude()
{
    AttitudeActual::DataFields data  = attState->getData(); // get attitude data
    GLC_StructOccurence *rootObject = m_World.rootOccurence(); // get the full 3D model
    double x = data.q3;
    double y = data.q2;
    double z = data.q4;
    double w = data.q1;

    if (w == 0.0) {
        w = 1.0;
    }
    // create and gives the product of 2 4x4 matrices to get the rotation of the 3D model's matrix
    QMatrix4x4 m1;
    m1.setRow(0, QVector4D(w, z, -y, x));
    m1.setRow(1, QVector4D(-z, w, x, y));
    m1.setRow(2, QVector4D(y, -x, w, z));
    m1.setRow(3, QVector4D(-x, -y, -z, w));
    QMatrix4x4 m2;
    m2.setRow(0, QVector4D(w, z, -y, -x));
    m2.setRow(1, QVector4D(-z, w, x, -y));
    m2.setRow(2, QVector4D(y, -x, w, -z));
    m2.setRow(3, QVector4D(x, y, z, w));
    QMatrix4x4 m0 = m1 * m2;
    // convert QMatrix4x4 to GLC_Matrix4x4
    GLC_Matrix4x4 rootObjectRotation(m0.data());
    rootObject->structInstance()->setMatrix(rootObjectRotation);
    rootObject->updateChildrenAbsoluteMatrix();
    updateGL();
}
开发者ID:EvalZero,项目名称:TauLabs,代码行数:33,代码来源:modelviewgadgetwidget.cpp

示例15: Q_UNUSED

void X11FilterContext::drawRichText(const QRectF &rect, const QString &text, bool wordWrap)
{
    Q_UNUSED(rect);
    Q_UNUSED(text);
    if (text == this->text && plain && mask_pix) {
        renderTextImageX11(0, rect.topLeft());
        return;
    }
    this->text = text;
    this->plain = false;

    if (!doc)
        doc = new QTextDocument();
    doc->setHtml(text);
    //painter->translate(rect.topLeft()); //drawContent() can not set target rect, so move here
    if (wordWrap)
        doc->setTextWidth(rect.width());

    QMatrix4x4 m(transform);
    const QRectF r = m.mapRect(QRectF(rect.x(), rect.y(), doc->size().width(), doc->size().height()));
    text_q = QImage(r.size().toSize(), QImage::Format_ARGB32);
    text_q.fill(QColor(0, 0, 0, 0));
    painter->begin(&text_q);
    prepare();
    const QPointF tl = m.map(rect.topLeft());
    m.setColumn(3, QVector4D(0, 0, 0, 1)); // reset O to let painter draw from 0
    const QPointF dp =  tl - r.topLeft(); //painter should start from the mapped top left relative to mapped rect's top left
    //qDebug() << dp << r.;
    painter->setTransform(m.toTransform());
    painter->translate(dp);

    doc->drawContents(painter);
    painter->end();
    renderTextImageX11(&text_q, r.topLeft()); //TODO: use boundingRect?
}
开发者ID:Jornason,项目名称:QtAV,代码行数:35,代码来源:X11FilterContext.cpp


注:本文中的QVector4D函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。