Snake/src/Core/Crawl/guiobject.h

210 lines
6.3 KiB
C
Raw Normal View History

//#
//# Copyright (C) 2021-2021 QuasarApp.
//# Distributed under the GPLv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
2021-05-25 17:18:56 +03:00
#ifndef GUIOBJECT_H
#define GUIOBJECT_H
#include "QObject"
2021-06-02 18:29:07 +03:00
#include <QQuaternion>
2021-05-25 17:18:56 +03:00
#include <QRectF>
2021-06-02 18:29:07 +03:00
#include <QVector3D>
2021-06-16 16:10:14 +03:00
#include "Crawl/irender.h"
2021-05-25 17:18:56 +03:00
#define DEFAULT_VIEW_TEMPLATE "qrc:/CrawlModule/GraphicItem.qml"
2021-07-05 17:39:26 +03:00
namespace CRAWL {
2021-06-07 17:37:03 +03:00
/**
* @brief The GuiObject class This base model for gui objects.
2021-06-25 22:07:39 +03:00
*
* # Overriding Own gui objects.
*
* The gui objct contains base properties for drow objects on scane
* * position
* * ratation
* * mash
* * and map textures
*
* All properies implemented on the GraphicItem.qml file.
*
* If you want to change view for your own object then you need to ooverride the GuiObject::viewTemplate property and create a own qml file for view your changes.
*
* ### Example:
*
2021-06-25 22:15:24 +03:00
* Create a new qml file **OwnView.qml**
2021-06-25 22:07:39 +03:00
* ```qml
* import CrawlModule 1.0
*
* GraphicItem {
* // your own implementation
* }
* ```
*
* Override property in cpp object.
*
* ```cpp
* class MyObject: public IWorldItem {
* MyObject(): IWorldItem("name", "qrc:/path/to/OwnView.qml") {
* }
* }
* ```
2021-06-07 17:37:03 +03:00
*/
class CRAWL_EXPORT GuiObject: public QObject, virtual public IRender {
2021-05-25 17:18:56 +03:00
Q_OBJECT
Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(int guiId READ guiId NOTIFY guiIdChanged)
Q_PROPERTY(QString viewTemplate READ viewTemplate NOTIFY viewTemplateChanged)
2021-06-02 18:29:07 +03:00
Q_PROPERTY(QVector3D position READ position WRITE setposition NOTIFY positionChanged)
Q_PROPERTY(QVector3D size READ size WRITE setSize NOTIFY sizeChanged)
Q_PROPERTY(QQuaternion ratation READ ratation WRITE setRatation NOTIFY ratationChanged)
2021-05-25 17:18:56 +03:00
2021-06-02 18:29:07 +03:00
Q_PROPERTY(QString mash READ mash WRITE setMash NOTIFY mashChanged)
2021-05-25 17:18:56 +03:00
// textures
Q_PROPERTY(QString baseColorMap READ baseColorMap NOTIFY baseColorMapChanged)
Q_PROPERTY(QString roughnessMap READ roughnessMap NOTIFY roughnessMapChanged)
Q_PROPERTY(QString normalMap READ normalMap NOTIFY normalMapChanged)
Q_PROPERTY(QString emissiveMap READ emissiveMap NOTIFY emissiveMapChanged)
2021-05-25 17:18:56 +03:00
public:
GuiObject(const QString& name,
const QString& viewTempalte = DEFAULT_VIEW_TEMPLATE,
QObject *ptr = nullptr);
2021-05-25 17:18:56 +03:00
QString color() const;
void setColor(QString color);
virtual void reset();
QString viewTemplate() const;
2021-05-25 17:18:56 +03:00
int guiId() const;
void setGuiId(int guiId);
2021-05-25 17:18:56 +03:00
void setX(float newX);
void setY(float newY);
void setZ(float newZ);
2021-05-25 17:18:56 +03:00
void setDx(float newDx);
void setDy(float newDy);
void setDz(float newDz);
2021-06-02 18:29:07 +03:00
const QString &baseColorMap() const;
const QString &roughnessMap() const;
const QString &normalMap() const;
const QString &emissiveMap() const;
2021-06-02 18:29:07 +03:00
/**
* @brief center This method return center of object
* @return 3d point of the object center.
* @warning This method calc center in runtime.
*/
QVector3D center() const;
2021-06-02 18:29:07 +03:00
/**
* @brief intersects This method check if this object contains @a point object.
* @param point This is checked point
* @return true if the point contains in the object cube.
2021-06-07 17:37:03 +03:00
* @warning This functions check intersect approximate and only works correctly for cubic objects. if you try compare plane objects or lines you get incorrect results.
2021-06-02 18:29:07 +03:00
*/
bool intersects(const QVector3D& point) const;
2021-06-07 17:37:03 +03:00
/**
* @brief intersects This method check intersects betwin current object and @a object.
* @param object This is input object.
* @return true if the two objects has common points.
* @warning This functions check intersect approximate and only works correctly for cubic objects. if you try compare plane objects or lines you get incorrect results.
*/
bool intersects(const GuiObject& object) const;
2021-06-02 18:29:07 +03:00
const QVector3D &position() const;
void setposition(const QVector3D &newposition);
2021-06-02 18:29:07 +03:00
const QVector3D &size() const;
void setSize(const QVector3D &newSize);
2021-05-25 17:18:56 +03:00
2021-06-02 18:29:07 +03:00
const QQuaternion &ratation() const;
void setRatation(const QQuaternion &newRatation);
2021-05-25 17:18:56 +03:00
2021-06-02 18:29:07 +03:00
const QString &mash() const;
void setMash(const QString &newMash);
2021-05-25 17:18:56 +03:00
/**
* @brief className This method return class name.
* The class name using as a group of objects on thw world.
* @return class name;
* @note the class name should be sets on the consturctor of child classes of this class.
*/
const QString &className() const;
2021-05-25 17:18:56 +03:00
signals:
void guiIdChanged(int guiId);
void colorChanged(QString color);
void viewTemplateChanged(QString viewTemplate);
void baseColorMapChanged();
void roughnessMapChanged();
void normalMapChanged();
void emissiveMapChanged();
2021-06-02 18:29:07 +03:00
void positionChanged();
void sizeChanged();
void ratationChanged();
void mashChanged();
protected:
2021-06-25 22:07:39 +03:00
2021-07-10 19:16:24 +03:00
/**
* @brief setBaseColorMap This method sets path to the base color map of the object. See the baseColorMap method for get more information.
* @param baseColorMap This is new value of the path to base color map.
*/
void setBaseColorMap(const QString& baseColorMap);
/**
* @brief setRoughnessMap This method sets path to the roughness map of the object. See the roughnessMap method for get more information.
* @param roughnessMap This is new value of the path to roughness map.
*/
void setRoughnessMap(const QString& roughnessMap);
/**
* @brief setNormalMap This method sets path to the normal map of the object. See the normalMap method for get more information.
* @param normalMap This is new value of the path to normal map.
*/
void setNormalMap(const QString& normalMap);
/**
* @brief setEmissiveMap This method sets path to the emissive map of the object. See the emissiveMap method for get more information.
* @param emissiveMap This is new value of the path to emissive map.
*/
void setEmissiveMap(const QString& emissiveMap);
private:
void generateId();
2021-07-10 19:16:24 +03:00
int _guiId = -1;
QString _color = "#ff1111";
QString _baseColorMap;
QString _roughnessMap;
QString _normalMap;
QString _emissiveMap;
QString _viewTemplate;
2021-06-02 18:29:07 +03:00
QVector3D _position;
QVector3D _size;
QQuaternion _ratation;
QString _mash;
QString _className;
2021-05-25 17:18:56 +03:00
};
2021-07-05 17:39:26 +03:00
}
2021-05-25 17:18:56 +03:00
#endif // GUIOBJECT_H