particle system are finished

This commit is contained in:
Andrei Yankovich 2021-08-03 21:01:16 +03:00
parent 12857c2265
commit ba6ee5bddd
26 changed files with 599 additions and 68 deletions

View File

@ -23,5 +23,7 @@
<file>CrawlCoreAssets/particles/sphere.png</file>
<file>CrawlCoreAssets/particles/smokeSprite.png</file>
<file>CrawlModule/particles/Fire.qml</file>
<file>CrawlModule/particles/Wint.qml</file>
<file>CrawlModule/particles/BaseAffector.qml</file>
</qresource>
</RCC>

View File

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

View File

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

View File

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

View File

@ -12,18 +12,20 @@ namespace CRAWL {
Fire::Fire(): ParticleEffect(AUTO_CLASS_NAME, "qrc:/CrawlModule/particles/Fire.qml") {
useDirectionVelosity({0, 0 ,0}, {10, 10, 0});
setParticleScale(4);
setParticleEndScale(12);
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(10);
setFireStrength(100);
}
void CRAWL::Fire::onIntersects(const IWorldItem *) {
@ -40,11 +42,11 @@ void Fire::setFireStrength(float newFireStrength) {
_fireStrength = newFireStrength;
setEmitRate(2 * _fireStrength);
setEmitRate(10 + _fireStrength);
setLifeSpan(1000 + _fireStrength);
auto vel = static_cast<VectorDirection*>(velocity());
vel->setVelosityDirection({0, 0 , _fireStrength});
vel->setVelosityDirection({0, 0 , _fireStrength / 4});
vel->setVelosityDirectionValatility({10, 10, 0});
emit fireStrengthChanged();

View File

@ -20,7 +20,7 @@ class Fire: public ParticleEffect
Q_OBJECT
/**
* @brief fireStrength This propertye chenge fire power. By Default it is 10.
* @brief fireStrength This propertye chenge fire power. By Default it is 100.
*/
Q_PROPERTY(float fireStrength READ fireStrength WRITE setFireStrength NOTIFY fireStrengthChanged)
public:

View File

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

View File

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

View File

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

View File

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

View File

@ -18,6 +18,31 @@ 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
{
@ -25,7 +50,7 @@ class CRAWL_EXPORT ParticleEffect : public IWorldItem
/**
* @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.
* 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)
@ -120,7 +145,7 @@ class CRAWL_EXPORT ParticleEffect : public IWorldItem
/**
* @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 propertye use ParticleEffect::useTargetVelosity and ParticleEffect::useDirectionVelosity methods
* @note For the initialisation of this property use ParticleEffect::useTargetVelosity and ParticleEffect::useDirectionVelosity methods
*/
Q_PROPERTY(QObject *velocity READ velocity NOTIFY velocityChanged)
@ -398,77 +423,77 @@ public:
signals:
/**
* @brief enabledChanged This signal emited when the enabled propertye changed.
* @brief enabledChanged This signal emited when the enabled property changed.
*/
void enabledChanged();
/**
* @brief emitRateChanged This signal emited when the emitRate propertye changed.
* @brief emitRateChanged This signal emited when the emitRate property changed.
*/
void emitRateChanged();
/**
* @brief depthBiasChanged This signal emited when the depthBias propertye changed.
* @brief depthBiasChanged This signal emited when the depthBias property changed.
*/
void depthBiasChanged();
/**
* @brief lifeSpanChanged This signal emited when the lifeSpan propertye changed.
* @brief lifeSpanChanged This signal emited when the lifeSpan property changed.
*/
void lifeSpanChanged();
/**
* @brief lifeSpanVariationChanged This signal emited when the ifeSpanVariation propertye changed.
* @brief lifeSpanVariationChanged This signal emited when the ifeSpanVariation property changed.
*/
void lifeSpanVariationChanged();
/**
* @brief particleEndScaleChanged This signal emited when the particleEndScale propertye changed.
* @brief particleEndScaleChanged This signal emited when the particleEndScale property changed.
*/
void particleEndScaleChanged();
/**
* @brief particleRotationVariationChanged This signal emited when the particleRotationVariation propertye changed.
* @brief particleRotationVariationChanged This signal emited when the particleRotationVariation property changed.
*/
void particleRotationVariationChanged();
/**
* @brief particleRotationVelocityChanged This signal emited when the particleRotationVelocity propertye changed.
* @brief particleRotationVelocityChanged This signal emited when the particleRotationVelocity property changed.
*/
void particleRotationVelocityChanged();
/**
* @brief particleRotationVelocityVariationChanged This signal emited when the particleRotationVelocityVariation propertye changed.
* @brief particleRotationVelocityVariationChanged This signal emited when the particleRotationVelocityVariation property changed.
*/
void particleRotationVelocityVariationChanged();
/**
* @brief particleScaleChanged This signal emited when the particleScale propertye changed.
* @brief particleScaleChanged This signal emited when the particleScale property changed.
*/
void particleScaleChanged();
/**
* @brief particleScaleVariationChanged This signal emited when the particleScaleVariation propertye changed.
* @brief particleScaleVariationChanged This signal emited when the particleScaleVariation property changed.
*/
void particleScaleVariationChanged();
/**
* @brief particleDelegateChanged This signal emited when the particleDelegate propertye changed.
* @brief particleDelegateChanged This signal emited when the particleDelegate property changed.
*/
void particleDelegateChanged();
/**
* @brief velocityChanged This signal emited when the velocity propertye changed.
* @brief velocityChanged This signal emited when the velocity property changed.
*/
void velocityChanged();
/**
* @brief particleShapeChanged This signal emited when the shape propertye changed.
* @brief particleShapeChanged This signal emited when the shape property changed.
*/
void particleShapeChanged();
/**
* @brief particleShapeChanged This signal emited when the particleRotation propertye changed.
* @brief particleShapeChanged This signal emited when the particleRotation property changed.
*/
void particleRotationChanged();

View File

@ -89,7 +89,7 @@ public:
/**
* @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 propertye will be workd only after invoke the useTargetVelosity method.
* @note This property will be workd only after invoke the useTargetVelosity method.
*/
void setVelosityMagnitude(float newVelosityMagnitude);
@ -104,7 +104,7 @@ public:
/**
* @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 propertye will be workd only after invoke the useTargetVelosity method.
* @note This property will be workd only after invoke the useTargetVelosity method.
*/
void setVelosityMagnitudeVariation(float newVelosityMagnitudeVariation);
@ -120,7 +120,7 @@ public:
/**
* @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 propertye will be workd only after invoke the useTargetVelosity method.
* @note This property will be workd only after invoke the useTargetVelosity method.
*/
void setVelosityNormalized(bool newVelosityNormalized);
@ -134,7 +134,7 @@ public:
/**
* @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 propertye will be workd only after invoke the useTargetVelosity method.
* @note This property will be workd only after invoke the useTargetVelosity method.
*/
void setVelosityTargetPosition(const QVector3D &newVelosityTargetPosition);
@ -148,34 +148,34 @@ public:
/**
* @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 propertye will be workd only after invoke the useTargetVelosity method.
* @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 propertye changed.
* @brief velosityMagnitudeChanged This signal emited when the velosityMagnitude property changed.
*/
void velosityMagnitudeChanged();
/**
* @brief velosityMagnitudeVariationChanged This signal emited when the velosityMagnitudeVariation propertye changed.
* @brief velosityMagnitudeVariationChanged This signal emited when the velosityMagnitudeVariation property changed.
*/
void velosityMagnitudeVariationChanged();
/**
* @brief velosityNormalizedChanged This signal emited when the velosityNormalized propertye changed.
* @brief velosityNormalizedChanged This signal emited when the velosityNormalized property changed.
*/
void velosityNormalizedChanged();
/**
* @brief velosityTargetPositionChanged This signal emited when the velosityTargetPosition propertye changed.
* @brief velosityTargetPositionChanged This signal emited when the velosityTargetPosition property changed.
*/
void velosityTargetPositionChanged();
/**
* @brief velosityTargetPositionVariationChanged This signal emited when the velosityTargetPositionVariation propertye changed.
* @brief velosityTargetPositionVariationChanged This signal emited when the velosityTargetPositionVariation property changed.
*/
void velosityTargetPositionVariationChanged();

View File

@ -60,7 +60,7 @@ public:
/**
* @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 propertye will be workd only after invoke the useDirectionVelosity method.
* @note This property will be workd only after invoke the useDirectionVelosity method.
*/
void setVelosityDirection(const QVector3D &newVelosityDirection);
@ -74,19 +74,19 @@ public:
/**
* @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 propertye will be workd only after invoke the useDirectionVelosity method.
* @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 propertye changed.
* @brief velosityDirectionChanged This signal emited when the velosityDirection property changed.
*/
void velosityDirectionChanged();
/**
* @brief velosityDirectionValatilityChanged This signal emited when the velosityDirectionValatility propertye changed.
* @brief velosityDirectionValatilityChanged This signal emited when the velosityDirectionValatility property changed.
*/
void velosityDirectionValatilityChanged();

View File

@ -47,7 +47,7 @@ public:
/**
* @brief viewObject This is object of view companent.
* @note For working with the view propertyes use the QOBject::getPropertye and QObject::setPropertye methods. For invoke view method use the "QMetaObject::invokeMethod" method.
* @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

40
src/Core/Crawl/wint.cpp Normal file
View 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
View 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

View File

@ -43,7 +43,6 @@ View3D {
ParticleSystem3D {
id: privateRoot
property var arrayObjects: []
property var world: (model)? model.world: null

View File

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

View File

@ -11,8 +11,7 @@ import QtQuick3D.Particles3D
ParticleEffect {
PointLight {
position: parent.position
brightness: 100 * (model)? model.fireStrength: 0;
brightness: (model)? Math.sqrt(model.fireStrength): 0;
color: (model)? model.color: "#ffffff";
}
}

View File

@ -24,7 +24,7 @@ ParticleEmitter3D {
depthBias: (model)? model.depthBias: 0
emitRate: (model)? model.emitRate: 0
enabled: (model)? model.enabled: false
enabled: (model)? model.enabled: true
lifeSpan: (model)? model.lifeSpan: 0
lifeSpanVariation: (model)? model.lifeSpanVariation: 0
particleEndScale: (model)? model.particleEndScale: 0
@ -80,10 +80,11 @@ ParticleEmitter3D {
root.velocity = view = obj;
} else {
console.log("wrong viewTemplate in model " + temp.errorString());
console.log("wrong path (viewTemplate property) ot thq velosity module " + temp.errorString());
}
}
}
onDelegateChanged: () => {
let temp = Qt.createComponent(privateRoot.delegate)
@ -93,7 +94,7 @@ ParticleEmitter3D {
if (temp.status === Component.Ready) {
root.particle = temp.createObject(root.parent);
} else {
console.log("wrong viewTemplate in model " + temp.errorString());
console.log("wrong path to the in model " + temp.errorString());
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -14,6 +14,7 @@
#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>
@ -32,6 +33,8 @@ CRAWL::WorldRule *World::initWorldRules() {
return new CRAWL::WorldRule {
{0, {{registerObject<Box>(), 100},
{registerObject<CRAWL::Fire>(), 10},
{registerObject<CRAWL::DynamicWint>(), 1},
{registerObject<Background>(), 1},
{registerObject<Day>(), 1}}}
};