Reputation: 5345
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)?
Upvotes: 4
Views: 1064
Reputation: 53215
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:
Upvotes: 3
Reputation: 21250
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.
Upvotes: 1
Reputation: 9789
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).
Upvotes: 0