Skip to content

Commit

Permalink
feat: #102 Update length of trail
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Sep 16, 2020
1 parent 11b8b4a commit 5709290
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<video::S3DVertex>(getVideoDriver()->getVertexDescriptor(EVT_STANDARD), EIT_32BIT);
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -191,6 +211,10 @@ namespace Skylicht

totalSegDraw++;
numSegDraw++;

// skip
if (currentLength >= m_length)
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ namespace Skylicht

float m_width;

float m_length;

float m_alpha;

int m_trailCount;
Expand All @@ -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);
};
}
}

0 comments on commit 5709290

Please sign in to comment.