protected override void Render(REScene scene, Camera3D camera, Canvas canvas)
        {
            double d = 2 * camera.FocusDistance * System.Math.Tan(camera.FOV / 2);
            double h = d / System.Math.Sqrt(camera.Ratio * camera.Ratio + 1);
            double w = h * camera.Ratio;

            double hFOV = 2 * System.Math.Atan(w / (2 * camera.FocusDistance));
            double vFOV = 2 * System.Math.Atan(h / (2 * camera.FocusDistance));

            double alpha0 = -hFOV / 2;
            double beta0 = -vFOV / 2;
            double dAlpha = hFOV / canvas.Width;
            double dBeta = vFOV / canvas.Height;

            double alpha = alpha0, beta = beta0;

            var ray = new ColoredRay3D();
            var dirZ = (float)camera.FocusDistance;
            for (int cy = 0; cy < canvas.Height; cy++) {
                var dirY = (float)(System.Math.Tan(beta) * camera.FocusDistance);
                for (int cx = 0; cx < canvas.Width; cx++) {
                    var dirX = (float)(System.Math.Tan(alpha) * camera.FocusDistance);

                    ray.Color = new PreciseColor(1.0f, 1.0f, 1.0f);
                    ray.Start = new Vector3D(camera.Position.X, camera.Position.Y, camera.Position.Z - (float)camera.FocusDistance);
                    ray.End = ray.Start + new Vector3D(dirX, dirY, dirZ);
                    PreciseColor color = ProcessRay(ray, scene, 0);
                    canvas[cx, cy] += color;
                    alpha += dAlpha;
                }
                alpha = alpha0;
                beta += dBeta;
            }
        }
Exemple #2
0
        public SensitiveMatrix(Canvas canvas)
            : base(null) {
            this.canvas = canvas;
            Rectangle3D origin = new Rectangle3D();

            // TODO: set rectangle's params

            //rectangle = new RERectangle(origin);

        }
Exemple #3
0
 public static Canvas FromImage(Bitmap img) {
     var res = new Canvas(img.Width, img.Height);
     for (var y = 0; y < res.Height; y++) {
         for (var x = 0; x < res.Width; x++) {
             var clr = img.GetPixel(x, y);
             res[x, y] = new PreciseColor(clr);
         }
     }
     return res;
 }
 protected override void Render(REScene scene, Camera3D camera, Canvas canvas)
 {
     foreach (REBaseLight lightSource in scene.Lights) {
         var start = lightSource.Origin.CoordinateSystem.Position;
         var dir = new Vector3D(
             (float)(_rnd.NextDouble() * 2 - 1),
             (float)(_rnd.NextDouble() * 2 - 1),
             (float)(_rnd.NextDouble() * 2 - 1)
         ).Normalize();
         var ray = new ColoredRay3D {
             Color = new PreciseColor(1, 1, 1),
             Start = start,
             End = start + dir
         };
         ProcessRay(ray, scene, 0);
     }
 }
Exemple #5
0
 public abstract void Render(Scene3D scene, Camera3D camera, Canvas canvas);
Exemple #6
0
 protected abstract void Render(REScene scene, Camera3D camera, Canvas canvas);
Exemple #7
0
 public override sealed void Render(Scene3D scene, Camera3D camera, Canvas canvas)
 {
     REScene wrappedScene = PrepareScene(scene, camera);
     Render(wrappedScene, camera, canvas);
 }