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

Vertex(help)

Started by habuTM Aug 3, 2002 at 8:08 PM 3 replies 350+ views
Original Post
habuTM
habuTM
I''m new in direct (don''t laugth) and i want to know is this type of vertex nesesary if i want to make cube struct Cvertex { D3DVECTOR sposition;//models space D3DVECTOR snormal; //s= struct D3DMATRICE smatrice;//transformation }; Queston is do I need matrice and do i need moedls space coordinates and how i make that cube store that cube to i buffer
What is life
Colin Jeanne
Colin Jeanne
A matrix is never part of the vertex definition.



I will not make a list of links... I will not make a list of links... I will not make a list of links...
Invader''s Realm
habuTM
habuTM
thanks
What is life
Dirge
Dirge
Here, I just did this code about an hour ago. it should help:


m_iNumVerts = 4;
m_iNumFaces = 2;

// Allocate the Vertex Buffer to store the Verices.
if ( FAILED( m_pd3dDevice->CreateVertexBuffer( m_iNumVerts * sizeof( VERTEX_XYZ_DIFF_TEX ), 0, D3DFVF_VERTEX_XYZ_DIFF_TEX,
D3DPOOL_MANAGED, &m_pVertexBuffer ) ) )
return FALSE;

// Lock the Vertex Buffer for modification.
VERTEX_XYZ_DIFF_TEX *pVert = NULL;
m_pVertexBuffer->Lock( 0, 0, (BYTE **)&pVert, 0 );
pVert[0].x = 1.0f; pVert[0].y = 0.0f; pVert[0].z = 0.0f; pVert[0].color = 0xFFFFFFFF; // Right Bottom.
pVert[1].x = 1.0f; pVert[1].y = 0.0f; pVert[1].z = 1.0f; pVert[1].color = 0xFFFFFFFF; // Right Top.
pVert[2].x = 0.0f; pVert[2].y = 0.0f; pVert[2].z = 0.0f; pVert[2].color = 0xFFFFFFFF; // Left Bottom.
pVert[3].x = 0.0f; pVert[3].y = 0.0f; pVert[3].z = 1.0f; pVert[3].color = 0xFFFFFFFF; // Left Top.
// Unlock the Vertex Buffer for use.
m_pVertexBuffer->Unlock();

// The number of Indices is the total number of faces * 3 (since each face has 3 vertices).
if ( FAILED( m_pd3dDevice->CreateIndexBuffer( m_iNumFaces * 3 * sizeof(WORD),
D3DUSAGE_WRITEONLY, D3DFMT_INDEX16,
D3DPOOL_DEFAULT, &m_pIndexBuffer ) ) )
return FALSE;

// Lock the Index Buffer for modification.
WORD *pIndex = NULL;
m_pIndexBuffer->Lock( 0, 0, (BYTE **)&pIndex, 0 );
pIndex[0] = 0;
pIndex[1] = 1;
pIndex[2] = 2;
pIndex[3] = 2;
pIndex[4] = 1;
pIndex[5] = 3;
// Unlock the Index Buffer for use.
m_pIndexBuffer->Unlock();


Here''s how to render:

m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
m_pd3dDevice->SetVertexShader( D3DFVF_VERTEX_XYZ_DIFF_TEX );
m_pd3dDevice->SetStreamSource( 0, m_pVertexBuffer, sizeof( VERTEX_XYZ_DIFF_TEX ) );
m_pd3dDevice->SetIndices( m_pIndexBuffer, 0 );
m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, m_iNumVerts, 0, m_iNumFaces );


Just put in 8 vertices instead of 4 and 12 faces instead of 2. Make sense? If not read the Direct3D docs.

"Love all, trust a few. Do wrong to none." - Shakespeare

Dirge - Aurelio Reis
www.CodeFortress.com
Current Causes:
Nissan sues Nissan
"Artificial Intelligence: the art of making computers that behave like the ones in movies."www.CodeFortress.com
habuTM
habuTM
That was just what I needed


have a break
What is life

Topic Locked

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

Sign in to reply to this topic.