Re: [Plib-users] bug in ssgOptimiser?
Brought to you by:
sjbaker
From: Steve B. <sjb...@ai...> - 2002-10-03 03:34:51
|
lo...@sl... wrote: > hello all, > In ssgOptimiser.cxx from CVS Sept. 30, at the end of the > OptVertexList::makeNormals function there is the following chunk of code > (roughly line 323): > > for ( i = 0 ; i < vnum ; i++ ) > if ( sgScalarProductVec2 ( vlist[i]->normal, vlist[i]->normal ) < > 0.001 ) > sgSetVec3 ( vlist[i]->normal, 0.0f, 0.0f, 1.0f ) ; > else > sgNormaliseVec3 ( vlist [ i ] -> normal ) ; > > > My belief is that the call to sgScalarProductVec2 should really be a call > to sgScalarProductVec3. Please correct me if I'm wrong. I guess so - but this is somewhat cryptic code anyway. The scalar product of a vector against itself is just the length of the vector...so sgLengthVecN(vlist[i].normal) would be more readable here. As to whether it should be Vec2 or Vec3, I'm not 100% certain what was originally intended here. If we assume the code is *WRONG* and it should be Vec3 - then this reads: If the normal is vastly too short and the normalise function might fail, then make the vector point straight up instead of maybe getting a divide by zero. If we assume the code is *RIGHT* then it reads: If the normal's X/Y projection is very short - then make it point straight up. In fact, both interpretations have the same consequences. If the vector is seriously de-normalised then it's X/Y projection will also be very short - so we'll set the vector to (0,0,1) in either case. If the vector is short in the X/Y plane - but has significant Z-direction length, then setting it to (0,0,1) has a very similar effect to normalising it. Hence, whilst I'm pretty sure this should be: if ( sgLengthVec3 ( vlist[i]->normal ) < 0.001 ) ...it won't make *any* difference to any programs out there - except to slow them down a teeny-tiny bit. Anyway - I've fixed it and committed to CVS. ----------------------------- Steve Baker ------------------------------- Mail : <sjb...@ai...> WorkMail: <sj...@li...> URLs : http://www.sjbaker.org http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net http://prettypoly.sf.net http://freeglut.sf.net http://toobular.sf.net http://lodestone.sf.net |