Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Perspective view in Qt.
Forum Updated to NodeBB v4.3 + New Features

Perspective view in Qt.

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 3.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sarthak
    wrote on last edited by
    #1

    Hi Guys,

    It has been roughly a month I have started working with Qt. Right now I am trying to vie an image in perspective view. Lets say I want to rotate the image in along the Y axis, I am using the Qtransform function to rotate.. here is the code snippet.
    int angle=20;
    QTransform transform;
    transform.rotate(angle, Qt::YAxis);
    image = QImage(”:/images/livingroom.jpg”);
    image = image.scaledToWidth(this->width());
    image = image.transformed(transform);

    But this is not producing the desired results. The result image is not a perspective view. Can anybody please help me in achieving this?

    1 Reply Last reply
    0
    • W Offline
      W Offline
      wlinaz
      wrote on last edited by
      #2

      I believe you are looking for

      QTransform::quadToQuad(const QPolygonF & one, const QPolygonF & two, QTransform & trans)

      or,

      QTransform::squareToQuad(const QPolygonF & quad, QTransform & trans)

      depending on the original image.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sarthak
        wrote on last edited by
        #3

        Hi,

        Pardon my ignorance, but do i need to find out the second polygon,( the one for the perspective view) manually? After that I have to map the image to the new polygon? Please correct me if I am wrong..

        1 Reply Last reply
        0
        • W Offline
          W Offline
          wlinaz
          wrote on last edited by
          #4

          Nope, that sounds about right. I don't suspect it should be too dificult.
          ie. To make the image "fade" to the right.
          Copy the original polygon,
          in the new copy divide imageheight by 2, adjust the upper right y value to imageheight/4 and lower right y value = imageheight *3/4.

          1 Reply Last reply
          0
          • W Offline
            W Offline
            wlinaz
            wrote on last edited by
            #5

            I found this example using matrix. This is another way to go.

            "https://blog.qt.digia.com/blog/2006/09/21/perspective-transformations/":https://blog.qt.digia.com/blog/2006/09/21/perspective-transformations/

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sarthak
              wrote on last edited by
              #6

              Lets say I want to rotate it by 25 degrees along the y axis, so how do i calculate the height of the right edge of the polygon?

              Because here you are saying the right edge is half of the left edge..but how do u find out this relation

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sarthak
                wrote on last edited by
                #7

                yes Even I had stumbled across that example, but i cannot find the code to do that....I can see that the snapshots given are exactly what i want

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  wlinaz
                  wrote on last edited by
                  #8

                  I think I'm getting a bit confused about what you are trying to do here. I'm starting to suspect that you are trying to do a 3d flyby of "livingroom.jpg"?
                  If this is the case, assume you are at 89.5 degrees. You will be looking more or less at the edge of a pic, a vertical line. If this is the case it's time to start thinking about Qt OpenGL classes and go 3D.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    sarthak
                    wrote on last edited by
                    #9

                    Umm,,,I would say I am trying to achieve exactly the same thing that the snapshots in the example show...
                    https://blog.qt.digia.com/blog/2006/09/21/perspective-transformations/

                    1 Reply Last reply
                    0
                    • W Offline
                      W Offline
                      wlinaz
                      wrote on last edited by
                      #10

                      First I'll answer your previous question.

                      "Lets say I want to rotate it by 25 degrees along the y axis, so how do i calculate the height of the right edge of the polygon?"

                      I'm thinking you can't. Too many unknowns... Distance from the object, what object is the focus, the width or scale of the scene. Best you can do is simulate a rotation.

                      At this point I would suggest you add a horizontal slider to you gui. Set min at -50 and max at +50. if value is > 0, adjust the left side of the target polygon. If the value is < 0 adjust the right side of the target polygon. Adjust the edge of the polygon by some multiple of the slider's value. I would not go crazy here though, maybe no more than 50% of the height of the image.

                      I haven't tried this but I'm betting this is going to be a huge resource issue, I hope your pic is small.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved