4
1
mirror of https://github.com/QuasarApp/Snake.git synced 2025-05-13 01:49:44 +00:00

Merge pull request from QuasarApp/effects

Particles effects
This commit is contained in:
Andrei Yankovich 2021-08-03 23:21:57 +03:00 committed by GitHub
commit 68d1203d6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 2246 additions and 76 deletions

@ -11,8 +11,8 @@ set(CURRENT_PROJECT "${PROJECT_NAME}Core")
add_definitions(-DCRAWL_LIBRARY)
file(GLOB SOURCE_CPP
"*Crawl/*.cpp"
"*Extensions/*.cpp"
"Crawl/*.cpp"
"Extensions/*.cpp"
"private/*.cpp"
"*.qrc"
"Crawl/*.qrc"

@ -15,5 +15,14 @@
<file>CrawlModule/AbstractMenuView.qml</file>
<file>CrawlModule/Light.qml</file>
<file>CrawlModule/DayLight.qml</file>
<file>CrawlModule/particles/ParticleEffect.qml</file>
<file>CrawlModule/particles/CrawlVectorDirection.qml</file>
<file>CrawlModule/particles/CrawlTargetDirection.qml</file>
<file>CrawlModule/particles/FireParticel.qml</file>
<file>CrawlCoreAssets/particles/fireColorTable.png</file>
<file>CrawlCoreAssets/particles/sphere.png</file>
<file>CrawlCoreAssets/particles/smokeSprite.png</file>
<file>CrawlModule/particles/Fire.qml</file>
<file>CrawlModule/particles/Wint.qml</file>
</qresource>
</RCC>

@ -0,0 +1,32 @@
//#
//# 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.
//#
#include "affector.h"
namespace CRAWL {
Affector::Affector(const QString &name,
const QString &viewTempalte,
QObject *ptr) :
IWorldItem(name, viewTempalte, ptr)
{
}
bool Affector::enabled() const {
return _enabled;
}
void Affector::setEnabled(bool newEnabled) {
if (_enabled == newEnabled)
return;
_enabled = newEnabled;
emit enabledChanged();
}
}

79
src/Core/Crawl/affector.h Normal file

@ -0,0 +1,79 @@
#ifndef AFFECTOR_H
#define AFFECTOR_H
#include "iworlditem.h"
namespace CRAWL {
/**
* @brief The Affector class is an abstract base class of affectors like Gravity3D, Wander3D, and PointRotator3D. By default affectors affect all particles in the system,
* but this can be limited by defining the particles list.
* If the system has multiple affectors, the order of affectors may result in different outcome, as affectors are applied one after another.
*
* For custumisation your own Affectors you need to change the templateView qml file for your own class.
* @note For get more inforamtion about available qml affectors see the qt documentation [page](https://doc.qt.io/qt-6.1/qml-qtquick3d-particles3d-affector3d.html)
**Example of qml view file**
@code
Attractor3D {
property var model: null
property int guiId: (model) ? model.guiId : -1;
rotation: (model)? model.rotation: Qt.quaternion(0, 0, 0, 0)
scale: (model)? model.size: Qt.vector3d(0, 0, 0);
position: (model) ? model.position: Qt.vector3d(0,0,0);
visible: (model)? model.visible: false
enabled: (model)? model.enabled: false
positionVariation: Qt.vector3d(50, 50, 50)
duration: 3000
durationVariation: 1000
}
@endcode
*/
class CRAWL_EXPORT Affector : public IWorldItem
{
Q_OBJECT
/**
* @brief enabled if enabled is set to false, this affector will not alter any particles. Usually this is used to conditionally turn an affector on or off.
The default value is true.
*/
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
public:
Affector(const QString& name,
const QString& viewTempalte = DEFAULT_VIEW_TEMPLATE,
QObject *ptr = nullptr);
/**
* @brief enabled if enabled is set to false, this affector will not alter any particles. Usually this is used to conditionally turn an affector on or off.
The default value is true.
* @return true if the Affector is enabled else false.
*/
bool enabled() const;
/**
* @brief setEnabled This method enable or disable the affector object.
* @param newEnabled new value.
*/
void setEnabled(bool newEnabled);
signals:
/**
* @brief enabledChanged This signal emited when the object change own enabled status.
*/
void enabledChanged();
private:
bool _enabled = true;
};
}
#endif // AFFECTOR_H

@ -0,0 +1,60 @@
//#
//# 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.
//#
#include "dynamicwint.h"
namespace CRAWL {
DynamicWint::DynamicWint() {
}
void DynamicWint::render(unsigned int tbfMsec) {
_time += tbfMsec;
if (_time > _nextWintChange) {
setMagnitude(_baseMagnitude + (rand() % _magnitudeVariation) - _magnitudeVariation / 2 );
setDirection(QVector3D{static_cast<float>(rand()) - rand(), static_cast<float>(rand()) - rand(), static_cast<float>(rand()) - rand()} * _directionChangeMask);
_nextWintChange += ((rand() % 100) / 100.0f) * dayLengthSec() * 1000;
}
}
int DynamicWint::dayLengthSec() const {
return _dayLengthSec;
}
void DynamicWint::setDayLengthSec(int newDayLengthSec) {
_dayLengthSec = newDayLengthSec;
}
unsigned int DynamicWint::magnitudeVariation() const {
return _magnitudeVariation;
}
void DynamicWint::setMagnitudeVariation(unsigned int newMagnitudeVariation) {
_magnitudeVariation = newMagnitudeVariation;
}
unsigned int DynamicWint::baseMagnitude() const {
return _baseMagnitude;
}
void DynamicWint::setBaseMagnitude(unsigned int newBaseMagnitude) {
_baseMagnitude = newBaseMagnitude;
}
const QVector3D &DynamicWint::directionChangeMask() const {
return _directionChangeMask;
}
void DynamicWint::setDirectionChangeMask(const QVector3D &newDirectionChangeMask) {
_directionChangeMask = newDirectionChangeMask;
}
}

@ -0,0 +1,90 @@
//#
//# 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.
//#
#ifndef DYNAMICWINT_H
#define DYNAMICWINT_H
#include "wint.h"
namespace CRAWL {
/**
* @brief The DynamicWint class This implementation dynamicly change wint direction and magnituede per day.
*/
class CRAWL_EXPORT DynamicWint : public Wint
{
Q_OBJECT
public:
DynamicWint();
// IRender interface
public:
void render(unsigned int tbfMsec) override;
/**
* @brief dayLengthSec This method return length of the game day in real secs.
* @note by default this value is 360 sec
* @return length of the game day in real secs.
*/
int dayLengthSec() const;
/**
* @brief setDayLengthSec This method sets new value of the day length.
* @param newDayLongSec This is new value of the day length.
* @note For get more information see the dayLengthSec method.
*/
void setDayLengthSec(int newDayLengthSec);
/**
* @brief magnitudeVariation This method return curerent value of the magnitude variation.
* @return curerent value of the magnitude variation.
*/
unsigned int magnitudeVariation() const;
/**
* @brief setMagnitudeVariation This method sets magnitude variation; by default it is 10
* @param newMagnitudeVariation This is new value of the magitude
*/
void setMagnitudeVariation(unsigned int newMagnitudeVariation);
/**
* @brief baseMagnitude This method return current base magnitude of the wint. The wint will be changed dynamicly one time per day length to the magnitudeVariation
* @return curretn value of the base magnitude
*/
unsigned int baseMagnitude() const;
/**
* @brief setBaseMagnitude This method sets new value of the base magnitude of the wint.
* @param newBaseMagnitude this is new value of the base magnitude of the wint.
*/
void setBaseMagnitude(unsigned int newBaseMagnitude);
/**
* @brief directionChangeMask This method return current value of mask of the direction variation. By default the wint will be changed by x and y axis.
* @return curertn value of the directionChangeMask
*/
const QVector3D &directionChangeMask() const;
/**
* @brief setDirectionChangeMask This method sets mask of the direction variation. By default the wint will be changed by x and y axis.
* @param newDirectionChangeMask This is new value of the directionChangeMask
*/
void setDirectionChangeMask(const QVector3D &newDirectionChangeMask);
private:
int _dayLengthSec = 360;
unsigned int _nextWintChange = 0;
unsigned int _time = 0;
unsigned int _magnitudeVariation = 50;
unsigned int _baseMagnitude = 50;
QVector3D _directionChangeMask = {1, 1, 0};
};
}
#endif // DYNAMICWINT_H

55
src/Core/Crawl/fire.cpp Normal file

@ -0,0 +1,55 @@
//#
//# 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.
//#
#include "fire.h"
#include "vectordirection.h"
namespace CRAWL {
Fire::Fire(): ParticleEffect(AUTO_CLASS_NAME, "qrc:/CrawlModule/particles/Fire.qml") {
useDirectionVelosity({0, 0 , 10}, {10, 10, 0});
setParticleScale(1);
setParticleEndScale(3);
setParticleScaleVariation(3);
setLifeSpanVariation(500);
setColor("#ffaf2c");
setSize({1, 1, 1});
setposition({0,0,10});
setEnabled(true);
setParticleDelegate("qrc:/CrawlModule/particles/FireParticel.qml");
setFireStrength(100);
}
void CRAWL::Fire::onIntersects(const IWorldItem *) {
}
float Fire::fireStrength() const {
return _fireStrength;
}
void Fire::setFireStrength(float newFireStrength) {
if (qFuzzyCompare(_fireStrength, newFireStrength))
return;
_fireStrength = newFireStrength;
setEmitRate(10 + _fireStrength);
setLifeSpan(1000 + _fireStrength);
auto vel = static_cast<VectorDirection*>(velocity());
vel->setVelosityDirection({0, 0 , _fireStrength / 4});
vel->setVelosityDirectionValatility({10, 10, 0});
emit fireStrengthChanged();
}
}

59
src/Core/Crawl/fire.h Normal file

@ -0,0 +1,59 @@
//#
//# 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.
//#
#ifndef FIRE_H
#define FIRE_H
#include "particleeffect.h"
namespace CRAWL {
/**
* @brief The Fire class This is default implementation of the Fire on game.
*/
class Fire: public ParticleEffect
{
Q_OBJECT
/**
* @brief fireStrength This propertye chenge fire power. By Default it is 100.
*/
Q_PROPERTY(float fireStrength READ fireStrength WRITE setFireStrength NOTIFY fireStrengthChanged)
public:
Fire();
// IWorldItem interface
/**
* @brief fireStrength This method return current value of the Fire::fireStrength propertye.
* @return current value of the Fire::fireStrength propertye.
*/
float fireStrength() const;
/**
* @brief setFireStrength This method sets new value of the Fire::fireStrength propertye.
* @param newFireStrength This is new value of the Fire::fireStrength prpertye.
* @warning This method change the emitRate, lifeSpan and velosity propertyes of this objects,
*/
void setFireStrength(float newFireStrength);
signals:
/**
* @brief fireStrengthChanged This signal emited when the Fire::fireStrength propertye is changed.
*/
void fireStrengthChanged();
protected:
void onIntersects(const IWorldItem *item);
private:
float _fireStrength = 0;
};
}
#endif // FIRE_H

@ -21,7 +21,7 @@ void GroupObject::render(unsigned int tbfMsec) {
for (ClasterItem* object: objects()) {
if (LocalPropertyes *props = getLocalPropertyes(object->guiId())) {
if (Localpropertys *props = getLocalpropertys(object->guiId())) {
if (!props->_rotation.isNull())
object->setRotation(_this->rotation() * props->_rotation);
@ -41,32 +41,32 @@ void GroupObject::installObject(ClasterItem *object,
}
void GroupObject::updatePosition(int id, const QVector3D &position) {
_extraPropertyes[id]._position = position;
_extrapropertys[id]._position = position;
}
void GroupObject::updateRotation(int id, const QQuaternion &roatation) {
_extraPropertyes[id]._rotation = roatation;
_extrapropertys[id]._rotation = roatation;
}
QQuaternion *GroupObject::getLocalrotation(int id) {
if (_extraPropertyes.contains(id)) {
return &_extraPropertyes[id]._rotation;
if (_extrapropertys.contains(id)) {
return &_extrapropertys[id]._rotation;
}
return nullptr;
}
QVector3D *GroupObject::getLocalPosition(int id) {
if (_extraPropertyes.contains(id)) {
return &_extraPropertyes[id]._position;
if (_extrapropertys.contains(id)) {
return &_extrapropertys[id]._position;
}
return nullptr;
}
LocalPropertyes *GroupObject::getLocalPropertyes(int id) {
if (_extraPropertyes.contains(id)) {
return &_extraPropertyes[id];
Localpropertys *GroupObject::getLocalpropertys(int id) {
if (_extrapropertys.contains(id)) {
return &_extrapropertys[id];
}
return nullptr;

@ -16,9 +16,9 @@
namespace CRAWL {
/**
* @brief The LocalPropertyes struct This structure contains local propertyes of the all childs object of a GroupObject class object.
* @brief The Localpropertys struct This structure contains local propertys of the all childs object of a GroupObject class object.
*/
struct LocalPropertyes {
struct Localpropertys {
QVector3D _position = {0,0,0};
QQuaternion _rotation = {};
};
@ -72,7 +72,7 @@ public:
* @param localPosition This is local position of the @a object. The default value is current object center.
* @param localRotation This is local rotation of the @a object. The default value is invalid quaternion and will be ignored..
* @note The @a object should be disable own render method of a render method
* or @a object should not be change position and rotation propertyes
* or @a object should not be change position and rotation propertys
* @note if you want to ignore the local rotation functionality then set the @a localRotation argument to invalid or default value.
*/
void installObject(ClasterItem* object,
@ -112,16 +112,16 @@ protected:
QVector3D* getLocalPosition(int id);
/**
* @brief getLocalPropertyes This method return all local propertyes of an object with @a id
* @brief getLocalpropertys This method return all local propertys of an object with @a id
* @param id This is id of the object for getting changes.
* @return pointer to structure with local propertyes of the object. IF the object with id not exists on this classter then return nullptr.
* @return pointer to structure with local propertys of the object. IF the object with id not exists on this classter then return nullptr.
* @warning use this return not const pointer and you can change them value but this is not thread safe.
*/
LocalPropertyes* getLocalPropertyes(int id);
Localpropertys* getLocalpropertys(int id);
private:
QHash<int, LocalPropertyes> _extraPropertyes;
QHash<int, Localpropertys> _extrapropertys;
};
}

@ -13,8 +13,7 @@ namespace CRAWL {
GuiObject::GuiObject(const QString &name, const QString &viewTempalte, QObject *ptr):
QObject (ptr) {
_viewTemplate = viewTempalte;
ViewTemaplateModel (viewTempalte, ptr) {
_className = name;
generateId();
setRotation(QQuaternion::fromEulerAngles({0,0,0}));
@ -58,10 +57,6 @@ void GuiObject::reset() {
setZ(0);
}
QString GuiObject::viewTemplate() const {
return _viewTemplate;
}
int GuiObject::guiId() const {
return _guiId;
}

@ -8,7 +8,7 @@
#ifndef GUIOBJECT_H
#define GUIOBJECT_H
#include "QObject"
#include "viewtemaplatemodel.h"
#include <QQuaternion>
#include <QRectF>
@ -58,11 +58,10 @@ namespace CRAWL {
* }
* ```
*/
class CRAWL_EXPORT GuiObject: public QObject, virtual public IRender {
class CRAWL_EXPORT GuiObject: public ViewTemaplateModel, virtual public IRender {
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)
Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(QVector3D position READ position WRITE setposition NOTIFY positionChanged)
Q_PROPERTY(QVector3D size READ size WRITE setSize NOTIFY sizeChanged)
@ -86,10 +85,6 @@ public:
void setColor(const QString &color);
virtual void reset();
QString viewTemplate() const;
int guiId() const;
void setGuiId(int guiId);
void setX(float newX);
void setY(float newY);
@ -159,10 +154,12 @@ public:
*/
void setVisible(bool newVisible);
int guiId() const;
void setGuiId(int guiId);
signals:
void guiIdChanged(int guiId);
void colorChanged(QString color);
void viewTemplateChanged(QString viewTemplate);
void baseColorMapChanged();
void roughnessMapChanged();
@ -213,7 +210,6 @@ private:
QString _roughnessMap;
QString _normalMap;
QString _emissiveMap;
QString _viewTemplate;
QVector3D _position;
QVector3D _size;

@ -134,7 +134,7 @@ public:
/**
* @brief render this method recursive invoke all render functions of the all world items.
* The render function is main function of the SnakeEngine This method recal all propertyes of all objects.
* The render function is main function of the SnakeEngine This method recal all propertys of all objects.
*/
virtual void render(unsigned int tbfMsec) override;

@ -146,22 +146,22 @@ signals:
void castsShadowChanged();
/**
* @brief shadowFactorChanged This signal emits when the shadowFactor propertye has changed.
* @brief shadowFactorChanged This signal emits when the shadowFactor property has changed.
*/
void shadowFactorChanged();
/**
* @brief shadowFilterChanged This signal emits when the shadowFilter propertye has changed.
* @brief shadowFilterChanged This signal emits when the shadowFilter property has changed.
*/
void shadowFilterChanged();
/**
* @brief shadowMapFarChanged This signal emits when the shadowMapFar propertye has changed.
* @brief shadowMapFarChanged This signal emits when the shadowMapFar property has changed.
*/
void shadowMapFarChanged();
/**
* @brief shadowBiasChanged This signal emits when the shadowBias propertye has changed.
* @brief shadowBiasChanged This signal emits when the shadowBias property has changed.
*/
void shadowBiasChanged();

@ -0,0 +1,274 @@
//#
//# 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.
//#
#include "particleeffect.h"
#include "targetdirection.h"
#include "vectordirection.h"
namespace CRAWL {
ParticleEffect::ParticleEffect(const QString &name,
const QString &viewTempalte,
QObject *ptr):
IWorldItem(name, viewTempalte, ptr) {
}
bool ParticleEffect::enabled() const {
return _enabled;
}
void ParticleEffect::setEnabled(bool newEnabled) {
if (_enabled == newEnabled)
return;
_enabled = newEnabled;
emit enabledChanged();
}
float ParticleEffect::emitRate() const {
return _emitRate;
}
void ParticleEffect::setEmitRate(float newEmitRate) {
if (qFuzzyCompare(_emitRate, newEmitRate))
return;
_emitRate = newEmitRate;
emit emitRateChanged();
}
float ParticleEffect::depthBias() const {
return _depthBias;
}
void ParticleEffect::setDepthBias(float newDepthBias) {
if (qFuzzyCompare(_depthBias, newDepthBias))
return;
_depthBias = newDepthBias;
emit depthBiasChanged();
}
int ParticleEffect::lifeSpan() const {
return _lifeSpan;
}
void ParticleEffect::setLifeSpan(int newLifeSpan) {
if (_lifeSpan == newLifeSpan)
return;
_lifeSpan = newLifeSpan;
emit lifeSpanChanged();
}
int ParticleEffect::lifeSpanVariation() const {
return _lifeSpanVariation;
}
void ParticleEffect::setLifeSpanVariation(int newLifeSpanVariation) {
if (_lifeSpanVariation == newLifeSpanVariation)
return;
_lifeSpanVariation = newLifeSpanVariation;
emit lifeSpanVariationChanged();
}
float ParticleEffect::particleEndScale() const {
return _particleEndScale;
}
void ParticleEffect::setParticleEndScale(float newParticleEndScale) {
if (qFuzzyCompare(_particleEndScale, newParticleEndScale))
return;
_particleEndScale = newParticleEndScale;
emit particleEndScaleChanged();
}
const QVector3D &ParticleEffect::particleRotationVariation() const {
return _particleRotationVariation;
}
void ParticleEffect::setParticleRotationVariation(const QVector3D &newParticleRotationVariation) {
if (_particleRotationVariation == newParticleRotationVariation)
return;
_particleRotationVariation = newParticleRotationVariation;
emit particleRotationVariationChanged();
}
const QVector3D &ParticleEffect::particleRotationVelocity() const {
return _particleRotationVelocity;
}
void ParticleEffect::setParticleRotationVelocity(const QVector3D &newParticleRotationVelocity) {
if (_particleRotationVelocity == newParticleRotationVelocity)
return;
_particleRotationVelocity = newParticleRotationVelocity;
emit particleRotationVelocityChanged();
}
const QVector3D &ParticleEffect::particleRotationVelocityVariation() const {
return _particleRotationVelocityVariation;
}
void ParticleEffect::setParticleRotationVelocityVariation(const QVector3D &newParticleRotationVelocityVariation) {
if (_particleRotationVelocityVariation == newParticleRotationVelocityVariation)
return;
_particleRotationVelocityVariation = newParticleRotationVelocityVariation;
emit particleRotationVelocityVariationChanged();
}
float ParticleEffect::particleScale() const {
return _particleScale;
}
void ParticleEffect::setParticleScale(float newParticleScale) {
if (qFuzzyCompare(_particleScale, newParticleScale))
return;
_particleScale = newParticleScale;
emit particleScaleChanged();
}
float ParticleEffect::particleScaleVariation() const {
return _particleScaleVariation;
}
void ParticleEffect::setParticleScaleVariation(float newParticleScaleVariation) {
if (qFuzzyCompare(_particleScaleVariation, newParticleScaleVariation))
return;
_particleScaleVariation = newParticleScaleVariation;
emit particleScaleVariationChanged();
}
const QString &ParticleEffect::particleDelegate() const {
return _particleDelegate;
}
void ParticleEffect::setParticleDelegate(const QString &newParticleDelegate) {
if (_particleDelegate == newParticleDelegate)
return;
_particleDelegate = newParticleDelegate;
emit particleDelegateChanged();
}
QObject *ParticleEffect::velocity() const {
return _velocity;
}
QVector3D ParticleEffect::brust(int count,
int duration,
const QVector3D &position) const {
QVector3D result = {0,0,0};
if (!viewObject()) {
QuasarAppUtils::Params::log("Failed to brust particles because the viewObject is empty.");
return result;
}
QMetaObject::invokeMethod(viewObject(),
"brust",
Qt::DirectConnection,
Q_RETURN_ARG(QVector3D, result),
Q_ARG(int, count),
Q_ARG(int, duration),
Q_ARG(QVector3D, position));
return result;
}
QVector3D ParticleEffect::brust(int count, int duration) const {
QVector3D result = {0,0,0};
if (!viewObject()) {
QuasarAppUtils::Params::log("Failed to brust particles because the viewObject is empty.");
return result;
}
QMetaObject::invokeMethod(viewObject(),
"brust",
Qt::DirectConnection,
Q_RETURN_ARG(QVector3D, result),
Q_ARG(int, count),
Q_ARG(int, duration));
return result;
}
QVector3D ParticleEffect::brust(int count) const {
QVector3D result = {0,0,0};
if (!viewObject()) {
QuasarAppUtils::Params::log("Failed to brust particles because the viewObject is empty.");
return result;
}
QMetaObject::invokeMethod(viewObject(),
"brust",
Qt::DirectConnection,
Q_RETURN_ARG(QVector3D, result),
Q_ARG(int, count));
return result;
}
void ParticleEffect::setVelocity(QObject *newVelocity) {
if (_velocity == newVelocity)
return;
_velocity = newVelocity;
emit velocityChanged();
}
const QVector3D &ParticleEffect::particleRotation() const {
return _particleRotation;
}
void ParticleEffect::setParticleRotation(const QVector3D &newParticleRotation) {
if (_particleRotation == newParticleRotation)
return;
_particleRotation = newParticleRotation;
emit particleRotationChanged();
}
const QString &ParticleEffect::particleShape() const {
return _particleShape;
}
void ParticleEffect::setParticleShape(const QString &newParticleShape) {
if (_particleShape == newParticleShape)
return;
_particleShape = newParticleShape;
emit particleShapeChanged();
}
void ParticleEffect::useDirectionVelosity(
const QVector3D& velosityDirection,
const QVector3D& velosityDirectionValatility) {
if (_velocity) {
_velocity->deleteLater();
}
setVelocity(new VectorDirection(velosityDirection, velosityDirectionValatility));
}
void ParticleEffect::useTargetVelosity(
float velosityMagnitude,
float velosityMagnitudeVariation,
bool velosityNormalized,
const QVector3D& velosityTargetPosition,
const QVector3D& velosityTargetPositionVariation) {
if (_velocity) {
_velocity->deleteLater();
}
setVelocity(new TargetDirection(velosityMagnitude,
velosityMagnitudeVariation,
velosityNormalized,
velosityTargetPosition,
velosityTargetPositionVariation));
};
}

@ -0,0 +1,570 @@
//#
//# 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.
//#
#ifndef PARTICLEEFFECT_H
#define PARTICLEEFFECT_H
#include "iworlditem.h"
namespace CRAWL {
/**
* @brief The ParticleEffect class This element emits logical particles into the ParticleSystem, with the given starting attributes.
At least one emitter is required to have particles in the ParticleSystem3D.
Please see the [qt](https://doc.qt.io/qt-6/qtquick3d-index.html) documentation for get more inforamtion
@note if you want that this effect alway shows then set the enabled property to true or invoke the brust method for singel show.
### Example:
@code{cpp}
Fire::Fire(): ParticleEffect(AUTO_CLASS_NAME, "qrc:/CrawlModule/particles/Fire.qml") {
useDirectionVelosity({0, 0 , 10}, {10, 10, 0});
setParticleScale(4);
setParticleEndScale(12);
setParticleScaleVariation(3);
setLifeSpanVariation(500);
setColor("#ffaf2c");
setSize({1, 1, 1});
setposition({0,0,10});
setEnabled(true);
setParticleDelegate("qrc:/CrawlModule/particles/FireParticel.qml");
setFireStrength(100);
}
@endcode
*/
class CRAWL_EXPORT ParticleEffect : public IWorldItem
{
Q_OBJECT
/**
* @brief enabled if enabled is set to false, this emitter will not emit any particles.
* Usually this is used to conditionally turn an emitter on or off. If you want to continue emitting burst,
* keep emitRate at 0 instead of toggling this to false. The default value is false.
*/
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
/**
* @brief emitRate This property defines the constant emitting rate in particles per second. For example, if the emitRate is 120 and system animates at 60 frames per second, 2 new particles are emitted at every frame.
* The default value is 0.
*/
Q_PROPERTY(float emitRate READ emitRate WRITE setEmitRate NOTIFY emitRateChanged)
/**
* @brief depthBias Holds the depth bias of the emitter. Depth bias is added to the object distance from camera when sorting objects. This can be used to force rendering order between objects close to each other, that might otherwise be rendered in different order in different frames. Negative values cause the sorting value to move closer to the camera while positive values move it further from the camera.
*/
Q_PROPERTY(float depthBias READ depthBias WRITE setDepthBias NOTIFY depthBiasChanged)
/**
* @brief lifeSpan This property defines the lifespan of a single particle in milliseconds.
* The default value is 1000.
* See also the lifeSpanVariation property.
*/
Q_PROPERTY(int lifeSpan READ lifeSpan WRITE setLifeSpan NOTIFY lifeSpanChanged)
/**
* @brief lifeSpanVariation This property defines the lifespan variation of a single particle in milliseconds.
* For example, to emit particles which will exist between 3 and 4 seconds:
* @code
lifeSpan: 3500
lifeSpanVariation: 500
@endcode
* The default value is 0.
*/
Q_PROPERTY(int lifeSpanVariation READ lifeSpanVariation WRITE setLifeSpanVariation NOTIFY lifeSpanVariationChanged)
/**
* @brief particleEndScale This property defines the scale multiplier of the particles at the end of particle lifeSpan.
* To have variation in the particle end sizes, use ParticleEffect::particleScaleVariation.
* When the value is negative, end scale is the same as the particleScale,
* so scale doesn't change during the particle lifeSpan.
* The default value is -1.0.
* See also ParticleEffect::particleScale and ParticleEffect::particleScaleVariation.
*/
Q_PROPERTY(float particleEndScale READ particleEndScale WRITE setParticleEndScale NOTIFY particleEndScaleChanged)
/**
* @brief particleRotationVariation This property defines the rotation variation of the particles in the beginning. Rotation variation is defined as degrees in euler angles.
* For example, to emit particles in fully random rotations: Qt.vector3d(180, 180, 180)
* See also ParticleEffect::particleRotation.
*/
Q_PROPERTY(QVector3D particleRotationVariation READ particleRotationVariation WRITE setParticleRotationVariation NOTIFY particleRotationVariationChanged)
/**
* @brief particleRotationVelocity This property defines the rotation velocity of the particles in the beginning.
* Rotation velocity is defined as degrees per second in euler angles.
* See also ParticleEffect::particleRotationVelocityVariation.
*/
Q_PROPERTY(QVector3D particleRotationVelocity READ particleRotationVelocity WRITE setParticleRotationVelocity NOTIFY particleRotationVelocityChanged)
/**
* @brief particleRotationVelocityVariation This property defines the rotation velocity variation of the particles.
* Rotation velocity variation is defined as degrees per second in euler angles.
* For example, to emit particles in random rotations which have random rotation velocity between -100 and 100
* degrees per second into any directions:
@code
particleRotationVariation: Qt.vector3d(180, 180, 180)
particleRotationVelocityVariation: Qt.vector3d(100, 100, 100)
@endcode
* See also ParticleEffect::particleRotationVelocity.
*/
Q_PROPERTY(QVector3D particleRotationVelocityVariation READ particleRotationVelocityVariation WRITE setParticleRotationVelocityVariation NOTIFY particleRotationVelocityVariationChanged)
/**
* @brief particleScale This property defines the scale multiplier of the particles at the beginning.
* To have variation in the particle sizes, use particleScaleVariation.
* The default value is 1.0.
* See also ParticleEffect::particleEndScale and ParticleEffect::particleScaleVariation.
*/
Q_PROPERTY(float particleScale READ particleScale WRITE setParticleScale NOTIFY particleScaleChanged)
/**
* @brief particleScaleVariation This property defines the scale variation of the particles.
* This variation is used for both particleScale and particleEndScale.
* For example, to emit particles which start at scale 0.5 - 1.5 and end at 2.5 - 3.5:
* @code
particleScale: 1.0
particleEndScale: 3.0
particleScaleVariation: 0.5
@endcode
* The default value is 0.0.
* See also ParticleEffect::particleScale and ParticleEffect::particleScaleVariation.
*/
Q_PROPERTY(float particleScaleVariation READ particleScaleVariation WRITE setParticleScaleVariation NOTIFY particleScaleVariationChanged)
/**
* @brief velocity can be used to set a starting velocity for emitted particles. If velocity is not set, particles start motionless and velocity comes from affectors if they are used.
* @note For the initialisation of this property use ParticleEffect::useTargetVelosity and ParticleEffect::useDirectionVelosity methods
*/
Q_PROPERTY(QObject *velocity READ velocity NOTIFY velocityChanged)
/**
* @brief particleDelegate This is path yo the qml delegate file of the particle object.
* @return path to delegate of the particle object.
*/
Q_PROPERTY(QString particleDelegate READ particleDelegate WRITE setParticleDelegate NOTIFY particleDelegateChanged)
/**
* @brief particleShape This property defines optional shape for the emitting area.
* Shape is scaled, positioned and rotated based on the emitter node properties.
* When the Shape fill property is set to false,
* emitting happens only from the surface of the shape. When the shape is not defined, emitting is done from the center point of the emitter node.
*/
Q_PROPERTY(QString particleShape READ particleShape WRITE setParticleShape NOTIFY particleShapeChanged)
/**
* @brief particleRotation This property defines the rotation of the particles in the beginning. Rotation is defined as degrees in euler angles.
*/
Q_PROPERTY(QVector3D particleRotation READ particleRotation WRITE setParticleRotation NOTIFY particleRotationChanged)
public:
ParticleEffect(const QString& name,
const QString& viewTempalte = "qrc:/CrawlModule/particles/ParticleEffect.qml",
QObject *ptr = nullptr);
/**
* @brief enabled if enabled is set to false, this emitter will not emit any particles.
* Usually this is used to conditionally turn an emitter on or off. If you want to continue emitting burst,
* keep emitRate at 0 instead of toggling this to false. The default value is true.
* @return true if this effect is enabled.
*/
bool enabled() const;
/**
* @brief setEnabled This method sets new value of the ParticleEffect::enabled property.
* @param newEnabled This is a new value of the ParticleEffect::enabled property
*/
void setEnabled(bool newEnabled);
/**
* @brief emitRate This property defines the constant emitting rate in particles per second. For example, if the emitRate is 120 and system animates at 60 frames per second, 2 new particles are emitted at every frame.
* The default value is 0.
* @return current value of the emitRate property
*/
float emitRate() const;
/**
* @brief setEmitRate This method sets new value of the ParticleEffect::emitRate property.
* @param newEmitRate This is a new value of the ParticleEffect::emitRate property
*/
void setEmitRate(float newEmitRate);
/**
* @brief depthBias Holds the depth bias of the emitter. Depth bias is added to the object distance from camera when sorting objects. This can be used to force rendering order between objects close to each other, that might otherwise be rendered in different order in different frames. Negative values cause the sorting value to move closer to the camera while positive values move it further from the camera.
* @return current value of the depthBias property
*/
float depthBias() const;
/**
* @brief setDepthBias This method sets new value of the ParticleEffect::depthBias property.
* @param newDepthBias This is a new value of the ParticleEffect::depthBias property
*/
void setDepthBias(float newDepthBias);
/**
* @brief lifeSpan This property defines the lifespan of a single particle in milliseconds.
* The default value is 1000.
* See also the lifeSpanVariation property.
* @return current value of the lifeSpan property
*/
int lifeSpan() const;
/**
* @brief setLifeSpan This method sets new value of the ParticleEffect::lifeSpan property.
* @param newLifeSpan This is a new value of the ParticleEffect::lifeSpan property
*/
void setLifeSpan(int newLifeSpan);
/**
* @brief lifeSpanVariation This property defines the lifespan variation of a single particle in milliseconds.
* For example, to emit particles which will exist between 3 and 4 seconds:
* @code
lifeSpan: 3500
lifeSpanVariation: 500
@endcode
* The default value is 0.
* @return current value of the lifeSpanVariation property
*/
int lifeSpanVariation() const;
/**
* @brief setLifeSpanVariation This method sets new value of the ParticleEffect::lifeSpanVariation property.
* @param newLifeSpanVariation This is a new value of the ParticleEffect::lifeSpanVariation property
*/
void setLifeSpanVariation(int newLifeSpanVariation);
/**
* @brief particleEndScale This property defines the scale multiplier of the particles at the end of particle lifeSpan.
* To have variation in the particle end sizes, use ParticleEffect::particleScaleVariation.
* When the value is negative, end scale is the same as the particleScale,
* so scale doesn't change during the particle lifeSpan.
* The default value is -1.0.
* See also ParticleEffect::particleScale and ParticleEffect::particleScaleVariation.
* @return current value of the particleEndScale property
*/
float particleEndScale() const;
/**
* @brief setParticleEndScale This method sets new value of the ParticleEffect::particleEndScale property.
* @param newParticleEndScale This is a new value of the ParticleEffect::particleEndScale property
*/
void setParticleEndScale(float newParticleEndScale);
/**
* @brief particleRotationVariation This property defines the rotation variation of the particles in the beginning. Rotation variation is defined as degrees in euler angles.
* For example, to emit particles in fully random rotations: Qt.vector3d(180, 180, 180)
* See also ParticleEffect::particleRotation.
* @return current value of the particleRotationVariation property
*/
const QVector3D &particleRotationVariation() const;
/**
* @brief setParticleRotationVariation This method sets new value of the ParticleEffect::particleRotationVariation property.
* @param newParticleRotationVariation This is a new value of the ParticleEffect::particleRotationVariation property
*/
void setParticleRotationVariation(const QVector3D &newParticleRotationVariation);
/**
* @brief particleRotationVelocity This property defines the rotation velocity of the particles in the beginning.
* Rotation velocity is defined as degrees per second in euler angles.
* See also ParticleEffect::particleRotationVelocityVariation.
* @return current value of the particleRotationVelocity property
*/
const QVector3D &particleRotationVelocity() const;
/**
* @brief setParticleRotationVelocity This method sets new value of the ParticleEffect::particleRotationVelocity property.
* @param newParticleRotationVelocity This is a new value of the ParticleEffect::particleRotationVelocity property
*/
void setParticleRotationVelocity(const QVector3D &newParticleRotationVelocity);
/**
* @brief particleRotationVelocityVariation This property defines the rotation velocity variation of the particles.
* Rotation velocity variation is defined as degrees per second in euler angles.
* For example, to emit particles in random rotations which have random rotation velocity between -100 and 100
* degrees per second into any directions:
@code
particleRotationVariation: Qt.vector3d(180, 180, 180)
particleRotationVelocityVariation: Qt.vector3d(100, 100, 100)
@endcode
* See also ParticleEffect::particleRotationVelocity.
* @return current value of the particleRotationVelocityVariation property
*/
const QVector3D &particleRotationVelocityVariation() const;
/**
* @brief setParticleRotationVelocityVariation This method sets new value of the ParticleEffect::particleRotationVelocityVariation property.
* @param newParticleRotationVelocityVariation This is a new value of the ParticleEffect::particleRotationVelocityVariation property
*/
void setParticleRotationVelocityVariation(const QVector3D &newParticleRotationVelocityVariation);
/**
* @brief particleScale This property defines the scale multiplier of the particles at the beginning.
* To have variation in the particle sizes, use particleScaleVariation.
* The default value is 1.0.
* See also ParticleEffect::particleEndScale and ParticleEffect::particleScaleVariation.
* @return current value of the particleScale property
*/
float particleScale() const;
/**
* @brief setParticleScale This method sets new value of the ParticleEffect::particleScale property.
* @param newParticleScale This is a new value of the ParticleEffect::particleScale property
*/
void setParticleScale(float newParticleScale);
/**
* @brief particleScaleVariation This property defines the scale variation of the particles.
* This variation is used for both particleScale and particleEndScale.
* For example, to emit particles which start at scale 0.5 - 1.5 and end at 2.5 - 3.5:
* @code
particleScale: 1.0
particleEndScale: 3.0
particleScaleVariation: 0.5
@endcode
* The default value is 0.0.
* See also ParticleEffect::particleScale and ParticleEffect::particleScaleVariation.
* @return current value of the ParticleEffect::particleScaleVariation property
*/
float particleScaleVariation() const;
/**
* @brief setParticleScaleVariation This method sets new value of the ParticleEffect::particleScaleVariation property.
* @param newParticleScaleVariation This is a new value of the ParticleEffect::particleScaleVariation property
*/
void setParticleScaleVariation(float newParticleScaleVariation);
/**
* @brief particleDelegate This is path yo the qml delegate file of the particle object.
* @return path to delegate of the particle object.
*/
const QString &particleDelegate() const;
/**
* @brief setParticleDelegate This method sets new value of the path to qml particle object.
* @param newParticleDelegate This is new value of the path to particle object.
*/
void setParticleDelegate(const QString &newParticleDelegate);
/**
* @brief velocity This property can be used to set a starting velocity for emitted particles. If velocity is not set, particles start motionless and velocity comes from affectors if they are used.
* @return current value of the ParticleEffect::velocity property
*/
QObject *velocity() const;
/**
* @brief brust This method emits count amount of particles from this emitter during the next duration milliseconds.
* The particles are emitted as if the emitter was at position but all other properties are the same.
* @param count This is count of emited particles
* @param duration This ducration of the emitting particles.
* @param position This is position wher the emiter should emit particles.
* @return
*/
QVector3D brust(int count,
int duration,
const QVector3D& position) const;
/**
* @brief brust This method emits count amount of particles from this emitter during the next duration milliseconds.
* @param count This is count of emited particles
* @param duration This ducration of the emitting particles.
* @return
*/
QVector3D brust(int count,
int duration) const;
/**
* @brief brust This method emits count amount of particles from this emitter immediately.
* @param count This is count of emited particles
* @return
*/
QVector3D brust(int count) const;
/**
* @brief particleShape The ParticleShape3D element supports shapes like Cube,
* Sphere and Cylinder for particles needs.
* For example, emitter can use shape property to emit particles from the shape area.
* Shapes don't have position, scale or rotation.
* Instead, they use parent node for these properties.
* @return path to qml shape element.
*/
const QString &particleShape() const;
/**
* @brief setParticleShape This method set new path to shape element
* @param newParticleShape This is new value of the path to qml shape element.
*/
void setParticleShape(const QString &newParticleShape);
/**
* @brief particleRotation This property defines the rotation of the particles in the beginning. Rotation is defined as degrees in euler angles.
* @return current value of the particleRotation property
*/
const QVector3D &particleRotation() const;
/**
* @brief setParticleRotationVelocity This method sets new value of the ParticleEffect::particleRotation property.
* @param newParticleRotationVelocity This is a new value of the ParticleEffect::particleRotation property
*/
void setParticleRotation(const QVector3D &newParticleRotation);
signals:
/**
* @brief enabledChanged This signal emited when the enabled property changed.
*/
void enabledChanged();
/**
* @brief emitRateChanged This signal emited when the emitRate property changed.
*/
void emitRateChanged();
/**
* @brief depthBiasChanged This signal emited when the depthBias property changed.
*/
void depthBiasChanged();
/**
* @brief lifeSpanChanged This signal emited when the lifeSpan property changed.
*/
void lifeSpanChanged();
/**
* @brief lifeSpanVariationChanged This signal emited when the ifeSpanVariation property changed.
*/
void lifeSpanVariationChanged();
/**
* @brief particleEndScaleChanged This signal emited when the particleEndScale property changed.
*/
void particleEndScaleChanged();
/**
* @brief particleRotationVariationChanged This signal emited when the particleRotationVariation property changed.
*/
void particleRotationVariationChanged();
/**
* @brief particleRotationVelocityChanged This signal emited when the particleRotationVelocity property changed.
*/
void particleRotationVelocityChanged();
/**
* @brief particleRotationVelocityVariationChanged This signal emited when the particleRotationVelocityVariation property changed.
*/
void particleRotationVelocityVariationChanged();
/**
* @brief particleScaleChanged This signal emited when the particleScale property changed.
*/
void particleScaleChanged();
/**
* @brief particleScaleVariationChanged This signal emited when the particleScaleVariation property changed.
*/
void particleScaleVariationChanged();
/**
* @brief particleDelegateChanged This signal emited when the particleDelegate property changed.
*/
void particleDelegateChanged();
/**
* @brief velocityChanged This signal emited when the velocity property changed.
*/
void velocityChanged();
/**
* @brief particleShapeChanged This signal emited when the shape property changed.
*/
void particleShapeChanged();
/**
* @brief particleShapeChanged This signal emited when the particleRotation property changed.
*/
void particleRotationChanged();
protected:
/**
* @brief useDirectionVelosity This method can be invoked a starting velocity for emitted particles. If velocity is not set, particles start motionless and velocity comes from affectors if they are used.
* This element sets emitted particle velocity towards the target direction vector.
* The length of the direction vector is used as the velocity magnitude.
* For example, to emit particles towards some random direction within x: 50..150, y: -20..20, z: 0:
* @code
* velositydirection: Qt.vector3d(100, 0, 0)
velositydirectionVariation: Qt.vector3d(50, 20, 0)
* @endcode
* @param velosityDirection see the ParticleEffect::velosityDirection property
* @param velosityDirectionValatility see the ParticleEffect::velosityDirectionValatility property
* @note This and useTargetVelosity method is not compatible. If you invoke them together then will works correctly will be only last invoked method.
*/
void useDirectionVelosity(const QVector3D& velosityDirection,
const QVector3D& velosityDirectionValatility = {});
/**
* @brief useTargetVelosity This method can be invoked a starting velocity for emitted particles. If velocity is not set, particles start motionless and velocity comes from affectors if they are used.
* This element sets emitted particle velocity towards the target position.
* For example, to emit particles towards position (100, 0, 0) with random magnitude between 10..20:
* @code
velosityposition: Qt.vector3d(100, 0, 0)
velositynormalized: true
velositymagnitude: 15.0
velositymagnitudeVariation: 5.0
* @endcode
* @param velosityMagnitude see the ParticleEffect::velosityMagnitude property
* @param velosityMagnitudeVariation see the ParticleEffect::velosityMagnitudeVariation property
* @param velosityNormalized see the ParticleEffect::velosityNormalized property
* @param velosityTargetPosition see the ParticleEffect::velosityTargetPosition property
* @param velosityTargetPositionVariation see the ParticleEffect::velosityTargetPositionVariation property
* @note This and useDirectionVelosity method is not compatible. If you invoke them together then will works correctly will be only last invoked method.
*/
void useTargetVelosity(float velosityMagnitude,
float velosityMagnitudeVariation,
bool velosityNormalized,
const QVector3D& velosityTargetPosition,
const QVector3D& velosityTargetPositionVariation);
/**
* @brief setVelocity This method sets new value of ParticleEffect::velocity property.
* @param newVelocity This is new value of the ParticleEffect::velocity property.
*/
void setVelocity(QObject *newVelocity);
private:
bool _enabled = false;
float _emitRate = 0;
float _depthBias = 0;
int _lifeSpan = 1000;
int _lifeSpanVariation = 0;
float _particleEndScale = -1.0;
QVector3D _particleRotation = {};
QVector3D _particleRotationVariation = {};
QVector3D _particleRotationVelocity = {};
QVector3D _particleRotationVelocityVariation = {};
float _particleScale = 1;
float _particleScaleVariation = 0;
QObject* _velocity = nullptr;
QString _particleDelegate;
QString _particleShape;
};
}
#endif // PARTICLEEFFECT_H

@ -0,0 +1,32 @@
//#
//# 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.
//#
#include "viewtemaplatemodel.h"
namespace CRAWL {
ViewTemaplateModel::ViewTemaplateModel(const QString &viewTempalte, QObject *ptr): QObject(ptr) {
_viewTemplate = viewTempalte;
}
const QString &ViewTemaplateModel::viewTemplate() const {
return _viewTemplate;
}
QObject *ViewTemaplateModel::viewObject() const {
return _viewObject;
}
void ViewTemaplateModel::setViewObject(QObject *newViewObject) {
if (_viewObject == newViewObject)
return;
_viewObject = newViewObject;
emit viewObjectChanged();
}
}

@ -0,0 +1,72 @@
//#
//# 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.
//#
#ifndef VIEWTEMAPLATEMODEL_H
#define VIEWTEMAPLATEMODEL_H
#include "global.h"
#include <QObject>
namespace CRAWL {
/**
* @brief The ViewTemaplateModel class This is base class for supporting model view template in qml.
* This class is base model og the view objects.
* All qml viewObjects will be generated using the ViewTemaplateModel::viewTemplate method on The main QML scane.
*
*/
class CRAWL_EXPORT ViewTemaplateModel: public QObject
{
Q_OBJECT
/**
* @brief viewTemplate This is path to the qml file with gui implementation of this model class.
*/
Q_PROPERTY(QString viewTemplate READ viewTemplate)
/**
* @brief viewObject This is object of view companent.
* @note If the object not inited and the model propetye of the view is empty then this property will be equals nullptr
*/
Q_PROPERTY(QObject *viewObject READ viewObject WRITE setViewObject NOTIFY viewObjectChanged)
public:
ViewTemaplateModel(const QString& viewTempalte,
QObject *ptr = nullptr);
/**
* @brief viewTemplate This is path to the qml file with gui implementation of this model class.
* @return path to the qml file with gui implementation of this model class.
*/
const QString& viewTemplate() const;
/**
* @brief viewObject This is object of view companent.
* @note For working with the view propertys use the QOBject::getproperty and QObject::setproperty methods. For invoke view method use the "QMetaObject::invokeMethod" method.
* For get more inforamtion about qt method see the Qt documentation.
* @return pointer to view object.
* @note If the object not inited and the model propetye of the view is empty then this property will be equals nullptr
*/
QObject *viewObject() const;
/**
* @brief setViewObject This method sets new value of the ViewObject. This method will be invoked automaticly.
* @param newViewObject This is new valur of the view object.
*/
void setViewObject(QObject *newViewObject);
signals:
void viewObjectChanged();
private:
QString _viewTemplate;
QObject *_viewObject = nullptr;
};
}
#endif // VIEWTEMAPLATEMODEL_H

40
src/Core/Crawl/wint.cpp Normal file

@ -0,0 +1,40 @@
//#
//# 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.
//#
#include "wint.h"
namespace CRAWL {
Wint::Wint(): Affector(AUTO_CLASS_NAME, "qrc:/CrawlModule/particles/Wint.qml") {
}
void Wint::onIntersects(const IWorldItem *) {}
float Wint::magnitude() const {
return _magnitude;
}
void Wint::setMagnitude(float newMagnitude) {
if (qFuzzyCompare(_magnitude, newMagnitude))
return;
_magnitude = newMagnitude;
emit magnitudeChanged();
}
const QVector3D &Wint::direction() const {
return _direction;
}
void Wint::setDirection(const QVector3D &newDirection) {
if (_direction == newDirection)
return;
_direction = newDirection;
emit directionChanged();
}
}

76
src/Core/Crawl/wint.h Normal file

@ -0,0 +1,76 @@
//#
//# 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.
//#
#ifndef WINT_H
#define WINT_H
#include "affector.h"
#include "Extensions/rotationaroundaxis.h"
namespace CRAWL {
/**
* @brief The Wint class This is example of the using Affector class.
* implementation of the wint.
*/
class CRAWL_EXPORT Wint: public Affector
{
Q_OBJECT
/**
* @brief direction This property defines the direction the gravity will affect toward. Values will be automatically normalized to a unit vector.
*/
Q_PROPERTY(QVector3D direction READ direction WRITE setDirection NOTIFY directionChanged)
/**
* @brief magnitude This property defines the magnitude in position change per second. Negative magnitude accelerates the opposite way from the direction.
The default value is 100.0.
*/
Q_PROPERTY(float magnitude READ magnitude WRITE setMagnitude NOTIFY magnitudeChanged)
public:
Wint();
// IWorldItem interface
/**
* @brief direction This method return current direction of the wint.
* @return direction of the wint.
*/
const QVector3D &direction() const;
/**
* @brief setDirection This method sets new direction of the wint.
* @param newDirection new value of the direction of the wint.
*/
void setDirection(const QVector3D &newDirection);
/**
* @brief magnitude This property defines the magnitude in position change per second. Negative magnitude accelerates the opposite way from the direction.
The default value is 10.0.
* @return current value of the magnitude.
*/
float magnitude() const;
/**
* @brief setMagnitude This method sets new vlaue of the magnitucde of this object.
* @param newMagnitude Tis is new value of the magnitude property
*/
void setMagnitude(float newMagnitude);
signals:
void directionChanged();
void magnitudeChanged();
protected:
void onIntersects(const IWorldItem *item) override;
QVector3D _direction = {1, 0, 0};
float _magnitude = 10;
};
}
#endif // WINT_H

@ -1 +1 @@
Subproject commit 799cff3421d159828bb49a2e26e851ea60790e25
Subproject commit 95e0432a8b0d94924c97f0a100cf92a3c0a3f369

@ -3,6 +3,7 @@ import QtQuick3D
import QtQuick.Controls.Material
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick3D.Particles3D
// https://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterUncreatableMetaObject
import engine.worldstatus
@ -12,7 +13,12 @@ View3D {
property var model: null;
property alias showMenu: privateRoot.showMenu
renderMode: View3D.Underlay
renderMode: View3D.Offscreen
Label {
text: scane.renderStats.fps
x: 200
}
PerspectiveCamera {
id: camera
@ -35,9 +41,8 @@ View3D {
environment: /*(privateRoot.world)? background:*/ defautlBackground
Node {
ParticleSystem3D {
id: privateRoot
property var arrayObjects: []
property var world: (model)? model.world: null
@ -67,7 +72,7 @@ View3D {
var temp = Qt.createComponent(viewTemplate)
if (temp.status === Component.Ready) {
var obj = temp.createObject(privateRoot)
obj.model = model.getGameObject(cppObjId);
obj.model = objModel;
arrayObjects.push(obj)
} else {
console.log("wrong viewTemplate in model " + temp.errorString());

@ -0,0 +1,22 @@
//#
//# 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.
//#
import QtQuick
import QtQuick3D
import QtQuick3D.Particles3D
TargetDirection3D {
property var model: null
property string path: ""
position: (model)? model.velosityTargetPosition : Qt.vector3d(0, 0, 0)
normalized: (model)? model.velosityNormalized : false
magnitude: (model)? model.velosityMagnitude : 1
magnitudeVariation: (model)? model.velosityMagnitudeVariation : 0
positionVariation: (model)? model.velosityTargetPositionVariation : Qt.vector3d(0, 0, 0)
}

@ -0,0 +1,18 @@
//#
//# 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.
//#
import QtQuick
import QtQuick3D
import QtQuick3D.Particles3D
VectorDirection3D {
property var model: null
property string path: ""
direction: (model)? model.velosityDirection : Qt.vector3d(0, 0, 0)
directionVariation: (model)? model.velosityDirectionValatility : Qt.vector3d(0, 0, 0)
}

@ -0,0 +1,17 @@
//#
//# 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.
//#
import QtQuick
import QtQuick3D
import QtQuick3D.Particles3D
ParticleEffect {
PointLight {
brightness: (model)? Math.sqrt(model.fireStrength): 0;
color: (model)? model.color: "#ffffff";
}
}

@ -0,0 +1,27 @@
//#
//# 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.
//#
import QtQuick
import QtQuick3D
import QtQuick3D.Particles3D
SpriteParticle3D {
id: particleFire
sprite: Texture {
source: "qrc:/CrawlCoreAssets/particles/sphere.png"
}
colorTable: Texture {
source: "qrc:/CrawlCoreAssets/particles/fireColorTable.png"
}
maxAmount: 300
color: "#ffffff"
colorVariation: Qt.vector4d(0.0, 0.6, 0.8, 0.0)
billboard: true
blendMode: SpriteParticle3D.Screen
fadeInDuration: 100
}

@ -0,0 +1,114 @@
//#
//# 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.
//#
import QtQuick
import QtQuick3D
import QtQuick3D.Particles3D
ParticleEmitter3D {
id: root
property var model: null
property int guiId: (model) ? model.guiId : -1;
rotation: (model)? model.rotation: Qt.quaternion(0, 0, 0, 0)
scale: (model)? model.size: Qt.vector3d(0, 0, 0);
position: (model) ? model.position: Qt.vector3d(0,0,0);
visible: (model)? model.visible: false
depthBias: (model)? model.depthBias: 0
emitRate: (model)? model.emitRate: 0
enabled: (model)? model.enabled: true
lifeSpan: (model)? model.lifeSpan: 0
lifeSpanVariation: (model)? model.lifeSpanVariation: 0
particleEndScale: (model)? model.particleEndScale: 0
particleRotation: (model)? model.particleRotation: Qt.vector3d(0, 0, 0)
particleRotationVariation: (model)? model.particleRotationVariation: Qt.vector3d(0, 0, 0)
particleRotationVelocity: (model)? model.particleRotationVelocity: Qt.vector3d(0, 0, 0)
particleRotationVelocityVariation: (model)? model.particleRotationVelocityVariation: Qt.vector3d(0, 0, 0)
particleScaleVariation: (model)? model.particleScaleVariation: 0
onModelChanged: () => {
if (root.model) {
root.model.viewObject = root;
}
}
Item {
id: privateRoot
property var velosity: (model)? model.velocity: null
property string delegate: (model)? model.particleDelegate: ""
property string particleShape: (model)? model.particleShape: ""
property var view: null
onVelosityChanged: () => {
if (!root.model)
return;
const objModel = root.model.velocity;
if (!objModel) {
if (view) {
view.distory();
}
root.velocity = view = null;
return;
}
const viewTemplate = objModel.viewTemplate;
if (!view || (view.path !== viewTemplate)) {
let temp = Qt.createComponent(viewTemplate)
if (!temp)
return
if (temp.status === Component.Ready) {
let obj = temp.createObject(root)
obj.model = objModel;
if (view) {
view.distory();
}
root.velocity = view = obj;
} else {
console.log("wrong path (viewTemplate property) ot thq velosity module " + temp.errorString());
}
}
}
onDelegateChanged: () => {
let temp = Qt.createComponent(privateRoot.delegate)
if (!temp)
return
if (temp.status === Component.Ready) {
root.particle = temp.createObject(root.parent);
} else {
console.log("wrong path to the in model " + temp.errorString());
}
}
onParticleShapeChanged: () => {
let temp = Qt.createComponent(privateRoot.particleShape)
if (!temp)
return
if (temp.status === Component.Ready) {
root.shape = temp.createObject(root.parent);
} else {
console.log("wrong viewTemplate in model " + temp.errorString());
}
}
}
}

@ -0,0 +1,39 @@
//#
//# 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.
//#
import QtQuick
import QtQuick3D
import QtQuick3D.Particles3D
Gravity3D {
property var model: null
property int guiId: (model) ? model.guiId : -1;
enabled: (model)? model.enabled: false
magnitude: (model)? model.magnitude: 0
direction: (model)? model.direction: Qt.vector3d(0, 0, 0)
Behavior on magnitude {
NumberAnimation {
duration: 5000
easing.type: Easing.InQuad
}
}
Behavior on direction {
Vector3dAnimation {
duration: 5000
easing.type: Easing.InQuad
}
}
}

@ -2,3 +2,9 @@ module CrawlModule
Crawl 1.0 Crawl.qml
DefaultMenu 1.0 DefaultMenu.qml
GraphicItem 1.0 GraphicItem.qml
ParticleEffect 1.0 ParticleEffect.qml
Light 1.0 Light.qml
GraphicItem 1.0 GraphicItem.qml
GraphicItem 1.0 GraphicItem.qml
GraphicItem 1.0 GraphicItem.qml
GraphicItem 1.0 GraphicItem.qml

@ -51,7 +51,7 @@ public:
/**
* @brief setMovableVector This method sets new value of the mvable vector.
* @param newMovableVector this is a new value ofthe movable vector
* @note The movable vector will be changed in time if you set the MovableObject::breakingForce propertye to non 0 value.
* @note The movable vector will be changed in time if you set the MovableObject::breakingForce property to non 0 value.
*/
void setMovableVector(const QVector3D &newMovableVector);

@ -0,0 +1,28 @@
//#
//# 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.
//#
#include "rotationaroundaxis.h"
#include <Crawl/guiobject.h>
namespace CRAWL {
RotationAroundAxis::RotationAroundAxis(): CircularMotion(nullptr) {
}
void RotationAroundAxis::renderRotation(GuiObject *object, unsigned int tbfMsec) {
setAnglePosition(anglePosition() + angularVelocity() * (tbfMsec / 1000.0f));
object->setRotation(QQuaternion::fromAxisAndAngle(axis(), angularVelocity()));
}
void RotationAroundAxis::renderPosition(GuiObject *, unsigned int ) {
}
}

@ -0,0 +1,34 @@
//#
//# 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.
//#
#ifndef ROTATIONAROUNDAXIS_H
#define ROTATIONAROUNDAXIS_H
#include "circularmotion.h"
namespace CRAWL {
/**
* @brief The RotationAroundAxis class This class provide the rotation of our axis
*/
class RotationAroundAxis: public CircularMotion
{
public:
RotationAroundAxis();
// BaseMotion interface
protected:
void renderRotation(GuiObject *object, unsigned int tbfMsec) override;
void renderPosition(GuiObject *object, unsigned int tbfMsec) override;
};
}
#endif // ROTATIONAROUNDAXIS_H

@ -0,0 +1,80 @@
//#
//# 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.
//#
#include "targetdirection.h"
namespace CRAWL {
TargetDirection::TargetDirection(float velosityMagnitude,
float velosityMagnitudeVariation,
bool velosityNormalized,
const QVector3D &velosityTargetPosition,
const QVector3D &velosityTargetPositionVariation,
QObject *parent):
ViewTemaplateModel("qrc:/CrawlModule/particles/CrawlTargetDirection.qml", parent)
{
setVelosityMagnitude(velosityMagnitude);
setVelosityMagnitudeVariation(velosityMagnitudeVariation);
setVelosityNormalized(velosityNormalized);
setVelosityTargetPosition(velosityTargetPosition);
setVelosityTargetPositionVariation(velosityTargetPositionVariation);
}
float TargetDirection::velosityMagnitude() const {
return _velosityMagnitude;
}
void TargetDirection::setVelosityMagnitude(float newVelosityMagnitude) {
if (qFuzzyCompare(_velosityMagnitude, newVelosityMagnitude))
return;
_velosityMagnitude = newVelosityMagnitude;
emit velosityMagnitudeChanged();
}
float TargetDirection::velosityMagnitudeVariation() const {
return _velosityMagnitudeVariation;
}
void TargetDirection::setVelosityMagnitudeVariation(float newVelosityMagnitudeVariation) {
if (qFuzzyCompare(_velosityMagnitudeVariation, newVelosityMagnitudeVariation))
return;
_velosityMagnitudeVariation = newVelosityMagnitudeVariation;
emit velosityMagnitudeVariationChanged();
}
bool TargetDirection::velosityNormalized() const {
return _velosityNormalized;
}
void TargetDirection::setVelosityNormalized(bool newVelosityNormalized) {
if (_velosityNormalized == newVelosityNormalized)
return;
_velosityNormalized = newVelosityNormalized;
emit velosityNormalizedChanged();
}
const QVector3D &TargetDirection::velosityTargetPosition() const {
return _velosityTargetPosition;
}
void TargetDirection::setVelosityTargetPosition(const QVector3D &newVelosityTargetPosition) {
if (_velosityTargetPosition == newVelosityTargetPosition)
return;
_velosityTargetPosition = newVelosityTargetPosition;
emit velosityTargetPositionChanged();
}
const QVector3D &TargetDirection::velosityTargetPositionVariation() const {
return _velosityTargetPositionVariation;
}
void TargetDirection::setVelosityTargetPositionVariation(const QVector3D &newVelosityTargetPositionVariation) {
if (_velosityTargetPositionVariation == newVelosityTargetPositionVariation)
return;
_velosityTargetPositionVariation = newVelosityTargetPositionVariation;
emit velosityTargetPositionVariationChanged();
}
}

@ -0,0 +1,191 @@
//#
//# 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.
//#
#include "Crawl/viewtemaplatemodel.h"
#include <QVector3D>
#include "global.h"
#ifndef TARGETDIRECTION_H
#define TARGETDIRECTION_H
namespace CRAWL {
/**
* @brief The TargetDirection class.
* This element sets emitted particle velocity towards the target position.
* For example, to emit particles towards position (100, 0, 0) with random magnitude between 10..20:
* @code
TargetDirection {
position: Qt.vector3d(100, 0, 0)
normalized: true
magnitude: 15.0
magnitudeVariation: 5.0
}
}
@endcode
* @note This class use the CrawlTargetDirection.qml template as a view temaplate.
*/
class TargetDirection: public ViewTemaplateModel
{
Q_OBJECT
/**
* @brief velosityMagnitude This property defines the magnitude in position change per second.
* Negative magnitude accelerates the opposite way from the position.
* When the normalized is false, this is multiplied with the distance to the target position.
* The default value is 1.0.
*/
Q_PROPERTY(float velosityMagnitude READ velosityMagnitude WRITE setVelosityMagnitude NOTIFY velosityMagnitudeChanged)
/**
* @brief velosityMagnitudeVariation This property defines the magnitude variation in position change per second.
* When the normalized is false, this is multiplied with the distance to the target position.
* The default value is 0.0.
*/
Q_PROPERTY(float velosityMagnitudeVariation READ velosityMagnitudeVariation WRITE setVelosityMagnitudeVariation NOTIFY velosityMagnitudeVariationChanged)
/**
* @brief velosityNormalized This property defines if the distance to position should be considered as normalized or not.
* When this is false, distance to the position affects the magnitude of the particles velocity.
* When set to true, distance is normalized and velocity amount comes only from magnitude and magnitudeVariation.
* The default value is false.
*/
Q_PROPERTY(bool velosityNormalized READ velosityNormalized WRITE setVelosityNormalized NOTIFY velosityNormalizedChanged)
/**
* @brief velosityTargetPosition This property defines the position for particles target.
* The default value is (0, 0, 0) (the center of the emitter).
*/
Q_PROPERTY(QVector3D velosityTargetPosition READ velosityTargetPosition WRITE setVelosityTargetPosition NOTIFY velosityTargetPositionChanged)
/**
* @brief velosityTargetPositionVariation This property defines the position variation for particles target.
* The default value is (0, 0, 0) (no variation).
*/
Q_PROPERTY(QVector3D velosityTargetPositionVariation READ velosityTargetPositionVariation WRITE setVelosityTargetPositionVariation NOTIFY velosityTargetPositionVariationChanged)
public:
TargetDirection(float velosityMagnitude = 1,
float velosityMagnitudeVariation = 0,
bool velosityNormalized = false,
const QVector3D& velosityTargetPosition = {0,0,0},
const QVector3D& velosityTargetPositionVariation = {0,0,0},
QObject * parent = nullptr);
/**
* @brief velosityMagnitude This property defines the magnitude in position change per second.
* Negative magnitude accelerates the opposite way from the position.
* When the normalized is false, this is multiplied with the distance to the target position.
* The default value is 1.0.
* @return current value of the velosityMagnitude property
*/
float velosityMagnitude() const;
/**
* @brief setVelosityMagnitude This method sets new value of the ParticleEffect::velosityMagnitude property.
* @param newVelosityMagnitude This is a new value of the ParticleEffect::velosityMagnitude property
* @note This property will be workd only after invoke the useTargetVelosity method.
*/
void setVelosityMagnitude(float newVelosityMagnitude);
/**
* @brief velosityMagnitudeVariation This property defines the magnitude variation in position change per second.
* When the normalized is false, this is multiplied with the distance to the target position.
* The default value is 0.0.
* @return current value of the velosityMagnitudeVariation property
*/
float velosityMagnitudeVariation() const;
/**
* @brief setVelosityMagnitudeVariation This method sets new value of the ParticleEffect::velosityMagnitudeVariation property.
* @param newVelosityMagnitudeVariation This is a new value of the ParticleEffect::velosityMagnitudeVariation property
* @note This property will be workd only after invoke the useTargetVelosity method.
*/
void setVelosityMagnitudeVariation(float newVelosityMagnitudeVariation);
/**
* @brief velosityNormalized This property defines if the distance to position should be considered as normalized or not.
* When this is false, distance to the position affects the magnitude of the particles velocity.
* When set to true, distance is normalized and velocity amount comes only from magnitude and magnitudeVariation.
* The default value is false.
* @return current value of the velosityNormalized property
*/
bool velosityNormalized() const;
/**
* @brief setVelosityNormalized This method sets new value of the ParticleEffect::velosityNormalized property.
* @param newVelosityNormalized This is a new value of the ParticleEffect::velosityNormalized property
* @note This property will be workd only after invoke the useTargetVelosity method.
*/
void setVelosityNormalized(bool newVelosityNormalized);
/**
* @brief velosityTargetPosition This property defines the position for particles target.
* The default value is (0, 0, 0) (the center of the emitter).
* @return current value of the velosityNormalized property
*/
const QVector3D &velosityTargetPosition() const;
/**
* @brief setVelosityTargetPosition This method sets new value of the ParticleEffect::velosityTargetPosition property.
* @param newVelosityTargetPosition This is a new value of the ParticleEffect::velosityTargetPosition property
* @note This property will be workd only after invoke the useTargetVelosity method.
*/
void setVelosityTargetPosition(const QVector3D &newVelosityTargetPosition);
/**
* @brief velosityTargetPositionVariation This property defines the position variation for particles target.
* The default value is (0, 0, 0) (no variation).
* @return current value of the velosityTargetPositionVariation property
*/
const QVector3D &velosityTargetPositionVariation() const;
/**
* @brief setVelosityTargetPositionVariation This method sets new value of the ParticleEffect::velosityTargetPositionVariation property.
* @param newVelosityTargetPositionVariation This is a new value of the ParticleEffect::velosityTargetPositionVariation property
* @note This property will be workd only after invoke the useTargetVelosity method.
*/
void setVelosityTargetPositionVariation(const QVector3D &newVelosityTargetPositionVariation);
signals:
/**
* @brief velosityMagnitudeChanged This signal emited when the velosityMagnitude property changed.
*/
void velosityMagnitudeChanged();
/**
* @brief velosityMagnitudeVariationChanged This signal emited when the velosityMagnitudeVariation property changed.
*/
void velosityMagnitudeVariationChanged();
/**
* @brief velosityNormalizedChanged This signal emited when the velosityNormalized property changed.
*/
void velosityNormalizedChanged();
/**
* @brief velosityTargetPositionChanged This signal emited when the velosityTargetPosition property changed.
*/
void velosityTargetPositionChanged();
/**
* @brief velosityTargetPositionVariationChanged This signal emited when the velosityTargetPositionVariation property changed.
*/
void velosityTargetPositionVariationChanged();
private:
float _velosityMagnitude = 1;
float _velosityMagnitudeVariation = 0;
bool _velosityNormalized = false;
QVector3D _velosityTargetPosition = {};
QVector3D _velosityTargetPositionVariation = {};
};
}
#endif // TARGETDIRECTION_H

@ -0,0 +1,44 @@
//#
//# 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.
//#
#include "vectordirection.h"
namespace CRAWL {
VectorDirection::VectorDirection(const QVector3D &direction,
const QVector3D &directionValatility,
QObject *parent):
ViewTemaplateModel("qrc:/CrawlModule/particles/CrawlVectorDirection.qml", parent) {
setVelosityDirection(direction);
setVelosityDirectionValatility(directionValatility);
}
const QVector3D &VectorDirection::velosityDirection() const {
return _velosityDirection;
}
void VectorDirection::setVelosityDirection(const QVector3D &newVelosityDirection) {
if (_velosityDirection == newVelosityDirection)
return;
_velosityDirection = newVelosityDirection;
emit velosityDirectionChanged();
}
const QVector3D &VectorDirection::velosityDirectionValatility() const {
return _velosityDirectionValatility;
}
void VectorDirection::setVelosityDirectionValatility(const QVector3D &newVelosityDirectionValatility) {
if (_velosityDirectionValatility == newVelosityDirectionValatility)
return;
_velosityDirectionValatility = newVelosityDirectionValatility;
emit velosityDirectionValatilityChanged();
}
}

@ -0,0 +1,99 @@
//#
//# 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.
//#
#ifndef VECTORDIRECTION_H
#define VECTORDIRECTION_H
#include "Crawl/viewtemaplatemodel.h"
#include <QVector3D>
#include "global.h"
namespace CRAWL {
/**
* @brief The VectorDirection class.
* This element sets emitted particle velocity towards the target direction vector.
* The length of the direction vector is used as the velocity magnitude.
* For example, to emit particles towards some random direction within x: 50..150, y: -20..20, z: 0:
* @code
* VectorDirection {
direction: Qt.vector3d(100, 0, 0)
directionVariation: Qt.vector3d(50, 20, 0)
}
@endcode
*
* @note This class use the CrawlVectorDirection.qml template as a view temaplate.
*/
class VectorDirection: public ViewTemaplateModel
{
Q_OBJECT
/**
* @brief velosityDirection this property defines the direction for particles target.
* The default value is (0, 100, 0) (upwards on the y-axis).
*/
Q_PROPERTY(QVector3D velosityDirection READ velosityDirection WRITE setVelosityDirection NOTIFY velosityDirectionChanged)
/**
* @brief velosityDirectionValatility This property defines the direction variation for particles target.
* The default value is (0, 0, 0) (no variation).
*/
Q_PROPERTY(QVector3D velosityDirectionValatility READ velosityDirectionValatility WRITE setVelosityDirectionValatility NOTIFY velosityDirectionValatilityChanged)
public:
VectorDirection(const QVector3D& direction = {},
const QVector3D& directionValatility = {},
QObject * parent = nullptr);
/**
* @brief velosityDirection this property defines the direction for particles target.
* The default value is (0, 100, 0) (upwards on the y-axis).
* @return current value of the velosityDirection property
*/
const QVector3D &velosityDirection() const;
/**
* @brief setVelosityDirection This method sets new value of the ParticleEffect::velosityDirection property.
* @param newVelosityDirection This is a new value of the ParticleEffect::velosityDirection property
* @note This property will be workd only after invoke the useDirectionVelosity method.
*/
void setVelosityDirection(const QVector3D &newVelosityDirection);
/**
* @brief velosityDirectionValatility This property defines the direction variation for particles target.
* The default value is (0, 0, 0) (no variation).
* @return current value of the velosityDirectionValatility property
*/
const QVector3D &velosityDirectionValatility() const;
/**
* @brief setVelosityDirectionValatility This method sets new value of the ParticleEffect::velosityDirectionValatility property.
* @param newVelosityDirectionValatility This is a new value of the ParticleEffect::velosityDirectionValatility property
* @note This property will be workd only after invoke the useDirectionVelosity method.
*/
void setVelosityDirectionValatility(const QVector3D &newVelosityDirectionValatility);
signals:
/**
* @brief velosityDirectionChanged This signal emited when the velosityDirection property changed.
*/
void velosityDirectionChanged();
/**
* @brief velosityDirectionValatilityChanged This signal emited when the velosityDirectionValatility property changed.
*/
void velosityDirectionValatilityChanged();
private:
QVector3D _velosityDirection = {};
QVector3D _velosityDirectionValatility = {};
};
}
#endif // VECTORDIRECTION_H

@ -7,56 +7,58 @@ import QtQuick.Controls
DefaultMenu {
columns: 2
rows: 2
Rectangle {
Layout.fillHeight: true
Layout.fillWidth: true
Layout.columnSpan: 2
Layout.rowSpan: 2
color: "#22000000"
MouseArea {
property bool track: false
property real oldX: 0
property real oldY: 0
cursorShape: Qt.DragMoveCursor
onPressed: (mouse) => {
track = true
oldX = mouse.x
oldY = mouse.y
}
track = true
oldX = mouse.x
oldY = mouse.y
}
onReleased: {
track = false
}
onPositionChanged: (mouse) => {
if (!model) {
return;
}
if (!model) {
return;
}
if (!track) {
return;
}
let delta = mouse.y - oldY;
let radianDelta = (delta / (parent.height / 2)) * 45
if (!track) {
return;
}
model.xChanged(radianDelta)
oldY = mouse.y;
let delta = mouse.y - oldY;
let radianDelta = (delta / (parent.height / 2)) * 45
delta = mouse.x - oldX;
radianDelta = (delta / (parent.width / 2)) * 45
model.yChanged(radianDelta)
oldX = mouse.x;
model.yChanged(radianDelta)
oldY = mouse.y;
delta = mouse.x - oldX;
radianDelta = (delta / (parent.width / 2)) * 45
model.xChanged(radianDelta)
oldX = mouse.x;
}
}
anchors.fill: parent
}
}
}

@ -14,6 +14,8 @@
#include "Crawl/iworlditem.h"
#include <Crawl/day.h>
#include <Crawl/defaultlight.h>
#include <Crawl/dynamicwint.h>
#include <Crawl/fire.h>
#include <Crawl/moon.h>
#include <Crawl/sun.h>
@ -29,7 +31,10 @@ CRAWL::WorldRule *World::initWorldRules() {
using Day = CRAWL::Day<CRAWL::Sun, CRAWL::Moon>;
return new CRAWL::WorldRule {
{0, {{registerObject<Box>(), 1000},
{0, {{registerObject<Box>(), 100},
{registerObject<CRAWL::Fire>(), 10},
{registerObject<CRAWL::DynamicWint>(), 1},
{registerObject<Background>(), 1},
{registerObject<Day>(), 1}}}
};