Archived

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

how to calculate normals for my cube?

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

Recommended Posts

this is my cube(x,y,z,nx,ny,nz,tu,tv):
//front

{-0.5f, 0.5f,-0.5f,0,0,0,0.0f,0.0f},
{ 0.5f, 0.5f,-0.5f,0,0,0,1.0f,0.0f},
{-0.5f,-0.5f,-0.5f,0,0,0,0.0f,1.0f},//triangle 1

{-0.5f,-0.5f,-0.5f,0,0,0,0.0f,1.0f},
{ 0.5f,-0.5f,-0.5f,0,0,0,1.0f,1.0f},
{ 0.5f, 0.5f,-0.5f,0,0,0,1.0f,0.0f},//triangle 2

//back

{-0.5f, 0.5f, 0.5f,0,0,0,1.0f,0.0f},
{ 0.5f, 0.5f, 0.5f,0,0,0,0.0f,0.0f},
{-0.5f,-0.5f, 0.5f,0,0,0,1.0f,1.0f},//triangle 1

{-0.5f,-0.5f, 0.5f,0,0,0,1.0f,1.0f},
{ 0.5f,-0.5f, 0.5f,0,0,0,0.0f,1.0f},
{ 0.5f, 0.5f, 0.5f,0,0,0,0.0f,0.0f},//triangle 2

//top

{-0.5f, 0.5f, 0.5f,0,0,0,0.0f,0.0f},
{ 0.5f, 0.5f, 0.5f,0,0,0,1.0f,0.0f},
{-0.5f, 0.5f,-0.5f,0,0,0,0.0f,1.0f},//triangle 1

{-0.5f, 0.5f,-0.5f,0,0,0,0.0f,1.0f},
{ 0.5f, 0.5f,-0.5f,0,0,0,1.0f,1.0f},
{ 0.5f, 0.5f, 0.5f,0,0,0,1.0f,0.0f},//triangle 2

//bottom

{-0.5f,-0.5f, 0.5f,0,0,0,1.0f,0.0f},
{ 0.5f,-0.5f, 0.5f,0,0,0,0.0f,0.0f},
{-0.5f,-0.5f,-0.5f,0,0,0,1.0f,1.0f},//triangle 1

{-0.5f,-0.5f,-0.5f,0,0,0,1.0f,1.0f},
{ 0.5f,-0.5f,-0.5f,0,0,0,0.0f,1.0f},
{ 0.5f,-0.5f, 0.5f,0,0,0,0.0f,0.0f},//triangle 2

//right

{ 0.5f, 0.5f,-0.5f,0,0,0,0.0f,0.0f},
{ 0.5f, 0.5f, 0.5f,0,0,0,1.0f,0.0f},
{ 0.5f,-0.5f,-0.5f,0,0,0,0.0f,1.0f},//triangle 1

{ 0.5f,-0.5f,-0.5f,0,0,0,0.0f,1.0f},
{ 0.5f,-0.5f, 0.5f,0,0,0,1.0f,1.0f},
{ 0.5f, 0.5f, 0.5f,0,0,0,1.0f,0.0f},//triangle 2

//left

{-0.5f, 0.5f,-0.5f,0,0,0,1.0f,0.0f},
{-0.5f, 0.5f, 0.5f,0,0,0,0.0f,0.0f},
{-0.5f,-0.5f,-0.5f,0,0,0,1.0f,1.0f},//triangle 1

{-0.5f,-0.5f,-0.5f,0,0,0,1.0f,1.0f},
{-0.5f,-0.5f, 0.5f,0,0,0,0.0f,1.0f},
{-0.5f, 0.5f, 0.5f,0,0,0,0.0f,0.0f},//triangle 2


I tried to calculate it by this function (from andypike.com)
D3DXVECTOR3 cCube::GetTriangeNormal(D3DXVECTOR3* vVertex1, D3DXVECTOR3* vVertex2, D3DXVECTOR3* vVertex3)
{
D3DXVECTOR3 vNormal;
D3DXVECTOR3 v1;
D3DXVECTOR3 v2;

D3DXVec3Subtract(&v1, vVertex2, vVertex1);
D3DXVec3Subtract(&v2, vVertex3, vVertex1);

D3DXVec3Cross(&vNormal, &v1, &v2);

D3DXVec3Normalize(&vNormal, &vNormal);

return vNormal;
}

and then running for each triangle and calculate his normals, but it''s not good, one half of each face is visible, the other one is not... why is that?

Share on other sites
Make sure all of your triangles are defined in the same "order". It is usually either clockwise or anticlockwise, they just all have to be the same.

Share on other sites
hmm
I tried this:
                //front		{-0.5f, 0.5f,-0.5f,0,0,0,0.0f,0.0f},		{ 0.5f, 0.5f,-0.5f,0,0,0,1.0f,0.0f},		{-0.5f,-0.5f,-0.5f,0,0,0,0.0f,1.0f},//triangle 1		{-0.5f,-0.5f,-0.5f,0,0,0,0.0f,1.0f},		{ 0.5f, 0.5f,-0.5f,0,0,0,1.0f,0.0f},		{ 0.5f,-0.5f,-0.5f,0,0,0,1.0f,1.0f},//triangle 2

It''s CW, but now it dosent display anything...

Share on other sites
Turn off backface culling!

Share on other sites
why post as AP?

anyway, I had! I can see everything without lightning, but when I turn lightning on, I cant see nothing (and yes, I got a light source)...

EDIT:
hmm that's weird, I can see only half of the cube with lightning...
only back, right and bottom faces, when rotating the cube...

here is the vertex buffer:
http://www.rafb.net/paste/results/p2654620.html

[edited by - ElectronicSandClock on January 7, 2004 1:55:43 PM]

Share on other sites
Make sure you don''t average your normals for each triangle that shares a point. Boxes are a special case where you want each face to have its own normal. Or else you''ll get this..

\
\----------
|
|

|
|
|
-------
|
|
--------|
|

Cheers
Chris

• 17
• 11
• 12
• 9
• 49
• Forum Statistics

• Total Topics
631395
• Total Posts
2999757
×