📄 gsparticlesystem.h
字号:
// GsParticleSystem.h: interface for the CGsParticleSystem class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_GSPARTICLESYSTEM_H__A9E0D0CA_CAE8_4DCE_AACC_CF74556CAA7D__INCLUDED_)
#define AFX_GSPARTICLESYSTEM_H__A9E0D0CA_CAE8_4DCE_AACC_CF74556CAA7D__INCLUDED_
#include "GSLib.h" // Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// RANDOM_NUM returns a float in the range 0.0f - 1.0f
#define RANDOM_NUM (((FLOAT)rand()-(FLOAT)rand())/RAND_MAX)
// RANDOM_VECTOR returns a D3DVECTOR whose components (x,y,Z) are between 0.0f and 1.0f
// remember that this is not a normalized vector.
#define RANDOM_VECTOR D3DVECTOR(RANDOM_NUM,RANDOM_NUM,RANDOM_NUM)
// max number of particles our ParticleSystem can support
#define MAX_PARTICLES 10000
// some defines for our ParticleSystem. This makes it easy to change settings
// by using defines and putting them all in one place
#define MIN_SPEED 0.0f // in world units / sec
#define MIN_LIFETIME 0.1f // in seconds
#define MIN_SPREAD 0.01f // in degrees
#define MIN_EMISSION 1.0f // in particles / sec
#define MIN_SIZE 0.5f // in world units
#define MIN_GRAVITY -5.0f // as a multiple of normal gravity
#define MIN_ALPHA 0.0f // as a ratio
#define MAX_SPEED 5000.0f // in world units / sec
#define MAX_LIFETIME 10.0f // in seconds
#define MAX_SPREAD 180.0f // in degrees
#define MAX_EMISSION 1000.0f // in particles / sec
#define MAX_SIZE 10.0f // in world units
#define MAX_GRAVITY 5.0f // as a multiple of normal gravity
#define MAX_ALPHA 1.0f // as a ratio
// useful macro to guarantee that values are within a given range
#define Clamp(x, min, max) x = (x<min ? min : x<max ? x : max);
#define GRAVITY D3DVECTOR(0.0f, -9.8f, 0.0f)
class GSLIB_API CGsParticle
{
public:
CGsParticle();
// CGsParticle(float life, float rotate, float scale, float alpha, GSANI* pAni);
virtual ~CGsParticle();
public:
// virtual FLAG Update(float fSec);
// float m_rotate;
// float m_life;
// float m_scale;
// float m_alpha;
// GSANI* m_pImage;
// Location of particle at last update
GVECTOR m_d3dvPrevLocation;
// Current location of particle
GVECTOR m_d3dvLocation;
// Current velocity of particle
GVECTOR m_d3dvVelocity;
// Current Color and how much color to add over time
D3DCOLORVALUE m_d3dcColor;
D3DCOLORVALUE m_d3dcColorDelta;
// Age of particle in seconds
float m_fAge;
// Age at which particle dies
float m_fLifetime;
// size of particle in world units and delta to add over time
float m_fSize;
float m_fSizeDelta;
// translucency and delta to add over time
// this may seem counter-intuitive, but 0.0f Alpha is transparent
float m_fAlpha;
float m_fAlphaDelta;
// gravity ratio and delta to add over time
// this is a proportion of normal gravity and can go negative
float m_fGravity;
float m_fGravityDelta;
//fix not used anymore
float m_bOrbiting;
LONG ani_index;
LONG frame_move;
protected:
// CGsKinetic m_movement;
};
class GSLIB_API CGsParticleEmitter
{
public:
LPCSTR GetName() {return m_key.c_str();}
INT GetParticlesPerSec() { return m_uParticlesPerSec;}
VOID SetParticlesPerSec(INT pps) { m_uParticlesPerSec = pps;}
D3DVECTOR GetLocation() { return m_d3dvLocation;}
VOID SetLocation(D3DVECTOR location);// { m_d3dvLocation = location;}
VOID SetPreviewLocation(D3DVECTOR location);// { m_d3dvLocation = location;}
float GetGravityStart() { return m_fGravityStart;}
VOID SetGravityStart(float Gravity) { m_fGravityStart = Gravity;}
float GetGravityVar() { return m_fGravityVar;}
VOID SetGravityVar(float Gravity) { m_fGravityVar = Gravity;}
float GetGravityEnd() { return m_fGravityEnd;}
VOID SetGravityEnd(float Gravity) { m_fGravityEnd = Gravity;}
float GetSizeStart() { return m_fSizeStart;}
VOID SetSizeStart(float Size) { m_fSizeStart = Size;}
float GetSizeVar() { return m_fSizeVar;}
VOID SetSizeVar(float Size) { m_fSizeVar = Size;}
float GetSizeEnd() { return m_fSizeEnd;}
VOID SetSizeEnd(float Size) { m_fSizeEnd = Size;}
float GetAlphaStart() { return m_fAlphaStart;}
VOID SetAlphaStart(float Alpha) { m_fAlphaStart = Alpha;}
float GetAlphaVar() { return m_fAlphaVar;}
VOID SetAlphaVar(float Alpha) { m_fAlphaVar = Alpha;}
float GetAlphaEnd() { return m_fAlphaEnd;}
VOID SetAlphaEnd(float Alpha) { m_fAlphaEnd = Alpha;}
D3DCOLORVALUE GetColorStart() { return m_d3dcColorStart;}
VOID SetColorStart(D3DCOLORVALUE Color) { m_d3dcColorStart = Color;}
D3DCOLORVALUE GetColorVar() { return m_d3dcColorVar;}
VOID SetColorVar(D3DCOLORVALUE Color) { m_d3dcColorVar = Color;}
D3DCOLORVALUE GetColorEnd() { return m_d3dcColorEnd;}
VOID SetColorEnd(D3DCOLORVALUE Color) { m_d3dcColorEnd = Color;}
float GetLife() { return m_fLife;}
VOID SetLife(float Life) { m_fLife = Life;}
float GetLifeVar() { return m_fLifeVar;}
VOID SetLifeVar(float Life) { m_fLifeVar = Life;}
float GetSpeed() { return m_fSpeed;}
VOID SetSpeed(float Speed) { m_fSpeed = Speed;}
float GetSpeedVar() { return m_fSpeedVar;}
VOID SetSpeedVar(float Speed) { m_fSpeedVar = Speed;}
float GetTheta() { return m_fTheta;}
VOID SetTheta(float Theta) { m_fTheta = Theta;}
BOOL IsAttractive() { return m_bIsAttractive;}
VOID SetAttractive(BOOL IsAttractive) { m_bIsAttractive = IsAttractive;}
BOOL GetSuppressed() { return m_bIsSuppressed;}
VOID SetSuppressed(BOOL IsSuppressed) { m_bIsSuppressed = IsSuppressed;}
BOOL IsColliding() { return m_bIsColliding;}
VOID SetColliding(BOOL IsColliding) { m_bIsColliding = IsColliding;}
BOOL IsGathering() { return m_isGathering;}
VOID SetGathering(BOOL bGathering) { m_isGathering = bGathering;}
LPCSTR GetANI(int index);
BOOL IsANIHasAlpha(int index);
BOOL SetANI(int index, LPCSTR str, BOOL hasAlpha);
BOOL SetANIBlend(int index, BOOL hasAlpha);
int GetNumParticlesActive() {return m_uParticlesAlive;}
public:
FLAG Update();
VOID SetGsEngine(CGsEngine* pEngine);
virtual FLAG Update(float fSec, BOOL bEmit=TRUE);
virtual HRESULT Render(GPOINT point);
BOOL Create(LPCSTR strConfig);
BOOL Export(LPCSTR strFile = NULL);
BOOL Load(CConfig &config);
BOOL Save(CConfig &config);
int GetNumParticles() {return m_uParticlesAlive;}
CGsParticleEmitter(CGsEngine* pEngine = NULL);
virtual ~CGsParticleEmitter();
protected:
//发生器初始设置
// GVECTOR m_splash_vector;
// float m_splash_angle;
// float m_life;
//
// float m_emit_freq;
//
// float m_alpha_born;
// float m_alpha_born_odds;
// float m_scale_born;
// float m_scale_born_odds;
// float m_life_born;
// float m_life_born_odds;
//粒子过程参数
// float m_alpha_inc;
// float m_scale_inc;
// float m_life_inc;
CGsEngine* m_pEngine;
protected:
BOOL m_isGathering;
// pointer back to main application in case we need to reference somethinng
// void* m_pApplication;
// An internal ID for us to remember which texture the system is using
unsigned int m_uTextureID;
// Particles Per Second to emit.
unsigned int m_uParticlesPerSec;
// Particles currently active
unsigned int m_uParticlesAlive;
// Last known location of System ( used for interpolation ).
D3DVECTOR m_d3dvPrevLocation;
// current location of system in world space
D3DVECTOR m_d3dvLocation;
// current velocity as a Vector ( cause that's what velocity is ) :)
D3DVECTOR m_d3dvVelocity;
// current Direction of System. Particles are emitted using this vector + some variation
D3DVECTOR m_d3dvDirection;
//General comment on my Start,Var,End system of parameter calculation.
//As the particle ages, we keep interpolating between the Start and End parameters.
//The Var parameter is always there to keep things a little randomized.
//It is useful to change particle parameters over time to simulate various natural phenomenon
//For example, Gas expands as it dissipates and as such takes up more screen space but also
//becomes more transparent.
//So in this instance we might use a SizeStart of 1.0f and a SizeEnd of 4.0f (depending on what looks best).
//And then we might set AlphaStart to 0.8f and AlphaEnd to 0.0f.
// used as a percentage of normal gravity. Note: to simulate wind or other forces you could make Gravity a Vector
// which could have components
float m_fGravityStart;
float m_fGravityVar;
float m_fGravityEnd;
// Size of the particles in World units
float m_fSizeStart;
float m_fSizeVar;
float m_fSizeEnd;
// Translucency of particles. Alpha 0 = invisible, Alpha 1 = full visibility
float m_fAlphaStart;
float m_fAlphaVar;
float m_fAlphaEnd;
// Color of particles, the color of the particles when they start and end.
// The color is interpolated linearly between these 2 values over time.
D3DCOLORVALUE m_d3dcColorStart;
D3DCOLORVALUE m_d3dcColorVar;
D3DCOLORVALUE m_d3dcColorEnd;
// Speed is a scalar and is combined with the normalized direction vector of the system to get a
// Velocity vector.
float m_fSpeed;
float m_fSpeedVar;
// Life of the particle in seconds,
float m_fLife;
float m_fLifeVar;
// Picture a vector in space with a start and an end
// now picture that the vector goes through the center of a Cone such
// that the tip of the cone is at the start of the vector and the bottom of the cone is at the end of the vector
// Now picture the angle from the vector out to the edge of the cone. This is m_fTheta.
// If it were Zero, the cone would collapse down to the vector and be a line.
// If it were 90 degrees, then the cone would turn into a hemisphere ( half of a sphere )
// ANd finally if this value were 180 degrees, then the cone would turn into a Sphere
// this values defines how much randomness the particles have in their directional vector
float m_fTheta;
// whether or not the system is moving autonomously
BOOL m_bIsMoving;
// whether or not the particles are attracted to the system
BOOL m_bIsAttractive;
// whether or not we are allowed to emit particles or whether they build up
BOOL m_bIsSuppressed;
// whether or not our particles collide with the ground plane
BOOL m_bIsColliding;
// age in seconds of the system
float m_fAge;
// last moment in time that we updated the system
float m_fTimeLastUpdate;
// this is a value that allows us to emit very precise amounts of particles.
// what if we want 0.5 particles per second ? 0.5 is not a full particle ( we don't round up ) so we can't emit one yet
// so we remember what we wanted to emit and add that next time we try to emit some more particles.
// Think about a faucet that is leaking very slowly. The drop slowly gets bigger and bigger till there is enough mass to allow
// it to break free.
float m_fEmissionResidue;
// a fixed array of particles.
// there are many ways to do this, some are better in certain situations.
// this version keeps us from dynamically allocating and freeing memory
// but also limits us to MAX_PARTICLES and also always costs us MAX_PARTICLES
// some people use linked lists of Live Particles and Free Particles.
CGsParticle m_rParticles[MAX_PARTICLES];
struct PARTICLE_ANI
{
GSANI* ptr_ani;
BOOL has_alpha;
};
std::vector<PARTICLE_ANI> m_ani_buf;
KEY m_key;
};
class GSLIB_API CGsParticleSystem
{
public:
CGsParticleSystem(CGsEngine* pEngine);
virtual ~CGsParticleSystem();
public:
BOOL Create(LPCSTR strConfig, GVECTOR pos);
protected:
CGsEngine* m_pEngine;
CGsKinetic m_movement;
CConfig m_config;
float m_life_inc;
};
#endif // !defined(AFX_GSPARTICLESYSTEM_H__A9E0D0CA_CAE8_4DCE_AACC_CF74556CAA7D__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -