How define a good Qt3D OrbitCamera controller
Unsolved
General and Desktop
-
Hello,
I am working on a 3D visualization project in pure C++ (in other words with no use of QML). Since I have a target object in the scene (placed in the origin) , I would like to perform an orbit movement around it. Thus I coded the following, which work well:void Visualization3D::setup3DViewer() { viewer3D_->defaultFrameGraph()->setClearColor(QRgb(0xfffffff)); viewer3D_->setRootEntity(root3DEntity_.get()); this->loadScene(); this->setupAmbient(); this->setup3DCamera(); } void Visualization3D::setup3DCamera(){ camera3DEntity_.reset(viewer3D_->camera()); camera3DEntity_->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f); camera3DEntity_->setPosition(QVector3D(0, -.5f, 1.0f)); camera3DEntity_->setViewCenter(QVector3D(0, 0, 0)); camera3DEntity_->viewSphere(QVector3D(0, 0, 0), 0); camController_->setAcceleration(1.0f); camController_->setLinearSpeed(1.0f); camController_->setZoomInLimit(1.0f); camController_->setCamera(camera3DEntity_.get()); } void Visualization3D::loadScene(){ Qt3DCore::QTransform *q = new Qt3DCore::QTransform(); q->setTranslation(QVector3D(0,0,0)); mesh_arr_.at(obj_reference_index_)->setMeshScale(QVector3D(0.025,0.025,0.025),false); mesh_arr_.at(grasping_candidate_index_)->setMeshScale(QVector3D(0.025,0.025,0.025),false); mesh_arr_.at(grasping_candidate_index_)->setMeshPose(q,false); for (size_t i = 0; i<mesh_arr_.size(); i++) mesh_arr_.at(i)->loadMesh(); }
Where which object is construct by:
viewer3D_ = std::make_shared<Qt3DExtras::Qt3DWindow>(); root3DEntity_ = std::make_shared<Qt3DCore::QEntity>(); camera3DEntity_= std::make_shared<Qt3DRender::QCamera>(); camController_ = std::make_shared<Qt3DExtras::QOrbitCameraController>(root3DEntity_.get()); lightEntity_ = std::make_shared<Qt3DCore::QEntity>(root3DEntity_.get());
However, when I zoom in or zoom out over the object this orbit is affected, i.e. the object is not the center of the orbit view anymore.
Is there any way to correct this?
OBS: I also try to get some signals of the Qt3DRender::QCamera, e.g the viewVectorChanged notifier signal (https://doc.qt.io/qt-5/qt3drender-qcamera.html#viewVector-prop) trying to performing some adjusts in camera center of view, however the signal does not work.
connect(camera3DEntity_.get(), SIGNAL(viewVectorChanged(const QVector3D)),this,SLOT(testSlot()));