Jim Wilson writes:
> I could really use some help visualizing
> the matrices. Which elements are which axis (in Plib)?
x is 1st
y is 2nd
z is 3rd < up >
where x cross y equals z
same as OpenGL xcept there Y is up
> And what does the fourth row/col represent?
fourth column is scaling almost allways 0
4th row is translation
so instead of doing
sgMat4 sgTRANS;
sgMakeTransMat4( sgTRANS, pilot_view->get_view_pos() );
and then later
sgPostMultMat4( sgTUX, sgTRANS )
you can almost always just do this instead
sgSetVec4(sgTUX[3],
pilot_view->get_view_pos()[0],
pilot_view->get_view_pos()[1],
pilot_view->get_view_pos()[2],
1.0);
Another thing to keep in mind is that the rotation matrix
is the upper 3x3 block of the 4x4 matrix and that the inverse
of a 'pure rotation' is just it's transpose
ie if v' = Av then v = -Av'
where ' = 'primed' and - = 'Inverse'
See sgTransposeNegateMat4() is sg.cxx
Another optimization trick is tht something like
sgVec3 ownship_up;
sgSetVec3( ownship_up, 0.0, 0.0, 1.0);
sgMat4 sgROT;
sgMakeRotMat4( sgROT, -90.0, ownship_up );
is going to turn into something like
sgMat ownship;
ownship[0][0] = 0 ;
ownship[0][1] = -1 ;
ownship[0][2] = 0 ;
ownship[0][3] = 0 ;
ownship[1][0] = 1 ;
ownship[1][1] = 0 ;
ownship[1][2] = 0 ;
ownship[1][3] = 0 ;
ownship[2][0] = 0 ;
ownship[2][1] = 0 ;
ownship[2][2] = 1 ;
ownship[2][3] = 0 ;
ownship[3][0] = 0 ;
ownship[3][1] = 0 ;
ownship[3][2] = 0 ;
ownship[3][3] = 0 ;
because the sin and cosine terms are going to be
one of 0, 1, -1
This in turn can be used to 'tweak' a series of Matrix Multiplies
in that most of the terms either just dissapear or merely change sign
For example
using this technique on the model annimation matrix stuff removed
around a hundred assignments and/or fpu ops per moving part :-)
Same kind of trick can be seen in tileentry.cxx -- WorldPosition()
>Also if someone could help me understand how the quats relate to
rotation/axis
>or compare to matrixes. Guess I'm not quite sure how as Norman said, using
>quats would have helped here
quats wouldn't necessarily help you here BUT THEY help earlier in the
pipeline creating the 'eye rotation' matrix from it's various contributors
joystick mouse keyboard ect
FWIW untested but should work
void HeadingPitchToMat(sgMat4 dst, const float heading, const float pitch )
{
sgQuat q;
float cp = (float) cos(pitch*SG_DEGREES_TO_RADIANS/SG_TWO);
float sp = (float) sin(pitch*SG_DEGREES_TO_RADIANS/SG_TWO);
float ch = (float) cos(heading*SG_DEGREES_TO_RADIANS/SG_TWO);
float sh = (float) sin(heading*SG_DEGREES_TO_RADIANS/SG_TWO);
q[SG_W] = 0;
q[SG_X] = ch - (sp * sh);
q[SG_Y] = sp * ch
q[SG_Z] = cp * sh;
SGfloat two_xx = q[SG_X] * (q[SG_X] + q[SG_X]) ;
SGfloat two_xy = q[SG_X] * (q[SG_Y] + q[SG_Y]) ;
SGfloat two_xz = q[SG_X] * (q[SG_Z] + q[SG_Z]) ;
SGfloat two_yy = q[SG_Y] * (q[SG_Y] + q[SG_Y]) ;
SGfloat two_yz = q[SG_Y] * (q[SG_Z] + q[SG_Z]) ;
SGfloat two_zz = q[SG_Z] * (q[SG_Z] + q[SG_Z]) ;
sgSetVec4 ( dst[0], SG_ONE-(two_yy+two_zz), two_xy, two_xz, SG_ZERO ) ;
sgSetVec4 ( dst[1], two_xy, SG_ONE-(two_xx+two_zz), two_yz, SG_ZERO ) ;
sgSetVec4 ( dst[2], two_xz, two_yz, SG_ONE-(two_xx+two_yy), SG_ZERO ) ;
sgSetVec4 ( dst[3], SG_ZERO, SG_ZERO, SG_ZERO, SG_ONE ) ;
}
Cheers
Norman
_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel