/* Sets the * _proportionofworldtoshow parameter, and, if _perspective, * adjusts the _fieldofviewangle and possibly the position if the _proportionofworldtoshow * would make _fieldofviewangle exceed WIDESTANGLE. Return tells if you had * to move to achieve your effect. */ //Special methods public void loadViewMatrix() { /* What we do here is a bit tricky. It involves matching two "trihedrons" (where a trihedron is a set * of three mutually perpendicular vectors used as the basis of a coordinate system). * (a) On the one hand, the standard OpenGL-style graphics pipeline * sets up its projection matrix with the expectation that the viewer is situated so that the points * of interest are on the negative z-axis of the viewer's coordinates. The viewers x and y axes are * thought of as situated with x pointing right and y pointing up. * (b) We plan to sometimes let our * viewer either "fly around" or "ride the back of the player." In this case, we expect to have the * viewer's attitudeTangent pointing towards the thing it is looking at, with its attitudeNormal in the plane * it's turning in, and its attitudeBinormal pointing up. Note that the attitudeNormal will seem to * point to the left, so that the attiudeTangent * attitudeNormal = attitudeBinormal points up. * In the constructor, we set up a standard view by these three replacements: x = -z, y = -x, z = y. * (c) In order to match the trihedron of (b) to the expectation of (a), we want to essentially relabel * the axes of (b), so that the attitudeTangent is now the -z axis we look towards, the attitudeBinormal * is the y axis of "up", and the attitudeNormal is the positinve x-axis. So that's how we get the * formula in the line below. Essentially we undo what the constructor does, by setting * z = -x, x = -y, y = z. * (note to b) By the way, if setAttitudeToMotoinLock(TRUE) has been called, * as we will do when riding a critter, then the attitude vectors will match, respetively, * the critterviwer's _tangent, _normal and _binormal. */ cMatrix3 viewmatrix = new cMatrix3(AttitudeNormal.neg(), AttitudeBinormal, AttitudeTangent.neg(), Position); /* The next thing to realize is that transforming a world position into the coordinates of a viewer * means pre-multiplying the world by the inverse of the viewer's position in world coordinates. Here's * why. If the viewer attitude is matrix V in world coordinates, and an object attitude is matrix W in * world coordinates, then our task is to find the matrix W' of the object in viewer coordiantes. Well, * if the matrix T transforms attitude V into the standard origin trihedron of the world --- which is the * identity matrix --- then T should transform W into W'. But if T * V = I, then T is V.inverse(). So * W' = V.inverse() * W. */ pgraphics().loadMatrix(viewmatrix.Inverse); }
/// <summary> /// You can override this for possibly locking the gun to the sprite direction. /// </summary> /// <param name="dt">The change in time since the last animate.</param> public override void animate(float dt) { base.animate(dt); //Calls updateAttitude(dt) and _psprite->animate(dt) if (_aimtoattitudelock) { AimVector = AttitudeTangent.roundOff(); } }