PDA

View Full Version : Rotate GraphicsObjects



FlyingEagle
20th November 2019, 01:48
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

d_stranz
20th November 2019, 06:09
Create a QGraphicsItemGroup and add your rectangles to it. You can then transform the group in the same way you transform a single object.

FlyingEagle
20th November 2019, 09:03
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.

13289

d_stranz
21st November 2019, 05:46
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.

FlyingEagle
21st November 2019, 16:04
You will have to transform rectangles in 3D

And how can I archive this?

d_stranz
21st November 2019, 17:39
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.

lamm
26th November 2019, 12:39
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

d_stranz
26th November 2019, 21:18
Computer Graphics Programming in C++/Qt

Thanks! You just sold a book.

lamm
27th November 2019, 05:41
Thanks! You just sold a book.

If it is Okay or better, please tell others; if not, tell me.