2006-01-19 12:19:55 +01:00
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
// File Name: ParticleEmitter.h
|
|
|
|
// Date: 6/29/05
|
|
|
|
// Author: Will Dull
|
|
|
|
// Purpose: The base particle and emitter
|
|
|
|
// classes.
|
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _PARTICLEEMITTER_H_
|
|
|
|
#define _PARTICLEEMITTER_H_
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
#include "maths/Vector3D.h"
|
2006-02-17 03:02:18 +01:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
class CTexture;
|
2006-01-19 12:19:55 +01:00
|
|
|
|
|
|
|
class CEmitter
|
2004-05-29 22:56:24 +02:00
|
|
|
{
|
2006-01-21 21:01:17 +01:00
|
|
|
static const int HALF_RAND = (RAND_MAX / 2);
|
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
public:
|
2006-01-19 12:19:55 +01:00
|
|
|
struct tColor
|
|
|
|
{
|
|
|
|
unsigned char r, g, b;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tParticle
|
|
|
|
{
|
|
|
|
// base stuff
|
2007-05-02 14:07:08 +02:00
|
|
|
CVector3D pos; // Current position 12
|
|
|
|
CVector3D dir; // Current direction with speed 12
|
2006-01-19 12:19:55 +01:00
|
|
|
float alpha; // Fade value 4
|
|
|
|
float alphaDelta; // Change of fade 4
|
|
|
|
tColor color; // Current color of particle 3
|
|
|
|
tColor deltaColor; // Change of color 3
|
|
|
|
short life; // How long it will last 2
|
|
|
|
|
|
|
|
// particle text stuff
|
2007-05-02 14:07:08 +02:00
|
|
|
CVector3D endPos; // For particle texture 12
|
2006-01-19 12:19:55 +01:00
|
|
|
bool inPos; // 1
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
tParticle* next; // pointer for link lists 4
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2006-01-19 12:19:55 +01:00
|
|
|
tParticle()
|
|
|
|
{
|
|
|
|
next = 0;
|
|
|
|
}
|
|
|
|
};
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2006-01-19 12:19:55 +01:00
|
|
|
//struct tParticleNode
|
|
|
|
//{
|
2007-05-02 14:07:08 +02:00
|
|
|
// tParticle* pParticle;
|
|
|
|
// tParticleNode* next;
|
2006-01-19 12:19:55 +01:00
|
|
|
//};
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2006-01-19 12:19:55 +01:00
|
|
|
protected:
|
2007-05-02 14:07:08 +02:00
|
|
|
CTexture* texture; // Texture ID
|
2006-01-19 12:19:55 +01:00
|
|
|
bool isFinished; // tells the engine it's ready to be deleted
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2006-01-19 12:19:55 +01:00
|
|
|
// Transformation Info
|
2007-05-02 14:07:08 +02:00
|
|
|
CVector3D pos; // XYZ Position
|
|
|
|
CVector3D finalPos; // Final position of the particles (IF IMPLOSION)
|
2006-01-19 12:19:55 +01:00
|
|
|
float yaw, yawVar; // Yaw and variation
|
|
|
|
float pitch, pitchVar; // Pitch and variation
|
|
|
|
float speed, speedVar; // Speed and variation
|
|
|
|
float updateSpeed; // Controls how fast emitter is updated.
|
|
|
|
float size; // size of the particles (if point sprites is not enabled)
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2006-01-19 12:19:55 +01:00
|
|
|
// Particle
|
2007-05-02 14:07:08 +02:00
|
|
|
tParticle* heap; // Pointer to beginning of array
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
tParticle* openList; // linked list of unused particles
|
|
|
|
tParticle* usedList; // linked list of used particles
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2006-01-19 12:19:55 +01:00
|
|
|
int blend_mode; // Method used to blend particles.
|
|
|
|
int max_particles; // Maximum particles emitter can put out
|
|
|
|
int particleCount; // Total emitted right now
|
|
|
|
int emitsPerFrame, emitVar; // Emits per frame and variation
|
|
|
|
int life, lifeVar; // Life count and variation (in Frames)
|
|
|
|
int emitterLife; // Life of the emitter
|
|
|
|
bool decrementLife; // Controls whether or not the particles life is decremented every update.
|
|
|
|
bool decrementAlpha; // Controls whether or not the particles alpha is decremented every update.
|
2007-05-02 14:07:08 +02:00
|
|
|
bool RenderParticles; // Controls the rendering of the particles.
|
2006-01-19 12:19:55 +01:00
|
|
|
tColor startColor, startColorVar; // Current color of particle
|
|
|
|
tColor endColor, endColorVar; // Current color of particle
|
|
|
|
|
|
|
|
// Physics
|
2007-05-02 14:07:08 +02:00
|
|
|
CVector3D force; // Forces that affect the particles
|
2006-01-19 12:19:55 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
CEmitter(const int MAX_PARTICLES = 4000, const int lifetime = -1, int textureID = 0);
|
2007-05-02 14:07:08 +02:00
|
|
|
virtual ~CEmitter(void);
|
2004-05-29 22:56:24 +02:00
|
|
|
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
// note: functions are virtual and overridable so as to suit the
|
|
|
|
// specific particle needs.
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
virtual bool Setup() { return false; }
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
virtual bool AddParticle();
|
|
|
|
|
|
|
|
virtual bool Update() { return false; }
|
|
|
|
|
|
|
|
virtual bool Render();
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2006-01-19 12:19:55 +01:00
|
|
|
inline float RandomNum()
|
|
|
|
{
|
|
|
|
int rn;
|
|
|
|
rn = rand();
|
|
|
|
return ((float)(rn - HALF_RAND) / (float)HALF_RAND);
|
|
|
|
}
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2006-01-19 12:19:55 +01:00
|
|
|
inline char RandomChar()
|
|
|
|
{
|
|
|
|
return (unsigned char)(rand() >> 24);
|
|
|
|
}
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
inline void RotationToDirection(float pitch, float yaw, CVector3D* direction)
|
2006-01-19 12:19:55 +01:00
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
direction->X = (float)(-sin(yaw)* cos(pitch));
|
|
|
|
direction->Y = (float)sin(pitch);
|
|
|
|
direction->Z = (float)(cos(pitch)* cos(yaw));
|
2006-01-19 12:19:55 +01:00
|
|
|
}
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2006-01-19 12:19:55 +01:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Accessors
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////
|
2007-05-02 14:07:08 +02:00
|
|
|
float GetPosX() { return pos.X; }
|
|
|
|
float GetPosY() { return pos.Y; }
|
|
|
|
float GetPosZ() { return pos.Z; }
|
|
|
|
CVector3D GetPosVec() { return pos; }
|
|
|
|
float GetFinalPosX() { return finalPos.X; }
|
|
|
|
float GetFinalPosY() { return finalPos.Y; }
|
|
|
|
float GetFinalPosZ() { return finalPos.Z; }
|
|
|
|
bool IsFinished(void) { return isFinished; }
|
|
|
|
int GetEmitterLife() { return emitterLife; }
|
|
|
|
int GetParticleCount() { return particleCount; }
|
|
|
|
float GetUpdateSpeed() { return updateSpeed; }
|
|
|
|
int GetMaxParticles(void) { return max_particles; }
|
|
|
|
tColor GetStartColor(void) { return startColor; }
|
|
|
|
tColor GetStartColorVar(void) { return startColorVar; }
|
|
|
|
tColor GetEndColor(void) { return endColor; }
|
|
|
|
tColor GetEndColorVar(void) { return endColorVar; }
|
|
|
|
int GetBlendMode(void) { return blend_mode; }
|
|
|
|
float GetSize(void) { return size; }
|
|
|
|
float GetYaw(void) { return yaw; }
|
|
|
|
float GetYawVar(void) { return yawVar; }
|
|
|
|
float GetPitch(void) { return pitch; }
|
|
|
|
float GetPitchVar(void) { return pitchVar; }
|
|
|
|
float GetSpeed(void) { return speed; }
|
|
|
|
float GetSpeedVar(void) { return speedVar; }
|
|
|
|
int GetEmitsPerFrame(void) { return emitsPerFrame; }
|
|
|
|
int GetEmitVar(void) { return emitVar; }
|
|
|
|
int GetLife(void) { return life; }
|
|
|
|
int GetLifeVar(void) { return lifeVar; }
|
|
|
|
float GetForceX(void) { return force.X; }
|
|
|
|
float GetForceY(void) { return force.Y; }
|
|
|
|
float GetForceZ(void) { return force.Z; }
|
2004-05-29 22:56:24 +02:00
|
|
|
|
|
|
|
|
2006-01-19 12:19:55 +01:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Mutators
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////
|
2007-05-02 14:07:08 +02:00
|
|
|
void SetPosX(float posX) { pos.X = posX; }
|
|
|
|
void SetPosY(float posY) { pos.Y = posY; }
|
|
|
|
void SetPosZ(float posZ) { pos.Z = posZ; }
|
|
|
|
inline void SetPosVec(const CVector3D& newPos)
|
2006-01-19 12:19:55 +01:00
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
pos = newPos;
|
2006-01-19 12:19:55 +01:00
|
|
|
}
|
2007-05-02 14:07:08 +02:00
|
|
|
void SetFinalPosX(float finalposX) { finalPos.X = finalposX; }
|
|
|
|
void SetFinalPosY(float finalposY) { finalPos.Y = finalposY; }
|
|
|
|
void SetFinalPosZ(float finalposZ) { finalPos.Z = finalposZ; }
|
|
|
|
void SetTexture(CTexture* id) { texture = id; }
|
|
|
|
void SetIsFinished(bool finished) { isFinished = finished; }
|
|
|
|
void SetEmitterLife(int life) { emitterLife = life; }
|
|
|
|
void SetUpdateSpeed(float speed) { updateSpeed = speed; }
|
|
|
|
void SetLife(int newlife) { life = newlife; }
|
|
|
|
void SetLifeVar(int newlifevar) { lifeVar = newlifevar; }
|
|
|
|
void SetSpeed(float newspeed) { speed = newspeed; }
|
|
|
|
void SetSpeedVar(float newspeedvar) { speedVar = newspeedvar; }
|
|
|
|
void SetYaw(float newyaw) { yaw = newyaw; }
|
|
|
|
void SetYawVar(float newyawvar) { yawVar = newyawvar; }
|
|
|
|
void SetPitch(float newpitch) { pitch = newpitch; }
|
|
|
|
void SetPitchVar(float newpitchvar) { pitchVar = newpitchvar; }
|
|
|
|
void SetStartColor(tColor newColor) { startColor = newColor; }
|
|
|
|
void SetStartColorVar(tColor newColorVar) { startColorVar = newColorVar; }
|
|
|
|
void SetEndColor(tColor newColor) { endColor = newColor; }
|
|
|
|
void SetEndColorVar(tColor newColorVar) { endColorVar = newColorVar; }
|
|
|
|
void SetStartColorR(int newColorR) { startColor.r = newColorR; }
|
|
|
|
void SetStartColorG(int newColorG) { startColor.g = newColorG; }
|
|
|
|
void SetStartColorB(int newColorB) { startColor.b = newColorB; }
|
|
|
|
void SetStartColorVarR(int newColorVarR) { startColorVar.r = newColorVarR; }
|
|
|
|
void SetStartColorVarG(int newColorVarG) { startColorVar.g = newColorVarG; }
|
|
|
|
void SetStartColorVarB(int newColorVarB) { startColorVar.b = newColorVarB; }
|
|
|
|
void SetEndColorR(int newColorR) { endColor.r = newColorR; }
|
|
|
|
void SetEndColorG(int newColorG) { endColor.g = newColorG; }
|
|
|
|
void SetEndColorB(int newColorB) { endColor.b = newColorB; }
|
|
|
|
void SetEndColorVarR(int newColorVarR) { endColorVar.r = newColorVarR; }
|
|
|
|
void SetEndColorVarG(int newColorVarG) { endColorVar.g = newColorVarG; }
|
|
|
|
void SetEndColorVarB(int newColorVarB) { endColorVar.b = newColorVarB; }
|
|
|
|
inline void SetBlendMode(int blendmode)
|
2006-01-19 12:19:55 +01:00
|
|
|
{
|
|
|
|
if(blendmode >= 1 && blendmode <= 4)
|
|
|
|
blend_mode = blendmode;
|
|
|
|
else
|
|
|
|
blend_mode = 1;
|
|
|
|
}
|
2007-05-02 14:07:08 +02:00
|
|
|
void SetEmitsPerFrame(int emitsperframe) { emitsPerFrame = emitsperframe; }
|
|
|
|
void SetEmitVar(int emitvar) { emitVar = emitvar; }
|
|
|
|
void SetForceX(float forceX) { force.X = forceX; }
|
|
|
|
void SetForceY(float forceY) { force.Y = forceY; }
|
|
|
|
void SetForceZ(float forceZ) { force.Z = forceZ; }
|
|
|
|
void SetSize(float newSize) { size = newSize; }
|
|
|
|
void SetRenderParticles(bool render) { RenderParticles = render; }
|
2004-05-29 22:56:24 +02:00
|
|
|
};
|
|
|
|
|
2006-01-21 21:01:17 +01:00
|
|
|
#endif
|