diff --git a/src/ClientLib/SnakeProject.qrc b/src/ClientLib/SnakeProject.qrc index 425a807..f707cfe 100644 --- a/src/ClientLib/SnakeProject.qrc +++ b/src/ClientLib/SnakeProject.qrc @@ -12,6 +12,8 @@ <file>SnakeProjectModule/Scene.qml</file> <file>SnakeProjectModule/SettingsView.qml</file> <file>SnakeProjectModule/SnakeItem.qml</file> + <file>SnakeProjectModule/3dPrimitive.qml</file> + <file>SnakeProjectModule/AbstractItem.qml</file> </qresource> <qresource prefix="/SnakeTr"> <file>languages/en.qm</file> diff --git a/src/ClientLib/SnakeProject/guiobject.cpp b/src/ClientLib/SnakeProject/guiobject.cpp index 419c576..4aec8d4 100644 --- a/src/ClientLib/SnakeProject/guiobject.cpp +++ b/src/ClientLib/SnakeProject/guiobject.cpp @@ -66,7 +66,7 @@ void GuiObject::generateId() { void GuiObject::setH(double h) { m_h = h; - emit hChanged(m_h); + emit hChanged(); } void GuiObject::reset() { @@ -92,19 +92,19 @@ void GuiObject::setRadius(int radius) { void GuiObject::setW(double w) { m_w = w; - emit wChanged(m_w); + emit wChanged(); } void GuiObject::setY(double y) { m_y = y; - emit yChanged(m_y); + emit yChanged(); } void GuiObject::setX(double x) { m_x = x; - emit xChanged(m_x); + emit xChanged(); } diff --git a/src/ClientLib/SnakeProject/guiobject.h b/src/ClientLib/SnakeProject/guiobject.h index dc903ef..07ad69f 100644 --- a/src/ClientLib/SnakeProject/guiobject.h +++ b/src/ClientLib/SnakeProject/guiobject.h @@ -80,10 +80,10 @@ signals: void textureChanged(QString texture); void guiIdChanged(int guiId); void colorChanged(QString color); - void xChanged(double x); - void yChanged(double y); - void wChanged(double w); - void hChanged(double h); + void xChanged(); + void yChanged(); + void wChanged(); + void hChanged(); void radiusChanged(int radius); void viewTemplateChanged(QString viewTemplate); }; diff --git a/src/ClientLib/SnakeProject/guiobject3d.cpp b/src/ClientLib/SnakeProject/guiobject3d.cpp new file mode 100644 index 0000000..039d410 --- /dev/null +++ b/src/ClientLib/SnakeProject/guiobject3d.cpp @@ -0,0 +1,54 @@ +#include "guiobject3d.h" + + +GuiObject3D::GuiObject3D(const QString &viewTempalte, QObject *ptr): + GuiObject(viewTempalte, ptr) { + +} + +double GuiObject3D::z() const { + return _z; +} + +double GuiObject3D::scaleZ() const { + return _scaleZ; +} + +void GuiObject3D::setZ(double z) { + if (z == _z){ + return; + } + + _z = z; + emit zChanged(); +} + +void GuiObject3D::setScaleZ(double scaleFactor) { + if (scaleFactor == _scaleZ){ + return; + } + + _scaleZ = scaleFactor; + emit scaleZChanged(); +} + +void GuiObject3D::setMash(const QString &mash) { + if (mash == _mash){ + return; + } + + _mash = mash; + emit mashChanged(); +} + +QString GuiObject3D::mash() const { + return _mash; +} + +double GuiObject3D::scaleX() const { + return h(); +} + +double GuiObject3D::scaleY() const { + return w(); +} diff --git a/src/ClientLib/SnakeProject/guiobject3d.h b/src/ClientLib/SnakeProject/guiobject3d.h new file mode 100644 index 0000000..f319630 --- /dev/null +++ b/src/ClientLib/SnakeProject/guiobject3d.h @@ -0,0 +1,93 @@ +#ifndef GUIOBJECT3D_H +#define GUIOBJECT3D_H + +#include "guiobject.h" + +/** + * @brief The GuiObject3D class This is 3d implementation of the Qt Quick 3d engine objects. + */ +class GuiObject3D : public GuiObject { + Q_OBJECT + + Q_PROPERTY(double z READ z NOTIFY zChanged) + Q_PROPERTY(double scaleZ READ scaleZ NOTIFY scaleZChanged) + Q_PROPERTY(double scaleX READ scaleX NOTIFY hChanged) + Q_PROPERTY(double scaleY READ scaleY NOTIFY wChanged) + + Q_PROPERTY(QString mash READ mash NOTIFY mashChanged) + +public: + GuiObject3D(const QString& viewTempalte = "GraphicItem", QObject *ptr = nullptr); + + /** + * @brief z this is z axis + * @return return z position of the object. + */ + double z() const; + + /** + * @brief scaleZ This is size object of the z axis. + * @return return size of z axis + */ + double scaleZ() const; + + /** + * @brief mash This method return path to mash of the 3d object. + * @return Path of the mash object. + * @note for preparew mash use the obj file in Blender and convert obj files to mash using **balsam** tool. + */ + QString mash() const; + + /** + * @brief setZ This method sets new z point of object. + * @param z this is new oint of z + */ + void setZ(double z); + + /** + * @brief setScaleZ This method sets new scale fcator of object. + * @param scaleFactor new value of the scale factor. + */ + void setScaleZ(double scaleFactor); + + /** + * @brief setMash This method sets new path to mash object. For create mash object use the balsam tool. + * @param mash This is path to mash object. + */ + void setMash(const QString& mash); + + /** + * @brief scaleX This method is simple wraper of the w property. + * @return width of the object. + */ + double scaleX() const; + + /** + * @brief scaleY This metthod is simple wraper of the h proprty. + * @return return height of the object. + */ + double scaleY() const; + +signals: + /** + * @brief zChanged This signal emmited when z point changed. + */ + void zChanged(); + + /** + * @brief scaleZChanged This signale emited when sale factor of the z axis are changed. + */ + void scaleZChanged(); + + /** + * @brief mashChanged + */ + void mashChanged(); + +private: + double _z = 0; + double _scaleZ = 1; + QString _mash = "#Cube"; +}; + +#endif // GUIOBJECT3D_H diff --git a/src/ClientLib/SnakeProject/head.cpp b/src/ClientLib/SnakeProject/head.cpp index 3701d32..de8c81c 100644 --- a/src/ClientLib/SnakeProject/head.cpp +++ b/src/ClientLib/SnakeProject/head.cpp @@ -29,7 +29,7 @@ void Head::render() { } - emit yChanged(m_y); + emit yChanged(); } void Head::reset() { diff --git a/src/ClientLib/SnakeProject/itemworld.cpp b/src/ClientLib/SnakeProject/itemworld.cpp index 5a1e24d..b57387c 100644 --- a/src/ClientLib/SnakeProject/itemworld.cpp +++ b/src/ClientLib/SnakeProject/itemworld.cpp @@ -29,14 +29,14 @@ void ItemWorld::render() { if (m_x + w() < 0) { m_x = (rand() % 400) + 200; m_y = rand() % 100; - emit xChanged(m_x); - emit yChanged(m_y); + emit xChanged(); + emit yChanged(); } } bool ItemWorld::move(const GuiObject *snakeRiger, double dx) { m_x -= dx; - emit xChanged(m_x); + emit xChanged(); return snakeRiger->rect().intersects(rect()) && !beckGroundObject; } diff --git a/src/ClientLib/SnakeProject/itemworld.h b/src/ClientLib/SnakeProject/itemworld.h index 6159eaf..2840eb8 100644 --- a/src/ClientLib/SnakeProject/itemworld.h +++ b/src/ClientLib/SnakeProject/itemworld.h @@ -16,7 +16,7 @@ protected: public: ItemWorld(double x, double y, const QString& GuiTemplate = "GraphicItem"); - void render(); + void render() override; virtual bool move(const GuiObject* snakeRiger, double dx); bool isBeckGroundObject(); diff --git a/src/ClientLib/SnakeProjectModule/3dPrimitive.qml b/src/ClientLib/SnakeProjectModule/3dPrimitive.qml new file mode 100644 index 0000000..0431c23 --- /dev/null +++ b/src/ClientLib/SnakeProjectModule/3dPrimitive.qml @@ -0,0 +1,25 @@ +import QtQuick +import QtQuick3D + +Node { + id: rootNode + + property var model: null + + Model { + id: suzanne + rotation: Qt.quaternion(0.707107, -0.707107, 0, 0) + scale.x: 100 + scale.y: 100 + scale.z: 100 + source: "meshes/suzanne.mesh" + + DefaultMaterial { + id: material_001_material + diffuseColor: "#ffcccccc" + } + materials: [ + material_001_material + ] + } +} diff --git a/src/ClientLib/SnakeProjectModule/AbstractItem.qml b/src/ClientLib/SnakeProjectModule/AbstractItem.qml new file mode 100644 index 0000000..3015828 --- /dev/null +++ b/src/ClientLib/SnakeProjectModule/AbstractItem.qml @@ -0,0 +1,6 @@ +import QtQuick + +Item { + property var model: null + property int guiId: (model) ? model.guiId : -1; +} diff --git a/src/ClientLib/SnakeProjectModule/GraphicItem.qml b/src/ClientLib/SnakeProjectModule/GraphicItem.qml index bd94564..6cf3c37 100644 --- a/src/ClientLib/SnakeProjectModule/GraphicItem.qml +++ b/src/ClientLib/SnakeProjectModule/GraphicItem.qml @@ -1,33 +1,39 @@ import QtQuick -Rectangle { +AbstractItem { id: graphicItem - property var model: null property real angle: (model) ? model.angle : 0; property string texture: (model) ? model.texture : ""; - property int guiId: (model) ? model.guiId : -1; - z:-1 property double devX: width / 2 property double devY: height / 2 - Image { - id: name - visible: texture.length - source: texture + property alias color: privateRoot.color + property alias radius: privateRoot.radius + + Rectangle { + id: privateRoot + Image { + id: name + visible: texture.length + source: texture + + anchors.fill: parent; + } + + color: (model) ? model.color : "#11ff32"; + + radius: (model) ? model.radius * metrix.gamePt : 0; + anchors.fill: parent - anchors.fill: parent; } - color: (model) ? model.color : "#11ff32"; - width: (model) ? model.w * metrix.gamePt: 0; height: (model) ? model.h * metrix.gamePt: 0; x: (model) ? model.x * metrix.gamePt - devX: 0; y: (model) ? model.y * metrix.gamePt - devY: 0; - - radius: (model) ? model.radius * metrix.gamePt : 0; + z:-1 transform: Rotation { origin.x: devX; @@ -36,3 +42,4 @@ Rectangle { } } + diff --git a/src/ClientLib/SnakeProjectModule/Scene.qml b/src/ClientLib/SnakeProjectModule/Scene.qml index b8b85be..8f80973 100644 --- a/src/ClientLib/SnakeProjectModule/Scene.qml +++ b/src/ClientLib/SnakeProjectModule/Scene.qml @@ -1,9 +1,10 @@ import QtQuick +import QtQuick3D import QtQuick.Controls.Material import QtQuick.Controls import QtQuick.Layouts -Item { +View3D { id: scene; z: -2 @@ -49,7 +50,7 @@ Item { obj.z = -2; arrayObjects.push(obj) } else { - console.log("wrong viewTemplate in model"); + console.log("wrong viewTemplate in model. Message: " + temp.errorString()); } } @@ -80,6 +81,16 @@ Item { } } + PerspectiveCamera { + id: camera + position: Qt.vector3d(0, 200, 300) + eulerRotation.x: -30 + } + + DirectionalLight { + eulerRotation.x: -30 + } + Timer { id: autoTimer; repeat: true; diff --git a/src/ClientLib/SnakeProjectModule/SnakeItem.qml b/src/ClientLib/SnakeProjectModule/SnakeItem.qml index eb1d281..02cecd2 100644 --- a/src/ClientLib/SnakeProjectModule/SnakeItem.qml +++ b/src/ClientLib/SnakeProjectModule/SnakeItem.qml @@ -1,7 +1,6 @@ import QtQuick GraphicItem { - Behavior on color { ColorAnimation { duration: 2000