// Project viewspace polygon vertices into screen coordinates.// Note that the y axis goes up in worldspace and viewspace, but// goes down in screenspace.
// Move in the view direction, across the x-y plane, as if // walking. This approach moves slower when looking up or // down at more of an angle motionvec.v[0] = DotProduct(&vpn, &xaxis); motionvec.v[1] = 0.0; motionvec.v[2] = DotProduct(&vpn, &zaxis); for (i=0 ; i<3 ; i++) { currentpos.v[i] += motionvec.v[i] * currentspeed; if (currentpos.v[i] > MAX_COORD) currentpos.v[i] = MAX_COORD; if (currentpos.v[i] < -MAX_COORD) currentpos.v[i] = -MAX_COORD; }
// Set up the world-to-view rotation. // Note: much of the work done in concatenating these matrices // can be factored out, since it contributes nothing to the // final result; multiply the three matrices together on paper // to generate a minimum equation for each of the 9 final elements s = sin(roll); c = cos(roll); mroll[0][0] = c; mroll[0][1] = s; mroll[1][0] = -s; mroll[1][1] = c; s = sin(pitch); c = cos(pitch); mpitch[1][1] = c; mpitch[1][2] = s; mpitch[2][1] = -s; mpitch[2][2] = c; s = sin(yaw); c = cos(yaw); myaw[0][0] = c; myaw[0][2] = -s; myaw[2][0] = s; myaw[2][2] = c; MConcat(mroll, myaw, mtemp1); MConcat(mpitch, mtemp1, mtemp2);
// Break out the rotation matrix into vright, vup, and vpn. // We could work directly with the matrix; breaking it out // into three vectors is just to make things clearer for (i=0 ; i<3 ; i++) { vright.v[i] = mtemp2[0][i]; vup.v[i] = mtemp2[1][i]; vpn.v[i] = mtemp2[2][i]; }