Ticket #1922: ParticleUpdates.patch

File ParticleUpdates.patch, 6.8 KB (added by wraitii, 11 years ago)
  • binaries/data/mods/public/art/particles/smoke_light.xml

     
    55    <blend mode="over"/>
    66
    77    <start_full/>
     8    <use_relative_velocity/>
    89
    9     <constant name="emissionrate" value="5.0"/>
     10    <constant name="emissionrate" value="2.0"/>
    1011    <uniform name="lifetime" min="30.0" max="35.0"/>
    1112
    1213    <constant name="position.y" value="2.0"/>
     
    1415    <uniform name="angle" min="-2.0" max="2.0"/>
    1516
    1617    <uniform name="velocity.x" min="-0.3" max="0.3"/>
    17     <uniform name="velocity.y" min="1.5" max="2.0"/>
     18    <uniform name="velocity.y" min="0.5" max="1.2"/>
    1819    <uniform name="velocity.z" min="-0.5" max="0.5"/>
    1920    <uniform name="velocity.angle" min="-2.0" max="2.0"/>
    2021
    21     <uniform name="size" min="3.0" max="4.5"/>
     22    <uniform name="size" min="1.0" max="1.5"/>
     23    <uniform name="size.growth" min="1.0" max="1.5"/>
    2224
    2325    <uniform name="color.r" min="0.6" max="1.0"/>
    2426    <copy name="color.g" from="color.r"/>
    2527    <copy name="color.b" from="color.r"/>
    2628
     29    <force y="0.2"/>
     30    <force x="0.04"/>
     31    <force z="0.04"/>
    2732</particles>
  • source/graphics/ParticleEmitterType.cpp

     
    325325    if (name == "velocity.z")   return VAR_VELOCITY_Z;
    326326    if (name == "velocity.angle")   return VAR_VELOCITY_ANGLE;
    327327    if (name == "size")         return VAR_SIZE;
     328    if (name == "size.growth")          return VAR_SIZE_GROWTH;
    328329    if (name == "color.r")      return VAR_COLOR_R;
    329330    if (name == "color.g")      return VAR_COLOR_G;
    330331    if (name == "color.b")      return VAR_COLOR_B;
     
    348349    m_Variables[VAR_VELOCITY_Z] = IParticleVarPtr(new CParticleVarConstant(0.f));
    349350    m_Variables[VAR_VELOCITY_ANGLE] = IParticleVarPtr(new CParticleVarConstant(0.f));
    350351    m_Variables[VAR_SIZE] = IParticleVarPtr(new CParticleVarConstant(1.f));
     352    m_Variables[VAR_SIZE_GROWTH] = IParticleVarPtr(new CParticleVarConstant(0.f));
    351353    m_Variables[VAR_COLOR_R] = IParticleVarPtr(new CParticleVarConstant(1.f));
    352354    m_Variables[VAR_COLOR_G] = IParticleVarPtr(new CParticleVarConstant(1.f));
    353355    m_Variables[VAR_COLOR_B] = IParticleVarPtr(new CParticleVarConstant(1.f));
     
    355357    m_BlendFuncSrc = GL_SRC_ALPHA;
    356358    m_BlendFuncDst = GL_ONE_MINUS_SRC_ALPHA;
    357359    m_StartFull = false;
     360    m_UseRelativeVelocity = false;
    358361    m_Texture = g_Renderer.GetTextureManager().GetErrorTexture();
    359362
    360363    CXeromyces XeroFile;
     
    370373    EL(texture);
    371374    EL(blend);
    372375    EL(start_full);
     376    EL(use_relative_velocity);
    373377    EL(constant);
    374378    EL(uniform);
    375379    EL(copy);
     
    430434        {
    431435            m_StartFull = true;
    432436        }
     437        else if (Child.GetNodeName() == el_use_relative_velocity)
     438        {
     439            m_UseRelativeVelocity = true;
     440        }
    433441        else if (Child.GetNodeName() == el_constant)
    434442        {
    435443            int id = GetVariableID(Child.GetAttributes().GetNamedItem(at_name));
     
    530538            particle.pos.Z = m_Variables[VAR_POSITION_Z]->Evaluate(emitter);
    531539            particle.pos += emitter.m_Pos;
    532540
    533             particle.velocity.X = m_Variables[VAR_VELOCITY_X]->Evaluate(emitter);
    534             particle.velocity.Y = m_Variables[VAR_VELOCITY_Y]->Evaluate(emitter);
    535             particle.velocity.Z = m_Variables[VAR_VELOCITY_Z]->Evaluate(emitter);
    536 
     541            if (m_UseRelativeVelocity)
     542            {
     543                float xVel = m_Variables[VAR_VELOCITY_X]->Evaluate(emitter);
     544                float yVel = m_Variables[VAR_VELOCITY_Y]->Evaluate(emitter);
     545                float zVel = m_Variables[VAR_VELOCITY_Z]->Evaluate(emitter);
     546                CVector3D EmitterAngle = emitter.GetRotation().ToMatrix().Transform(CVector3D(xVel,yVel,zVel));
     547                particle.velocity.X = EmitterAngle.X;
     548                particle.velocity.Y = EmitterAngle.Y;
     549                particle.velocity.Z = EmitterAngle.Z;
     550            } else {
     551                particle.velocity.X = m_Variables[VAR_VELOCITY_X]->Evaluate(emitter);
     552                particle.velocity.Y = m_Variables[VAR_VELOCITY_Y]->Evaluate(emitter);
     553                particle.velocity.Z = m_Variables[VAR_VELOCITY_Z]->Evaluate(emitter);
     554            }
    537555            particle.angle = m_Variables[VAR_ANGLE]->Evaluate(emitter);
    538556            particle.angleSpeed = m_Variables[VAR_VELOCITY_ANGLE]->Evaluate(emitter);
    539557
    540558            particle.size = m_Variables[VAR_SIZE]->Evaluate(emitter);
     559            particle.sizeGrowth = m_Variables[VAR_SIZE_GROWTH]->Evaluate(emitter);
    541560
    542561            RGBColor color;
    543562            color.X = m_Variables[VAR_COLOR_R]->Evaluate(emitter);
     
    564583        p.pos += p.velocity * dt;
    565584        p.angle += p.angleSpeed * dt;
    566585        p.age += dt;
     586        p.size += p.sizeGrowth * dt;
    567587
    568588        // Make alpha fade in/out nicely
    569589        // TODO: this should probably be done as a variable or something,
  • source/graphics/ParticleEmitter.cpp

     
    277277void CModelParticleEmitter::SetTransform(const CMatrix3D& transform)
    278278{
    279279    m_Emitter->SetPosition(transform.GetTranslation());
     280    m_Emitter->SetRotation(transform.GetRotation());
    280281}
  • source/graphics/ParticleEmitterType.h

     
    6767        VAR_VELOCITY_Z,
    6868        VAR_VELOCITY_ANGLE,
    6969        VAR_SIZE,
     70        VAR_SIZE_GROWTH,
    7071        VAR_COLOR_R,
    7172        VAR_COLOR_G,
    7273        VAR_COLOR_B,
     
    9697    GLenum m_BlendFuncSrc;
    9798    GLenum m_BlendFuncDst;
    9899    bool m_StartFull;
    99 
     100    bool m_UseRelativeVelocity;
     101   
    100102    float m_MaxLifetime;
    101103    size_t m_MaxParticles;
    102104    CBoundingBoxAligned m_MaxBounds;
  • source/graphics/ParticleEmitter.h

     
    2121#include "graphics/ModelAbstract.h"
    2222#include "graphics/ParticleEmitterType.h"
    2323#include "graphics/Texture.h"
     24#include "maths/Quaternion.h"
    2425#include "renderer/VertexArray.h"
    2526
    2627#include <map>
     
    3536    float angle;
    3637    float angleSpeed;
    3738    float size;
     39    float sizeGrowth;
    3840    SColor4ub color;
    3941    float age;
    4042    float maxAge;
     
    8183    }
    8284
    8385    /**
     86     * Set the rotation to be used for emission of new particles (note: depends on particles).
     87     */
     88    void SetRotation(const CQuaternion& rot)
     89    {
     90        m_Rot = rot;
     91    }
     92   
     93    CQuaternion GetRotation() const
     94    {
     95        return m_Rot;
     96    }
     97   
     98
     99    /**
    84100     * Get the bounding box of the center points of particles at their current positions.
    85101     */
    86102    CBoundingBoxAligned GetParticleBounds() { return m_ParticleBounds; }
     
    122138    bool m_Active;
    123139
    124140    CVector3D m_Pos;
     141    CQuaternion m_Rot;
    125142
    126143    std::map<std::string, float> m_EntityVariables;
    127144