示例#1
0
		// 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)
			{
				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 = Vector3.Normalize(axis);
					Vector3 unitPerp = Vector3.Normalize(axis.FindPerpendicularIn3d());
					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) / segments;

				// set drawing color
                SetColor(color);

				// begin drawing a triangle fan (for disk) or line loop (for circle)
				drawBegin(filled ? PrimitiveType.TriangleStrip : 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 = pointOnCircle.RotateAboutGlobalY(step, ref sin, ref cos);
				}

				// close drawing operation
				drawEnd();
				if (filled) EndDoubleSidedDrawing();
			}
			else
			{
				DeferredCircle.AddToBuffer(radius, axis, center, color, segments, filled, in3D);
			}
		}
示例#2
0
		// 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.UnitY;

			// "fixed local offset" camera mode parameters
			_fixedLocalOffset = new Vector3(5, 5, -5);

			// "offset POV" camera mode parameters
			PovOffset = new Vector3(0, 1, -3);
		}