#### Archived

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

# This is really driving me nuts

## Recommended Posts

I have a function that generates texture coordinates, and every so often, it messes things up. About every 50th face that coordinates are generated for, I get floating point errors, i think. The flaw is very noticeable when viweing the face with in 3d, and when I save the floating point numbers to a file when i see one of the errors, this is output: "-1#IND" instead of an actual number. What the hell causes "-1#IND" to occur? Here is the function in question:

void CFace::GenerateTextureCoordinates()
{
D3DXVECTOR3 vS( 0.0f, 0.0f, 0.0f ), vT( 0.0f, 0.0f, 0.0f ), vRef( 0.0f, 0.0f, 0.0f );

m_vNormal = Normal( m_Verts[0].m_vPos,
m_Verts[1].m_vPos,
m_Verts[2].m_vPos );

if( ( m_vNormal.x == 0.0f && m_vNormal.y ==  1.0f && m_vNormal.z == 0.0f ) ||
( m_vNormal.x == 0.0f && m_vNormal.y == -1.0f && m_vNormal.z == 0.0f ) )
vRef.x = 1.0f;
else
vRef.y = -1.0f;

vS = Normalize( GetCrossProduct( m_vNormal, vRef ) );
vT = Normalize( GetCrossProduct( m_vNormal, vS ) );

for( int y = 0; y < 4; y++ )
{
// The final values here are occasionally producing -1#IND

m_Verts[y].m_fU = ( m_Verts[y].m_vPos.x * vS.x ) +
( m_Verts[y].m_vPos.y * vS.y ) +
( m_Verts[y].m_vPos.z * vS.z );
// The final values here are occasionally producing -1#IND

m_Verts[y].m_fV = ( m_Verts[y].m_vPos.x * vT.x ) +
( m_Verts[y].m_vPos.y * vT.y ) +
( m_Verts[y].m_vPos.z * vT.z );
}

TRACE_LEAVE_FN()
}

[edited by - Mulligan on January 19, 2003 4:27:37 PM]

##### Share on other sites
-1#ind iv a divison bu zero , division by zero is indetermined, check your dotproduct and cros products, when you are normalizing so be carfeull dividing everything by zero, you should add a check , if the length of the vector is zero , just add a little epsilon ( 0.0000001f ) this will prevent dividing by zero lenght vectors , byez and sorry for my english

##### Share on other sites
I think thats it, thanks!

• ### Forum Statistics

• Total Topics
628370
• Total Posts
2982300

• 10
• 9
• 13
• 24
• 11