qtqt3d

Why do I got partial invisible areas when scale the plane along the Z axis in Qt3D


I create a 3D scene using Qt3D, there is an orthographic camera and a plane in the scene, I want the camera to capture the plane just right. The problem is, when I call QTransform::setScale3D() to scale up the plane along with Z-axis, increasing from 1, when the value acoss 2, part of the image goes black suddenly. After a lot of testing, I ensure that the position and rotation of the plane and the camera all not changed.

Some codes are as follows:

rootEntity = new Qt3DCore::QEntity;
// create a plane
plane = new Qt3DCore::QEntity(rootEntity);
// mesh
auto planeMesh = new Qt3DExtras::QPlaneMesh;
planeMesh->setWidth(1.0f);
planeMesh->setHeight(1.0f);
// transform
transform = new Qt3DCore::QTransform;
transform->setTranslation(QVector3D(0, 0, 0));
transform->setRotation(QQuaternion::fromEulerAngles(QVector3D(0, 0, 0)));
transform->setScale3D(QVector3D(1, 1, 2));
//transform->setScale3D(QVector3D(m_planeWidth, 1, m_planeHeight));
// material
//auto mat = new Qt3DExtras::QPhongMaterial;
texMat = new Qt3DExtras::QTextureMaterial;
// add component
plane->addComponent(planeMesh);
plane->addComponent(transform);
plane->addComponent(texMat);
// configure camera
camera()->setPosition(QVector3D(0.0f, 1.0f, 0.0f));
//camera()->rotate(QQuaternion::fromEulerAngles(QVector3D(-90, 0, 0)));
camera()->transform()->setRotation(QQuaternion::fromEulerAngles(QVector3D(-90, 0, 0)));
//camera()->setViewCenter(QVector3D(0.0f, 0.0f, 0.0f));
camera()->lens()->setOrthographicProjection(
    m_planeWidth / 2,   // left
    m_planeWidth / 2,   // right
    m_planeHeight / 2,  // bottom
    m_planeHeight / 2,  // top
    0.3f,               // nearPlane
    1000.0f);           // farPlane

Screenshots:

When the plane's scale-Z is 1:

When the plane's scale-Z is 1

When the plane's scale-Z goes to 2:

When the plane's scale-Z goes to 2

Any helpful discussion is welcome. Thanks in advance.


Solution

  • OK, I set the parameter left/right/bottom/top of the orthographic camera incorrectly. The left and bottom should be negative, but I set them all positive. I found my mistake when I printed the default values of those 6 properties of the orthographic camera, they are -0.5, 0.5, -0.5, 0.5. It's a little embarrassed.