add sparkle explosions
This commit is contained in:
@ -0,0 +1,125 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// 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_LINERENDERERINTERFACE
|
||||
#define H_SPK_LINERENDERERINTERFACE
|
||||
|
||||
#include "Core/SPK_DEF.h"
|
||||
|
||||
namespace SPK
|
||||
{
|
||||
/**
|
||||
* @brief Base Interface for rendering particles with lines
|
||||
* @since 1.04.00
|
||||
*/
|
||||
class LineRendererInterface
|
||||
{
|
||||
public :
|
||||
|
||||
/////////////////
|
||||
// Constructor //
|
||||
/////////////////
|
||||
|
||||
/**
|
||||
* @brief Constructor of LineRendererInterface
|
||||
* @param length : the length multiplier of this LineRendererInterface
|
||||
* @param width : the width of this GLLineRenderer
|
||||
*/
|
||||
inline LineRendererInterface(float length = 1.0f,float width = 1.0f);
|
||||
|
||||
////////////////
|
||||
// Destructor //
|
||||
////////////////
|
||||
|
||||
/** @brief Destructor of LineRendererInterface */
|
||||
virtual inline ~LineRendererInterface() {}
|
||||
|
||||
/////////////
|
||||
// Setters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Sets the length multiplier of this LineRendererInterface
|
||||
*
|
||||
* The length multiplier is the value which will be multiplied by the Particle velocity to get the line length in the universe.<br>
|
||||
* A positive length means the line will be drawn in advance to the Particle, as opposed to a negative length.
|
||||
*
|
||||
* @param length : the length multiplier of this GLLineRenderer
|
||||
*/
|
||||
inline void setLength(float length);
|
||||
|
||||
/**
|
||||
* @brief Sets the width of this LineRendererInterface
|
||||
* @param width : the width of this LineRendererInterface
|
||||
*/
|
||||
virtual inline void setWidth(float width);
|
||||
|
||||
/////////////
|
||||
// Getters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Gets the length multiplier of this LineRendererInterface
|
||||
* @return the length multiplier of this LineRendererInterface
|
||||
*/
|
||||
inline float getLength() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the width of this LineRendererInterface
|
||||
* @return the width of this LineRendererInterface
|
||||
*/
|
||||
inline float getWidth() const;
|
||||
|
||||
protected :
|
||||
|
||||
float length;
|
||||
float width;
|
||||
};
|
||||
|
||||
|
||||
inline LineRendererInterface::LineRendererInterface(float length,float width) :
|
||||
length(length),
|
||||
width(width)
|
||||
{}
|
||||
|
||||
inline void LineRendererInterface::setLength(float length)
|
||||
{
|
||||
this->length = length;
|
||||
}
|
||||
|
||||
inline void LineRendererInterface::setWidth(float width)
|
||||
{
|
||||
this->width = width;
|
||||
}
|
||||
|
||||
inline float LineRendererInterface::getLength() const
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
inline float LineRendererInterface::getWidth() const
|
||||
{
|
||||
return width;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,216 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// 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_ORIENTED2DRENDERERINTERFACE
|
||||
#define H_SPK_ORIENTED2DRENDERERINTERFACE
|
||||
|
||||
#include "Core/SPK_Vector3D.h"
|
||||
#include "Core/SPK_Group.h"
|
||||
|
||||
namespace SPK
|
||||
{
|
||||
/**
|
||||
* @brief Defines the orientation of a particle oriented in 2D
|
||||
* @since 1.04.00
|
||||
*/
|
||||
enum Orientation2D
|
||||
{
|
||||
ORIENTATION2D_UP, /**< Oriented towards the camera plane */
|
||||
ORIENTATION2D_DIRECTION, /**< Oriented towards the direction of the particle */
|
||||
ORIENTATION2D_POINT, /**< Oriented towards a point in the universe */
|
||||
ORIENTATION2D_AXIS /**< The orientation vector is defined by an axis */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Base Interface for rendering particles that can be oriented in a 2D world
|
||||
* @since 1.04.00
|
||||
*/
|
||||
class Oriented2DRendererInterface
|
||||
{
|
||||
public :
|
||||
|
||||
///////////////
|
||||
// Parameter //
|
||||
///////////////
|
||||
|
||||
/**
|
||||
* @brief The orientation vector
|
||||
*
|
||||
* It is used in 2 orientation modes :
|
||||
* <ul>
|
||||
* <li>ORIENTATION2D_AXIS : The orientation vector is used as the axis</li>
|
||||
* <li>ORIENTATION2D_POINT : The orientation vector is the point particle look to</li>
|
||||
* </ul>
|
||||
* In other modes the orientation vector is not used
|
||||
*/
|
||||
Vector3D orientationVector;
|
||||
|
||||
//////////////////
|
||||
// Constructors //
|
||||
//////////////////
|
||||
|
||||
/** @brief Constructor of Oriented2DRendererInterface */
|
||||
inline Oriented2DRendererInterface();
|
||||
|
||||
////////////////
|
||||
// Destructor //
|
||||
////////////////
|
||||
|
||||
/** @brief Destructor of Oriented2DRendererInterface */
|
||||
virtual inline ~Oriented2DRendererInterface() {}
|
||||
|
||||
/////////////
|
||||
// Setters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Sets the way quads are oriented in the universe
|
||||
* @param orientation : the orientation of the quad
|
||||
*/
|
||||
inline void setOrientation(Orientation2D orientation);
|
||||
|
||||
/////////////
|
||||
// Getters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Gets the orientation of the quads
|
||||
* @return the orientation of the quads
|
||||
*/
|
||||
inline Orientation2D getOrientation() const;
|
||||
|
||||
protected :
|
||||
|
||||
Orientation2D orientation;
|
||||
|
||||
inline bool hasGlobalOrientation();
|
||||
inline void computeGlobalOrientation2D();
|
||||
inline void computeSingleOrientation2D(const Particle& particle);
|
||||
|
||||
inline void scaleQuadVectors(const Particle& particle,float scaleX,float scaleY) const;
|
||||
inline void rotateAndScaleQuadVectors(const Particle& particle,float scaleX,float scaleY) const;
|
||||
|
||||
inline const Vector3D& quadUp() const;
|
||||
inline const Vector3D& quadSide() const;
|
||||
|
||||
private :
|
||||
|
||||
// Used to store the orientation of quads before scaling
|
||||
mutable Vector3D up;
|
||||
mutable Vector3D side;
|
||||
|
||||
// This is where are stored quad orientation info after computation
|
||||
mutable Vector3D sideQuad;
|
||||
mutable Vector3D upQuad;
|
||||
};
|
||||
|
||||
|
||||
inline Oriented2DRendererInterface::Oriented2DRendererInterface() :
|
||||
orientation(ORIENTATION2D_UP)
|
||||
{
|
||||
orientationVector.set(0.0f,-1.0f);
|
||||
}
|
||||
|
||||
inline void Oriented2DRendererInterface::setOrientation(Orientation2D orientation)
|
||||
{
|
||||
this->orientation = orientation;
|
||||
}
|
||||
|
||||
inline Orientation2D Oriented2DRendererInterface::getOrientation() const
|
||||
{
|
||||
return orientation;
|
||||
}
|
||||
|
||||
inline const Vector3D& Oriented2DRendererInterface::quadUp() const
|
||||
{
|
||||
return upQuad;
|
||||
}
|
||||
|
||||
inline const Vector3D& Oriented2DRendererInterface::quadSide() const
|
||||
{
|
||||
return sideQuad;
|
||||
}
|
||||
|
||||
inline bool Oriented2DRendererInterface::hasGlobalOrientation()
|
||||
{
|
||||
return ((orientation == ORIENTATION2D_UP)||(ORIENTATION2D_AXIS));
|
||||
}
|
||||
|
||||
inline void Oriented2DRendererInterface::computeGlobalOrientation2D()
|
||||
{
|
||||
if (orientation == ORIENTATION2D_UP)
|
||||
up.set(0.0f,-0.5f);
|
||||
else if (orientation == ORIENTATION2D_AXIS)
|
||||
{
|
||||
up.set(orientationVector.x,orientationVector.y);
|
||||
up.normalize();
|
||||
up *= 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
inline void Oriented2DRendererInterface::computeSingleOrientation2D(const Particle& particle)
|
||||
{
|
||||
if (orientation == ORIENTATION2D_DIRECTION)
|
||||
up = particle.velocity();
|
||||
else if (orientation == ORIENTATION2D_POINT)
|
||||
{
|
||||
up = orientationVector;
|
||||
up -= particle.position();
|
||||
}
|
||||
|
||||
up.z = 0.0f;
|
||||
up.normalize();
|
||||
up *= 0.5f;
|
||||
}
|
||||
|
||||
inline void Oriented2DRendererInterface::scaleQuadVectors(const Particle& particle,float scaleX,float scaleY) const
|
||||
{
|
||||
float size = particle.getParamCurrentValue(PARAM_SIZE);
|
||||
|
||||
upQuad.set(up.x,up.y);
|
||||
upQuad *= size * scaleY;
|
||||
|
||||
sideQuad.set(-up.y,up.x);
|
||||
sideQuad *= size * scaleX;
|
||||
}
|
||||
|
||||
inline void Oriented2DRendererInterface::rotateAndScaleQuadVectors(const Particle& particle,float scaleX,float scaleY) const
|
||||
{
|
||||
float size = particle.getParamCurrentValue(PARAM_SIZE);
|
||||
|
||||
float angleTexture = particle.getParamCurrentValue(PARAM_ANGLE);
|
||||
float cosA = cos(angleTexture);
|
||||
float sinA = sin(angleTexture);
|
||||
|
||||
upQuad.x = cosA * up.x + sinA * up.y;
|
||||
upQuad.y = -sinA * up.x + cosA * up.y;
|
||||
upQuad.z = 0.0f;
|
||||
|
||||
sideQuad.set(-upQuad.y,upQuad.x);
|
||||
|
||||
sideQuad *= size * scaleX;
|
||||
upQuad *= size * scaleY;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,387 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// 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_ORIENTED3DRENDERERINTERFACE
|
||||
#define H_SPK_ORIENTED3DRENDERERINTERFACE
|
||||
|
||||
#include "Core/SPK_Vector3D.h"
|
||||
#include "Core/SPK_Group.h"
|
||||
|
||||
// Packs the orientations parameters into one int for orientation presets
|
||||
#define PACK_ORIENTATION(lock,look,up) ((lock << 0x10)|(look << 0x8)|(up))
|
||||
|
||||
namespace SPK
|
||||
{
|
||||
/**
|
||||
* @brief Defines the orientation of the vector Look of an oriented 3D particle
|
||||
*
|
||||
* Enumerators marked as (fast) are the ones that only needs to be computed once for
|
||||
* a set of particles instead of being computed for each particles.
|
||||
*
|
||||
* @since 1.04.00
|
||||
*/
|
||||
enum LookOrientation
|
||||
{
|
||||
LOOK_CAMERA_PLANE, /**< Look towards the camera plane (fast) */
|
||||
LOOK_CAMERA_POINT, /**< Look towards the camera point (better effect but more expensive) */
|
||||
LOOK_AXIS, /**< The look vector is defined by an axis (fast) */
|
||||
LOOK_POINT, /**< Look towards a point in the universe */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the orientation of the vector Up of an oriented 3D particle
|
||||
*
|
||||
* Enumerators marked as (fast) are the ones that only needs to be computed once for
|
||||
* a set of particles instead of being computed for each particles.
|
||||
*
|
||||
* @since 1.04.00
|
||||
*/
|
||||
enum UpOrientation
|
||||
{
|
||||
UP_CAMERA, /**< The up vector is defined by the up vector of the camera (fast) */
|
||||
UP_DIRECTION, /**< The up vector is oriented towards the direction of the particle */
|
||||
UP_AXIS, /**< The up vector is is defined by an axis (fast) */
|
||||
UP_POINT, /**< The up vector is oriented towards a point */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines which axis is locked and will not change when computing a cross product.
|
||||
*
|
||||
* Note that the side vector cannot be locked as it is always derived from the look and up vectors.
|
||||
*
|
||||
* @since 1.04.00
|
||||
*/
|
||||
enum LockedAxis
|
||||
{
|
||||
LOCK_LOOK, /**< The look vector is locked */
|
||||
LOCK_UP, /**< The up vector is locked */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Orientation presets to easily set up common orientations
|
||||
* @since 1.04.00
|
||||
*/
|
||||
enum OrientationPreset
|
||||
{
|
||||
CAMERA_PLANE_ALIGNED = PACK_ORIENTATION(LOCK_LOOK,LOOK_CAMERA_PLANE,UP_CAMERA), /**< Particles are oriented towards the camera plane (the most common) */
|
||||
CAMERA_POINT_ALIGNED = PACK_ORIENTATION(LOCK_LOOK,LOOK_CAMERA_POINT,UP_CAMERA), /**< Particles are oriented towards the camera point (better effect but more expensive) */
|
||||
DIRECTION_ALIGNED = PACK_ORIENTATION(LOCK_UP,LOOK_CAMERA_PLANE,UP_DIRECTION), /**< Particles are oriented function of their direction and try to look to the camera */
|
||||
AROUND_AXIS = PACK_ORIENTATION(LOCK_UP,LOOK_CAMERA_POINT,LOOK_AXIS), /**< Particles can only rotate around an axis and try to look to the camera */
|
||||
TOWARDS_POINT = PACK_ORIENTATION(LOCK_LOOK,LOOK_POINT,UP_CAMERA), /**< Particles are oriented towards a point in the universe */
|
||||
FIXED_ORIENTATION = PACK_ORIENTATION(LOCK_LOOK,LOOK_AXIS,UP_AXIS), /**< Particles have a fixed orientation in the universe */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Base Interface for rendering particles that can be oriented in a 3D world
|
||||
* @since 1.04.00
|
||||
*/
|
||||
class SPK_PREFIX Oriented3DRendererInterface
|
||||
{
|
||||
public :
|
||||
|
||||
///////////////
|
||||
// Parameter //
|
||||
///////////////
|
||||
|
||||
/**
|
||||
* @brief The look vector
|
||||
*
|
||||
* It is used in 2 LookOrientation modes :
|
||||
* <ul>
|
||||
* <li>LOOK_AXIS : The look vector is used as the axis</li>
|
||||
* <li>LOOK_POINT : The look vector is the point quads look to</li>
|
||||
* </ul>
|
||||
* In other modes the look vector is not used
|
||||
*/
|
||||
Vector3D lookVector;
|
||||
|
||||
/**
|
||||
* @brief The up vector
|
||||
*
|
||||
* It is used in 2 UpOrientation modes :
|
||||
* <ul>
|
||||
* <li>UP_AXIS : The up axis is used as the axis</li>
|
||||
* <li>UP_POINT : The up axis is the point quads will be oriented towards</li>
|
||||
* </ul>
|
||||
* In other modes the up vector is not used
|
||||
*/
|
||||
Vector3D upVector;
|
||||
|
||||
//////////////////
|
||||
// Constructors //
|
||||
//////////////////
|
||||
|
||||
/** @brief Constructor of Oriented3DRendererInterface */
|
||||
Oriented3DRendererInterface();
|
||||
|
||||
////////////////
|
||||
// Destructor //
|
||||
////////////////
|
||||
|
||||
/** @brief Destructor of Oriented3DRendererInterface */
|
||||
virtual inline ~Oriented3DRendererInterface() {}
|
||||
|
||||
/////////////
|
||||
// Setters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Sets the way quads are oriented in the universe
|
||||
*
|
||||
* This method allows to accuratly configure the orientation of quads.<br>
|
||||
* Another method with only one parameters that take presets exist.<br>
|
||||
* See setOrientation(OrientationPreset)
|
||||
*
|
||||
* @param lookOrientation : The way the look vector of the quad is set
|
||||
* @param upOrientation : The way the up vector of the quad is set
|
||||
* @param lockedAxis : tells which axis prevails over the other
|
||||
*/
|
||||
void setOrientation(LookOrientation lookOrientation,UpOrientation upOrientation,LockedAxis lockedAxis);
|
||||
|
||||
/**
|
||||
* @brief Sets the way quads are oriented in the universe
|
||||
*
|
||||
* This method takes some presets to orientate the quads.<br>
|
||||
* Another method that has more options to configure orientation exists<br>
|
||||
* See setOrientation(LookOrientation,UpOrientation,LockedAxis)
|
||||
*
|
||||
* @param orientation : the orientation preset of the quad
|
||||
*/
|
||||
void setOrientation(OrientationPreset orientation);
|
||||
|
||||
/////////////
|
||||
// Getters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Gets the look orientation of the quads
|
||||
* @return the look orientation of the quads
|
||||
*/
|
||||
inline LookOrientation getLookOrientation() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the up orientation of the quads
|
||||
* @return the up orientation of the quads
|
||||
*/
|
||||
inline UpOrientation getUpOrientation() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the locked axis (the one prevailing over the others)
|
||||
* @return the locked axis
|
||||
*/
|
||||
inline LockedAxis getLockedAxis() const;
|
||||
|
||||
protected :
|
||||
|
||||
// Orientation
|
||||
LookOrientation lookOrientation;
|
||||
UpOrientation upOrientation;
|
||||
LockedAxis lockedAxis;
|
||||
|
||||
inline bool precomputeOrientation3D(const Group& group,const Vector3D& look,const Vector3D& up,const Vector3D& pos);
|
||||
inline void computeGlobalOrientation3D();
|
||||
inline void computeSingleOrientation3D(const Particle& particle);
|
||||
|
||||
inline void scaleQuadVectors(const Particle& particle,float scaleX,float scaleY) const;
|
||||
inline void rotateAndScaleQuadVectors(const Particle& particle,float scaleX,float scaleY) const;
|
||||
|
||||
inline const Vector3D& quadUp() const;
|
||||
inline const Vector3D& quadSide() const;
|
||||
|
||||
private :
|
||||
|
||||
// Used to store modelview information
|
||||
mutable Vector3D mVLook;
|
||||
mutable Vector3D mVUp;
|
||||
mutable Vector3D mVPos;
|
||||
|
||||
// Used to store precomputed orientation
|
||||
mutable Vector3D globalLook;
|
||||
mutable Vector3D globalUp;
|
||||
|
||||
// Used to store the orientation of quads before scaling
|
||||
mutable Vector3D up;
|
||||
mutable Vector3D side;
|
||||
mutable Vector3D look;
|
||||
|
||||
// Is using rotation
|
||||
mutable int quadRotated;
|
||||
|
||||
// This is where are stored quad orientation info after computation
|
||||
mutable Vector3D sideQuad;
|
||||
mutable Vector3D upQuad;
|
||||
};
|
||||
|
||||
|
||||
inline LookOrientation Oriented3DRendererInterface::getLookOrientation() const
|
||||
{
|
||||
return lookOrientation;
|
||||
}
|
||||
|
||||
inline UpOrientation Oriented3DRendererInterface::getUpOrientation() const
|
||||
{
|
||||
return upOrientation;
|
||||
}
|
||||
|
||||
inline LockedAxis Oriented3DRendererInterface::getLockedAxis() const
|
||||
{
|
||||
return lockedAxis;
|
||||
}
|
||||
|
||||
inline const Vector3D& Oriented3DRendererInterface::quadUp() const
|
||||
{
|
||||
return upQuad;
|
||||
}
|
||||
|
||||
inline const Vector3D& Oriented3DRendererInterface::quadSide() const
|
||||
{
|
||||
return sideQuad;
|
||||
}
|
||||
|
||||
inline bool Oriented3DRendererInterface::precomputeOrientation3D(const Group& group,const Vector3D& modelViewLook,const Vector3D& modelViewUp,const Vector3D& modelViewPos)
|
||||
{
|
||||
mVLook = modelViewLook;
|
||||
mVUp = modelViewUp;
|
||||
mVPos = modelViewPos;
|
||||
|
||||
bool globalOrientation = true;
|
||||
|
||||
if (lookOrientation == LOOK_CAMERA_PLANE)
|
||||
globalLook = -mVLook;
|
||||
else if (lookOrientation == LOOK_AXIS)
|
||||
globalLook = lookVector;
|
||||
else
|
||||
globalOrientation = false;
|
||||
|
||||
if (upOrientation == UP_CAMERA)
|
||||
globalUp = mVUp;
|
||||
else if (upOrientation == UP_AXIS)
|
||||
globalUp = upVector;
|
||||
else globalOrientation = false;
|
||||
|
||||
quadRotated = group.getModel()->isEnabled(PARAM_ANGLE);
|
||||
|
||||
return globalOrientation;
|
||||
}
|
||||
|
||||
inline void Oriented3DRendererInterface::computeGlobalOrientation3D()
|
||||
{
|
||||
look = globalLook;
|
||||
up = globalUp;
|
||||
|
||||
crossProduct(up,look,side);
|
||||
if (lockedAxis == LOCK_LOOK)
|
||||
crossProduct(look,side,up);
|
||||
else if (quadRotated)
|
||||
{
|
||||
crossProduct(side,up,look);
|
||||
look.normalize();
|
||||
}
|
||||
|
||||
up.normalize();
|
||||
up *= 0.5f;
|
||||
|
||||
side.normalize();
|
||||
side *= 0.5f;
|
||||
}
|
||||
|
||||
inline void Oriented3DRendererInterface::computeSingleOrientation3D(const Particle& particle)
|
||||
{
|
||||
if (lookOrientation == LOOK_CAMERA_POINT)
|
||||
{
|
||||
look = mVPos;
|
||||
look -= particle.position();
|
||||
}
|
||||
else if (lookOrientation == LOOK_POINT)
|
||||
{
|
||||
look = lookVector;
|
||||
look -= particle.position();
|
||||
}
|
||||
else
|
||||
look = globalLook;
|
||||
|
||||
if (upOrientation == UP_DIRECTION)
|
||||
up = particle.velocity();
|
||||
else if (upOrientation == UP_POINT)
|
||||
{
|
||||
up = upVector;
|
||||
up -= particle.position();
|
||||
}
|
||||
else
|
||||
up = globalUp;
|
||||
|
||||
crossProduct(up,look,side);
|
||||
if (lockedAxis == LOCK_LOOK)
|
||||
crossProduct(look,side,up);
|
||||
else if (quadRotated)
|
||||
{
|
||||
crossProduct(side,up,look);
|
||||
look.normalize();
|
||||
}
|
||||
|
||||
side.normalize();
|
||||
side *= 0.5f;
|
||||
|
||||
up.normalize();
|
||||
up *= 0.5f;
|
||||
}
|
||||
|
||||
inline void Oriented3DRendererInterface::scaleQuadVectors(const Particle& particle,float scaleX,float scaleY) const
|
||||
{
|
||||
float size = particle.getParamCurrentValue(PARAM_SIZE);
|
||||
|
||||
sideQuad = side;
|
||||
sideQuad *= size * scaleX;
|
||||
|
||||
upQuad = up;
|
||||
upQuad *= size * scaleY;
|
||||
}
|
||||
|
||||
inline void Oriented3DRendererInterface::rotateAndScaleQuadVectors(const Particle& particle,float scaleX,float scaleY) const
|
||||
{
|
||||
float size = particle.getParamCurrentValue(PARAM_SIZE);
|
||||
|
||||
float angleTexture = particle.getParamCurrentValue(PARAM_ANGLE);
|
||||
float cosA = cos(angleTexture);
|
||||
float sinA = sin(angleTexture);
|
||||
|
||||
upQuad.x = (look.x * look.x + (1.0f - look.x * look.x) * cosA) * up.x
|
||||
+ (look.x * look.y * (1.0f - cosA) - look.z * sinA) * up.y
|
||||
+ (look.x * look.z * (1.0f - cosA) + look.y * sinA) * up.z;
|
||||
|
||||
upQuad.y = (look.x * look.y * (1.0f - cosA) + look.z * sinA) * up.x
|
||||
+ (look.y * look.y + (1.0f - look.y * look.y) * cosA) * up.y
|
||||
+ (look.y * look.z * (1.0f - cosA) - look.x * sinA) * up.z;
|
||||
|
||||
upQuad.z = (look.x * look.z * (1.0f - cosA) - look.y * sinA) * up.x
|
||||
+ (look.y * look.z * (1.0f - cosA) + look.x * sinA) * up.y
|
||||
+ (look.z * look.z + (1.0f - look.z * look.z) * cosA) * up.z;
|
||||
|
||||
crossProduct(upQuad,look,sideQuad);
|
||||
|
||||
sideQuad *= size * scaleX;
|
||||
upQuad *= size * scaleY;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,137 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// 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_POINTRENDERERINTERFACE
|
||||
#define H_SPK_POINTRENDERERINTERFACE
|
||||
|
||||
#include "Core/SPK_DEF.h"
|
||||
|
||||
namespace SPK
|
||||
{
|
||||
/**
|
||||
* @enum PointType
|
||||
* @brief Constants defining the type of points to render
|
||||
*/
|
||||
enum PointType
|
||||
{
|
||||
POINT_SQUARE, /**< Points are renderered as squares */
|
||||
POINT_CIRCLE, /**< Points are renderered as circles */
|
||||
POINT_SPRITE, /**< Points are renderered as point sprites (textured points) */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Base Interface for rendering particles with points
|
||||
* @since 1.04.00
|
||||
*/
|
||||
class PointRendererInterface
|
||||
{
|
||||
public :
|
||||
|
||||
/////////////////
|
||||
// Constructor //
|
||||
/////////////////
|
||||
|
||||
/**
|
||||
* @brief Constructor of PointRendererInterface
|
||||
* @param type : the initial type of this PointRendererInterface (must be supported by default by the platform)
|
||||
* @param size : the width of this PointRendererInterface
|
||||
*/
|
||||
inline PointRendererInterface(PointType type = POINT_SQUARE,float size = 1.0f);
|
||||
|
||||
////////////////
|
||||
// Destructor //
|
||||
////////////////
|
||||
|
||||
/** @brief Destructor of PointRendererInterface */
|
||||
virtual inline ~PointRendererInterface() {}
|
||||
|
||||
/////////////
|
||||
// Setters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Sets the type of points to use in this PointRendererInterface
|
||||
*
|
||||
* If the type is not supported by the platform, false is returned and the type per default is set.
|
||||
*
|
||||
* @param type : the type of points to use in this PointRendererInterface
|
||||
* @return true if the type can be set, false otherwise
|
||||
*/
|
||||
virtual inline bool setType(PointType type);
|
||||
|
||||
/**
|
||||
* @brief Sets the size of the points in this PointRendererInterface
|
||||
* @param size : the size of the points in this PointRendererInterface
|
||||
*/
|
||||
virtual inline void setSize(float size);
|
||||
|
||||
/////////////
|
||||
// Getters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Gets the type of points in this PointRendererInterface
|
||||
* @return the type of points in this PointRendererInterface
|
||||
*/
|
||||
inline PointType getType() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the size of points in this PointRendererInterface
|
||||
* @return the size of points in this PointRendererInterface
|
||||
*/
|
||||
inline float getSize() const;
|
||||
|
||||
protected :
|
||||
|
||||
PointType type;
|
||||
float size;
|
||||
};
|
||||
|
||||
|
||||
inline PointRendererInterface::PointRendererInterface(PointType type,float size) :
|
||||
type(type),
|
||||
size(size)
|
||||
{}
|
||||
|
||||
inline bool PointRendererInterface::setType(PointType type)
|
||||
{
|
||||
this->type = type;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void PointRendererInterface::setSize(float size)
|
||||
{
|
||||
this->size = size;
|
||||
}
|
||||
|
||||
inline PointType PointRendererInterface::getType() const
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
inline float PointRendererInterface::getSize() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,265 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// 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_QUADRENDERERINTERFACE
|
||||
#define H_SPK_QUADRENDERERINTERFACE
|
||||
|
||||
#include "Core/SPK_DEF.h"
|
||||
#include "Core/SPK_Particle.h"
|
||||
|
||||
namespace SPK
|
||||
{
|
||||
/**
|
||||
* @enum TexturingMode
|
||||
* @brief Constants defining the way to apply texture over the particles
|
||||
* @since 1.02.00
|
||||
*/
|
||||
enum TexturingMode
|
||||
{
|
||||
TEXTURE_NONE, /**< Constant telling no texturing is used */
|
||||
TEXTURE_2D, /**< Constant telling a 2D texture is used */
|
||||
TEXTURE_3D, /**< Constant telling a 3D texture is used */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Base Interface for rendering particles with quads
|
||||
* @since 1.04.00
|
||||
*/
|
||||
class SPK_PREFIX QuadRendererInterface
|
||||
{
|
||||
public :
|
||||
|
||||
//////////////////
|
||||
// Constructors //
|
||||
//////////////////
|
||||
|
||||
/**
|
||||
* @brief Constructor of QuadRendererInterface
|
||||
* @param scaleX the scale of the width of the quad
|
||||
* @param scaleY the scale of the height of the quad
|
||||
*/
|
||||
QuadRendererInterface(float scaleX = 1.0f,float scaleY = 1.0f);
|
||||
|
||||
////////////////
|
||||
// Destructor //
|
||||
////////////////
|
||||
|
||||
/** @brief Destructor of QuadRendererInterface */
|
||||
virtual inline ~QuadRendererInterface() {}
|
||||
|
||||
/////////////
|
||||
// Setters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Sets the texturing mode for this GLQuadRenderer
|
||||
*
|
||||
* The texturing mode defines whether or not to apply a texture
|
||||
* and if so which type of texture to apply (2D,3D or atlas).<br>
|
||||
* <br>
|
||||
* Note that the validity of the texturing mode depends on the rendering API below.<br>
|
||||
* The method returns true if the rendering mode can be set, false if it cannot
|
||||
*
|
||||
* @param mode : the texturing mode of this GLQuadRenderer
|
||||
* @return true if the rendering mode can be set, false if it cannot
|
||||
*/
|
||||
virtual inline bool setTexturingMode(TexturingMode mode);
|
||||
|
||||
/**
|
||||
* @brief Sets the cut of the texture
|
||||
*
|
||||
* This is available only if SPK::PARAM_TEXTURE_INDEX is enabled and texturing mode is TEXTURE_2D.<br>
|
||||
* <br>
|
||||
* Particles can be rendered only with a part of the texture depending on their texture index value.<br>
|
||||
* The cut can only be constant.<br>
|
||||
* The user defines in how many parts the texture must be divided in X and Y.<br>
|
||||
* The first index is located at the top left cut, the it goes from left to right and from top to bottom.<br>
|
||||
* <br>
|
||||
* For instance a cut with nbX = 3 and nbY = 2 will be as followed :
|
||||
* <br><i>
|
||||
* -------------<br>
|
||||
* | 0 | 1 | 2 |<br>
|
||||
* -------------<br>
|
||||
* | 3 | 4 | 5 |<br>
|
||||
* -------------</i><br>
|
||||
* <br>
|
||||
* By default nbX and nbY are equal to 1.<br>
|
||||
*
|
||||
* @param nbX : the number of cuts in the X axis
|
||||
* @param nbY : the number of cuts in the Y axis
|
||||
*/
|
||||
void setAtlasDimensions(size_t nbX,size_t nbY);
|
||||
|
||||
/**
|
||||
* @brief Sets the size ratio of this GLQuadRenderer
|
||||
*
|
||||
* These values defines how quads are scaled.
|
||||
* The height and width of a quad in the universe is defined as followed :
|
||||
* <ul>
|
||||
* <li><i>width = size * ratioX</i>
|
||||
* <li><i>height = size * ratioY</i>
|
||||
* </ul>
|
||||
*
|
||||
* @param scaleX : the scale of the width of the quad
|
||||
* @param scaleY : the scale of the height of the quad
|
||||
*/
|
||||
inline void setScale(float scaleX,float scaleY);
|
||||
|
||||
/////////////
|
||||
// Getters //
|
||||
/////////////
|
||||
|
||||
/**
|
||||
* @brief Gets the texturing mode of this GLQuadRenderer
|
||||
* @return the texturing mode of this GLQuadRenderer
|
||||
*/
|
||||
inline TexturingMode getTexturingMode() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the atlas dimension on the X axis
|
||||
*
|
||||
* See setAtlasDimensions(size_t,size_t) for more information
|
||||
*
|
||||
* @return the atlas dimension on the X axis
|
||||
*/
|
||||
inline size_t getAtlasDimensionX() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the atlas dimension on the Y axis
|
||||
*
|
||||
* See setAtlasDimensions(size_t,size_t) for more information
|
||||
*
|
||||
* @return the atlas dimension on the Y axis
|
||||
*/
|
||||
inline size_t getAtlasDimensionY() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the scale of the width of this GLQuadRenderer
|
||||
* @return the scale of the width of this GLQuadRenderer
|
||||
*/
|
||||
inline float getScaleX() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the scale of the height of this GLQuadRenderer
|
||||
* @return the scale of the height of this GLQuadRenderer
|
||||
*/
|
||||
inline float getScaleY() const;
|
||||
|
||||
protected :
|
||||
|
||||
TexturingMode texturingMode;
|
||||
|
||||
float scaleX;
|
||||
float scaleY;
|
||||
|
||||
// texture atlas info
|
||||
size_t textureAtlasNbX;
|
||||
size_t textureAtlasNbY;
|
||||
float textureAtlasW;
|
||||
float textureAtlasH;
|
||||
|
||||
inline void computeAtlasCoordinates(const Particle& particle) const;
|
||||
|
||||
inline float textureAtlasU0() const;
|
||||
inline float textureAtlasU1() const;
|
||||
inline float textureAtlasV0() const;
|
||||
inline float textureAtlasV1() const;
|
||||
|
||||
private :
|
||||
|
||||
// this is where textureAtlas are stored after computation
|
||||
mutable float atlasU0;
|
||||
mutable float atlasU1;
|
||||
mutable float atlasV0;
|
||||
mutable float atlasV1;
|
||||
};
|
||||
|
||||
|
||||
inline bool QuadRendererInterface::setTexturingMode(TexturingMode mode)
|
||||
{
|
||||
texturingMode = mode;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void QuadRendererInterface::setScale(float scaleX,float scaleY)
|
||||
{
|
||||
this->scaleX = scaleX;
|
||||
this->scaleY = scaleY;
|
||||
}
|
||||
|
||||
inline TexturingMode QuadRendererInterface::getTexturingMode() const
|
||||
{
|
||||
return texturingMode;
|
||||
}
|
||||
|
||||
inline size_t QuadRendererInterface::getAtlasDimensionX() const
|
||||
{
|
||||
return textureAtlasNbX;
|
||||
}
|
||||
|
||||
inline size_t QuadRendererInterface::getAtlasDimensionY() const
|
||||
{
|
||||
return textureAtlasNbY;
|
||||
}
|
||||
|
||||
inline float QuadRendererInterface::getScaleX() const
|
||||
{
|
||||
return scaleX;
|
||||
}
|
||||
|
||||
inline float QuadRendererInterface::getScaleY() const
|
||||
{
|
||||
return scaleY;
|
||||
}
|
||||
|
||||
inline float QuadRendererInterface::textureAtlasU0() const
|
||||
{
|
||||
return atlasU0;
|
||||
}
|
||||
|
||||
inline float QuadRendererInterface::textureAtlasU1() const
|
||||
{
|
||||
return atlasU1;
|
||||
}
|
||||
|
||||
inline float QuadRendererInterface::textureAtlasV0() const
|
||||
{
|
||||
return atlasV0;
|
||||
}
|
||||
|
||||
inline float QuadRendererInterface::textureAtlasV1() const
|
||||
{
|
||||
return atlasV1;
|
||||
}
|
||||
|
||||
inline void QuadRendererInterface::computeAtlasCoordinates(const Particle& particle) const
|
||||
{
|
||||
int textureIndex = static_cast<int>(particle.getParamCurrentValue(PARAM_TEXTURE_INDEX));
|
||||
atlasU0 = atlasU1 = static_cast<float>(textureIndex % textureAtlasNbX) / textureAtlasNbX;
|
||||
atlasV0 = atlasV1 = static_cast<float>(textureIndex / textureAtlasNbY) / textureAtlasNbY;
|
||||
atlasU1 += textureAtlasW;
|
||||
atlasV1 += textureAtlasH;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user