Archived

This topic is now archived and is closed to further replies.

DirectX Multiple Point Lists not working.

This topic is 5137 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a question...I have a point list used for a smoke particle system. When I introduce a new point list however, the new point list behaves incorrectly. Even when the new point list is based on the exact same class as the old. What would cause this? -=Lohrno PS: I know this is kind of a cross-post but I have not been able to get help in the DirectX forum after like 5 bumps...Feel free to delete if this is deemed objectionable. [edited by - Lohrno on November 13, 2003 1:51:06 PM]

Share this post


Link to post
Share on other sites
I think the reason no one is helping is because they need more information on your problem. You need to explain it further and list the code where the problem is occuring.

Do you mean you''re deriving a class from a particle list class, and the new class doesn''t behave the same as the base?

Jiia

Share this post


Link to post
Share on other sites
Okay, I have a class for a smoke particle system like so:


class ParticleSprite //This is a basic class to store position and color.

{
public:
float x;
float y;
float z;
float xvel;
float yvel;
float zvel;
DWORD color;
};

class ParticleSpriteEmitter //A Base ParticleSpriteEmitter Class, default behavior will be smoke that rises up.

{
public:
ParticleSpriteEmitter();
~ParticleSpriteEmitter();
void InitVB();
void LoadTex(char *Tex);
virtual void Render();
void UpdateVB();
virtual void Spawn(); //Should Create a new Particle.

virtual void Update(); //Should define behavior, and check for termination condition.

virtual int CheckDestroy(ParticleSprite P); //Checks for termination condition.

float x;
float y;
float z;
float top;
vector<ParticleSprite> Particles;
int number;
DWORD Rate;
DWORD SpawnTime;
DWORD Timer;
float r;
LPDIRECT3DVERTEXBUFFER9 pVB;
LPDIRECT3DTEXTURE9 pTexture;
};

void ParticleSpriteEmitter::Update()
{

O("ParticleSpriteEmitter: Entering Update function");
int i = 0;
int a = 0;
if (number == 0)
{
O("Number is 0, so spawning...");
Spawn();
O("Spawned...");
SpawnTime = timeGetTime() + Rate;
return;
}
else
{

O("Number is nonzero, so looping...");
for (i = 0;i<number;i++)
{
if(CheckDestroy(Particles[i]))
{
Particles.erase(&Particles[i]);
O("Deleting Particle...");
number--;
i = 0;
}
}
if (number >0)
{

for (i = 0;i<number;i++)
{
a = 75-(int)Particles[i].y;
if (a<0) a =0;
Particles[i].x += Particles[i].xvel;
Particles[i].y += Particles[i].yvel;
Particles[i].z += Particles[i].zvel;
Particles[i].color = D3DCOLOR_ARGB(a,255,255,255);
}
}
if (timeGetTime()>=SpawnTime)
{
O("Spawning....");
SpawnTime = timeGetTime()+Rate;
for(i = 0;i<20;i++)
Spawn();
}

}
O("ParticleSpriteEmitter: Leaving Update..");
}


void ParticleSpriteEmitter::Spawn()
{
float SideVel = 0.5f;
char str[90];
ParticleSprite NewP; //New Particle

NewP.x = x+(10*((rand()%10000-5000)/10000.0f));;
NewP.y = y;
NewP.z = z;
NewP.x = (SideVel*((rand()%10000-5000)/10000.0f));
NewP.xvel = -1*NewP.x;
NewP.zvel = 1.0f;
NewP.yvel = 1.0f;
number++;
Particles.push_back(NewP);
}

int ParticleSpriteEmitter::CheckDestroy(ParticleSprite P)
{
if (P.y > 75.0f) return 1;
else return 0;
}

void ParticleSpriteEmitter::UpdateVB()
{
char str[290];
int i = 0;
PTVERTEX *verts = new PTVERTEX[number];

r+=0.1f;
for (i = 0;i<number;i++)
{
verts[i].x = Particles[i].x;
verts[i].y = Particles[i].y;
verts[i].z = Particles[i].z;
verts[i].color = Particles[i].color;

}



VOID* pVertices;
pVB->Lock( 0, sizeof(PTVERTEX)*number, (void**)&pVertices, 0 );
memcpy( pVertices, verts, sizeof(PTVERTEX)*number );
pVB->Unlock();

}


void ParticleSpriteEmitter::Render()
{
//Spawn();

UpdateVB();
D3DXMATRIXA16 matWorld;
D3DXMatrixTranslation(&matWorld,x,y,z);
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

g_pd3dDevice->SetFVF(D3DFVF_PTVERTEX);
g_pd3dDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_POINTSCALEENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_POINTSIZE, FtoDW(1.5f) );
g_pd3dDevice->SetRenderState( D3DRS_POINTSIZE_MIN, FtoDW(0.5f) );
g_pd3dDevice->SetRenderState( D3DRS_POINTSCALE_A, FtoDW(0.20f) );
g_pd3dDevice->SetRenderState( D3DRS_POINTSCALE_B, FtoDW(0.20f) );
g_pd3dDevice->SetRenderState( D3DRS_POINTSCALE_C, FtoDW(0.20f) );
g_pd3dDevice->SetTexture(0,pTexture);
// RemoveMenu(

g_pd3dDevice->SetStreamSource( 0, pVB, 0, sizeof(PTVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_PTVERTEX );
if (FAILED( g_pd3dDevice->DrawPrimitive( D3DPT_POINTLIST, 0, number ))) OutputDebugString("DRAWPRIMITIVE FAILED!");



}

void ParticleSpriteEmitter::InitVB()
{
if (FAILED(
g_pd3dDevice->CreateVertexBuffer( sizeof(PTVERTEX), D3DUSAGE_WRITEONLY, D3DFVF_PTVERTEX, D3DPOOL_DEFAULT, &pVB, NULL )
))
OutputDebugString("CREATEVERTEXBUFFER FAILED!!!! AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!!!!!");
}

ParticleSpriteEmitter::ParticleSpriteEmitter()
{
number = 0;
pVB = 0;
pTexture = 0;
x = 0;
y = 0;
z = 0;
r = 0.0f;
Rate = 40;
Timer = timeGetTime();

}

ParticleSpriteEmitter::~ParticleSpriteEmitter()
{
pTexture->Release();
pVB->Release();
}

void ParticleSpriteEmitter::LoadTex(char *Tex)
{
if (FAILED(D3DXCreateTextureFromFileEx(g_pd3dDevice, Tex, 0, 0, 0, 0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT , 0, NULL, NULL, &pTexture)))
OutputDebugString("Texure Load FAILED!!!!!\n");
}


No, I'm not deriving a new class from this...

When I initialize, update, and render one object of this class, it is fine. However, if I simply add another object, weird things happen.

This happens with any point list class I use. In the case of the smoke, if I have two instances of the ParticleSpriteEmitter class, and they are not in the right order (way different positions...) the second one loses the bottom half of it's particles.

I also had a Point list consisting of one fire Point Sprite. When I tried to render it, it would appear at the top of my smoke.

-=Lohrno

[edited by - Lohrno on November 13, 2003 11:47:18 PM]

Share this post


Link to post
Share on other sites