include(debugger/debugger.pri)
include(scenegraph/scenegraph.pri)
include(items/items.pri)
+include(particles/particles.pri)
symbian: {
TARGET.UID3=0x2001E623
$$PWD/qsgcanvasitem_p.h \
$$PWD/qsgcontext2d_p.h \
$$PWD/qsgcontext2d_p_p.h \
+ $$PWD/qsgspriteengine_p.h \
+ $$PWD/qsgsprite_p.h \
+ $$PWD/qsgspriteimage_p.h \
SOURCES += \
$$PWD/qsgevents.cpp \
$$PWD/qsgimplicitsizeitem.cpp \
$$PWD/qsgcanvasitem.cpp \
$$PWD/qsgcontext2d.cpp \
+ $$PWD/qsgspriteengine.cpp \
+ $$PWD/qsgsprite.cpp \
+ $$PWD/qsgspriteimage.cpp \
SOURCES += \
$$PWD/qsgshadereffectitem.cpp \
//#include "private/qsgpincharea_p.h"
#include "qsgcanvasitem_p.h"
#include "qsgcontext2d_p.h"
+#include "qsgsprite_p.h"
+#include "qsgspriteimage_p.h"
static QDeclarativePrivate::AutoParentResult qsgitem_autoParent(QObject *obj, QObject *parent)
{
qmlRegisterType<QSGContext2D>();
qmlRegisterType<QSGCanvasGradient>();
+ qmlRegisterType<QSGSprite>("QtQuick", 2, 0, "Sprite");
+ qmlRegisterType<QSGSpriteImage>("QtQuick", 2, 0, "SpriteImage");
qmlRegisterType<QSGParentChange>(uri, major, minor,"ParentChange");
qmlRegisterType<QSGAnchorChanges>(uri, major, minor,"AnchorChanges");
**
****************************************************************************/
-#include "spritestate.h"
+#include "qsgsprite_p.h"
QT_BEGIN_NAMESPACE
-SpriteState::SpriteState(QObject *parent) :
+QSGSprite::QSGSprite(QObject *parent) :
QObject(parent)
, m_generatedCount(0)
, m_framesPerRow(0)
QT_MODULE(Declarative)
-class SpriteState : public QObject
+class QSGSprite : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QVariantMap to READ to WRITE setTo NOTIFY toChanged)
public:
- explicit SpriteState(QObject *parent = 0);
+ explicit QSGSprite(QObject *parent = 0);
QUrl source() const
{
}
private:
- friend class SpriteParticle;
- friend class SpriteEngine;
+ friend class QSGImageParticle;
+ friend class QSGSpriteEngine;
int m_generatedCount;
int m_framesPerRow;
QUrl m_source;
**
****************************************************************************/
-#include "spriteengine.h"
-#include "spritestate.h"
+#include "qsgspriteengine_p.h"
+#include "qsgsprite_p.h"
#include <QDebug>
#include <QPainter>
#include <QSet>
QT_BEGIN_NAMESPACE
-SpriteEngine::SpriteEngine(QObject *parent) :
+QSGSpriteEngine::QSGSpriteEngine(QObject *parent) :
QObject(parent), m_timeOffset(0)
{
//Default size 1
m_advanceTime.start();
}
-SpriteEngine::SpriteEngine(QList<SpriteState*> states, QObject *parent) :
+QSGSpriteEngine::QSGSpriteEngine(QList<QSGSprite*> states, QObject *parent) :
QObject(parent), m_states(states), m_timeOffset(0)
{
//Default size 1
m_advanceTime.start();
}
-SpriteEngine::~SpriteEngine()
+QSGSpriteEngine::~QSGSpriteEngine()
{
}
-int SpriteEngine::maxFrames()
+int QSGSpriteEngine::maxFrames()
{
return m_maxFrames;
}
But States maintain their listed index for internal structures
TODO: All these calculations should be pre-calculated and cached during initialization for a significant performance boost
*/
-int SpriteEngine::spriteState(int sprite)
+int QSGSpriteEngine::spriteState(int sprite)
{
int state = m_sprites[sprite];
if(!m_states[state]->m_generatedCount)
return state + extra;
}
-int SpriteEngine::spriteStart(int sprite)
+int QSGSpriteEngine::spriteStart(int sprite)
{
int state = m_sprites[sprite];
if(!m_states[state]->m_generatedCount)
return state + extra*rowDuration;
}
-int SpriteEngine::spriteFrames(int sprite)
+int QSGSpriteEngine::spriteFrames(int sprite)
{
int state = m_sprites[sprite];
if(!m_states[state]->m_generatedCount)
return m_states[state]->m_framesPerRow;
}
-int SpriteEngine::spriteDuration(int sprite)
+int QSGSpriteEngine::spriteDuration(int sprite)
{
int state = m_sprites[sprite];
if(!m_states[state]->m_generatedCount)
return rowDuration;
}
-int SpriteEngine::spriteCount()//TODO: Actually image state count, need to rename these things to make sense together
+int QSGSpriteEngine::spriteCount()//TODO: Actually image state count, need to rename these things to make sense together
{
return m_imageStateCount;
}
-void SpriteEngine::setGoal(int state, int sprite, bool jump)
+void QSGSpriteEngine::setGoal(int state, int sprite, bool jump)
{
if(sprite >= m_sprites.count() || state >= m_states.count())
return;
return;
}
-QImage SpriteEngine::assembledImage()
+QImage QSGSpriteEngine::assembledImage()
{
int frameHeight = 0;
int frameWidth = 0;
int maxSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
- foreach(SpriteState* state, m_states){
+ foreach(QSGSprite* state, m_states){
if(state->frames() > m_maxFrames)
m_maxFrames = state->frames();
image.fill(0);
QPainter p(&image);
int y = 0;
- foreach(SpriteState* state, m_states){
+ foreach(QSGSprite* state, m_states){
QImage img(state->source().toLocalFile());
if(img.height() == frameHeight && img.width() < maxSize){//Simple case
p.drawImage(0,y,img);
return image;
}
-void SpriteEngine::setCount(int c)
+void QSGSpriteEngine::setCount(int c)
{
m_sprites.resize(c);
m_goals.resize(c);
m_startTimes.resize(c);
}
-void SpriteEngine::startSprite(int index)
+void QSGSpriteEngine::startSprite(int index)
{
if(index >= m_sprites.count())
return;
restartSprite(index);
}
-void SpriteEngine::restartSprite(int index)
+void QSGSpriteEngine::restartSprite(int index)
{
m_startTimes[index] = m_timeOffset + m_advanceTime.elapsed();
int time = m_states[m_sprites[index]]->duration() * m_states[m_sprites[index]]->frames() + m_startTimes[index];
addToUpdateList(time, index);
}
-uint SpriteEngine::updateSprites(uint time)
+uint QSGSpriteEngine::updateSprites(uint time)
{
//Sprite State Update;
while(!m_stateUpdates.isEmpty() && time >= m_stateUpdates.first().first){
return m_stateUpdates.first().first;
}
-int SpriteEngine::goalSeek(int curIdx, int spriteIdx, int dist)
+int QSGSpriteEngine::goalSeek(int curIdx, int spriteIdx, int dist)
{
QString goalName;
if(m_goals[spriteIdx] != -1)
return curIdx;
if(dist < 0)
dist = m_states.count();
- SpriteState* curState = m_states[curIdx];
+ QSGSprite* curState = m_states[curIdx];
for(QVariantMap::const_iterator iter = curState->m_to.constBegin();
iter!=curState->m_to.constEnd(); iter++){
if(iter.key() == goalName)
return -1;
}
-void SpriteEngine::addToUpdateList(uint t, int idx)
+void QSGSpriteEngine::addToUpdateList(uint t, int idx)
{
for(int i=0; i<m_stateUpdates.count(); i++){
if(m_stateUpdates[i].first==t){
QT_MODULE(Declarative)
-class SpriteState;
+class QSGSprite;
-class SpriteEngine : public QObject
+class QSGSpriteEngine : public QObject
{
Q_OBJECT
//TODO: Optimize single sprite case
- Q_PROPERTY(QDeclarativeListProperty<SpriteState> sprites READ sprites)
+ Q_PROPERTY(QDeclarativeListProperty<QSGSprite> sprites READ sprites)
Q_PROPERTY(QString globalGoal READ globalGoal WRITE setGlobalGoal NOTIFY globalGoalChanged)
public:
- explicit SpriteEngine(QObject *parent = 0);
- SpriteEngine(QList<SpriteState*> sprites, QObject *parent=0);
- ~SpriteEngine();
+ explicit QSGSpriteEngine(QObject *parent = 0);
+ QSGSpriteEngine(QList<QSGSprite*> sprites, QObject *parent=0);
+ ~QSGSpriteEngine();
- QDeclarativeListProperty<SpriteState> sprites()
+ QDeclarativeListProperty<QSGSprite> sprites()
{
- return QDeclarativeListProperty<SpriteState>(this, m_states);
+ return QDeclarativeListProperty<QSGSprite>(this, m_states);
}
QString globalGoal() const
{
void startSprite(int index=0);
private://Nothing outside should use this?
- friend class SpriteGoalAffector;//XXX: Fix interface
+ friend class QSGSpriteGoalAffector;//XXX: Fix interface
int stateCount() {return m_states.count();}
- int stateIndex(SpriteState* s){return m_states.indexOf(s);}//TODO: Does this need to be hidden?
- SpriteState* state(int idx){return m_states[idx];}//Used by spritegoal affector
+ int stateIndex(QSGSprite* s){return m_states.indexOf(s);}//TODO: Does this need to be hidden?
+ QSGSprite* state(int idx){return m_states[idx];}//Used by spritegoal affector
signals:
void globalGoalChanged(QString arg);
void restartSprite(int sprite);
void addToUpdateList(uint t, int idx);
int goalSeek(int curState, int spriteIdx, int dist=-1);
- QList<SpriteState*> m_states;
+ QList<QSGSprite*> m_states;
QVector<int> m_sprites;//int is the index in m_states of the current state
QVector<int> m_goals;
QVector<int> m_startTimes;
};
//Common use is to have your own list property which is transparently an engine
-inline void spriteAppend(QDeclarativeListProperty<SpriteState> *p, SpriteState* s)
+inline void spriteAppend(QDeclarativeListProperty<QSGSprite> *p, QSGSprite* s)
{
- reinterpret_cast<QList<SpriteState *> *>(p->data)->append(s);
+ reinterpret_cast<QList<QSGSprite *> *>(p->data)->append(s);
p->object->metaObject()->invokeMethod(p->object, "createEngine");
}
-inline SpriteState* spriteAt(QDeclarativeListProperty<SpriteState> *p, int idx)
+inline QSGSprite* spriteAt(QDeclarativeListProperty<QSGSprite> *p, int idx)
{
- return reinterpret_cast<QList<SpriteState *> *>(p->data)->at(idx);
+ return reinterpret_cast<QList<QSGSprite *> *>(p->data)->at(idx);
}
-inline void spriteClear(QDeclarativeListProperty<SpriteState> *p)
+inline void spriteClear(QDeclarativeListProperty<QSGSprite> *p)
{
- reinterpret_cast<QList<SpriteState *> *>(p->data)->clear();
+ reinterpret_cast<QList<QSGSprite *> *>(p->data)->clear();
p->object->metaObject()->invokeMethod(p->object, "createEngine");
}
-inline int spriteCount(QDeclarativeListProperty<SpriteState> *p)
+inline int spriteCount(QDeclarativeListProperty<QSGSprite> *p)
{
- return reinterpret_cast<QList<SpriteState *> *>(p->data)->count();
+ return reinterpret_cast<QList<QSGSprite *> *>(p->data)->count();
}
QT_END_NAMESPACE
**
****************************************************************************/
-#include "spriteimage.h"
-#include "spritestate.h"
-#include "spriteengine.h"
+#include "qsgspriteimage_p.h"
+#include "qsgsprite_p.h"
+#include "qsgspriteengine_p.h"
#include <private/qsgcontext_p.h>
#include <private/qsgadaptationlayer_p.h>
#include <qsgnode.h>
QT_BEGIN_NAMESPACE
-class SpriteMaterial : public QSGMaterial
+class QSGSpriteMaterial : public QSGMaterial
{
public:
- SpriteMaterial();
- virtual ~SpriteMaterial();
+ QSGSpriteMaterial();
+ virtual ~QSGSpriteMaterial();
virtual QSGMaterialType *type() const { static QSGMaterialType type; return &type; }
virtual QSGMaterialShader *createShader() const;
virtual int compare(const QSGMaterial *other) const
{
- return this - static_cast<const SpriteMaterial *>(other);
+ return this - static_cast<const QSGSpriteMaterial *>(other);
}
QSGTexture *texture;
int height;
};
-SpriteMaterial::SpriteMaterial()
+QSGSpriteMaterial::QSGSpriteMaterial()
: timestamp(0)
, timelength(1)
, framecount(1)
setFlag(Blending, true);
}
-SpriteMaterial::~SpriteMaterial()
+QSGSpriteMaterial::~QSGSpriteMaterial()
{
delete texture;
}
public:
SpriteMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
{
- QFile vf(vertexFile ? vertexFile : ":resources/spriteimagevertex.shader");
+ QFile vf(vertexFile ? vertexFile : ":defaultshaders/spriteimagevertex.shader");
vf.open(QFile::ReadOnly);
m_vertex_code = vf.readAll();
- QFile ff(fragmentFile ? fragmentFile : ":resources/spriteimagefragment.shader");
+ QFile ff(fragmentFile ? fragmentFile : ":defaultshaders/spriteimagefragment.shader");
ff.open(QFile::ReadOnly);
m_fragment_code = ff.readAll();
virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *)
{
- SpriteMaterial *m = static_cast<SpriteMaterial *>(newEffect);
+ QSGSpriteMaterial *m = static_cast<QSGSpriteMaterial *>(newEffect);
m->texture->bind();
program()->setUniformValue(m_opacity_id, state.opacity());
};
float SpriteMaterialData::chunkOfBytes[1024];
-QSGMaterialShader *SpriteMaterial::createShader() const
+QSGMaterialShader *QSGSpriteMaterial::createShader() const
{
return new SpriteMaterialData;
}
SpriteVertex v4;
};
-SpriteImage::SpriteImage(QSGItem *parent) :
+QSGSpriteImage::QSGSpriteImage(QSGItem *parent) :
QSGItem(parent)
, m_node(0)
, m_material(0)
this, SLOT(update()));
}
-QDeclarativeListProperty<SpriteState> SpriteImage::sprites()
+QDeclarativeListProperty<QSGSprite> QSGSpriteImage::sprites()
{
- return QDeclarativeListProperty<SpriteState>(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);
+ return QDeclarativeListProperty<QSGSprite>(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);
}
-void SpriteImage::createEngine()
+void QSGSpriteImage::createEngine()
{
//TODO: delay until component complete
if(m_spriteEngine)
delete m_spriteEngine;
if(m_sprites.count())
- m_spriteEngine = new SpriteEngine(m_sprites, this);
+ m_spriteEngine = new QSGSpriteEngine(m_sprites, this);
else
m_spriteEngine = 0;
reset();
SpriteImage_Attributes
};
-QSGGeometryNode* SpriteImage::buildNode()
+QSGGeometryNode* QSGSpriteImage::buildNode()
{
if (!m_spriteEngine) {
qWarning() << "SpriteImage: No sprite engine...";
m_material = 0;
}
- m_material = new SpriteMaterial();
+ m_material = new QSGSpriteMaterial();
QImage image = m_spriteEngine->assembledImage();
if(image.isNull())
return m_node;
}
-void SpriteImage::reset()
+void QSGSpriteImage::reset()
{
m_pleaseReset = true;
}
-QSGNode *SpriteImage::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
+QSGNode *QSGSpriteImage::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
{
if(m_pleaseReset){
delete m_node;
return m_node;
}
-void SpriteImage::prepareNextFrame()
+void QSGSpriteImage::prepareNextFrame()
{
if (m_node == 0)
m_node = buildNode();
QT_MODULE(Declarative)
class QSGContext;
-class SpriteState;
-class SpriteEngine;
+class QSGSprite;
+class QSGSpriteEngine;
class QSGGeometryNode;
-class SpriteMaterial;
-class SpriteImage : public QSGItem
+class QSGSpriteMaterial;
+class QSGSpriteImage : public QSGItem
{
Q_OBJECT
Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged)
//###try to share similar spriteEngines for less overhead?
- Q_PROPERTY(QDeclarativeListProperty<SpriteState> sprites READ sprites)
+ Q_PROPERTY(QDeclarativeListProperty<QSGSprite> sprites READ sprites)
Q_CLASSINFO("DefaultProperty", "sprites")
public:
- explicit SpriteImage(QSGItem *parent = 0);
+ explicit QSGSpriteImage(QSGItem *parent = 0);
- QDeclarativeListProperty<SpriteState> sprites();
+ QDeclarativeListProperty<QSGSprite> sprites();
bool running() const
{
void prepareNextFrame();
QSGGeometryNode* buildNode();
QSGGeometryNode *m_node;
- SpriteMaterial *m_material;
- QList<SpriteState*> m_sprites;
- SpriteEngine* m_spriteEngine;
+ QSGSpriteMaterial *m_material;
+ QList<QSGSprite*> m_sprites;
+ QSGSpriteEngine* m_spriteEngine;
QTime m_timestamp;
int m_maxFrames;
bool m_pleaseReset;
--- /dev/null
+INCLUDEPATH += $$PWD
+
+HEADERS += \
+ $$PWD/qsgangleddirection_p.h \
+ $$PWD/qsgcustomparticle_p.h \
+ $$PWD/qsgellipseextruder_p.h \
+ $$PWD/qsgemitter_p.h \
+ $$PWD/qsgfollowemitter_p.h \
+ $$PWD/qsgfriction_p.h \
+ $$PWD/qsggravity_p.h \
+ $$PWD/qsgimageparticle_p.h \
+ $$PWD/qsgitemparticle_p.h \
+ $$PWD/qsgkill_p.h \
+ $$PWD/qsglineextruder_p.h \
+ $$PWD/qsgmaskextruder_p.h \
+ $$PWD/qsgmodelparticle_p.h \
+ $$PWD/qsgparticleaffector_p.h \
+ $$PWD/qsgparticleemitter_p.h \
+ $$PWD/qsgparticleextruder_p.h \
+ $$PWD/qsgparticlepainter_p.h \
+ $$PWD/qsgparticlesmodule_p.h \
+ $$PWD/qsgparticlesystem_p.h \
+ $$PWD/qsgpointattractor_p.h \
+ $$PWD/qsgpointdirection_p.h \
+ $$PWD/qsgspritegoal_p.h \
+ $$PWD/qsgstochasticdirection_p.h \
+ $$PWD/qsgtargeteddirection_p.h \
+ $$PWD/qsgturbulence_p.h \
+ $$PWD/qsgwander_p.h
+
+SOURCES += \
+ $$PWD/qsgangleddirection.cpp \
+ $$PWD/qsgcustomparticle.cpp \
+ $$PWD/qsgellipseextruder.cpp \
+ $$PWD/qsgemitter.cpp \
+ $$PWD/qsgfollowemitter.cpp \
+ $$PWD/qsgfriction.cpp \
+ $$PWD/qsggravity.cpp \
+ $$PWD/qsgimageparticle.cpp \
+ $$PWD/qsgitemparticle.cpp \
+ $$PWD/qsgkill.cpp \
+ $$PWD/qsglineextruder.cpp \
+ $$PWD/qsgmaskextruder.cpp \
+ $$PWD/qsgmodelparticle.cpp \
+ $$PWD/qsgparticleaffector.cpp \
+ $$PWD/qsgparticleemitter.cpp \
+ $$PWD/qsgparticleextruder.cpp \
+ $$PWD/qsgparticlepainter.cpp \
+ $$PWD/qsgparticlesmodule.cpp \
+ $$PWD/qsgparticlesystem.cpp \
+ $$PWD/qsgpointattractor.cpp \
+ $$PWD/qsgpointdirection.cpp \
+ $$PWD/qsgspritegoal.cpp \
+ $$PWD/qsgstochasticdirection.cpp \
+ $$PWD/qsgtargeteddirection.cpp \
+ $$PWD/qsgturbulence.cpp \
+ $$PWD/qsgwander.cpp
+
+RESOURCES += \
+ $$PWD/particles.qrc
--- /dev/null
+<RCC>
+ <qresource prefix="/">
+ <file>defaultshaders/spritefragment.shader</file>
+ <file>defaultshaders/spritevertex.shader</file>
+ <file>defaultshaders/ctfragment.shader</file>
+ <file>defaultshaders/ctvertex.shader</file>
+ <file>defaultshaders/trailsfragment.shader</file>
+ <file>defaultshaders/trailsvertex.shader</file>
+ <file>defaultshaders/spriteimagefragment.shader</file>
+ <file>defaultshaders/spriteimagevertex.shader</file>
+ <file>defaultshaders/identitytable.png</file>
+ <file>defaultshaders/defaultFadeInOut.png</file>
+ <file>defaultshaders/deformablefragment.shader</file>
+ <file>defaultshaders/deformablevertex.shader</file>
+ <file>defaultshaders/ultravertex.shader</file>
+ <file>defaultshaders/ultrafragment.shader</file>
+ <file>defaultshaders/supervertex.shader</file>
+ <file>defaultshaders/superfragment.shader</file>
+ <file>defaultshaders/simplevertex.shader</file>
+ <file>defaultshaders/simplefragment.shader</file>
+ </qresource>
+</RCC>
**
****************************************************************************/
-#include "angledvector.h"
+#include "qsgangleddirection_p.h"
#include <cmath>
QT_BEGIN_NAMESPACE
const qreal CONV = 0.017453292519943295;
-AngledVector::AngledVector(QObject *parent) :
- VaryingVector(parent)
+QSGAngledDirection::QSGAngledDirection(QObject *parent) :
+ QSGStochasticDirection(parent)
, m_angle(0)
, m_magnitude(0)
, m_angleVariation(0)
}
-const QPointF &AngledVector::sample(const QPointF &from)
+const QPointF &QSGAngledDirection::sample(const QPointF &from)
{
//TODO: Faster
qreal theta = m_angle*CONV - m_angleVariation*CONV + rand()/float(RAND_MAX) * m_angleVariation*CONV * 2;
**
****************************************************************************/
-#ifndef ANGLEDVECTOR_H
-#define ANGLEDVECTOR_H
-#include "varyingvector.h"
+#ifndef QSGANGLEDDIRECTION_H
+#define QSGANGLEDDIRECTION_H
+#include "qsgstochasticdirection_p.h"
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class AngledVector : public VaryingVector
+class QSGAngledDirection : public QSGStochasticDirection
{
Q_OBJECT
Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged)
Q_PROPERTY(qreal angleVariation READ angleVariation WRITE setAngleVariation NOTIFY angleVariationChanged)
Q_PROPERTY(qreal magnitudeVariation READ magnitudeVariation WRITE setMagnitudeVariation NOTIFY magnitudeVariationChanged)
public:
- explicit AngledVector(QObject *parent = 0);
+ explicit QSGAngledDirection(QObject *parent = 0);
const QPointF &sample(const QPointF &from);
qreal angle() const
{
QT_END_NAMESPACE
QT_END_HEADER
-#endif // ANGLEDVECTOR_H
+#endif // QSGANGLEDDIRECTION_H
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgcustomparticle_p.h"
+#include <private/qsgshadereffectmesh_p.h>
+#include <cstdlib>
+
+QT_BEGIN_NAMESPACE
+/*
+ "uniform highp mat4 qt_ModelViewProjectionMatrix; \n"
+ "attribute highp vec4 qt_Vertex; \n"
+ "attribute highp vec2 qt_MultiTexCoord0; \n"
+ "varying highp vec2 qt_TexCoord0; \n"
+ "void main() { \n"
+ " qt_TexCoord0 = qt_MultiTexCoord0; \n"
+ " gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex; \n"
+ "}";
+*/
+//Includes comments because the code isn't self explanatory
+static const char qt_particles_default_vertex_code[] =
+ "attribute highp vec2 vPos; \n"
+ "attribute highp vec2 vTex; \n"
+ "attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize \n"
+ "attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration \n"
+ "uniform highp mat4 qt_ModelViewProjectionMatrix; \n"
+ "uniform highp float timestamp; \n"
+ "varying highp vec2 fTex; \n"
+ "void main() { \n"
+ " fTex = vTex; \n"
+ " highp float size = vData.z; \n"
+ " highp float endSize = vData.w; \n"
+ " highp float t = (timestamp - vData.x) / vData.y; \n"
+ " highp float currentSize = mix(size, endSize, t * t); \n"
+ " if (t < 0. || t > 1.) \n"
+ " currentSize = 0.; \n"
+ " highp vec2 pos = vPos \n"
+ " - currentSize / 2. + currentSize * vTex // adjust size \n"
+ " + vVec.xy * t * vData.y // apply speed vector.. \n"
+ " + 0.5 * vVec.zw * pow(t * vData.y, 2.); \n"
+ " gl_Position = qt_ModelViewProjectionMatrix * vec4(pos.x, pos.y, 0, 1); \n"
+ "}";
+
+static const char qt_particles_default_fragment_code[] =//TODO: Default frag requires source?
+ "uniform sampler2D source; \n"
+ "varying highp vec2 fTex; \n"
+ "uniform lowp float qt_Opacity; \n"
+ "void main() { \n"
+ " gl_FragColor = texture2D(source, fTex) * qt_Opacity; \n"
+ "}";
+
+/*
+static const char qt_particles_default_vertex_code[] =
+ "attribute highp vec2 vPos; \n"
+ "attribute highp vec2 vTex; \n"
+ "uniform highp mat4 qt_ModelViewProjectionMatrix; \n"
+ "void main() { \n"
+ " highp float currentSize = 1000.0; \n"
+ " highp vec2 pos = vec2(100.0,100.0) \n"
+ " - currentSize / 2. + currentSize * vTex; // adjust size \n"
+ " gl_Position = qt_ModelViewProjectionMatrix * vec4(pos.x, pos.y, 0, 1); \n"
+ "}";
+static const char qt_particles_default_fragment_code[] =//TODO: Default frag requires source?
+ "void main() { \n"
+ " gl_FragColor = vec4(0,255,0,255); \n"
+ "}";
+*/
+
+static const char qt_position_attribute_name[] = "qt_Vertex";
+static const char qt_texcoord_attribute_name[] = "qt_MultiTexCoord0";
+
+static QSGGeometry::Attribute PlainParticle_Attributes[] = {
+ { 0, 2, GL_FLOAT }, // Position
+ { 1, 2, GL_FLOAT }, // TexCoord
+ { 2, 4, GL_FLOAT }, // Data
+ { 3, 4, GL_FLOAT }, // Vectors
+ { 4, 1, GL_FLOAT } // r
+};
+
+static QSGGeometry::AttributeSet PlainParticle_AttributeSet =
+{
+ 5, // Attribute Count
+ (2 + 2 + 4 + 4 + 1) * sizeof(float),
+ PlainParticle_Attributes
+};
+
+struct PlainVertex {
+ float x;
+ float y;
+ float tx;
+ float ty;
+ float t;
+ float lifeSpan;
+ float size;
+ float endSize;
+ float sx;
+ float sy;
+ float ax;
+ float ay;
+ float r;
+};
+
+struct PlainVertices {
+ PlainVertex v1;
+ PlainVertex v2;
+ PlainVertex v3;
+ PlainVertex v4;
+};
+
+QSGCustomParticle::QSGCustomParticle(QSGItem* parent)
+ : QSGParticlePainter(parent)
+ , m_pleaseReset(true)
+ , m_dirtyData(true)
+{
+ setFlag(QSGItem::ItemHasContents);
+}
+
+void QSGCustomParticle::componentComplete()
+{
+ reset();
+ QSGParticlePainter::componentComplete();
+}
+
+
+//Trying to keep the shader conventions the same as in qsgshadereffectitem
+/*!
+ \qmlproperty string CustomParticle::fragmentShader
+
+ This property holds the fragment shader's GLSL source code.
+ The default shader passes the texture coordinate along to the fragment
+ shader as "varying highp vec2 qt_TexCoord0".
+*/
+
+void QSGCustomParticle::setFragmentShader(const QByteArray &code)
+{
+ if (m_source.fragmentCode.constData() == code.constData())
+ return;
+ m_source.fragmentCode = code;
+ if (isComponentComplete()) {
+ reset();
+ }
+ emit fragmentShaderChanged();
+}
+
+/*!
+ \qmlproperty string CustomParticle::vertexShader
+
+ This property holds the vertex shader's GLSL source code.
+ The default shader expects the texture coordinate to be passed from the
+ vertex shader as "varying highp vec2 qt_TexCoord0", and it samples from a
+ sampler2D named "source".
+*/
+
+void QSGCustomParticle::setVertexShader(const QByteArray &code)
+{
+ if (m_source.vertexCode.constData() == code.constData())
+ return;
+ m_source.vertexCode = code;
+ if (isComponentComplete()) {
+ reset();
+ }
+ emit vertexShaderChanged();
+}
+
+void QSGCustomParticle::setCount(int c)
+{
+ QSGParticlePainter::setCount(c);
+ m_pleaseReset = true;
+}
+
+void QSGCustomParticle::reset()
+{
+ disconnectPropertySignals();
+
+ m_source.attributeNames.clear();
+ m_source.uniformNames.clear();
+ m_source.respectsOpacity = false;
+ m_source.respectsMatrix = false;
+ m_source.className = metaObject()->className();
+
+ for (int i = 0; i < m_sources.size(); ++i) {
+ const SourceData &source = m_sources.at(i);
+ delete source.mapper;
+ if (source.item && source.item->parentItem() == this)
+ source.item->setParentItem(0);
+ }
+ m_sources.clear();
+
+ QSGParticlePainter::reset();
+ m_pleaseReset = true;
+}
+
+
+void QSGCustomParticle::changeSource(int index)
+{
+ Q_ASSERT(index >= 0 && index < m_sources.size());
+ QVariant v = property(m_sources.at(index).name.constData());
+ setSource(v, index);
+}
+
+void QSGCustomParticle::updateData()
+{
+ m_dirtyData = true;
+ update();
+}
+
+void QSGCustomParticle::setSource(const QVariant &var, int index)
+{
+ Q_ASSERT(index >= 0 && index < m_sources.size());
+
+ SourceData &source = m_sources[index];
+
+ source.item = 0;
+ if (var.isNull()) {
+ return;
+ } else if (!qVariantCanConvert<QObject *>(var)) {
+ qWarning("Could not assign source of type '%s' to property '%s'.", var.typeName(), source.name.constData());
+ return;
+ }
+
+ QObject *obj = qVariantValue<QObject *>(var);
+
+ QSGTextureProvider *int3rface = QSGTextureProvider::from(obj);
+ if (!int3rface) {
+ qWarning("Could not assign property '%s', did not implement QSGTextureProvider.", source.name.constData());
+ }
+
+ source.item = qobject_cast<QSGItem *>(obj);
+
+ // TODO: Copy better solution in QSGShaderEffectItem when they find it.
+ // 'source.item' needs a canvas to get a scenegraph node.
+ // The easiest way to make sure it gets a canvas is to
+ // make it a part of the same item tree as 'this'.
+ if (source.item && source.item->parentItem() == 0) {
+ source.item->setParentItem(this);
+ source.item->setVisible(false);
+ }
+}
+
+void QSGCustomParticle::disconnectPropertySignals()
+{
+ disconnect(this, 0, this, SLOT(updateData()));
+ for (int i = 0; i < m_sources.size(); ++i) {
+ SourceData &source = m_sources[i];
+ disconnect(this, 0, source.mapper, 0);
+ disconnect(source.mapper, 0, this, 0);
+ }
+}
+
+void QSGCustomParticle::connectPropertySignals()
+{
+ QSet<QByteArray>::const_iterator it;
+ for (it = m_source.uniformNames.begin(); it != m_source.uniformNames.end(); ++it) {
+ int pi = metaObject()->indexOfProperty(it->constData());
+ if (pi >= 0) {
+ QMetaProperty mp = metaObject()->property(pi);
+ if (!mp.hasNotifySignal())
+ qWarning("QSGShaderEffectItem: property '%s' does not have notification method!", it->constData());
+ QByteArray signalName("2");
+ signalName.append(mp.notifySignal().signature());
+ connect(this, signalName, this, SLOT(updateData()));
+ } else {
+ qWarning("QSGShaderEffectItem: '%s' does not have a matching property!", it->constData());
+ }
+ }
+ for (int i = 0; i < m_sources.size(); ++i) {
+ SourceData &source = m_sources[i];
+ int pi = metaObject()->indexOfProperty(source.name.constData());
+ if (pi >= 0) {
+ QMetaProperty mp = metaObject()->property(pi);
+ QByteArray signalName("2");
+ signalName.append(mp.notifySignal().signature());
+ connect(this, signalName, source.mapper, SLOT(map()));
+ source.mapper->setMapping(this, i);
+ connect(source.mapper, SIGNAL(mapped(int)), this, SLOT(changeSource(int)));
+ } else {
+ qWarning("QSGShaderEffectItem: '%s' does not have a matching source!", source.name.constData());
+ }
+ }
+}
+
+void QSGCustomParticle::updateProperties()
+{
+ QByteArray vertexCode = m_source.vertexCode;
+ QByteArray fragmentCode = m_source.fragmentCode;
+ if (vertexCode.isEmpty())
+ vertexCode = qt_particles_default_vertex_code;
+ if (fragmentCode.isEmpty())
+ fragmentCode = qt_particles_default_fragment_code;
+
+ m_source.attributeNames.clear();
+ m_source.attributeNames << "vPos" << "vTex" << "vData" << "vVec" << "r";
+
+ lookThroughShaderCode(vertexCode);
+ lookThroughShaderCode(fragmentCode);
+
+ if (!m_source.attributeNames.contains(qt_position_attribute_name))
+ qWarning("QSGShaderEffectItem: Missing reference to \'%s\'.", qt_position_attribute_name);
+ if (!m_source.attributeNames.contains(qt_texcoord_attribute_name))
+ qWarning("QSGShaderEffectItem: Missing reference to \'%s\'.", qt_texcoord_attribute_name);
+ if (!m_source.respectsMatrix)
+ qWarning("QSGShaderEffectItem: Missing reference to \'qt_ModelViewProjectionMatrix\'.");
+ if (!m_source.respectsOpacity)
+ qWarning("QSGShaderEffectItem: Missing reference to \'qt_Opacity\'.");
+
+ for (int i = 0; i < m_sources.size(); ++i) {
+ QVariant v = property(m_sources.at(i).name);
+ setSource(v, i);
+ }
+
+ connectPropertySignals();
+}
+
+void QSGCustomParticle::lookThroughShaderCode(const QByteArray &code)
+{
+ // Regexp for matching attributes and uniforms.
+ // In human readable form: attribute|uniform [lowp|mediump|highp] <type> <name>
+ static QRegExp re(QLatin1String("\\b(attribute|uniform)\\b\\s*\\b(?:lowp|mediump|highp)?\\b\\s*\\b(\\w+)\\b\\s*\\b(\\w+)"));
+ Q_ASSERT(re.isValid());
+
+ int pos = -1;
+
+ QString wideCode = QString::fromLatin1(code.constData(), code.size());
+
+ while ((pos = re.indexIn(wideCode, pos + 1)) != -1) {
+ QByteArray decl = re.cap(1).toLatin1(); // uniform or attribute
+ QByteArray type = re.cap(2).toLatin1(); // type
+ QByteArray name = re.cap(3).toLatin1(); // variable name
+
+ if (decl == "attribute") {
+ if(!m_source.attributeNames.contains(name))//TODO: Can they add custom attributes?
+ qWarning() << "Custom Particle: Unknown attribute " << name;
+ } else {
+ Q_ASSERT(decl == "uniform");//TODO: Shouldn't assert
+
+ if (name == "qt_ModelViewProjectionMatrix") {
+ m_source.respectsMatrix = true;
+ } else if (name == "qt_Opacity") {
+ m_source.respectsOpacity = true;
+ } else if (name == "timestamp") {
+ //TODO: Copy the whole thing just because I have one more uniform?
+ } else {
+ m_source.uniformNames.insert(name);
+ if (type == "sampler2D") {
+ SourceData d;
+ d.mapper = new QSignalMapper;
+ d.name = name;
+ d.item = 0;
+ m_sources.append(d);
+ }
+ }
+ }
+ }
+}
+
+QSGNode *QSGCustomParticle::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
+{
+ if(m_pleaseReset){
+ if(m_node)
+ delete m_node;
+ //delete m_material;//Shader effect item doesn't regen material?
+
+ m_node = 0;
+ m_pleaseReset = false;
+ m_dirtyData = false;
+ }
+
+ if(m_system && m_system->isRunning())
+ prepareNextFrame();
+ if (m_node){
+ if(oldNode)
+ Q_ASSERT(oldNode == m_node);
+ update();
+ m_node->markDirty(QSGNode::DirtyMaterial); //done in buildData?
+ }
+
+ return m_node;
+}
+
+void QSGCustomParticle::prepareNextFrame(){
+ if(!m_node)
+ m_node = buildCustomNode();
+ if(!m_node)
+ return;
+
+ m_lastTime = m_system->systemSync(this) / 1000.;
+ if(m_dirtyData || true)//Currently this is how we update timestamp... potentially over expensive.
+ buildData();
+}
+
+QSGShaderEffectNode* QSGCustomParticle::buildCustomNode()
+{
+ if (m_count * 4 > 0xffff) {
+ printf("CustomParticle: Too many particles... \n");//####Why is this here?
+ return 0;
+ }
+
+ if(m_count <= 0) {
+ printf("CustomParticle: Too few particles... \n");
+ return 0;
+ }
+
+
+ //Create Particle Geometry
+ int vCount = m_count * 4;
+ int iCount = m_count * 6;
+ QSGGeometry *g = new QSGGeometry(PlainParticle_AttributeSet, vCount, iCount);
+ g->setDrawingMode(GL_TRIANGLES);
+ PlainVertex *vertices = (PlainVertex *) g->vertexData();
+ for (int p=0; p<m_count; ++p) {
+ double r = rand()/(double)RAND_MAX;//TODO: Seed?
+ for (int i=0; i<4; ++i) {
+ vertices[i].x = 0;
+ vertices[i].y = 0;
+ vertices[i].t = -1;
+ vertices[i].lifeSpan = 0;
+ vertices[i].size = 0;
+ vertices[i].endSize = 0;
+ vertices[i].sx = 0;
+ vertices[i].sy = 0;
+ vertices[i].ax = 0;
+ vertices[i].ay = 0;
+ vertices[i].r = r;
+ }
+
+ vertices[0].tx = 0;
+ vertices[0].ty = 0;
+
+ vertices[1].tx = 1;
+ vertices[1].ty = 0;
+
+ vertices[2].tx = 0;
+ vertices[2].ty = 1;
+
+ vertices[3].tx = 1;
+ vertices[3].ty = 1;
+
+ vertices += 4;
+ }
+ quint16 *indices = g->indexDataAsUShort();
+ for (int i=0; i<m_count; ++i) {
+ int o = i * 4;
+ indices[0] = o;
+ indices[1] = o + 1;
+ indices[2] = o + 2;
+ indices[3] = o + 1;
+ indices[4] = o + 3;
+ indices[5] = o + 2;
+ indices += 6;
+ }
+
+ updateProperties();
+ QSGShaderEffectNode* node = new QSGShaderEffectNode();
+
+
+ node->setGeometry(g);
+ node->setMaterial(&m_material);
+
+ /*
+ //For debugging, just use grid vertices like ShaderEffect
+ node->setGeometry(0);
+ QSGShaderEffectMesh* mesh = new QSGGridMesh();
+ node->setFlag(QSGNode::OwnsGeometry, false);
+
+ qDebug() << m_source.attributeNames;
+ QSGGeometry* geometry = node->geometry();
+ geometry = mesh->updateGeometry(geometry, m_source.attributeNames, QRectF(0,0,width(),height()));
+ if(!geometry)
+ qDebug() << "Should have written the error handling";
+ else
+ qDebug() << "Mesh Loaded";
+ node->setGeometry(geometry);
+ qDebug() << QString("INIT") << geometry << (QObject*)node;
+ node->setFlag(QSGNode::OwnsGeometry, true);
+ */
+ QSGShaderEffectProgram s = m_source;
+ if (s.fragmentCode.isEmpty())
+ s.fragmentCode = qt_particles_default_fragment_code;
+ if (s.vertexCode.isEmpty())
+ s.vertexCode = qt_particles_default_vertex_code;
+ m_material.setProgramSource(s);
+ node->markDirty(QSGNode::DirtyMaterial);
+ node->markDirty(QSGNode::DirtyAll);
+ return node;
+}
+
+static const QByteArray timestampName("timestamp");
+
+void QSGCustomParticle::buildData()
+{
+ if(!m_node)//Operates on m_node
+ return;
+ QVector<QPair<QByteArray, QVariant> > values;
+ QVector<QPair<QByteArray, QPointer<QSGItem> > > textures;
+ const QVector<QPair<QByteArray, QPointer<QSGItem> > > &oldTextures = m_material.textureProviders();
+
+ for (QSet<QByteArray>::const_iterator it = m_source.uniformNames.begin();
+ it != m_source.uniformNames.end(); ++it) {
+ values.append(qMakePair(*it, property(*it)));
+ }
+ for (int i = 0; i < oldTextures.size(); ++i) {
+ QSGTextureProvider *oldSource = QSGTextureProvider::from(oldTextures.at(i).second);
+ if (oldSource && oldSource->textureChangedSignal())
+ disconnect(oldTextures.at(i).second, oldSource->textureChangedSignal(), m_node, SLOT(markDirtyTexture()));
+ }
+ for (int i = 0; i < m_sources.size(); ++i) {
+ const SourceData &source = m_sources.at(i);
+ textures.append(qMakePair(source.name, source.item));
+ QSGTextureProvider *t = QSGTextureProvider::from(source.item);
+ if (t && t->textureChangedSignal())
+ connect(source.item, t->textureChangedSignal(), m_node, SLOT(markDirtyTexture()), Qt::DirectConnection);
+ }
+ values.append(qMakePair(timestampName, QVariant(m_lastTime)));
+ m_material.setUniforms(values);
+ m_material.setTextureProviders(textures);
+ m_node->markDirty(QSGNode::DirtyMaterial);
+ m_dirtyData = false;
+}
+
+void QSGCustomParticle::load(QSGParticleData *d)
+{
+ reload(d);//We don't do anything special in C++ here.
+}
+
+void QSGCustomParticle::reload(QSGParticleData *d)
+{
+ if (m_node == 0)
+ return;
+
+ PlainVertices *particles = (PlainVertices *) m_node->geometry()->vertexData();
+
+ int pos = particleTypeIndex(d);
+
+ PlainVertices &p = particles[pos];
+
+ //Perhaps we could be more efficient?
+ vertexCopy(p.v1, d->pv);
+ vertexCopy(p.v2, d->pv);
+ vertexCopy(p.v3, d->pv);
+ vertexCopy(p.v4, d->pv);
+
+}
+
+QT_END_NAMESPACE
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CUSTOM_PARTICLE_H
+#define CUSTOM_PARTICLE_H
+#include "qsgparticlepainter_p.h"
+#include <QtDeclarative/private/qsgshadereffectnode_p.h>
+#include <QSignalMapper>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class QSGNode;
+
+//Genealogy: Hybrid of UltraParticle and ShaderEffectItem
+class QSGCustomParticle : public QSGParticlePainter
+{
+ Q_OBJECT
+ Q_PROPERTY(QByteArray fragmentShader READ fragmentShader WRITE setFragmentShader NOTIFY fragmentShaderChanged)
+ Q_PROPERTY(QByteArray vertexShader READ vertexShader WRITE setVertexShader NOTIFY vertexShaderChanged)
+
+public:
+ explicit QSGCustomParticle(QSGItem* parent=0);
+ virtual void load(QSGParticleData*);
+ virtual void reload(QSGParticleData*);
+ virtual void setCount(int c);
+
+ QByteArray fragmentShader() const { return m_source.fragmentCode; }
+ void setFragmentShader(const QByteArray &code);
+
+ QByteArray vertexShader() const { return m_source.vertexCode; }
+ void setVertexShader(const QByteArray &code);
+public Q_SLOTS:
+ void updateData();
+ void changeSource(int);
+Q_SIGNALS:
+ void fragmentShaderChanged();
+ void vertexShaderChanged();
+protected:
+ QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
+ void prepareNextFrame();
+ void setSource(const QVariant &var, int index);
+ void disconnectPropertySignals();
+ void connectPropertySignals();
+ void reset();
+ void updateProperties();
+ void lookThroughShaderCode(const QByteArray &code);
+ virtual void componentComplete();
+ QSGShaderEffectNode *buildCustomNode();
+
+private:
+ void buildData();
+
+ bool m_pleaseReset;
+ bool m_dirtyData;
+ QSGShaderEffectProgram m_source;
+ struct SourceData
+ {
+ QSignalMapper *mapper;
+ QPointer<QSGItem> item;
+ QByteArray name;
+ };
+ QVector<SourceData> m_sources;
+ QSGShaderEffectMaterial m_material;
+ QSGShaderEffectNode* m_node;
+ qreal m_lastTime;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif //HEADER_GUARD
**
****************************************************************************/
-#include "ellipseextruder.h"
+#include "qsgellipseextruder_p.h"
#include <cmath>
QT_BEGIN_NAMESPACE
-EllipseExtruder::EllipseExtruder(QObject *parent) :
- ParticleExtruder(parent)
+QSGEllipseExtruder::QSGEllipseExtruder(QObject *parent) :
+ QSGParticleExtruder(parent)
, m_fill(true)
{
}
-QPointF EllipseExtruder::extrude(const QRectF & r)
+QPointF QSGEllipseExtruder::extrude(const QRectF & r)
{
qreal theta = ((qreal)rand()/RAND_MAX) * 6.2831853071795862;
qreal mag = m_fill ? ((qreal)rand()/RAND_MAX) : 1;
r.y() + r.height()/2 + mag * (r.height()/2) * sin(theta));
}
-bool EllipseExtruder::contains(const QRectF &bounds, const QPointF &point)
+bool QSGEllipseExtruder::contains(const QRectF &bounds, const QPointF &point)
{
return bounds.contains(point);//TODO: Ellipse
}
#ifndef ELLIPSEEXTRUDER_H
#define ELLIPSEEXTRUDER_H
-#include "particleextruder.h"
+#include "qsgparticleextruder_p.h"
QT_BEGIN_HEADER
QT_MODULE(Declarative)
-class EllipseExtruder : public ParticleExtruder
+class QSGEllipseExtruder : public QSGParticleExtruder
{
Q_OBJECT
Q_PROPERTY(bool fill READ fill WRITE setFill NOTIFY fillChanged)//###Use base class? If it's still box
public:
- explicit EllipseExtruder(QObject *parent = 0);
+ explicit QSGEllipseExtruder(QObject *parent = 0);
virtual QPointF extrude(const QRectF &);
virtual bool contains(const QRectF &bounds, const QPointF &point);
**
****************************************************************************/
-#include "trailsemitter.h"
-#include "particlesystem.h"
-#include "particle.h"
+#include "qsgemitter_p.h"
+#include "qsgparticlesystem_p.h"
+#include "qsgparticlepainter_p.h"//TODO: What was this for again?
QT_BEGIN_NAMESPACE
-TrailsEmitter::TrailsEmitter(QSGItem* parent)
- : ParticleEmitter(parent)
+QSGBasicEmitter::QSGBasicEmitter(QSGItem* parent)
+ : QSGParticleEmitter(parent)
, m_speed_from_movement(0)
, m_particle_count(0)
, m_reset_last(true)
// setFlag(ItemHasContents);
}
-void TrailsEmitter::setSpeedFromMovement(qreal t)
+void QSGBasicEmitter::setSpeedFromMovement(qreal t)
{
if (t == m_speed_from_movement)
return;
emit speedFromMovementChanged();
}
-void TrailsEmitter::reset()
+void QSGBasicEmitter::reset()
{
m_reset_last = true;
}
-void TrailsEmitter::emitWindow(int timeStamp)
+void QSGBasicEmitter::emitWindow(int timeStamp)
{
if (m_system == 0)
return;
pt = time;
while (pt < time || !m_burstQueue.isEmpty()) {
//int pos = m_last_particle % m_particle_count;
- ParticleData* datum = m_system->newDatum(m_system->m_groupIds[m_particle]);
+ QSGParticleData* datum = m_system->newDatum(m_system->m_groupIds[m_particle]);
if(datum){//actually emit(otherwise we've been asked to skip this one)
datum->e = this;//###useful?
ParticleVertex &p = datum->pv;
#include <QtCore>
#include <QtGui>
-#include "particleemitter.h"
+#include "qsgparticleemitter_p.h"
QT_BEGIN_HEADER
QT_MODULE(Declarative)
-class ParticleTrailsMaterial;
class QSGGeometryNode;
-class TrailsEmitter : public ParticleEmitter
+class QSGBasicEmitter : public QSGParticleEmitter
{
Q_OBJECT
Q_PROPERTY(qreal speedFromMovement READ speedFromMovement WRITE setSpeedFromMovement NOTIFY speedFromMovementChanged)
public:
- explicit TrailsEmitter(QSGItem* parent=0);
- virtual ~TrailsEmitter(){}
+ explicit QSGBasicEmitter(QSGItem* parent=0);
+ virtual ~QSGBasicEmitter(){}
virtual void emitWindow(int timeStamp);
**
****************************************************************************/
-#include "followemitter.h"
-#include "particle.h"
+#include "qsgfollowemitter_p.h"
+#include "qsgparticlepainter_p.h"//TODO: What was this for again?
#include <cmath>
QT_BEGIN_NAMESPACE
-FollowEmitter::FollowEmitter(QSGItem *parent) :
- ParticleEmitter(parent)
+QSGFollowEmitter::QSGFollowEmitter(QSGItem *parent) :
+ QSGParticleEmitter(parent)
, m_particlesPerParticlePerSecond(0)
, m_lastTimeStamp(0)
, m_emitterXVariation(0)
, m_emitterYVariation(0)
, m_followCount(0)
, m_emissionExtruder(0)
- , m_defaultEmissionExtruder(new ParticleExtruder(this))
+ , m_defaultEmissionExtruder(new QSGParticleExtruder(this))
{
connect(this, SIGNAL(followChanged(QString)),
this, SLOT(recalcParticlesPerSecond()));
this, SLOT(recalcParticlesPerSecond()));
}
-void FollowEmitter::recalcParticlesPerSecond(){
+void QSGFollowEmitter::recalcParticlesPerSecond(){
if(!m_system)
return;
m_followCount = m_system->m_groupData[m_system->m_groupIds[m_follow]]->size;
}
}
-void FollowEmitter::reset()
+void QSGFollowEmitter::reset()
{
m_followCount = 0;
}
-void FollowEmitter::emitWindow(int timeStamp)
+void QSGFollowEmitter::emitWindow(int timeStamp)
{
if (m_system == 0)
return;
int gId2 = m_system->m_groupIds[m_particle];
for(int i=0; i<m_system->m_groupData[gId]->size; i++){
pt = m_lastEmission[i];
- ParticleData* d = m_system->m_data[i + m_system->m_groupData[gId]->start];
+ QSGParticleData* d = m_system->m_data[i + m_system->m_groupData[gId]->start];
if(!d || !d->stillAlive())
continue;
if(pt < d->pv.t)
continue;
}
while(pt < time || !m_burstQueue.isEmpty()){
- ParticleData* datum = m_system->newDatum(gId2);
+ QSGParticleData* datum = m_system->newDatum(gId2);
if(datum){//else, skip this emission
datum->e = this;//###useful?
ParticleVertex &p = datum->pv;
// sizeOffset*2,
// sizeOffset*2);
- ParticleExtruder* effectiveEmissionExtruder = m_emissionExtruder ? m_emissionExtruder : m_defaultEmissionExtruder;
+ QSGParticleExtruder* effectiveEmissionExtruder = m_emissionExtruder ? m_emissionExtruder : m_defaultEmissionExtruder;
const QPointF &newPos = effectiveEmissionExtruder->extrude(boundsRect);
p.x = newPos.x();
p.y = newPos.y();
#ifndef FOLLOWEMITTER_H
#define FOLLOWEMITTER_H
-#include "particleemitter.h"
-#include "particleaffector.h"
+#include "qsgparticleemitter_p.h"
+#include "qsgparticleaffector_p.h"
QT_BEGIN_HEADER
QT_MODULE(Declarative)
-class FollowEmitter : public ParticleEmitter
+class QSGFollowEmitter : public QSGParticleEmitter
{
Q_OBJECT
Q_PROPERTY(QString follow READ follow WRITE setFollow NOTIFY followChanged)
//TODO: Document that FollowEmitter's box is where it follows. It emits in a rect centered on the followed particle
//TODO: A set of properties that can involve the particle size of the followed
- Q_PROPERTY(ParticleExtruder* emissionShape READ emissonShape WRITE setEmissionShape NOTIFY emissionShapeChanged)
+ Q_PROPERTY(QSGParticleExtruder* emissionShape READ emissonShape WRITE setEmissionShape NOTIFY emissionShapeChanged)
Q_PROPERTY(qreal emissionHeight READ emitterYVariation WRITE setEmitterYVariation NOTIFY emitterYVariationChanged)
Q_PROPERTY(qreal emissionWidth READ emitterXVariation WRITE setEmitterXVariation NOTIFY emitterXVariationChanged)
public:
- explicit FollowEmitter(QSGItem *parent = 0);
+ explicit QSGFollowEmitter(QSGItem *parent = 0);
virtual void emitWindow(int timeStamp);
virtual void reset();
return m_follow;
}
- ParticleExtruder* emissonShape() const
+ QSGParticleExtruder* emissonShape() const
{
return m_emissionExtruder;
}
void followChanged(QString arg);
- void emissionShapeChanged(ParticleExtruder* arg);
+ void emissionShapeChanged(QSGParticleExtruder* arg);
public slots:
}
}
- void setEmissionShape(ParticleExtruder* arg)
+ void setEmissionShape(QSGParticleExtruder* arg)
{
if (m_emissionExtruder != arg) {
m_emissionExtruder = arg;
void recalcParticlesPerSecond();
private:
- QSet<ParticleData*> m_pending;
+ QSet<QSGParticleData*> m_pending;
QVector<qreal> m_lastEmission;
int m_particlesPerParticlePerSecond;
qreal m_lastTimeStamp;
qreal m_emitterYVariation;
QString m_follow;
int m_followCount;
- ParticleExtruder* m_emissionExtruder;
- ParticleExtruder* m_defaultEmissionExtruder;
+ QSGParticleExtruder* m_emissionExtruder;
+ QSGParticleExtruder* m_defaultEmissionExtruder;
};
QT_END_NAMESPACE
**
****************************************************************************/
-#include "frictionaffector.h"
+#include "qsgfriction_p.h"
QT_BEGIN_NAMESPACE
-FrictionAffector::FrictionAffector(QSGItem *parent) :
- ParticleAffector(parent), m_factor(0.0)
+QSGFrictionAffector::QSGFrictionAffector(QSGItem *parent) :
+ QSGParticleAffector(parent), m_factor(0.0)
{
}
-bool FrictionAffector::affectParticle(ParticleData *d, qreal dt)
+bool QSGFrictionAffector::affectParticle(QSGParticleData *d, qreal dt)
{
if(!m_factor)
return false;
#ifndef FRICTIONAFFECTOR_H
#define FRICTIONAFFECTOR_H
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
QT_BEGIN_HEADER
QT_MODULE(Declarative)
-class FrictionAffector : public ParticleAffector
+class QSGFrictionAffector : public QSGParticleAffector
{
Q_OBJECT
Q_PROPERTY(qreal factor READ factor WRITE setFactor NOTIFY factorChanged)
public:
- explicit FrictionAffector(QSGItem *parent = 0);
+ explicit QSGFrictionAffector(QSGItem *parent = 0);
qreal factor() const
{
return m_factor;
}
protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
signals:
void factorChanged(qreal arg);
**
****************************************************************************/
-#include "gravityaffector.h"
+#include "qsggravity_p.h"
#include <cmath>
QT_BEGIN_NAMESPACE
const qreal CONV = 0.017453292520444443;
-GravityAffector::GravityAffector(QSGItem *parent) :
- ParticleAffector(parent), m_acceleration(-10), m_angle(90), m_xAcc(0), m_yAcc(0)
+QSGGravityAffector::QSGGravityAffector(QSGItem *parent) :
+ QSGParticleAffector(parent), m_acceleration(-10), m_angle(90), m_xAcc(0), m_yAcc(0)
{
connect(this, SIGNAL(accelerationChanged(qreal)),
this, SLOT(recalc()));
recalc();
}
-void GravityAffector::recalc()
+void QSGGravityAffector::recalc()
{
qreal theta = m_angle * CONV;
m_xAcc = m_acceleration * cos(theta);
m_yAcc = m_acceleration * sin(theta);
}
-bool GravityAffector::affectParticle(ParticleData *d, qreal dt)
+bool QSGGravityAffector::affectParticle(QSGParticleData *d, qreal dt)
{
Q_UNUSED(dt);
bool changed = false;
#ifndef GRAVITYAFFECTOR_H
#define GRAVITYAFFECTOR_H
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
QT_BEGIN_HEADER
QT_MODULE(Declarative)
-class GravityAffector : public ParticleAffector
+class QSGGravityAffector : public QSGParticleAffector
{
Q_OBJECT
Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged)
public:
- explicit GravityAffector(QSGItem *parent = 0);
+ explicit QSGGravityAffector(QSGItem *parent = 0);
qreal acceleration() const
{
return m_acceleration;
return m_angle;
}
protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
signals:
void accelerationChanged(qreal arg);
#include <qsgtexturematerial.h>
#include <qsgtexture.h>
#include <QFile>
-#include "ultraparticle.h"
-#include "particleemitter.h"
-#include "spritestate.h"
-#include "spriteengine.h"
+#include "qsgimageparticle_p.h"
+#include "qsgparticleemitter_p.h"
+#include "qsgsprite_p.h"
+#include "qsgspriteengine_p.h"
#include <QGLFunctions>
#include <qsgengine.h>
public:
UltraMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
{
- QFile vf(vertexFile ? vertexFile : ":resources/ultravertex.shader");
+ QFile vf(vertexFile ? vertexFile : ":defaultshaders/ultravertex.shader");
vf.open(QFile::ReadOnly);
m_vertex_code = vf.readAll();
- QFile ff(fragmentFile ? fragmentFile : ":resources/ultrafragment.shader");
+ QFile ff(fragmentFile ? fragmentFile : ":defaultshaders/ultrafragment.shader");
ff.open(QFile::ReadOnly);
m_fragment_code = ff.readAll();
public:
SimpleMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
{
- QFile vf(vertexFile ? vertexFile : ":resources/simplevertex.shader");
+ QFile vf(vertexFile ? vertexFile : ":defaultshaders/simplevertex.shader");
vf.open(QFile::ReadOnly);
m_vertex_code = vf.readAll();
- QFile ff(fragmentFile ? fragmentFile : ":resources/simplefragment.shader");
+ QFile ff(fragmentFile ? fragmentFile : ":defaultshaders/simplefragment.shader");
ff.open(QFile::ReadOnly);
m_fragment_code = ff.readAll();
return new SimpleMaterialData;
}
-UltraParticle::UltraParticle(QSGItem* parent)
- : ParticleType(parent)
+QSGImageParticle::QSGImageParticle(QSGItem* parent)
+ : QSGParticlePainter(parent)
, m_do_reset(false)
, m_color_variation(0.0)
, m_node(0)
setFlag(ItemHasContents);
}
-QDeclarativeListProperty<SpriteState> UltraParticle::sprites()
+QDeclarativeListProperty<QSGSprite> QSGImageParticle::sprites()
{
- return QDeclarativeListProperty<SpriteState>(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);
+ return QDeclarativeListProperty<QSGSprite>(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);
}
-void UltraParticle::setImage(const QUrl &image)
+void QSGImageParticle::setImage(const QUrl &image)
{
if (image == m_image_name)
return;
}
-void UltraParticle::setColortable(const QUrl &table)
+void QSGImageParticle::setColortable(const QUrl &table)
{
if (table == m_colortable_name)
return;
reset();
}
-void UltraParticle::setSizetable(const QUrl &table)
+void QSGImageParticle::setSizetable(const QUrl &table)
{
if (table == m_sizetable_name)
return;
reset();
}
-void UltraParticle::setOpacitytable(const QUrl &table)
+void QSGImageParticle::setOpacitytable(const QUrl &table)
{
if (table == m_opacitytable_name)
return;
reset();
}
-void UltraParticle::setColor(const QColor &color)
+void QSGImageParticle::setColor(const QColor &color)
{
if (color == m_color)
return;
reset();
}
-void UltraParticle::setColorVariation(qreal var)
+void QSGImageParticle::setColorVariation(qreal var)
{
if (var == m_color_variation)
return;
reset();
}
-void UltraParticle::setAlphaVariation(qreal arg)
+void QSGImageParticle::setAlphaVariation(qreal arg)
{
if (m_alphaVariation != arg) {
m_alphaVariation = arg;
reset();
}
-void UltraParticle::setAlpha(qreal arg)
+void QSGImageParticle::setAlpha(qreal arg)
{
if (m_alpha != arg) {
m_alpha = arg;
reset();
}
-void UltraParticle::setRedVariation(qreal arg)
+void QSGImageParticle::setRedVariation(qreal arg)
{
if (m_redVariation != arg) {
m_redVariation = arg;
reset();
}
-void UltraParticle::setGreenVariation(qreal arg)
+void QSGImageParticle::setGreenVariation(qreal arg)
{
if (m_greenVariation != arg) {
m_greenVariation = arg;
reset();
}
-void UltraParticle::setBlueVariation(qreal arg)
+void QSGImageParticle::setBlueVariation(qreal arg)
{
if (m_blueVariation != arg) {
m_blueVariation = arg;
reset();
}
-void UltraParticle::setRotation(qreal arg)
+void QSGImageParticle::setRotation(qreal arg)
{
if (m_rotation != arg) {
m_rotation = arg;
reset();
}
-void UltraParticle::setRotationVariation(qreal arg)
+void QSGImageParticle::setRotationVariation(qreal arg)
{
if (m_rotationVariation != arg) {
m_rotationVariation = arg;
reset();
}
-void UltraParticle::setRotationSpeed(qreal arg)
+void QSGImageParticle::setRotationSpeed(qreal arg)
{
if (m_rotationSpeed != arg) {
m_rotationSpeed = arg;
reset();
}
-void UltraParticle::setRotationSpeedVariation(qreal arg)
+void QSGImageParticle::setRotationSpeedVariation(qreal arg)
{
if (m_rotationSpeedVariation != arg) {
m_rotationSpeedVariation = arg;
reset();
}
-void UltraParticle::setAutoRotation(bool arg)
+void QSGImageParticle::setAutoRotation(bool arg)
{
if (m_autoRotation != arg) {
m_autoRotation = arg;
reset();
}
-void UltraParticle::setXVector(VaryingVector* arg)
+void QSGImageParticle::setXVector(QSGStochasticDirection* arg)
{
if (m_xVector != arg) {
m_xVector = arg;
reset();
}
-void UltraParticle::setYVector(VaryingVector* arg)
+void QSGImageParticle::setYVector(QSGStochasticDirection* arg)
{
if (m_yVector != arg) {
m_yVector = arg;
reset();
}
-void UltraParticle::setBloat(bool arg)
+void QSGImageParticle::setBloat(bool arg)
{
if (m_bloat != arg) {
m_bloat = arg;
if(perfLevel < 9999)
reset();
}
-void UltraParticle::setCount(int c)
+void QSGImageParticle::setCount(int c)
{
- ParticleType::setCount(c);
+ QSGParticlePainter::setCount(c);
m_pleaseReset = true;
}
-void UltraParticle::reset()
+void QSGImageParticle::reset()
{
- ParticleType::reset();
+ QSGParticlePainter::reset();
m_pleaseReset = true;
}
-void UltraParticle::createEngine()
+void QSGImageParticle::createEngine()
{
if(m_spriteEngine)
delete m_spriteEngine;
if(m_sprites.count())
- m_spriteEngine = new SpriteEngine(m_sprites, this);
+ m_spriteEngine = new QSGSpriteEngine(m_sprites, this);
else
m_spriteEngine = 0;
reset();
UltraParticle_Attributes
};
-QSGGeometryNode* UltraParticle::buildSimpleParticleNode()
+QSGGeometryNode* QSGImageParticle::buildSimpleParticleNode()
{
perfLevel = Simple;//TODO: Intermediate levels
QImage image = QImage(m_image_name.toLocalFile());
return m_node;
}
-QSGGeometryNode* UltraParticle::buildParticleNode()
+QSGGeometryNode* QSGImageParticle::buildParticleNode()
{
if (m_count * 4 > 0xffff) {
printf("UltraParticle: Too many particles... \n");//####Why is this here?
QImage opacitytable(m_opacitytable_name.toLocalFile());
m_material = new UltraMaterial();
if(colortable.isNull())
- colortable = QImage(":resources/identitytable.png");
+ colortable = QImage(":defaultshaders/identitytable.png");
if(sizetable.isNull())
- sizetable = QImage(":resources/identitytable.png");
+ sizetable = QImage(":defaultshaders/identitytable.png");
if(opacitytable.isNull())
- opacitytable = QImage(":resources/defaultFadeInOut.png");
+ opacitytable = QImage(":defaultshaders/defaultFadeInOut.png");
Q_ASSERT(!colortable.isNull());
Q_ASSERT(!sizetable.isNull());
Q_ASSERT(!opacitytable.isNull());
return m_node;
}
-QSGNode *UltraParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
+QSGNode *QSGImageParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
{
if(m_pleaseReset){
if(m_node){
return m_node;
}
-void UltraParticle::prepareNextFrame()
+void QSGImageParticle::prepareNextFrame()
{
if (m_node == 0){ //TODO: Staggered loading (as emitted)
m_node = buildParticleNode();
return iv;
}
-IntermediateVertices* UltraParticle::fetchIntermediateVertices(int pos)
+IntermediateVertices* QSGImageParticle::fetchIntermediateVertices(int pos)
{
//Note that this class ruins typesafety for you. Maybe even thread safety.
//TODO: Something better, possibly with templates or inheritance
}
}
-void UltraParticle::reloadColor(const Color4ub &c, ParticleData* d)
+void QSGImageParticle::reloadColor(const Color4ub &c, QSGParticleData* d)
{
UltraVertices *particles = (UltraVertices *) m_node->geometry()->vertexData();
int pos = particleTypeIndex(d);
p.v1.color = p.v2.color = p.v3.color = p.v4.color = c;
}
-void UltraParticle::reload(ParticleData *d)
+void QSGImageParticle::reload(QSGParticleData *d)
{
if (m_node == 0)
return;
vertexCopy(*p->v4, d->pv);
}
-void UltraParticle::load(ParticleData *d)
+void QSGImageParticle::load(QSGParticleData *d)
{
if (m_node == 0)
return;
#ifndef ULTRAPARTICLE_H
#define ULTRAPARTICLE_H
-#include "particle.h"
-#include "varyingvector.h"
+#include "qsgparticlepainter_p.h"
+#include "qsgstochasticdirection_p.h"
#include <QDeclarativeListProperty>
-#include "coloredparticle.h"
-
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
class UltraMaterial;
class QSGGeometryNode;
-class SpriteState;
-class SpriteEngine;
+class QSGSprite;
+class QSGSpriteEngine;
-/*struct Color4ub {//in coloredparticle
+struct Color4ub {
uchar r;
uchar g;
uchar b;
uchar a;
-};*/
+};
struct SimpleVertex {
float x;
UltraVertex* v4;
};
-class UltraParticle : public ParticleType
+class QSGImageParticle : public QSGParticlePainter
{
Q_OBJECT
Q_PROPERTY(QUrl image READ image WRITE setImage NOTIFY imageChanged)
//###Call i/j? Makes more sense to those with vector calculus experience, and I could even add the cirumflex in QML?
//xVector is the vector from the top-left point to the top-right point, and is multiplied by current size
- Q_PROPERTY(VaryingVector* xVector READ xVector WRITE setXVector NOTIFY xVectorChanged)
+ Q_PROPERTY(QSGStochasticDirection* xVector READ xVector WRITE setXVector NOTIFY xVectorChanged)
//yVector is the same, but top-left to bottom-left. The particle is always a parallelogram.
- Q_PROPERTY(VaryingVector* yVector READ yVector WRITE setYVector NOTIFY yVectorChanged)
- Q_PROPERTY(QDeclarativeListProperty<SpriteState> sprites READ sprites)
+ Q_PROPERTY(QSGStochasticDirection* yVector READ yVector WRITE setYVector NOTIFY yVectorChanged)
+ Q_PROPERTY(QDeclarativeListProperty<QSGSprite> sprites READ sprites)
Q_PROPERTY(bool bloat READ bloat WRITE setBloat NOTIFY bloatChanged)//Just a debugging property to bypass optimizations
public:
- explicit UltraParticle(QSGItem *parent = 0);
- virtual ~UltraParticle(){}
+ explicit QSGImageParticle(QSGItem *parent = 0);
+ virtual ~QSGImageParticle(){}
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
+ virtual void load(QSGParticleData*);
+ virtual void reload(QSGParticleData*);
virtual void setCount(int c);
- QDeclarativeListProperty<SpriteState> sprites();
- SpriteEngine* spriteEngine() {return m_spriteEngine;}
+ QDeclarativeListProperty<QSGSprite> sprites();
+ QSGSpriteEngine* spriteEngine() {return m_spriteEngine;}
enum PerformanceLevel{//TODO: Expose?
Unknown = 0,
bool autoRotation() const { return m_autoRotation; }
- VaryingVector* xVector() const { return m_xVector; }
+ QSGStochasticDirection* xVector() const { return m_xVector; }
- VaryingVector* yVector() const { return m_yVector; }
+ QSGStochasticDirection* yVector() const { return m_yVector; }
bool bloat() const { return m_bloat; }
void autoRotationChanged(bool arg);
- void xVectorChanged(VaryingVector* arg);
+ void xVectorChanged(QSGStochasticDirection* arg);
- void yVectorChanged(VaryingVector* arg);
+ void yVectorChanged(QSGStochasticDirection* arg);
void bloatChanged(bool arg);
public slots:
- void reloadColor(const Color4ub &c, ParticleData* d);
+ void reloadColor(const Color4ub &c, QSGParticleData* d);
void setAlphaVariation(qreal arg);
void setAlpha(qreal arg);
void setAutoRotation(bool arg);
- void setXVector(VaryingVector* arg);
+ void setXVector(QSGStochasticDirection* arg);
- void setYVector(VaryingVector* arg);
+ void setYVector(QSGStochasticDirection* arg);
void setBloat(bool arg);
qreal m_rotationSpeed;
qreal m_rotationSpeedVariation;
bool m_autoRotation;
- VaryingVector* m_xVector;
- VaryingVector* m_yVector;
+ QSGStochasticDirection* m_xVector;
+ QSGStochasticDirection* m_yVector;
- QList<SpriteState*> m_sprites;
- SpriteEngine* m_spriteEngine;
+ QList<QSGSprite*> m_sprites;
+ QSGSpriteEngine* m_spriteEngine;
bool m_bloat;
PerformanceLevel perfLevel;
**
****************************************************************************/
-#include "itemparticle.h"
+#include "qsgitemparticle_p.h"
#include <QtDeclarative/private/qsgvisualitemmodel_p.h>
#include <qsgnode.h>
#include <QDebug>
QT_BEGIN_NAMESPACE
-ItemParticle::ItemParticle(QSGItem *parent) :
- ParticleType(parent), m_fade(true)
+QSGItemParticle::QSGItemParticle(QSGItem *parent) :
+ QSGParticlePainter(parent), m_fade(true)
{
setFlag(QSGItem::ItemHasContents);
}
-void ItemParticle::freeze(QSGItem* item)
+void QSGItemParticle::freeze(QSGItem* item)
{
m_stasis << item;
}
-void ItemParticle::unfreeze(QSGItem* item)
+void QSGItemParticle::unfreeze(QSGItem* item)
{
m_stasis.remove(item);
}
-void ItemParticle::take(QSGItem *item, bool prioritize)
+void QSGItemParticle::take(QSGItem *item, bool prioritize)
{
if(prioritize)
m_pendingItems.push_front(item);
m_pendingItems.push_back(item);
}
-void ItemParticle::give(QSGItem *item)
+void QSGItemParticle::give(QSGItem *item)
{
//TODO: This
}
-void ItemParticle::load(ParticleData* d)
+void QSGItemParticle::load(QSGParticleData* d)
{
if(m_pendingItems.isEmpty())
return;
qWarning() << "Current model particles prefers overwrite:false";
//remove old item from the particle that is dying to make room for this one
m_items[pos]->setOpacity(0.);
- ItemParticleAttached* mpa;
- if((mpa = qobject_cast<ItemParticleAttached*>(qmlAttachedPropertiesObject<ItemParticle>(m_items[pos], false))))
+ QSGItemParticleAttached* mpa;
+ if((mpa = qobject_cast<QSGItemParticleAttached*>(qmlAttachedPropertiesObject<QSGItemParticle>(m_items[pos], false))))
mpa->detach();//reparent as well?
m_items[pos] = 0;
m_data[pos] = 0;
m_pendingItems.pop_front();
m_items[pos]->setX(d->curX() - m_items[pos]->width()/2);
m_items[pos]->setY(d->curY() - m_items[pos]->height()/2);
- ItemParticleAttached* mpa = qobject_cast<ItemParticleAttached*>(qmlAttachedPropertiesObject<ItemParticle>(m_items[pos]));
+ QSGItemParticleAttached* mpa = qobject_cast<QSGItemParticleAttached*>(qmlAttachedPropertiesObject<QSGItemParticle>(m_items[pos]));
if(mpa){
mpa->m_mp = this;
mpa->attach();
m_activeCount++;
}
-void ItemParticle::reload(ParticleData* d)
+void QSGItemParticle::reload(QSGParticleData* d)
{
//No-op unless we start copying the data.
}
-void ItemParticle::setCount(int c)
+void QSGItemParticle::setCount(int c)
{
- ParticleType::setCount(c);//###Do we need our own?
+ QSGParticlePainter::setCount(c);//###Do we need our own?
m_particleCount = c;
reset();
}
-int ItemParticle::count()
+int QSGItemParticle::count()
{
return m_particleCount;
}
-void ItemParticle::reset()
+void QSGItemParticle::reset()
{
- ParticleType::reset();
+ QSGParticlePainter::reset();
//TODO: Cleanup items?
m_items.resize(m_particleCount);
m_data.resize(m_particleCount);
}
-QSGNode* ItemParticle::updatePaintNode(QSGNode* n, UpdatePaintNodeData* d)
+QSGNode* QSGItemParticle::updatePaintNode(QSGNode* n, UpdatePaintNodeData* d)
{
//Dummy update just to get painting tick
if(m_pleaseReset){
return QSGItem::updatePaintNode(n,d);
}
-void ItemParticle::prepareNextFrame()
+void QSGItemParticle::prepareNextFrame()
{
qint64 timeStamp = m_system->systemSync(this);
qreal curT = timeStamp/1000.0;
//TODO: Size, better fade?
for(int i=0; i<m_particleCount; i++){
QSGItem* item = m_items[i];
- ParticleData* data = m_data[i];
+ QSGParticleData* data = m_data[i];
if(!item || !data)
continue;
qreal t = ((timeStamp/1000.0) - data->pv.t) / data->pv.lifeSpan;
}
if(t >= 1.0){//Usually happens from load
item->setOpacity(0.);
- ItemParticleAttached* mpa;
- if((mpa = qobject_cast<ItemParticleAttached*>(qmlAttachedPropertiesObject<ItemParticle>(m_items[i]))))
+ QSGItemParticleAttached* mpa;
+ if((mpa = qobject_cast<QSGItemParticleAttached*>(qmlAttachedPropertiesObject<QSGItemParticle>(m_items[i]))))
mpa->detach();//reparent as well?
m_items[i] = 0;
m_data[i] = 0;
}
}
-ItemParticleAttached *ItemParticle::qmlAttachedProperties(QObject *object)
+QSGItemParticleAttached *QSGItemParticle::qmlAttachedProperties(QObject *object)
{
- return new ItemParticleAttached(object);
+ return new QSGItemParticleAttached(object);
}
QT_END_NAMESPACE
#ifndef ITEMPARTICLE_H
#define ITEMPARTICLE_H
-#include "particle.h"
+#include "qsgparticlepainter_p.h"
#include <QPointer>
#include <QSet>
QT_BEGIN_HEADER
QT_MODULE(Declarative)
class QSGVisualDataModel;
-class ItemParticleAttached;
+class QSGItemParticleAttached;
-class ItemParticle : public ParticleType
+class QSGItemParticle : public QSGParticlePainter
{
Q_OBJECT
Q_PROPERTY(bool fade READ fade WRITE setFade NOTIFY fadeChanged)
public:
- explicit ItemParticle(QSGItem *parent = 0);
+ explicit QSGItemParticle(QSGItem *parent = 0);
bool fade() const { return m_fade; }
virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
+ virtual void load(QSGParticleData*);
+ virtual void reload(QSGParticleData*);
virtual void setCount(int c);
virtual int count();
- static ItemParticleAttached *qmlAttachedProperties(QObject *object);
+ static QSGItemParticleAttached *qmlAttachedProperties(QObject *object);
signals:
void fadeChanged();
QList<QSGItem*> m_pendingItems;
QVector<QSGItem*> m_items;
- QVector<ParticleData*> m_data;
+ QVector<QSGParticleData*> m_data;
QVector<int> m_idx;
QList<int> m_available;
QSet<QSGItem*> m_stasis;
int m_activeCount;
};
-class ItemParticleAttached : public QObject
+class QSGItemParticleAttached : public QObject
{
Q_OBJECT
- Q_PROPERTY(ItemParticle* particle READ particle CONSTANT);
+ Q_PROPERTY(QSGItemParticle* particle READ particle CONSTANT);
public:
- ItemParticleAttached(QObject* parent)
+ QSGItemParticleAttached(QObject* parent)
: QObject(parent), m_mp(0)
{;}
- ItemParticle* particle() {return m_mp;}
+ QSGItemParticle* particle() {return m_mp;}
void detach(){emit detached();}
void attach(){emit attached();}
private:
- ItemParticle* m_mp;
- friend class ItemParticle;
+ QSGItemParticle* m_mp;
+ friend class QSGItemParticle;
Q_SIGNALS:
void detached();
void attached();
QT_END_NAMESPACE
-QML_DECLARE_TYPEINFO(ItemParticle, QML_HAS_ATTACHED_PROPERTIES)
+QML_DECLARE_TYPEINFO(QSGItemParticle, QML_HAS_ATTACHED_PROPERTIES)
QT_END_HEADER
#endif // ITEMPARTICLE_H
**
****************************************************************************/
-#include "killaffector.h"
-#include "particleemitter.h"
+#include "qsgkill_p.h"
+#include "qsgparticleemitter_p.h"
QT_BEGIN_NAMESPACE
-KillAffector::KillAffector(QSGItem *parent) :
- ParticleAffector(parent)
+QSGKillAffector::QSGKillAffector(QSGItem *parent) :
+ QSGParticleAffector(parent)
{
}
-bool KillAffector::affectParticle(ParticleData *d, qreal dt)
+bool QSGKillAffector::affectParticle(QSGParticleData *d, qreal dt)
{
Q_UNUSED(dt);
if(d->stillAlive()){
#ifndef KILLAFFECTOR_H
#define KILLAFFECTOR_H
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
QT_BEGIN_HEADER
QT_MODULE(Declarative)
-class KillAffector : public ParticleAffector
+class QSGKillAffector : public QSGParticleAffector
{
Q_OBJECT
public:
- explicit KillAffector(QSGItem *parent = 0);
+ explicit QSGKillAffector(QSGItem *parent = 0);
protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
signals:
public slots:
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "lineextruder.h"
+#include "qsglineextruder_p.h"
#include <cmath>
-LineExtruder::LineExtruder(QObject *parent) :
- ParticleExtruder(parent), m_mirrored(false)
+QSGLineExtruder::QSGLineExtruder(QObject *parent) :
+ QSGParticleExtruder(parent), m_mirrored(false)
{
}
-QPointF LineExtruder::extrude(const QRectF &r)
+QPointF QSGLineExtruder::extrude(const QRectF &r)
{
qreal x,y;
if(!r.height()){
#ifndef LINEEXTRUDER_H
#define LINEEXTRUDER_H
-#include "particleextruder.h"
+#include "qsgparticleextruder_p.h"
-class LineExtruder : public ParticleExtruder
+class QSGLineExtruder : public QSGParticleExtruder
{
Q_OBJECT
//Default is topleft to bottom right. Flipped makes it topright to bottom left
Q_PROPERTY(bool mirrored READ mirrored WRITE setmirrored NOTIFY mirroredChanged)
public:
- explicit LineExtruder(QObject *parent = 0);
+ explicit QSGLineExtruder(QObject *parent = 0);
virtual QPointF extrude(const QRectF &);
bool mirrored() const
{
**
****************************************************************************/
-#include "maskextruder.h"
+#include "qsgmaskextruder_p.h"
#include <QImage>
#include <QDebug>
QT_BEGIN_NAMESPACE
-MaskExtruder::MaskExtruder(QObject *parent) :
- ParticleExtruder(parent)
+QSGMaskExtruder::QSGMaskExtruder(QObject *parent) :
+ QSGParticleExtruder(parent)
, m_lastWidth(-1)
, m_lastHeight(-1)
{
}
-QPointF MaskExtruder::extrude(const QRectF &r)
+QPointF QSGMaskExtruder::extrude(const QRectF &r)
{
ensureInitialized(r);
if(!m_mask.count())
return p + r.topLeft();
}
-bool MaskExtruder::contains(const QRectF &bounds, const QPointF &point)
+bool QSGMaskExtruder::contains(const QRectF &bounds, const QPointF &point)
{
ensureInitialized(bounds);//###Current usage patterns WILL lead to different bounds/r calls. Separate list?
QPoint p = point.toPoint() - bounds.topLeft().toPoint();
return m_img.rect().contains(p) && (bool)m_img.pixelIndex(p);
}
-void MaskExtruder::ensureInitialized(const QRectF &r)
+void QSGMaskExtruder::ensureInitialized(const QRectF &r)
{
if(m_lastWidth == r.width() && m_lastHeight == r.height())
return;
#ifndef MASKEXTRUDER_H
#define MASKEXTRUDER_H
-#include "particleextruder.h"
+#include "qsgparticleextruder_p.h"
#include <QUrl>
#include <QImage>
QT_MODULE(Declarative)
-class MaskExtruder : public ParticleExtruder
+class QSGMaskExtruder : public QSGParticleExtruder
{
Q_OBJECT
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
public:
- explicit MaskExtruder(QObject *parent = 0);
+ explicit QSGMaskExtruder(QObject *parent = 0);
virtual QPointF extrude(const QRectF &);
virtual bool contains(const QRectF &bounds, const QPointF &point);
**
****************************************************************************/
-#include "dataparticle.h"
+#include "qsgmodelparticle_p.h"
#include <QtDeclarative/private/qsgvisualitemmodel_p.h>
#include <qsgnode.h>
#include <QDebug>
QT_BEGIN_NAMESPACE
-DataParticle::DataParticle(QSGItem *parent) :
- ParticleType(parent), m_ownModel(false), m_comp(0), m_model(0), m_fade(true), m_modelCount(0)
+QSGModelParticle::QSGModelParticle(QSGItem *parent) :
+ QSGParticlePainter(parent), m_ownModel(false), m_comp(0), m_model(0), m_fade(true), m_modelCount(0)
{
setFlag(QSGItem::ItemHasContents);
}
-QVariant DataParticle::model() const
+QVariant QSGModelParticle::model() const
{
return m_dataSource;
}
-void DataParticle::setModel(const QVariant &arg)
+void QSGModelParticle::setModel(const QVariant &arg)
{
if(arg == m_dataSource)
return;
updateCount();
}
-void DataParticle::updateCount()
+void QSGModelParticle::updateCount()
{
int newCount = 0;
if(m_model)
m_modelCount = newCount;
}
-QDeclarativeComponent *DataParticle::delegate() const
+QDeclarativeComponent *QSGModelParticle::delegate() const
{
if(m_model)
return m_model->delegate();
return 0;
}
-void DataParticle::setDelegate(QDeclarativeComponent *comp)
+void QSGModelParticle::setDelegate(QDeclarativeComponent *comp)
{
if (QSGVisualDataModel *dataModel = qobject_cast<QSGVisualDataModel*>(m_model))
if (comp == dataModel->delegate())
emit delegateChanged();
}
-int DataParticle::modelCount() const
+int QSGModelParticle::modelCount() const
{
if(m_model)
- const_cast<DataParticle*>(this)->updateCount();//TODO: Investigate why this doesn't get called properly
+ const_cast<QSGModelParticle*>(this)->updateCount();//TODO: Investigate why this doesn't get called properly
return m_modelCount;
}
-void DataParticle::freeze(QSGItem* item)
+void QSGModelParticle::freeze(QSGItem* item)
{
m_stasis << item;
}
-void DataParticle::unfreeze(QSGItem* item)
+void QSGModelParticle::unfreeze(QSGItem* item)
{
m_stasis.remove(item);
}
-void DataParticle::load(ParticleData* d)
+void QSGModelParticle::load(QSGParticleData* d)
{
if(!m_model || !m_model->count())
return;
m_items[pos] = m_model->item(m_available.first());
m_idx[pos] = m_available.first();
m_available.pop_front();
- DataParticleAttached* mpa = qobject_cast<DataParticleAttached*>(qmlAttachedPropertiesObject<DataParticle>(m_items[pos]));
+ QSGModelParticleAttached* mpa = qobject_cast<QSGModelParticleAttached*>(qmlAttachedPropertiesObject<QSGModelParticle>(m_items[pos]));
if(mpa){
mpa->m_mp = this;
mpa->attach();
m_activeCount++;
}
-void DataParticle::reload(ParticleData* d)
+void QSGModelParticle::reload(QSGParticleData* d)
{
//No-op unless we start copying the data.
}
-void DataParticle::setCount(int c)
+void QSGModelParticle::setCount(int c)
{
- ParticleType::setCount(c);//###Do we need our own?
+ QSGParticlePainter::setCount(c);//###Do we need our own?
m_particleCount = c;
reset();
}
-int DataParticle::count()
+int QSGModelParticle::count()
{
return m_particleCount;
}
-void DataParticle::reset()
+void QSGModelParticle::reset()
{
- ParticleType::reset();
+ QSGParticlePainter::reset();
//TODO: Cleanup items?
m_items.resize(m_particleCount);
m_data.resize(m_particleCount);
}
-QSGNode* DataParticle::updatePaintNode(QSGNode* n, UpdatePaintNodeData* d)
+QSGNode* QSGModelParticle::updatePaintNode(QSGNode* n, UpdatePaintNodeData* d)
{
//Dummy update just to get painting tick
if(m_pleaseReset){
return QSGItem::updatePaintNode(n,d);
}
-void DataParticle::prepareNextFrame()
+void QSGModelParticle::prepareNextFrame()
{
qint64 timeStamp = m_system->systemSync(this);
qreal curT = timeStamp/1000.0;
//TODO: Size, better fade?
for(int i=0; i<m_particleCount; i++){
QSGItem* item = m_items[i];
- ParticleData* data = m_data[i];
+ QSGParticleData* data = m_data[i];
if(!item || !data)
continue;
qreal t = ((timeStamp/1000.0) - data->pv.t) / data->pv.lifeSpan;
}
}
-DataParticleAttached *DataParticle::qmlAttachedProperties(QObject *object)
+QSGModelParticleAttached *QSGModelParticle::qmlAttachedProperties(QObject *object)
{
- return new DataParticleAttached(object);
+ return new QSGModelParticleAttached(object);
}
QT_END_NAMESPACE
#ifndef DATAPARTICLE_H
#define DATAPARTICLE_H
-#include "particle.h"
+#include "qsgparticlepainter_p.h"
#include <QPointer>
#include <QSet>
QT_BEGIN_HEADER
QT_MODULE(Declarative)
class QSGVisualDataModel;
-class DataParticleAttached;
+class QSGModelParticleAttached;
-class DataParticle : public ParticleType
+class QSGModelParticle : public QSGParticlePainter
{
Q_OBJECT
Q_PROPERTY(bool fade READ fade WRITE setFade NOTIFY fadeChanged)
Q_CLASSINFO("DefaultProperty", "delegate")
public:
- explicit DataParticle(QSGItem *parent = 0);
+ explicit QSGModelParticle(QSGItem *parent = 0);
QVariant model() const;
void setModel(const QVariant &);
bool fade() const { return m_fade; }
virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
+ virtual void load(QSGParticleData*);
+ virtual void reload(QSGParticleData*);
virtual void setCount(int c);
virtual int count();
- static DataParticleAttached *qmlAttachedProperties(QObject *object);
+ static QSGModelParticleAttached *qmlAttachedProperties(QObject *object);
signals:
void modelChanged();
void delegateChanged();
QList<QSGItem*> m_pendingItems;
QVector<QSGItem*> m_items;
- QVector<ParticleData*> m_data;
+ QVector<QSGParticleData*> m_data;
QVector<int> m_idx;
QList<int> m_available;
QSet<QSGItem*> m_stasis;
int m_modelCount;
};
-class DataParticleAttached : public QObject
+class QSGModelParticleAttached : public QObject
{
Q_OBJECT
- Q_PROPERTY(DataParticle* particle READ particle CONSTANT);
+ Q_PROPERTY(QSGModelParticle* particle READ particle CONSTANT);
public:
- DataParticleAttached(QObject* parent)
+ QSGModelParticleAttached(QObject* parent)
: QObject(parent), m_mp(0)
{;}
- DataParticle* particle() {return m_mp;}
+ QSGModelParticle* particle() {return m_mp;}
void detach(){emit detached();}
void attach(){emit attached();}
private:
- DataParticle* m_mp;
- friend class DataParticle;
+ QSGModelParticle* m_mp;
+ friend class QSGModelParticle;
Q_SIGNALS:
void detached();
void attached();
QT_END_NAMESPACE
-QML_DECLARE_TYPEINFO(DataParticle, QML_HAS_ATTACHED_PROPERTIES)
+QML_DECLARE_TYPEINFO(QSGModelParticle, QML_HAS_ATTACHED_PROPERTIES)
QT_END_HEADER
#endif // DATAPARTICLE_H
**
****************************************************************************/
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
#include <QDebug>
QT_BEGIN_NAMESPACE
-ParticleAffector::ParticleAffector(QSGItem *parent) :
+QSGParticleAffector::QSGParticleAffector(QSGItem *parent) :
QSGItem(parent), m_needsReset(false), m_system(0), m_active(true)
- , m_updateIntSet(false), m_shape(new ParticleExtruder(this)), m_signal(false)
+ , m_updateIntSet(false), m_shape(new QSGParticleExtruder(this)), m_signal(false)
{
- connect(this, SIGNAL(systemChanged(ParticleSystem*)),
+ connect(this, SIGNAL(systemChanged(QSGParticleSystem*)),
this, SLOT(updateOffsets()));
connect(this, SIGNAL(xChanged()),
this, SLOT(updateOffsets()));
this, SLOT(updateOffsets()));//TODO: in componentComplete and all relevant signals
}
-void ParticleAffector::componentComplete()
+void QSGParticleAffector::componentComplete()
{
if(!m_system)
qWarning() << "Affector created without a particle system specified";//TODO: useful QML warnings, like line number?
QSGItem::componentComplete();
}
-void ParticleAffector::affectSystem(qreal dt)
+void QSGParticleAffector::affectSystem(qreal dt)
{
if(!m_active)
return;
}
//foreach(ParticleData* d, m_system->m_data){
for(int i=0; i<m_system->m_particle_count; i++){
- ParticleData* d = m_system->m_data[i];
+ QSGParticleData* d = m_system->m_data[i];
if(!d || (m_onceOff && m_onceOffed.contains(d->systemIndex)))
continue;
if(m_groups.isEmpty() || m_groups.contains(d->group)){
}
}
-bool ParticleAffector::affectParticle(ParticleData *d, qreal dt)
+bool QSGParticleAffector::affectParticle(QSGParticleData *d, qreal dt)
{
Q_UNUSED(d);
Q_UNUSED(dt);
return false;
}
-void ParticleAffector::reset(int idx)
+void QSGParticleAffector::reset(int idx)
{//TODO: This, among other ones, should be restructured so they don't all need to remember to call the superclass
if(m_onceOff)
m_onceOffed.remove(idx);
}
-void ParticleAffector::updateOffsets()
+void QSGParticleAffector::updateOffsets()
{
if(m_system)
m_offset = m_system->mapFromItem(this, QPointF(0, 0));
#define PARTICLEAFFECTOR_H
#include <QObject>
-#include "particlesystem.h"
-#include "particleextruder.h"
+#include "qsgparticlesystem_p.h"
+#include "qsgparticleextruder_p.h"
QT_BEGIN_HEADER
QT_MODULE(Declarative)
-class ParticleAffector : public QSGItem
+class QSGParticleAffector : public QSGItem
{
Q_OBJECT
- Q_PROPERTY(ParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
+ Q_PROPERTY(QSGParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
Q_PROPERTY(QStringList particles READ particles WRITE setParticles NOTIFY particlesChanged)
Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
Q_PROPERTY(bool onceOff READ onceOff WRITE setOnceOff NOTIFY onceOffChanged)
- Q_PROPERTY(ParticleExtruder* shape READ shape WRITE setShape NOTIFY shapeChanged)
+ Q_PROPERTY(QSGParticleExtruder* shape READ shape WRITE setShape NOTIFY shapeChanged)
Q_PROPERTY(bool signal READ signal WRITE setSignal NOTIFY signalChanged)
public:
- explicit ParticleAffector(QSGItem *parent = 0);
+ explicit QSGParticleAffector(QSGItem *parent = 0);
virtual void affectSystem(qreal dt);
virtual void reset(int systemIdx);//As some store their own data per idx?
- ParticleSystem* system() const
+ QSGParticleSystem* system() const
{
return m_system;
}
return m_onceOff;
}
- ParticleExtruder* shape() const
+ QSGParticleExtruder* shape() const
{
return m_shape;
}
signals:
- void systemChanged(ParticleSystem* arg);
+ void systemChanged(QSGParticleSystem* arg);
void particlesChanged(QStringList arg);
void onceOffChanged(bool arg);
- void shapeChanged(ParticleExtruder* arg);
+ void shapeChanged(QSGParticleExtruder* arg);
void affected(qreal x, qreal y);//###Idx too?
void signalChanged(bool arg);
public slots:
-void setSystem(ParticleSystem* arg)
+void setSystem(QSGParticleSystem* arg)
{
if (m_system != arg) {
m_system = arg;
}
}
-void setShape(ParticleExtruder* arg)
+void setShape(QSGParticleExtruder* arg)
{
if (m_shape != arg) {
m_shape = arg;
}
protected:
- friend class ParticleSystem;
- virtual bool affectParticle(ParticleData *d, qreal dt);
+ friend class QSGParticleSystem;
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
bool m_needsReset;//### What is this really saving?
- ParticleSystem* m_system;
+ QSGParticleSystem* m_system;
QStringList m_particles;
bool activeGroup(int g) {return m_groups.isEmpty() || m_groups.contains(g);}
bool m_active;
bool m_onceOff;
- ParticleExtruder* m_shape;
+ QSGParticleExtruder* m_shape;
bool m_signal;
**
****************************************************************************/
-#include "particleemitter.h"
+#include "qsgparticleemitter_p.h"
QT_BEGIN_NAMESPACE
-ParticleEmitter::ParticleEmitter(QSGItem *parent) :
+QSGParticleEmitter::QSGParticleEmitter(QSGItem *parent) :
QSGItem(parent)
, m_particlesPerSecond(10)
, m_particleDuration(1000)
this, SIGNAL(particleCountChanged()));
}
-ParticleEmitter::~ParticleEmitter()
+QSGParticleEmitter::~QSGParticleEmitter()
{
if(m_defaultExtruder)
delete m_defaultExtruder;
}
-void ParticleEmitter::componentComplete()
+void QSGParticleEmitter::componentComplete()
{
if(!m_system)
qWarning() << "Emitter created without a particle system specified";//TODO: useful QML warnings, like line number?
QSGItem::componentComplete();
}
-void ParticleEmitter::emitWindow(int timeStamp)
+void QSGParticleEmitter::emitWindow(int timeStamp)
{
Q_UNUSED(timeStamp);
}
-void ParticleEmitter::setEmitting(bool arg)
+void QSGParticleEmitter::setEmitting(bool arg)
{
if (m_emitting != arg) {
m_emitting = arg;
}
-ParticleExtruder* ParticleEmitter::effectiveExtruder()
+QSGParticleExtruder* QSGParticleEmitter::effectiveExtruder()
{
if(m_extruder)
return m_extruder;
if(!m_defaultExtruder)
- m_defaultExtruder = new ParticleExtruder;
+ m_defaultExtruder = new QSGParticleExtruder;
return m_defaultExtruder;
}
-void ParticleEmitter::pulse(qreal seconds)
+void QSGParticleEmitter::pulse(qreal seconds)
{
if(!particleCount())
qWarning() << "pulse called on an emitter with a particle count of zero";
m_burstLeft = seconds*1000.0;//TODO: Change name to match
}
-void ParticleEmitter::burst(int num)
+void QSGParticleEmitter::burst(int num)
{
if(!particleCount())
qWarning() << "burst called on an emitter with a particle count of zero";
m_burstQueue << qMakePair(num, QPointF(x(), y()));
}
-void ParticleEmitter::setMaxParticleCount(int arg)
+void QSGParticleEmitter::setMaxParticleCount(int arg)
{
if (m_maxParticleCount != arg) {
if(arg < 0 && m_maxParticleCount >= 0){
}
}
-int ParticleEmitter::particleCount() const
+int QSGParticleEmitter::particleCount() const
{
if(m_maxParticleCount >= 0)
return m_maxParticleCount;
#include <QSGItem>
#include <QDebug>
-#include "particlesystem.h"
-#include "particleextruder.h"
-#include "varyingvector.h"
+#include "qsgparticlesystem_p.h"
+#include "qsgparticleextruder_p.h"
+#include "qsgstochasticdirection_p.h"
#include <QList>
#include <QPair>
QT_MODULE(Declarative)
-class ParticleEmitter : public QSGItem
+class QSGParticleEmitter : public QSGItem
{
Q_OBJECT
//###currently goes in emitters OR sets system. Pick one?
- Q_PROPERTY(ParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
+ Q_PROPERTY(QSGParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
Q_PROPERTY(QString particle READ particle WRITE setParticle NOTIFY particleChanged)
- Q_PROPERTY(ParticleExtruder* shape READ extruder WRITE setExtruder NOTIFY extruderChanged)
+ Q_PROPERTY(QSGParticleExtruder* shape READ extruder WRITE setExtruder NOTIFY extruderChanged)
Q_PROPERTY(bool emitting READ emitting WRITE setEmitting NOTIFY emittingChanged)
Q_PROPERTY(qreal particlesPerSecond READ particlesPerSecond WRITE setParticlesPerSecond NOTIFY particlesPerSecondChanged)
Q_PROPERTY(qreal particleEndSize READ particleEndSize WRITE setParticleEndSize NOTIFY particleEndSizeChanged)
Q_PROPERTY(qreal particleSizeVariation READ particleSizeVariation WRITE setParticleSizeVariation NOTIFY particleSizeVariationChanged)
- Q_PROPERTY(VaryingVector *speed READ speed WRITE setSpeed NOTIFY speedChanged)
- Q_PROPERTY(VaryingVector *acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
+ Q_PROPERTY(QSGStochasticDirection *speed READ speed WRITE setSpeed NOTIFY speedChanged)
+ Q_PROPERTY(QSGStochasticDirection *acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
public:
- explicit ParticleEmitter(QSGItem *parent = 0);
- virtual ~ParticleEmitter();
+ explicit QSGParticleEmitter(QSGItem *parent = 0);
+ virtual ~QSGParticleEmitter();
virtual void emitWindow(int timeStamp);
bool emitting() const
return m_particleDuration;
}
- ParticleSystem* system() const
+ QSGParticleSystem* system() const
{
return m_system;
}
void particleDurationChanged(int);
void emittingChanged(bool);
- void systemChanged(ParticleSystem* arg);
+ void systemChanged(QSGParticleSystem* arg);
void particleChanged(QString arg);
void particleDurationVariationChanged(int arg);
- void extruderChanged(ParticleExtruder* arg);
+ void extruderChanged(QSGParticleExtruder* arg);
void particleSizeChanged(qreal arg);
void particleSizeVariationChanged(qreal arg);
- void speedChanged(VaryingVector * arg);
+ void speedChanged(QSGStochasticDirection * arg);
- void accelerationChanged(VaryingVector * arg);
+ void accelerationChanged(QSGStochasticDirection * arg);
void maxParticleCountChanged(int arg);
void particleCountChanged();
}
}
- void setSystem(ParticleSystem* arg)
+ void setSystem(QSGParticleSystem* arg)
{
if (m_system != arg) {
m_system = arg;
emit particleDurationVariationChanged(arg);
}
}
- void setExtruder(ParticleExtruder* arg)
+ void setExtruder(QSGParticleExtruder* arg)
{
if (m_extruder != arg) {
m_extruder = arg;
}
}
- void setSpeed(VaryingVector * arg)
+ void setSpeed(QSGStochasticDirection * arg)
{
if (m_speed != arg) {
m_speed = arg;
}
}
- void setAcceleration(VaryingVector * arg)
+ void setAcceleration(QSGStochasticDirection * arg)
{
if (m_acceleration != arg) {
m_acceleration = arg;
int particleCount() const;
virtual void reset(){;}
- ParticleExtruder* extruder() const
+ QSGParticleExtruder* extruder() const
{
return m_extruder;
}
return m_particleSizeVariation;
}
- VaryingVector * speed() const
+ QSGStochasticDirection * speed() const
{
return m_speed;
}
- VaryingVector * acceleration() const
+ QSGStochasticDirection * acceleration() const
{
return m_acceleration;
}
int m_particleDuration;
int m_particleDurationVariation;
bool m_emitting;
- ParticleSystem* m_system;
+ QSGParticleSystem* m_system;
QString m_particle;
- ParticleExtruder* m_extruder;
- ParticleExtruder* m_defaultExtruder;
- ParticleExtruder* effectiveExtruder();
- VaryingVector * m_speed;
- VaryingVector * m_acceleration;
+ QSGParticleExtruder* m_extruder;
+ QSGParticleExtruder* m_defaultExtruder;
+ QSGParticleExtruder* effectiveExtruder();
+ QSGStochasticDirection * m_speed;
+ QSGStochasticDirection * m_acceleration;
qreal m_particleSize;
qreal m_particleEndSize;
qreal m_particleSizeVariation;
QList<QPair<int, QPointF > > m_burstQueue;
int m_maxParticleCount;
private:
- VaryingVector m_nullVector;
+ QSGStochasticDirection m_nullVector;
};
QT_END_NAMESPACE
**
****************************************************************************/
-#include "particleextruder.h"
+#include "qsgparticleextruder_p.h"
QT_BEGIN_NAMESPACE
-ParticleExtruder::ParticleExtruder(QObject *parent) :
+QSGParticleExtruder::QSGParticleExtruder(QObject *parent) :
QObject(parent), m_fill(true)
{
}
-QPointF ParticleExtruder::extrude(const QRectF &rect)
+QPointF QSGParticleExtruder::extrude(const QRectF &rect)
{
if(m_fill)
return QPointF(((qreal)rand() / RAND_MAX) * rect.width() + rect.x(),
}
}
-bool ParticleExtruder::contains(const QRectF &bounds, const QPointF &point)
+bool QSGParticleExtruder::contains(const QRectF &bounds, const QPointF &point)
{
return bounds.contains(point);
}
QT_MODULE(Declarative)
-class ParticleExtruder : public QObject
+class QSGParticleExtruder : public QObject
{
Q_OBJECT
Q_PROPERTY(bool fill READ fill WRITE setFill NOTIFY fillChanged)//###Should this be base class, or a BoxExtruder?
public:
- explicit ParticleExtruder(QObject *parent = 0);
+ explicit QSGParticleExtruder(QObject *parent = 0);
virtual QPointF extrude(const QRectF &);
virtual bool contains(const QRectF &bounds, const QPointF &point);//###Needed for follow emitter, but does it belong? Only marginally conceptually valid, and that's from user's perspective
bool fill() const
**
****************************************************************************/
-#include "particle.h"
+#include "qsgparticlepainter_p.h"
#include <QDebug>
QT_BEGIN_NAMESPACE
-ParticleType::ParticleType(QSGItem *parent) :
+QSGParticlePainter::QSGParticlePainter(QSGItem *parent) :
QSGItem(parent),
m_system(0)
{
this, SLOT(calcSystemOffset()));
}
-void ParticleType::componentComplete()
+void QSGParticlePainter::componentComplete()
{
if(!m_system)
qWarning() << "Particle created without a particle system specified";//TODO: useful QML warnings, like line number?
}
-void ParticleType::setSystem(ParticleSystem *arg)
+void QSGParticlePainter::setSystem(QSGParticleSystem *arg)
{
if (m_system != arg) {
m_system = arg;
}
}
-void ParticleType::load(ParticleData*)
+void QSGParticlePainter::load(QSGParticleData*)
{
}
-void ParticleType::reload(ParticleData*)
+void QSGParticlePainter::reload(QSGParticleData*)
{
}
-void ParticleType::reset()
+void QSGParticlePainter::reset()
{
//Have to every time because what it's emitting may have changed and that affects particleTypeIndex
m_particleStarts.clear();
m_lastStart = 0;
}
-void ParticleType::setCount(int c)
+void QSGParticlePainter::setCount(int c)
{
if(c == m_count)
return;
emit countChanged();
}
-int ParticleType::count()
+int QSGParticlePainter::count()
{
return m_count;
}
-int ParticleType::particleTypeIndex(ParticleData* d)
+int QSGParticlePainter::particleTypeIndex(QSGParticleData* d)
{
if(!m_particleStarts.contains(d->group)){
m_particleStarts.insert(d->group, m_lastStart);
}
-void ParticleType::calcSystemOffset()
+void QSGParticlePainter::calcSystemOffset()
{
if(!m_system)
return;
QPointF lastOffset = m_systemOffset;
- m_systemOffset = this->mapFromItem(m_system, QPointF());
+ m_systemOffset = -1 * this->mapFromItem(m_system, QPointF());
if(lastOffset != m_systemOffset){
- //Reload all particles
+ //Reload all particles//TODO: Necessary?
foreach(const QString &g, m_particles){
int gId = m_system->m_groupIds[g];
for(int i=0; i<m_system->m_groupData[gId]->size; i++)
#include <QObject>
#include <QDebug>
-#include "particlesystem.h"
+#include "qsgparticlesystem_p.h"
QT_BEGIN_HEADER
QT_MODULE(Declarative)
-class ParticleType : public QSGItem
+class QSGParticlePainter : public QSGItem
{
Q_OBJECT
- Q_PROPERTY(ParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
+ Q_PROPERTY(QSGParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
Q_PROPERTY(QStringList particles READ particles WRITE setParticles NOTIFY particlesChanged)
public:
- explicit ParticleType(QSGItem *parent = 0);
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
+ explicit QSGParticlePainter(QSGItem *parent = 0);
+ virtual void load(QSGParticleData*);
+ virtual void reload(QSGParticleData*);
virtual void setCount(int c);
virtual int count();
- ParticleSystem* system() const
+ QSGParticleSystem* system() const
{
return m_system;
}
return m_particles;
}
- int particleTypeIndex(ParticleData*);
- virtual void componentComplete();
+ int particleTypeIndex(QSGParticleData*);
signals:
void countChanged();
- void systemChanged(ParticleSystem* arg);
+ void systemChanged(QSGParticleSystem* arg);
void particlesChanged(QStringList arg);
public slots:
-void setSystem(ParticleSystem* arg);
+void setSystem(QSGParticleSystem* arg);
void setParticles(QStringList arg)
{
void calcSystemOffset();
protected:
virtual void reset();
+ virtual void componentComplete();
// virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *){
// qDebug() << "Shouldn't be here..." << this;
// return 0;
// }
- ParticleSystem* m_system;
- friend class ParticleSystem;
+ QSGParticleSystem* m_system;
+ friend class QSGParticleSystem;
int m_count;
bool m_pleaseReset;
QStringList m_particles;
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Declarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgangleddirection_p.h"
+#include "qsgcustomparticle_p.h"
+#include "qsgellipseextruder_p.h"
+#include "qsgemitter_p.h"
+#include "qsgfollowemitter_p.h"
+#include "qsgfriction_p.h"
+#include "qsggravity_p.h"
+#include "qsgimageparticle_p.h"
+#include "qsgitemparticle_p.h"
+#include "qsgkill_p.h"
+#include "qsglineextruder_p.h"
+#include "qsgmaskextruder_p.h"
+#include "qsgmodelparticle_p.h"
+#include "qsgparticleaffector_p.h"
+#include "qsgparticleemitter_p.h"
+#include "qsgparticleextruder_p.h"
+#include "qsgparticlepainter_p.h"
+#include "qsgparticlesmodule_p.h"
+#include "qsgparticlesystem_p.h"
+#include "qsgpointattractor_p.h"
+#include "qsgpointdirection_p.h"
+#include "qsgspritegoal_p.h"
+#include "qsgstochasticdirection_p.h"
+#include "qsgtargeteddirection_p.h"
+#include "qsgturbulence_p.h"
+#include "qsgwander_p.h"
+
+QT_BEGIN_NAMESPACE
+
+void QSGParticlesModule::defineModule()
+{
+ const char* uri = "QtQuick.Particles";
+ //Debugging only exposition
+ qmlRegisterType<QSGParticlePainter>(uri, 2, 0, "ParticlePainter");
+ qmlRegisterType<QSGParticleEmitter>(uri, 2, 0, "ParticleEmitter");
+ qmlRegisterType<QSGParticleExtruder>(uri, 2, 0, "ParticleExtruder");
+ qmlRegisterType<QSGStochasticDirection>(uri, 2, 0, "NullVector");
+ //Probably should be nocreate types
+
+ qmlRegisterType<QSGParticleSystem>(uri, 2, 0, "ParticleSystem");
+
+ qmlRegisterType<QSGImageParticle>(uri, 2, 0, "ImageParticle");
+ qmlRegisterType<QSGCustomParticle>(uri, 2, 0, "CustomParticle");
+ qmlRegisterType<QSGItemParticle>(uri, 2, 0, "ItemParticle");
+ qmlRegisterType<QSGModelParticle>(uri, 2, 0, "ModelParticle");
+
+ qmlRegisterType<QSGBasicEmitter>(uri, 2, 0, "Emitter");
+ qmlRegisterType<QSGFollowEmitter>(uri, 2, 0, "FollowEmitter");
+
+ qmlRegisterType<QSGEllipseExtruder>(uri, 2, 0, "EllipseShape");
+ qmlRegisterType<QSGLineExtruder>(uri, 2, 0, "LineShape");
+ qmlRegisterType<QSGMaskExtruder>(uri, 2, 0, "MaskShape");
+
+ qmlRegisterType<QSGPointDirection>(uri, 2, 0, "PointDirection");
+ qmlRegisterType<QSGAngledDirection>(uri, 2, 0, "AngledDirection");
+ qmlRegisterType<QSGTargetedDirection>(uri, 2, 0, "TargetedDirection");
+
+ qmlRegisterType<QSGParticleAffector>(uri, 2, 0, "ParticleAffector");//if it has a triggered signal, it's useful
+ qmlRegisterType<QSGWanderAffector>(uri, 2, 0, "Wander");
+ qmlRegisterType<QSGFrictionAffector>(uri, 2, 0, "Friction");
+ qmlRegisterType<QSGPointAttractorAffector>(uri, 2, 0, "PointAttractor");
+ qmlRegisterType<QSGGravityAffector>(uri, 2, 0, "Gravity");
+ qmlRegisterType<QSGKillAffector>(uri, 2, 0, "Kill");
+ qmlRegisterType<QSGSpriteGoalAffector>(uri, 2, 0, "SpriteGoal");
+ qmlRegisterType<QSGTurbulenceAffector>(uri, 2, 0 , "Turbulence");
+}
+
+QT_END_NAMESPACE
+
+//Q_EXPORT_PLUGIN2(Particles, QT_PREPEND_NAMESPACE(ParticlesModule))
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "burstemitter.h"
+
+#ifndef QSGPARTICLESMODULE_H
+#define QSGPARTICLESMODULE_H
+
+#include <qdeclarative.h>
+
+QT_BEGIN_HEADER
+
QT_BEGIN_NAMESPACE
-void BurstEmitter::burst(int count, qreal x, qreal y)
+QT_MODULE(Declarative)
+
+class QSGParticlesModule
{
- qreal oldX = QSGItem::x();
- qreal oldY = QSGItem::y();
- setX(x);
- setY(y);
- TrailsEmitter::burst(count);
- setX(oldX);
- setY(oldY);
-}
+public:
+ static void defineModule();
+};
QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QSGPARTICLESMODULE_H
**
****************************************************************************/
-#include "particlesystem.h"
+#include "qsgparticlesystem_p.h"
#include <qsgnode.h>
-#include "particleemitter.h"
-#include "particleaffector.h"
-#include "particle.h"
+#include "qsgparticleemitter_p.h"
+#include "qsgparticleaffector_p.h"
+#include "qsgparticlepainter_p.h"
#include <cmath>
#include <QDebug>
QT_BEGIN_NAMESPACE
-ParticleData::ParticleData()
+QSGParticleData::QSGParticleData()
: group(0)
, e(0)
, particleIndex(0)
pv.ay = 0;
}
-ParticleSystem::ParticleSystem(QSGItem *parent) :
+QSGParticleSystem::QSGParticleSystem(QSGItem *parent) :
QSGItem(parent), m_particle_count(0), m_running(true) , m_startTime(0), m_overwrite(false)
{
m_groupIds = QHash<QString, int>();
}
-void ParticleSystem::registerParticleType(ParticleType* p)
+void QSGParticleSystem::registerParticleType(QSGParticlePainter* p)
{
- m_particles << QPointer<ParticleType>(p);//###Set or uniqueness checking?
+ m_particles << QPointer<QSGParticlePainter>(p);//###Set or uniqueness checking?
reset();
}
-void ParticleSystem::registerParticleEmitter(ParticleEmitter* e)
+void QSGParticleSystem::registerParticleEmitter(QSGParticleEmitter* e)
{
- m_emitters << QPointer<ParticleEmitter>(e);//###How to get them out?
+ m_emitters << QPointer<QSGParticleEmitter>(e);//###How to get them out?
connect(e, SIGNAL(particleCountChanged()),
this, SLOT(countChanged()));
connect(e, SIGNAL(particleChanged(QString)),
reset();
}
-void ParticleSystem::registerParticleAffector(ParticleAffector* a)
+void QSGParticleSystem::registerParticleAffector(QSGParticleAffector* a)
{
- m_affectors << QPointer<ParticleAffector>(a);
+ m_affectors << QPointer<QSGParticleAffector>(a);
//reset();//TODO: Slim down the huge batch of resets at the start
}
-void ParticleSystem::countChanged()
+void QSGParticleSystem::countChanged()
{
reset();//Need to give Particles new Count
}
-void ParticleSystem::setRunning(bool arg)
+void QSGParticleSystem::setRunning(bool arg)
{
if (m_running != arg) {
m_running = arg;
}
}
-void ParticleSystem::componentComplete()
+void QSGParticleSystem::componentComplete()
{
QSGItem::componentComplete();
reset();
}
-void ParticleSystem::initializeSystem()
+void QSGParticleSystem::initializeSystem()
{
int oldCount = m_particle_count;
m_particle_count = 0;//TODO: Only when changed?
if(!m_emitters.count() || !m_particles.count())
return;
- foreach(ParticleEmitter* e, m_emitters){
+ foreach(QSGParticleEmitter* e, m_emitters){
if(!m_groupIds.contains(e->particle())
|| (!e->particle().isEmpty() && !m_groupIds[e->particle()])){//or it was accidentally inserted by a failed lookup earlier
GroupData* gd = new GroupData;
if(m_particle_count > 16000)
qWarning() << "Particle system contains a vast number of particles (>16000). Expect poor performance";
- foreach(ParticleType* particle, m_particles){
+ foreach(QSGParticlePainter* particle, m_particles){
int particleCount = 0;
if(particle->particles().isEmpty()){//Uses default particle
particleCount += m_groupData[0]->size;
qDebug() << "System Initialized. Size:" << m_particle_count;
}
-void ParticleSystem::reset()
+void QSGParticleSystem::reset()
{
//Clear guarded pointers which have been deleted
int cleared = 0;
cleared += m_particles.removeAll(0);
cleared += m_affectors.removeAll(0);
//qDebug() << "Reset" << m_emitters.count() << m_particles.count() << "Cleared" << cleared;
- foreach(ParticleType* p, m_particles)
+ foreach(QSGParticlePainter* p, m_particles)
p->reset();
- foreach(ParticleEmitter* e, m_emitters)
+ foreach(QSGParticleEmitter* e, m_emitters)
e->reset();
if(!m_running)
return;
initializeSystem();
- foreach(ParticleType* p, m_particles)
+ foreach(QSGParticlePainter* p, m_particles)
p->update();
- foreach(ParticleEmitter* e, m_emitters)
+ foreach(QSGParticleEmitter* e, m_emitters)
e->emitWindow(0);//Start, so that starttime factors appropriately
}
-ParticleData* ParticleSystem::newDatum(int groupId)
+QSGParticleData* QSGParticleSystem::newDatum(int groupId)
{
Q_ASSERT(groupId < m_groupData.count());//XXX shouldn't really be an assert
Q_ASSERT(m_groupData[groupId]->size);
m_groupData[groupId]->nextIdx = 0;
Q_ASSERT(nextIdx < m_data.size());
- ParticleData* ret;
+ QSGParticleData* ret;
if(m_data[nextIdx]){//Recycle, it's faster.
ret = m_data[nextIdx];
if(!m_overwrite && ret->stillAlive()){
return 0;//Artificial longevity (or too fast emission) means this guy hasn't died. To maintain count, don't emit a new one
}//###Reset?
}else{
- ret = new ParticleData;
+ ret = new QSGParticleData;
m_data[nextIdx] = ret;
}
return ret;
}
-void ParticleSystem::emitParticle(ParticleData* pd)
+void QSGParticleSystem::emitParticle(QSGParticleData* pd)
{// called from prepareNextFrame()->emitWindow - enforce?
//Account for relative emitter position
QPointF offset = this->mapFromItem(pd->e, QPointF(0, 0));
pd->pv.y += offset.y();
}
- foreach(ParticleAffector *a, m_affectors)
+ foreach(QSGParticleAffector *a, m_affectors)
if(a && a->m_needsReset)
a->reset(pd->systemIndex);
- foreach(ParticleType* p, m_groupData[pd->group]->types)
+ foreach(QSGParticlePainter* p, m_groupData[pd->group]->types)
if(p)
p->load(pd);
}
-qint64 ParticleSystem::systemSync(ParticleType* p)
+qint64 QSGParticleSystem::systemSync(QSGParticlePainter* p)
{
if (!m_running)
return 0;
qreal time = m_timeInt / 1000.;
dt = time - dt;
m_needsReset.clear();
- foreach(ParticleEmitter* emitter, m_emitters)
+ foreach(QSGParticleEmitter* emitter, m_emitters)
if(emitter)
emitter->emitWindow(m_timeInt);
- foreach(ParticleAffector* a, m_affectors)
+ foreach(QSGParticleAffector* a, m_affectors)
if(a)
a->affectSystem(dt);
- foreach(ParticleData* d, m_needsReset)
- foreach(ParticleType* p, m_groupData[d->group]->types)
+ foreach(QSGParticleData* d, m_needsReset)
+ foreach(QSGParticlePainter* p, m_groupData[d->group]->types)
if(p && d)
p->reload(d);
}
}
//sets the x accleration without affecting the instantaneous x velocity or position
-void ParticleData::setInstantaneousAX(qreal ax)
+void QSGParticleData::setInstantaneousAX(qreal ax)
{
qreal t = (system->m_timeInt / 1000.0) - pv.t;
qreal sx = (pv.sx + t*pv.ax) - t*ax;
}
//sets the x velocity without affecting the instantaneous x postion
-void ParticleData::setInstantaneousSX(qreal vx)
+void QSGParticleData::setInstantaneousSX(qreal vx)
{
qreal t = (system->m_timeInt / 1000.0) - pv.t;
qreal sx = vx - t*pv.ax;
}
//sets the instantaneous x postion
-void ParticleData::setInstantaneousX(qreal x)
+void QSGParticleData::setInstantaneousX(qreal x)
{
qreal t = (system->m_timeInt / 1000.0) - pv.t;
pv.x = x - t*pv.sx - 0.5 * t*t*pv.ax;
}
//sets the y accleration without affecting the instantaneous y velocity or position
-void ParticleData::setInstantaneousAY(qreal ay)
+void QSGParticleData::setInstantaneousAY(qreal ay)
{
qreal t = (system->m_timeInt / 1000.0) - pv.t;
qreal sy = (pv.sy + t*pv.ay) - t*ay;
}
//sets the y velocity without affecting the instantaneous y position
-void ParticleData::setInstantaneousSY(qreal vy)
+void QSGParticleData::setInstantaneousSY(qreal vy)
{
qreal t = (system->m_timeInt / 1000.0) - pv.t;
//qDebug() << t << (system->m_timeInt/1000.0) << pv.x << pv.sx << pv.ax << pv.x + pv.sx * t + 0.5 * pv.ax * t * t;
}
//sets the instantaneous Y position
-void ParticleData::setInstantaneousY(qreal y)
+void QSGParticleData::setInstantaneousY(qreal y)
{
qreal t = (system->m_timeInt / 1000.0) - pv.t;
pv.y = y - t*pv.sy - 0.5 * t*t*pv.ay;
}
-qreal ParticleData::curX() const
+qreal QSGParticleData::curX() const
{
qreal t = (system->m_timeInt / 1000.0) - pv.t;
return pv.x + pv.sx * t + 0.5 * pv.ax * t * t;
}
-qreal ParticleData::curSX() const
+qreal QSGParticleData::curSX() const
{
qreal t = (system->m_timeInt / 1000.0) - pv.t;
return pv.sx + t*pv.ax;
}
-qreal ParticleData::curY() const
+qreal QSGParticleData::curY() const
{
qreal t = (system->m_timeInt / 1000.0) - pv.t;
return pv.y + pv.sy * t + 0.5 * pv.ay * t * t;
}
-qreal ParticleData::curSY() const
+qreal QSGParticleData::curSY() const
{
qreal t = (system->m_timeInt / 1000.0) - pv.t;
return pv.sy + t*pv.ay;
}
-void ParticleData::debugDump()
+void QSGParticleData::debugDump()
{
qDebug() << "Particle" << group
<< "Pos: " << pv.x << "," << pv.y
<< "Time: " << pv.t << "," <<pv.lifeSpan;
}
-bool ParticleData::stillAlive()
+bool QSGParticleData::stillAlive()
{
if(!system)
return false;
QT_MODULE(Declarative)
-class ParticleAffector;
-class ParticleEmitter;
-class ParticleType;
-class ParticleData;
+class QSGParticleAffector;
+class QSGParticleEmitter;
+class QSGParticlePainter;
+class QSGParticleData;
struct GroupData{
int size;
int start;
int nextIdx;
- QList<ParticleType*> types;
+ QList<QSGParticlePainter*> types;
};
-class ParticleSystem : public QSGItem
+class QSGParticleSystem : public QSGItem
{
Q_OBJECT
Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged)
*/
public:
- explicit ParticleSystem(QSGItem *parent = 0);
+ explicit QSGParticleSystem(QSGItem *parent = 0);
bool isRunning() const
{
private slots:
void countChanged();
public://but only really for related class usage. Perhaps we should all be friends?
- void emitParticle(ParticleData* p);
- ParticleData* newDatum(int groupId);
- qint64 systemSync(ParticleType* p);
+ void emitParticle(QSGParticleData* p);
+ QSGParticleData* newDatum(int groupId);
+ qint64 systemSync(QSGParticlePainter* p);
QElapsedTimer m_timestamp;
- QVector<ParticleData*> m_data;
- QSet<ParticleData*> m_needsReset;
+ QVector<QSGParticleData*> m_data;
+ QSet<QSGParticleData*> m_needsReset;
QHash<QString, int> m_groupIds;
QHash<int, GroupData*> m_groupData;//id, size, start
qint64 m_timeInt;
bool m_initialized;
- void registerParticleType(ParticleType* p);
- void registerParticleEmitter(ParticleEmitter* e);
- void registerParticleAffector(ParticleAffector* a);
+ void registerParticleType(QSGParticlePainter* p);
+ void registerParticleEmitter(QSGParticleEmitter* e);
+ void registerParticleAffector(QSGParticleAffector* a);
bool overwrite() const
{
return m_overwrite;
private:
void initializeSystem();
bool m_running;
- QList<QPointer<ParticleEmitter> > m_emitters;
- QList<QPointer<ParticleAffector> > m_affectors;
- QList<QPointer<ParticleType> > m_particles;
- QList<QPointer<ParticleType> > m_syncList;
+ QList<QPointer<QSGParticleEmitter> > m_emitters;
+ QList<QPointer<QSGParticleAffector> > m_affectors;
+ QList<QPointer<QSGParticlePainter> > m_particles;
+ QList<QPointer<QSGParticlePainter> > m_syncList;
qint64 m_startTime;
int m_nextGroupId;
bool m_overwrite;
//TODO: Need opacity over life control. More variable size over life?
};
-class ParticleData{
+class QSGParticleData{
public:
- ParticleData();
+ QSGParticleData();
ParticleVertex pv;
qreal curSY() const;
int group;
- ParticleEmitter* e;
- ParticleSystem* system;
+ QSGParticleEmitter* e;
+ QSGParticleSystem* system;
int particleIndex;
int systemIndex;
**
****************************************************************************/
-#include "attractoraffector.h"
+#include "qsgpointattractor_p.h"
#include <cmath>
#include <QDebug>
QT_BEGIN_NAMESPACE
-AttractorAffector::AttractorAffector(QSGItem *parent) :
- ParticleAffector(parent), m_strength(0.0), m_x(0), m_y(0)
+QSGPointAttractorAffector::QSGPointAttractorAffector(QSGItem *parent) :
+ QSGParticleAffector(parent), m_strength(0.0), m_x(0), m_y(0)
{
}
-bool AttractorAffector::affectParticle(ParticleData *d, qreal dt)
+bool QSGPointAttractorAffector::affectParticle(QSGParticleData *d, qreal dt)
{
if(m_strength == 0.0)
return false;
#ifndef ATTRACTORAFFECTOR_H
#define ATTRACTORAFFECTOR_H
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
QT_BEGIN_HEADER
QT_MODULE(Declarative)
-class AttractorAffector : public ParticleAffector
+class QSGPointAttractorAffector : public QSGParticleAffector
{
Q_OBJECT
//Like Gravitational singularity, but linear to distance instead of quadratic
Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged)
Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged)
public:
- explicit AttractorAffector(QSGItem *parent = 0);
+ explicit QSGPointAttractorAffector(QSGItem *parent = 0);
qreal strength() const
{
}
}
protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
private:
qreal m_strength;
qreal m_x;
**
****************************************************************************/
-#include "pointvector.h"
+#include "qsgpointdirection_p.h"
QT_BEGIN_NAMESPACE
-PointVector::PointVector(QObject *parent) :
- VaryingVector(parent)
+QSGPointDirection::QSGPointDirection(QObject *parent) :
+ QSGStochasticDirection(parent)
, m_x(0)
, m_y(0)
, m_xVariation(0)
{
}
-const QPointF &PointVector::sample(const QPointF &)
+const QPointF &QSGPointDirection::sample(const QPointF &)
{
m_ret.setX(m_x - m_xVariation + rand() / float(RAND_MAX) * m_xVariation * 2);
m_ret.setY(m_y - m_yVariation + rand() / float(RAND_MAX) * m_yVariation * 2);
#ifndef POINTVECTOR_H
#define POINTVECTOR_H
-#include "varyingvector.h"
+#include "qsgstochasticdirection_p.h"
QT_BEGIN_HEADER
QT_MODULE(Declarative)
-class PointVector : public VaryingVector
+class QSGPointDirection : public QSGStochasticDirection
{
Q_OBJECT
Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged)
Q_PROPERTY(qreal xVariation READ xVariation WRITE setXVariation NOTIFY xVariationChanged)
Q_PROPERTY(qreal yVariation READ yVariation WRITE setYVariation NOTIFY yVariationChanged)
public:
- explicit PointVector(QObject *parent = 0);
+ explicit QSGPointDirection(QObject *parent = 0);
virtual const QPointF &sample(const QPointF &from);
qreal x() const
{
**
****************************************************************************/
-#include "spritegoalaffector.h"
-#include "spriteparticle.h"
-#include "spriteengine.h"
-#include "spritestate.h"
+#include "qsgspritegoal_p.h"
+#include "private/qsgspriteengine_p.h"
+#include "private/qsgsprite_p.h"
+#include "qsgimageparticle_p.h"
#include <QDebug>
QT_BEGIN_NAMESPACE
-SpriteGoalAffector::SpriteGoalAffector(QSGItem *parent) :
- ParticleAffector(parent), m_goalIdx(-1), m_jump(false)
+QSGSpriteGoalAffector::QSGSpriteGoalAffector(QSGItem *parent) :
+ QSGParticleAffector(parent), m_goalIdx(-1), m_jump(false)
{
}
-void SpriteGoalAffector::updateStateIndex(SpriteEngine* e)
+void QSGSpriteGoalAffector::updateStateIndex(QSGSpriteEngine* e)
{
m_lastEngine = e;
for(int i=0; i<e->stateCount(); i++){
m_goalIdx = -1;//Can't find it
}
-void SpriteGoalAffector::setGoalState(QString arg)
+void QSGSpriteGoalAffector::setGoalState(QString arg)
{
if (m_goalState != arg) {
m_goalState = arg;
}
}
-bool SpriteGoalAffector::affectParticle(ParticleData *d, qreal dt)
+bool QSGSpriteGoalAffector::affectParticle(QSGParticleData *d, qreal dt)
{
Q_UNUSED(dt);
//TODO: Affect all engines
- SpriteEngine *engine = 0;
- foreach(ParticleType *p, m_system->m_groupData[d->group]->types)
- if(qobject_cast<SpriteParticle*>(p))
- engine = qobject_cast<SpriteParticle*>(p)->spriteEngine();
+ QSGSpriteEngine *engine = 0;
+ foreach(QSGParticlePainter *p, m_system->m_groupData[d->group]->types)
+ if(qobject_cast<QSGImageParticle*>(p))
+ engine = qobject_cast<QSGImageParticle*>(p)->spriteEngine();
if(!engine)
return false;
#ifndef SPRITEGOALAFFECTOR_H
#define SPRITEGOALAFFECTOR_H
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
QT_BEGIN_HEADER
QT_MODULE(Declarative)
-class SpriteEngine;
+class QSGSpriteEngine;
-class SpriteGoalAffector : public ParticleAffector
+class QSGSpriteGoalAffector : public QSGParticleAffector
{
Q_OBJECT
Q_PROPERTY(QString goalState READ goalState WRITE setGoalState NOTIFY goalStateChanged)
Q_PROPERTY(bool jump READ jump WRITE setJump NOTIFY jumpChanged)
public:
- explicit SpriteGoalAffector(QSGItem *parent = 0);
+ explicit QSGSpriteGoalAffector(QSGItem *parent = 0);
QString goalState() const
{
return m_jump;
}
protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
signals:
void goalStateChanged(QString arg);
}
private:
- void updateStateIndex(SpriteEngine* e);
+ void updateStateIndex(QSGSpriteEngine* e);
QString m_goalState;
int m_goalIdx;
- SpriteEngine* m_lastEngine;
+ QSGSpriteEngine* m_lastEngine;
bool m_jump;
};
**
****************************************************************************/
-#include "varyingvector.h"
+#include "qsgstochasticdirection_p.h"
QT_BEGIN_NAMESPACE
-VaryingVector::VaryingVector(QObject *parent) :
+QSGStochasticDirection::QSGStochasticDirection(QObject *parent) :
QObject(parent)
{
}
-const QPointF &VaryingVector::sample(const QPointF &from)
+const QPointF &QSGStochasticDirection::sample(const QPointF &from)
{
return m_ret;
}
QT_MODULE(Declarative)
-class VaryingVector : public QObject
+class QSGStochasticDirection : public QObject
{
Q_OBJECT
public:
- explicit VaryingVector(QObject *parent = 0);
+ explicit QSGStochasticDirection(QObject *parent = 0);
virtual const QPointF &sample(const QPointF &from);
signals:
**
****************************************************************************/
-#include "directedvector.h"
-#include "particleemitter.h"
+#include "qsgtargeteddirection_p.h"
+#include "qsgparticleemitter_p.h"
#include <cmath>
#include <QDebug>
QT_BEGIN_NAMESPACE
-DirectedVector::DirectedVector(QObject *parent) :
- VaryingVector(parent)
+QSGTargetedDirection::QSGTargetedDirection(QObject *parent) :
+ QSGStochasticDirection(parent)
, m_targetX(0)
, m_targetY(0)
, m_targetVariation(0)
{
}
-const QPointF &DirectedVector::sample(const QPointF &from)
+const QPointF &QSGTargetedDirection::sample(const QPointF &from)
{
//###This approach loses interpolating the last position of the target (like we could with the emitter) is it worthwhile?
qreal targetX;
qreal targetY;
if(m_targetItem){
- ParticleEmitter* parentEmitter = qobject_cast<ParticleEmitter*>(parent());
+ QSGParticleEmitter* parentEmitter = qobject_cast<QSGParticleEmitter*>(parent());
targetX = m_targetItem->width()/2;
targetY = m_targetItem->height()/2;
if(!parentEmitter){
#ifndef DIRECTEDVECTOR_H
#define DIRECTEDVECTOR_H
-#include "varyingvector.h"
+#include "qsgstochasticdirection_p.h"
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QSGItem;
-class DirectedVector : public VaryingVector
+class QSGTargetedDirection : public QSGStochasticDirection
{
Q_OBJECT
Q_PROPERTY(qreal targetX READ targetX WRITE setTargetX NOTIFY targetXChanged)
Q_PROPERTY(qreal magnitudeVariation READ magnitudeVariation WRITE setMagnitudeVariation NOTIFY magnitudeVariationChanged)
public:
- explicit DirectedVector(QObject *parent = 0);
+ explicit QSGTargetedDirection(QObject *parent = 0);
virtual const QPointF &sample(const QPointF &from);
qreal targetX() const
**
****************************************************************************/
-#include "turbulenceaffector.h"
-#include "particle.h"
+#include "qsgturbulence_p.h"
+#include "qsgparticlepainter_p.h"//TODO: Why was this needed again?
#include <cmath>
#include <cstdlib>
#include <QDebug>
QT_BEGIN_NAMESPACE
-TurbulenceAffector::TurbulenceAffector(QSGItem *parent) :
- ParticleAffector(parent),
+QSGTurbulenceAffector::QSGTurbulenceAffector(QSGItem *parent) :
+ QSGParticleAffector(parent),
m_strength(10), m_lastT(0), m_frequency(64), m_gridSize(10), m_field(0), m_inited(false)
{
//TODO: Update grid on size change
}
-TurbulenceAffector::~TurbulenceAffector()
+QSGTurbulenceAffector::~QSGTurbulenceAffector()
{
if (m_field) {
for(int i=0; i<m_gridSize; i++)
return sqrt(x*x + y*y);
}
-void TurbulenceAffector::setSize(int arg)
+void QSGTurbulenceAffector::setSize(int arg)
{
if (m_gridSize != arg) {
if(m_field){ //deallocate and then reallocate grid
}
}
-void TurbulenceAffector::ensureInit()
+void QSGTurbulenceAffector::ensureInit()
{
if(m_inited)
return;
m_magSum = magnitude(m_spacing.x(), m_spacing.y())*2;
}
-void TurbulenceAffector::mapUpdate()
+void QSGTurbulenceAffector::mapUpdate()
{
QPoint pos(rand() % m_gridSize, rand() % m_gridSize);
QPointF vector(m_strength - (((qreal)rand() / RAND_MAX) * m_strength*2),
}
-void TurbulenceAffector::affectSystem(qreal dt)
+void QSGTurbulenceAffector::affectSystem(qreal dt)
{
if(!m_system || !m_active)
return;
m_lastT += period;
}
- foreach(ParticleData *d, m_system->m_data){
+ foreach(QSGParticleData *d, m_system->m_data){
if(!d || !activeGroup(d->group))
return;
qreal fx = 0.0;
#ifndef TURBULENCEAFFECTOR_H
#define TURBULENCEAFFECTOR_H
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
#include <QDeclarativeListProperty>
QT_BEGIN_HEADER
QT_MODULE(Declarative)
-class ParticleType;
+class QSGParticlePainter;
-class TurbulenceAffector : public ParticleAffector
+class QSGTurbulenceAffector : public QSGParticleAffector
{
Q_OBJECT
Q_PROPERTY(int strength READ strength WRITE setStrength NOTIFY strengthChanged)
Q_PROPERTY(int frequency READ frequency WRITE setFrequency NOTIFY frequencyChanged)
Q_PROPERTY(int gridSize READ size WRITE setSize NOTIFY sizeChanged)
public:
- explicit TurbulenceAffector(QSGItem *parent = 0);
- ~TurbulenceAffector();
+ explicit QSGTurbulenceAffector(QSGItem *parent = 0);
+ ~QSGTurbulenceAffector();
virtual void affectSystem(qreal dt);
int strength() const
**
****************************************************************************/
-#include "wanderaffector.h"
-#include "particlesystem.h"//for ParticlesVertices
+#include "qsgwander_p.h"
+#include "qsgparticlesystem_p.h"//for ParticlesVertices
QT_BEGIN_NAMESPACE
-WanderAffector::WanderAffector(QSGItem *parent) :
- ParticleAffector(parent)
+QSGWanderAffector::QSGWanderAffector(QSGItem *parent) :
+ QSGParticleAffector(parent)
{
m_needsReset = true;
}
-WanderAffector::~WanderAffector()
+QSGWanderAffector::~QSGWanderAffector()
{
for(QHash<int, WanderData*>::const_iterator iter=m_wanderData.constBegin();
iter != m_wanderData.constEnd(); iter++)
delete (*iter);
}
-WanderData* WanderAffector::getData(int idx)
+WanderData* QSGWanderAffector::getData(int idx)
{
if(m_wanderData.contains(idx))
return m_wanderData[idx];
return d;
}
-void WanderAffector::reset(int systemIdx)
+void QSGWanderAffector::reset(int systemIdx)
{
if(m_wanderData.contains(systemIdx))
delete m_wanderData[systemIdx];
m_wanderData.remove(systemIdx);
}
-bool WanderAffector::affectParticle(ParticleData* data, qreal dt)
+bool QSGWanderAffector::affectParticle(QSGParticleData* data, qreal dt)
{
WanderData* d = getData(data->systemIndex);
if (m_xVariance != 0.) {
#ifndef WANDERAFFECTOR_H
#define WANDERAFFECTOR_H
#include <QHash>
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
QT_BEGIN_HEADER
QT_MODULE(Declarative)
-class SpriteEmitter;
-
struct WanderData{
qreal x_vel;
qreal y_vel;
qreal y_var;
};
-class WanderAffector : public ParticleAffector
+class QSGWanderAffector : public QSGParticleAffector
{
Q_OBJECT
Q_PROPERTY(qreal xVariance READ xVariance WRITE setXVariance NOTIFY xVarianceChanged)
Q_PROPERTY(qreal pace READ pace WRITE setPace NOTIFY paceChanged)
public:
- explicit WanderAffector(QSGItem *parent = 0);
- ~WanderAffector();
+ explicit QSGWanderAffector(QSGItem *parent = 0);
+ ~QSGWanderAffector();
virtual void reset(int systemIdx);
qreal xVariance() const
return m_pace;
}
protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
signals:
void xVarianceChanged(qreal arg);
#include <private/qdeclarativeitemsmodule_p.h>
#include <private/qdeclarativeutilmodule_p.h>
#include <private/qsgitemsmodule_p.h>
+#include <private/qsgparticlesmodule_p.h>
#include <qsgtexture.h>
#ifdef Q_OS_WIN // for %APPDATA%
QDeclarativeUtilModule::defineModule();
QDeclarativeEnginePrivate::defineModule();
QSGItemsModule::defineModule();
+ QSGParticlesModule::defineModule();
QDeclarativeValueTypeFactory::registerValueTypes();
}
globalClass = new QDeclarativeGlobalScriptClass(&scriptEngine);
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef BURSTEMITTER_H
-#define BURSTEMITTER_H
-
-#include "trailsemitter.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-//Convenience Class - can't do function overloads in QML?
-class BurstEmitter : public TrailsEmitter
-{
- Q_OBJECT
-public:
- explicit BurstEmitter(QSGItem* parent = 0):TrailsEmitter(parent){}
-public slots:
- void burst(int count, qreal x, qreal y);
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <private/qsgcontext_p.h>
-#include <private/qsgadaptationlayer_p.h>
-#include <qsgnode.h>
-#include <qsgtexturematerial.h>
-#include <qsgtexture.h>
-#include <QFile>
-#include "coloredparticle.h"
-#include "particleemitter.h"
-#include <QGLFunctions>
-#include <qsgengine.h>
-
-QT_BEGIN_NAMESPACE
-
-class ParticleTrailsMaterial : public QSGMaterial
-{
-public:
- ParticleTrailsMaterial()
- : timestamp(0)
- {
- setFlag(Blending, true);
- }
-
- ~ParticleTrailsMaterial()
- {
- delete texture;
- }
-
- virtual QSGMaterialType *type() const { static QSGMaterialType type; return &type; }
- virtual QSGMaterialShader *createShader() const;
- virtual int compare(const QSGMaterial *other) const
- {
- return this - static_cast<const ParticleTrailsMaterial *>(other);
- }
-
- QSGTexture *texture;
-
- qreal timestamp;
-};
-
-
-class ParticleTrailsMaterialData : public QSGMaterialShader
-{
-public:
- ParticleTrailsMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
- {
- QFile vf(vertexFile ? vertexFile : ":resources/trailsvertex.shader");
- vf.open(QFile::ReadOnly);
- m_vertex_code = vf.readAll();
-
- QFile ff(fragmentFile ? fragmentFile : ":resources/trailsfragment.shader");
- ff.open(QFile::ReadOnly);
- m_fragment_code = ff.readAll();
-
- Q_ASSERT(!m_vertex_code.isNull());
- Q_ASSERT(!m_fragment_code.isNull());
- }
-
- void deactivate() {
- QSGMaterialShader::deactivate();
-
- for (int i=0; i<8; ++i) {
- program()->setAttributeArray(i, GL_FLOAT, chunkOfBytes, 1, 0);
- }
- }
-
- virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *)
- {
- ParticleTrailsMaterial *m = static_cast<ParticleTrailsMaterial *>(newEffect);
- state.context()->functions()->glActiveTexture(GL_TEXTURE0);
- m->texture->bind();
-
- program()->setUniformValue(m_opacity_id, state.opacity());
- program()->setUniformValue(m_timestamp_id, (float) m->timestamp);
-
- if (state.isMatrixDirty())
- program()->setUniformValue(m_matrix_id, state.combinedMatrix());
- }
-
- virtual void initialize() {
- m_matrix_id = program()->uniformLocation("matrix");
- m_opacity_id = program()->uniformLocation("opacity");
- m_timestamp_id = program()->uniformLocation("timestamp");
- }
-
- virtual const char *vertexShader() const { return m_vertex_code.constData(); }
- virtual const char *fragmentShader() const { return m_fragment_code.constData(); }
-
- virtual char const *const *attributeNames() const {
- static const char *attr[] = {
- "vPos",
- "vTex",
- "vData",
- "vVec",
- "vColor",
- 0
- };
- return attr;
- }
-
- virtual bool isColorTable() const { return false; }
-
- int m_matrix_id;
- int m_opacity_id;
- int m_timestamp_id;
-
- QByteArray m_vertex_code;
- QByteArray m_fragment_code;
-
- static float chunkOfBytes[1024];
-};
-float ParticleTrailsMaterialData::chunkOfBytes[1024];
-
-
-QSGMaterialShader *ParticleTrailsMaterial::createShader() const
-{
- return new ParticleTrailsMaterialData;
-}
-
-
-class ParticleTrailsMaterialCT : public ParticleTrailsMaterial
-{
-public:
- ParticleTrailsMaterialCT()
- {
- }
-
- ~ParticleTrailsMaterialCT()
- {
- delete colortable;
- delete sizetable;
- delete opacitytable;
- }
-
- virtual QSGMaterialType *type() const { static QSGMaterialType type; return &type; }
- virtual QSGMaterialShader *createShader() const;
-
- QSGTexture *colortable;
- QSGTexture *sizetable;
- QSGTexture *opacitytable;
-};
-
-
-class ParticleTrailsMaterialDataCT : public ParticleTrailsMaterialData
-{
-public:
- ParticleTrailsMaterialDataCT()
- : ParticleTrailsMaterialData(":resources/ctvertex.shader", ":resources/ctfragment.shader")
- {
- }
-
- bool isColorTable() const { return true; }
-
- virtual void initialize() {
- ParticleTrailsMaterialData::initialize();
- m_colortable_id = program()->uniformLocation("colortable");
- m_sizetable_id = program()->uniformLocation("sizetable");
- m_opacitytable_id = program()->uniformLocation("opacitytable");
- }
-
- virtual void updateState(const RenderState &state, QSGMaterial *current, QSGMaterial *old)
- {
- // Bind the texture to unit 1 before calling the base class, so that the
- // base class can set active texture back to 0.
- ParticleTrailsMaterialCT *m = static_cast<ParticleTrailsMaterialCT *>(current);
- state.context()->functions()->glActiveTexture(GL_TEXTURE1);
- m->colortable->bind();
- program()->setUniformValue(m_colortable_id, 1);
-
- state.context()->functions()->glActiveTexture(GL_TEXTURE2);
- m->sizetable->bind();
- program()->setUniformValue(m_sizetable_id, 2);
-
- state.context()->functions()->glActiveTexture(GL_TEXTURE3);
- m->opacitytable->bind();
- program()->setUniformValue(m_opacitytable_id, 3);
-
- ParticleTrailsMaterialData::updateState(state, current, old);
- }
-
- int m_colortable_id;
- int m_sizetable_id;
- int m_opacitytable_id;
-};
-
-
-QSGMaterialShader *ParticleTrailsMaterialCT::createShader() const
-{
- return new ParticleTrailsMaterialDataCT;
-}
-
-ColoredParticle::ColoredParticle(QSGItem* parent)
- : ParticleType(parent)
- , m_do_reset(false)
- , m_color(Qt::white)
- , m_color_variation(0.5)
- , m_node(0)
- , m_material(0)
- , m_alphaVariation(0.0)
- , m_alpha(1.0)
- , m_redVariation(0.0)
- , m_greenVariation(0.0)
- , m_blueVariation(0.0)
-{
- setFlag(ItemHasContents);
-}
-
-void ColoredParticle::setImage(const QUrl &image)
-{
- if (image == m_image_name)
- return;
- m_image_name = image;
- emit imageChanged();
- reset();
-}
-
-
-void ColoredParticle::setColortable(const QUrl &table)
-{
- if (table == m_colortable_name)
- return;
- m_colortable_name = table;
- emit colortableChanged();
- reset();
-}
-
-void ColoredParticle::setSizetable(const QUrl &table)
-{
- if (table == m_sizetable_name)
- return;
- m_sizetable_name = table;
- emit sizetableChanged();
- reset();
-}
-
-void ColoredParticle::setOpacitytable(const QUrl &table)
-{
- if (table == m_opacitytable_name)
- return;
- m_opacitytable_name = table;
- emit opacitytableChanged();
- reset();
-}
-
-void ColoredParticle::setColor(const QColor &color)
-{
- if (color == m_color)
- return;
- m_color = color;
- emit colorChanged();
- //m_system->pleaseReset();//XXX
-}
-
-void ColoredParticle::setColorVariation(qreal var)
-{
- if (var == m_color_variation)
- return;
- m_color_variation = var;
- emit colorVariationChanged();
- //m_system->pleaseReset();//XXX
-}
-
-void ColoredParticle::setCount(int c)
-{
- ParticleType::setCount(c);
- m_pleaseReset = true;
-}
-
-void ColoredParticle::reset()
-{
- ParticleType::reset();
- m_pleaseReset = true;
-}
-
-static QSGGeometry::Attribute ColoredParticle_Attributes[] = {
- { 0, 2, GL_FLOAT }, // Position
- { 1, 2, GL_FLOAT }, // TexCoord
- { 2, 4, GL_FLOAT }, // Data
- { 3, 4, GL_FLOAT }, // Vectors
- { 4, 4, GL_UNSIGNED_BYTE } // Colors
-};
-
-static QSGGeometry::AttributeSet ColoredParticle_AttributeSet =
-{
- 5, // Attribute Count
- (2 + 2 + 4 + 4) * sizeof(float) + 4 * sizeof(uchar),
- ColoredParticle_Attributes
-};
-
-QSGGeometryNode* ColoredParticle::buildParticleNode()
-{
- if (m_count * 4 > 0xffff) {
- printf("ColoredParticle: Too many particles... \n");
- return 0;
- }
-
- if(m_count <= 0) {
- printf("ColoredParticle: Too few particles... \n");
- return 0;
- }
-
- QImage image(m_image_name.toLocalFile());
- if (image.isNull()) {
- printf("ParticleTrails: loading image failed... '%s'\n", qPrintable(m_image_name.toLocalFile()));
- return 0;
- }
-
- int vCount = m_count * 4;
- int iCount = m_count * 6;
-
- QSGGeometry *g = new QSGGeometry(ColoredParticle_AttributeSet, vCount, iCount);
- g->setDrawingMode(GL_TRIANGLES);
-
- ColoredParticleVertex *vertices = (ColoredParticleVertex *) g->vertexData();
- for (int p=0; p<m_count; ++p) {
-
- for (int i=0; i<4; ++i) {
- vertices[i].x = 0;
- vertices[i].y = 0;
- vertices[i].t = -1;
- vertices[i].lifeSpan = 0;
- vertices[i].size = 0;
- vertices[i].endSize = 0;
- vertices[i].sx = 0;
- vertices[i].sy = 0;
- vertices[i].ax = 0;
- vertices[i].ay = 0;
- }
-
- vertices[0].tx = 0;
- vertices[0].ty = 0;
-
- vertices[1].tx = 1;
- vertices[1].ty = 0;
-
- vertices[2].tx = 0;
- vertices[2].ty = 1;
-
- vertices[3].tx = 1;
- vertices[3].ty = 1;
-
- vertices += 4;
- }
-
- quint16 *indices = g->indexDataAsUShort();
- for (int i=0; i<m_count; ++i) {
- int o = i * 4;
- indices[0] = o;
- indices[1] = o + 1;
- indices[2] = o + 2;
- indices[3] = o + 1;
- indices[4] = o + 3;
- indices[5] = o + 2;
- indices += 6;
- }
-
- if (m_material) {
- delete m_material;
- m_material = 0;
- }
-
- QImage colortable(m_colortable_name.toLocalFile());
- QImage sizetable(m_sizetable_name.toLocalFile());
- QImage opacitytable(m_opacitytable_name.toLocalFile());
- if(!colortable.isNull() || !sizetable.isNull() || !opacitytable.isNull()){
- //using tabled shaders
- m_material = new ParticleTrailsMaterialCT();
- if(colortable.isNull())
- colortable = QImage(":resources/identitytable.png");
- if(sizetable.isNull())
- sizetable = QImage(":resources/identitytable.png");
- if(opacitytable.isNull())
- opacitytable = QImage(":resources/defaultFadeInOut.png");
- Q_ASSERT(!colortable.isNull());
- Q_ASSERT(!sizetable.isNull());
- Q_ASSERT(!opacitytable.isNull());
- ParticleTrailsMaterialCT* ct_material = static_cast<ParticleTrailsMaterialCT *>(m_material);
- ct_material->colortable = sceneGraphEngine()->createTextureFromImage(colortable);
- ct_material->sizetable = sceneGraphEngine()->createTextureFromImage(sizetable);
- ct_material->opacitytable = sceneGraphEngine()->createTextureFromImage(opacitytable);
- }
-
- if (!m_material)
- m_material = new ParticleTrailsMaterial();
-
-
- m_material->texture = sceneGraphEngine()->createTextureFromImage(image);
- m_material->texture->setFiltering(QSGTexture::Linear);
-
- m_node = new QSGGeometryNode();
- m_node->setGeometry(g);
- m_node->setMaterial(m_material);
-
- m_last_particle = 0;
-
- return m_node;
-}
-
-QSGNode *ColoredParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
-{
- if(m_pleaseReset){
- if(m_node)
- delete m_node;
- if(m_material)
- delete m_material;
-
- m_node = 0;
- m_material = 0;
- m_pleaseReset = false;
- }
-
- if(m_system && m_system->isRunning())
- prepareNextFrame();
- if (m_node){
- update();
- m_node->markDirty(QSGNode::DirtyMaterial);
- }
-
- return m_node;
-}
-
-void ColoredParticle::prepareNextFrame()
-{
- if (m_node == 0){ //TODO: Staggered loading (as emitted)
- m_node = buildParticleNode();
- if(m_node == 0)
- return;
- }
- qint64 timeStamp = m_system->systemSync(this);
-
- qreal time = timeStamp / 1000.;
- m_material->timestamp = time;
-}
-
-void ColoredParticle::reloadColor(const Color4ub &c, ParticleData* d)
-{
- ColoredParticleVertices *particles = (ColoredParticleVertices *) m_node->geometry()->vertexData();
- int pos = particleTypeIndex(d);
- ColoredParticleVertices &p = particles[pos];
- p.v1.color = p.v2.color = p.v3.color = p.v4.color = c;
-}
-
-void ColoredParticle::vertexCopy(ColoredParticleVertex &b,const ParticleVertex& a)
-{
- b.x = a.x - m_systemOffset.x();
- b.y = a.y - m_systemOffset.y();
- b.t = a.t;
- b.lifeSpan = a.lifeSpan;
- b.size = a.size;
- b.endSize = a.endSize;
- b.sx = a.sx;
- b.sy = a.sy;
- b.ax = a.ax;
- b.ay = a.ay;
-}
-
-void ColoredParticle::reload(ParticleData *d)
-{
- if (m_node == 0)
- return;
-
- ColoredParticleVertices *particles = (ColoredParticleVertices *) m_node->geometry()->vertexData();
-
- int pos = particleTypeIndex(d);
-
- ColoredParticleVertices &p = particles[pos];
-
- //Perhaps we could be more efficient?
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
-}
-
-void ColoredParticle::load(ParticleData *d)
-{
- if (m_node == 0)
- return;
-
- //Color initialization
- // Particle color
- Color4ub color;
- qreal redVariation = m_color_variation + m_redVariation;
- qreal greenVariation = m_color_variation + m_greenVariation;
- qreal blueVariation = m_color_variation + m_blueVariation;
- color.r = m_color.red() * (1 - redVariation) + rand() % 256 * redVariation;
- color.g = m_color.green() * (1 - greenVariation) + rand() % 256 * greenVariation;
- color.b = m_color.blue() * (1 - blueVariation) + rand() % 256 * blueVariation;
- color.a = m_alpha * m_color.alpha() * (1 - m_alphaVariation) + rand() % 256 * m_alphaVariation;
- ColoredParticleVertices *particles = (ColoredParticleVertices *) m_node->geometry()->vertexData();
- ColoredParticleVertices &p = particles[particleTypeIndex(d)];
- p.v1.color = p.v2.color = p.v3.color = p.v4.color = color;
-
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
-}
-
-QT_END_NAMESPACE
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef COLOREDPARTICLE_H
-#define COLOREDPARTICLE_H
-#include "particle.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class ParticleTrailsMaterial;
-class QSGGeometryNode;
-
-struct Color4ub {
- uchar r;
- uchar g;
- uchar b;
- uchar a;
-};
-
-struct ColoredParticleVertex {
- float x;
- float y;
- float tx;
- float ty;
- float t;
- float lifeSpan;
- float size;
- float endSize;
- float sx;
- float sy;
- float ax;
- float ay;
- Color4ub color;
-};
-
-struct ColoredParticleVertices {
- ColoredParticleVertex v1;
- ColoredParticleVertex v2;
- ColoredParticleVertex v3;
- ColoredParticleVertex v4;
-};
-
-class ColoredParticle : public ParticleType
-{
- Q_OBJECT
- Q_PROPERTY(QUrl image READ image WRITE setImage NOTIFY imageChanged)
- Q_PROPERTY(QUrl colorTable READ colortable WRITE setColortable NOTIFY colortableChanged)
- Q_PROPERTY(QUrl sizeTable READ sizetable WRITE setSizetable NOTIFY sizetableChanged)
- Q_PROPERTY(QUrl opacityTable READ opacitytable WRITE setOpacitytable NOTIFY opacitytableChanged)
-
- Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
- //Stacks (added) with individual colorVariations
- Q_PROPERTY(qreal colorVariation READ colorVariation WRITE setColorVariation NOTIFY colorVariationChanged)
- Q_PROPERTY(qreal redVariation READ redVariation WRITE setRedVariation NOTIFY redVariationChanged)
- Q_PROPERTY(qreal greenVariation READ greenVariation WRITE setGreenVariation NOTIFY greenVariationChanged)
- Q_PROPERTY(qreal blueVariation READ blueVariation WRITE setBlueVariation NOTIFY blueVariationChanged)
- //Stacks (multiplies) with the Alpha in the color, mostly here so you can use svg color names (which have full alpha)
- Q_PROPERTY(qreal alpha READ alpha WRITE setAlpha NOTIFY alphaChanged)
- Q_PROPERTY(qreal alphaVariation READ alphaVariation WRITE setAlphaVariation NOTIFY alphaVariationChanged)
-
-public:
- explicit ColoredParticle(QSGItem *parent = 0);
- virtual ~ColoredParticle(){}
-
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
- virtual void setCount(int c);
-
- QUrl image() const { return m_image_name; }
- void setImage(const QUrl &image);
-
- QUrl colortable() const { return m_colortable_name; }
- void setColortable(const QUrl &table);
-
- QUrl sizetable() const { return m_sizetable_name; }
- void setSizetable (const QUrl &table);
-
- QUrl opacitytable() const { return m_opacitytable_name; }
- void setOpacitytable(const QUrl &table);
-
- QColor color() const { return m_color; }
- void setColor(const QColor &color);
-
- qreal colorVariation() const { return m_color_variation; }
- void setColorVariation(qreal var);
-
- qreal renderOpacity() const { return m_render_opacity; }
-
- qreal alphaVariation() const
- {
- return m_alphaVariation;
- }
-
- qreal alpha() const
- {
- return m_alpha;
- }
-
- qreal redVariation() const
- {
- return m_redVariation;
- }
-
- qreal greenVariation() const
- {
- return m_greenVariation;
- }
-
- qreal blueVariation() const
- {
- return m_blueVariation;
- }
-
-signals:
-
- void imageChanged();
- void colortableChanged();
- void sizetableChanged();
- void opacitytableChanged();
-
- void colorChanged();
- void colorVariationChanged();
-
- void particleDurationChanged();
- void alphaVariationChanged(qreal arg);
-
- void alphaChanged(qreal arg);
-
- void redVariationChanged(qreal arg);
-
- void greenVariationChanged(qreal arg);
-
- void blueVariationChanged(qreal arg);
-
-public slots:
- void setAlphaVariation(qreal arg)
- {
- if (m_alphaVariation != arg) {
- m_alphaVariation = arg;
- emit alphaVariationChanged(arg);
- }
- }
-
- void setAlpha(qreal arg)
- {
- if (m_alpha != arg) {
- m_alpha = arg;
- emit alphaChanged(arg);
- }
- }
-
- void setRedVariation(qreal arg)
- {
- if (m_redVariation != arg) {
- m_redVariation = arg;
- emit redVariationChanged(arg);
- }
- }
-
- void setGreenVariation(qreal arg)
- {
- if (m_greenVariation != arg) {
- m_greenVariation = arg;
- emit greenVariationChanged(arg);
- }
- }
-
- void setBlueVariation(qreal arg)
- {
- if (m_blueVariation != arg) {
- m_blueVariation = arg;
- emit blueVariationChanged(arg);
- }
- }
-
- void reloadColor(const Color4ub &c, ParticleData* d);
-protected:
- QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
- void reset();
- void prepareNextFrame();
- QSGGeometryNode* buildParticleNode();
-private:
- void vertexCopy(ColoredParticleVertex &b,const ParticleVertex& a);
- bool m_do_reset;
-
- QUrl m_image_name;
- QUrl m_colortable_name;
- QUrl m_sizetable_name;
- QUrl m_opacitytable_name;
-
-
- QColor m_color;
- qreal m_color_variation;
- qreal m_particleDuration;
-
- QSGGeometryNode *m_node;
- ParticleTrailsMaterial *m_material;
-
- // derived values...
- int m_last_particle;
-
- qreal m_render_opacity;
- qreal m_alphaVariation;
- qreal m_alpha;
- qreal m_redVariation;
- qreal m_greenVariation;
- qreal m_blueVariation;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // COLOREDPARTICLE_H
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <private/qsgcontext_p.h>
-#include <private/qsgadaptationlayer_p.h>
-#include <qsgnode.h>
-#include <qsgtexturematerial.h>
-#include <qsgtexture.h>
-#include <QFile>
-#include "deformableparticle.h"
-#include <QGLFunctions>
-#include <qsgengine.h>
-
-QT_BEGIN_NAMESPACE
-
-const float CONV = 0.017453292519943295;
-class DeformableParticleMaterial : public QSGMaterial
-{
-public:
- DeformableParticleMaterial()
- : timestamp(0)
- {
- setFlag(Blending, true);
- }
-
- ~DeformableParticleMaterial()
- {
- delete texture;
- }
-
- virtual QSGMaterialType *type() const { static QSGMaterialType type; return &type; }
- virtual QSGMaterialShader *createShader() const;
- virtual int compare(const QSGMaterial *other) const
- {
- return this - static_cast<const DeformableParticleMaterial *>(other);
- }
-
- QSGTexture *texture;
-
- qreal timestamp;
-};
-
-
-class DeformableParticleMaterialData : public QSGMaterialShader
-{
-public:
- DeformableParticleMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
- {
- QFile vf(vertexFile ? vertexFile : ":resources/deformablevertex.shader");
- vf.open(QFile::ReadOnly);
- m_vertex_code = vf.readAll();
-
- QFile ff(fragmentFile ? fragmentFile : ":resources/deformablefragment.shader");
- ff.open(QFile::ReadOnly);
- m_fragment_code = ff.readAll();
-
- Q_ASSERT(!m_vertex_code.isNull());
- Q_ASSERT(!m_fragment_code.isNull());
- }
-
- void deactivate() {
- QSGMaterialShader::deactivate();
-
- for (int i=0; i<8; ++i) {
- program()->setAttributeArray(i, GL_FLOAT, chunkOfBytes, 1, 0);
- }
- }
-
- virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *)
- {
- DeformableParticleMaterial *m = static_cast<DeformableParticleMaterial *>(newEffect);
- state.context()->functions()->glActiveTexture(GL_TEXTURE0);
- m->texture->bind();
-
- program()->setUniformValue(m_opacity_id, state.opacity());
- program()->setUniformValue(m_timestamp_id, (float) m->timestamp);
-
- if (state.isMatrixDirty())
- program()->setUniformValue(m_matrix_id, state.combinedMatrix());
- }
-
- virtual void initialize() {
- m_matrix_id = program()->uniformLocation("matrix");
- m_opacity_id = program()->uniformLocation("opacity");
- m_timestamp_id = program()->uniformLocation("timestamp");
- }
-
- virtual const char *vertexShader() const { return m_vertex_code.constData(); }
- virtual const char *fragmentShader() const { return m_fragment_code.constData(); }
-
- virtual char const *const *attributeNames() const {
- static const char *attr[] = {
- "vPos",
- "vTex",
- "vData",
- "vVec",
- "vDeformVec",
- "vRotation",
- 0
- };
- return attr;
- }
-
- virtual bool isColorTable() const { return false; }
-
- int m_matrix_id;
- int m_opacity_id;
- int m_timestamp_id;
-
- QByteArray m_vertex_code;
- QByteArray m_fragment_code;
-
- static float chunkOfBytes[1024];
-};
-float DeformableParticleMaterialData::chunkOfBytes[1024];
-
-
-QSGMaterialShader *DeformableParticleMaterial::createShader() const
-{
- return new DeformableParticleMaterialData;
-}
-
-struct DeformableParticleVertex {
- float x;
- float y;
- float tx;
- float ty;
- float t;
- float lifeSpan;
- float size;
- float endSize;
- float sx;
- float sy;
- float ax;
- float ay;
- float xx;
- float xy;
- float yx;
- float yy;
- float rotation;
- float rotationSpeed;
- float autoRotate;//Assume that GPUs prefer floats to bools
-};
-
-struct DeformableParticleVertices {
- DeformableParticleVertex v1;
- DeformableParticleVertex v2;
- DeformableParticleVertex v3;
- DeformableParticleVertex v4;
-};
-
-
-DeformableParticle::DeformableParticle(QSGItem* parent)
- : ParticleType(parent)
- , m_do_reset(false)
- , m_rotation(0)
- , m_autoRotation(false)
- , m_xVector(0)
- , m_yVector(0)
- , m_rotationVariation(0)
- , m_rotationSpeed(0)
- , m_rotationSpeedVariation(0)
-{
- setFlag(ItemHasContents);
-}
-
-void DeformableParticle::setImage(const QUrl &image)
-{
- if (image == m_image)
- return;
- m_image = image;
- emit imageChanged();
- reset();
-}
-
-void DeformableParticle::setCount(int c)
-{
- ParticleType::setCount(c);
- m_pleaseReset = true;
-}
-
-void DeformableParticle::reset()
-{
- ParticleType::reset();
- m_pleaseReset = true;
-}
-
-static QSGGeometry::Attribute DeformableParticle_Attributes[] = {
- { 0, 2, GL_FLOAT }, // Position
- { 1, 2, GL_FLOAT }, // TexCoord
- { 2, 4, GL_FLOAT }, // Data
- { 3, 4, GL_FLOAT }, // Vectors
- { 4, 4, GL_FLOAT }, // DeformationVectors
- { 5, 3, GL_FLOAT } // Rotation
-};
-
-static QSGGeometry::AttributeSet DeformableParticle_AttributeSet =
-{
- 6, // Attribute Count
- (2 + 2 + 4 + 4 + 4 + 3) * sizeof(float),
- DeformableParticle_Attributes
-};
-
-QSGGeometryNode* DeformableParticle::buildParticleNode()
-{
- if (m_count * 4 > 0xffff) {
- printf("DeformableParticle: Too many particles... \n");
- return 0;
- }
-
- if(m_count <= 0) {
- printf("DeformableParticle: Too few particles... \n");
- return 0;
- }
-
- QImage image(m_image.toLocalFile());
- if (image.isNull()) {
- printf("DeformableParticle: loading image failed... '%s'\n", qPrintable(m_image.toLocalFile()));
- return 0;
- }
-
- int vCount = m_count * 4;
- int iCount = m_count * 6;
-
- QSGGeometry *g = new QSGGeometry(DeformableParticle_AttributeSet, vCount, iCount);
- g->setDrawingMode(GL_TRIANGLES);
-
- DeformableParticleVertex *vertices = (DeformableParticleVertex *) g->vertexData();
- for (int p=0; p<m_count; ++p) {
-
- for (int i=0; i<4; ++i) {
- vertices[i].x = 0;
- vertices[i].y = 0;
- vertices[i].t = -1;
- vertices[i].lifeSpan = 0;
- vertices[i].size = 0;
- vertices[i].endSize = 0;
- vertices[i].sx = 0;
- vertices[i].sy = 0;
- vertices[i].ax = 0;
- vertices[i].ay = 0;
- vertices[i].xx = 1;
- vertices[i].xy = 0;
- vertices[i].yx = 0;
- vertices[i].yy = 1;
- vertices[i].rotation = 0;
- vertices[i].rotationSpeed = 0;
- vertices[i].autoRotate = 0;
- }
-
- vertices[0].tx = 0;
- vertices[0].ty = 0;
-
- vertices[1].tx = 1;
- vertices[1].ty = 0;
-
- vertices[2].tx = 0;
- vertices[2].ty = 1;
-
- vertices[3].tx = 1;
- vertices[3].ty = 1;
-
- vertices += 4;
- }
-
- quint16 *indices = g->indexDataAsUShort();
- for (int i=0; i<m_count; ++i) {
- int o = i * 4;
- indices[0] = o;
- indices[1] = o + 1;
- indices[2] = o + 2;
- indices[3] = o + 1;
- indices[4] = o + 3;
- indices[5] = o + 2;
- indices += 6;
- }
-
- if (m_material) {
- delete m_material;
- m_material = 0;
- }
-
- if (!m_material)
- m_material = new DeformableParticleMaterial();
-
-
- m_material->texture = sceneGraphEngine()->createTextureFromImage(image);
- m_material->texture->setFiltering(QSGTexture::Linear);
-
- m_node = new QSGGeometryNode();
- m_node->setGeometry(g);
- m_node->setMaterial(m_material);
-
- m_last_particle = 0;
-
- return m_node;
-}
-
-QSGNode *DeformableParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
-{
- if(m_pleaseReset){
- if(m_node)
- delete m_node;
- if(m_material)
- delete m_material;
-
- m_node = 0;
- m_material = 0;
- m_pleaseReset = false;
- }
-
- if(m_system && m_system->isRunning())
- prepareNextFrame();
- if (m_node){
- update();
- m_node->markDirty(QSGNode::DirtyMaterial);
- }
-
- return m_node;
-}
-
-void DeformableParticle::prepareNextFrame()
-{
- if (m_node == 0){ //TODO: Staggered loading (as emitted)
- m_node = buildParticleNode();
- if(m_node == 0)
- return;
- }
- qint64 timeStamp = m_system->systemSync(this);
-
- qreal time = timeStamp / 1000.;
- m_material->timestamp = time;
-
-}
-
-
-void DeformableParticle::vertexCopy(DeformableParticleVertex &b,const ParticleVertex& a)
-{
- b.x = a.x - m_systemOffset.x();
- b.y = a.y - m_systemOffset.y();
- b.t = a.t;
- b.lifeSpan = a.lifeSpan;
- b.size = a.size;
- b.endSize = a.endSize;
- b.sx = a.sx;
- b.sy = a.sy;
- b.ax = a.ax;
- b.ay = a.ay;
-}
-
-void DeformableParticle::reload(ParticleData *d)
-{
- if (m_node == 0)
- return;
-
- DeformableParticleVertices *particles = (DeformableParticleVertices *) m_node->geometry()->vertexData();
-
- int pos = particleTypeIndex(d);
-
- DeformableParticleVertices &p = particles[pos];
-
- //Perhaps we could be more efficient?
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
- //TODO: Allow for change of deformation data?
-}
-
-void DeformableParticle::load(ParticleData *d)
-{
- if (m_node == 0)
- return;
-
- //Deformation Initialization
- DeformableParticleVertices *particles = (DeformableParticleVertices *) m_node->geometry()->vertexData();
- DeformableParticleVertices &p = particles[particleTypeIndex(d)];
- if(m_xVector){
- const QPointF &ret = m_xVector->sample(QPointF(d->pv.x, d->pv.y));
- p.v1.xx = p.v2.xx = p.v3.xx = p.v4.xx = ret.x();
- p.v1.xy = p.v2.xy = p.v3.xy = p.v4.xy = ret.y();
- }
- if(m_yVector){
- const QPointF &ret = m_yVector->sample(QPointF(d->pv.x, d->pv.y));
- p.v1.yx = p.v2.yx = p.v3.yx = p.v4.yx = ret.x();
- p.v1.yy = p.v2.yy = p.v3.yy = p.v4.yy = ret.y();
- }
- p.v1.rotation = p.v2.rotation = p.v3.rotation = p.v4.rotation =
- (m_rotation + (m_rotationVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationVariation) ) * CONV;
- p.v1.rotationSpeed = p.v2.rotationSpeed = p.v3.rotationSpeed = p.v4.rotationSpeed =
- (m_rotationSpeed + (m_rotationSpeedVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationSpeedVariation) ) * CONV;
- p.v1.autoRotate = p.v2.autoRotate = p.v3.autoRotate = p.v4.autoRotate = m_autoRotation?1.0:0.0;
-
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
-}
-
-QT_END_NAMESPACE
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DEFORMABLEPARTICLE_H
-#define DEFORMABLEPARTICLE_H
-#include "particle.h"
-#include "varyingvector.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class DeformableParticleMaterial;
-class QSGGeometryNode;
-struct DeformableParticleVertex;
-
-class DeformableParticle : public ParticleType
-{
- Q_OBJECT
- //Note that the particle centering can be less accurate with this one
- Q_PROPERTY(QUrl image READ image WRITE setImage NOTIFY imageChanged)
-
- Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
- Q_PROPERTY(qreal rotationVariation READ rotationVariation WRITE setRotationVariation NOTIFY rotationVariationChanged)
- Q_PROPERTY(qreal rotationSpeed READ rotationSpeed WRITE setRotationSpeed NOTIFY rotationSpeedChanged)
- Q_PROPERTY(qreal rotationSpeedVariation READ rotationSpeedVariation WRITE setRotationSpeedVariation NOTIFY rotationSpeedVariationChanged)
- //If true, then will face the direction of motion. Stacks with rotation, e.g. setting rotation
- //to 180 will lead to facing away from the direction of motion
- Q_PROPERTY(bool autoRotation READ autoRotation WRITE autoRotation NOTIFY autoRotationChanged)
-
- //###Call i/j? Makes more sense to those with vector calculus experience, and I could even add the cirumflex in QML?
- //xVector is the vector from the top-left point to the top-right point, and is multiplied by current size
- Q_PROPERTY(VaryingVector* xVector READ xVector WRITE setXVector NOTIFY xVectorChanged)
- //yVector is the same, but top-left to bottom-left. The particle is always a parallelogram.
- Q_PROPERTY(VaryingVector* yVector READ yVector WRITE setYVector NOTIFY yVectorChanged)
-
- //Do we want to add the tables?
- //Q_PROPERTY(QUrl colorTable READ colortable WRITE setColortable NOTIFY colortableChanged)
- //Q_PROPERTY(QUrl sizeTable READ sizetable WRITE setSizetable NOTIFY sizetableChanged)
- //Q_PROPERTY(QUrl opacityTable READ opacitytable WRITE setOpacitytable NOTIFY opacitytableChanged)
-
- //Does it need alpha? For convenience only, as images probably don't have it
- //Q_PROPERTY(qreal alpha READ alpha WRITE setAlpha NOTIFY alphaChanged)
- //Q_PROPERTY(qreal alphaVariation READ alphaVariation WRITE setAlphaVariation NOTIFY alphaVariationChanged)
-
-public:
- explicit DeformableParticle(QSGItem *parent = 0);
- virtual ~DeformableParticle(){}
-
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
- virtual void setCount(int c);
-
- QUrl image() const { return m_image; }
- void setImage(const QUrl &image);
-
- qreal rotation() const
- {
- return m_rotation;
- }
-
- bool autoRotation() const
- {
- return m_autoRotation;
- }
-
- VaryingVector* xVector() const
- {
- return m_xVector;
- }
-
- VaryingVector* yVector() const
- {
- return m_yVector;
- }
-
- qreal rotationVariation() const
- {
- return m_rotationVariation;
- }
-
- qreal rotationSpeed() const
- {
- return m_rotationSpeed;
- }
-
- qreal rotationSpeedVariation() const
- {
- return m_rotationSpeedVariation;
- }
-
-signals:
-
- void imageChanged();
- void rotationChanged(qreal arg);
-
- void autoRotationChanged(bool arg);
-
- void xVectorChanged(VaryingVector* arg);
-
- void yVectorChanged(VaryingVector* arg);
-
- void rotationVariationChanged(qreal arg);
-
- void rotationSpeedChanged(qreal arg);
-
- void rotationSpeedVariationChanged(qreal arg);
-
-public slots:
-void setRotation(qreal arg)
-{
- if (m_rotation != arg) {
- m_rotation = arg;
- emit rotationChanged(arg);
- }
-}
-
-void autoRotation(bool arg)
-{
- if (m_autoRotation != arg) {
- m_autoRotation = arg;
- emit autoRotationChanged(arg);
- }
-}
-
-void setXVector(VaryingVector* arg)
-{
- if (m_xVector != arg) {
- m_xVector = arg;
- emit xVectorChanged(arg);
- }
-}
-
-void setYVector(VaryingVector* arg)
-{
- if (m_yVector != arg) {
- m_yVector = arg;
- emit yVectorChanged(arg);
- }
-}
-
-void setRotationVariation(qreal arg)
-{
- if (m_rotationVariation != arg) {
- m_rotationVariation = arg;
- emit rotationVariationChanged(arg);
- }
-}
-
-void setRotationSpeed(qreal arg)
-{
- if (m_rotationSpeed != arg) {
- m_rotationSpeed = arg;
- emit rotationSpeedChanged(arg);
- }
-}
-
-void setRotationSpeedVariation(qreal arg)
-{
- if (m_rotationSpeedVariation != arg) {
- m_rotationSpeedVariation = arg;
- emit rotationSpeedVariationChanged(arg);
- }
-}
-
-protected:
- QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
- void reset();
- void prepareNextFrame();
- QSGGeometryNode* buildParticleNode();
-private:
- void vertexCopy(DeformableParticleVertex &b,const ParticleVertex& a);
- bool m_do_reset;
-
- QUrl m_image;
- QSGGeometryNode *m_node;
- DeformableParticleMaterial *m_material;
-
- // derived values...
- int m_last_particle;
-
- qreal m_render_opacity;
- // generated vars
- qreal m_rotation;
- bool m_autoRotation;
- VaryingVector* m_xVector;
- VaryingVector* m_yVector;
- qreal m_rotationVariation;
- qreal m_rotationSpeed;
- qreal m_rotationSpeedVariation;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // DEFORMABLEPARTICLE_H
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "driftaffector.h"
-#include "particlesystem.h"
-QT_BEGIN_NAMESPACE
-DriftAffector::DriftAffector(QSGItem *parent) :
- ParticleAffector(parent)
-{
-}
-
-DriftAffector::~DriftAffector()
-{
-}
-
-bool DriftAffector::affectParticle(ParticleData *data, qreal dt)
-{
- if(!m_xDrift && !m_yDrift)
- return false;
- qreal dx = (((qreal)qrand() / (qreal)RAND_MAX) - 0.5) * 2 * m_xDrift * dt;
- qreal dy = (((qreal)qrand() / (qreal)RAND_MAX) - 0.5) * 2 * m_yDrift * dt;
- if(dx)
- data->setInstantaneousSX(data->curSX() + dx);
- if(dy)
- data->setInstantaneousSY(data->curSY() + dy);
-
- return true;
-}
-QT_END_NAMESPACE
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DRIFTAFFECTOR_H
-#define DRIFTAFFECTOR_H
-#include "particleaffector.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-
-class DriftAffector : public ParticleAffector
-{
- Q_OBJECT
- Q_PROPERTY(qreal xDrift READ xDrift WRITE setXDrift NOTIFY xDriftChanged)
- Q_PROPERTY(qreal yDrift READ yDrift WRITE setYDrift NOTIFY yDriftChanged)
-public:
- explicit DriftAffector(QSGItem *parent = 0);
- ~DriftAffector();
- qreal yDrift() const
- {
- return m_yDrift;
- }
-
- qreal xDrift() const
- {
- return m_xDrift;
- }
-protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
-
-signals:
-
- void yDriftChanged(qreal arg);
-
- void xDriftChanged(qreal arg);
-
-public slots:
-
-void setYDrift(qreal arg)
-{
- if (m_yDrift != arg) {
- m_yDrift = arg;
- emit yDriftChanged(arg);
- }
-}
-
-void setXDrift(qreal arg)
-{
- if (m_xDrift != arg) {
- m_xDrift = arg;
- emit xDriftChanged(arg);
- }
-}
-
-private:
- qreal m_yDrift;
- qreal m_xDrift;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // DRIFTAFFECTOR_H
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "eternalaffector.h"
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-EternalAffector::EternalAffector(QSGItem *parent) :
- ParticleAffector(parent)
-{
-}
-
-bool EternalAffector::affectParticle(ParticleData *d, qreal dt)
-{
- qreal target = (m_system->m_timeInt - m_targetLife)/1000.0;
- if(d->pv.t < target)
- d->pv.t = target;
- return true;
-}
-
-QT_END_NAMESPACE
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "gravitationalsingularityaffector.h"
-#include <cmath>
-#include <QDebug>
-QT_BEGIN_NAMESPACE
-GravitationalSingularityAffector::GravitationalSingularityAffector(QSGItem *parent) :
- ParticleAffector(parent), m_strength(0.0), m_x(0), m_y(0)
-{
-}
-
-const qreal LIMIT = 200;
-qreal limit(qreal val){
- if(qAbs(val) > LIMIT){
- return val < 0 ? LIMIT * -1 : LIMIT;
- }else{
- return val;
- }
-}
-
-bool GravitationalSingularityAffector::affectParticle(ParticleData *d, qreal dt)
-{
- if(!m_strength)
- return false;
- qreal dx = m_x - d->curX();
- qreal dy = m_y - d->curY();
- qreal r = sqrt((dx*dx) + (dy*dy));
- if(r < 0.1 ){//Simulated event horizion - It's right on top of it, and will never escape again. just stick it here.
- d->pv.ax = 0;
- d->pv.ay = 0;
- d->pv.sx = 0;
- d->pv.sy = 0;
- d->pv.x = m_x;
- d->pv.y = m_y;
- return true;
- }else if(r < 50.0){//Too close, typical dt values are far too coarse for simulation. This may kill perf though
- int parts = floor(100.0/r);
- ParticleData* f = new ParticleData;//Fake, where it's all in real time for convenience
- f->pv.x = d->curX();
- f->pv.y = d->curY();
- f->pv.sx = limit(d->curSX());
- f->pv.sy = limit(d->curSY());
- f->pv.ax = d->pv.ax;
- f->pv.ay = d->pv.ay;
- subaffect(f, dt/parts, true);
- for(int i=1; i<parts; i++)
- subaffect(f, dt/parts, false);
-
- //Copy values from f, and turn into 'from start' values
- qreal t = (m_system->m_timeInt/1000.) - d->pv.t;
- qreal sy = limit(f->pv.sy) - t*f->pv.ay;
- qreal y = f->pv.y - t*sy - 0.5 * t*t*f->pv.ay;
- qreal sx = limit(f->pv.sx) - t*f->pv.ax;
- qreal x = f->pv.x - t*sx - 0.5 * t*t*f->pv.ax;
-
- d->pv.ay = f->pv.ay;
- d->pv.sy = sy;
- d->pv.y = y;
- d->pv.ax = f->pv.ax;
- d->pv.sx = sx;
- d->pv.x = x;
- return true;
- }
- qreal theta = atan2(dy,dx);
- qreal ds = (m_strength / (r*r)) * dt;
- dx = ds * cos(theta);
- dy = ds * sin(theta);
- d->setInstantaneousSX(limit(d->pv.sx + dx));
- d->setInstantaneousSY(limit(d->pv.sy + dy));
- return true;
-}
-
-const qreal EPSILON = 0.1;
-bool fuzzyCompare(qreal a, qreal b)
-{
- //Not using qFuzzyCompare because I want control of epsilon
- return (a >= b - EPSILON && a <= b + EPSILON);
-}
-
-bool fuzzyLess(qreal a, qreal b)
-{
- //Not using qFuzzyCompare because I want control of epsilon
- return a <= b + EPSILON;
-}
-
-bool fuzzyMore(qreal a, qreal b)
-{
- //Not using qFuzzyCompare because I want control of epsilon
- return a >= b - EPSILON;
-}
-
-bool lineIntersect(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3)
-{
- if(x3 < qMin(x1,x2) || x3 > qMax(x1,x2) || y3 < qMin(y1,y2) || y3 > qMax(y1,y2))
- return false;
- qreal m,c;
- m = (y2-y1) / (x2-x1);
- c = y1 - m*x1;
- return (fuzzyCompare(y3, m*x3 + c));
-}
-
-void GravitationalSingularityAffector::subaffect(ParticleData *d, qreal dt, bool first)
-{
- if(!first){
- qreal nextX = d->pv.x + d->pv.sx * dt + d->pv.ax * dt * dt * 0.5;
- qreal nextY = d->pv.y + d->pv.sy * dt + d->pv.ay * dt * dt * 0.5;
- if(lineIntersect(d->pv.x, d->pv.y, nextX, nextY, m_x, m_y)){
- d->pv.ax = 0;
- d->pv.ay = 0;
- d->pv.sx = 0;
- d->pv.sy = 0;
- d->pv.x = m_x;
- d->pv.y = m_y;
- return;
- //Passed center - the near infinite forces cancel out
-// d->pv.x = m_x + m_x - d->pv.x;
-// d->pv.y = m_y + m_y - d->pv.y;
-// d->pv.sx *= -1;
-// d->pv.sy *= -1;
-// return;
- }
- //Simulate advancing a dt
- d->pv.x = nextX;
- d->pv.y = nextY;
- d->pv.sx += d->pv.ax * dt;
- d->pv.sy += d->pv.ay * dt;
- }
- qreal dx = m_x - d->pv.x;
- qreal dy = m_y - d->pv.y;
- qreal r = sqrt((dx*dx) + (dy*dy));
- if(!r)
- return;
- qreal theta = atan2(dy,dx);
- qreal ds = (m_strength / (r*r)) * dt;
- dx = ds * cos(theta);
- dy = ds * sin(theta);
- d->pv.sx = d->pv.sx + dx;
- d->pv.sy = d->pv.sy + dy;
-}
-QT_END_NAMESPACE
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef GRAVITATIONALSINGULARITYAFFECTOR_H
-#define GRAVITATIONALSINGULARITYAFFECTOR_H
-#include "particleaffector.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-
-class GravitationalSingularityAffector : public ParticleAffector
-{
- Q_OBJECT
- Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged)
- Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged)
- Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged)
-public:
- explicit GravitationalSingularityAffector(QSGItem *parent = 0);
-
- qreal strength() const
- {
- return m_strength;
- }
-
- qreal x() const
- {
- return m_x;
- }
-
- qreal y() const
- {
- return m_y;
- }
-protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
- void subaffect(ParticleData *d, qreal dt, bool first);
-signals:
-
- void strengthChanged(qreal arg);
-
- void xChanged(qreal arg);
-
- void yChanged(qreal arg);
-
-public slots:
-
-void setStrength(qreal arg)
-{
- if (m_strength != arg) {
- m_strength = arg;
- emit strengthChanged(arg);
- }
-}
-
-void setX(qreal arg)
-{
- if (m_x != arg) {
- m_x = arg;
- emit xChanged(arg);
- }
-}
-
-void setY(qreal arg)
-{
- if (m_y != arg) {
- m_y = arg;
- emit yChanged(arg);
- }
-}
-
-private:
-qreal m_strength;
-qreal m_x;
-qreal m_y;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // GRAVITATIONALSINGULARITYAFFECTOR_H
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "V1/qdeclarativeparticles_p.h"
-#include "pluginmain.h"
-#include "spritestate.h"
-#include "spriteengine.h"
-#include "particleaffector.h"
-#include "wanderaffector.h"
-//#include "rockingaffector.h"
-//#include "scalingaffector.h"
-#include "resetaffector.h"
-#include "gravityaffector.h"
-#include "driftaffector.h"
-#include "gravitationalsingularityaffector.h"
-#include "frictionaffector.h"
-#include "meanderaffector.h"
-#include "attractoraffector.h"
-#include "speedlimitaffector.h"
-#include "killaffector.h"
-//#include "zoneaffector.h"
-//#include "toggleaffector.h"
-#include "spritegoalaffector.h"
-#include "swarmaffector.h"
-#include "turbulenceaffector.h"
-#include "eternalaffector.h"
-#include "particlesystem.h"
-#include "particleemitter.h"
-//#include "spriteemitter.h"
-#include "trailsemitter.h"
-#include "burstemitter.h"
-#include "particle.h"
-#include "coloredparticle.h"
-#include "spriteparticle.h"
-//#include "modelparticle.h"
-#include "dataparticle.h"
-#include "itemparticle.h"
-#include "superparticle.h"
-#include "ultraparticle.h"
-//#include "pairedparticle.h"
-#include "spriteimage.h"
-#include "followemitter.h"
-#include "particleextruder.h"
-#include "ellipseextruder.h"
-#include "lineextruder.h"
-#include "maskextruder.h"
-#include "varyingvector.h"
-#include "pointvector.h"
-#include "angledvector.h"
-#include "directedvector.h"
-//#include "followaffector.h"
-#include "deformableparticle.h"
-#include "pictureaffector.h"
-
-QT_BEGIN_NAMESPACE
-
-void ParticlesPlugin::registerTypes(const char *uri)
-{
- Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.particles"));
-
- qmlRegisterType<QDeclarativeParticles>(uri, 1, 0, "Particles");
- qmlRegisterType<QDeclarativeParticleMotion>(uri,1,0,"ParticleMotion");
- qmlRegisterType<QDeclarativeParticleMotionGravity>(uri,1,0,"ParticleMotionGravity");
- qmlRegisterType<QDeclarativeParticleMotionLinear>(uri,1,0,"ParticleMotionLinear");
- qmlRegisterType<QDeclarativeParticleMotionWander>(uri,1,0,"ParticleMotionWander");
- qmlRegisterType<SpriteState>(uri, 2, 0, "Sprite");
- qmlRegisterType<SpriteEngine>(uri, 2, 0, "SpriteEngine");
- qmlRegisterType<SpriteImage>(uri, 2, 0, "SpriteImage");
-
- qmlRegisterType<ParticleSystem>(uri, 2, 0, "ParticleSystem");
-
- qmlRegisterType<ParticleType>(uri, 2, 0, "Particle");
- qmlRegisterType<ColoredParticle>(uri, 2, 0, "ColoredParticle");
- qmlRegisterType<SpriteParticle>(uri, 2, 0, "SpriteParticle");
- //qmlRegisterType<ModelParticle>(uri, 2, 0, "ModelParticle");
- qmlRegisterType<DataParticle>(uri, 2, 0, "DataParticle");
- qmlRegisterType<ItemParticle>(uri, 2, 0, "ItemParticle");
- //qmlRegisterType<PairedParticle>(uri, 2, 0, "PairedParticle");
- qmlRegisterType<DeformableParticle>(uri, 2, 0, "DeformableParticle");
- qmlRegisterType<SuperParticle>(uri, 2, 0, "SuperParticle");
- qmlRegisterType<UltraParticle>(uri, 2, 0, "UltraParticle");
-
- qmlRegisterType<ParticleEmitter>(uri, 2, 0, "ParticleEmitter");
- qmlRegisterType<TrailsEmitter>(uri, 2, 0, "TrailEmitter");
- qmlRegisterType<TrailsEmitter>(uri, 2, 0, "BurstEmitter");
-
- qmlRegisterType<FollowEmitter>(uri, 2, 0, "FollowEmitter");
- qmlRegisterType<ParticleExtruder>(uri, 2, 0, "Box");
- qmlRegisterType<EllipseExtruder>(uri, 2, 0, "Ellipse");
- qmlRegisterType<LineExtruder>(uri, 2, 0, "Line");
- qmlRegisterType<MaskExtruder>(uri, 2, 0, "Mask");
-
- qmlRegisterType<VaryingVector>(uri, 2, 0, "NullVector");
- qmlRegisterType<PointVector>(uri, 2, 0, "PointVector");
- qmlRegisterType<AngledVector>(uri, 2, 0, "AngleVector");
- qmlRegisterType<DirectedVector>(uri, 2, 0, "DirectedVector");
-
- qmlRegisterType<ParticleAffector>(uri, 2, 0, "ParticleAffector");
- qmlRegisterType<WanderAffector>(uri, 2, 0, "Wander");
- //qmlRegisterType<ScalingAffector>(uri, 2, 0, "Scale");
- //qmlRegisterType<RockingAffector>(uri, 2, 0, "Rocking");
- qmlRegisterType<DriftAffector>(uri, 2, 0, "Drift");
- qmlRegisterType<FrictionAffector>(uri, 2, 0, "Friction");
- qmlRegisterType<GravitationalSingularityAffector>(uri, 2, 0, "GravitationalSingularity");
- qmlRegisterType<AttractorAffector>(uri, 2, 0, "Attractor");
- qmlRegisterType<MeanderAffector>(uri, 2, 0, "Meander");
- qmlRegisterType<SpeedLimitAffector>(uri, 2, 0, "SpeedLimit");
- qmlRegisterType<GravityAffector>(uri, 2, 0, "Gravity");
- qmlRegisterType<EternalAffector>(uri, 2, 0, "Stasis");
- qmlRegisterType<ResetAffector>(uri, 2, 0, "Reset");
- //qmlRegisterType<ZoneAffector>(uri, 2, 0, "Zone");
- //qmlRegisterType<ToggleAffector>(uri, 2, 0, "Toggle");
- qmlRegisterType<KillAffector>(uri, 2, 0, "Kill");
- qmlRegisterType<SpriteGoalAffector>(uri, 2, 0, "SpriteGoal");
- qmlRegisterType<SwarmAffector>(uri, 2, 0 , "Swarm");
- qmlRegisterType<TurbulenceAffector>(uri, 2, 0 , "Turbulence");
- qmlRegisterType<PictureAffector>(uri, 2, 0, "Picture");
-}
-
-QT_END_NAMESPACE
-
-Q_EXPORT_PLUGIN2(Particles, QT_PREPEND_NAMESPACE(ParticlesPlugin))
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "meanderaffector.h"
-
-QT_BEGIN_NAMESPACE
-
-MeanderAffector::MeanderAffector(QSGItem *parent) :
- ParticleAffector(parent)
-{
-}
-
-bool MeanderAffector::affectParticle(ParticleData *data, qreal dt)
-{
- if(!m_xDrift && !m_yDrift)
- return false;
- qreal dx = (((qreal)qrand() / (qreal)RAND_MAX) - 0.5) * 2 * m_xDrift * dt;
- qreal dy = (((qreal)qrand() / (qreal)RAND_MAX) - 0.5) * 2 * m_yDrift * dt;
- if(dx)
- data->setInstantaneousAX(data->pv.ax + dx);
- if(dy)
- data->setInstantaneousAY(data->pv.ay + dy);
-
- return true;
-}
-
-QT_END_NAMESPACE
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MEANDERAFFECTOR_H
-#define MEANDERAFFECTOR_H
-#include "particleaffector.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-
-class MeanderAffector : public ParticleAffector
-{
- Q_OBJECT
- //Like drift, but affects da/dt instead of ds/dt
- Q_PROPERTY(qreal xDrift READ xDrift WRITE setXDrift NOTIFY xDriftChanged)
- Q_PROPERTY(qreal yDrift READ yDrift WRITE setYDrift NOTIFY yDriftChanged)
-public:
- explicit MeanderAffector(QSGItem *parent = 0);
-
- qreal xDrift() const
- {
- return m_xDrift;
- }
-
- qreal yDrift() const
- {
- return m_yDrift;
- }
-protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
-signals:
-
- void xDriftChanged(qreal arg);
-
- void yDriftChanged(qreal arg);
-
-public slots:
-
- void setXDrift(qreal arg)
- {
- if (m_xDrift != arg) {
- m_xDrift = arg;
- emit xDriftChanged(arg);
- }
- }
- void setYDrift(qreal arg)
- {
- if (m_yDrift != arg) {
- m_yDrift = arg;
- emit yDriftChanged(arg);
- }
- }
-
-private:
- qreal m_xDrift;
- qreal m_yDrift;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // MEANDERAFFECTOR_H
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
-** This file is part of the Declarative module of the Qt Toolkit.
+** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
**
****************************************************************************/
-#ifndef ETERNALAFFECTOR_H
-#define ETERNALAFFECTOR_H
-#include "particleaffector.h"
+#include <QtDeclarative/qdeclarativeextensionplugin.h>
+#include <QtDeclarative/qdeclarative.h>
-QT_BEGIN_HEADER
+#include "V1/qdeclarativeparticles_p.h"
QT_BEGIN_NAMESPACE
-QT_MODULE(Declarative)
-
-class EternalAffector : public ParticleAffector
+class QParticlesQmlModule : public QDeclarativeExtensionPlugin
{
Q_OBJECT
- Q_PROPERTY(int targetLife READ targetLife WRITE setTargetLife NOTIFY targetLifeChanged)
-
public:
- explicit EternalAffector(QSGItem *parent = 0);
- int targetLife() const
- {
- return m_targetLife;
- }
-
-protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
-
-signals:
-
- void targetLifeChanged(int arg);
-
-public slots:
-
- void setTargetLife(int arg)
+ virtual void registerTypes(const char *uri)
{
- if (m_targetLife != arg) {
- m_targetLife = arg;
- emit targetLifeChanged(arg);
- }
+ Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.particles"));
+ qmlRegisterType<QDeclarativeParticleMotion>(uri,1,0,"ParticleMotion");
+ qmlRegisterType<QDeclarativeParticleMotionGravity>(uri,1,0,"ParticleMotionGravity");
+ qmlRegisterType<QDeclarativeParticleMotionLinear>(uri,1,0,"ParticleMotionLinear");
+ qmlRegisterType<QDeclarativeParticleMotionWander>(uri,1,0,"ParticleMotionWander");
+ qmlRegisterType<QDeclarativeParticles>(uri,1,0,"Particles");
}
-private:
- int m_targetLife;
};
QT_END_NAMESPACE
-QT_END_HEADER
+#include "particles.moc"
+
+Q_EXPORT_PLUGIN2(qmlparticlesplugin, QT_PREPEND_NAMESPACE(QParticlesQmlModule));
-#endif // ETERNALAFFECTOR_H
include(../qimportbase.pri)
HEADERS += \
- V1/qdeclarativeparticles_p.h \
- spritestate.h \
- pluginmain.h \
- particleaffector.h \
- wanderaffector.h \
- #rockingaffector.h \
- #scalingaffector.h \
- driftaffector.h \
- particleemitter.h \
- particlesystem.h \
- trailsemitter.h \
- #spriteemitter.h \
- particle.h \
- coloredparticle.h \
- spriteparticle.h \
- spritegoalaffector.h \
- #zoneaffector.h \
- frictionaffector.h \
- gravitationalsingularityaffector.h \
- killaffector.h \
- speedlimitaffector.h \
- spriteengine.h \
- gravityaffector.h \
- attractoraffector.h \
- meanderaffector.h \
- #toggleaffector.h \
- spriteimage.h \
- #pairedparticle.h \
- followemitter.h \
- swarmaffector.h \
- turbulenceaffector.h \
- particleextruder.h \
- ellipseextruder.h \
- maskextruder.h \
- varyingvector.h \
- pointvector.h \
- angledvector.h \
- directedvector.h \
- #modelparticle.h \
- eternalaffector.h \
- lineextruder.h \
- resetaffector.h \
- deformableparticle.h \
- pictureaffector.h \
- superparticle.h \
- ultraparticle.h \
- burstemitter.h \
- dataparticle.h \
- itemparticle.h
+ V1/qdeclarativeparticles_p.h
SOURCES += \
- V1/qdeclarativeparticles.cpp \
- spritestate.cpp \
- main.cpp \
- particleaffector.cpp \
- wanderaffector.cpp \
- #rockingaffector.cpp \
- #scalingaffector.cpp \
- driftaffector.cpp \
- particleemitter.cpp \
- particlesystem.cpp \
- trailsemitter.cpp \
- #spriteemitter.cpp \
- particle.cpp \
- coloredparticle.cpp \
- spriteparticle.cpp \
- spritegoalaffector.cpp \
- #zoneaffector.cpp \
- frictionaffector.cpp \
- gravitationalsingularityaffector.cpp \
- killaffector.cpp \
- speedlimitaffector.cpp \
- spriteengine.cpp \
- gravityaffector.cpp \
- attractoraffector.cpp \
- meanderaffector.cpp \
- #toggleaffector.cpp \
- spriteimage.cpp \
- #pairedparticle.cpp \
- followemitter.cpp \
- swarmaffector.cpp \
- turbulenceaffector.cpp \
- particleextruder.cpp \
- ellipseextruder.cpp \
- maskextruder.cpp \
- varyingvector.cpp \
- pointvector.cpp \
- angledvector.cpp \
- directedvector.cpp \
- #modelparticle.cpp \
- eternalaffector.cpp \
- lineextruder.cpp \
- resetaffector.cpp \
- deformableparticle.cpp \
- pictureaffector.cpp \
- superparticle.cpp \
- ultraparticle.cpp \
- burstemitter.cpp \
- dataparticle.cpp \
- itemparticle.cpp
-
-QT += declarative opengl
-#Because we use QDeclarativePixmapCache once...
-QT += core-private gui-private declarative-private script-private
+ particles.cpp \
+ V1/qdeclarativeparticles.cpp
+QT += declarative opengl core gui declarative-private core-private gui-private
OTHER_FILES += \
qmldir
-RESOURCES += \
- spriteparticles.qrc
-
DESTDIR = $$QT.declarative.imports/$$TARGETPATH
target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "pictureaffector.h"
-#include "coloredparticle.h"
-#include <QDebug>
-#include <private/qsgtexture_p.h>
-#include <private/qdeclarativepixmapcache_p.h>
-
-QT_BEGIN_NAMESPACE
-
-PictureAffector::PictureAffector(QSGItem *parent) :
- ParticleAffector(parent), m_pix(0)
-{
- m_needsReset = true;
-}
-
-void PictureAffector::reset(int systemIdx)
-{
- ParticleAffector::reset(systemIdx);
-}
-
-void PictureAffector::startLoadImage()
-{
- if(m_pix)
- m_pix->clear();
- else
- m_pix = new QDeclarativePixmap();
- m_pix->load(qmlEngine(this), m_image, QDeclarativePixmap::Cache);
- if(m_pix->isReady())
- loadImage();
- else
- m_pix->connectFinished(this, SLOT(loadImage()));
-}
-void PictureAffector::loadImage()
-{
- m_loadedImage = m_pix->pixmap().toImage();
- if(m_loadedImage.isNull())
- qWarning() << "PictureAffector could not load picture " << m_image;
-}
-
-bool PictureAffector::affectParticle(ParticleData *d, qreal dt)
-{
- Q_UNUSED(dt);
- if(!width() || !height()){
- qWarning() << "PictureAffector needs a size";
- return false;
- }
-
- if(m_loadedImage.isNull())
- return false;
-
- if(m_loadedImage.size()!=QSize(width(), height()))
- m_loadedImage = m_loadedImage.scaled(width(), height());//TODO: Aspect Ratio Control?
-
- bool affected = false;
- QPoint pos = QPoint(d->curX() - m_offset.x(), d->curY() - m_offset.y());
- if(!QRect(0,0,width(),height()).contains(pos)){
- //XXX: Just a debugging helper, as I don't think it can get here.
- qWarning() << "PictureAffector gives up.";
- return false;
- }
- Color4ub c;
- QRgb col = m_loadedImage.pixel(pos);
- c.a = qAlpha(col);
- c.b = qBlue(col);
- c.g = qGreen(col);
- c.r = qRed(col);
- foreach(ParticleType *p, m_system->m_groupData[d->group]->types){
- if(qobject_cast<ColoredParticle*>(p)){
- ColoredParticle* cp = qobject_cast<ColoredParticle*>(p);
- cp->reloadColor(c, d);
- affected = true;
- }
- }
-
- return affected;//Doesn't affect particle data, but necessary for onceOff
-}
-
-QT_END_NAMESPACE
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef PICTUREAFFECTOR_H
-#define PICTUREAFFECTOR_H
-#include "particleaffector.h"
-#include <QDebug>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class QDeclarativePixmap;
-class PictureAffector : public ParticleAffector
-{
- Q_OBJECT
- //Usually want to use "particles" to target just colored stuff, and save performance
- //Use onceOff (inherited) to determine if this is an emitter modification or a more constant enforcer
- Q_PROPERTY(QUrl image READ image WRITE setImage NOTIFY imageChanged)
- //TODO: Bool smooth, where it interpolates
-public:
- explicit PictureAffector(QSGItem *parent = 0);
-
- QUrl image() const
- {
- return m_image;
- }
-
-protected:
- virtual void reset(int systemIdx);
- virtual bool affectParticle(ParticleData *d, qreal dt);
-signals:
-
- void imageChanged(QUrl arg);
-
-public slots:
- void setImage(QUrl arg)
- {
- if (m_image != arg) {
- m_image = arg;
- startLoadImage();
- emit imageChanged(arg);
- }
- }
-
-private slots:
- void loadImage();
-private:
- void startLoadImage();
- QUrl m_image;
- QDeclarativePixmap* m_pix;
- QImage m_loadedImage;
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // PICTUREAFFECTOR_H
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef PLUGINMAIN_H
-#define PLUGINMAIN_H
-
-#include <QtDeclarative>
-#include <QtDeclarative/QDeclarativeExtensionPlugin>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class ParticlesPlugin : public QDeclarativeExtensionPlugin
-{
- Q_OBJECT
-public:
- virtual void registerTypes(const char *uri);
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // PLUGINMAIN_H
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "resetaffector.h"
-#include <cmath>
-QT_BEGIN_NAMESPACE
-ResetAffector::ResetAffector(QSGItem *parent) :
- ParticleAffector(parent)
-{
-}
-
-void ResetAffector::reset(int idx)
-{
- ParticleAffector::reset(idx);
- if(m_data[idx])
- delete m_data[idx];
- m_data.insert(idx, 0);//TODO: Either load with data now, or get data next tick whether active or not
-}
-
-bool ResetAffector::affectParticle(ParticleData *d, qreal dt)
-{
- TrajectoryData* trajectory;
- if(m_data[d->systemIndex]){
- trajectory = m_data[d->systemIndex];
- //TODO: Faster to calculate once (not 4 times)
- d->setInstantaneousSX(trajectory->sx);
- d->setInstantaneousSY(trajectory->sy);
- d->setInstantaneousAX(trajectory->ax);
- d->setInstantaneousAY(trajectory->ay);
- }else{
- trajectory = new TrajectoryData;
- }
- trajectory->sx = d->pv.sx;
- trajectory->sy = d->pv.sy;
- trajectory->ax = d->pv.ax;
- trajectory->ay = d->pv.ay;
- m_data.insert(d->systemIndex, trajectory);//overwrites
- return true;
-}
-QT_END_NAMESPACE
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef RESETAFFECTOR_H
-#define RESETAFFECTOR_H
-#include "particleaffector.h"
-#include <QHash>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-struct TrajectoryData{
- qreal sx,sy,ax,ay;
-};
-
-class ResetAffector : public ParticleAffector
-{
- Q_OBJECT
-public:
- explicit ResetAffector(QSGItem *parent = 0);
- virtual void reset(int systemIdx);
-
-signals:
-
-public slots:
-protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
-private:
- QHash<int, TrajectoryData*> m_data;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // RESETAFFECTOR_H
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "speedlimitaffector.h"
-#include <cmath>
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-SpeedLimitAffector::SpeedLimitAffector(QSGItem *parent) :
- ParticleAffector(parent), m_speedLimit(-1)
-{
-}
-
-bool SpeedLimitAffector::affectParticle(ParticleData *d, qreal dt){
- Q_UNUSED(dt);
- if(m_speedLimit <= 0)
- return false;
-
- qreal x = d->curSX();
- qreal y = d->curSY();
- qreal s = sqrt(x*x + y*y);
- if(s <= m_speedLimit)
- return false;
-
-
- if(s >= m_speedLimit*1.01){
- qreal theta = atan2(y,x);
- d->setInstantaneousSX(m_speedLimit * cos(theta));
- d->setInstantaneousSY(m_speedLimit * sin(theta));
- }
-
- d->setInstantaneousAY(0);
- d->setInstantaneousAX(0);
-
- return true;
-}
-
-QT_END_NAMESPACE
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef SPEEDLIMITAFFECTOR_H
-#define SPEEDLIMITAFFECTOR_H
-#include "particleaffector.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class SpeedLimitAffector : public ParticleAffector
-{
- Q_OBJECT
- Q_PROPERTY(qreal speedLimit READ speedLimit WRITE setSpeedLimit NOTIFY speedLimitChanged)
-
-
-public:
- explicit SpeedLimitAffector(QSGItem *parent = 0);
-
- qreal speedLimit() const
- {
- return m_speedLimit;
- }
-
-protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
-signals:
-
- void speedLimitChanged(qreal arg);
-
-public slots:
-void setSpeedLimit(qreal arg)
-{
- if (m_speedLimit != arg) {
- m_speedLimit = arg;
- emit speedLimitChanged(arg);
- }
-}
-
-private:
-qreal m_speedLimit;
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // SPEEDLIMITAFFECTOR_H
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "spriteparticle.h"
-#include "spritestate.h"
-#include "spriteengine.h"
-#include "particleemitter.h"
-#include <private/qsgcontext_p.h>
-#include <private/qsgadaptationlayer_p.h>
-#include <qsgnode.h>
-#include <qsgtexturematerial.h>
-#include <qsgengine.h>
-#include <qsgtexture.h>
-#include <QFile>
-#include <cmath>
-#include <qmath.h>
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-class SpriteParticlesMaterial : public QSGMaterial
-{
-public:
- SpriteParticlesMaterial();
- virtual ~SpriteParticlesMaterial();
- virtual QSGMaterialType *type() const { static QSGMaterialType type; return &type; }
- virtual QSGMaterialShader *createShader() const;
- virtual int compare(const QSGMaterial *other) const
- {
- return this - static_cast<const SpriteParticlesMaterial *>(other);
- }
-
- QSGTexture *texture;
-
- qreal timestamp;
- int framecount;
- int animcount;
-};
-
-SpriteParticlesMaterial::SpriteParticlesMaterial()
- : timestamp(0)
- , framecount(1)
- , animcount(1)
-{
- setFlag(Blending, true);
-}
-
-SpriteParticlesMaterial::~SpriteParticlesMaterial()
-{
- delete texture;
-}
-
-class SpriteParticlesMaterialData : public QSGMaterialShader
-{
-public:
- SpriteParticlesMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
- {
- QFile vf(vertexFile ? vertexFile : ":resources/spritevertex.shader");
- vf.open(QFile::ReadOnly);
- m_vertex_code = vf.readAll();
-
- QFile ff(fragmentFile ? fragmentFile : ":resources/spritefragment.shader");
- ff.open(QFile::ReadOnly);
- m_fragment_code = ff.readAll();
-
- Q_ASSERT(!m_vertex_code.isNull());
- Q_ASSERT(!m_fragment_code.isNull());
- }
-
- void deactivate() {
- QSGMaterialShader::deactivate();
-
- for (int i=0; i<8; ++i) {
- program()->setAttributeArray(i, GL_FLOAT, chunkOfBytes, 1, 0);
- }
- }
-
- virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *)
- {
- SpriteParticlesMaterial *m = static_cast<SpriteParticlesMaterial *>(newEffect);
- m->texture->bind();
-
- program()->setUniformValue(m_opacity_id, state.opacity());
- program()->setUniformValue(m_timestamp_id, (float) m->timestamp);
- program()->setUniformValue(m_framecount_id, (float) m->framecount);
- program()->setUniformValue(m_animcount_id, (float) m->animcount);
-
- if (state.isMatrixDirty())
- program()->setUniformValue(m_matrix_id, state.combinedMatrix());
- }
-
- virtual void initialize() {
- m_matrix_id = program()->uniformLocation("matrix");
- m_opacity_id = program()->uniformLocation("opacity");
- m_timestamp_id = program()->uniformLocation("timestamp");
- m_framecount_id = program()->uniformLocation("framecount");
- m_animcount_id = program()->uniformLocation("animcount");
- }
-
- virtual const char *vertexShader() const { return m_vertex_code.constData(); }
- virtual const char *fragmentShader() const { return m_fragment_code.constData(); }
-
- virtual char const *const *attributeNames() const {
- static const char *attr[] = {
- "vPos",
- "vTex",
- "vData",
- "vVec",
- "vAnimData",
- 0
- };
- return attr;
- }
-
- virtual bool isColorTable() const { return false; }
-
- int m_matrix_id;
- int m_opacity_id;
- int m_timestamp_id;
- int m_framecount_id;
- int m_animcount_id;
-
- QByteArray m_vertex_code;
- QByteArray m_fragment_code;
-
- static float chunkOfBytes[1024];
-};
-float SpriteParticlesMaterialData::chunkOfBytes[1024];
-
-QSGMaterialShader *SpriteParticlesMaterial::createShader() const
-{
- return new SpriteParticlesMaterialData;
-}
-
-struct SpriteParticleVertex {
- float x;
- float y;
- float tx;
- float ty;
- float t;
- float lifeSpan;
- float size;
- float endSize;
- float sx;
- float sy;
- float ax;
- float ay;
- float animIdx;
- float frameDuration;
- float frameCount;
- float animT;
-};
-
-struct SpriteParticleVertices {
- SpriteParticleVertex v1;
- SpriteParticleVertex v2;
- SpriteParticleVertex v3;
- SpriteParticleVertex v4;
-};
-
-SpriteParticle::SpriteParticle(QSGItem *parent) :
- ParticleType(parent)
- , m_node(0)
- , m_material(0)
- , m_spriteEngine(0)
-{
- setFlag(ItemHasContents);
- }
-QDeclarativeListProperty<SpriteState> SpriteParticle::sprites()
-{
- return QDeclarativeListProperty<SpriteState>(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);
-}
-
-void SpriteParticle::createEngine()
-{
- if(m_spriteEngine)
- delete m_spriteEngine;
- if(m_sprites.count())
- m_spriteEngine = new SpriteEngine(m_sprites, this);
- else
- m_spriteEngine = 0;
- reset();//###this is probably out of updatePaintNode and shouldn't be
-}
-
-void SpriteParticle::setCount(int c)
-{
- ParticleType::setCount(c);
- m_pleaseReset = true;
-}
-
-static QSGGeometry::Attribute SpriteParticle_Attributes[] = {
- { 0, 2, GL_FLOAT }, // Position
- { 1, 2, GL_FLOAT }, // TexCoord
- { 2, 4, GL_FLOAT }, // Data
- { 3, 4, GL_FLOAT }, // Vectors
- { 4, 4, GL_FLOAT } // Colors
-};
-
-static QSGGeometry::AttributeSet SpriteParticle_AttributeSet =
-{
- 5, // Attribute Count
- (2 + 2 + 4 + 4 + 4) * sizeof(float),
- SpriteParticle_Attributes
-};
-
-
-
-QSGGeometryNode* SpriteParticle::buildParticleNode()
-{
- if (m_count * 4 > 0xffff) {
- qWarning() << "SpriteParticle: too many particles...";
- return 0;
- }
-
- if (m_count * 4 == 0) {
- qWarning() << "SpriteParticle: No particles...";
- return 0;
- }
-
- if (!m_spriteEngine) {
- qWarning() << "SpriteParticle: No sprite engine...";
- return 0;
- }
-
- if (m_material) {
- delete m_material;
- m_material = 0;
- }
-
- m_material = new SpriteParticlesMaterial();
-
- QImage image = m_spriteEngine->assembledImage();
- if(image.isNull())
- return 0;
- m_material->texture = sceneGraphEngine()->createTextureFromImage(image);
- m_material->texture->setFiltering(QSGTexture::Linear);
- m_material->framecount = m_spriteEngine->maxFrames();
- m_spriteEngine->setCount(m_count);
-
- int vCount = m_count * 4;
- int iCount = m_count * 6;
- QSGGeometry *g = new QSGGeometry(SpriteParticle_AttributeSet, vCount, iCount);
- g->setDrawingMode(GL_TRIANGLES);
-
- SpriteParticleVertex *vertices = (SpriteParticleVertex *) g->vertexData();
- for (int p=0; p<m_count; ++p) {
-
- for (int i=0; i<4; ++i) {
- vertices[i].x = 0;
- vertices[i].y = 0;
- vertices[i].t = -1;
- vertices[i].lifeSpan = -1;
- vertices[i].size = 0;
- vertices[i].endSize = 0;
- vertices[i].sx = 0;
- vertices[i].sy = 0;
- vertices[i].ax = 0;
- vertices[i].ay = 0;
- vertices[i].animIdx = 0;
- vertices[i].frameDuration = 1;
- vertices[i].frameCount = 1;
- vertices[i].animT = -1;
-
- }
-
- vertices[0].tx = 0;
- vertices[0].ty = 0;
-
- vertices[1].tx = 1.0;
- vertices[1].ty = 0;
-
- vertices[2].tx = 0;
- vertices[2].ty = 1.0;
-
- vertices[3].tx = 1.0;
- vertices[3].ty = 1.0;
-
- vertices += 4;
- }
-
- quint16 *indices = g->indexDataAsUShort();
- for (int i=0; i<m_count; ++i) {
- int o = i * 4;
- indices[0] = o;
- indices[1] = o + 1;
- indices[2] = o + 2;
- indices[3] = o + 1;
- indices[4] = o + 3;
- indices[5] = o + 2;
- indices += 6;
- }
-
-
- m_node = new QSGGeometryNode();
- m_node->setGeometry(g);
- m_node->setMaterial(m_material);
- m_last_particle = 0;
- return m_node;
-}
-
-void SpriteParticle::vertexCopy(SpriteParticleVertex &b,const ParticleVertex& a)
-{
- b.x = a.x + m_systemOffset.x();
- b.y = a.y + m_systemOffset.y();
- b.t = a.t;
- b.lifeSpan = a.lifeSpan;
- b.size = a.size;
- b.endSize = a.endSize;
- b.sx = a.sx;
- b.sy = a.sy;
- b.ax = a.ax;
- b.ay = a.ay;
-}
-
-void SpriteParticle::load(ParticleData *d)
-{
- if (m_node == 0) //error creating node
- return;
-
- SpriteParticleVertices *particles = (SpriteParticleVertices *) m_node->geometry()->vertexData();
- int pos = particleTypeIndex(d);
- SpriteParticleVertices &p = particles[pos];
-
- // Initial Sprite State
- m_spriteEngine->startSprite(pos);
- p.v1.animT = p.v2.animT = p.v3.animT = p.v4.animT = p.v1.t;
- p.v1.animIdx = p.v2.animIdx = p.v3.animIdx = p.v4.animIdx = 0;
- p.v1.frameCount = p.v2.frameCount = p.v3.frameCount = p.v4.frameCount = m_spriteEngine->spriteFrames(pos);
- p.v1.frameDuration = p.v2.frameDuration = p.v3.frameDuration = p.v4.frameDuration = m_spriteEngine->spriteDuration(pos);
-
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
-
-}
-
-void SpriteParticle::reload(ParticleData *d)
-{
- if (m_node == 0) //error creating node
- return;
-
- SpriteParticleVertices *particles = (SpriteParticleVertices *) m_node->geometry()->vertexData();
- int pos = particleTypeIndex(d);
- SpriteParticleVertices &p = particles[pos];
-
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
-}
-
-
-QSGNode *SpriteParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
-{
- if(m_pleaseReset){
- if(m_node)
- delete m_node;
- if(m_material)
- delete m_material;
-
- m_node = 0;
- m_material = 0;
- m_pleaseReset = false;
- }
- if(m_system&& m_system->isRunning())
- prepareNextFrame();
- if (m_node){
- update();
- m_node->markDirty(QSGNode::DirtyMaterial);
- }
-
- return m_node;
-}
-
-void SpriteParticle::prepareNextFrame()
-{
- if (m_node == 0){ //TODO: Staggered loading (as emitted) (is it just moving this check to load()?)
- m_node = buildParticleNode();
- if(m_node == 0)
- return;
- }
- qint64 timeStamp = m_system->systemSync(this);
-
-
- qreal time = timeStamp / 1000.;
- m_material->timestamp = time;
- m_material->animcount = m_spriteEngine->spriteCount();
-
- //Advance State
- SpriteParticleVertices *particles = (SpriteParticleVertices *) m_node->geometry()->vertexData();
- m_spriteEngine->updateSprites(timeStamp);
- for(int i=0; i<m_count; i++){
- SpriteParticleVertices &p = particles[i];
- int curIdx = m_spriteEngine->spriteState(i);
- if(curIdx != p.v1.animIdx){
- p.v1.animIdx = p.v2.animIdx = p.v3.animIdx = p.v4.animIdx = curIdx;
- p.v1.animT = p.v2.animT = p.v3.animT = p.v4.animT = m_spriteEngine->spriteStart(i)/1000.0;
- p.v1.frameCount = p.v2.frameCount = p.v3.frameCount = p.v4.frameCount = m_spriteEngine->spriteFrames(i);
- p.v1.frameDuration = p.v2.frameDuration = p.v3.frameDuration = p.v4.frameDuration = m_spriteEngine->spriteDuration(i);
- }
- }
-}
-
-void SpriteParticle::reset()
-{
- ParticleType::reset();
- m_pleaseReset = true;
-}
-
-QT_END_NAMESPACE
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef SPRITEPARTICLE_H
-#define SPRITEPARTICLE_H
-#include "particle.h"
-#include <QDeclarativeListProperty>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class SpriteState;
-class SpriteEngine;
-class QSGGeometryNode;
-class SpriteParticlesMaterial;
-class SpriteParticleVertex;
-
-class SpriteParticle : public ParticleType
-{
- Q_OBJECT
- Q_PROPERTY(QDeclarativeListProperty<SpriteState> sprites READ sprites)
- Q_CLASSINFO("DefaultProperty", "sprites")
-public:
- explicit SpriteParticle(QSGItem *parent = 0);
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
- virtual void setCount(int c);
-
- QDeclarativeListProperty<SpriteState> sprites();
- SpriteEngine* spriteEngine() {return m_spriteEngine;}
-signals:
-
-public slots:
-protected:
- QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
- void reset();
- void prepareNextFrame();
- QSGGeometryNode* buildParticleNode();
-private slots:
- void createEngine();
-private:
- QSGGeometryNode *m_node;
- SpriteParticlesMaterial *m_material;
-
- int m_particle_duration;
- int m_last_particle;
-
- QList<SpriteState*> m_sprites;
- SpriteEngine* m_spriteEngine;
-
- void vertexCopy(SpriteParticleVertex &b,const ParticleVertex& a);
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // SPRITEPARTICLE_H
+++ /dev/null
-<RCC>
- <qresource prefix="/">
- <file>resources/spritefragment.shader</file>
- <file>resources/spritevertex.shader</file>
- <file>resources/ctfragment.shader</file>
- <file>resources/ctvertex.shader</file>
- <file>resources/trailsfragment.shader</file>
- <file>resources/trailsvertex.shader</file>
- <file>resources/spriteimagefragment.shader</file>
- <file>resources/spriteimagevertex.shader</file>
- <file>resources/identitytable.png</file>
- <file>resources/defaultFadeInOut.png</file>
- <file>resources/deformablefragment.shader</file>
- <file>resources/deformablevertex.shader</file>
- <file>resources/ultravertex.shader</file>
- <file>resources/ultrafragment.shader</file>
- <file>resources/supervertex.shader</file>
- <file>resources/superfragment.shader</file>
- <file>resources/simplevertex.shader</file>
- <file>resources/simplefragment.shader</file>
- </qresource>
-</RCC>
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <private/qsgcontext_p.h>
-#include <private/qsgadaptationlayer_p.h>
-#include <qsgnode.h>
-#include <qsgtexturematerial.h>
-#include <qsgtexture.h>
-#include <QFile>
-#include "superparticle.h"
-#include "particleemitter.h"
-#include <QGLFunctions>
-#include <qsgengine.h>
-
-QT_BEGIN_NAMESPACE
-
-const float CONV = 0.017453292519943295;
-class SuperMaterial : public QSGMaterial
-{
-public:
- SuperMaterial()
- : timestamp(0)
- {
- setFlag(Blending, true);
- }
-
- ~SuperMaterial()
- {
- delete texture;
- delete colortable;
- delete sizetable;
- delete opacitytable;
- }
-
- virtual QSGMaterialType *type() const { static QSGMaterialType type; return &type; }
- virtual QSGMaterialShader *createShader() const;
- virtual int compare(const QSGMaterial *other) const
- {
- return this - static_cast<const SuperMaterial *>(other);
- }
-
- QSGTexture *texture;
- QSGTexture *colortable;
- QSGTexture *sizetable;
- QSGTexture *opacitytable;
-
- qreal timestamp;
-};
-
-
-class SuperMaterialData : public QSGMaterialShader
-{
-public:
- SuperMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
- {
- QFile vf(vertexFile ? vertexFile : ":resources/supervertex.shader");
- vf.open(QFile::ReadOnly);
- m_vertex_code = vf.readAll();
-
- QFile ff(fragmentFile ? fragmentFile : ":resources/superfragment.shader");
- ff.open(QFile::ReadOnly);
- m_fragment_code = ff.readAll();
-
- Q_ASSERT(!m_vertex_code.isNull());
- Q_ASSERT(!m_fragment_code.isNull());
- }
-
- void deactivate() {
- QSGMaterialShader::deactivate();
-
- for (int i=0; i<8; ++i) {
- program()->setAttributeArray(i, GL_FLOAT, chunkOfBytes, 1, 0);
- }
- }
-
- virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *)
- {
- SuperMaterial *m = static_cast<SuperMaterial *>(newEffect);
- state.context()->functions()->glActiveTexture(GL_TEXTURE0);
- m->texture->bind();
-
- state.context()->functions()->glActiveTexture(GL_TEXTURE1);
- m->colortable->bind();
- program()->setUniformValue(m_colortable_id, 1);
-
- state.context()->functions()->glActiveTexture(GL_TEXTURE2);
- m->sizetable->bind();
- program()->setUniformValue(m_sizetable_id, 2);
-
- state.context()->functions()->glActiveTexture(GL_TEXTURE3);
- m->opacitytable->bind();
- program()->setUniformValue(m_opacitytable_id, 3);
-
- program()->setUniformValue(m_opacity_id, state.opacity());
- program()->setUniformValue(m_timestamp_id, (float) m->timestamp);
-
- if (state.isMatrixDirty())
- program()->setUniformValue(m_matrix_id, state.combinedMatrix());
- }
-
- virtual void initialize() {
- m_colortable_id = program()->uniformLocation("colortable");
- m_sizetable_id = program()->uniformLocation("sizetable");
- m_opacitytable_id = program()->uniformLocation("opacitytable");
- m_matrix_id = program()->uniformLocation("matrix");
- m_opacity_id = program()->uniformLocation("opacity");
- m_timestamp_id = program()->uniformLocation("timestamp");
- }
-
- virtual const char *vertexShader() const { return m_vertex_code.constData(); }
- virtual const char *fragmentShader() const { return m_fragment_code.constData(); }
-
- virtual char const *const *attributeNames() const {
- static const char *attr[] = {
- "vPos",
- "vTex",
- "vData",
- "vVec",
- "vColor",
- "vDeformVec",
- "vRotation",
- 0
- };
- return attr;
- }
-
- virtual bool isColorTable() const { return false; }
-
- int m_matrix_id;
- int m_opacity_id;
- int m_timestamp_id;
- int m_colortable_id;
- int m_sizetable_id;
- int m_opacitytable_id;
-
- QByteArray m_vertex_code;
- QByteArray m_fragment_code;
-
- static float chunkOfBytes[1024];
-};
-float SuperMaterialData::chunkOfBytes[1024];
-
-
-QSGMaterialShader *SuperMaterial::createShader() const
-{
- return new SuperMaterialData;
-}
-
-SuperParticle::SuperParticle(QSGItem* parent)
- : ParticleType(parent)
- , m_do_reset(false)
- , m_color(Qt::white)
- , m_color_variation(0.5)
- , m_node(0)
- , m_material(0)
- , m_alphaVariation(0.0)
- , m_alpha(1.0)
- , m_redVariation(0.0)
- , m_greenVariation(0.0)
- , m_blueVariation(0.0)
-{
- setFlag(ItemHasContents);
-}
-
-void SuperParticle::setImage(const QUrl &image)
-{
- if (image == m_image_name)
- return;
- m_image_name = image;
- emit imageChanged();
- reset();
-}
-
-
-void SuperParticle::setColortable(const QUrl &table)
-{
- if (table == m_colortable_name)
- return;
- m_colortable_name = table;
- emit colortableChanged();
- reset();
-}
-
-void SuperParticle::setSizetable(const QUrl &table)
-{
- if (table == m_sizetable_name)
- return;
- m_sizetable_name = table;
- emit sizetableChanged();
- reset();
-}
-
-void SuperParticle::setOpacitytable(const QUrl &table)
-{
- if (table == m_opacitytable_name)
- return;
- m_opacitytable_name = table;
- emit opacitytableChanged();
- reset();
-}
-
-void SuperParticle::setColor(const QColor &color)
-{
- if (color == m_color)
- return;
- m_color = color;
- emit colorChanged();
- //m_system->pleaseReset();//XXX
-}
-
-void SuperParticle::setColorVariation(qreal var)
-{
- if (var == m_color_variation)
- return;
- m_color_variation = var;
- emit colorVariationChanged();
- //m_system->pleaseReset();//XXX
-}
-
-void SuperParticle::setCount(int c)
-{
- ParticleType::setCount(c);
- m_pleaseReset = true;
-}
-
-void SuperParticle::reset()
-{
- ParticleType::reset();
- m_pleaseReset = true;
-}
-
-static QSGGeometry::Attribute SuperParticle_Attributes[] = {
- { 0, 2, GL_FLOAT }, // Position
- { 1, 2, GL_FLOAT }, // TexCoord
- { 2, 4, GL_FLOAT }, // Data
- { 3, 4, GL_FLOAT }, // Vectors
- { 4, 4, GL_UNSIGNED_BYTE }, // Colors
- { 5, 4, GL_FLOAT }, // DeformationVectors
- { 6, 3, GL_FLOAT } // Rotation
-};
-
-static QSGGeometry::AttributeSet SuperParticle_AttributeSet =
-{
- 7, // Attribute Count
- (2 + 2 + 4 + 4 + 4 + 3) * sizeof(float) + 4 * sizeof(uchar),
- SuperParticle_Attributes
-};
-
-QSGGeometryNode* SuperParticle::buildParticleNode()
-{
- if (m_count * 4 > 0xffff) {
- printf("SuperParticle: Too many particles... \n");
- return 0;
- }
-
- if(m_count <= 0) {
- printf("SuperParticle: Too few particles... \n");
- return 0;
- }
-
- QImage image(m_image_name.toLocalFile());
- if (image.isNull()) {
- printf("SuperParticle: loading image failed... '%s'\n", qPrintable(m_image_name.toLocalFile()));
- return 0;
- }
-
- int vCount = m_count * 4;
- int iCount = m_count * 6;
-
- QSGGeometry *g = new QSGGeometry(SuperParticle_AttributeSet, vCount, iCount);
- g->setDrawingMode(GL_TRIANGLES);
-
- SuperVertex *vertices = (SuperVertex *) g->vertexData();
- for (int p=0; p<m_count; ++p) {
-
- for (int i=0; i<4; ++i) {
- vertices[i].x = 0;
- vertices[i].y = 0;
- vertices[i].t = -1;
- vertices[i].lifeSpan = 0;
- vertices[i].size = 0;
- vertices[i].endSize = 0;
- vertices[i].sx = 0;
- vertices[i].sy = 0;
- vertices[i].ax = 0;
- vertices[i].ay = 0;
- vertices[i].xx = 1;
- vertices[i].xy = 0;
- vertices[i].yx = 0;
- vertices[i].yy = 1;
- vertices[i].rotation = 0;
- vertices[i].rotationSpeed = 0;
- vertices[i].autoRotate = 0;
- }
-
- vertices[0].tx = 0;
- vertices[0].ty = 0;
-
- vertices[1].tx = 1;
- vertices[1].ty = 0;
-
- vertices[2].tx = 0;
- vertices[2].ty = 1;
-
- vertices[3].tx = 1;
- vertices[3].ty = 1;
-
- vertices += 4;
- }
-
- quint16 *indices = g->indexDataAsUShort();
- for (int i=0; i<m_count; ++i) {
- int o = i * 4;
- indices[0] = o;
- indices[1] = o + 1;
- indices[2] = o + 2;
- indices[3] = o + 1;
- indices[4] = o + 3;
- indices[5] = o + 2;
- indices += 6;
- }
-
- if (m_material) {
- delete m_material;
- m_material = 0;
- }
-
- QImage colortable(m_colortable_name.toLocalFile());
- QImage sizetable(m_sizetable_name.toLocalFile());
- QImage opacitytable(m_opacitytable_name.toLocalFile());
- m_material = new SuperMaterial();
- if(colortable.isNull())
- colortable = QImage(":resources/identitytable.png");
- if(sizetable.isNull())
- sizetable = QImage(":resources/identitytable.png");
- if(opacitytable.isNull())
- opacitytable = QImage(":resources/defaultFadeInOut.png");
- Q_ASSERT(!colortable.isNull());
- Q_ASSERT(!sizetable.isNull());
- Q_ASSERT(!opacitytable.isNull());
- m_material->colortable = sceneGraphEngine()->createTextureFromImage(colortable);
- m_material->sizetable = sceneGraphEngine()->createTextureFromImage(sizetable);
- m_material->opacitytable = sceneGraphEngine()->createTextureFromImage(opacitytable);
-
- m_material->texture = sceneGraphEngine()->createTextureFromImage(image);
- m_material->texture->setFiltering(QSGTexture::Linear);
-
- m_node = new QSGGeometryNode();
- m_node->setGeometry(g);
- m_node->setMaterial(m_material);
-
- m_last_particle = 0;
-
- return m_node;
-}
-
-QSGNode *SuperParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
-{
- if(m_pleaseReset){
- if(m_node)
- delete m_node;
- if(m_material)
- delete m_material;
-
- m_node = 0;
- m_material = 0;
- m_pleaseReset = false;
- }
-
- if(m_system && m_system->isRunning())
- prepareNextFrame();
- if (m_node){
- update();
- m_node->markDirty(QSGNode::DirtyMaterial);
- }
-
- return m_node;
-}
-
-void SuperParticle::prepareNextFrame()
-{
- if (m_node == 0){ //TODO: Staggered loading (as emitted)
- m_node = buildParticleNode();
- if(m_node == 0)
- return;
- }
- qint64 timeStamp = m_system->systemSync(this);
-
- qreal time = timeStamp / 1000.;
- m_material->timestamp = time;
-}
-
-void SuperParticle::reloadColor(const Color4ub &c, ParticleData* d)
-{
- SuperVertices *particles = (SuperVertices *) m_node->geometry()->vertexData();
- int pos = particleTypeIndex(d);
- SuperVertices &p = particles[pos];
- p.v1.color = p.v2.color = p.v3.color = p.v4.color = c;
-}
-
-void SuperParticle::vertexCopy(SuperVertex &b,const ParticleVertex& a)
-{
- b.x = a.x - m_systemOffset.x();
- b.y = a.y - m_systemOffset.y();
- b.t = a.t;
- b.lifeSpan = a.lifeSpan;
- b.size = a.size;
- b.endSize = a.endSize;
- b.sx = a.sx;
- b.sy = a.sy;
- b.ax = a.ax;
- b.ay = a.ay;
-}
-
-void SuperParticle::reload(ParticleData *d)
-{
- if (m_node == 0)
- return;
-
- SuperVertices *particles = (SuperVertices *) m_node->geometry()->vertexData();
-
- int pos = particleTypeIndex(d);
-
- SuperVertices &p = particles[pos];
-
- //Perhaps we could be more efficient?
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
-}
-
-void SuperParticle::load(ParticleData *d)
-{
- if (m_node == 0)
- return;
-
- //Color initialization
- // Particle color
- Color4ub color;
- qreal redVariation = m_color_variation + m_redVariation;
- qreal greenVariation = m_color_variation + m_greenVariation;
- qreal blueVariation = m_color_variation + m_blueVariation;
- color.r = m_color.red() * (1 - redVariation) + rand() % 256 * redVariation;
- color.g = m_color.green() * (1 - greenVariation) + rand() % 256 * greenVariation;
- color.b = m_color.blue() * (1 - blueVariation) + rand() % 256 * blueVariation;
- color.a = m_alpha * m_color.alpha() * (1 - m_alphaVariation) + rand() % 256 * m_alphaVariation;
- SuperVertices *particles = (SuperVertices *) m_node->geometry()->vertexData();
- SuperVertices &p = particles[particleTypeIndex(d)];
- p.v1.color = p.v2.color = p.v3.color = p.v4.color = color;
- if(m_xVector){
- const QPointF &ret = m_xVector->sample(QPointF(d->pv.x, d->pv.y));
- p.v1.xx = p.v2.xx = p.v3.xx = p.v4.xx = ret.x();
- p.v1.xy = p.v2.xy = p.v3.xy = p.v4.xy = ret.y();
- }
- if(m_yVector){
- const QPointF &ret = m_yVector->sample(QPointF(d->pv.x, d->pv.y));
- p.v1.yx = p.v2.yx = p.v3.yx = p.v4.yx = ret.x();
- p.v1.yy = p.v2.yy = p.v3.yy = p.v4.yy = ret.y();
- }
- p.v1.rotation = p.v2.rotation = p.v3.rotation = p.v4.rotation =
- (m_rotation + (m_rotationVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationVariation) ) * CONV;
- p.v1.rotationSpeed = p.v2.rotationSpeed = p.v3.rotationSpeed = p.v4.rotationSpeed =
- (m_rotationSpeed + (m_rotationSpeedVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationSpeedVariation) ) * CONV;
- p.v1.autoRotate = p.v2.autoRotate = p.v3.autoRotate = p.v4.autoRotate = m_autoRotation?1.0:0.0;
-
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
-}
-
-QT_END_NAMESPACE
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef SUPERPARTICLE_H
-#define SUPERPARTICLE_H
-#include "particle.h"
-#include "varyingvector.h"
-
-#include "coloredparticle.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class SuperMaterial;
-class QSGGeometryNode;
-
-/*struct Color4ub {//in coloredparticle
- uchar r;
- uchar g;
- uchar b;
- uchar a;
-};*/
-
-struct SuperVertex {
- float x;
- float y;
- float tx;
- float ty;
- float t;
- float lifeSpan;
- float size;
- float endSize;
- float sx;
- float sy;
- float ax;
- float ay;
- Color4ub color;
- float xx;
- float xy;
- float yx;
- float yy;
- float rotation;
- float rotationSpeed;
- float autoRotate;//Assume that GPUs prefer floats to bools
-};
-
-struct SuperVertices {
- SuperVertex v1;
- SuperVertex v2;
- SuperVertex v3;
- SuperVertex v4;
-};
-
-class SuperParticle : public ParticleType
-{
- Q_OBJECT
- Q_PROPERTY(QUrl image READ image WRITE setImage NOTIFY imageChanged)
- Q_PROPERTY(QUrl colorTable READ colortable WRITE setColortable NOTIFY colortableChanged)
- Q_PROPERTY(QUrl sizeTable READ sizetable WRITE setSizetable NOTIFY sizetableChanged)
- Q_PROPERTY(QUrl opacityTable READ opacitytable WRITE setOpacitytable NOTIFY opacitytableChanged)
-
- Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
- //Stacks (added) with individual colorVariations
- Q_PROPERTY(qreal colorVariation READ colorVariation WRITE setColorVariation NOTIFY colorVariationChanged)
- Q_PROPERTY(qreal redVariation READ redVariation WRITE setRedVariation NOTIFY redVariationChanged)
- Q_PROPERTY(qreal greenVariation READ greenVariation WRITE setGreenVariation NOTIFY greenVariationChanged)
- Q_PROPERTY(qreal blueVariation READ blueVariation WRITE setBlueVariation NOTIFY blueVariationChanged)
- //Stacks (multiplies) with the Alpha in the color, mostly here so you can use svg color names (which have full alpha)
- Q_PROPERTY(qreal alpha READ alpha WRITE setAlpha NOTIFY alphaChanged)
- Q_PROPERTY(qreal alphaVariation READ alphaVariation WRITE setAlphaVariation NOTIFY alphaVariationChanged)
-
- Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
- Q_PROPERTY(qreal rotationVariation READ rotationVariation WRITE setRotationVariation NOTIFY rotationVariationChanged)
- Q_PROPERTY(qreal rotationSpeed READ rotationSpeed WRITE setRotationSpeed NOTIFY rotationSpeedChanged)
- Q_PROPERTY(qreal rotationSpeedVariation READ rotationSpeedVariation WRITE setRotationSpeedVariation NOTIFY rotationSpeedVariationChanged)
- //If true, then will face the direction of motion. Stacks with rotation, e.g. setting rotation
- //to 180 will lead to facing away from the direction of motion
- Q_PROPERTY(bool autoRotation READ autoRotation WRITE autoRotation NOTIFY autoRotationChanged)
-
- //###Call i/j? Makes more sense to those with vector calculus experience, and I could even add the cirumflex in QML?
- //xVector is the vector from the top-left point to the top-right point, and is multiplied by current size
- Q_PROPERTY(VaryingVector* xVector READ xVector WRITE setXVector NOTIFY xVectorChanged)
- //yVector is the same, but top-left to bottom-left. The particle is always a parallelogram.
- Q_PROPERTY(VaryingVector* yVector READ yVector WRITE setYVector NOTIFY yVectorChanged)
-public:
- explicit SuperParticle(QSGItem *parent = 0);
- virtual ~SuperParticle(){}
-
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
- virtual void setCount(int c);
-
- QUrl image() const { return m_image_name; }
- void setImage(const QUrl &image);
-
- QUrl colortable() const { return m_colortable_name; }
- void setColortable(const QUrl &table);
-
- QUrl sizetable() const { return m_sizetable_name; }
- void setSizetable (const QUrl &table);
-
- QUrl opacitytable() const { return m_opacitytable_name; }
- void setOpacitytable(const QUrl &table);
-
- QColor color() const { return m_color; }
- void setColor(const QColor &color);
-
- qreal colorVariation() const { return m_color_variation; }
- void setColorVariation(qreal var);
-
- qreal renderOpacity() const { return m_render_opacity; }
-
- qreal alphaVariation() const
- {
- return m_alphaVariation;
- }
-
- qreal alpha() const
- {
- return m_alpha;
- }
-
- qreal redVariation() const
- {
- return m_redVariation;
- }
-
- qreal greenVariation() const
- {
- return m_greenVariation;
- }
-
- qreal blueVariation() const
- {
- return m_blueVariation;
- }
-
- qreal rotation() const
- {
- return m_rotation;
- }
-
- qreal rotationVariation() const
- {
- return m_rotationVariation;
- }
-
- qreal rotationSpeed() const
- {
- return m_rotationSpeed;
- }
-
- qreal rotationSpeedVariation() const
- {
- return m_rotationSpeedVariation;
- }
-
- bool autoRotation() const
- {
- return m_autoRotation;
- }
-
- VaryingVector* xVector() const
- {
- return m_xVector;
- }
-
- VaryingVector* yVector() const
- {
- return m_yVector;
- }
-
-signals:
-
- void imageChanged();
- void colortableChanged();
- void sizetableChanged();
- void opacitytableChanged();
-
- void colorChanged();
- void colorVariationChanged();
-
- void particleDurationChanged();
- void alphaVariationChanged(qreal arg);
-
- void alphaChanged(qreal arg);
-
- void redVariationChanged(qreal arg);
-
- void greenVariationChanged(qreal arg);
-
- void blueVariationChanged(qreal arg);
-
- void rotationChanged(qreal arg);
-
- void rotationVariationChanged(qreal arg);
-
- void rotationSpeedChanged(qreal arg);
-
- void rotationSpeedVariationChanged(qreal arg);
-
- void autoRotationChanged(bool arg);
-
- void xVectorChanged(VaryingVector* arg);
-
- void yVectorChanged(VaryingVector* arg);
-
-public slots:
- void setAlphaVariation(qreal arg)
- {
- if (m_alphaVariation != arg) {
- m_alphaVariation = arg;
- emit alphaVariationChanged(arg);
- }
- }
-
- void setAlpha(qreal arg)
- {
- if (m_alpha != arg) {
- m_alpha = arg;
- emit alphaChanged(arg);
- }
- }
-
- void setRedVariation(qreal arg)
- {
- if (m_redVariation != arg) {
- m_redVariation = arg;
- emit redVariationChanged(arg);
- }
- }
-
- void setGreenVariation(qreal arg)
- {
- if (m_greenVariation != arg) {
- m_greenVariation = arg;
- emit greenVariationChanged(arg);
- }
- }
-
- void setBlueVariation(qreal arg)
- {
- if (m_blueVariation != arg) {
- m_blueVariation = arg;
- emit blueVariationChanged(arg);
- }
- }
-
- void reloadColor(const Color4ub &c, ParticleData* d);
- void setRotation(qreal arg)
- {
- if (m_rotation != arg) {
- m_rotation = arg;
- emit rotationChanged(arg);
- }
- }
-
- void setRotationVariation(qreal arg)
- {
- if (m_rotationVariation != arg) {
- m_rotationVariation = arg;
- emit rotationVariationChanged(arg);
- }
- }
-
- void setRotationSpeed(qreal arg)
- {
- if (m_rotationSpeed != arg) {
- m_rotationSpeed = arg;
- emit rotationSpeedChanged(arg);
- }
- }
-
- void setRotationSpeedVariation(qreal arg)
- {
- if (m_rotationSpeedVariation != arg) {
- m_rotationSpeedVariation = arg;
- emit rotationSpeedVariationChanged(arg);
- }
- }
-
- void autoRotation(bool arg)
- {
- if (m_autoRotation != arg) {
- m_autoRotation = arg;
- emit autoRotationChanged(arg);
- }
- }
-
- void setXVector(VaryingVector* arg)
- {
- if (m_xVector != arg) {
- m_xVector = arg;
- emit xVectorChanged(arg);
- }
- }
-
- void setYVector(VaryingVector* arg)
- {
- if (m_yVector != arg) {
- m_yVector = arg;
- emit yVectorChanged(arg);
- }
- }
-
-protected:
- QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
- void reset();
- void prepareNextFrame();
- QSGGeometryNode* buildParticleNode();
-private:
- void vertexCopy(SuperVertex &b,const ParticleVertex& a);
- bool m_do_reset;
-
- QUrl m_image_name;
- QUrl m_colortable_name;
- QUrl m_sizetable_name;
- QUrl m_opacitytable_name;
-
-
- QColor m_color;
- qreal m_color_variation;
- qreal m_particleDuration;
-
- QSGGeometryNode *m_node;
- SuperMaterial *m_material;
-
- // derived values...
- int m_last_particle;
-
- qreal m_render_opacity;
- qreal m_alphaVariation;
- qreal m_alpha;
- qreal m_redVariation;
- qreal m_greenVariation;
- qreal m_blueVariation;
- qreal m_rotation;
- qreal m_rotationVariation;
- qreal m_rotationSpeed;
- qreal m_rotationSpeedVariation;
- bool m_autoRotation;
- VaryingVector* m_xVector;
- VaryingVector* m_yVector;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // SUPERPARTICLE_H
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "swarmaffector.h"
-#include "particle.h"
-#include <cmath>
-#include <QDebug>
-QT_BEGIN_NAMESPACE
-
-SwarmAffector::SwarmAffector(QSGItem *parent) :
- ParticleAffector(parent), m_strength(1), m_inited(false)
-{
- connect(this, SIGNAL(leadersChanged(QStringList)),
- this, SLOT(updateGroupList()));
-}
-
-void SwarmAffector::ensureInit()
-{
- if(m_inited)
- return;
- m_inited = true;
- updateGroupList();
- m_lastPos.resize(m_system->count());
-}
-
-const qreal epsilon = 0.0000001;
-bool SwarmAffector::affectParticle(ParticleData *d, qreal dt)
-{
- ensureInit();
- QPointF curPos(d->curX(), d->curY());
- if(m_leaders.isEmpty() || m_leadGroups.contains(d->group)){
- m_lastPos[d->systemIndex] = curPos;
- if(m_leadGroups.contains(d->group))
- return false;
- }
-
- qreal fx = 0.0;
- qreal fy = 0.0;
- for(int i=0; i < m_lastPos.count(); i++){
- if(m_lastPos[i].isNull())
- continue;
- QPointF diff = m_lastPos[i] - curPos;
- qreal r = sqrt(diff.x() * diff.x() + diff.y() * diff.y());
- if(r == 0.0)
- continue;
- qreal f = m_strength * (1/r);
- if(f < epsilon)
- continue;
- qreal theta = atan2(diff.y(), diff.x());
- fx += cos(theta) * f;
- fy += sin(theta) * f;
- }
- if(!fx && !fy)
- return false;
- d->setInstantaneousSX(d->curSX()+fx * dt);
- d->setInstantaneousSY(d->curSY()+fy * dt);
- return true;
-}
-
-void SwarmAffector::reset(int systemIdx)
-{
- if(!m_system)
- return;
- if(!m_lastPos[systemIdx].isNull())
- m_lastPos[systemIdx] = QPointF();
-}
-
-void SwarmAffector::updateGroupList()
-{
- if(!m_system || !m_system->m_initialized)
- return;
- m_leadGroups.clear();
- foreach(const QString &s, m_leaders)
- m_leadGroups << m_system->m_groupIds[s];
-}
-QT_END_NAMESPACE
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef SWARMAFFECTOR_H
-#define SWARMAFFECTOR_H
-#include "particleaffector.h"
-#include <QDeclarativeListProperty>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-
-class ParticleType;
-
-class SwarmAffector : public ParticleAffector
-{
- Q_OBJECT
- Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged)
- Q_PROPERTY(QStringList leaders READ leaders WRITE setLeaders NOTIFY leadersChanged)
-public:
- explicit SwarmAffector(QSGItem *parent = 0);
- virtual bool affectParticle(ParticleData *d, qreal dt);
- virtual void reset(int systemIdx);
-
- qreal strength() const
- {
- return m_strength;
- }
-
- QStringList leaders() const
- {
- return m_leaders;
- }
-
-signals:
-
- void strengthChanged(qreal arg);
-
- void leadersChanged(QStringList arg);
-
-public slots:
-
-void setStrength(qreal arg)
-{
- if (m_strength != arg) {
- m_strength = arg;
- emit strengthChanged(arg);
- }
-}
-
-void setLeaders(QStringList arg)
-{
- if (m_leaders != arg) {
- m_leaders = arg;
- emit leadersChanged(arg);
- }
-}
-
-private:
- void ensureInit();
- void mapUpdate(int idx, qreal strength);
- QVector<QPointF> m_lastPos;
- qreal m_strength;
- bool m_inited;
- QStringList m_leaders;
- QSet<int> m_leadGroups;
-private slots:
- void updateGroupList();
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // SWARMAFFECTOR_H
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "toggleaffector.h"
-
-QT_BEGIN_NAMESPACE
-
-ToggleAffector::ToggleAffector(QObject *parent) :
- ParticleAffector(parent)
-{
-}
-
-bool ToggleAffector::affect(ParticleData *d, qreal dt)
-{
- if(m_affecting)
- return m_affector->affect(d, dt);
- else
- return false;
-}
-
-QT_END_NAMESPACE
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef TOGGLEAFFECTOR_H
-#define TOGGLEAFFECTOR_H
-#include "particleaffector.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class ToggleAffector : public ParticleAffector
-{
- Q_OBJECT
- Q_PROPERTY(bool affecting READ affecting WRITE setAffecting NOTIFY affectingChanged)
- Q_PROPERTY(ParticleAffector* affector READ affector WRITE affector NOTIFY affectorChanged)
- Q_CLASSINFO("DefaultProperty", "affector")
-
-public:
- explicit ToggleAffector(QObject *parent = 0);
- virtual bool affect(ParticleData *d, qreal dt);
- bool affecting() const
- {
- return m_affecting;
- }
-
- ParticleAffector* affector() const
- {
- return m_affector;
- }
-
-signals:
-
- void affectingChanged(bool arg);
-
- void affectorChanged(ParticleAffector* arg);
-
-public slots:
-void setAffecting(bool arg)
-{
- if (m_affecting != arg) {
- m_affecting = arg;
- emit affectingChanged(arg);
- }
-}
-
-void affector(ParticleAffector* arg)
-{
- if (m_affector != arg) {
- m_affector = arg;
- emit affectorChanged(arg);
- }
-}
-
-private:
-bool m_affecting;
-ParticleAffector* m_affector;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // TOGGLEAFFECTOR_H
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "zoneaffector.h"
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-ZoneAffector::ZoneAffector(QObject *parent) :
- ParticleAffector(parent), m_x(0), m_y(0), m_width(0), m_height(0), m_affector(0)
-{
-}
-
-bool ZoneAffector::affect(ParticleData *d, qreal dt)
-{
- if(!m_affector)
- return false;
- qreal x = d->curX();
- qreal y = d->curY();
- if(x >= m_x && x <= m_x+m_width && y >= m_y && y <= m_y+m_height)
- return m_affector->affect(d, dt);
- return false;
-}
-
-void ZoneAffector::reset(int systemIdx)
-{
- if(m_affector)
- m_affector->reset(systemIdx);
-}
-QT_END_NAMESPACE
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef ZONEAFFECTOR_H
-#define ZONEAFFECTOR_H
-#include "particleaffector.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class ZoneAffector : public ParticleAffector
-{
- Q_OBJECT
- //TODO: Can we get anchors in here? consider becoming an un-parented QSGItem?
- Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged);
- Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged);
- Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged);
- Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged);
- Q_PROPERTY(ParticleAffector* affector READ affector WRITE affector NOTIFY affectorChanged)
- Q_CLASSINFO("DefaultProperty", "affector")
-public:
- explicit ZoneAffector(QObject *parent = 0);
-
- virtual bool affect(ParticleData *d, qreal dt);
- virtual void reset(int systemIdx);
-
- ParticleAffector* affector() const
- {
- return m_affector;
- }
-
- qreal x() const
- {
- return m_x;
- }
-
- qreal y() const
- {
- return m_y;
- }
-
- qreal width() const
- {
- return m_width;
- }
-
- qreal height() const
- {
- return m_height;
- }
-
-signals:
-
-
- void affectorChanged(ParticleAffector* arg);
-
- void xChanged(qreal arg);
-
- void yChanged(qreal arg);
-
- void widthChanged(qreal arg);
-
- void heightChanged(qreal arg);
-
-public slots:
-
-
-void affector(ParticleAffector* arg)
-{
- if (m_affector != arg) {
- m_affector = arg;
- emit affectorChanged(arg);
- }
-}
-
-void setX(qreal arg)
-{
- if (m_x != arg) {
- m_x = arg;
- emit xChanged(arg);
- }
-}
-
-void setY(qreal arg)
-{
- if (m_y != arg) {
- m_y = arg;
- emit yChanged(arg);
- }
-}
-
-void setWidth(qreal arg)
-{
- if (m_width != arg) {
- m_width = arg;
- emit widthChanged(arg);
- }
-}
-
-void setHeight(qreal arg)
-{
- if (m_height != arg) {
- m_height = arg;
- emit heightChanged(arg);
- }
-}
-
-private:
-qreal m_x;
-qreal m_y;
-qreal m_width;
-qreal m_height;
-ParticleAffector* m_affector;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // ZONEAFFECTOR_H