From: Dan Mapes (dmapes++at++RoninWorks.com)
Date: 10/05/2000 11:08:58
The first argument to VMatrix::makeVecRotVec must be normalized but the man page only mentions the need for the second argument to be normalized.
Truely trivial but still annoying
---------------------------- bug.C
#include <stdio.h>
#include <stdlib.h>
#include <Performer/pr/pfLinMath.h>
static float randomPos()
{
return (2.0 * ((float)rand())/32000.0f) -0.5f;
}
static void printMat( const char *tag, float mat[4][4] )
{
printf("\n%s:\n", tag );
for ( int i = 0; i < 4; ++i )
printf("\t%7.5f %7.5f %7.5f %7.5f\n", mat[i][0], mat[i][1], mat[i][2], mat[i][3] );
}
/*
Copied from pfMatrix man page:
void pfMatrix::makeVecRotVec(const pfVec3& v1, const pfVec3& v2);
pfMatrix::makeVecRotVec sets the pfMatrix to the rotation matrix which
rotates the vector v1 onto v2, i.e. v2 = v1 * dst. v2 must be
normalized. The rotation axis is always chosen to be perpendicular to
both v0 and v1 so that the rotation angle is as small as possible. Note
that the result is ambiguous only when v0 == -v1; in this case the
rotation axis is chosen to be an arbitrary vector perpendicular to v0 and
v1.
*/
void main( int, char * )
{
pfVec3 axisA( 1.0f, 0.0f, 0.0f );
pfVec3 axisB( 0.0f, 1.0f, 0.0f );
pfMatrix mat;
mat.makeVecRotVec( axisA, axisB );
printMat( "Both vectors normalized", mat.mat );
axisA[0] = 2.0f;
mat.makeVecRotVec( axisA, axisB );
printMat( "First vectors length is doubled", mat.mat );
axisA[0] = 4.0f;
mat.makeVecRotVec( axisA, axisB );
printMat( "First vectors length is doubled again", mat.mat );
printf("\n\nManual says only the second vector needs to be normalized.\n");
printf("but we get different results when the first vector has\n");
printf("different lengths.\n\n");
}
This archive was generated by hypermail 2b29 : Thu Oct 05 2000 - 11:09:39 PDT