-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #102 add Cylinder, line, ring zone
- Loading branch information
1 parent
51171a2
commit 8793b08
Showing
12 changed files
with
538 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
Projects/Skylicht/Components/Source/ParticleSystem/Particles/Zones/CCylinder.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
!@ | ||
MIT License | ||
Copyright (c) 2020 Skylicht Technology CO., LTD | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files | ||
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, | ||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
This file is part of the "Skylicht Engine". | ||
https://github.com/skylicht-lab/skylicht-engine | ||
!# | ||
*/ | ||
|
||
#include "pch.h" | ||
#include "CCylinder.h" | ||
#include "ParticleSystem/Particles/CParticle.h" | ||
|
||
namespace Skylicht | ||
{ | ||
namespace Particle | ||
{ | ||
CCylinder::CCylinder(const core::vector3df& position, | ||
const core::vector3df& direction, | ||
float radius, | ||
float length) : | ||
CZone(Cylinder), | ||
m_position(position), | ||
m_direction(direction), | ||
m_radius(radius), | ||
m_length(length) | ||
{ | ||
m_direction.normalize(); | ||
} | ||
|
||
CCylinder::~CCylinder() | ||
{ | ||
|
||
} | ||
|
||
void CCylinder::generatePosition(CParticle& particle, bool full) | ||
{ | ||
float cLength = random(0.0f, m_length) - m_length * 0.5f; | ||
float cAngle = random(0.0f, 2 * core::PI); | ||
float cRadius = full ? random(0.0f, m_radius) : m_radius; | ||
|
||
core::vector3df pos = getTransformPosition(m_position); | ||
core::vector3df dir = getTransformVector(m_direction); | ||
|
||
// We need at least two points to compute a base | ||
core::vector3df rPoint = pos + core::vector3df(10.0f, 10.0f, 10.0f); | ||
float dist = dir.dotProduct(rPoint); | ||
|
||
while (dist == 0.0f || dir * dist + pos == rPoint) | ||
{ | ||
// avoid dist == 0, which leads to a div by zero. | ||
rPoint += core::vector3df(10.0f, 10.0f, random(-10.0f, 10.0f)); | ||
dist = dir.dotProduct(rPoint); | ||
} | ||
|
||
core::vector3df p1 = dir * dist + pos; | ||
dist = p1.getDistanceFrom(rPoint); | ||
|
||
core::vector3df a = (rPoint - p1) / dist; | ||
core::vector3df tmp1 = dir, tmp2 = a; tmp2 = tmp2.crossProduct(tmp1*(-1)); | ||
core::vector3df b = tmp2; | ||
|
||
particle.Position = pos + cLength * dir + a * cRadius * cosf(cAngle) + b * cRadius * sinf(cAngle); | ||
} | ||
|
||
core::vector3df CCylinder::computeNormal(const core::vector3df& point) | ||
{ | ||
core::vector3df pos = getTransformPosition(m_position); | ||
core::vector3df dir = getTransformVector(m_direction); | ||
|
||
float dist = dir.dotProduct(point - pos); | ||
|
||
if (dist >= m_length * 0.5f) | ||
return dir; | ||
|
||
if (dist <= -m_length * 0.5f) | ||
return -dir; | ||
|
||
core::vector3df ext = point - (dir*dist + pos); | ||
ext.normalize(); | ||
|
||
return ext; | ||
} | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
Projects/Skylicht/Components/Source/ParticleSystem/Particles/Zones/CCylinder.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
!@ | ||
MIT License | ||
Copyright (c) 2020 Skylicht Technology CO., LTD | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files | ||
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, | ||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
This file is part of the "Skylicht Engine". | ||
https://github.com/skylicht-lab/skylicht-engine | ||
!# | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "CZone.h" | ||
|
||
namespace Skylicht | ||
{ | ||
namespace Particle | ||
{ | ||
class CCylinder : public CZone | ||
{ | ||
protected: | ||
core::vector3df m_position; | ||
core::vector3df m_direction; | ||
float m_radius; | ||
float m_length; | ||
|
||
public: | ||
CCylinder(const core::vector3df& position, | ||
const core::vector3df& direction, | ||
float radius, | ||
float length); | ||
|
||
virtual ~CCylinder(); | ||
|
||
inline void setPosition(const core::vector3df& pos) | ||
{ | ||
m_position = pos; | ||
} | ||
|
||
inline void setDirection(const core::vector3df& direction) | ||
{ | ||
m_direction = direction; | ||
m_direction.normalize(); | ||
} | ||
|
||
inline void setRadius(float r) | ||
{ | ||
m_radius = r; | ||
} | ||
|
||
inline void setLength(float l) | ||
{ | ||
m_length = l; | ||
} | ||
|
||
inline const core::vector3df& getPosition() | ||
{ | ||
return m_position; | ||
} | ||
|
||
inline const core::vector3df& getDirection() | ||
{ | ||
return m_direction; | ||
} | ||
|
||
inline float getRadius() | ||
{ | ||
return m_radius; | ||
} | ||
|
||
inline float getLength() | ||
{ | ||
return m_length; | ||
} | ||
|
||
virtual void generatePosition(CParticle& particle, bool full); | ||
|
||
virtual core::vector3df computeNormal(const core::vector3df& point); | ||
}; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
Projects/Skylicht/Components/Source/ParticleSystem/Particles/Zones/CLine.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
!@ | ||
MIT License | ||
Copyright (c) 2020 Skylicht Technology CO., LTD | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files | ||
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, | ||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
This file is part of the "Skylicht Engine". | ||
https://github.com/skylicht-lab/skylicht-engine | ||
!# | ||
*/ | ||
|
||
#include "pch.h" | ||
#include "CLine.h" | ||
#include "ParticleSystem/Particles/CParticle.h" | ||
|
||
namespace Skylicht | ||
{ | ||
namespace Particle | ||
{ | ||
CLine::CLine(const core::vector3df& p1, const core::vector3df& p2) : | ||
CZone(Line) | ||
{ | ||
setLine(p1, p2); | ||
} | ||
|
||
CLine::~CLine() | ||
{ | ||
|
||
} | ||
|
||
void CLine::setLine(const core::vector3df& p1, const core::vector3df& p2) | ||
{ | ||
m_p1 = p1; | ||
m_p2 = p2; | ||
} | ||
|
||
void CLine::generatePosition(CParticle& particle, bool full) | ||
{ | ||
core::vector3df pos = getTransformPosition(m_p1); | ||
core::vector3df direction = getTransformPosition(m_p2) - pos; | ||
|
||
float ratio = random(0.0f, 1.0f); | ||
particle.Position = pos + direction * ratio; | ||
} | ||
|
||
core::vector3df CLine::computeNormal(const core::vector3df& point) | ||
{ | ||
core::vector3df pos = getTransformPosition(m_p1); | ||
core::vector3df direction = getTransformPosition(m_p2) - pos; | ||
|
||
float d = -direction.dotProduct(point); | ||
float sqrNorm = direction.getLengthSQ(); | ||
float t = 0.0f; | ||
if (sqrNorm > 0.0f) | ||
{ | ||
t = -(direction.dotProduct(pos) + d) / sqrNorm; | ||
|
||
// t is clamped to the segment | ||
if (t < 0.0f) | ||
t = 0.0f; | ||
else if (t > 1.0f) | ||
t = 1.0f; | ||
} | ||
|
||
core::vector3df normal = point; | ||
normal -= pos + t * direction; | ||
normal.normalize(); | ||
|
||
return normal; | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Projects/Skylicht/Components/Source/ParticleSystem/Particles/Zones/CLine.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
!@ | ||
MIT License | ||
Copyright (c) 2020 Skylicht Technology CO., LTD | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files | ||
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, | ||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
This file is part of the "Skylicht Engine". | ||
https://github.com/skylicht-lab/skylicht-engine | ||
!# | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "CZone.h" | ||
|
||
namespace Skylicht | ||
{ | ||
namespace Particle | ||
{ | ||
class CLine : public CZone | ||
{ | ||
protected: | ||
core::vector3df m_p1; | ||
core::vector3df m_p2; | ||
|
||
public: | ||
CLine(const core::vector3df& p1, const core::vector3df& p2); | ||
|
||
virtual ~CLine(); | ||
|
||
void setLine(const core::vector3df& p1, const core::vector3df& p2); | ||
|
||
virtual void generatePosition(CParticle& particle, bool full); | ||
|
||
virtual core::vector3df computeNormal(const core::vector3df& point); | ||
}; | ||
} | ||
} |
Oops, something went wrong.