Basically, the tile sums up the question - I am wondering if there is any build in qt class similar to QRect, but for 3D object (to describe a box rather then rectangle)?
-
Is this for real-time graphics with OpenGL? If so, I would not attempt to build a 3D object with Qt's built-in classes. – Cameron Tinker Nov 22 '13 at 19:15
-
No, it is purely to define 3D region internally, to pass it around and add/subtract such regions. Application is console, and deals with generating random point inside 3D region and such - wont to attempt render anything on the screen. – Ilya Kobelevskiy Nov 22 '13 at 19:25
-
@IlyaKobelevskiy: have you taken a look at Qt3D? – László Papp Jan 13 '14 at 17:46
3 Answers
Basically, the tile sums up the question - I am wondering if there is any build in qt class similar to QRect, but for 3D object (to describe a box rather then rectangle)?
Sure, there is.
The desired class is currently in Qt3D, although it is not yet re-released again with Qt 5.
I have been an active user of this class in 3D world simulation projects, and it works pretty okay.
There is actually even a 3D base QML item in there exposed if you are willing to go down that way:

- 51,870
- 39
- 111
- 135
-
Thanks, that looks interesting, I was not aware of Qt3D previously! – Ilya Kobelevskiy Jan 15 '14 at 15:08
Assuming that 3D rectangle is a 2D rectangle that has a height (Z axis), I would implement it (parallelepiped?) in the following way:
class Box: public QRect
{
public:
Box(int x, int y, int width, int height, int length)
:
QRect(x, y, width, height),
m_length(length)
{}
int length() const { return m_length; }
private:
int m_length;
};
Thus you have shape, that has width, height and length. I use length
as a third dimension parameter, because word height
is already reserved by QRect class.
You can, of course, extend this class, but I guess the main functionality is there.

- 20,808
- 3
- 47
- 55
If you're looking for a built-in class, I'm not sure if one exists, but you could build out your own class with a little knowledge of 3D vectors. The hardest functions might be intersection, translation, or implementing operators such as &
, &=
, |
, |=
, !=
, <<
, ==
, and >>
.
You might consider representing a box by its dimensions and its coordinates at the center of the box. Then you would have a box of a certain width, height, and depth centered about a 3D point at the origin (x,y,z).

- 9,634
- 10
- 46
- 85
-
Yes, that is what I was trying to avoid - implementing it myself :(. I'll wait a bit if anything else comes up, and accept this answer... – Ilya Kobelevskiy Nov 22 '13 at 19:27