// reset all camera state to default values public void Reset() { // reset camera's position and orientation ResetLocalSpace(); ls = new LocalSpace(); // "look at" point, center of view Target = Vector3.Zero; // vehicle being tracked VehicleToTrack = null; // aim at predicted position of vehicleToTrack, this far into thefuture AimLeadTime = 1; // make first update abrupt smoothNextMove = false; // relative rate at which camera transitions proceed smoothMoveSpeed = 1.5f; // select camera aiming mode Mode = CameraMode.Fixed; // "constant distance from vehicle" camera mode parameters FixedDistanceDistance = 1; FixedDistanceVerticalOffset = 0; // "look straight down at vehicle" camera mode parameters LookDownDistance = 30; // "static" camera mode parameters FixedPosition = new Vector3(75, 75, 75); FixedTarget = Vector3.Zero; FixedUp = Vector3.Up; // "fixed local offset" camera mode parameters FixedLocalOffset = new Vector3(5, 5, -5); // "offset POV" camera mode parameters PovOffset = new Vector3(0, 1, -3); }
// General purpose circle/disk drawing routine. Draws circles or disks (as // specified by "filled" argument) and handles both special case 2d circles // on the XZ plane or arbitrary circles in 3d space (as specified by "in3d" // argument) public static void DrawCircleOrDisk(float radius, Vector3 axis, Vector3 center, Color color, int segments, bool filled, bool in3d) { if (Demo.IsDrawPhase == true) { LocalSpace ls = new LocalSpace(); if (in3d) { // define a local space with "axis" as the Y/up direction // (XXX should this be a method on LocalSpace?) Vector3 unitAxis = axis; unitAxis.Normalize(); Vector3 unitPerp = Vector3Helpers.FindPerpendicularIn3d(axis); unitPerp.Normalize(); ls.Up = unitAxis; ls.Forward = unitPerp; ls.Position = (center); ls.SetUnitSideFromForwardAndUp(); } // make disks visible (not culled) from both sides if (filled) { BeginDoubleSidedDrawing(); } // point to be rotated about the (local) Y axis, angular step size Vector3 pointOnCircle = new Vector3(radius, 0, 0); float step = (float)(2 * Math.PI) / (float)segments; // set drawing color SetColor(color); // begin drawing a triangle fan (for disk) or line loop (for circle) drawBegin(filled ? PrimitiveType.TriangleFan : PrimitiveType.LineStrip); // for the filled case, first emit the center point if (filled) { AddVertex(in3d ? ls.Position : center); } // rotate p around the circle in "segments" steps float sin = 0, cos = 0; int vertexCount = filled ? segments + 1 : segments; for (int i = 0; i < vertexCount; i++) { // emit next point on circle, either in 3d (globalized out // of the local space), or in 2d (offset from the center) AddVertex(in3d ? ls.GlobalizePosition(pointOnCircle) : pointOnCircle + center); // rotate point one more step around circle pointOnCircle = Vector3Helpers.RotateAboutGlobalY(pointOnCircle, step, ref sin, ref cos); } // close drawing operation drawEnd(); if (filled) { EndDoubleSidedDrawing(); } } else { DeferredCircle.AddToBuffer(radius, axis, center, color, segments, filled, in3d); } }