Answer the question
In order to leave comments, you need to log in
How to organize the storage of elements so that some can be referred to by name?
Hello.
There are a number of objects - 3D objects (class Object3D), Lines (Line_3D), Skyboxes (Skybox) and so on.
Let's say they are inherited from the Drawable class, which looks like this:
class Drawable{
public:
virtual void draw(QOpenGLFunctions * functions, Camera * camera, QMatrix4x4 projection_matrix) = 0;
};
// Где-то вне цикла отрисовки
QList<Drawable *> drawQueue;
// ...
void WidgetGL::paintGL() {
foreach (Drawable drawable, objList)
drawable.draw(context()->functions(),&_camera,m_projectionMatrix);
}
Line_3D * ox = new Line_3D(QVector3D(0.0,0.0,0.0),QVector3D(1.0,0.0,0.0),QVector3D(1.0,0.0,0.0));
Line_3D * oy = new Line_3D(QVector3D(0.0,0.0,0.0),QVector3D(0.0,1.0,0.0),QVector3D(0.0,1.0,0.0));
Line_3D * oz = new Line_3D(QVector3D(0.0,0.0,0.0),QVector3D(0.0,0.0,1.0),QVector3D(0.0,0.0,1.0));
drawQueue.append(dynamic_cast<Drawable*>(ox));
drawQueue.append(dynamic_cast<Drawable*>(oy));
drawQueue.append(dynamic_cast<Drawable*>(oz));
class SceneComponents : public QObject
{
Q_OBJECT
public:
explicit SceneComponents(QObject *parent = nullptr);
void addDrawable(Drawable * drawable);
QList<Drawable *> getDrawQueue() const;
private:
QList<Drawable *> drawQueue;
QList<Object3D *> _object3dList;
QList<Line_3D *> _line3dList;
QList<Skybox *> _skyboxList;
QList<Ray *> _rayList;
};
class SceneComponents : public QObject
{
Q_OBJECT
public:
explicit SceneComponents(QObject *parent = nullptr);
void addDrawable(Drawable * drawable);
QList<Drawable *> getDrawQueue() const;
private:
QList<Drawable *> drawQueue;
QList<Object3D *> _object3dList;
QList<Line_3D *> _line3dList;
QList<Skybox *> _skyboxList;
QList<Ray *> _rayList;
QMap<QString,Drawable*> _objectByName;
};
Answer the question
In order to leave comments, you need to log in
And you QMap<QString,Drawable*> _objectByName;
replace with QMap<Drawable*, QString> _objectByName;
Then the name can be empty, and you can get the object by name through the key (..) method
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question