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
-
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.
-
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 -
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(); }
-
Can you also share the obj file you load ?
-
You can get any object around
https://www.turbosquid.com/Search/3D-Models/free/objI'm working on the zoom slider not on the model
-
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%)
-
I meant just the code so I can build it here.
-
@Silenzio76 have you ever hear of git? try it.. is for your own good
-
@arsinte_andrei never used mais voilĂ https://github.com/silenzio76/cargo
-
can noone help me?
-
@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. -