Пример #1
0
 public void TestInBox()
 {
     Random rnd = new Random();
     Point3 pa = new Point3(), pb = new Point3(), pc = new Point3();
     Triangle t = new Triangle(pa, pb, pc, null, null, null, null, null, null, null);
     for(int i = 0x00; i < 100; i++) {
         pa.SetValues(rnd.NextDouble(), rnd.NextDouble(), rnd.NextDouble());
         pb.SetValues(rnd.NextDouble(), rnd.NextDouble(), rnd.NextDouble());
         pc.SetValues(rnd.NextDouble(), rnd.NextDouble(), rnd.NextDouble());
         double a = rnd.NextDouble(), b = rnd.NextDouble(), c = rnd.NextDouble(), d = rnd.NextDouble(), e = rnd.NextDouble(), f = rnd.NextDouble();
         double mx = Math.Min(a, b), Mx = Math.Max(a, b), my = Math.Min(c, d), My = Math.Max(c, d), mz = Math.Min(e, f), Mz = Math.Max(e, f);
         if(pa.InBox(mx, Mx, my, My, mz, Mz) || pb.InBox(mx, Mx, my, My, mz, Mz) || pc.InBox(mx, Mx, my, My, mz, Mz)) {
             Assert.IsTrue(t.InBox(mx, Mx, my, My, mz, Mz));
         }
     }
 }
Пример #2
0
 public void PointAt(double t, Point3 pt)
 {
     pt.SetValues(Offset.X+Direction.X*t, Offset.Y+Direction.Y*t, Offset.Z+Direction.Z*t);
 }
Пример #3
0
		private void CalculateImage (int yfrom, int yto) {
			double sd = this.screenDistance;
			double sh = 2.0d*sd*Math.Tan(0.5d*this.foVH);
			int w = this.Width;
			int h = this.Height;
			double sw = sh*w/h;
			double dwh = sw/w;
			Ray ray = new Ray(0.0d, 0.0d, 0.0d, 0.0d, 0.0d, 1.0d);
			uint[] pixel = this.raster.Pixel;
			int k = Width*yfrom, ks = Width*yto, kc;
			uint l, m;
			uint aasqrt = this.antialiasSqrt;
			uint aadsqrt = this.dispersionAntialiasSqrt;
			RayTracer rt = new RayTracer(this.acc, this.Lights, settings);
			uint aa = aasqrt*aasqrt, aac, aad = aadsqrt*aadsqrt, aadc;
			Point3 tmp = new Point3(0.0d, 0.0d, 0.0d);
			double focusLength = Point3.DiffLength(this.position, this.lookAt);
			double frac = 1.0d+focusLength/this.screenDistance;
			uint aaaad = aa*aad;
			double dwha = dwh/aasqrt;
			double dwhad = dispersion*dwh;
			double yp = dwh*yfrom-0.5d*sh-0.5d*dwha*aasqrt, xp;
			double yd, xd;
			double dis = this.displacement;
			ColorCache cc;
			#region PIXEL
			for(; k < ks;) {
				kc = k+Width;
				xp = -0.5d*sw-0.5d*dwha*aasqrt-dis;
				for(; k < kc;) {
					l = 0x00;
					cc = new ColorCache(0x00);
					#region ANTIALIASING
					for(; l < aa;) {
						aac = l+aasqrt;
						for(; l < aac; l++) {
							m = 0x00;
							tmp.SetValues(xp*frac, -yp*frac, focusLength);
							yd = -0.5d*dwhad*(aadsqrt-0x01);
							#region DISPERSION
							for(; m < aad;) {
								xd = -0.5d*dwhad*(aadsqrt-0x01);
								aadc = m+aadsqrt;
								for(; m < aadc; m++) {
									ray.Offset.SetValues(xp+xd, -yp-yd, 0.0d);
									ray.Direction.SetValues(ray.Offset, tmp);
									ray.Direction.Normalize();
									ray.NormalizeDirection();
									ray.Transform(this.matrix);
#if FAST_COLOR_INTERSECTION
									rt.CalculateColor(ray, 0, Color.White);
									cc.AddColor(new Color(ColorUtils.FromWavelength(350+5*(int)SystemDiagnostics.Intersections)));
									SystemDiagnostics.Intersections = 0x00;
#elif FAST_COLOR_MIGRATION
									rt.CalculateColor(ray, 0, Color.White);
									cc.AddColor(new Color(ColorUtils.FromWavelength(350+5*(int)SystemDiagnostics.Migrations)));
									SystemDiagnostics.Migrations = 0x00;
#else
									cc.AddColor(rt.CalculateColor(ray, 0, Color.White));
#endif
									xd += dwhad;
								}
								yd += dwhad;
							}
							#endregion
							xp += dwha;
						}
						yp += dwha;
						xp -= dwh;
					}
					#endregion
					yp -= dwh;
					xp += dwh;
					pixel[k++] = ColorUtils.AlphaChannel|cc.Mix(aaaad).RGB8;
				}
				#endregion
				yp += dwh;
			}
		}