diff --git a/Projects/Skylicht/Components/Source/ParticleSystem/Particles/CParticleTrail.cpp b/Projects/Skylicht/Components/Source/ParticleSystem/Particles/CParticleTrail.cpp index 9015c16ae..2c6d66d93 100644 --- a/Projects/Skylicht/Components/Source/ParticleSystem/Particles/CParticleTrail.cpp +++ b/Projects/Skylicht/Components/Source/ParticleSystem/Particles/CParticleTrail.cpp @@ -36,8 +36,10 @@ namespace Skylicht m_width(0.1f), m_alpha(1.0f), m_trailCount(0), - m_maxSegmentCount(10) + m_maxSegmentCount(0) { + setLength(2.0f); + group->setCallback(this); m_meshBuffer = new CMeshBuffer(getVideoDriver()->getVertexDescriptor(EVT_STANDARD), EIT_32BIT); @@ -61,6 +63,12 @@ namespace Skylicht m_meshBuffer->drop(); } + void CParticleTrail::setLength(float l) + { + m_maxSegmentCount = (int)(l / m_segmentLength + 1.0f); + m_length = l; + } + void CParticleTrail::update(CCamera *camera) { if (m_group == NULL) @@ -99,6 +107,8 @@ namespace Skylicht endSeg = (int)(numSeg - m_maxSegmentCount + 1); u32 numSegDraw = 0; + float currentLength = 0.0f; + for (int i = numSeg; i >= endSeg; i--) { core::vector3df pos1; @@ -127,10 +137,20 @@ namespace Skylicht thickness = p1.Width; } - // line direction + // direction core::vector3df direction = pos1 - pos2; + + // length + currentLength = currentLength + direction.getLength(); + direction.normalize(); + if (currentLength > m_length) + { + float cutLength = currentLength - m_length; + pos2 = pos2 + cutLength * direction; + } + // look core::vector3df lookdir = pos1 - campos; if (lookdir.getLength() < 0.2f) @@ -191,6 +211,10 @@ namespace Skylicht totalSegDraw++; numSegDraw++; + + // skip + if (currentLength >= m_length) + break; } } } diff --git a/Projects/Skylicht/Components/Source/ParticleSystem/Particles/CParticleTrail.h b/Projects/Skylicht/Components/Source/ParticleSystem/Particles/CParticleTrail.h index 896dfe437..4f035dbdf 100644 --- a/Projects/Skylicht/Components/Source/ParticleSystem/Particles/CParticleTrail.h +++ b/Projects/Skylicht/Components/Source/ParticleSystem/Particles/CParticleTrail.h @@ -71,6 +71,8 @@ namespace Skylicht float m_width; + float m_length; + float m_alpha; int m_trailCount; @@ -96,6 +98,28 @@ namespace Skylicht { return m_meshBuffer; } + + inline void setWidth(float f) + { + m_width = f; + } + + inline float getWidth() + { + return m_width; + } + + inline void setSegmentLength(float f) + { + m_segmentLength = f; + } + + inline float getSegmentLength() + { + return m_segmentLength; + } + + void setLength(float l); }; } } \ No newline at end of file