[Interest] [ Qt3D ] Is QRotateTransform rotation axis?

Eddie Sutton edsutton at gmail.com
Tue Mar 24 04:28:40 CET 2015


Hi Sean,

Sorry, I sent email before I intended,

>On Mar 23, 2015, at 9:34 AM, Sean Harmer <sean.harmer at kdab.com> wrote:
>The transformations are applied about the origin in local coords. For the cylinder that is indeed the centre of the mesh. 
>
>To solve this add in a translation to move the origin to one end of the cylinder, rotate, and then translate back again.

Can you please outline the translation calls?

For example, which translation method is used to move origin to one end of the cylinder?


/// Add new pipe at specified coordinates and angle
///
/// Implementation Hint:
/// --------------------
/// The transformations are applied about the origin in local coords.
/// For the cylinder that is indeed the centre of the mesh.
///
/// To solve this add in a translation to move the origin to
/// one end of the cylinder, rotate, and then translate back again.
///
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);
}



-Ed


> 
> Cheers,
> 
> Sean
> 
> On 21/03/2015 16:40, Eddie Sutton 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.
>> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150323/89bca698/attachment.html>


More information about the Interest mailing list