Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How do I rotate an object around specified axis?



  • Hi there,
    I want to rotate an object around one axis and show it's 360 view..like 3d view.
    Please help how can it be achieved. Thanks.



  • @Ronak5

    You need to give details on what you have already as starting point.



  • @koahnig
    thanks for reply..so like I've a static car object/image which I want to rotate around it's centre continuously and show it's complete view.



  • @Ronak5

    What are the Qt classes you are using?


  • Moderators

    @Ronak5
    thats still not enough information. Is it a 2d canvas, an image, a 3d model etc.

    I would suggest posting the qml code you use to display the non rotationg car.



  • @J.Hilk

    Ok sure.. so it's just a whole image of a car with few image parts of the car like doors on it(as of now doors only). But yea it's just a image source.

    Image {
        id: car1
        x: 500
        y: 160
        width: 293
        height: 330
        source: "car-1.png"
        opacity:1
    
        Image {
            id: door1
            x: -28
            y: 17
            width: 338
            height: 365
            visible: be.door1
            source: "door-1.png"
        }
    
        Image {
            id: door3
            x: -16
            y: 17
            width: 338
            height: 365
            visible: be.door3
            source: "door-3.png"
        }
    
    
        Image {
            id: door2
            x: -22
            y: -63
            width: 338
            height: 365
            visible:be.door2
            source: "door-2.png"
        }
    
        Image {
            id: door4
            x: -22
            y: -63
            width: 338
            height: 365
            visible: be.door4
            source: "door-4.png"
        }
    }

  • Moderators

    @Ronak5
    ok,
    all QtQuick items have a "rotation" property/function, you can see details here:
    http://doc.qt.io/qt-5/qml-qtquick-rotation.html

    should work for images as well,

    but you won't be able to make a true 3d rotaion with 2d images

    for that you would need to go into qt3d,

    theres a "demo" by KDAB, here's a yt-link for that. Not sure if the source code is public available.
    https://www.youtube.com/watch?v=zCBESbHSR1k



  • @J.Hilk
    hey thanks a lot for the hints. So I had gone through the "rotation" property.
    But with the explanation there, looks for each rotation tag it needs same image source everytime and output i get is multiple different rotated images.
    What i was looking for specifically is infinitely rotating the image only.

    And I've been going through 3d examples also, but got nothing concrete as of now. I'll go through the link posted above.
    Please update if you could provide any more inputs here.
    Appreciate your help. Thanks again.!


  • Moderators

    @Ronak5
    here's a very basic example (working) its with a rectangle, but its the same for an image

    import QtQuick 2.9
    import QtQuick.Window 2.2
    
    Window {
        id:root
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Rectangle{
            id: redRect
    
            anchors.centerIn: parent
    
            color: "red"
    
            height: Math.min(root.height, root.width) /3
            width:  height
    
        }
    
        Timer{
            id:rotateTimer
    
            interval: 20
            repeat: true
            running: true
    
            onTriggered: redRect.rotation = redRect.rotation + 1
        }
    }
    
    


  • @J.Hilk

    Oh, so you've used a timer here and just applied rotate on image. Wow! I never knew there's something like this could be done. This shall help atleast for 2d-rotation I believe. Thanks a lot man! This is something new I've learned today!


Log in to reply