コード例 #1
0
ファイル: GLView.cs プロジェクト: jcnossen/upspring.net
		private void RenderAllAxis()
		{
			for (int a = 0; a < 3; a++) {
				Ray ray = new Ray(new Vector3(), AxisVector[a]);
				Vector3[] hits = camera.Frustum.RayIntersect(ray);

				if (hits.Length >= 2) {
					GLUtil.Color(AxisVector[a]);
					GLUtil.Line(hits[0], hits[1]);

					// Print the label on the far hit pos
					Vector3 wPos = (from h in hits orderby (h - camera.Position).SqLength select h).Last();
					Vector2 pos = camera.ProjectPoint(wPos);
					PrintClampedCentered(pos.x, camera.Height - pos.y, AxisLabel[a], 1.2f);
				}
			}

			//	Vector2 p = camera.ProjectPoint(new Vector3());
			//	PrintClampedCentered(p.x,camera.Height - p.y, "o", 0.8f);

			//	PrintClampedCentered(lastMousePos.X, camera.Height - lastMousePos.Y, "mp", 0.8f);
		}
コード例 #2
0
ファイル: RenderCtl.cs プロジェクト: jcnossen/upspring.net
		public static Intersection GetPrimitiveOnRay(Ray ray, Vector3 relViewPos, IEnumerable<IEditorPrimitive> primitives)
		{
			var items = RayPrimitivesIntersect(ray, relViewPos, primitives);
				
			Intersection[] isect = new Intersection[(int)PrimitiveType.MaxTypes];

			foreach (var i in items) {
				//float dist = i.point.DistanceTo(camera.Position);
				float dist = ray.DistanceToPoint(i.point);

				float f = i.primitive.GetSelectFactor(ray.start, ray.dir, i.point);

				int sp = (int)i.primitive.PrimitiveType;
				if (isect [sp].primitive == null || f < i.primitive.GetSelectFactor (ray.start, ray.dir, isect[sp].point))
					isect[sp] = i;
			}

			return isect.FirstOrDefault(i => i.primitive != null);
		}
コード例 #3
0
ファイル: RenderCtl.cs プロジェクト: jcnossen/upspring.net
		/// <summary>
		/// Tests all primitives against the given ray for intersections. 
		/// All intersections that come within range are returned
		/// </summary>
		public static Intersection[] RayPrimitivesIntersect(Ray ray, Vector3 camPos, IEnumerable<IEditorPrimitive> primitives)
		{
			List<Intersection> intersections = new List<Intersection>();

			foreach (var i in primitives) {
				Vector3 hitPos, hitNormal;
				if (i.RayIntersect(ray, camPos, 0.008f, out hitPos, out hitNormal)) {
					Intersection inters = new Intersection();

					inters.primitive = i;
					inters.point = hitPos;

					intersections.Add(inters);
				}
			}
			return intersections.ToArray();
		}
コード例 #4
0
ファイル: Frustum.cs プロジェクト: jcnossen/upspring.net
		public Vector3[] RayIntersect(Ray ray)
		{
			List<Vector3> hits = new List<Vector3>();
			foreach (Plane pl in planes) {
				Vector3 hp;
				if (ray.IntersectPlane(pl, out hp)) {
					// See if the hitpoint is actually within the frustum
					if (IsPointVisible(hp))
						hits.Add(hp);
				}
			}
			return hits.ToArray();
		}