久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Qt3d.在三角形上繪制透明的 QSphereMesh

Qt3d. Draw transparent QSphereMesh over triangles(Qt3d.在三角形上繪制透明的 QSphereMesh)
本文介紹了Qt3d.在三角形上繪制透明的 QSphereMesh的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有一個通過 OpenGL 繪制三角形的函數(shù)

I have a function that draws triangles through OpenGL

我通過按下一個按鈕來繪制兩個三角形(函數(shù) on_drawMapPushButton_clicked()).

I draw two triangles by pressing a button (function on_drawMapPushButton_clicked()).

然后我畫一個放置在這些三角形上方的球體.現(xiàn)在我看到,那個球體正確地繪制在第一個三角形上,但第二個三角形繪制在球體上,反之亦然.

Then i draw a sphere that placed above these triangles. And now i see, that sphere is drawed correctly over first triangle, but second triangle drawed over the sphere and not vice versa.

如果我第二次按下按鈕,球體就會正確地繪制在第一個和第二個三角形上.

If i press the button second time, then spehere is drawed correctly over first and second triangles.

當(dāng)我第三次按下按鈕時,第二個三角形再次繪制在球體上.

When i press the button third time, then second triangle drawed over the sphere again.

當(dāng)我第四次按下按鈕時,球體在第一個和第二個三角形上正確繪制,依此類推.

When i press the button fourth time, then spehere is drawed correctly over first and second triangles and so on.

如果我在 sphereMesh QPhongMaterial 中使用 QPhongMaterial 而不是 QPhongAlphaMaterial,那么總是在第一個和第二個三角形上正確繪制球體.喜歡它必須如此.

If i use in sphereMesh QPhongMaterial instead of QPhongAlphaMaterial, then spehere is drawed correctly over first and second triangles always. Like it must to be.

我不明白我做錯了什么讓我的球體總是在三角形上繪制.

I can't understand what i do wrong to get my sphere is drawed always over the triangles.

代碼,繪制透明球體:

selectModel_ = new Qt3DExtras::QSphereMesh(selectEntity_);
selectModel_->setRadius(75);
selectModel_->setSlices(150);

selectMaterial_ = new Qt3DExtras::QPhongAlphaMaterial(selectEntity_);
selectMaterial_->setAmbient(QColor(28, 61, 136));
selectMaterial_->setDiffuse(QColor(11, 56, 159));
selectMaterial_->setSpecular(QColor(10, 67, 199));
selectMaterial_->setShininess(0.8f);

selectEntity_->addComponent(selectModel_);
selectEntity_->addComponent(selectMaterial_);

函數(shù) drawTriangles:

void drawTriangles(QPolygonF triangles, QColor color){
    int numOfVertices = triangles.size();

    // Create and fill vertex buffer
    QByteArray bufferBytes;
    bufferBytes.resize(3 * numOfVertices * static_cast<int>(sizeof(float)));
    float *positions = reinterpret_cast<float*>(bufferBytes.data());

    for(auto point : triangles){
        *positions++ = static_cast<float>(point.x());
        *positions++ = 0.0f; //We need to drow only on the surface
        *positions++ = static_cast<float>(point.y());
    }

    geometry_ = new Qt3DRender::QGeometry(mapEntity_);
    auto *buf = new Qt3DRender::QBuffer(geometry_);
    buf->setData(bufferBytes);

    positionAttribute_ = new Qt3DRender::QAttribute(mapEntity_);
    positionAttribute_->setName(Qt3DRender::QAttribute::defaultPositionAttributeName());
    positionAttribute_->setVertexBaseType(Qt3DRender::QAttribute::Float); //In our buffer we will have only floats
    positionAttribute_->setVertexSize(3); // Size of a vertex
    positionAttribute_->setAttributeType(Qt3DRender::QAttribute::VertexAttribute); // Attribute type
    positionAttribute_->setByteStride(3 * sizeof(float));
    positionAttribute_->setBuffer(buf); 
    geometry_->addAttribute(positionAttribute_); // Add attribute to ours  Qt3DRender::QGeometry

    // Create and fill an index buffer
    QByteArray indexBytes;
    indexBytes.resize(numOfVertices * static_cast<int>(sizeof(unsigned int))); // start to end
    unsigned int *indices = reinterpret_cast<unsigned int*>(indexBytes.data());

    for(unsigned int i = 0; i < static_cast<unsigned int>(numOfVertices); ++i) {
        *indices++ = i;
    }

    auto *indexBuffer = new Qt3DRender::QBuffer(geometry_);
    indexBuffer->setData(indexBytes);

    indexAttribute_ = new Qt3DRender::QAttribute(geometry_);
    indexAttribute_->setVertexBaseType(Qt3DRender::QAttribute::UnsignedInt); //In our buffer we will have only unsigned ints
    indexAttribute_->setAttributeType(Qt3DRender::QAttribute::IndexAttribute); // Attribute type
    indexAttribute_->setBuffer(indexBuffer);
    indexAttribute_->setCount(static_cast<unsigned int>(numOfVertices)); // Set count of our vertices
    geometry_->addAttribute(indexAttribute_); // Add the attribute to ours Qt3DRender::QGeometry

    shape_ = new Qt3DRender::QGeometryRenderer(mapEntity_);
    shape_->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles);
    shape_->setGeometry(geometry_); 

    //Create material
    material_ = new Qt3DExtras::QPhongMaterial(mapEntity_);
    material_->setAmbient(color);

    trianglesEntity_ = new Qt3DCore::QEntity(mapEntity_);
    trianglesEntity_->addComponent(shape_); 
    trianglesEntity_->addComponent(material_);
}

按下按鈕處理程序 on_drawMapPushButton_clicked():

void on_drawMapPushButton_clicked()
{
    clearMap(); //Implementation is above
    QPolygonF triangle1;
    triangle1 << QPointF( 0 ,-1000) << QPointF(0 ,1000) << QPointF(1000, -1000);
    drawTriangles(triangle1, Qt::black);

    QPolygonF triangle2;
    triangle2 << QPointF(-1000,-1000) << QPointF(-100,1000) << QPointF(-100,-1000);
    drawTriangles(triangle2, Qt::red);
}

地圖清除函數(shù)clearMap():

void clearMap()
{
    if(mapEntity_){
        delete mapEntity_;
        mapEntity_ = nullptr;
        mapEntity_ = new Qt3DCore::QEntity(view3dRootEntity_);
    }
}

推薦答案

我的錯誤是我錯誤地創(chuàng)建和刪除了三角形和球體實(shí)體的順序.

My mistake was that i did wrong order of creating and deletion of Triangles and Sphere entities.

在偽代碼中正確的順序如下:

In pseudo code right order is as follows:

clearTriangles();
clearSphere();       
drawTriangles();
drawSphere();

這篇關(guān)于Qt3d.在三角形上繪制透明的 QSphereMesh的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 亚洲综合国产精品 | 国产精品成人一区 | 中日韩毛片| 久热久草 | 国产日韩欧美一区 | 999久久久久久久久6666 | 91视频大全 | 永久免费视频 | 成人免费大片黄在线播放 | 婷婷久 | 一区二区三区四区在线播放 | 9191av| 欧美日韩国产精品一区 | 粉嫩一区二区三区四区公司1 | 欧美激情视频一区二区三区在线播放 | 懂色中文一区二区在线播放 | 91精品观看 | 欧美精品一区二区三区在线播放 | 欧美日一区 | 午夜精品久久久 | 成人在线精品视频 | 国产精品视频中文字幕 | 在线成人www免费观看视频 | 精品国产免费人成在线观看 | 亚洲精品在线免费观看视频 | 天天操网 | 天天操 天天操 | 日本公妇乱淫xxxⅹ 国产在线不卡 | 日韩欧美一区二区三区免费观看 | 国产精品美女久久久久久免费 | 日韩精品一区二区不卡 | www.788.com色淫免费 | 亚洲五码在线 | 永久www成人看片 | 蜜桃av鲁一鲁一鲁一鲁 | 成人精品视频 | 超碰97在线免费 | 欧美一级片在线播放 | 国产精品福利视频 | 中文字幕在线播放不卡 | 免费三级黄 |