Exemplo n.º 1
0
		/**
	 * RenderScene
	 */
		public void RenderScene (Canvas canvas, int width, int section, int nsections)
		{
			Vector view = camera.GetViewDir ();
			Vector up = camera.GetOrthoUp ();
			Vector plane = new Vector ();
			Vector horIncr = new Vector ();
			Vector vertIncr = new Vector ();
			double ylen = camera.GetFocalDist () * (double)Math.Tan (0.5f * camera.GetFOV ());
			double xlen = ylen * canvas.GetWidth () / canvas.GetHeight ();
			Point upleft = new Point ();
			Point upright = new Point ();
			Point lowleft = new Point ();
			Point basepoint = new Point ();
			Point current;
			Ray eyeRay = new Ray ();
			int ypixel, xpixel;

			RayID = 1;
			plane.Cross (view, up);
			view.Scale (camera.GetFocalDist ());
			up.Scale (ylen);
			plane.Scale (-xlen);
			upleft.FindCorner (view, up, plane, camera.GetPosition ());
			plane.Negate ();
			upright.FindCorner (view, up, plane, camera.GetPosition ());
			up.Negate ();
			plane.Negate ();
			lowleft.FindCorner (view, up, plane, camera.GetPosition ());
			horIncr.Sub (upright, upleft);
			horIncr.Scale (horIncr.Length () / ((double)canvas.GetWidth ()));
			vertIncr.Sub (lowleft, upleft);
			vertIncr.Scale (vertIncr.Length () / ((double)canvas.GetHeight ()));
			basepoint.Set (upleft.GetX () + 0.5f * (horIncr.GetX () + vertIncr.GetX ()), upleft.GetY () + 0.5f * (horIncr.GetY () + vertIncr.GetY ()),
				upleft.GetZ () + 0.5f * (horIncr.GetZ () + vertIncr.GetZ ()));
			eyeRay.SetOrigin (camera.GetPosition ());

			int xstart = section * width / nsections;
			int xend = xstart + width / nsections;

			MainCL.logger.InfoFormat ("+" + xstart + " to " + (xend - 1) + " by " + canvas.GetHeight ());

			for (ypixel = 0; ypixel < canvas.GetHeight (); ypixel++) {
				current = new Point (basepoint);
				for (xpixel = 0; xpixel < canvas.GetWidth (); xpixel++) {
					if (xpixel >= xstart && xpixel < xend) {
						Color color = new Color (0.0f, 0.0f, 0.0f);
						eyeRay.GetDirection ().Sub (current, eyeRay.GetOrigin ());
						eyeRay.GetDirection ().Normalize ();
						eyeRay.SetID (RayID);
						this.RayID = this.RayID + 1;
						Shade (octree, eyeRay, color, 1.0f, 0, 0);
						canvas.Write (Brightness, xpixel, ypixel, color);
					}
					current.Add (horIncr);
				}
				basepoint.Add (vertIncr);
			}
			MainCL.logger.InfoFormat ("-" + xstart + " to " + (xend - 1) + " by " + canvas.GetHeight ());
		}
Exemplo n.º 2
0
		/**
	 * FindLightBlock
	 *
	 * @param tree
	 * @param ray
	 * @param maxt
	 * @return boolean
	 */
		private bool FindLightBlock (OctNode tree, Ray ray, double maxt)
		{
			OctNode current = tree.FindTreeNode (ray.GetOrigin ());
			IntersectPt test = new IntersectPt ();
			Point testpt = new Point ();

			while (current != null) {
				ObjNode currentnode = current.GetList ();
				while (currentnode != null) {
					bool found = false;
					if (currentnode.GetObj ().GetCachePt ().GetID () == ray.GetID ()) {
						found = true;
					}
					if (!found) {
						test.SetOrigID (0);
						if (currentnode.GetObj ().Intersect (ray, test)) {
							if (test.GetT () < maxt) {
								return (true);
							}
						}
					}
					currentnode = currentnode.Next ();
				}
				OctNode adjacent = current.Intersect (ray, testpt, test.GetThreshold ());
				if (adjacent == null) {
					current = null;
				} else {
					current = adjacent.FindTreeNode (testpt);
				}
			}
			return (false);
		}