[Interest] [ Qt3D ] Is QRotateTransform rotation axis?

Eddie Sutton edsutton at gmail.com
Sat Mar 21 18:01:19 CET 2015


>[ Qt3D ] Is QRotateTransform rotation axis fixed?

In screenshot below, I rotated the 4th pipe 90 degrees.

using namespace Qt3D;


const float PipeLength = 50;

const float PipeDiameter = 5;


/// Add new pipe at specified coordinates and angle

void addPipe(QEntity *parentEntity,

             float x,

             float y,

             float z,

             float angleDegrees)

{

    static int pipeCount = 0;

    QColor colorPipe = Qt::gray;

    if( 0 != (0x01 & ++pipeCount))

    {   // alternate colors to make easy to visualize pipe segments

        colorPipe = Qt::blue;

    }


    QEntity *entity = new QEntity();

    Qt3D::QTransform *transform = new Qt3D::QTransform();


    QCylinderMesh *mesh = new QCylinderMesh();

    mesh->setRings(50.0f);

    mesh->setSlices(30.0f);

    mesh->setRadius(PipeDiameter/2);

    mesh->setLength(PipeLength);


    QPhongMaterial *material = new QPhongMaterial();

    material->setDiffuse(colorPipe);

    material->setAmbient(Qt::gray);

    material->setSpecular(Qt::white);

    material->setShininess(150.0f);


    QTranslateTransform *translation = new QTranslateTransform();

    translation->setTranslation(QVector3D(x, y, z));


    QRotateTransform *rotateX = new QRotateTransform();

    rotateX->setAxis(QVector3D(-1.0f, 0.0f, 0.0f)); //<- 1,0,0 rotates
at center of pipe X axis

    rotateX->setAngleDeg(angleDegrees);


    // Do I need both X & Z rotation?

    // I gueess it depends on native orientation of a QCylinderMesh?

    QRotateTransform *rotateZ = new QRotateTransform();

    //rotateZ->setAxis(QVector3D(0.0f, 0.0f, 1.0f));

    rotateZ->setAngleDeg(angleDegrees);


    // addTransform order matters !!!

    transform->addTransform(rotateX);

    transform->addTransform(rotateZ);

    transform->addTransform(translation);


    entity->addComponent(transform);

    entity->addComponent(mesh);

    entity->addComponent(material);

    entity->setParent(parentEntity);

}


int main(int ac, char **av)

{

    QGuiApplication app(ac, av);


    Window view;

    Qt3D::QAspectEngine engine;

    engine.registerAspect(new Qt3D::QRenderAspect());


    Qt3D::QInputAspect *input = new Qt3D::QInputAspect;

    engine.registerAspect(input);

    engine.initialize();

    QVariantMap data;

    data.insert(QStringLiteral("surface"),
QVariant::fromValue(static_cast<QSurface *>(&view)));

    data.insert(QStringLiteral("eventSource"), QVariant::fromValue(&view));

    engine.setData(data);

    QEntity *root = new QEntity();


    // Camera

    QCamera *cameraEntity = new QCamera(root);

    cameraEntity->setObjectName(QStringLiteral("cameraEntity"));


    float fieldOfView = 45;

    float aspect = 16.0f/9.0f;

    float nearPlane = 0.1;

    float farPlane = 1000.0f;

    cameraEntity->lens()->setPerspectiveProjection(fieldOfView,
aspect, nearPlane, farPlane);


    // Experimentally determined by addPipes and incrementing one axis
value at a time

    //cameraEntity->setPosition(QVector3D(0, +250.0f, +250.0f));

    // z axis is towards camera, +Y uo, +X right

    //

    //

    //                +Y

    //                 ^

    //                 |

    //                 |

    //                 |

    //                 |

    //                 +-----------> +X

    //                /

    //               /

    //              /

    //            +Z

    cameraEntity->setPosition(QVector3D(0, +250.0f, +250.0f));


    // Is this vector from center-of-world to camera?

    cameraEntity->setUpVector(QVector3D(0, 0, -1));


    cameraEntity->setViewCenter(QVector3D(0, 0, 0));

    input->setCamera(cameraEntity);


    // FrameGraph

    QFrameGraph *frameGraph = new QFrameGraph();

    QForwardRenderer *forwardRenderer = new QForwardRenderer();

    forwardRenderer->setCamera(cameraEntity);

    forwardRenderer->setClearColor(Qt::black);

    frameGraph->setActiveFrameGraph(forwardRenderer);

    root->addComponent(frameGraph);


    // Add pipes

    float angle = 90;

    float x = 0;

    float y = 0;

    float z = 0;

    for(int i = 0; i < 3; ++i)

    {

        addPipe(root,

                x, y, z,

                angle );

        x = x + PipeLength;

        //y = y - PipeLength;

    }


    // rotate last pipe +90 degrees to visualize rotation axis

    addPipe(root,

            x, y, z,

            angle + 90);


    engine.setRootEntity(root);

    view.show();


    if (app.arguments().contains(("--bench")))

        QTimer::singleShot(25 * 1000, &app, &QCoreApplication::quit);


    return app.exec();

}




[image: Inline image 1]

On Sat, Mar 21, 2015 at 11:40 AM, Eddie Sutton <edsutton at gmail.com> wrote:

>
> I am starting from the Qt3D bigscene example.
>
> I plan to use QCylinderMesh entities to represent underground pipes for a
> utility infrastructure app where I know; 1) the pitch angle, and 2) depth
> of each pipe.
>
> The rotations axis appears to be to length midpoint of the cylinder.
> Could this be changed to the end of the cylinder?
>
>     QRotateTransform *rotateX = new QRotateTransform();
>
>     //It appears 1,0,0 rotates at center of pipe X axis. Where is 0.0 Where is 1.0? Where is -1.0?
>
>     rotateX->setAxis(QVector3D(1.0f, 0.0f, 0.0f));
>
>     rotateX->setAngleDeg(angleDegrees);
>
>
>
>
> I am new to OpenGL.  I am struggling with camera perspective and
> coordinate system, units, etc.  Pointers to Qt3D docs, or other learning
> resources are appreciated.
>
>
> I think I want to use whatever coordinate system is most popular in CAE.
> Or perhaps aerospace navigation since I am basically navigating through
> underground space.  I am thinking +Z up , +X right, -Y towards camera?
>
> Any advice?  I am concerned it could be difficult to change once I get too
> far down the road.
>
> Is the right or left handed coordinates system all determined by QCamera::setPosition
> and QCamera->setUpVector ?  Like on a space station up/down is your point
> of view, and left/right is dependent on your up/down perspective?
>
> Thanks in advance for any direction,
>
> -Ed
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150321/6ed5ea7b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 9145 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150321/6ed5ea7b/attachment.png>


More information about the Interest mailing list