Graphics Reference
In-Depth Information
void CModel::ComputePlaneRotation( float sec) {
.
Source file.
Model _ AimPlane.cpp
file
// details are in ... Listing 16.15 ...
// compute direction to tiger (dirToTgr -
in the Model
folder of
the
D3D _ Orientation project.
V f )
if ( this ->m _ RotateWithMatrix)
// front is negative z
A:
dirToTgr = -dirToTgr;
// V u is the WC y -axis direction
vec3 upVec(0, 1, 0);
// V s =
V u ×
V f (Equation 16.6 )
vec3 sideVec = cross(upVec, dirToTgr);
// if V f and V u almost parallel
B:
if (length2(sideVec)<0.001f)
// assign fixed up/side vectors
.
V u perpendicular to V f and V s
//
C:
upVec=cross(dirToTgr,sideVec);
// normalize all vectors
normalize(upVec); normalize(sideVec);
// plane rotation matrix ( R p )
D:
mat3 R;
// r 00 = x s r 01 = y s r 02 = z s
R[0][0]=sideVec.x; R[0][1]=sideVec.y; R[0][2]=sideVec.z;
// r 10 = x u r 11 = y u r 12 = z u
R[1][0]=upVec.x;
R[1][1]=upVec.y;
R[1][2]=upVec.z;
// r 20 = x f r 21 = y f r 22 = z f
R[2][0]=dirToTgr.x;R[2][1]=dirToTgr.y;R[2][2]=dirToTgr.z;
// M p . rotation R p
planeXf.SetRotation(planeRot);
// plane scene node
updated M p
m _ PlaneNode->SetXformInfo(planeXf);
else
// details are in: Listing 16.17 ...
// rotate plane by working with Quaternion
.
Listing 16.16. Aiming the plane with a rotation matrix.
Search WWH ::




Custom Search