Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt3D & QSlider



  • Greetings,

    I wrote this piece of code to render my Obj file:

    Qt3DCore::QEntity * add3dElements(Qt3DExtras::Qt3DWindow *view){
        Qt3DCore::QEntity *eRoot = new Qt3DCore::QEntity;
    
        Qt3DRender::QCamera *cCam = view->camera();
        /*cCam->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
        cCam->setPosition(QVector3D(0, 0, 8.0f));
        cCam->setUpVector(QVector3D(0, 1, 0));
        cCam->setViewCenter(QVector3D(0, 0, 0));*/
        cCam->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
        cCam->setProjectionType(Qt3DRender::QCameraLens::PerspectiveProjection);
        cCam->setAspectRatio(view->width() / view->height());
        cCam->setUpVector(QVector3D(0.0f, 1.0f, 0.0f));
        //cCam->setViewCenter(QVector3D(0.04f, 1.0f, 0.0f));
        cCam->setViewCenter(QVector3D(0, 0, 0));
        //cCam->setPosition(QVector3D(0.0f, 2.5f, 2.1f));
        cCam->setPosition(QVector3D(0, 0, 8.0f));
        cCam->setNearPlane(0.001f);
        cCam->setFarPlane(100.0f);
    
        Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController();
        camController->setCamera(cCam);
    
    
        Qt3DCore::QEntity *eLight = new Qt3DCore::QEntity(eRoot);
    
        Qt3DRender::QPointLight *plPoint = new Qt3DRender::QPointLight(eLight);
        plPoint->setColor("silver");
        plPoint->setIntensity(2);
        eLight->addComponent(plPoint);
    
        Qt3DCore::QTransform *tLightMng = new Qt3DCore::QTransform(eLight);
        tLightMng->setTranslation(cCam->position());
        eLight->addComponent(tLightMng);
    
        Qt3DCore::QEntity *eModel = new Qt3DCore::QEntity(eRoot);
        Qt3DRender::QMesh *mModel = new Qt3DRender::QMesh();
        mModel->setSource(QUrl("qrc:/truck"));
    
        Qt3DExtras::QPhongMaterial *pmModel = new Qt3DExtras::QPhongMaterial();
        pmModel->setDiffuse(QColor(Qt::lightGray));
    
    
    
        Qt3DCore::QTransform *tModelMng = new Qt3DCore::QTransform();
        tModelMng->setScale(0.45f);
        tModelMng->setRotation(QQuaternion::fromEulerAngles(0.0, 0.0, 0.0));
    
        eModel->addComponent(mModel);
        eModel->addComponent(tModelMng);
        eModel->addComponent(pmModel);
    
    
        view->setRootEntity(eRoot);
        return eRoot;
    };
    

    It's possible link c++ via 3 QSlider to the QCamera or the QTransform component to manage Pitch, Yaw and Zoom?
    Did code's samples exist to do that?

    Thank you in advance


  • Lifetime Qt Champion

    Hi,

    This example shows how to use QCheckBoxes but you'll get the idea on how to mix controls and a Qt3D scene.



  • the problem is to link the "tModelMng->setRotation(QQuaternion::fromEulerAngles(0.0, 0.0, 0.0));"

    to the QSlider/QDial to set the rotation and zoom, like Qt 3D: Scene2D QML Example, but in c++ code, not to retrieve the "Enabled" property.


  • Lifetime Qt Champion

    Don't link them directly, link your sliders to a slot where you call tModelMng->setRotation(QQuaternion::fromEulerAngles(pitchSlider->value(), yawSlider->value(), rollSlider->value()));.



  • Already tryed, not works!
    How can retrieve the QTransform Obj?
    I had tryed iteration, dynamic casting, but nothing seems to work


  • Lifetime Qt Champion

    Can you provide a minimal compilable example that shows what you are trying to achieve ?



  • @SGaist to the function above add:

    int main(int argc, char **argv)
    {
        QApplication app(argc, argv);
        //keypad global management
        
    
        QWidget *widget = new QWidget;
         QVBoxLayout *vSceneLayout = new QVBoxLayout();
        QWidget *wSpacer = new QWidget();
       wSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
        QLabel *lbPitch = new QLabel("Pitch rot.");
        QDial *dPicth = new QDial();
        dPicth->setMaximum(36000);
        dPicth->setValue(0);
        QLabel *lbYaw = new QLabel("Yaw rot.");
        QDial *dYaw = new QDial();
        dYaw->setMaximum(36000);
        dYaw->setValue(0);
        QLabel *lbZoom = new QLabel("Zoom");
        QSlider *sZoom = new QSlider(Qt::Horizontal);
        sZoom->setTickInterval(10);
        sZoom->setValue(45);
        sZoom->setMinimum(0);
        sZoom->setMaximum(10000);
        setSliderStyle(sZoom);
        QHBoxLayout *hlCmd = new QHBoxLayout();
        hlCmd->addWidget(wSpacer);
        hlCmd->addWidget(lbPitch);
        hlCmd->addWidget(dPicth);
        hlCmd->addWidget(lbYaw);
        hlCmd->addWidget(dYaw);
        hlCmd->addWidget(lbZoom);
        hlCmd->addWidget(sZoom);
    
        Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow();
        view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f)));
        Qt3DCore::QEntity *scene = add3dElements(view);
    
    Qt3DCore::QTransform *meshTrans = new Qt3DCore::QTransform(scene);
        QObject::connect(dPitch, &QDial::valueChanged, [=] (float) {
            meshTrans->setRotationX(dPitch->value()/100);
            scene->addComponent(meshTrans);
        });
    
        QObject::connect(dYaw, &QDial::valueChanged, [=] (float) {
            meshTrans->setRotationY(dYaw->value()/100);
            scene->addComponent(meshTrans);
        });
           
        view->setRootEntity(scene);
        QWidget *container = QWidget::createWindowContainer(view);
    
        vSceneLayout->addWidget(container, 1);
        vSceneLayout->addLayout(hlCmd);
        hLayout->addLayout(vSceneLayout, 1);
    
        widget->setWindowState(Qt::WindowMaximized);
        widget->setGeometry(QGuiApplication::screens().at(0)->availableGeometry());
    
        widget->show();
    
    
    
    
        return app.exec();
    }
    

  • Lifetime Qt Champion

    Can you also share the obj file you load ?



  • You can get any object around
    https://www.turbosquid.com/Search/3D-Models/free/obj

    I'm working on the zoom slider not on the model


  • Lifetime Qt Champion

    Would it be possible to have complete working minimal buildable sample code ?
    The two put together don't build out of the box and I'm currently getting only a grey zone.



  • @SGaist
    play/change this line to a value lesser of 1(ex.0.45f)

     Qt3DCore::QTransform *tModelMng = new Qt3DCore::QTransform();
    **==>> tModelMng->setScale(0.45f);**
     tModelMng->setRotation(QQuaternion::fromEulerAngles(45.0f,30.0f, 0.0f));
    

    [0_1559129464565_build-CargoAssistant-Desktop_Qt_5_12_0_MinGW_64_bit-Debug.7z.001](Uploading 100%) [0_1559129533552_build-CargoAssistant-Desktop_Qt_5_12_0_MinGW_64_bit-Debug.7z.002](Uploading 100%)


  • Lifetime Qt Champion

    I meant just the code so I can build it here.



  • @SGaist [0_1559220017289_CargoAssistant.7z](Uploading 100%)
    the system not permits me to upload !
    tryed today and yesterday(not enough priviledge)!



  • @Silenzio76 have you ever hear of git? try it.. is for your own good





  • can noone help me?


  • Qt Champions 2019

    @Silenzio76 You still did not upload code as @SGaist asked you.
    You should not try to upload it here as it does not work.
    Upload it to some file sharing service and put the link here.



  • @Silenzio76 said in Qt3D & QSlider:

    https://github.com/silenzio76/cargo

    this is where hi post the code
    in the github


Log in to reply