-1

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.

Sang
  • 141
  • 11
  • 1
    Do I understand it correctly that you want to have a background image spanning the whole screen? Maybe [my implementation of such a background image helps](https://github.com/florianblume/Qt3D-BackgroundImage). – Florian Blume Mar 31 '22 at 14:46
  • Yes, but the image‘s aspect is variable, perhaps 2 : 1. So the size of the window also needs to match it. @FlorianBlume – Sang Apr 01 '22 at 02:23
  • Well then I don't think I fully get what you want to achieve. Maybe update your question with more details and a [minimal and reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) so I and others can help you better. – Florian Blume Apr 01 '22 at 07:07

1 Answers1

1

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.

Sang
  • 141
  • 11