From: Alan Alpert Date: Wed, 27 Apr 2011 05:40:20 +0000 (+1000) Subject: Add variable rotation speed to deformable particle X-Git-Tag: qt-v5.0.0-alpha1~2170^2~180 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=31dd5d55dd79318512e9efc13cb447553accd32d;p=profile%2Fivi%2Fqtdeclarative.git Add variable rotation speed to deformable particle Change-Id: I105f18f0d7ec860de5d8bc8a9f3e4f007ea71ae2 (cherry picked from commit 41296b3ed046ddf73eca320bf0a97008decca287) --- diff --git a/src/imports/particles/deformableparticle.cpp b/src/imports/particles/deformableparticle.cpp index 2043e12..69de693 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 21982d1..0de6d82 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 1ea7f22..0157095 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); }