예제 #1
0
        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;
            }
        }
예제 #2
0
        protected virtual REScene PrepareScene(Scene3D scene, Camera3D camera)
        {
            var wrappedScene = new REScene();
            var preparationContext = new RenderPreparationContext(wrappedScene);
            preparationContext.PushCoordinateSystem(camera.CoordinateSystem);
            _shapeDecorator = new Shape3DDecorator(preparationContext);

            scene.Shapes.AcceptVisitor(_shapeDecorator);
            wrappedScene.Objects.Add(_shapeDecorator.DecoratedShape);

            scene.Lights.AcceptVisitor(_shapeDecorator);
            wrappedScene.Lights.Add(_shapeDecorator.DecoratedLight);

            preparationContext.PopCoordinateSystem();
            return wrappedScene;
        }
예제 #3
0
 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);
     }
 }
예제 #4
0
 public abstract void Render(Scene3D scene, Camera3D camera, Canvas canvas);
예제 #5
0
 protected abstract void Render(REScene scene, Camera3D camera, Canvas canvas);
예제 #6
0
 public override sealed void Render(Scene3D scene, Camera3D camera, Canvas canvas)
 {
     REScene wrappedScene = PrepareScene(scene, camera);
     Render(wrappedScene, camera, canvas);
 }