   Particle System Problem! ("Pretty" screenshots too)
  I recently rewrote my particle system code because the coloring was done badly and wasn't working right but now my problem is far worse. It seems to me like the particles are ENORMOUS (they shouldn't be) and the texture and coloring aren't working properly. I hope someone can help me with this problem.SCREENSHOTS:http://24.167.180.51/programming/problem.phpCODE:Particle.h  #ifndef PARTICLE__H#define PARTICLE__H#include <d3dx9.h>class PARTICLEEMITTER;class PARTICLE{public:D3DXVECTOR3 m_Position;D3DXVECTOR3 m_Velocity;D3DCOLOR    m_Color;float  m_Age;float  m_Life;PARTICLEEMITTER* m_Parent;PARTICLE();};#endifParticle.cpp #include <d3dx9.h>#include "particle.h"float Rand(float min = 0.0f, float max = 1.0f);PARTICLE::PARTICLE(){m_Position = m_Velocity = D3DXVECTOR3(0.0f, 0.0f, 0.0f);m_Color = D3DCOLOR_XRGB(255, 255, 255);m_Parent = NULL;m_Age = 0.0f;m_Life = 1.0f;}ParticleEmitter.h   #include "particle.h"class PARTICLEEMITTER{public:LPDIRECT3DVERTEXBUFFER9 m_pVB;LPDIRECT3DTEXTURE9 m_pTexture;D3DXVECTOR3 m_Position;D3DXVECTOR3 m_Velocity;PARTICLE*   m_Particles;DWORD  m_NumParticles;PARTICLE*   m_DeadParticles;DWORD  m_NumDeadParticles;PARTICLEEMITTER();~PARTICLEEMITTER();void Init(DWORD);void Update(float);void Render();};ParticleEmitter.cpp   #include <d3dx9.h>#include <iostream>#include "particleemitter.h"using namespace std;#define SAFE_RELEASE(x) if(x != NULL) x->Release(); x=NULL;float Rand(float, float);extern LPDIRECT3DDEVICE9 g_pd3dDevice;DWORD  FtoDW(float f);// {return *((DWORD*)&f);}struct PARTICLEVERTEX{D3DXVECTOR3 pos;D3DCOLOR   diffuse;};#define D3DFVF_PARTICLEVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE)PARTICLEEMITTER::PARTICLEEMITTER(){m_DeadParticles = m_Particles = NULL;m_pTexture = NULL;m_pVB = NULL;m_Position = m_Velocity = D3DXVECTOR3(0.0f, 0.0f, 0.0f);}PARTICLEEMITTER::~PARTICLEEMITTER(){SAFE_RELEASE(m_pVB);SAFE_RELEASE(m_pTexture);}void PARTICLEEMITTER::Init(DWORD NumParticles){m_NumParticles = NumParticles;m_Particles = new PARTICLE[NumParticles];D3DXCreateTextureFromFileEx(g_pd3dDevice, "star.bmp", 0, 0, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, NULL, NULL, NULL, &m_pTexture);//g_pd3dDevice->CreateVertexBuffer(NumParticles*sizeof(PARTICLEVERTEX), D3DUSAGE_POINTS, D3DFVF_PARTICLEVERTEX, D3DPOOL_MANAGED, &m_pVB, NULL);for(DWORD i=0; i < m_NumParticles; i++){m_Particles[i].m_Color = D3DCOLOR_XRGB((int)Rand(0.0f, 255.0f), (int)Rand(0.0f, 255.0f), (int)Rand(0.0f, 255.0f));m_Particles[i].m_Position = D3DXVECTOR3(Rand(0.0f, 5.0f), Rand(0.0f, 5.0f), Rand(0.0f, 5.0f));}}void PARTICLEEMITTER::Update(float elapsed){PARTICLEVERTEX* pVertices;if(m_pVB == NULL){cout << "NULL VB for all " << m_NumParticles << " particles!" << endl;HRESULT hr = g_pd3dDevice->CreateVertexBuffer(m_NumParticles*sizeof(PARTICLEVERTEX), D3DUSAGE_POINTS/* | D3DUSAGE_DYNAMIC*/, D3DFVF_PARTICLEVERTEX, D3DPOOL_MANAGED, &m_pVB, NULL);cout << "Creating new one... hr = " << hr << endl;return;}HRESULT h = m_pVB->Lock(0, 0, (void**)&pVertices, 0);if(FAILED(h))cout << "Lock Failed" << endl;for(DWORD i=0; i < m_NumParticles; i++){//m_Particles.m_Age += elapsed;</font><font color=gray>//m_Particles.m_Parent = this;</font><font color=gray>//m_Particles.m_Position += m_Particles.m_Velocity*elapsed;</font><font color=gray>//if(m_Particles.m_Age &lt; m_Particles.m_Life)</font><font color=gray><font color=gray>//{</font></font>pVertices[<font color=purple>i</font>].diffuse = m_Particles[<font color=purple>i</font>].m_Color;pVertices[<font color=purple>i</font>].pos = m_Particles[<font color=purple>i</font>].m_Position;<font color=gray><font color=gray>//}</font></font><font color=gray>//else</font><font color=gray><font color=gray>//{</font></font><font color=gray>//pVertices.diffuse = D3DCOLOR_ARGB(0, 0, 0, 0);</font><font color=gray>//pVertices.pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);</font><font color=gray><font color=gray>//}</font></font>}m_pVB-&gt;Unlock();cout &lt;&lt; <font color=darkred>"Update Complete!"</font> &lt;&lt; endl;}<font color=blue>void</font> PARTICLEEMITTER::Render(){<font color=blue>if</font>(m_pVB == NULL)<font color=blue>return</font>;g_pd3dDevice-&gt;SetRenderState( D3DRS_ZWRITEENABLE, FALSE );    g_pd3dDevice-&gt;SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );    g_pd3dDevice-&gt;SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );    g_pd3dDevice-&gt;SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );g_pd3dDevice-&gt;SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE );    g_pd3dDevice-&gt;SetRenderState( D3DRS_POINTSCALEENABLE,  TRUE );    g_pd3dDevice-&gt;SetRenderState( D3DRS_POINTSIZE,FtoDW(0.08f) );    g_pd3dDevice-&gt;SetRenderState( D3DRS_POINTSIZE_MIN, FtoDW(0.00f) );    g_pd3dDevice-&gt;SetRenderState( D3DRS_POINTSCALE_A,  FtoDW(0.00f) );    g_pd3dDevice-&gt;SetRenderState( D3DRS_POINTSCALE_B,  FtoDW(0.00f) );    g_pd3dDevice-&gt;SetRenderState( D3DRS_POINTSCALE_C,  FtoDW(1.00f) );g_pd3dDevice-&gt;SetStreamSource(0, m_pVB, 0, <font color=blue>sizeof</font>(PARTICLEVERTEX));g_pd3dDevice-&gt;SetFVF(D3DFVF_PARTICLEVERTEX);g_pd3dDevice-&gt;SetTexture(0, m_pTexture);g_pd3dDevice-&gt;DrawPrimitive(D3DPT_POINTLIST, 0, m_NumParticles); <font color=gray>//This is the line I commented out to change between the two screenshots.</font>g_pd3dDevice-&gt;SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE );    g_pd3dDevice-&gt;SetRenderState( D3DRS_POINTSCALEENABLE,  TRUE );g_pd3dDevice-&gt;SetRenderState( D3DRS_ZWRITEENABLE, TRUE );    g_pd3dDevice-&gt;SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );cout &lt;&lt; <font color=darkred>"Render Complete!"</font> &lt;&lt; endl;}</pre><!–ENDSCRIPT–>Thank you so much!<SPAN CLASS=editedby>[edited by - ms291052 &#111;n February 9, 2004 11:10:09 PM]</SPAN>   
  bump ;  Hmm it maybe a longshot but it looks like that the FVF is set incorrectly. Maybe you changed the FVF for the sprites and didnt change it back to the terrain FVF... !? ;  What is your pointsize max set at?-=Lohrno ;  struct PARTICLEVERTEX{D3DXVECTOR3 pos;D3DCOLOR   diffuse;};#define D3DFVF_PARTICLEVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE)How is that incorrect?[edit]Ah, nevermind, I see what you mean. Since my "engine" only likes .x levels, I have a terrain exporter, and that terrain is in .x format. Thus, it's drawn like standard meshes (so I never explicitly set the FVF).[/edit]I suppose I never set D3DRS_POINTSIZE_MAX. According to the docs the default is 64.0f, is that bad?   [edited by - ms291052 on February 9, 2004 4:43:45 PM];quote:Original post by ms291052  I suppose I never set D3DRS_POINTSIZE_MAX. According to the docs the default is 64.0f, is that bad?Yeah that''s pretty huge.  Try somewhere between 3 and 10...-=Lohrno ;  I tried 3.0f, 10.0f, and 0.08f and none of them changed anything . Any other thoughts? ;  sry to off topic here put how you put that gun there that a mesh? or a pic? how you did that.. looks good btw.. bout your particles gonna review how i did mine and ill try to figure your problem out ;  Yeah it looks kinda like the textures got changed around in a bad way...if you didn't set FVF back it would probably give you complete garbage...if you didnt set it, it might cause odd effects...That pattern kind of looks like you're using clamp...I hope you aren't.   Either that or the Texture coords are being messed with.Here, I have a little function that shows renderstates in outputdebugstring, take a look...-=Lohrno   [edited by - Lohrno on February 9, 2004 8:25:53 PM];  switch(UserName){case Lohrno :{quote:Original post by Madprog  sry to off topic here put how you put that gun there that a mesh? or a pic? how you did that.. looks good btw.. bout your particles gonna review how i did mine and ill try to figure your problem out   The guns are (for now) bitmaps that are just rendered on quads and as of now they''re not my artwork :-[. Eventually they will be meshes and my artwork... but that comes after I get my engine 99.9% working.}//Notice there is NO break herecase Madprog:{Thank you both for looking into my problem. I double checked everything and the FVF and RenderStates appear to be fine (I use about 4-5 different FVFs and none of the others act weird, but I didn''t specifically check them).} break;default:{Any other ideas?} 