add sparkle explosions
This commit is contained in:
146
libs/spark/include/Extensions/Emitters/SPK_NormalEmitter.h
Normal file
146
libs/spark/include/Extensions/Emitters/SPK_NormalEmitter.h
Normal file
@ -0,0 +1,146 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// SPARK particle engine //
|
||||
// Copyright (C) 2008-2009 - Julien Fryer - julienfryer@gmail.com //
|
||||
// //
|
||||
// This software is provided 'as-is', without any express or implied //
|
||||
// warranty. In no event will the authors be held liable for any damages //
|
||||
// arising from the use of this software. //
|
||||
// //
|
||||
// Permission is granted to anyone to use this software for any purpose, //
|
||||
// including commercial applications, and to alter it and redistribute it //
|
||||
// freely, subject to the following restrictions: //
|
||||
// //
|
||||
// 1. The origin of this software must not be misrepresented; you must not //
|
||||
// claim that you wrote the original software. If you use this software //
|
||||
// in a product, an acknowledgment in the product documentation would be //
|
||||
// appreciated but is not required. //
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be //
|
||||
// misrepresented as being the original software. //
|
||||
// 3. This notice may not be removed or altered from any source distribution. //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef H_SPK_NORMALEMITTER
|
||||
#define H_SPK_NORMALEMITTER
|
||||
|
||||
#include "Core/SPK_Emitter.h"
|
||||
|
||||
|
||||
namespace SPK
|
||||
{
|
||||
/**
|
||||
* @class NormalEmitter
|
||||
* @brief An Emitter that emits particles following a Zone normals
|
||||
*
|
||||
* The Zone used to derive the direction of emission can either be the Emitter Zone
|
||||
* or another Zone that can be set with setNormalZone(Zone*).<br>
|
||||
* If the normal zone is NULL the emitter Zone is used.
|
||||
*
|
||||
* @since 1.02.00
|
||||
*/
|
||||
class SPK_PREFIX NormalEmitter : public Emitter
|
||||
{
|
||||
SPK_IMPLEMENT_REGISTERABLE(NormalEmitter)
|
||||
|
||||
public :
|
||||
|
||||
//////////////////
|
||||
// Constructors //
|
||||
//////////////////
|
||||
|
||||
/**
|
||||
* @brief Constructor of NormalEmitter
|
||||
* @param normalZone : the Zone used to compute normals (NULL to used the Emitter Zone)
|
||||
* @param inverted : true to invert the normals, false otherwise
|
||||
*/
|
||||
NormalEmitter(Zone* normalZone = NULL,bool inverted = false);
|
||||
|
||||
/**
|
||||
* @brief Creates and registers a new NormalEmitter
|
||||
* @param normalZone : the Zone used to compute normals (NULL to used the Emitter Zone)
|
||||
* @param inverted : true to invert the normals, false otherwise
|
||||
* @return A new registered NormalEmitter
|
||||
* @since 1.04.00
|
||||
*/
|
||||
static inline NormalEmitter* create(Zone* normalZone = NULL,bool inverted = false);
|
||||
|
||||
/////////////
|
||||
// Setters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Sets whether normals are inverted or not
|
||||
* @param inverted true to use inverted normals, false not to
|
||||
*/
|
||||
inline void setInverted(bool inverted);
|
||||
|
||||
/**
|
||||
* @brief the Zone used to compute normals
|
||||
*
|
||||
* Note that if the normal zone is NULL, the Emitter Zone is used.
|
||||
*
|
||||
* @param zone : the Zone used to compute normals (NULL to used the Emitter Zone)
|
||||
*/
|
||||
void setNormalZone(Zone* zone);
|
||||
|
||||
/////////////
|
||||
// Getters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Tells whether normals are inverted for this NormalEmitter
|
||||
* @return true if normals are inverted, false if not
|
||||
*/
|
||||
inline bool isInverted() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the normal Zone of this NormalEmitter
|
||||
* @return the normal Zone of this NormalEmitter
|
||||
*/
|
||||
inline Zone* getNormalZone() const;
|
||||
|
||||
///////////////
|
||||
// Interface //
|
||||
///////////////
|
||||
|
||||
virtual Registerable* findByName(const std::string& name);
|
||||
|
||||
protected :
|
||||
|
||||
virtual void registerChildren(bool registerAll);
|
||||
virtual void copyChildren(const NormalEmitter& emitter,bool createBase);
|
||||
virtual void destroyChildren(bool keepChildren);
|
||||
|
||||
private :
|
||||
|
||||
bool inverted;
|
||||
Zone* normalZone;
|
||||
|
||||
virtual void generateVelocity(Particle& particle,float speed) const;
|
||||
};
|
||||
|
||||
|
||||
inline NormalEmitter* NormalEmitter::create(Zone* normalZone,bool inverted)
|
||||
{
|
||||
NormalEmitter* obj = new NormalEmitter(normalZone,inverted);
|
||||
registerObject(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
inline void NormalEmitter::setInverted(bool inverted)
|
||||
{
|
||||
this->inverted = inverted;
|
||||
}
|
||||
|
||||
inline bool NormalEmitter::isInverted() const
|
||||
{
|
||||
return inverted;
|
||||
}
|
||||
|
||||
inline Zone* NormalEmitter::getNormalZone() const
|
||||
{
|
||||
return normalZone;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
63
libs/spark/include/Extensions/Emitters/SPK_RandomEmitter.h
Normal file
63
libs/spark/include/Extensions/Emitters/SPK_RandomEmitter.h
Normal file
@ -0,0 +1,63 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// SPARK particle engine //
|
||||
// Copyright (C) 2008-2009 - Julien Fryer - julienfryer@gmail.com //
|
||||
// //
|
||||
// This software is provided 'as-is', without any express or implied //
|
||||
// warranty. In no event will the authors be held liable for any damages //
|
||||
// arising from the use of this software. //
|
||||
// //
|
||||
// Permission is granted to anyone to use this software for any purpose, //
|
||||
// including commercial applications, and to alter it and redistribute it //
|
||||
// freely, subject to the following restrictions: //
|
||||
// //
|
||||
// 1. The origin of this software must not be misrepresented; you must not //
|
||||
// claim that you wrote the original software. If you use this software //
|
||||
// in a product, an acknowledgment in the product documentation would be //
|
||||
// appreciated but is not required. //
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be //
|
||||
// misrepresented as being the original software. //
|
||||
// 3. This notice may not be removed or altered from any source distribution. //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef H_SPK_RANDOMEMITTER
|
||||
#define H_SPK_RANDOMEMITTER
|
||||
|
||||
#include "Core/SPK_Emitter.h"
|
||||
|
||||
|
||||
namespace SPK
|
||||
{
|
||||
/**
|
||||
* @class RandomEmitter
|
||||
* @brief An Emitter that emits in a random direction
|
||||
* @since 1.02.00
|
||||
*/
|
||||
class SPK_PREFIX RandomEmitter : public Emitter
|
||||
{
|
||||
SPK_IMPLEMENT_REGISTERABLE(RandomEmitter)
|
||||
|
||||
public :
|
||||
|
||||
/**
|
||||
* @brief Creates and registers a new RandomEmitter
|
||||
* @return A new registered RandomEmitter
|
||||
* @since 1.04.00
|
||||
*/
|
||||
static inline RandomEmitter* create();
|
||||
|
||||
private :
|
||||
|
||||
virtual void generateVelocity(Particle& particle,float speed) const;
|
||||
};
|
||||
|
||||
|
||||
inline RandomEmitter* RandomEmitter::create()
|
||||
{
|
||||
RandomEmitter* obj = new RandomEmitter;
|
||||
registerObject(obj);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
183
libs/spark/include/Extensions/Emitters/SPK_SphericEmitter.h
Normal file
183
libs/spark/include/Extensions/Emitters/SPK_SphericEmitter.h
Normal file
@ -0,0 +1,183 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// SPARK particle engine //
|
||||
// Copyright (C) 2008-2009 - Julien Fryer - julienfryer@gmail.com //
|
||||
// //
|
||||
// This software is provided 'as-is', without any express or implied //
|
||||
// warranty. In no event will the authors be held liable for any damages //
|
||||
// arising from the use of this software. //
|
||||
// //
|
||||
// Permission is granted to anyone to use this software for any purpose, //
|
||||
// including commercial applications, and to alter it and redistribute it //
|
||||
// freely, subject to the following restrictions: //
|
||||
// //
|
||||
// 1. The origin of this software must not be misrepresented; you must not //
|
||||
// claim that you wrote the original software. If you use this software //
|
||||
// in a product, an acknowledgment in the product documentation would be //
|
||||
// appreciated but is not required. //
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be //
|
||||
// misrepresented as being the original software. //
|
||||
// 3. This notice may not be removed or altered from any source distribution. //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef H_SPK_SPHERICEMITTER
|
||||
#define H_SPK_SPHERICEMITTER
|
||||
|
||||
#include "Core/SPK_Emitter.h"
|
||||
|
||||
|
||||
namespace SPK
|
||||
{
|
||||
/**
|
||||
* @class SphericEmitter
|
||||
* @brief An Emitter that emits particles in a portion of sphere
|
||||
*
|
||||
* This Emitter can emit particles in a spheric way.
|
||||
* To do that 2 angles and a direction Vector3D can be parametered :
|
||||
* <ul>
|
||||
* <li>The direction Vector3D defines the direction of the emitter.</li>
|
||||
* <li>The angles defines the area in between which wil be emitted the particles velocities.</li>
|
||||
* </ul>
|
||||
* Here are a few examples :
|
||||
* <ul>
|
||||
* <li><i>0 and 2 * PI</i> will define a complete sphere ie equivalent to a RandomEmitter</li>
|
||||
* <li><i>0 and 0</i> will define a Emitter equivalent to a StraightEmitter</li>
|
||||
* <li><i>PI and PI</i> will define a disk</li>
|
||||
* <li><i>PI / 2 and PI / 2</i> will define a Cone of angle PI / 2</li>
|
||||
* <li>...</li>
|
||||
* </ul>
|
||||
*/
|
||||
class SPK_PREFIX SphericEmitter : public Emitter
|
||||
{
|
||||
SPK_IMPLEMENT_REGISTERABLE(SphericEmitter)
|
||||
|
||||
public :
|
||||
|
||||
/////////////////
|
||||
// Constructor //
|
||||
/////////////////
|
||||
|
||||
/**
|
||||
* @brief Constructor of SphericEmitter
|
||||
* @param direction : the direction of the SphericEmitter
|
||||
* @param angleA : the first angle in radians of the SphericEmitter
|
||||
* @param angleB : the second angle in radians of the SphericEmitter
|
||||
*/
|
||||
SphericEmitter(const Vector3D& direction = Vector3D(0.0f,0.0f,-1.0f),float angleA = 0.0f,float angleB = 0.0f);
|
||||
|
||||
/**
|
||||
* @brief Creates and registers a new SphericEmitter
|
||||
* @param direction : the direction of the SphericEmitter
|
||||
* @param angleA : the first angle in radians of the SphericEmitter
|
||||
* @param angleB : the second angle in radians of the SphericEmitter
|
||||
* @since 1.04.00
|
||||
*/
|
||||
static inline SphericEmitter* create(const Vector3D& direction = Vector3D(0.0f,0.0f,-1.0f),float angleA = 0.0f,float angleB = 0.0f);
|
||||
|
||||
/////////////
|
||||
// Setters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Sets the direction of this SphericEmitter
|
||||
*
|
||||
* Note that it is not necessary to provide a normalized Vector3D.
|
||||
* This Vector3D only indicates a direction, its norm does not matter.
|
||||
*
|
||||
* @param direction : the direction of this SphericEmitter
|
||||
*/
|
||||
void setDirection(const Vector3D& direction);
|
||||
|
||||
/**
|
||||
* @brief Sets the angles of this SphericEmitter
|
||||
*
|
||||
* Note that angles are clamped between 0 and 2 * PI
|
||||
* AngleA does not have to be inferior to angleB, it has no importance as angles are sorted within the method.
|
||||
*
|
||||
* @param angleA : the first angle in radians of this SphericEmitter
|
||||
* @param angleB : the second angle in radians of this SphericEmitter
|
||||
*/
|
||||
void setAngles(float angleA,float angleB);
|
||||
|
||||
/////////////
|
||||
// Getters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Gets the direction of this SphericEmitter
|
||||
* @return the direction of this SphericEmitter
|
||||
*/
|
||||
inline const Vector3D& getDirection() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the direction of this SphericEmitter
|
||||
* @return the direction of this SphericEmitter
|
||||
*/
|
||||
inline const Vector3D& getTransformedDirection() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the minimum angle of this SphericEmitter
|
||||
* @return the minimum angle of this SphericEmitter
|
||||
*/
|
||||
inline float getAngleMin() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the maximum angle of this SphericEmitter
|
||||
* @return the maximum angle of this SphericEmitter
|
||||
*/
|
||||
inline float getAngleMax() const;
|
||||
|
||||
protected :
|
||||
|
||||
virtual void innerUpdateTransform();
|
||||
|
||||
private :
|
||||
|
||||
static const float PI;
|
||||
|
||||
Vector3D direction;
|
||||
Vector3D tDirection; // transformed direction
|
||||
|
||||
float angleMin;
|
||||
float angleMax;
|
||||
|
||||
float cosAngleMin;
|
||||
float cosAngleMax;
|
||||
|
||||
float matrix[9];
|
||||
|
||||
void computeMatrix();
|
||||
|
||||
virtual void generateVelocity(Particle& particle,float speed) const;
|
||||
};
|
||||
|
||||
|
||||
inline SphericEmitter* SphericEmitter::create(const Vector3D& direction,float angleA,float angleB)
|
||||
{
|
||||
SphericEmitter* obj = new SphericEmitter(direction,angleA,angleB);
|
||||
registerObject(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
inline const Vector3D& SphericEmitter::getDirection() const
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
|
||||
inline const Vector3D& SphericEmitter::getTransformedDirection() const
|
||||
{
|
||||
return tDirection;
|
||||
}
|
||||
|
||||
inline float SphericEmitter::getAngleMin() const
|
||||
{
|
||||
return angleMin;
|
||||
}
|
||||
|
||||
inline float SphericEmitter::getAngleMax() const
|
||||
{
|
||||
return angleMax;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
69
libs/spark/include/Extensions/Emitters/SPK_StaticEmitter.h
Normal file
69
libs/spark/include/Extensions/Emitters/SPK_StaticEmitter.h
Normal file
@ -0,0 +1,69 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// SPARK particle engine //
|
||||
// Copyright (C) 2008-2009 - Julien Fryer - julienfryer@gmail.com //
|
||||
// //
|
||||
// This software is provided 'as-is', without any express or implied //
|
||||
// warranty. In no event will the authors be held liable for any damages //
|
||||
// arising from the use of this software. //
|
||||
// //
|
||||
// Permission is granted to anyone to use this software for any purpose, //
|
||||
// including commercial applications, and to alter it and redistribute it //
|
||||
// freely, subject to the following restrictions: //
|
||||
// //
|
||||
// 1. The origin of this software must not be misrepresented; you must not //
|
||||
// claim that you wrote the original software. If you use this software //
|
||||
// in a product, an acknowledgment in the product documentation would be //
|
||||
// appreciated but is not required. //
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be //
|
||||
// misrepresented as being the original software. //
|
||||
// 3. This notice may not be removed or altered from any source distribution. //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef H_SPK_STATICEMITTER
|
||||
#define H_SPK_STATICEMITTER
|
||||
|
||||
#include "Core/SPK_Emitter.h"
|
||||
|
||||
|
||||
namespace SPK
|
||||
{
|
||||
/**
|
||||
* @class StaticEmitter
|
||||
* @brief An Emitter that emits particles with no initial velocity
|
||||
* @since 1.05.00
|
||||
*/
|
||||
class StaticEmitter : public Emitter
|
||||
{
|
||||
SPK_IMPLEMENT_REGISTERABLE(StaticEmitter)
|
||||
|
||||
public :
|
||||
|
||||
/**
|
||||
* @brief Creates and registers a new StaticEmitter
|
||||
* @return A new registered StaticEmitter
|
||||
*/
|
||||
static inline StaticEmitter* create();
|
||||
|
||||
private :
|
||||
|
||||
virtual inline void generateVelocity(Particle& particle,float speed) const;
|
||||
};
|
||||
|
||||
|
||||
inline StaticEmitter* StaticEmitter::create()
|
||||
{
|
||||
StaticEmitter* obj = new StaticEmitter;
|
||||
registerObject(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
inline void StaticEmitter::generateVelocity(Particle& particle,float speed) const
|
||||
{
|
||||
particle.velocity().set(0.0f,0.0f,0.0f); // no initial velocity
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
126
libs/spark/include/Extensions/Emitters/SPK_StraightEmitter.h
Normal file
126
libs/spark/include/Extensions/Emitters/SPK_StraightEmitter.h
Normal file
@ -0,0 +1,126 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// SPARK particle engine //
|
||||
// Copyright (C) 2008-2009 - Julien Fryer - julienfryer@gmail.com //
|
||||
// //
|
||||
// This software is provided 'as-is', without any express or implied //
|
||||
// warranty. In no event will the authors be held liable for any damages //
|
||||
// arising from the use of this software. //
|
||||
// //
|
||||
// Permission is granted to anyone to use this software for any purpose, //
|
||||
// including commercial applications, and to alter it and redistribute it //
|
||||
// freely, subject to the following restrictions: //
|
||||
// //
|
||||
// 1. The origin of this software must not be misrepresented; you must not //
|
||||
// claim that you wrote the original software. If you use this software //
|
||||
// in a product, an acknowledgment in the product documentation would be //
|
||||
// appreciated but is not required. //
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be //
|
||||
// misrepresented as being the original software. //
|
||||
// 3. This notice may not be removed or altered from any source distribution. //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef H_SPK_STRAIGHEMITTER
|
||||
#define H_SPK_STRAIGHEMITTER
|
||||
|
||||
#include "Core/SPK_Emitter.h"
|
||||
#include "Core/SPK_Particle.h"
|
||||
|
||||
|
||||
namespace SPK
|
||||
{
|
||||
/**
|
||||
* @class StraightEmitter
|
||||
* @brief An Emitter that emits in a given direction
|
||||
*/
|
||||
class SPK_PREFIX StraightEmitter : public Emitter
|
||||
{
|
||||
SPK_IMPLEMENT_REGISTERABLE(StraightEmitter)
|
||||
|
||||
public :
|
||||
|
||||
/////////////////
|
||||
// Constructor //
|
||||
/////////////////
|
||||
|
||||
/**
|
||||
* @brief The constructor of StraightEmitter
|
||||
* @param direction : the direction of the StraighEmitter
|
||||
*/
|
||||
StraightEmitter(const Vector3D& direction = Vector3D(0.0f,0.0f,-1.0f));
|
||||
|
||||
/**
|
||||
* @brief Creates and registers a new StraightEmitter
|
||||
* @param direction : the direction of the StraighEmitter
|
||||
* @since 1.04.00
|
||||
*/
|
||||
static inline StraightEmitter* create(const Vector3D& direction = Vector3D(0.0f,0.0f,-1.0f));
|
||||
|
||||
/////////////
|
||||
// Setters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Sets the direction of this StraightEmitter
|
||||
*
|
||||
* Note that it is not necessary to provide a normalized Vector3D.
|
||||
* This Vector3D only indicates a direction, its norm does not matter.
|
||||
*
|
||||
* @param direction : the direction of this StraightEmitter
|
||||
*/
|
||||
void setDirection(const Vector3D& direction);
|
||||
|
||||
/////////////
|
||||
// Getters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Gets the direction of this StraightEmitter
|
||||
* @return the direction of this StraightEmitter
|
||||
*/
|
||||
inline const Vector3D& getDirection() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the transformed direction of this StraightEmitter
|
||||
* @return the transformed direction of this StraightEmitter
|
||||
*/
|
||||
inline const Vector3D& getTransformedDirection() const;
|
||||
|
||||
protected :
|
||||
|
||||
virtual void innerUpdateTransform();
|
||||
|
||||
private :
|
||||
|
||||
Vector3D direction;
|
||||
Vector3D tDirection;
|
||||
|
||||
virtual inline void generateVelocity(Particle& particle,float speed) const;
|
||||
};
|
||||
|
||||
|
||||
inline StraightEmitter* StraightEmitter::create(const Vector3D& direction)
|
||||
{
|
||||
StraightEmitter* obj = new StraightEmitter(direction);
|
||||
registerObject(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
inline const Vector3D& StraightEmitter::getDirection() const
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
|
||||
inline const Vector3D& StraightEmitter::getTransformedDirection() const
|
||||
{
|
||||
return tDirection;
|
||||
}
|
||||
|
||||
inline void StraightEmitter::generateVelocity(Particle& particle,float speed) const
|
||||
{
|
||||
particle.velocity() = tDirection;
|
||||
particle.velocity() *= speed;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user