public void Draw(LandscapeGeomipmap landscape, Object3D plane) { switch (Mode) { case "free": updateObject(); break; case "follow": float minimum = Math.Max(landscape.getHeight(VEye), objective.Scene.SeaHeight); updateObject(minimum - 1.0f, true); followObjective(); break; case "followFree": float minimum1 = Math.Max(landscape.getHeight(VEye), plane.getPosition().Y); updateObject(minimum1 - 1.0f, true); /*updateObject(getObjective().getPosition().Y + 0.5f);*/ break; default: updateObject(landscape.getHeight(VEye)); break; } }
/// <summary> /// follow an object by keeping distance, but not direction /// </summary> /// <param name="following">object to follow</param> public void followObjectiveZ(Object3D following) { Vector3 v = VView; vDest = following.getPosition(); vEye = vDest - v; }
// CalculateShootingRay Calculates a world space ray starting at the player's // position and pointing in the direction of the cursor. Viewport.Unproject is used // to accomplish this. see the accompanying documentation for more explanation // of the math behind this function. public Ray CalculateShootingRay(Object3D model, Matrix projectionMatrix, Matrix viewMatrix) { // create 2 positions in screenspace using the cursor position. 0 is as // close as possible to the camera, 1 is as far away as possible. Vector3 nearSource = model.getPosition(); nearSource.Y += 2.0f; Vector3 farSource = new Vector3(Position, 1f); // use Viewport.Unproject to tell what those two screen space positions // would be in world space. we'll need the projection matrix and view // matrix, which we have saved as member variables. We also need a world // matrix, which can just be identity. /* * Vector3 nearPoint = GraphicsDevice.Viewport.Unproject(nearSource, * projectionMatrix, viewMatrix, Matrix.Identity); */ Vector3 nearPoint = nearSource; Vector3 farPoint = GraphicsDevice.Viewport.Unproject(farSource, projectionMatrix, viewMatrix, Matrix.Identity); // find the direction vector that goes from the nearPoint to the farPoint // and normalize it.... Vector3 direction = farPoint - nearPoint; direction.Normalize(); // and then create a new ray using nearPoint as the source. return(new Ray(nearPoint, direction)); }
public void rotateAroundObjective(float angle, Vector3 axis) { if (objective != null) { Matrix transform = Matrix.Identity; axis.Normalize(); transform = Matrix.CreateFromAxisAngle(axis, angle); Vector3 viewVector = Vector3.Transform(VView, transform); vDest = objective.getPosition(); vEye = vDest - viewVector; } }