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);
    // 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

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.