Description
The following program shows a simple sphere and two buttons called ViewAll and Set View Sphere. Both operations should perform equal.
Basically, the camera should be positioned, so that the complete sphere fits into the view port, after pressing View All.
#include <QApplication> #include <QCamera> #include <QCameraLens> #include <QDebug> #include <QDiffuseSpecularMaterial> #include <QFrame> #include <QPushButton> #include <QSphereMesh> #include <Qt3DWindow> #include <QTransform> #include <QVBoxLayout> #include <QWidget> int main(int argc, char* argv[]) { QApplication a(argc, argv); auto view = new Qt3DExtras::Qt3DWindow(); auto rootEntity = new Qt3DCore::QEntity(); view->setRootEntity(rootEntity); auto camera = view->camera(); camera->lens()->setPerspectiveProjection(45.0f, 1., 0.1f, 10000.0f); camera->setPosition(QVector3D(0, 2, 0)); camera->setUpVector(QVector3D(0, 1, 0)); camera->setViewCenter(QVector3D(0, 0, 0)); auto sphere = new Qt3DCore::QEntity(); sphere->addComponent(new Qt3DExtras::QSphereMesh); sphere->addComponent(new Qt3DExtras::QDiffuseSpecularMaterial); sphere->setParent(rootEntity); auto container = QWidget::createWindowContainer(view); QFrame frame; frame.setLayout(new QVBoxLayout); frame.layout()->addWidget(container); frame.resize(QSize(400, 300)); auto btnViewAll = new QPushButton("View All"); frame.layout()->addWidget(btnViewAll); auto btnSetViewSphere = new QPushButton("Set View Sphere"); frame.layout()->addWidget(btnSetViewSphere); QObject::connect(btnViewAll, &QPushButton::clicked, [&]() { camera->viewAll(); }); QObject::connect(btnSetViewSphere, &QPushButton::clicked, [&]() { camera->viewSphere(QVector3D(0, 0, 0), 1); }); frame.show(); return a.exec(); }
Instead the upper and lower portion of the sphere are clipped. I included a picture of the bad view all and of what has to be basically done in my understanding of what
a proper ViewAll should do.