base 3d support o

This commit is contained in:
Andrei Yankovich 2021-06-01 16:18:54 +03:00
parent 68fc713e2c
commit 2995397e81
13 changed files with 226 additions and 29 deletions

View File

@ -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>

View File

@ -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();
}

View File

@ -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);
};

View File

@ -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();
}

View File

@ -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

View File

@ -29,7 +29,7 @@ void Head::render() {
}
emit yChanged(m_y);
emit yChanged();
}
void Head::reset() {

View File

@ -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;
}

View File

@ -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();

View File

@ -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
]
}
}

View File

@ -0,0 +1,6 @@
import QtQuick
Item {
property var model: null
property int guiId: (model) ? model.guiId : -1;
}

View File

@ -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 {
}
}

View File

@ -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;

View File

@ -1,7 +1,6 @@
import QtQuick
GraphicItem {
Behavior on color {
ColorAnimation {
duration: 2000