Files
Leviathan/Client/Game/engine/Renderer/KPrimitiveFXParticle.h
T
2026-06-01 12:46:52 +02:00

239 lines
6.4 KiB
C++

#pragma once
#include "K3DTypes.h"
#include "KResource.h"
//#include <vector>
#include "KPrimitive.h"
#include "KSmartPtr.h"
class K3DRenderDevice;
const unsigned short c_Particle_Size = 2000;
class KCommonParticleIndexBuffer
{
private:
WORD* m_pIdxBuffer;
KCommonParticleIndexBuffer()
{
m_pIdxBuffer = new WORD[c_Particle_Size*6];
for(int i = 0; i < c_Particle_Size; ++i)
{
m_pIdxBuffer[i*6+0] = (unsigned short)(i*4+2);
m_pIdxBuffer[i*6+1] = (unsigned short)(i*4+1);
m_pIdxBuffer[i*6+2] = (unsigned short)(i*4+0);
m_pIdxBuffer[i*6+3] = (unsigned short)(i*4+1);
m_pIdxBuffer[i*6+4] = (unsigned short)(i*4+2);
m_pIdxBuffer[i*6+5] = (unsigned short)(i*4+3);
}
}
public:
static KCommonParticleIndexBuffer& GetInstance();
~KCommonParticleIndexBuffer()
{
SAFE_DELETE_ARRAY( m_pIdxBuffer );
}
public:
const WORD* GetCommonIndexbuffer( unsigned short nSize )
{
if( nSize < c_Particle_Size ) return m_pIdxBuffer;
assert( false );
return NULL;
}
};
#define GetIndexbufferInstance() KCommonParticleIndexBuffer::GetInstance()
////////////////////////////////////////////////////////////////////////////////////////
/// KBillboardPrimitive
////////////////////////////////////////////////////////////////////////////////////////
class KBillboardPrimitive : public KPrimitive
{
public:
KBillboardPrimitive()
{
m_bUseAdditiveRender = false;
}
void SetAdditiveRenderMode( bool bUseAdditive )
{
m_bUseAdditiveRender = bUseAdditive;
}
bool GetAdditiveRenderMode()
{
return m_bUseAdditiveRender;
}
virtual float GetDistance( const K3DVector &vCam ) = 0;
protected:
bool m_bUseAdditiveRender;
};
////////////////////////////////////////////////////////////////////////////////////////
/// KFXBillboardPrimitive
////////////////////////////////////////////////////////////////////////////////////////
DECL_SPTR(KResFXBillboard)
class KFXBillboardPrimitive : public K3DPrimitive
{
public:
KFXBillboardPrimitive();
virtual ~KFXBillboardPrimitive();
void SetBillboardRes( KResFXBillboard *res );
KResFXBillboard *GetBillboardRes();
void SetTransform( const K3DMatrix &transform );
const K3DMatrix &GetTransform();
void SetColor ( const KColor &color );
const KColor &GetColor();
void SetUV( float _l, float _t, float _r, float _b );
void GetUV( float *_l, float *_t, float *_r, float *_b );
void SetFixedAxis( int nAxis );
void SetAngle( float fAngle );
virtual void Render( KViewportObject *viewport, class K3DRenderDevice *dev, bool bUseAccum = true );
virtual float GetDistance( const K3DVector &vCam )
{
return ( vCam - m_matTransform.GetPosVector() ).SquareMagnitude();
}
protected:
void _UpdateBillboard(KViewportObject* pViewport, K3DRenderDevice* pDev);
protected:
static int s_nVertexStride;
bool m_bUseAdditiveRender;
float l,t,r,b;
K3DMatrix m_matTransform;
KColor m_colSprite;
KResFXBillboardSPtr m_spRes;
K3DSPRITEVERTEX m_VtxBuf[4];
int m_nFixedAxis;
float m_fAngle;
};
////////////////////////////////////////////////////////////////////////////////////////
/// KFXParticlePrimitive
////////////////////////////////////////////////////////////////////////////////////////
DECL_SPTR(KResFXParticle)
class KFXParticlePrimitive : public K3DPrimitive
{
public:
KFXParticlePrimitive();
virtual ~KFXParticlePrimitive();
void ResetParticleCount();
void SetParticleRes( KResFXParticle *res );
KResFXParticle *GetParticleRes();
/**
Set total number of particle.
If old _PARTICLE array is exist, delete that array and reallocate memory according to count argument value.
*/
void SetParticleCount( int count );
/**
@param num Index of __PARTICLE array
@param pos Particle's position.
The m_nDrawParticleCount value is increased when this function is called.
*/
/// Set rendering source rectangle.
void GetParticleUV( int num, float *_l, float *_t, float *_r, float *_b );
/// This struct has each particle's position, color, width,height,source information.
struct _PARTICLE
{
K3DVertex pos;
KColor color;
float fWidth, fHeight;
float l, t, r, b;
bool newparticle;
K3DMatrix matParent;
_PARTICLE() : newparticle(false)
{
K3DMatrixIdentity( matParent );
}
};
void SetParticleInfo( int num, _PARTICLE& particle );
const _PARTICLE &GetParticle( int num );
int GetMaxParticleCount();
/// Get Drawable particle's count.
int GetDrawParticleCount();
/// Do not anything in this function!
virtual void Render( KViewportObject *viewport, class K3DRenderDevice *dev, bool bUseAccum = true );
virtual float GetDistance( const K3DVector &vCam )
{
if( m_nDrawParticleCount > 0 )
{
if( m_pParticles )
return ( vCam - K3DVector(0,0, m_pParticles->pos.z) ).SquareMagnitude();
}
return 0.f;
}
void NewParticle( int num );
void SetAttachParent( bool bAttachParent );
bool IsValidIndexBuffer() { return m_pIdxBuf == NULL ? false : true; }
protected:
inline void _UpdateParticle(KViewportObject* pViewport, K3DRenderDevice* pDev);
protected:
static int s_nVertexStride;
int m_nParticleCount;
int m_nDrawParticleCount;
_PARTICLE* m_pParticles;
bool m_bIsAttachParent;
K3DSPRITEVERTEX* m_pVtxBuf;
const WORD* m_pIdxBuf;
KResFXParticleSPtr m_spRes;
};
////////////////////////////////////////////////////////////////////////////////////////
// KFXAfterImagePrimitive
////////////////////////////////////////////////////////////////////////////////////////
/**
KFXAfterImagePrimitive Description.
- This class has two custom vertex's array which render afterimage.
- The render function do real-rendering action. ( render to device)
*/
class K3DTexture;
class KFXAfterImagePrimitive : public K3DPrimitive
{
public:
KFXAfterImagePrimitive();
virtual ~KFXAfterImagePrimitive();
void Clear();
void SetTransform( const K3DMatrix &transform );
void SetTexture( K3DTexture *pTex );
/// Allocates new memorys to two custom vertex's array which size is determined by a nDepth value.
void Initialize ( int nDepth );
void ReserveVtx(int nCount);
void PopVertex(int nCount);
void PushVertex( const K3DSPRITEVERTEX &vtx1, const K3DSPRITEVERTEX &vtx2);
void UpdateVertex();
void RemoveVertex();
virtual void Render( KViewportObject *viewport, class K3DRenderDevice *dev, bool bUseAccum = true );
void SetMoveAdded(const K3DVertex & vMoveAdded);
protected:
int m_nDepth;
int m_nDrawCount;
int m_nCurPos;
int m_nVertexStride;
K3DSPRITEVERTEX* m_pVtx;
K3DTextureSPtr m_spTex;
K3DMatrix m_Transform;
};