c++ - Qt3D rotate camera around mesh -


i've started learning qt/qml/c++ , trying build basic 3d scene rotate camera around mesh object.

i'm finding difficult follow examples , i'm finding documentation doesn't provide useful instructions. there doesn't seem many tutorials out there either, perhaps i'm looking in wrong places.

main.cpp

#include <qt3dquickextras/qt3dquickwindow.h> #include <qt3dquick/qqmlaspectengine>  #include <qguiapplication> #include <qtqml>  int main(int argc, char **argv) {     qguiapplication app(argc, argv);     qt3dextras::quick::qt3dquickwindow view;      // expose window context property can set aspect ratio     view.engine()->qmlengine()->rootcontext()->setcontextproperty("_window", &view);     view.setsource(qurl("qrc:/main.qml"));     view.setwidth(800);     view.setheight(600);     view.show();      return app.exec(); } 

main.qml

import qt3d.core 2.0 import qt3d.render 2.0 import qt3d.input 2.0 import qt3d.extras 2.0  entity {     id: sceneroot      camera {         id: camera         projectiontype: cameralens.perspectiveprojection         fieldofview: 25         aspectratio: _window.width / _window.height         nearplane : 0.1         farplane : 1000.0         position: qt.vector3d( 0, 0.0, 20.0 )         upvector: qt.vector3d( 0.0, 1.0, 0.0 )         viewcenter: qt.vector3d( 0.0, 0.0, 0.0 )     }      orbitcameracontroller {         camera: camera     }      components: [         rendersettings {             activeframegraph: forwardrenderer {                 clearcolor: qt.rgba(0, 0.5, 1, 1)                 camera: camera             }         },         inputsettings { }     ]      phongmaterial {         id: carmaterial     }      mesh {         id: carmesh         source: "resources/aventador.obj"     }      entity {         id: carentity         components: [ carmesh, carmaterial ]     } } 

how camera rotate around mesh object?

the orbitcameracontroller allows move camera along orbital path. make rotate around mesh, set viewcenter of camera position of mesh (translation of transform of entity containing mesh) , use keyboard/mouse rotate around.

so add:

transform{         id: cartransform         translation: qt.vector3d(5.0, 5.0, 5.0) //random values, choose own } 

and add transform components of entity. change viewcenter of camera to

viewcenter: cartransform.translation 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -