Archived

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

Pik

Damn Dots!

Recommended Posts

Ok, I need to get this working as soon as possible. I have a class that includes the data for my vertices, but I can''t get the data into the vertex buffer and have it show up correctly. I can statically set the vertex buffer, but I''m trying to dynamically copy the data in since its sort of a sprite system. This is what I have now // Custom Vertex stuff #define D3DFVF_KERNVERTEX (D3DFVF_XYZ |D3DFVF_TEX1) struct KERNVERTEX { D3DXVECTOR3 position; // vertex position float tu1, tv1; // texture coordinates }; // Particle class class CParticle { public: KERNVERTEX m_vertices[2]; // 3 verts triangle //D3DXVECTOR3 m_vertices[2]; // failed attempt... ... // Stuff left out b/c space }; // Particle Manager class CParticleManager { CParticle m_particles[NUMBERPARTICLES]; LPDIRECT3DDEVICE8 m_pd3dDevice; LPDIRECT3DVERTEXBUFFER8 m_kernsVB; ... // other stuff, like con, desc, init... } //Particle drawing, creation, etc. Functions in CParticleManager int CCob::CreateKerns() { HRESULT hr; KERNVERTEX* pVertices; // 2 test tri''s // setting the particle locations in particle array m_particles[0].SetVertex( D3DXVECTOR3( 0.0f, 0.0f, 0.0f ), 0); m_particles[0].SetVertex( D3DXVECTOR3( 0.0f, 10.0f, 0.0f ), 1); m_particles[0].SetVertex( D3DXVECTOR3( 0.0f, 0.0f, 10.0f ), 2); m_particles[1].SetVertex( D3DXVECTOR3(10.0f, 0.0f, 0.0f ), 0); m_particles[1].SetVertex( D3DXVECTOR3(10.0f, 0.0f, 10.0f ), 1); m_particles[1].SetVertex( D3DXVECTOR3( 0.0f, 0.0f, 10.0f ), 2); if( FAILED( hr = m_kernsVB->Lock( 0, 0, (BYTE**)&pVertices,0 ) ) ) return DXTRACE_ERR( "Lock", hr ); m_kernsVB->Unlock(); return 0; } int CParticleManager::DrawKerns() { HRESULT hr; KERNVERTEX* pVertices; if( FAILED( hr = m_kernsVB->Lock( 0,0, (BYTE**)&pVertices,0))) return DXTRACE_ERR( "Lock", hr); for( int i=0; i>=m_numParticles; i++) { memcpy( pVertices+sizeof(KERNVERTEX)*i, &m_kernels.m_vertices, sizeof( 3*sizeof(KERNVERTEX) ) ); // Then some failed things... // pVertices[(i )* sizeof(KERNVERTEX) ].position = m_particles[i].GetVertex(0); // pVertices[(i+1)* sizeof(KERNVERTEX) ].position = m_particles[i].GetVertex(1); // pVertices[(i+2)* sizeof(KERNVERTEX) ].position = m_particles[i].GetVertex(2); } m_kernsVB->Unlock(); m_pd3dDevice->SetStreamSource(0, m_kernsVB, sizeof( KERNVERTEX) ); m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, m_numKernels ); return(0); } Thats the blunt of the material. Once again, the data is in the particle class and I need to get it into my vertex buffer. I''ve tried many different ways and none work. THere might be a dumb error or two in that code, so don''t say its a missing parenthesis or something. I cut it down a bit to save space and such. Thanks to anyone that tries to help!

Share this post


Link to post
Share on other sites
KERNVERTEX m_vertices[2]; // 3 verts triangle
//D3DXVECTOR3 m_vertices[2]; // failed attempt...

Should at least have 3 vertices in there ([3], not [2]) for a triangle, which is why this doesn''t work:

// Then some failed things...
// pVertices[(i )* sizeof(KERNVERTEX) ].position = m_particles.GetVertex(0);
// pVertices[(i+1)* sizeof(KERNVERTEX) ].position = m_particles[i].GetVertex(1);
// pVertices[(i+2)* sizeof(KERNVERTEX) ].position = m_particles[i].GetVertex(2);


Jim Adams

Share this post


Link to post
Share on other sites
Ok, I got the array stuff fixed, but it still isn''t working. I''ve messed and changed a few things. All the data structures are the same. Here is the main 2 segments:

// Set 3 test triangles
m_particles[0].SetVertex( D3DXVECTOR3( 10.0f,10.0f, 0.0f ), 0);
m_particles[0].SetVertex( D3DXVECTOR3( 10.0f, 0.0f, 0.0f ), 1);
m_particles[0].SetVertex( D3DXVECTOR3( 0.0f, 0.0f, 0.0f ), 2);
// This is the same thing, diff way
m_particles[1].m_vertices[0] = D3DXVECTOR3( 0.0f,-10.0f, 0.0f );
m_particles[1].m_vertices[1] = D3DXVECTOR3( 10.0f, 0.0f, 0.0f );
m_particles[1].m_vertices[2] = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
m_particles[2].SetVertex( D3DXVECTOR3( 0.0f, 0.0f, 0.0f ), 0);
m_particles[2].SetVertex( D3DXVECTOR3( 0.0f,-10.0f, 10.0f ), 1);
m_particles[2].SetVertex( D3DXVECTOR3( 10.0f, 0.0f, 0.0f ), 2);

// Drawing routine
KERNVERTEX* pVertices;
if( FAILED( hr = m_kernsVB->Lock( 0,0, (BYTE**)&pVertices,0)))
return DXTRACE_ERR( "Lock", hr);

// This is supposed to copy points to VB
for( int i=0; i {
pVertices[i*3 ].position = m_particles.GetVertex(0);
pVertices[i*3+1].position = m_particles[i].GetVertex(1);
pVertices[i*3+2].position = m_particles[i].GetVertex(2);
}
m_kernsVB->Unlock();

// And finally the draw
m_pd3dDevice->SetStreamSource(0, m_kernsVB, sizeof( KERNVERTEX) );
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, m_numParticles );

The really strange part about this is that the first particle works and shows up like its supposed to. The other two aren''t anywhere in sight though. The first one works, so it shouldn''t be the vertex buffer breaking. I really think the problem has to be in copying the stuff to the vertex buffer.

m_particles holds an array of the particles. It also holds 3 D3DXVECTOR3''s that need to be put in the vertex buffer. Thanks t0 Jim for pointing out that big flaw with arrays to me.

Share this post


Link to post
Share on other sites
I'd thought of that and included one of these so culling is cut off:
m_pd3d->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE);

Thanks for trying though

--------

Holy Crap! I tried rearranging the points and managed to get them working! Apparently the culling isn't cut off or something. I placed the function above in the RestoreDevices() function of the DX Appwizard. So now I guess the question is, why the hell is culling still kicking in?

Edited by - Pik on February 6, 2002 12:23:13 PM

Share this post


Link to post
Share on other sites