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

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

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

問(wèn)題描述

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

I have a function that draws triangles through OpenGL

我通過(guò)按下一個(gè)按鈕來(lái)繪制兩個(gè)三角形(函數(shù) on_drawMapPushButton_clicked()).

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

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

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.

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

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

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

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

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

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

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

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.

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

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_);
    }
}

推薦答案

我的錯(cuò)誤是我錯(cuò)誤地創(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的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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)形?)
主站蜘蛛池模板: 奇米久久 | 成人在线观看免费视频 | 草比av| 久久久蜜桃一区二区人 | 国产成人在线视频 | 亚洲成年影院 | 中文字幕在线视频一区二区三区 | 国产精品视频yy9299一区 | 亚洲欧美综合精品久久成人 | 亚洲九九 | 色综合久久久久 | 欧美精品一区二区三区在线播放 | 国产精品久久久久影院色老大 | 日韩成人在线观看 | 日韩精品免费在线观看 | com.色.www在线观看 | 天天夜夜操| 99久久精品免费看国产四区 | 国产欧美一区二区三区国产幕精品 | 97精品超碰一区二区三区 | 午夜精品一区二区三区免费视频 | 在线观看视频一区 | 中文字幕一区在线 | 国产成人精品一区二区三区 | 亚洲啪啪 | 黄色一级网 | 欧美精品乱码久久久久久按摩 | 久久999| 欧美一级片在线观看 | 精品国模一区二区三区欧美 | 国产精品久久久久婷婷二区次 | 一级毛片色一级 | 日韩不卡一区二区 | 国产精品久久久久久久久久久久久 | 国产精品久久一区二区三区 | 一区二区三区小视频 | 成人中文网 | 午夜精品一区二区三区免费视频 | 成人午夜视频在线观看 | 99精品久久久久 | 国产日韩欧美在线 |