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

Qt 3D Billboarding



  • I'm trying to implement billboarding for a QPlaneMesh in Qt 5.8 C++. So far, the plane more or less faces towards the camera when I move around, but often it's upside down. I tried different rotations with QQuaternions with no success.

    // camera
    Qt3DRender::QCamera* camera = view->camera();
    camera ->lens()->setPerspectiveProjection(90.0f, 16.0f/9.0f, 0.1f, 1000.0f);
    camera ->setPosition(QVector3D(2.0f, 2.0f, 2.0f));
    camera ->setUpVector(QVector3D(0, 1, 0));
    camera ->setViewCenter(QVector3D(0, 0, 0));
    
    // controls
    Qt3DExtras::QFirstPersonCameraController* camController = new Qt3DExtras::QFirstPersonCameraController(rootEntity);
    camController->setCamera(camera);
    
    // signal/slots
    QObject::connect(camera, &Qt3DRender::QCamera::positionChanged, plane, &Plane::rotate);
    
    // Plane::rotate
    void Plane::rotate(QVector3D target)
    {
        planeTransform->setRotation(QQuaternion::rotationTo(planeTransform->translation(), target));
    }
    

    So the plane gets rotated towars the position of the camera.
    Anyone got an idea how to improve things?


Log in to reply