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()); }
void QSGHiQSubPixelDistanceFieldTextMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) { Q_ASSERT(oldEffect == 0 || newEffect->type() == oldEffect->type()); QSGDistanceFieldTextMaterial *material = static_cast<QSGDistanceFieldTextMaterial *>(newEffect); QSGDistanceFieldTextMaterial *oldMaterial = static_cast<QSGDistanceFieldTextMaterial *>(oldEffect); if (oldMaterial == 0 || material->color() != oldMaterial->color()) { QVector4D c = material->color(); state.context()->functions()->glBlendColor(c.x(), c.y(), c.z(), 1.0f); } if (oldMaterial == 0 || material->fontScale() != oldMaterial->fontScale()) program()->setUniformValue(m_fontScale_id, GLfloat(material->fontScale())); if (oldMaterial == 0 || state.isMatrixDirty()) { int viewportWidth = state.viewportRect().width(); QMatrix4x4 mat = state.combinedMatrix().inverted(); program()->setUniformValue(m_vecDelta_id, mat.column(0) * (qreal(2) / viewportWidth)); } QSGDistanceFieldTextMaterialShader::updateState(state, newEffect, oldEffect); }
void OculusRiftNode::render( qint64 pTimeStamp, QUuid pSourcePinId ) { Q_UNUSED( pSourcePinId ) #if !defined( OCULUS_PLUGIN_SUPPORTED ) Q_UNUSED( pTimeStamp ) #else fugio::Performance Perf( mNode, "drawGeometry", pTimeStamp ); if( !mNode->isInitialised() ) { return; } if( !mOculusRift->hmd() ) { return; } // We need to keep a reference to ourselves here as ovr_SubmitFrame can // call the main app event loop, which can close the context and delete us! QSharedPointer<fugio::NodeControlInterface> C = mNode->control(); mOculusRift->drawStart(); const float NearPlane = variant( mPinNearPlane ).toFloat(); const float FarPlane = variant( mPinFarPlane ).toFloat(); // float Yaw(3.141592f); // Vector3f Pos2(0.0f,1.6f,-5.0f); // Pos2.y = ovrHmd_GetFloat(mHMD, OVR_KEY_EYE_HEIGHT, Pos2.y); QMatrix4x4 MatEye = variant( mPinViewMatrix ).value<QMatrix4x4>(); QVector3D TrnEye = MatEye.column( 3 ).toVector3D(); MatEye.setColumn( 3, QVector4D( 0, 0, 0, 1 ) ); const Vector3f Pos2( TrnEye.x(), TrnEye.y(), TrnEye.z() ); Matrix4f tempRollPitchYaw; memcpy( tempRollPitchYaw.M, MatEye.constData(), sizeof( float ) * 16 ); const Matrix4f rollPitchYaw = tempRollPitchYaw; // Render Scene to Eye Buffers for (int eye = 0; eye < 2; eye++) { mOculusRift->drawEyeStart( eye ); // Get view and projection matrices //Matrix4f rollPitchYaw = Matrix4f( MatEye.transposed().data() ); Matrix4f finalRollPitchYaw = rollPitchYaw * Matrix4f( mOculusRift->eyeRenderPos( eye ).Orientation); Vector3f finalUp = finalRollPitchYaw.Transform(Vector3f(0, 1, 0)); Vector3f finalForward = finalRollPitchYaw.Transform(Vector3f(0, 0, -1)); Vector3f shiftedEyePos = Pos2 + rollPitchYaw.Transform( mOculusRift->eyeRenderPos( eye ).Position ); Matrix4f view = Matrix4f::LookAtRH(shiftedEyePos, shiftedEyePos + finalForward, finalUp); Matrix4f proj = ovrMatrix4f_Projection( mOculusRift->defaultEyeFOV( eye ), NearPlane, FarPlane, ovrProjection_None ); mProjection->setVariant( QMatrix4x4( &proj.M[ 0 ][ 0 ], 4, 4 ).transposed() ); mView->setVariant( QMatrix4x4( &view.M[ 0 ][ 0 ], 4, 4 ).transposed() ); fugio::OpenGLStateInterface *CurrentState = 0; for( QSharedPointer<fugio::PinInterface> P : mNode->enumInputPins() ) { if( !P->isConnected() ) { continue; } if( P->connectedPin().isNull() ) { continue; } if( P->connectedPin()->control().isNull() ) { continue; } QObject *O = P->connectedPin()->control()->qobject(); if( !O ) { continue; } if( true ) { fugio::RenderInterface *Geometry = qobject_cast<fugio::RenderInterface *>( O ); if( Geometry ) { Geometry->render( pTimeStamp ); continue; } } if( true ) { fugio::OpenGLStateInterface *NextState = qobject_cast<fugio::OpenGLStateInterface *>( O ); if( NextState != 0 ) { if( CurrentState != 0 ) { CurrentState->stateEnd(); } CurrentState = NextState; CurrentState->stateBegin(); continue; } } } if( CurrentState != 0 ) { CurrentState->stateEnd(); } mOculusRift->drawEyeEnd( eye ); } mOculusRift->drawEnd(); pinUpdated( mPinProjection ); pinUpdated( mPinView ); #endif }
inline QMatrix4x4 matrix( const QMatrix4x4 & modelView ) { QMatrix4x4 bilboard; bilboard.setColumn( 3, modelView.column(3) ); return bilboard; }
void traceMatrix (QMatrix4x4 qm){ for (int i = 0; i < 4; i++) std::cout << qm.column(i)[0] << " " << qm.column(i)[1] << " " << qm.column(i)[2] << " " << qm.column(i)[3] << std::endl; }
QVector3D Frustum::bottomRight(QMatrix4x4 const& _m) const { return _m * bottomRight() - _m.column(3).toVector3D(); }
QVector3D Frustum::topLeft(QMatrix4x4 const& _m) const { return _m * topLeft() - _m.column(3).toVector3D(); }
void AnimeGLWidget::drawLayers(ObjectItem *pLayerItem) { int selFrame = m_pEditData->getSelectFrame(); int flag = pLayerItem->data(Qt::CheckStateRole).toInt(); if (m_pEditData->getObjectModel()->isLayer(pLayerItem->getIndex()) && (flag & ObjectItem::kState_Disp)) { FrameData d; bool valid; d = pLayerItem->getDisplayFrameData(selFrame, &valid); if (valid) { QMatrix4x4 mat = pLayerItem->getDisplayMatrix(selFrame); if (m_pSetting->getUseZSort()) { DRAW_FRAMEDATA draw; draw.mat = mat; draw.data = d; if (m_pSetting->getDrawFrame() && !m_pEditData->isExportPNG()) { ObjectItem *p = m_pEditData->getObjectModel()->getItemFromIndex(m_pEditData->getSelIndex()); if (pLayerItem == p) { if (m_bPressCtrl) { draw.frameCol = QColor(0, 255, 0, 255); } else { draw.frameCol = QColor(255, 0, 0, 255); } } else { draw.frameCol = QColor(64, 64, 64, 255); } } else { draw.frameCol = QColor(0, 0, 0, 0); } m_drawList.append(draw); } else { drawFrameData(d, mat); if (m_pSetting->getDrawFrame() && !m_pEditData->isExportPNG()) { QColor col; ObjectItem *p = m_pEditData->getObjectModel()->getItemFromIndex(m_pEditData->getSelIndex()); if (pLayerItem == p) { if (m_bPressCtrl) { col = QColor(0, 255, 0, 255); } else { col = QColor(255, 0, 0, 255); } } else { col = QColor(64, 64, 64, 255); } drawFrame(d, mat, col); } } } } QList<ObjectItem *> children; for (int i = 0; i < pLayerItem->childCount(); i++) { ObjectItem *pChild = pLayerItem->child(i); bool valid; QMatrix4x4 m = pChild->getDisplayMatrix(selFrame, &valid); if (!valid) { children.append(pChild); continue; } int j; for (j = 0; j < children.size(); j++) { QMatrix4x4 m1 = children[j]->getDisplayMatrix(selFrame, &valid); if (!valid) { continue; } if (m.column(3).z() < m1.column(3).z()) { children.insert(j, pChild); break; } } if (j == children.size()) { children.append(pChild); } } foreach (ObjectItem *p, children) { drawLayers(p); }