Skip to main content
GameDev.net gamedev.net
🔒 Locked

Particle Problem

Started by PickDX May 20, 2003 at 1:07 PM 3 replies 350+ views
Original Post
PickDX
PickDX
I'm trying to figure out this bit of particle code - Here's a screenshot of what I'm getting. It's like a light show, the poly jumps around when I move and is very erratic - like what others have experienced, but I can't seem to fix it using what was prescribed to them. If anyone can tell me what I'm doing wrong, would greatly appreciate it. // The Particle vertex buffer and texture IDirect3DVertexBuffer8 *g_pParticleVB = NULL; IDirect3DTexture8 *g_pParticleTexture = NULL; #define VERTEXFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1) ~ // The 3D vertex format and descriptor typedef struct { FLOAT x, y, z; // 3D coordinates D3DCOLOR Diffuse; // Color FLOAT u, v; // Texture coordinates } s3DVertex; ~ BOOL CGraphics::SetupParticle() { BYTE *Ptr; s3DVertex Verts[4] = { { -50.0f, 50.0f, 0.0f, 0xFFFFFFFF, 0.0f, 0.0f }, { 50.0f, 50.0f, 0.0f, 0xFFFFFFFF, 1.0f, 0.0f }, { -50.0f, 0.0f, 0.0f, 0xFFFFFFFF, 0.0f, 1.0f }, { 50.0f, 0.0f, 0.0f, 0xFFFFFFFF, 1.0f, 1.0f } }; if(FAILED(m_pD3DDevice -> CreateVertexBuffer(sizeof(s3DVertex)*4, 0, VERTEXFVF, D3DPOOL_DEFAULT, &g_pParticleVB))) return FALSE; if(FAILED(g_pParticleVB -> Lock(0,0, (BYTE**)&Ptr, 0))) return FALSE; memcpy(Ptr, Verts, sizeof(Verts)); g_pParticleVB -> Unlock(); if(FAILED(D3DXCreateTextureFromFile(m_pD3DDevice, "Particle.bmp", &g_pParticleTexture))) return FALSE; return TRUE; } BOOL CGraphics::FrameParticle(float x, float y, float z, float scale) { static D3DMATERIAL8 Mat; static BOOL InitMat = TRUE; static DWORD Counter = timeGetTime(); if(timeGetTime() < Counter +30) return TRUE; Counter = timeGetTime(); D3DXMATRIX matWorld, matView, matTransposed; D3DXMATRIX matTranslation, matScale; D3DMATERIAL8 d3dm; float Red = (float)(rand() % 101) / 100.0f; float Green = (float)(rand() % 101) / 100.0f; float Blue = (float)(rand() % 101) / 100.0f; m_pD3DDevice -> SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); m_pD3DDevice -> SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); m_pD3DDevice -> SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); m_pD3DDevice -> SetRenderState(D3DRS_AMBIENT, 0xffffffff); m_pD3DDevice -> SetStreamSource(0, g_pParticleVB, sizeof(sVertex)); //m_pD3DDevice -> SetVertexShader(VERTEXFVF); m_pD3DDevice -> SetTexture(0, g_pParticleTexture); ZeroMemory(&d3dm, sizeof(D3DMATERIAL8)); d3dm.Diffuse.r = d3dm.Ambient.r = Red; d3dm.Diffuse.g = d3dm.Ambient.g = Green; d3dm.Diffuse.b = d3dm.Ambient.b = Blue; d3dm.Diffuse.a = d3dm.Ambient.a = 10.0f; m_pD3DDevice -> SetMaterial(&d3dm); D3DXMatrixScaling(&matScale, scale, scale, scale); D3DXMatrixTranslation(&matTranslation, x, y, z); m_pD3DDevice -> GetTransform(D3DTS_VIEW, &matView); D3DXMatrixTranspose(&matTransposed, &matView); D3DXMatrixMultiply(&matWorld, &matScale, &matTransposed); D3DXMatrixMultiply(&matWorld, &matWorld, &matTranslation); m_pD3DDevice -> SetTransform(D3DTS_WORLD, &matWorld); m_pD3DDevice -> DrawPrimitive(D3DPT_TRIANGLESTRIP, 0,2); m_pD3DDevice -> SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); m_pD3DDevice->SetTexture(0, NULL); return TRUE; } [edited by - PickDX on May 20, 2003 2:12:22 PM]
PickDX
PickDX
bump

anyone?
Foxhound
Foxhound
Hi,

what''s that sVertex?
in your code i can only see a s3DVertex defined!
maybe the size of an sVertex is not the same as an s3DVertex?!?!

m_pD3DDevice -> SetStreamSource(0, g_pParticleVB, sizeof(sVertex));

or maybe i''ve missed something
Sonicmage
Sonicmage
I could be wrong but it looks like your transformations are being done in the wrong order. Usually, you want to scale before you translate which means the translation matrix multiply comes FIRST, followed by the scaling.
Sonicmage
Sonicmage
Also, try playing around with using point sprites. You can use the point size rather than the scaling.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.