Question

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)?

Was it helpful?

Solution

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.

QGLCube Class Reference

There is actually even a 3D base QML item in there exposed if you are willing to go down that way:

QML Item3D Element

OTHER TIPS

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.

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top