thank you Lauris Kaplinski for the great reply!

i did as you mentioned and have a better result, just not the right one. i tried changing odd to even and (k & 1) is the only one that gives near results. i've taken a screenshot to show what i see...

&&

i can see through the mesh which i hope is a result of incorrect normals, or else something in my rendering section is broken!

[source lang="cpp"] float vu[3]; float vv[3]; float cp[3]; float result; for (int k = 0; k < nvertices - 2; k++) { vu[0] = vertices[k + 1][0] - vertices[k][0]; vu[1] = vertices[k + 1][1] - vertices[k][1]; vu[2] = vertices[k + 1][2] - vertices[k][2]; vv[0] = vertices[k + 2][0] - vertices[k][0]; vv[1] = vertices[k + 2][1] - vertices[k][1]; vv[2] = vertices[k + 2][2] - vertices[k][2]; cp[0] = (vu[1] * vv[2]) - (vu[2] * vv[1]); cp[1] = (vu[2] * vv[0]) - (vu[0] * vv[2]); cp[2] = (vu[0] * vv[1]) - (vu[1] * vv[0]); result = (float)sqrt((cp[0]*cp[0]) + (cp[1]*cp[1]) + (cp[2]*cp[2])); if (result == 0.0f) result = 1.0f; normals[k][0] = cp[0] / result; normals[k][1] = cp[1] / result; normals[k][2] = cp[2] / result; if (k &amp; 1) { normals[k][0] = -normals[k][0]; normals[k][1] = -normals[k][1]; normals[k][2] = -normals[k][2]; } }[/source]

above i changed the cross product from what i had originally. a few articles i read on calculating normals seem to use the same cross product. i hope its not incorrect. changing it gives me a completely dark shaded model.

*scratches head*

### Show differencesHistory of post edits

### #4juddo

Posted 08 November 2012 - 07:23 PM

thank you Lauris Kaplinski for the great reply!

i did as you mentioned and have a better result, just not the right one. i tried changing odd to even and (k &amp; 1) is the only one that gives near results. i've taken a screenshot to show what i see...

&amp;&amp;

i can see through the mesh which i hope is a result of incorrect normals, or else something in my rendering section is broken!

[source lang="cpp"] float vu[3]; float vv[3]; float cp[3]; float result; for (int k = 0; k < nvertices - 2; k++) { vu[0] = vertices[k + 1][0] - vertices[k][0]; vu[1] = vertices[k + 1][1] - vertices[k][1]; vu[2] = vertices[k + 1][2] - vertices[k][2]; vv[0] = vertices[k + 2][0] - vertices[k][0]; vv[1] = vertices[k + 2][1] - vertices[k][1]; vv[2] = vertices[k + 2][2] - vertices[k][2]; cp[0] = (vu[1] * vv[2]) - (vu[2] * vv[1]); cp[1] = (vu[2] * vv[0]) - (vu[0] * vv[2]); cp[2] = (vu[0] * vv[1]) - (vu[1] * vv[0]); result = (float)sqrt((cp[0]*cp[0]) + (cp[1]*cp[1]) + (cp[2]*cp[2])); if (result == 0.0f) result = 1.0f; normals[k][0] = cp[0] / result; normals[k][1] = cp[1] / result; normals[k][2] = cp[2] / result; if (k &amp; 1) { normals[k][0] = -normals[k][0]; normals[k][1] = -normals[k][1]; normals[k][2] = -normals[k][2]; } }[/source]

above i changed the cross product from what i had originally. a few articles i read on calculating normals seem to use the same cross product. i hope its not incorrect. changing it gives me a completely dark shaded model.

i did as you mentioned and have a better result, just not the right one. i tried changing odd to even and (k &amp; 1) is the only one that gives near results. i've taken a screenshot to show what i see...

&amp;&amp;

i can see through the mesh which i hope is a result of incorrect normals, or else something in my rendering section is broken!

[source lang="cpp"] float vu[3]; float vv[3]; float cp[3]; float result; for (int k = 0; k < nvertices - 2; k++) { vu[0] = vertices[k + 1][0] - vertices[k][0]; vu[1] = vertices[k + 1][1] - vertices[k][1]; vu[2] = vertices[k + 1][2] - vertices[k][2]; vv[0] = vertices[k + 2][0] - vertices[k][0]; vv[1] = vertices[k + 2][1] - vertices[k][1]; vv[2] = vertices[k + 2][2] - vertices[k][2]; cp[0] = (vu[1] * vv[2]) - (vu[2] * vv[1]); cp[1] = (vu[2] * vv[0]) - (vu[0] * vv[2]); cp[2] = (vu[0] * vv[1]) - (vu[1] * vv[0]); result = (float)sqrt((cp[0]*cp[0]) + (cp[1]*cp[1]) + (cp[2]*cp[2])); if (result == 0.0f) result = 1.0f; normals[k][0] = cp[0] / result; normals[k][1] = cp[1] / result; normals[k][2] = cp[2] / result; if (k &amp; 1) { normals[k][0] = -normals[k][0]; normals[k][1] = -normals[k][1]; normals[k][2] = -normals[k][2]; } }[/source]

above i changed the cross product from what i had originally. a few articles i read on calculating normals seem to use the same cross product. i hope its not incorrect. changing it gives me a completely dark shaded model.

### #3juddo

Posted 08 November 2012 - 07:16 PM

thank you Lauris Kaplinski for the great reply!

i did as you mentioned and have a better result, just not the right one. i tried changing odd to even and (k &amp; 1) is the only one that gives near results. i've taken a screenshot to show what i see...

&amp;&amp;

i can see through the mesh which i hope is a result of incorrect normals, or else something in my rendering section is broken!

[source lang="cpp"] float vu[3]; float vv[3]; float cp[3]; float result; for (int k = 0; k < nvertices - 2; k++) { vu[0] = vertices[k + 1][0] - vertices[k][0]; vu[1] = vertices[k + 1][1] - vertices[k][1]; vu[2] = vertices[k + 1][2] - vertices[k][2]; vv[0] = vertices[k + 2][0] - vertices[k][0]; vv[1] = vertices[k + 2][1] - vertices[k][1]; vv[2] = vertices[k + 2][2] - vertices[k][2]; cp[0] = (vu[1] * vv[2]) - (vu[2] * vv[1]); cp[1] = (vu[2] * vv[0]) - (vu[0] * vv[2]); cp[2] = (vu[0] * vv[1]) - (vu[1] * vv[0]); result = (float)sqrt((cp[0]*cp[0]) + (cp[1]*cp[1]) + (cp[2]*cp[2])); if (result == 0.0f) result = 1.0f; normals[k][0] = cp[0] / result; normals[k][1] = cp[1] / result; normals[k][2] = cp[2] / result; if (k &amp; 1) { normals[k][0] = -normals[k][0]; normals[k][1] = -normals[k][1]; normals[k][2] = -normals[k][2]; } }[/source]

above i changed the cross product from what i had originally. a few articles i read on calculating normals seem to use the same cross product. i hope its not incorrect. changing it gives me a completely dark shaded model.

i did as you mentioned and have a better result, just not the right one. i tried changing odd to even and (k &amp; 1) is the only one that gives near results. i've taken a screenshot to show what i see...

&amp;&amp;

i can see through the mesh which i hope is a result of incorrect normals, or else something in my rendering section is broken!

[source lang="cpp"] float vu[3]; float vv[3]; float cp[3]; float result; for (int k = 0; k < nvertices - 2; k++) { vu[0] = vertices[k + 1][0] - vertices[k][0]; vu[1] = vertices[k + 1][1] - vertices[k][1]; vu[2] = vertices[k + 1][2] - vertices[k][2]; vv[0] = vertices[k + 2][0] - vertices[k][0]; vv[1] = vertices[k + 2][1] - vertices[k][1]; vv[2] = vertices[k + 2][2] - vertices[k][2]; cp[0] = (vu[1] * vv[2]) - (vu[2] * vv[1]); cp[1] = (vu[2] * vv[0]) - (vu[0] * vv[2]); cp[2] = (vu[0] * vv[1]) - (vu[1] * vv[0]); result = (float)sqrt((cp[0]*cp[0]) + (cp[1]*cp[1]) + (cp[2]*cp[2])); if (result == 0.0f) result = 1.0f; normals[k][0] = cp[0] / result; normals[k][1] = cp[1] / result; normals[k][2] = cp[2] / result; if (k &amp; 1) { normals[k][0] = -normals[k][0]; normals[k][1] = -normals[k][1]; normals[k][2] = -normals[k][2]; } }[/source]

above i changed the cross product from what i had originally. a few articles i read on calculating normals seem to use the same cross product. i hope its not incorrect. changing it gives me a completely dark shaded model.

### #2juddo

Posted 08 November 2012 - 07:15 PM

thank you Lauris Kaplinski for the great reply!

i did as you mentioned and have a better result, just not the right one. i tried changing odd to even and (k & 1) is the only one that gives near results. i've taken a screenshot to show what i see...

&&

i can see through the mesh which i hope is a result of incorrect normals, or else something in my rendering section is broken!

[source lang="cpp"] float vu[3]; float vv[3]; float cp[3]; float result; for (int k = 0; k < nvertices; k++) { vu[0] = vertices[k + 1][0] - vertices[k][0]; vu[1] = vertices[k + 1][1] - vertices[k][1]; vu[2] = vertices[k + 1][2] - vertices[k][2]; vv[0] = vertices[k + 2][0] - vertices[k][0]; vv[1] = vertices[k + 2][1] - vertices[k][1]; vv[2] = vertices[k + 2][2] - vertices[k][2]; cp[0] = (vu[1] * vv[2]) - (vu[2] * vv[1]); cp[1] = (vu[2] * vv[0]) - (vu[0] * vv[2]); cp[2] = (vu[0] * vv[1]) - (vu[1] * vv[0]); result = (float)sqrt((cp[0]*cp[0]) + (cp[1]*cp[1]) + (cp[2]*cp[2])); if (result == 0.0f) result = 1.0f; normals[k][0] = cp[0] / result; normals[k][1] = cp[1] / result; normals[k][2] = cp[2] / result; if (k & 1) { normals[k][0] = -normals[k][0]; normals[k][1] = -normals[k][1]; normals[k][2] = -normals[k][2]; } }[/source]

above i changed the cross product from what i had originally. a few articles i read on calculating normals seem to use the same cross product. i hope its not incorrect. changing it gives me a completely dark shaded model.

i did as you mentioned and have a better result, just not the right one. i tried changing odd to even and (k & 1) is the only one that gives near results. i've taken a screenshot to show what i see...

&&

i can see through the mesh which i hope is a result of incorrect normals, or else something in my rendering section is broken!

[source lang="cpp"] float vu[3]; float vv[3]; float cp[3]; float result; for (int k = 0; k < nvertices; k++) { vu[0] = vertices[k + 1][0] - vertices[k][0]; vu[1] = vertices[k + 1][1] - vertices[k][1]; vu[2] = vertices[k + 1][2] - vertices[k][2]; vv[0] = vertices[k + 2][0] - vertices[k][0]; vv[1] = vertices[k + 2][1] - vertices[k][1]; vv[2] = vertices[k + 2][2] - vertices[k][2]; cp[0] = (vu[1] * vv[2]) - (vu[2] * vv[1]); cp[1] = (vu[2] * vv[0]) - (vu[0] * vv[2]); cp[2] = (vu[0] * vv[1]) - (vu[1] * vv[0]); result = (float)sqrt((cp[0]*cp[0]) + (cp[1]*cp[1]) + (cp[2]*cp[2])); if (result == 0.0f) result = 1.0f; normals[k][0] = cp[0] / result; normals[k][1] = cp[1] / result; normals[k][2] = cp[2] / result; if (k & 1) { normals[k][0] = -normals[k][0]; normals[k][1] = -normals[k][1]; normals[k][2] = -normals[k][2]; } }[/source]

above i changed the cross product from what i had originally. a few articles i read on calculating normals seem to use the same cross product. i hope its not incorrect. changing it gives me a completely dark shaded model.

### #1juddo

Posted 08 November 2012 - 07:07 PM

thank you Lauris Kaplinski for the great reply!

i did as you mentioned and have a better result, just not the right one. i tried changing odd to even and (k & 1) is the only one that gives near results. i've taken a screenshot to show what i see...

&&

[source lang="cpp"] float vu[3]; float vv[3]; float cp[3]; float result; for (int k = 0; k < nvertices; k++) { vu[0] = vertices[k + 1][0] - vertices[k][0]; vu[1] = vertices[k + 1][1] - vertices[k][1]; vu[2] = vertices[k + 1][2] - vertices[k][2]; vv[0] = vertices[k + 2][0] - vertices[k][0]; vv[1] = vertices[k + 2][1] - vertices[k][1]; vv[2] = vertices[k + 2][2] - vertices[k][2]; cp[0] = (vu[1] * vv[2]) - (vu[2] * vv[1]); cp[1] = (vu[2] * vv[0]) - (vu[0] * vv[2]); cp[2] = (vu[0] * vv[1]) - (vu[1] * vv[0]); result = (float)sqrt((cp[0]*cp[0]) + (cp[1]*cp[1]) + (cp[2]*cp[2])); if (result == 0.0f) result = 1.0f; normals[k][0] = cp[0] / result; normals[k][1] = cp[1] / result; normals[k][2] = cp[2] / result; if (k & 1) { normals[k][0] = -normals[k][0]; normals[k][1] = -normals[k][1]; normals[k][2] = -normals[k][2]; } }[/source]

i did as you mentioned and have a better result, just not the right one. i tried changing odd to even and (k & 1) is the only one that gives near results. i've taken a screenshot to show what i see...

&&

[source lang="cpp"] float vu[3]; float vv[3]; float cp[3]; float result; for (int k = 0; k < nvertices; k++) { vu[0] = vertices[k + 1][0] - vertices[k][0]; vu[1] = vertices[k + 1][1] - vertices[k][1]; vu[2] = vertices[k + 1][2] - vertices[k][2]; vv[0] = vertices[k + 2][0] - vertices[k][0]; vv[1] = vertices[k + 2][1] - vertices[k][1]; vv[2] = vertices[k + 2][2] - vertices[k][2]; cp[0] = (vu[1] * vv[2]) - (vu[2] * vv[1]); cp[1] = (vu[2] * vv[0]) - (vu[0] * vv[2]); cp[2] = (vu[0] * vv[1]) - (vu[1] * vv[0]); result = (float)sqrt((cp[0]*cp[0]) + (cp[1]*cp[1]) + (cp[2]*cp[2])); if (result == 0.0f) result = 1.0f; normals[k][0] = cp[0] / result; normals[k][1] = cp[1] / result; normals[k][2] = cp[2] / result; if (k & 1) { normals[k][0] = -normals[k][0]; normals[k][1] = -normals[k][1]; normals[k][2] = -normals[k][2]; } }[/source]