Results 1 to 9 of 9

Thread: Rotate GraphicsObjects

  1. #1
    Join Date
    Nov 2019
    Posts
    6
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default Rotate GraphicsObjects

    Hi,

    i am able to paint/add i.e. rectangles as graphicsobject in a scene/graphicsview.

    now i wanted to rotate them and i tried with transform.rotate() and it works with all items or a single item.

    but now i want to rotate 4 of the rectangles combined as a cube (without botton & top).

    how can i archieve this?

    regards

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Rotate GraphicsObjects

    Create a QGraphicsItemGroup and add your rectangles to it. You can then transform the group in the same way you transform a single object.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Nov 2019
    Posts
    6
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default Re: Rotate GraphicsObjects

    Ok, now i can group the items, but ...

    ... i think it is more a mathematical problem ...

    i have to arrange the items in a square (from top-view).

    but the items have to be rotated to do this, but the rotation point is not in 2D.

    Cube01.png
    Last edited by FlyingEagle; 20th November 2019 at 12:51.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Rotate GraphicsObjects

    Qt Graphics / View is 2D only, so you are going to have to define your "rectangles" as parallelograms. You will have to transform rectangles in 3D, then project the rectangle coordinates onto the 2D plane, which will yield parallelograms.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Nov 2019
    Posts
    6
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default Re: Rotate GraphicsObjects

    Quote Originally Posted by d_stranz View Post
    You will have to transform rectangles in 3D
    And how can I archive this?

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Rotate GraphicsObjects

    Google is your friend. Try "3d graphics transformation". You may be able to find a third-party library to do this. But basically, you must build your model as a 3D object, transform it to the desired orientation, then project the 3D x-y-z coordinates onto a 2D x-y plane.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #7
    Join Date
    Mar 2010
    Posts
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotate GraphicsObjects

    There is a section on 3D rotations about an arbitrary axis in my book "Computer Graphics Programming in C++/Qt", available as e-book and as paperback on Amazon/Kindle. Even without buying the book, you can find the C++/Qt code from https://github.com/LAmmeraal/. Just look at the file edit3d.pro to see which source files are relevant. The files rota3d.cpp and rota3d.h deal with rotations. If you use Windows, you can immediately try the executable file edit3d.exe, using the Edit menu. The above book explains all this in more detail.
    Best wishes,
    Leen Ammeraal
    Last edited by lamm; 26th November 2019 at 18:38.

  8. The following user says thank you to lamm for this useful post:

    d_stranz (26th November 2019)

  9. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Rotate GraphicsObjects

    Computer Graphics Programming in C++/Qt
    Thanks! You just sold a book.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  10. #9
    Join Date
    Mar 2010
    Posts
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotate GraphicsObjects

    Quote Originally Posted by d_stranz View Post
    Thanks! You just sold a book.
    If it is Okay or better, please tell others; if not, tell me.

Similar Threads

  1. How to rotate a QSlider?
    By Gokulnathvc in forum Newbie
    Replies: 5
    Last Post: 4th January 2018, 00:22
  2. how can i rotate a text ?
    By savaliya_ambani in forum Qt for Embedded and Mobile
    Replies: 9
    Last Post: 11th June 2010, 13:52
  3. How to rotate the control?
    By tszzp in forum Qt Programming
    Replies: 9
    Last Post: 25th November 2009, 10:05
  4. rotate in QState
    By estel in forum Qt Programming
    Replies: 0
    Last Post: 21st October 2009, 13:39
  5. Rotate a QRectF
    By whitefurrows in forum Qt Programming
    Replies: 5
    Last Post: 15th July 2009, 16:33

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.