aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2011-04-27 15:40:20 +1000
committerAlan Alpert <alan.alpert@nokia.com>2011-04-28 09:52:11 +1000
commit31dd5d55dd79318512e9efc13cb447553accd32d (patch)
treedf1517c354c72a5801629ed67e51b9161e661dc5 /src/imports
parent40b6a270a1f3b4c0bfb2d35cb96c4f929a7802ad (diff)
Add variable rotation speed to deformable particle
Change-Id: I105f18f0d7ec860de5d8bc8a9f3e4f007ea71ae2 (cherry picked from commit 41296b3ed046ddf73eca320bf0a97008decca287)
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/particles/deformableparticle.cpp10
-rw-r--r--src/imports/particles/deformableparticle.h35
-rw-r--r--src/imports/particles/resources/deformablevertex.shader6
3 files changed, 45 insertions, 6 deletions
diff --git a/src/imports/particles/deformableparticle.cpp b/src/imports/particles/deformableparticle.cpp
index 2043e12be9..69de693f09 100644
--- a/src/imports/particles/deformableparticle.cpp
+++ b/src/imports/particles/deformableparticle.cpp
@@ -176,6 +176,7 @@ struct DeformableParticleVertex {
float yx;
float yy;
float rotation;
+ float rotationSpeed;
float autoRotate;//Assume that GPUs prefer floats to bools
};
@@ -195,6 +196,8 @@ DeformableParticle::DeformableParticle(QSGItem* parent)
, m_xVector(0)
, m_yVector(0)
, m_rotationVariation(0)
+ , m_rotationSpeed(0)
+ , m_rotationSpeedVariation(0)
{
setFlag(ItemHasContents);
}
@@ -226,13 +229,13 @@ static QSGGeometry::Attribute DeformableParticle_Attributes[] = {
{ 2, 4, GL_FLOAT }, // Data
{ 3, 4, GL_FLOAT }, // Vectors
{ 4, 4, GL_FLOAT }, // DeformationVectors
- { 5, 2, GL_FLOAT } // Rotation
+ { 5, 3, GL_FLOAT } // Rotation
};
static QSGGeometry::AttributeSet DeformableParticle_AttributeSet =
{
6, // Attribute Count
- (2 + 2 + 4 + 4 + 4 + 2) * sizeof(float),
+ (2 + 2 + 4 + 4 + 4 + 3) * sizeof(float),
DeformableParticle_Attributes
};
@@ -279,6 +282,7 @@ QSGGeometryNode* DeformableParticle::buildParticleNode()
vertices[i].yx = 0;
vertices[i].yy = 1;
vertices[i].rotation = 0;
+ vertices[i].rotationSpeed = 0;
vertices[i].autoRotate = 0;
}
@@ -421,6 +425,8 @@ void DeformableParticle::load(ParticleData *d)
}
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);
diff --git a/src/imports/particles/deformableparticle.h b/src/imports/particles/deformableparticle.h
index 21982d14da..0de6d8228a 100644
--- a/src/imports/particles/deformableparticle.h
+++ b/src/imports/particles/deformableparticle.h
@@ -62,11 +62,12 @@ class DeformableParticle : public ParticleType
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)
- //###Ought to be vectors, not points. Varying Vectors even?
//###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)
@@ -118,6 +119,16 @@ public:
return m_rotationVariation;
}
+ qreal rotationSpeed() const
+ {
+ return m_rotationSpeed;
+ }
+
+ qreal rotationSpeedVariation() const
+ {
+ return m_rotationSpeedVariation;
+ }
+
signals:
void imageChanged();
@@ -131,6 +142,10 @@ signals:
void rotationVariationChanged(qreal arg);
+ void rotationSpeedChanged(qreal arg);
+
+ void rotationSpeedVariationChanged(qreal arg);
+
public slots:
void setRotation(qreal arg)
{
@@ -172,6 +187,22 @@ void setRotationVariation(qreal 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();
@@ -195,6 +226,8 @@ private:
VaryingVector* m_xVector;
VaryingVector* m_yVector;
qreal m_rotationVariation;
+ qreal m_rotationSpeed;
+ qreal m_rotationSpeedVariation;
};
QT_END_NAMESPACE
diff --git a/src/imports/particles/resources/deformablevertex.shader b/src/imports/particles/resources/deformablevertex.shader
index 1ea7f22046..01570950b1 100644
--- a/src/imports/particles/resources/deformablevertex.shader
+++ b/src/imports/particles/resources/deformablevertex.shader
@@ -3,7 +3,7 @@ attribute highp vec2 vTex;
attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize
attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration
attribute highp vec4 vDeformVec; //x,y x unit vector; z,w = y unit vector
-attribute highp vec2 vRotation; //x = radians of rotation, y= bool autoRotate
+attribute highp vec3 vRotation; //x = radians of rotation, y=rotation speed, z= bool autoRotate
uniform highp mat4 matrix;
uniform highp float timestamp;
@@ -26,8 +26,8 @@ void main() {
currentSize = 0.;
pos = vPos;
}else{
- highp float rotation = vRotation.x;
- if(vRotation.y == 1.0){
+ highp float rotation = vRotation.x + vRotation.y * t * vData.y;
+ if(vRotation.z == 1.0){
highp vec2 curVel = vVec.zw * t * vData.y + vVec.xy;
rotation += atan(curVel.y, curVel.x);
}