[Plib-devel] Bug with sign of pitch?
Brought to you by:
sjbaker
From: Wolfram K. <w_...@rz...> - 2000-07-18 09:39:50
|
I have a trivial question: If I am in a slightly ascending aeroplane, is my pitch positive? I would guess so, but looking at void sgHPRfromVec3 ( sgVec3 hpr, const sgVec3 src ) at the line hpr[1] = -(SGfloat) atan2 ( tmp [ 2 ], sqrt ( sgSquare ( tmp [ 0 ] ) + sgSquare ( tmp [ 1 ] ) ) ) * SG_RADIANS_TO_DEGREES ; it seems to be negative, is that correct? Here is the reason for my question: While sg contains a function to convert a cartesian Vec3 into a HPR, the other conversion was missing and I implemented it for PPE by copying code from sgMakeCoordMat4. It seems to work in PPE, but when I converted the result back as a check, I get inverted pitch. Is the bug in my new function or in plib, for example sgHPRfromVec3 ? BTW, I game developers might use this code as well. I use it for camera-movement (when I do a "make object fully visible"). Its quite simple, but perhaps you want to put it into plib? Here is the function: --------------------- cut ------------------------------ void /*sg*/Vec3fromHPR ( sgVec3 vec3, const sgVec3 hpr ) // If hpr are the hpr of the camera, then this function gives the normalised // viewing direction. Of course roll is lost in this conversion. { double ch, sh, cp, sp; if ( hpr[0] == SG_ZERO ) { ch = SGD_ONE ; sh = SGD_ZERO ; } else { sh = (SGfloat) sin( (double)( hpr[0] * SG_DEGREES_TO_RADIANS )) ; ch = (SGfloat) cos( (double)( hpr[0] * SG_DEGREES_TO_RADIANS )) ; } if ( hpr[1] == SG_ZERO ) { cp = SGD_ONE ; sp = SGD_ZERO ; } else { sp = sin( (double)( hpr[1] * SG_DEGREES_TO_RADIANS )) ; cp = cos( (double)( hpr[1] * SG_DEGREES_TO_RADIANS )) ; } vec3[0] = (SGfloat)( -sh * cp ) ; vec3[1] = (SGfloat)( ch * cp ) ; vec3[2] = (SGfloat)( sp ) ; // rest is check sgVec3 hprCheck; sgHPRfromVec3 ( hprCheck, vec3) ; if(0.01<abs(hprCheck[0]-hpr[0])) fprintf(stderr,"\n*** Heading: %f vs %f***\n",hprCheck[0],hpr[0]); if(0.01<abs(hprCheck[1]-hpr[1])) fprintf(stderr,"\n*** Pitch: %f vs %f ***\n",hprCheck[1],hpr[1]); } --------------------- cut ------------------------------ Bye bye, Wolfram Kuss. |