Update of /cvsroot/plib/plib/src/sg
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13664/plib/src/sg
Modified Files:
sg.cxx sg.h sgd.cxx
Log Message:
Moved some math out of puAux and into SG.
Index: sg.cxx
===================================================================
RCS file: /cvsroot/plib/plib/src/sg/sg.cxx,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- sg.cxx 20 Jan 2004 22:12:15 -0000 1.41
+++ sg.cxx 18 Mar 2004 19:14:43 -0000 1.42
@@ -1284,6 +1284,7 @@
Kevin B. Thompson <kev...@ya...>
Modified by Sylvan W. Clebsch <sy...@st...>
Largely rewritten by "Negative0" <neg...@ea...>
+ More added by John Fay.
*/
@@ -1680,6 +1681,102 @@
}
[...79 lines suppressed...]
+ sgAddScaledVec3 ( t2_minus_t1_t2_t1, line2.direction_vector, line.direction_vector, -t1_dot_t2 ) ;
+
+ sgFloat u = sgScalarProductVec3 ( r1_minus_r2, t1_t2_t2_minus_t1 ) / ( 1.0f - t1_dot_t2 * t1_dot_t2 ) ;
+ sgFloat v = sgScalarProductVec3 ( r1_minus_r2, t2_minus_t1_t2_t1 ) / ( 1.0f - t1_dot_t2 * t1_dot_t2 ) ;
+
+ /* Since line 2 is a line segment, we limit "v" to between 0 and the distance between the points. */
+ sgFloat length = sgDistanceVec3 ( seg.a, seg.b ) ;
+ if ( v < 0.0 ) v = 0.0 ;
+ if ( v > length ) v = length ;
+
+ sgVec3 point1, point2 ;
+ sgAddScaledVec3 ( point1, line.point_on_line, line.direction_vector, u ) ;
+ sgAddScaledVec3 ( point2, line2.point_on_line, line2.direction_vector, v ) ;
+ return sgDistanceSquaredVec3 ( point1, point2 ) ;
+}
+
+
void sgReflectInPlaneVec3 ( sgVec3 dst, const sgVec3 src, const sgVec4 plane )
{
SGfloat src_dot_norm = sgScalarProductVec3 ( src, plane ) ;
Index: sg.h
===================================================================
RCS file: /cvsroot/plib/plib/src/sg/sg.h,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- sg.h 2 Feb 2004 01:35:15 -0000 1.57
+++ sg.h 18 Mar 2004 19:14:43 -0000 1.58
@@ -1175,6 +1175,7 @@
Kevin B. Thompson <kev...@ya...>
Modified by Sylvan W. Clebsch <sy...@st...>
Largely rewritten by "Negative0" <neg...@ea...>
+ Added to by John Fay
*/
/*
@@ -1288,6 +1289,7 @@
sgEulerToQuat ( dst, tmp ) ;
}
+
/* Multiply quaternions together (concatenate rotations) */
void sgMultQuat ( sgQuat dst, const sgQuat a, const sgQuat b ) ;
@@ -2759,6 +2761,27 @@
}
+/* Function to rotate a vector through a given quaternion using the formula
+ * R = Q r Q-1 -- this gives the components of a ROTATED vector in a STATIONARY
+ * coordinate system. We assume that Q is a unit quaternion.
+ */
+
+void sgRotateVecQuat ( sgVec3 vec, sgQuat q ) ;
+void sgdRotateVecQuat ( sgdVec3 vec, sgdQuat q ) ;
+
+/* Function to rotate a vector through a given quaternion using the formula
+ * R = Q-1 r Q -- this gives the components of a STATIONARY vector in a ROTATED
+ * coordinate system. We assume that Q is a unit quaternion.
+ */
+
+void sgRotateCoordQuat ( sgVec3 vec, sgQuat q ) ;
+void sgdRotateCoordQuat ( sgdVec3 vec, sgdQuat q ) ;
+
+sgFloat sgDistSquaredToLineLineSegment ( const sgLineSegment3 seg, const sgLine3 line ) ;
+sgdFloat sgdDistSquaredToLineLineSegment ( const sgdLineSegment3 seg, const sgdLine3 line ) ;
+
+
+
/*
Intersection testing.
*/
Index: sgd.cxx
===================================================================
RCS file: /cvsroot/plib/plib/src/sg/sgd.cxx,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- sgd.cxx 12 Nov 2003 12:39:16 -0000 1.12
+++ sgd.cxx 18 Mar 2004 19:14:43 -0000 1.13
@@ -1678,6 +1678,104 @@
dst[SGD_W] = scale0 * from[SGD_W] + scale1 * to[SGD_W] ;
}
+
+
+
+/* Function to rotate a vector through a given quaternion using the formula
+ * R = Q r Q-1 -- this gives the components of a ROTATED vector in a STATIONARY
+ * coordinate system. We assume that Q is a unit quaternion.
+ */
+void sgdRotateVecQuat ( sgdVec3 vec, sgdQuat q )
[...73 lines suppressed...]
+ sgdAddScaledVec3 ( t2_minus_t1_t2_t1, line2.direction_vector, line.direction_vector, -t1_dot_t2 ) ;
+
+ sgdFloat u = sgdScalarProductVec3 ( r1_minus_r2, t1_t2_t2_minus_t1 ) / ( 1.0f - t1_dot_t2 * t1_dot_t2 ) ;
+ sgdFloat v = sgdScalarProductVec3 ( r1_minus_r2, t2_minus_t1_t2_t1 ) / ( 1.0f - t1_dot_t2 * t1_dot_t2 ) ;
+
+ /* Since line 2 is a line segment, we limit "v" to between 0 and the distance between the points. */
+ sgdFloat length = sgdDistanceVec3 ( seg.a, seg.b ) ;
+ if ( v < 0.0 ) v = 0.0 ;
+ if ( v > length ) v = length ;
+
+ sgdVec3 point1, point2 ;
+ sgdAddScaledVec3 ( point1, line.point_on_line, line.direction_vector, u ) ;
+ sgdAddScaledVec3 ( point2, line2.point_on_line, line2.direction_vector, v ) ;
+ return sgdDistanceSquaredVec3 ( point1, point2 ) ;
+}
+
+
void sgdReflectInPlaneVec3 ( sgdVec3 dst, const sgdVec3 src, const sgdVec4 plane )
{
|