add sparkle explosions

This commit is contained in:
gmueller
2011-01-05 23:02:10 +01:00
parent b19f44ec32
commit a02ad6bd34
106 changed files with 19753 additions and 88 deletions

View File

@ -0,0 +1,154 @@
//////////////////////////////////////////////////////////////////////////////////
// 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_AABOX
#define H_SPK_AABOX
#include "Core/SPK_Zone.h"
namespace SPK
{
/**
* @class AABox
* @brief A Zone defining an axis-aligned Box
*
* An AABox is defined by its center and a dimension in each axis.
*/
class SPK_PREFIX AABox : public Zone
{
SPK_IMPLEMENT_REGISTERABLE(AABox)
public :
/////////////////
// Constructor //
/////////////////
/**
* @brief Constructor of AABox
* @param position : the position of the AABox
* @param dimension : the dimension of the AABox
*/
AABox(const Vector3D& position = Vector3D(0.0f,0.0f,0.0f),const Vector3D& dimension = Vector3D(0.0f,0.0f,0.0f));
/**
* @brief Creates and registers a new AABox
* @param position : the position of the AABox
* @param dimension : the dimension of the AABox
* @since 1.04.00
*/
static inline AABox* create(const Vector3D& position = Vector3D(0.0f,0.0f,0.0f),const Vector3D& dimension = Vector3D(0.0f,0.0f,0.0f));
////////////
// Setter //
////////////
/**
* @brief Sets the dimensions of this AABox
*
* The negative dimensions are clamped to 0.<br>
* An AABox with 0 as its 3 dimensions is equivalent to a Point
*
* @param dimension : the dimensions of this AABox
*/
void setDimension(const Vector3D& dimension);
////////////
// Getter //
////////////
/**
* @brief Gets the dimensions of this AABox
* @return the dimensions of this AABox
*/
inline const Vector3D& getDimension() const;
///////////////
// Interface //
///////////////
virtual void generatePosition(Particle& particle,bool full) const;
virtual bool contains(const Vector3D& v) const;
virtual bool intersects(const Vector3D& v0,const Vector3D& v1,Vector3D* intersection,Vector3D* normal) const;
virtual void moveAtBorder(Vector3D& v,bool inside) const;
virtual Vector3D computeNormal(const Vector3D& point) const;
private :
Vector3D dimension;
inline bool slabIntersects(float p0,float p1,float bMin,float bMax,float& tEnter,float& tExit,int& firstAxis,int axis) const;
};
inline AABox* AABox::create(const Vector3D& position,const Vector3D& dimension)
{
AABox* obj = new AABox(position,dimension);
registerObject(obj);
return obj;
}
inline const Vector3D& AABox::getDimension() const
{
return dimension;
}
inline bool AABox::slabIntersects(float p0,float p1,float bMin,float bMax,float& tEnter,float& tExit,int& firstAxis,int axis) const
{
float dir = p1 - p0;
if (dir == 0.0f)
{
if ((p0 < bMin)||(p0 > bMax))
return false;
return true;
}
float t0 = (bMin - p0) / dir;
float t1 = (bMax - p0) / dir;
if (t0 > t1)
{
std::swap(t0,t1);
axis += 3;
}
if ((t1 < tEnter)||(t0 > tExit))
return false;
if (t0 > tEnter)
{
tEnter = t0;
firstAxis = (firstAxis & 0xF0) | (axis & 0x0F);
}
if (t1 < tExit)
{
tExit = t1;
firstAxis = (firstAxis & 0x0F) | ((axis << 4) & 0xF0);
}
return true;
}
}
#endif

View File

@ -0,0 +1,176 @@
//////////////////////////////////////////////////////////////////////////////////
// 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_LINE
#define H_SPK_LINE
#include "Core/SPK_Zone.h"
namespace SPK
{
/**
* @class Line
* @brief A Zone defining a line in the universe
*
* As any Zone, a Line is defined by a position. The Line in itself is defined by two bounds.<br>
* Moving the position results in moving the 2 bounds in the universe by the same vector.<br>
* <br>
* To conform with the Zone class (the position is defined as the center of the Zone), the position is always set to
* be the center of the line. Therefore, if a bound is modified, the position will be modified as well.
*
* @since 1.01.00
*/
class SPK_PREFIX Line : public Zone
{
SPK_IMPLEMENT_REGISTERABLE(Line)
public :
/////////////////
// Constructor //
/////////////////
/**
* @brief Constructor of Line
* @param p0 : the first bound of this Line
* @param p1 : the second bound of this Line
*/
Line(const Vector3D& p0 = Vector3D(0.0f,0.0f,0.0f),const Vector3D& p1 = Vector3D(0.0f,0.0f,0.0f));
/**
* @brief Creates and registers a new Line
* @param p0 : the first bound of this Line
* @param p1 : the second bound of this Line
* @since 1.04.00
*/
static inline Line* create(const Vector3D& p0 = Vector3D(0.0f,0.0f,0.0f),const Vector3D& p1 = Vector3D(0.0f,0.0f,0.0f));
/////////////
// Setters //
/////////////
void setPosition(const Vector3D& v);
/**
* @brief Sets the bounds of this Line
* @param p0 : the first bound of this Line
* @param p1 : the second bound of this Line
*/
void setBounds(const Vector3D& p0,const Vector3D& p1);
/////////////
// Getters //
/////////////
/**
* @brief Gets the bound of index of this Line
* @param index : the index of the bound (0 or 1)
* @return the first bound of index of this Line
* @since 1.03.00
*/
inline const Vector3D& getBound(size_t index) const;
/**
* @brief Gets the transformed bound of index of this Line
* @param index : the index of the bound (0 or 1)
* @return the transformed bound of index of this Line
* @since 1.03.00
*/
inline const Vector3D& getTransformedBound(size_t index) const;
///////////////
// Interface //
///////////////
/**
* @brief Pushes a new bound to this Line
*
* This method replaces the first bound by the second bound and the second bound by the new bound.<br>
* It allows to follow the trajectory of a moving object over time with a single Line.
*
* @param bound : the new bound of this Line
*/
void pushBound(const Vector3D& bound);
virtual void generatePosition(Particle& particle,bool full) const;
virtual inline bool contains(const Vector3D& v) const;
virtual inline bool intersects(const Vector3D& v0,const Vector3D& v1,Vector3D* intersection,Vector3D* normal) const;
virtual inline void moveAtBorder(Vector3D& v,bool inside) const;
virtual Vector3D computeNormal(const Vector3D& point) const;
protected :
virtual void innerUpdateTransform();
private :
Vector3D bounds[2];
Vector3D tBounds[2];
Vector3D tDist;
inline void computeDist();
inline void computePosition();
};
inline Line* Line::create(const Vector3D& p0,const Vector3D& p1)
{
Line* obj = new Line(p0,p1);
registerObject(obj);
return obj;
}
inline const Vector3D& Line::getBound(size_t index) const
{
return bounds[index];
}
inline const Vector3D& Line::getTransformedBound(size_t index) const
{
return tBounds[index];
}
inline bool Line::contains(const Vector3D& v) const
{
return false;
}
inline bool Line::intersects(const Vector3D& v0,const Vector3D& v1,Vector3D* intersection,Vector3D* normal) const
{
return false;
}
inline void Line::moveAtBorder(Vector3D& v,bool inside) const {}
inline void Line::computeDist()
{
tDist = tBounds[1] - tBounds[0];
}
inline void Line::computePosition()
{
Zone::setPosition((bounds[0] + bounds[1]) * 0.5f);
}
}
#endif

View File

@ -0,0 +1,163 @@
//////////////////////////////////////////////////////////////////////////////////
// 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_PLANE
#define H_SPK_PLANE
#include "Core/SPK_Zone.h"
#include "Core/SPK_Particle.h"
namespace SPK
{
/**
* @class Plane
* @brief A Zone defining a plane in the universe
*
* A Plane is defined by 2 parameters :
* <ul>
* <li>A Position is the universe</li>
* <li>A Normal</li>
* </ul>
* The defined Plane is the Plane having the normal and passing by the position.<br>
* The direction of the normal defines the sens of the plane. The normal goes from inside the Plane to outside.<br>
* <br>
* Note that the normal does not have to be normalized as it is normalized internally when set.
*/
class SPK_PREFIX Plane : public Zone
{
SPK_IMPLEMENT_REGISTERABLE(Plane)
public :
//////////////////
// Constructors //
//////////////////
/**
* @brief Constructor of Plane
* @param position : the position of the Plane
* @param normal : the normal of the Plane
*/
Plane(const Vector3D& position = Vector3D(0.0f,0.0f,0.0f),const Vector3D& normal = Vector3D(0.0f,1.0f,0.0f));
/**
* @brief Creates and registers a new Plane
* @param position : the position of the Plane
* @param normal : the normal of the Plane
* @return a new registered plane
* @since 1.04.00
*/
static inline Plane* create(const Vector3D& position = Vector3D(0.0f,0.0f,0.0f),const Vector3D& normal = Vector3D(0.0f,1.0f,0.0f));
/////////////
// Setters //
/////////////
/**
* @brief Sets the normal of this Plane
*
* Note that the normal is normalized internally.
*
* @param normal : the normal of this Plane
*/
inline void setNormal(const Vector3D& normal);
/////////////
// Getters //
/////////////
/**
* @brief Gets the normal of this Plane
* @return the normal of this Plane
*/
inline const Vector3D& getNormal() const;
/**
* @brief Gets the transformed normal of this Plane
* @return the transformed normal of this Plane
* @since 1.05.00
*/
inline const Vector3D& getTransformedNormal() const;
///////////////
// Interface //
///////////////
virtual inline void generatePosition(Particle& particle,bool full) const;
virtual inline bool contains(const Vector3D& v) const;
virtual bool intersects(const Vector3D& v0,const Vector3D& v1,Vector3D* intersection,Vector3D* normal) const;
virtual void moveAtBorder(Vector3D& v,bool inside) const;
virtual inline Vector3D computeNormal(const Vector3D& point) const;
protected :
virtual void innerUpdateTransform();
private :
Vector3D normal;
Vector3D tNormal;
};
inline Plane* Plane::create(const Vector3D& position,const Vector3D& normal)
{
Plane* obj = new Plane(position,normal);
registerObject(obj);
return obj;
}
inline void Plane::setNormal(const Vector3D& normal)
{
this->normal = normal;
this->normal.normalize();
tNormal = this->normal;
notifyForUpdate();
}
inline const Vector3D& Plane::getNormal() const
{
return normal;
}
inline const Vector3D& Plane::getTransformedNormal() const
{
return tNormal;
}
inline void Plane::generatePosition(Particle& particle,bool full) const
{
particle.position() = getTransformedPosition();
}
inline bool Plane::contains(const Vector3D& v) const
{
return dotProduct(normal,v - getTransformedPosition()) <= 0.0f;
}
inline Vector3D Plane::computeNormal(const Vector3D& point) const
{
return tNormal;
}
}
#endif

View File

@ -0,0 +1,93 @@
//////////////////////////////////////////////////////////////////////////////////
// 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_POINT
#define H_SPK_POINT
#include "Core/SPK_Zone.h"
#include "Core/SPK_Particle.h"
namespace SPK
{
/**
* @class Point
* @brief A Zone defining a point in the universe
*/
class SPK_PREFIX Point : public Zone
{
SPK_IMPLEMENT_REGISTERABLE(Point)
public :
/////////////////
// Constructor //
/////////////////
/**
* @brief Constructor of Point
* @param position : the position of the Point
*/
Point(const Vector3D& position = Vector3D(0.0f,0.0f,0.0f));
/**
* @brief Creates and registers a new Point
* @param position : the position of the Point
* @return A new registered Point
* @since 1.04.00
*/
static inline Point* create(const Vector3D& position = Vector3D(0.0f,0.0f,0.0f));
// Interface
virtual inline void generatePosition(Particle& particle,bool full) const;
virtual inline bool contains(const Vector3D& v) const;
virtual inline bool intersects(const Vector3D& v0,const Vector3D& v1,Vector3D* intersection,Vector3D* normal) const;
virtual inline void moveAtBorder(Vector3D& v,bool inside) const;
virtual Vector3D computeNormal(const Vector3D& point) const;
};
inline Point* Point::create(const Vector3D& position)
{
Point* obj = new Point(position);
registerObject(obj);
return obj;
}
inline void Point::generatePosition(Particle& particle,bool full) const
{
particle.position() = getTransformedPosition();
}
inline bool Point::contains(const Vector3D& v) const
{
return false;
}
inline bool Point::intersects(const Vector3D& v0,const Vector3D& v1,Vector3D* intersection,Vector3D* normal) const
{
return false;
}
inline void Point::moveAtBorder(Vector3D& v,bool inside) const {}
}
#endif

View File

@ -0,0 +1,198 @@
//////////////////////////////////////////////////////////////////////////////////
// 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_RING
#define H_SPK_RING
#include "Core/SPK_Zone.h"
namespace SPK
{
/**
* @brief A ZOne defining a flat ring in the universe
*
* A ring is defined by :
* <ul>
* <li>The position of its center</li>
* <li>The normal of the plane on which it lies</li>
* <li>A minimum and maximum radius</li>
* </ul>
* Note that by having the minimum radius equal to 0, the ring becomes a disk in the universe.<br>
* Note that the normal does not have to be normalized as it is normalized internally when set.
*
* @since 1.05.00
*/
class SPK_PREFIX Ring : public Zone
{
SPK_IMPLEMENT_REGISTERABLE(Ring)
public :
//////////////////
// Constructors //
//////////////////
/**
* @brief Constructor of ring
* @param position : the position of the ring
* @param normal : the normal of the plane on which lies the ring
* @param minRadius : the minimum radius of the ring
* @param maxRadius : the maximum radius of the ring
*/
Ring(const Vector3D& position = Vector3D(0.0f,0.0f,0.0f),const Vector3D& normal = Vector3D(0.0f,1.0f,0.0f),float minRadius = 0.0f,float maxRadius = 1.0f);
/**
* @brief Creates and registers a new Ring
* @param position : the position of the ring
* @param normal : the normal of the plane on which lies the ring
* @param minRadius : the minimum radius of the ring
* @param maxRadius : the maximum radius of the ring
* @return a new registered ring
*/
static inline Ring* create(const Vector3D& position = Vector3D(0.0f,0.0f,0.0f),const Vector3D& normal = Vector3D(0.0f,1.0f,0.0f),float minRadius = 0.0f,float maxRadius = 1.0f);
/////////////
// Setters //
/////////////
/**
* @brief Sets the normal of the plane on which lies this ring
*
* Note that the normal is normalized internally
*
* @param normal : the normal of the plane on which lies the ring
*/
inline void setNormal(const Vector3D& normal);
/**
* @brief Sets the min and max radius of this ring
*
* A radius cannot be negative.<br>
* Note that negative radius are inverted internally
*
* @param minRadius : the minimum radius of this ring
* @param maxRadius : the maximum radius of this ring
*/
void setRadius(float minRadius,float maxRadius);
/////////////
// Getters //
/////////////
/**
* @brief Gets the normal of this ring
* @return the normal of this ring
*/
inline const Vector3D& getNormal() const;
/**
* @brief Gets the transformed normal of this ring
* @return the transformed normal of this ring
*/
inline const Vector3D& getTransformedNormal() const;
/**
* @brief Gets the minimum radius of this ring
* @return the minimum radius of this ring
*/
inline float getMinRadius() const;
/**
* @brief Gets the maximum radius of this ring
* @return the maximum radius of this ring
*/
inline float getMaxRadius() const;
///////////////
// Interface //
///////////////
virtual void generatePosition(Particle& particle,bool full) const;
virtual inline bool contains(const Vector3D& v) const;
virtual bool intersects(const Vector3D& v0,const Vector3D& v1,Vector3D* intersection,Vector3D* normal) const;
virtual void moveAtBorder(Vector3D& v,bool inside) const;
virtual inline Vector3D computeNormal(const Vector3D& point) const;
protected :
virtual void innerUpdateTransform();
private :
Vector3D normal;
Vector3D tNormal;
float minRadius;
float maxRadius;
// Square of the radius (for optimization purpose)
float sqrMinRadius;
float sqrMaxRadius;
};
inline Ring* Ring::create(const Vector3D& position,const Vector3D& normal,float minRadius,float maxRadius)
{
Ring* obj = new Ring(position,normal,minRadius,maxRadius);
registerObject(obj);
return obj;
}
inline void Ring::setNormal(const Vector3D& normal)
{
this->normal = normal;
this->normal.normalize();
tNormal = this->normal;
notifyForUpdate();
}
inline const Vector3D& Ring::getNormal() const
{
return normal;
}
inline const Vector3D& Ring::getTransformedNormal() const
{
return tNormal;
}
inline float Ring::getMinRadius() const
{
return minRadius;
}
inline float Ring::getMaxRadius() const
{
return maxRadius;
}
inline bool Ring::contains(const Vector3D& v) const
{
return false;
}
inline Vector3D Ring::computeNormal(const Vector3D& point) const
{
return tNormal;
}
}
#endif

View File

@ -0,0 +1,117 @@
//////////////////////////////////////////////////////////////////////////////////
// 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_SPHERE
#define H_SPK_SPHERE
#include "Core/SPK_Zone.h"
namespace SPK
{
/**
* @class Sphere
* @brief A Zone defining a sphere in the universe
*/
class SPK_PREFIX Sphere : public Zone
{
SPK_IMPLEMENT_REGISTERABLE(Sphere)
public :
/////////////////
// Constructor //
/////////////////
/**
* @brief Constructor of Sphere
* @param position : position of the center of the Sphere
* @param radius : radius of the Sphere
*/
Sphere(const Vector3D& position = Vector3D(0.0f,0.0f,0.0f),float radius = 0.0f);
/**
* @brief Creates and registers a new Sphere
* @param position : position of the center of the Sphere
* @param radius : radius of the Sphere
* @return A new registered Sphere
* @since 1.04.00
*/
static inline Sphere* create(const Vector3D& position = Vector3D(0.0f,0.0f,0.0f),float radius = 0.0f);
////////////
// Setter //
////////////
/**
* @brief Sets the radius of this Sphere
*
* A negative radius will be clamped to 0.0f and the Sphere will therefore acts as a Point.
*
* @param radius : the radius of this Sphere
*/
inline void setRadius(float radius);
////////////
// Getter //
////////////
/**
* @brief Gets the radius of this Sphere
* @return the radius of this Sphere
*/
inline float getRadius() const;
///////////////
// Interface //
///////////////
virtual void generatePosition(Particle& particle,bool full) const;
virtual bool contains(const Vector3D& v) const;
virtual bool intersects(const Vector3D& v0,const Vector3D& v1,Vector3D* intersection,Vector3D* normal) const;
virtual void moveAtBorder(Vector3D& v,bool inside) const;
virtual Vector3D computeNormal(const Vector3D& point) const;
private :
float radius;
};
inline Sphere* Sphere::create(const Vector3D& position,float radius)
{
Sphere* obj = new Sphere(position,radius);
registerObject(obj);
return obj;
}
inline void Sphere::setRadius(float radius)
{
this->radius = radius >= 0.0f ? radius : 0.0f;
}
inline float Sphere::getRadius() const
{
return radius;
}
}
#endif