QMatrix4x4 EditData::getNowSelectMatrix() { QModelIndex index = getSelIndex(); if (!getObjectModel()->isLayer(index)) { return QMatrix4x4(); } int frame = getSelectFrame(); ObjectItem *pItem = getObjectModel()->getItemFromIndex(index); return pItem->getDisplayMatrix(frame); }
// ColorRangeRGB(...)* static QMatrix4x4 ColorRangeRGB(ColorRange from, ColorRange to) { if (from == to) return QMatrix4x4(); static const qreal R2 = 235, R1 = 16; static const qreal s = 255; if (to == ColorRange_Limited) { qDebug("output rgb limited range"); QMatrix4x4 m; m.translate(R1/s, R1/s, R1/s); m.scale((R2 - R1)/s, (R2 - R1)/s, (R2 - R1)/s); return m; } if (to == ColorRange_Full) { // TODO: Unknown QMatrix4x4 m; m.scale(s/(R2 - R1), s/(R2 - R1), s/(R2 - R1)); m.translate(-s/R1, -s/R1, -s/R1); return m; } return QMatrix4x4(); }
static QMatrix4x4 matrix4x4FromString(const QString &s, bool *ok) { if (s.count(QLatin1Char(',')) == 15) { float matValues[16]; bool vOK = true; QStringRef mutableStr(&s); for (int i = 0; vOK && i < 16; ++i) { int cidx = mutableStr.indexOf(QLatin1Char(',')); matValues[i] = mutableStr.left(cidx).toDouble(&vOK); mutableStr = mutableStr.mid(cidx + 1); } if (vOK) { if (ok) *ok = true; return QMatrix4x4(matValues); } } if (ok) *ok = false; return QMatrix4x4(); }
void tst_QMatrix4x4::multiply_data() { QTest::addColumn<QMatrix4x4>("m1"); QTest::addColumn<QMatrix4x4>("m2"); QTest::newRow("identity * identity") << QMatrix4x4() << QMatrix4x4(); QTest::newRow("identity * general") << QMatrix4x4() << QMatrix4x4(generalValues); QTest::newRow("general * identity") << QMatrix4x4(generalValues) << QMatrix4x4(); QTest::newRow("general * general") << QMatrix4x4(generalValues) << QMatrix4x4(generalValues); }
/******************************************************* * void vAxisRotMatrix(float fVecX, float fVecY, float fVecZ, Matrix mNewMat) * * Calculate the rotation matrix for rotation about an arbitrary axis. * * The axis of rotation is specified by (fVecX,fVecY,fVecZ). The length * of the vector is the amount to rotate by. * * Parameters: fVecX,fVecY,fVecZ - Axis of rotation * mNewMat - Output matrix of rotation in column-major format * (ie, translation components are in column 3 on rows * 0,1, and 2). * *******************************************************/ void vAxisRotMatrix(float fVecX, float fVecY, float fVecZ, QMatrix4x4 &mNewMat) { float fRadians, fInvLength, fNewVecX, fNewVecY, fNewVecZ; /* Find the length of the vector which is the angle of rotation * (in radians) */ fRadians = sqrt(fVecX * fVecX + fVecY * fVecY + fVecZ * fVecZ); /* If the vector has zero length - return the identity matrix */ if (fRadians > -0.000001 && fRadians < 0.000001) { // vCopyMatrix(mIdentity, mNewMat); return; } /* Normalize the rotation vector now in preparation for making * rotation matrix. */ fInvLength = 1 / fRadians; fNewVecX = fVecX * fInvLength; fNewVecY = fVecY * fInvLength; fNewVecZ = fVecZ * fInvLength; /* Create the arbitrary axis rotation matrix */ double dSinAlpha = sin(fRadians); double dCosAlpha = cos(fRadians); double dT = 1 - dCosAlpha; // mNewMat[0][0] = dCosAlpha + fNewVecX*fNewVecX*dT; // mNewMat[0][1] = fNewVecX*fNewVecY*dT + fNewVecZ*dSinAlpha; // mNewMat[0][2] = fNewVecX*fNewVecZ*dT - fNewVecY*dSinAlpha; // mNewMat[0][3] = 0; // mNewMat[1][0] = fNewVecX*fNewVecY*dT - dSinAlpha*fNewVecZ; // mNewMat[1][1] = dCosAlpha + fNewVecY*fNewVecY*dT; // mNewMat[1][2] = fNewVecY*fNewVecZ*dT + dSinAlpha*fNewVecX; // mNewMat[1][3] = 0; // mNewMat[2][0] = fNewVecZ*fNewVecX*dT + dSinAlpha*fNewVecY; // mNewMat[2][1] = fNewVecZ*fNewVecY*dT - dSinAlpha*fNewVecX; // mNewMat[2][2] = dCosAlpha + fNewVecZ*fNewVecZ*dT; // mNewMat[2][3] = 0; // mNewMat[3][0] = 0; // mNewMat[3][1] = 0; // mNewMat[3][2] = 0; // mNewMat[3][3] = 1; mNewMat = QMatrix4x4(dCosAlpha + fNewVecX*fNewVecX*dT, fNewVecX*fNewVecY*dT + fNewVecZ*dSinAlpha, fNewVecX*fNewVecZ*dT - fNewVecY*dSinAlpha, 0, fNewVecX*fNewVecY*dT - dSinAlpha*fNewVecZ, dCosAlpha + fNewVecY*fNewVecY*dT, fNewVecY*fNewVecZ*dT + dSinAlpha*fNewVecX, 0, fNewVecZ*fNewVecX*dT + dSinAlpha*fNewVecY, fNewVecZ*fNewVecY*dT - dSinAlpha*fNewVecX, dCosAlpha + fNewVecZ*fNewVecZ*dT, 0, 0,0,0,1); }
bool KisTransformUtils::checkImageTooBig(const QRectF &bounds, const MatricesPack &m) { bool imageTooBig = false; QMatrix4x4 unprojectedMatrix = QMatrix4x4(m.T) * m.P * QMatrix4x4(m.TS * m.SC * m.S); QVector<QPointF> points; points << bounds.topLeft(); points << bounds.topRight(); points << bounds.bottomRight(); points << bounds.bottomLeft(); foreach (const QPointF &pt, points) { QVector4D v(pt.x(), pt.y(), 0, 1); v = unprojectedMatrix * v; qreal z = v.z() / v.w(); imageTooBig = z > 1024.0; if (imageTooBig) { break; } }
void tst_QMatrix4x4::mapVector3D_data() { QTest::addColumn<QMatrix4x4>("m1"); QTest::newRow("identity") << QMatrix4x4(); QTest::newRow("general") << QMatrix4x4(generalValues); QMatrix4x4 t1; t1.translate(-100.5f, 64.0f, 75.25f); QTest::newRow("translate3D") << t1; QMatrix4x4 t2; t2.translate(-100.5f, 64.0f); QTest::newRow("translate2D") << t2; QMatrix4x4 s1; s1.scale(-100.5f, 64.0f, 75.25f); QTest::newRow("scale3D") << s1; QMatrix4x4 s2; s2.scale(-100.5f, 64.0f); QTest::newRow("scale2D") << s2; }
void GLWidgetSimpleShadow::updateShadowMatrix(GLWidget3D* glWidget3D){ QVector3D light_dir(-0.40f, 0.81f, -0.51f); ////////////////////////////////////////////////////// float fov = 45.0f; float aspect = (float)shadowWidth / (float)shadowHeight; float zfar = 15000.0f;//3800.0 float znear = 7000.0f;//1500.0 float f = 1.0f / tanf(fov * (M_PI / 360.0)); double m[16] = { f/aspect, 0, 0, 0, 0, f, 0, 0, 0, 0, (zfar+znear)/(znear-zfar), (2.0f*zfar*znear)/(znear-zfar), 0, 0, -1, 0 }; light_pMatrix=QMatrix4x4(m); // BIAS MATRIX light_biasMatrix.setToIdentity(); light_biasMatrix.scale(0.5f); light_biasMatrix.translate(0.5f,0.5f,0.5f); // UNIFORMS LOC light_mvpMatrixLoc= glGetUniformLocation(programId, "light_mvpMatrix"); light_biasMatrixLoc= glGetUniformLocation(programId, "light_biasMatrix"); light_dirLoc= glGetUniformLocation(programId, "lightDir"); //printf("LOC lights %d %d %d\n",light_mvpMatrixLoc,light_biasMatrixLoc,light_dirLoc); // UPDATE MATRIX light_mvMatrix.setToIdentity(); light_mvMatrix.lookAt(-light_dir*10000,//2500 light_dir.normalized(),//QVector3D(-0.60f,0.55,-0.6), QVector3D(0.0f, 0.0f, 1.0f)); light_mvpMatrix=light_pMatrix*light_mvMatrix; /////////////////////////////////////////////////////// float light_mvpMatrixArray[16]; float light_biasMatrixArray[16]; for(int i=0;i<16;i++){ light_mvpMatrixArray[i]=light_mvpMatrix.data()[i]; light_biasMatrixArray[i]=light_biasMatrix.data()[i]; } glUniformMatrix4fv(light_mvpMatrixLoc,1,GL_FALSE,light_mvpMatrixArray); glUniformMatrix4fv(light_biasMatrixLoc,1,GL_FALSE,light_biasMatrixArray); glUniform3f(light_dirLoc,light_dir.x(),light_dir.y(),light_dir.z()); }//
void Viewport3D::refocus(const boost::optional<Coordinate> position) { const auto pos = position ? position.get() : state->viewerState->currentPosition; const auto scaledPos = Dataset::current().scales[0].componentMul(pos); translateX = scaledPos.x; translateY = scaledPos.y; glMatrixMode(GL_MODELVIEW); glLoadMatrixf(QMatrix4x4().data()); glTranslatef(scaledPos.x, scaledPos.y, scaledPos.z); std::array<float, 16> rotationState; rotation.copyDataTo(rotationState.data()); // transforms to row-major matrix glMultMatrixf(rotationState.data()); glTranslatef(-scaledPos.x, -scaledPos.y, -scaledPos.z); glGetFloatv(GL_MODELVIEW_MATRIX, state->skeletonState->skeletonVpModelView); }
QT_BEGIN_NAMESPACE // #define QSG_UPDATER_DEBUG QSGNodeUpdater::QSGNodeUpdater() : m_matrix_stack(64) , m_combined_matrix_stack(64) , m_opacity_stack(64) , m_current_clip(0) , m_force_update(0) { m_opacity_stack.add(1); m_matrix_stack.add(QMatrix4x4()); }
void GlPainter::initColorMatrix() { _colorMatrix = QMatrix4x4(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0); QMatrix4x4 colorSpaceMatrix; if (_frame->height > 576) colorSpaceMatrix = QMatrix4x4( 1.164383561643836, 0.000000000000000, 1.792741071428571, -0.972945075016308, 1.164383561643836, -0.213248614273730, -0.532909328559444, 0.301482665475862, 1.164383561643836, 2.112401785714286, 0.000000000000000, -1.133402217873451, 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000); else colorSpaceMatrix = QMatrix4x4( 1.164383561643836, 0.000000000000000, 1.596026785714286, -0.874202217873451, 1.164383561643836, -0.391762290094914, -0.812967647237771, 0.531667823499146, 1.164383561643836, 2.017232142857142, 0.000000000000000, -1.085630789302022, 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000); _colorMatrix = _colorMatrix * colorSpaceMatrix; }
// For yuv->rgb, assume yuv is full range before convertion, rgb is full range after convertion. so if input yuv is limited range, transform to full range first. If display rgb is limited range, transform to limited range at last. // *ColorRangeYUV(...) static QMatrix4x4 ColorRangeYUV(ColorRange from, ColorRange to) { if (from == to) return QMatrix4x4(); static const qreal Y2 = 235, Y1 = 16, C2 = 240, C1 = 16; static const qreal s = 255; //TODO: can be others if (from == ColorRange_Limited) { //TODO: Unknown. But what if realy want unknown? qDebug("input yuv limited range"); // [Y1, Y2] => [0, s] QMatrix4x4 m; m.scale(s/(Y2 - Y1), s/(C2 - C1), s/(C2 - C1)); m.translate(-Y1/s, -C1/s, -C1/s); return m; } if (from == ColorRange_Full) { // [0, s] => [Y1, Y2] QMatrix4x4 m; m.translate(Y1/s, C1/s, C1/s); m.scale((Y2 - Y1)/s, (C2 - C1)/s, (C2 - C1)/s); return m; } // ColorRange_Unknown return QMatrix4x4(); }
static QMatrix4x4 matrix4x4FromObject(QQmlV4Handle object, QV4::ExecutionEngine *v4, bool *ok) { if (ok) *ok = false; QV4::Scope scope(v4); QV4::ScopedArrayObject array(scope, object); if (!array) return QMatrix4x4(); if (array->getLength() != 16) return QMatrix4x4(); float matVals[16]; QV4::ScopedValue v(scope); for (quint32 i = 0; i < 16; ++i) { v = array->getIndexed(i); if (!v->isNumber()) return QMatrix4x4(); matVals[i] = v->asDouble(); } if (ok) *ok = true; return QMatrix4x4(matVals); }
QVector<Vertex> MainWindow::vertexCloud( QVector<unsigned int>& triangleVertexIndexes){ // first time loading if (cloud.length() == 0) if (!loadModelByAdress("../Models/teapot.txt", sc).isEmpty()) return {}; QVector<Vertex> res = sc.vertexes; Vertex up(cameraProps[2].X - cameraProps[0].X, cameraProps[2].Y - cameraProps[0].Y, cameraProps[2].Z - cameraProps[0].Z); Vertex left(cameraProps[3].X - cameraProps[0].X, cameraProps[3].Y - cameraProps[0].Y, cameraProps[3].Z - cameraProps[0].Z); Vertex forward( cameraProps[0].X - cameraProps[1].X, cameraProps[0].Y - cameraProps[1].Y, cameraProps[0].Z - cameraProps[1].Z ); // creating a view matrix QMatrix4x4 viewMatrix = QMatrix4x4 (left.X, up.X, forward.X, 0, left.Y, up.Y, forward.Y, 0, left.Z, up.Z, forward.Z, 0, -left.X * cameraProps[0].X - left.Y * cameraProps[0].Y - left.Z * cameraProps[0].Z, -up.X * cameraProps[0].X - up.Y * cameraProps[0].Y - up.Z * cameraProps[0].Z, -forward.X * cameraProps[0].X - forward.Y * cameraProps[0].Y - forward.Z * cameraProps[0].Z, 1), perspectiveMatrix = QMatrix4x4(); perspectiveMatrix.frustum(-10, 10, -10, 10, 20, 200); traceMatrix(viewMatrix); traceMatrix(perspectiveMatrix); for (int i = 0; i< res.length(); i++){ QVector4D pointCoordinations(res[i].X , res[i].Y, res[i].Z, 1.0); pointCoordinations = pointCoordinations * viewMatrix * perspectiveMatrix; res[i] = Vertex(pointCoordinations[0], pointCoordinations[1], pointCoordinations[2]); } triangleVertexIndexes = sc.polygon_vertex_indexes; return res; }
GeometryData* hexPin(int subdivisions, float pinRadius) { GeometryData* geom = new GeometryData(); geom->setShaderOverride(PerVertexColorShader::staticName()); geom->setDataFormat(GeometryData::PositionNormalColor); appendPin(subdivisions, pinRadius, 1.0f, QColor::fromRgb(0xffff0000), geom, QMatrix4x4()); appendPin(subdivisions, pinRadius, 1.0f, QColor::fromRgb(0xffff0000), geom, Math::matrixRotateZ(qDegreesToRadians(180.0f))); appendPin(subdivisions, pinRadius, 1.0f, QColor::fromRgb(0xff00ff00), geom, Math::matrixRotateZ(qDegreesToRadians(90.0f))); appendPin(subdivisions, pinRadius, 1.0f, QColor::fromRgb(0xff00ff00), geom, Math::matrixRotateZ(qDegreesToRadians(-90.0f))); appendPin(subdivisions, pinRadius, 1.0f, QColor::fromRgb(0xff0000ff), geom, Math::matrixRotateY(qDegreesToRadians(90.0f))); appendPin(subdivisions, pinRadius, 1.0f, QColor::fromRgb(0xff0000ff), geom, Math::matrixRotateY(qDegreesToRadians(-90.0f))); return geom; }
/** * Set light direction. */ void GLESRenderer::setLightDirection(const QVector3D & newVal) { lightDirection = newVal; #ifdef DEBUG_GLESRENDERER ShaderDebugger::debugVector3D(lightDirection, "GLESRenderer uses lightDirection in object space:"); #endif QMatrix4x4 nMatrix = QMatrix4x4(normalMatrix); lightDirection = (nMatrix * lightDirection);//transform to eye space halfPlaneVector = (lightDirection + QVector3D(0.0,0.0,1.0)).normalized();//eye direction is 0,0,1 in eye space #ifdef DEBUG_GLESRENDERER ShaderDebugger::debugVector3D(lightDirection, "GLESRenderer uses lightDirection in eye space:"); ShaderDebugger::debugVector3D(lightDirection, "GLESRenderer uses halfplane vector in eye space:"); #endif if(bound && (location_uLightDirection != -1)) setUniformValue(location_uLightDirection, lightDirection); if(location_uHalfPlaneVector != -1) setUniformValue(location_uHalfPlaneVector, halfPlaneVector); }
static QMatrix4x4 channelMap(const VideoFormat& fmt) { if (fmt.isPlanar()) //currently only for planar return QMatrix4x4(); switch (fmt.pixelFormat()) { case VideoFormat::Format_UYVY: return QMatrix4x4(0.0f, 0.5f, 0.0f, 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); case VideoFormat::Format_YUYV: return QMatrix4x4(0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f); case VideoFormat::Format_VYUY: return QMatrix4x4(0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); case VideoFormat::Format_YVYU: return QMatrix4x4(0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); case VideoFormat::Format_VYU: return QMatrix4x4(0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); default: break; } const quint8 *channels = NULL;//{ 0, 1, 2, 3}; for (int i = 0; gl_channel_maps[i].pixfmt != VideoFormat::Format_Invalid; ++i) { if (gl_channel_maps[i].pixfmt == fmt.pixelFormat()) { channels = gl_channel_maps[i].channels; break; } } QMatrix4x4 m; if (!channels) return m; m.fill(0); for (int i = 0; i < 4; ++i) { m(i, channels[i]) = 1; } qDebug() << m; return m; }
KisTransformUtils::MatricesPack::MatricesPack(const ToolTransformArgs &args) { TS = QTransform::fromTranslate(-args.originalCenter().x(), -args.originalCenter().y()); SC = QTransform::fromScale(args.scaleX(), args.scaleY()); S.shear(0, args.shearY()); S.shear(args.shearX(), 0); if (args.mode() == ToolTransformArgs::FREE_TRANSFORM) { P.rotate(180. * args.aX() / M_PI, QVector3D(1, 0, 0)); P.rotate(180. * args.aY() / M_PI, QVector3D(0, 1, 0)); P.rotate(180. * args.aZ() / M_PI, QVector3D(0, 0, 1)); projectedP = P.toTransform(args.cameraPos().z()); } else if (args.mode() == ToolTransformArgs::PERSPECTIVE_4POINT) { projectedP = args.flattenedPerspectiveTransform(); P = QMatrix4x4(projectedP); } QPointF translation = args.transformedCenter(); T = QTransform::fromTranslate(translation.x(), translation.y()); }
Exercise20::Exercise20(QWidget * parent) : AbstractGLExercise(parent) , m_drawable(NULL) , m_he(NULL) , m_shadingMode(Phong_Shading) , m_materialMode(Gold) { m_view = QMatrix4x4(); m_view.lookAt( QVector3D( 0.f, 1.f, 4.f) , QVector3D( 0.f, 0.f, 0.f) , QVector3D( 0.f, 1.f, 0.f)); m_prog_toon = new QGLShaderProgram; m_prog_phong = new QGLShaderProgram; setupLight(); setupMaterials(); }
QMatrix4x4 Quat4::matrix() { // I'm being lazy here. Eventually transpose it by hand... float w = scalar(); return QMatrix4x4(1.0f - 2.0f * ( y() * y() + z() * z() ), 2.0f * (x() * y() + z() * w), 2.0f * (x() * z() - y() * w), 0.0f, 2.0f * ( x() * y() - z() * w ), 1.0f - 2.0f * ( x() * x() + z() * z() ), 2.0f * (z() * y() + x() * w ), 0.0f, 2.0f * ( x() * z() + y() * w ), 2.0f * ( y() * z() - x() * w ), 1.0f - 2.0f * ( x() * x() + y() * y() ), 0.0f, 0, 0, 0, 1.0f).transposed(); }
static QVector3D unproject( QVector3D v, const QMatrix4x4 &modelView, const QMatrix4x4 &projection, QRect viewport ) { // Reimplementation of QVector3D::unproject() - see qtbase/src/gui/math3d/qvector3d.cpp // The only difference is that the original implementation uses tolerance 1e-5 // (see qFuzzyIsNull()) as a protection against division by zero. For us it is however // common to get lower values (e.g. as low as 1e-8 when zoomed out to the whole Earth with web mercator). QMatrix4x4 inverse = QMatrix4x4( projection * modelView ).inverted(); QVector4D tmp( v, 1.0f ); tmp.setX( ( tmp.x() - float( viewport.x() ) ) / float( viewport.width() ) ); tmp.setY( ( tmp.y() - float( viewport.y() ) ) / float( viewport.height() ) ); tmp = tmp * 2.0f - QVector4D( 1.0f, 1.0f, 1.0f, 1.0f ); QVector4D obj = inverse * tmp; if ( qgsDoubleNear( obj.w(), 0, 1e-10 ) ) obj.setW( 1.0f ); obj /= obj.w(); return obj.toVector3D(); }
const Matrix4d& Light::getProjection(double aspect, int projection_nb) { Matrix4d mat; if(m_type == SUN) { computePSSM(mat, projection_nb); } else { computeLightFrustum(mat); if(m_type == OMNI) { switch(projection_nb) { case 0: mat *= Matrix4d(negx); break; case 1: mat *= Matrix4d(posx); break; case 2: mat *= Matrix4d(negy); break; case 3: mat *= Matrix4d(posy); break; case 4: mat *= Matrix4d(negz); break; case 5: mat *= Matrix4d(posz); break; } } } debug("MATRIX_STACK", "get projection" << QMatrix4x4(mat.values)); return mat; }
QMatrix4x4 iPolacion::getMatrizRotacion(QVector4D q){ QMatrix4x4 m = QMatrix4x4((1-(2*((q.y()*q.y())+(q.z()*q.z())))), ((2*q.x()*q.y())-(2*q.w()*q.z())), ((2*q.w()*q.y())+(2*q.x()*q.z())), 0 , ((2*q.x()*q.y())+(2*q.w()*q.z())), (1-(2*((q.x()*q.x())+(q.z()*q.z())))), ((-2*q.w()*q.x())+(2*q.y()*q.z())), 0 , ((-2*q.w()*q.y())+(2*q.x()*q.z())), ((2*q.w()*q.x())+(2*q.y()*q.z())), (1-(2*((q.x()*q.x())+(q.y()*q.y())))), 0 , 0,0,0,1); return m; }
void QSGNodeUpdater::enterTransformNode(QSGTransformNode *t) { #ifdef QSG_UPDATER_DEBUG qDebug() << "enter transform:" << t << "force=" << m_force_update; #endif if (!t->matrix().isIdentity()) { if (!m_combined_matrix_stack.isEmpty()) { t->setCombinedMatrix(*m_combined_matrix_stack.last() * t->matrix()); } else { t->setCombinedMatrix(t->matrix()); } m_combined_matrix_stack.add(&t->combinedMatrix()); } else { if (!m_combined_matrix_stack.isEmpty()) { t->setCombinedMatrix(*m_combined_matrix_stack.last()); } else { t->setCombinedMatrix(QMatrix4x4()); } } }
void Light::computePSSM(Matrix4d& mat, int split_nb) const { // Get viewprojection matrix Viewpoint* targetVp = RENDER_MANAGER.getRenderPassInfo()->lod_viewpoint; #ifdef MERGEFORSUN Matrix4d VpMat = targetVp->getViewProjection(1,0); debug("MATRIX_STACK", "compute PSSM" << QMatrix4x4(VpMat.values)); #else Matrix4d VpMat = targetVp->getProjection(1,0); #endif // Compute subfrustum mat = VpMat; // Compute matrix targetting subfrustum /* const float w = 0.001; const float h = 0.001; const float d = 0.0026; mat[0] = 0; mat[1] = 0; mat[2] = -d; mat[3] = 0; mat[4] = 0; mat[5] = h; mat[6] = 0; mat[7] = 0; mat[8] = w; mat[9] = 0; mat[10] = 0; mat[11] = 0; mat[12] = 0; mat[13] = 0; mat[14] = -1; mat[15] = 1; */ }
void OpenGLWidget::paintGL() { if(!m_glFuncs) { return; } m_shaderProgram.bind(); m_vertexArray.bind(); m_texture.bind(); static const QVector3D cameraUp(0.0f, 1.0f, 0.0f); QVector3D cameraRight = QVector3D::crossProduct(m_cameraFront, cameraUp).normalized(); m_cameraPosition += m_forwardSpeed * 50 / 1000 * m_cameraFront; m_cameraPosition += m_strafeSpeed * 50 / 1000 * cameraRight; m_cameraPosition += m_upSpeed * 50 / 1000 * cameraUp; QMatrix4x4 viewMatrix; viewMatrix.lookAt(m_cameraPosition, m_cameraPosition + m_cameraFront, cameraUp); QMatrix4x4 projectionMatrix; projectionMatrix.perspective(45.0f, float(width()) / height(), 0.1f, 100.0f); m_shaderProgram.setUniformValue("viewMatrix", viewMatrix); m_shaderProgram.setUniformValue("projectionMatrix", projectionMatrix); m_glFuncs->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(!m_chunkMesh.isEmpty()) { m_shaderProgram.setUniformValue("modelMatrix", QMatrix4x4()); m_glFuncs->glDrawElements(GL_TRIANGLES, m_chunkMesh.getNumberOfElements(), GL_UNSIGNED_INT, 0); } m_texture.release(); m_vertexArray.release(); m_shaderProgram.release(); }
void RenderState::draw_line(QVector3D point1, QVector3D point2, QMatrix4x4 world_view_projection, QMatrix4x4 model_view_projection, QVector3D color) { QVector< QVector3D > temp_vertices; temp_vertices.push_back(point1); temp_vertices.push_back(point2); this->update_shaders(world_view_projection, model_view_projection, QMatrix4x4(), color); const char *vert ="vertex";// convert the qstring to c-string for opengl purposes const char *normals = "normal";// convert the qstring to c-string for opengl purposes this->shader_program->setAttributeArray(vert, temp_vertices.constData());//load the vertices to the shaders this->shader_program->enableAttributeArray(vert);//enable the shader attribute( vertices ) this->shader_program->setAttributeArray(normals, temp_vertices.constData());//load the normals to the shaders this->shader_program->enableAttributeArray(normals);//enable the shader attribute( vertices ) glLineWidth(1.0); glDrawArrays(GL_LINES, 0, temp_vertices.size()); this->shader_program->disableAttributeArray(vert);// disable the vertex attributes this->shader_program->disableAttributeArray(normals);// disable the normal attributes this->shader_program->release(); // release the current updated shader code (awaiting next frame) temp_vertices.clear(); }
void Window::hapticRendering() { hlBeginFrame(); hlMaterialf(HL_FRONT_AND_BACK, HL_STIFFNESS, haptic.getStiffness()); hlMaterialf(HL_FRONT_AND_BACK, HL_DAMPING, haptic.getDamping()); hlMaterialf(HL_FRONT_AND_BACK, HL_STATIC_FRICTION, haptic.getStaticFriction()); hlMaterialf(HL_FRONT_AND_BACK, HL_DYNAMIC_FRICTION, haptic.getDynamicFriction()); hlMaterialf(HL_FRONT_AND_BACK, HL_POPTHROUGH, haptic.getPopthroughValue()); hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, haptic.getShapeID()); //vertexArrayObject.bind(); shaderProgram->bind(); shaderProgram->setUniformValue("translateFactor", -1.0f, -1.0f, 0.0f); shaderProgram->setUniformValue("mvp", QMatrix4x4(glm::value_ptr(mvp))); glDrawElements(GL_TRIANGLES, mesh->getNumberOfIndices(), GL_UNSIGNED_INT, 0); //vertexArrayObject.release(); shaderProgram->release(); hlEndShape(); hlEndFrame(); }
void QtCamGraphicsViewfinder::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(widget); Q_UNUSED(option); painter->fillRect(boundingRect(), Qt::black); if (!d_ptr->renderer || !d_ptr->enabled) { return; } bool needsNativePainting = d_ptr->renderer->needsNativePainting(); if (needsNativePainting) { painter->beginNativePainting(); } d_ptr->renderer->paint(QMatrix4x4(painter->combinedTransform()), painter->viewport()); if (needsNativePainting) { painter->endNativePainting(); } }
void ShaderEffectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { if (!m_active) return; const QGLContext *context = QGLContext::currentContext(); if (context) { if (!m_checkedShaderPrograms) { m_hasShaderPrograms = QGLShaderProgram::hasOpenGLShaderPrograms(context); m_checkedShaderPrograms = true; if (!m_hasShaderPrograms) qWarning() << "ShaderEffectItem::paint - Shader programs are not supported"; } if ( !m_hasShaderPrograms ) return; checkViewportUpdateMode(); painter->save(); painter->beginNativePainting(); if (context->format().samples() > 1) painter->setRenderHint(QPainter::Antialiasing); QMatrix4x4 combinedMatrix = QMatrix4x4(painter->transform()); renderEffect(painter, combinedMatrix); painter->endNativePainting(); painter->restore(); } else { if (!m_checkedOpenGL) { qWarning() << "ShaderEffectItem::paint - OpenGL not available"; m_checkedOpenGL = true; } } }