Archived

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

How to Normal

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

Recommended Posts

This is quite basic question. I am trying to draw 3d box with just 8 vertices in D3dIM. This can be possible when I call "DrawIndexedPrimitive()" 6 times(each call for each surface of box). Of course, I have 6 Index array which are pointing the vertices. // pDev : IDirect3DDevice7 // pVertices : vertex array which contains 8 vertice for box // pIndices : array of Indices which are pointing vertex // pIndices[0]: indices of vertices for Surface 0 of box // pIndices[1]: indices of vertices for Surface 1 of box for(int i=0; i<6; i++) { pDev->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX, (LPVOID)pVertices, 8, pIndices, 4, D3DDP_WAIT); } But problem is normal vector.. Should I calculate normal vector whenever calling DrawIndexedPrimitive each time?

Share on other sites
NO!!!! Absolutely not. calculating normals takes a lot of work by the processor. precalculate your normals

<(o)>

Share on other sites
Thankyou...

Actual code is like the following...
Here You can see SetSideNormal() Function.
I don''t like to do like this...
Is there any way?
I need to save memory and consider performance...

WORD g_nBoxIndices[6][4] = { {0, 1, 3, 2}, {1, 5, 2, 6},
{7, 6, 4, 5}, {3, 7, 0, 4}, {3, 2, 7, 6}, {4, 5, 0, 1}};

float g_fBoxNormals[6][3] = { {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, -1.0f, 0.0f},
{1.0f, 0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f} };

void SetSideNormal(D3DVERTEX *pVtx, int nSide)
{
for (int i=0; i<4; i++)
{
pVtx[g_nBoxIndices[nSide]].nx = g_fBoxNormals[nSide][0];
pVtx[g_nBoxIndices[nSide][i]].ny = g_fBoxNormals[nSide][1];
pVtx[g_nBoxIndices[nSide][i]].nz = g_fBoxNormals[nSide][2];
}
}

void DrawBox()
{
//...

for(int i=0; i<6; i++)
{
SetSideNormal(m_pBoxes[nBox]->pVertex, i);
pDev->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX, (LPVOID)pBoxVertex, 8, g_nBoxIndices[i], 4, D3DDP_WAIT);
}
//...
}

• 16
• 9
• 15
• 10
• 13
×

Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!