[Plib-cvs] plib/src/sg sg.cxx,1.38,1.39 sg.h,1.50,1.51
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2003-10-07 03:00:17
|
Update of /cvsroot/plib/plib/src/sg In directory sc8-pr-cvs1:/tmp/cvs-serv5321/plib/src/sg Modified Files: sg.cxx sg.h Log Message: Angle calculation routines changed to return degree results. Index: sg.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/sg/sg.cxx,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- sg.cxx 9 Sep 2002 09:07:03 -0000 1.38 +++ sg.cxx 7 Oct 2003 03:00:08 -0000 1.39 @@ -156,10 +156,12 @@ } // -dw- inconsistent linkage! + float sgTriArea( sgVec3 p0, sgVec3 p1, sgVec3 p2 ) { /* From comp.graph.algorithms FAQ + 2A(P) = abs(N.(sum_{i=0}^{n-1}(v_i x v_{i+1}))) This is an optimized version for a triangle [...180 lines suppressed...] { + // nornmal has to be normalized. sgVec3 nv1, nv2 ; sgNormalizeVec3 ( nv1, v1 ) ; @@ -1001,6 +1001,14 @@ dst->hpr[2] = sgATan2 ( sr, cr ) ; } +} + + +void sgMakeNormal(sgVec2 dst, const sgVec2 a, const sgVec2 b ) +{ + sgSubVec2 ( dst, b, a ) ; + float tmp = dst [ 0 ] ; dst [ 0 ] = -dst [ 1 ] ; dst [ 1 ] = tmp ; + sgNormaliseVec2 ( dst ) ; } Index: sg.h =================================================================== RCS file: /cvsroot/plib/plib/src/sg/sg.h,v retrieving revision 1.50 retrieving revision 1.51 diff -u -d -r1.50 -r1.51 --- sg.h 15 Sep 2003 21:53:53 -0000 1.50 +++ sg.h 7 Oct 2003 03:00:11 -0000 1.51 @@ -854,6 +854,9 @@ sgReflectInPlaneVec3 ( dst, dst, plane ) ; } +extern void sgMakeNormal ( sgVec2 dst, const sgVec3 a, const sgVec3 b ) ; + + extern void sgMakeNormal ( sgVec3 dst, const sgVec3 a, const sgVec3 b, const sgVec3 c ) ; @@ -888,21 +891,26 @@ float sgTriArea( sgVec3 p0, sgVec3 p1, sgVec3 p2 ); -// Fast code. Result is in the range 0..pi: +// Fast code. Result is in the range 0..180: inline SGfloat sgAngleBetweenNormalizedVec3 ( sgVec3 v1, sgVec3 v2 ) { float f = sgScalarProductVec3 ( v1, v2 ) ; - return (float)(acos((f>=1.0f)?1.0f:(f<=-1.0f)?-1.0f:f)*SG_RADIANS_TO_DEGREES) ; + return (float) acos ( ( f >= 1.0f ) ? 1.0f : + ( f <= -1.0f ) ? -1.0f : f ) * + SG_RADIANS_TO_DEGREES ; } -// Fast code. Result is in the range 0..pi: +// Fast code. Result is in the range 0..180: + SGfloat sgAngleBetweenVec3 ( sgVec3 v1, sgVec3 v2 ); -// all three have to be normalized. Slow code. Result is in the range 0..2*pi: +// All three have to be normalized. Slow code. Result is in the range 0..360: + SGfloat sgAngleBetweenNormalizedVec3 (sgVec3 first, sgVec3 second, sgVec3 normal); -// normal has to be normalized. Slow code. Result is in the range 0..2*pi: +// Normal has to be normalized. Slow code. Result is in the range 0..360: + SGfloat sgAngleBetweenVec3 ( sgVec3 v1, sgVec3 v2, sgVec3 normal ); class sgSphere |