Results 1 to 20 of 26

Thread: Help with a visual effect

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    44
    Thanked 2 Times in 2 Posts

    Thumbs up Help with a visual effect

    Hi, I want to know what's the simple way to obain this visual effect: a rectangle (for example) that rotates 180 degrees from the Y axis:
    Qt Code:
    1. Coordinate system
    2. |Y
    3. |
    4. |
    5. |
    6. |_________________ X
    7. /
    8. /
    9. /
    10. / Z
    To copy to clipboard, switch view to plain text mode 

    All I want is to emulate the effect of a page (of a book) turning around
    I think that I could use openGL but I don't hve much experinece with it, maybe it can be easily achieved with QPainter
    Thanks in advance.
    Last edited by SkripT; 4th May 2006 at 17:39.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Help with a visual effect

    If you have a point (x, y, z) and you rotate it around Y axis by a degrees, you'll get (x', y', z') where:
    x' = x cos a + z sin a,
    y' = y,
    z' = -x sin a + z cos a.

    Second thing you will need is a projection. In this case it probably will be enough if you use:
    xp = x - z
    yp = y + z
    (where xp, and yp are the painter coordinates).

    The algorithm:
    • translate the painter so that the (0, 0) point is in the middle of the top edge of the book,
    • x1 = width/2, y1 = 0, z1 = 0, (upper corner of the page)
    • x2 = width/2, y2 = height, z2 = 0, (lower corner of the page)
    • for a = 0, 1, ..., 180:
      • calculate new x1, y1, z1, x2, y2 and z2
      • draw a (0, 0)--(x1-z1, y1-z1)--(x2-z2, y2-z2)--(0, height) rectangle

    Note that in fact x1 == x2, z1 == z2 and both y1 and y2 are constant.

  3. The following user says thank you to jacek for this useful post:

    SkripT (4th May 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    44
    Thanked 2 Times in 2 Posts

    Default Re: Help with a visual effect

    Thanks a lot jacek, good knowledge of maths

    EDIT: taking a look at this alogrithm carefully, I think that it will paint the rectangle with the correct size in each degree, the problem is that I want to paint an image (texture) on this rectangle and I want that it "deforms" with each degree. Is it still possible with QPainter?
    Last edited by SkripT; 4th May 2006 at 18:52.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Help with a visual effect

    Quote Originally Posted by SkripT
    I want that it "deforms" with each degree. Is it still possible with QPainter?
    Try QPainter::setMatrix() or QImage::transform().

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Help with a visual effect

    Wouldn't it be enough to transform the painter matrix to do it all?

    Hmm... Looks like QMatrix is just 2x2 in size...

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Help with a visual effect

    Quote Originally Posted by wysota
    Looks like QMatrix is just 2x2 in size...
    No, it's 3x3, but the last column is [0;0;1]. Anyway, it will be enough, since you only have to shear and scale the painter (or image).

  8. #7
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    44
    Thanked 2 Times in 2 Posts

    Default Re: Help with a visual effect

    Thanks a lot jacek and wysota for your replies. My question is: so, using QMatrix is enought to do all the rotations/shear/scale that I need applied on the image or the rectangle to simulate the effect that I need? QMatrix seems to work only in 2D and this effect has a 3D component I think....

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Help with a visual effect

    Quote Originally Posted by SkripT
    QMatrix is enought to do all the rotations/shear/scale that I need applied on the image or the rectangle to simulate the effect that I need?
    Theoretically, yes.
    Quote Originally Posted by SkripT
    QMatrix seems to work only in 2D and this effect has a 3D component I think....
    Do you have a 3D monitor?

  10. #9
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    44
    Thanked 2 Times in 2 Posts

    Default Re: Help with a visual effect

    Quote Originally Posted by jacek
    Theoretically, yes.

    Do you have a 3D monitor?
    Not, but now I know what to request for christmas .

    I will try with QMatrix it and I comment the results

  11. #10
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    44
    Thanked 2 Times in 2 Posts

    Default Re: Help with a visual effect

    Hi again, I've been reading carefully and testing what the docs explains from QMatrix class and I don't know how could I use it to obtain the effect that I want . I know that I should call QMatrix::shear and QMatrix::scale in some way because, as the docs says, "...Rotation is achieved by carefully setting both the shearing factors and the scaling factors" but I don't know how
    It's clear that I'm not a math expert... Could you please guide me a little bit in how could I configure the QMatrix to get the respective "transformated" rectangle for each angle rotated? Thanks again.

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

  13. The following 2 users say thank you to wysota for this useful post:

    SkripT (5th May 2006), superteny (27th May 2009)

Similar Threads

  1. Help for 3D like Visual Effect.
    By AmolShinde_8 in forum Qt Programming
    Replies: 0
    Last Post: 6th October 2008, 15:25
  2. Qt 4.4.1 Compile Error with MS Visual C++ 2008 Express SP1
    By BrainB0ne in forum Installation and Deployment
    Replies: 3
    Last Post: 19th August 2008, 15:49
  3. Qt configure with msvc.net
    By jivanr in forum Installation and Deployment
    Replies: 1
    Last Post: 11th June 2007, 08:17
  4. Compile App using OpenGL and Visual Studios 2003
    By Rayven in forum General Programming
    Replies: 3
    Last Post: 26th April 2007, 15:43
  5. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.