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); }
/*! 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); }
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) ; }
// 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 ); }
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); }
//----------------------------------------------------------------------------- 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(); }
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(); }
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); }
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; }
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; }
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(); }
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); } }
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(); }
////////////////////////////////////////////////////////////////////// // 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(); }
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? }
void TerrainTessellationScene::render() { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); m_material->bind(); QOpenGLShaderProgramPtr shader = m_material->shader(); shader->bind(); // Set the horizontal and vertical scales applied in the tess eval shader shader->setUniformValue( "horizontalScale", m_horizontalScale ); shader->setUniformValue( "verticalScale", m_verticalScale ); // Pass in the model matrix to transform our grid QMatrix4x4 viewMatrix = m_camera->viewMatrix(); QMatrix4x4 modelViewMatrix = viewMatrix * m_modelMatrix; QMatrix4x4 mvp = m_camera->projectionMatrix() * modelViewMatrix; shader->setUniformValue( "mvp", mvp ); // We also need the viewport matrix (to transform into screen-space) shader->setUniformValue( "viewportMatrix", m_viewportMatrix ); // Set the wireframe line properties shader->setUniformValue( "line.width", 1.0f ); shader->setUniformValue( "line.color", QVector4D( 0.0f, 1.0f, 0.0f, 1.0f ) ); // Render the quad as a patch m_vao.bind(); m_funcs->glPatchParameteri( GL_PATCH_VERTICES, 1 ); glDrawArrays( GL_PATCHES, 0, m_patchCount ); }
void LanczosShader::createKernel(float delta, int *size) { const float a = 2.0; // The two outermost samples always fall at points where the lanczos // function returns 0, so we'll skip them. const int sampleCount = qBound(3, qCeil(delta * a) * 2 + 1 - 2, 29); const int center = sampleCount / 2; const int kernelSize = center + 1; const float factor = 1.0 / delta; QVector<float> values(kernelSize); float sum = 0; for (int i = 0; i < kernelSize; i++) { const float val = lanczos(i * factor, a); sum += i > 0 ? val * 2 : val; values[i] = val; } memset(m_kernel, 0, 16 * sizeof(QVector4D)); // Normalize the kernel for (int i = 0; i < kernelSize; i++) { const float val = values[i] / sum; m_kernel[i] = QVector4D(val, val, val, val); } *size = kernelSize; }
static inline QVector4D qt_sRGB_to_linear_RGB(const QVector4D &color) { return QVector4D(qt_sRGB_to_linear_RGB(color.x()), qt_sRGB_to_linear_RGB(color.y()), qt_sRGB_to_linear_RGB(color.z()), color.w()); }
QVector3D myCam::getPositionFromViewMatrix(QMatrix4x4 matrix) { QMatrix4x4 viewRot = matrix; viewRot.setColumn(3, QVector4D(0,0,0,1)); QVector4D p = -(viewRot.transposed() * matrix.column(3)); return QVector3D(p.x(), p.y(), p.z()); }
/*! \class Qt3D::QDiffuseSpecularMapMaterialPrivate \internal */ QDiffuseSpecularMapMaterialPrivate::QDiffuseSpecularMapMaterialPrivate() : QMaterialPrivate() , m_diffuseSpecularMapEffect(new QEffect()) , m_diffuseTexture(new QTexture2D()) , m_specularTexture(new QTexture2D()) , m_ambientParameter(new QParameter(QStringLiteral("ka"), QColor::fromRgbF(0.05f, 0.05f, 0.05f, 1.0f))) , m_diffuseParameter(new QParameter(QStringLiteral("diffuseTexture"), m_diffuseTexture)) , m_specularParameter(new QParameter(QStringLiteral("specularTexture"), m_specularTexture)) , m_shininessParameter(new QParameter(QStringLiteral("shininess"), 150.0f)) , m_lightPositionParameter(new QParameter(QStringLiteral("lightPosition"), QVector4D(1.0f, 1.0f, 0.0f, 1.0f))) , m_lightIntensityParameter(new QParameter(QStringLiteral("lightIntensity"), QVector3D(1.0f, 1.0f, 1.0f))) , m_textureScaleParameter(new QParameter(QStringLiteral("texCoordScale"), 1.0f)) , m_diffuseSpecularMapGL3Technique(new QTechnique()) , m_diffuseSpecularMapGL2Technique(new QTechnique()) , m_diffuseSpecularMapES2Technique(new QTechnique()) , m_diffuseSpecularMapGL3RenderPass(new QRenderPass()) , m_diffuseSpecularMapGL2RenderPass(new QRenderPass()) , m_diffuseSpecularMapES2RenderPass(new QRenderPass()) , m_diffuseSpecularMapGL3Shader(new QShaderProgram()) , m_diffuseSpecularMapGL2ES2Shader(new QShaderProgram()) { m_diffuseTexture->setMagnificationFilter(QAbstractTextureProvider::Linear); m_diffuseTexture->setMinificationFilter(QAbstractTextureProvider::LinearMipMapLinear); m_diffuseTexture->setWrapMode(QTextureWrapMode(QTextureWrapMode::Repeat)); m_diffuseTexture->setGenerateMipMaps(true); m_diffuseTexture->setMaximumAnisotropy(16.0f); m_specularTexture->setMagnificationFilter(QAbstractTextureProvider::Linear); m_specularTexture->setMinificationFilter(QAbstractTextureProvider::LinearMipMapLinear); m_specularTexture->setWrapMode(QTextureWrapMode(QTextureWrapMode::Repeat)); m_specularTexture->setGenerateMipMaps(true); m_specularTexture->setMaximumAnisotropy(16.0f); }
void FogScene::render() { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); QOpenGLShaderProgramPtr shader = m_torus->material()->shader(); shader->bind(); // Set the fog parameters shader->setUniformValue( "fog.color", QVector3D( 1.0f, 1.0f, 1.0f ) ); shader->setUniformValue( "fog.minDistance", 10.0f ); shader->setUniformValue( "fog.maxDistance", 50.0f ); // Set the lighting parameters shader->setUniformValue( "light.position", QVector4D( 0.0f, 0.0f, 0.0f, 1.0f ) ); shader->setUniformValue( "light.intensity", QVector3D( 0.8f, 0.8f, 0.8f ) ); // Set the material properties shader->setUniformValue( "material.kd", QVector3D( 0.9f, 0.5f, 0.3f ) ); shader->setUniformValue( "material.ks", QVector3D( 0.5f, 0.5f, 0.5f ) ); shader->setUniformValue( "material.ka", QVector3D( 0.2f, 0.2f, 0.2f ) ); shader->setUniformValue( "material.shininess", 10.0f ); // Draw torus for ( int i = 0; i < 10; ++i ) { // Calculate needed matrices m_modelMatrix.setToIdentity(); m_modelMatrix.translate( 0.0f, 0.0f, -4.0f * float( i ) ); m_camera->setStandardUniforms( shader, m_modelMatrix ); // Draw torus m_torus->render(); } }
//------------------------------------------------------------------------------ void CModel::render(const SSceneObject *sceneObject) const { if((!sceneObject) || (sceneObject->meshes.size() != model.meshes.size())) return; auto soMesh = sceneObject->meshes.constBegin(); for(int32 i = 0; i < model.meshes.size(); i++, soMesh++) { const SMesh *mesh = &model.meshes[i]; uint32 faceStart = 0; for(int32 j = 0; j < mesh->faces.size(); j++) { const SFaces *faces = &mesh->faces[j]; uint32 facesCount = faces->faces.size(); const SCamera *c =context->getCamera()->getCamera(); soMesh->mvp = c->viewProjection * soMesh->mw; soMesh->cam = c->position.toVector3D() * QVector3D(-1.0, 1.0, -1.0); soMesh->fbSize = QVector4D(c->width, c->height, 1.0f / c->width, 1.0f / c->height); context->getRenderer()->addMesh(SRenderMesh(mesh->vboVertices, mesh->vboIndices, faceStart, facesCount, &(*soMesh), mesh->faces[j].material)); faceStart += facesCount; } } }
void QSGDistanceFieldStyledTextMaterial::setStyleColor(const QColor &color) { m_styleColor = QVector4D(color.redF() * color.alphaF(), color.greenF() * color.alphaF(), color.blueF() * color.alphaF(), color.alphaF()); }
void GeometryEngine::drawLineGeometry(QOpenGLShaderProgram *program) { arrayBufLines.bind(); // Tell OpenGL programmable pipeline how to locate vertex position data int vertexLocation = program->attributeLocation("a_position"); program->enableAttributeArray(vertexLocation); program->setAttributeBuffer(vertexLocation, GL_FLOAT, 0, 3, sizeof(QVector3D)); /*if (isTransparent) { glEnable (GL_BLEND); } else { glDisable(GL_BLEND); }*/ // lines and line color program->setUniformValue("wireframe", true); program->setUniformValue("wire_color", QVector4D(0,1,0,1)); // draw lines int count = (int)arrayBufLines.size() / sizeof(QVector3D); for (int i = 0; i < count; i += 2) glDrawArrays(GL_LINES, i, 2); // turn off the custom coloring program->setUniformValue("wireframe", false); }
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); }
void checkSelfAddition() { QFETCH(float, xO); QFETCH(float, yO); QFETCH(float, zO); QFETCH(float, wO); QFETCH(float, xA); QFETCH(float, yA); QFETCH(float, zA); QFETCH(float, wA); QFETCH(float, xR); QFETCH(float, yR); QFETCH(float, zR); QFETCH(float, wR); // GIVEN QVector4D vo(xO, yO, zO, wO); // WHEN vo += QVector4D(xA, yA, zA, wA); // THEN QCOMPARE(vo.x(), xR); QCOMPARE(vo.y(), yR); QCOMPARE(vo.z(), zR); QCOMPARE(vo.w(), wR); }
QVector3D RenderState::mouse_raycast(int mx, int my, QMatrix4x4 view_matrix) { float nx = (2.0f * mx) / this->width() - 1.0f; // normalize the x-mouse position float ny = 1.0f - (2.0f * my) / this->height();// normalize the y-mouse position QVector4D ray_clip = QVector4D(nx, ny, -1, 1.0); // clip the x,y,z values between -1:1 QMatrix4x4 pInverse =this->projection_matrix.inverted(NULL);// invert the projection QMatrix4x4 vInverse = view_matrix.inverted(NULL);// invert the view QVector4D ray_eye = pInverse*ray_clip; // "convert" the normalized ray to the projection values ray_eye = QVector4D(ray_eye.x(),ray_eye.y(),-1.0,0);// change the w-value of the vector for matrix manipulation purposes QVector4D ray_wor4 = vInverse * ray_eye; // "convert" the new ray to the view values QVector3D ray_wor = ray_wor4.toVector3D(); // take the x,y,z values of the new position ray_wor.normalize();// make the ray a unit vector return ray_wor; // return the raycast of the 2D mouse in the 3D world view projection }
void AdaptiveGrid::update( const QVector3D & viewpoint , const QMatrix4x4 & modelViewProjection) { // Project the camera's eye position onto the grid plane. bool intersects; // should always intersect. const QVector3D i = intersection(intersects, m_location, m_normal , viewpoint, viewpoint - m_normal); // This transforms the horizontal plane vectors u and v onto the actual // grid plane. Than express the intersection i as a linear combination of // u and v by solving the linear equation system. // Finally round the s and t values to get the nearest major grid point. const float l = (viewpoint - i).length(); const float distancelog = log(l * .4998f) / log(8.f); const float distance = pow(8.f, ceil(distancelog)); QMatrix4x4 T; // ToDo const QVector3D uv(QVector3D(T * QVector4D(distance, 0.f, 0.f, 1.f)) - m_location); const float u[3] = { uv.x(), uv.y(), uv.z() }; const QVector3D vv(QVector3D(T * QVector4D(0.f, 0.f, distance, 1.f)) - m_location); const float v[3] = { vv.x(), vv.y(), vv.z() }; const size_t j = u[0] != 0.0 ? 0 : u[1] != 0.0 ? 1 : 2; const size_t k = v[0] != 0.0 && j != 0 ? 0 : v[1] != 0.0 && j != 1 ? 1 : 2; const QVector3D av(i - m_location); const float a[3] = { av.x(), av.y(), av.z() }; const float t = v[k] ? a[k] / v[k] : 0.f; const float s = u[j] ? (a[j] - t * v[j]) / u[j] : 0.f; const QVector3D irounded = round(s) * uv + round(t) * vv; QMatrix4x4 offset; offset.translate(irounded); offset.scale(distance); m_program->bind(); m_program->setUniformValue("viewPlaneDistance", QVector2D(l, mod(distancelog, 1.f))); m_program->setUniformValue("transform", modelViewProjection * offset); m_program->release(); }
void Rotate (QVector<Vertex>& incomeCoords, float angle, QVector3D os ){ QMatrix4x4 rot; rot.rotate(angle, os); for (int i = 0; i < incomeCoords.length(); i++){ QVector4D coords = QVector4D( incomeCoords[i].X, incomeCoords[i].Y, incomeCoords[i].Z, 1.0 ); coords = coords * rot; incomeCoords[i] = Vertex(coords[0] / coords[3], coords[1] / coords[3], coords[2] / coords[3]); } }
// ____________drawing____________ QVector<QVector2D> From3DTo2D (const QVector<QVector3D> Input3D, const QMatrix4x4 view, const QMatrix4x4 perspective){ QVector<QVector2D> resultPoints = {}; for (int curPoint = 0; curPoint < Input3D.length(); curPoint++){ QVector4D temp = QVector4D(Input3D[curPoint].x(), Input3D[curPoint].y(), Input3D[curPoint].z(), 1.0); temp = temp * view * perspective; resultPoints << QVector2D(temp.x() / temp.w(), temp.y() / temp.w()); } return resultPoints; }