public static IBasicShape MapApiToDomain(ShapeDto input) { IBasicShape output = null; switch (input.Type) { case ShapeDto.ShapeType.Sphere: // TODO: worth normalizing Shape instantiation e.g. new() output = Sphere.CreateDefaultInstance(); break; case ShapeDto.ShapeType.Plane: output = new Plane(); break; default: throw new ArgumentOutOfRangeException(nameof(input.Type), "Unrecognized shape type: " + input.Type); } if (input.Material != null) { output.Material = MaterialFactory.MapApiToDomain(input.Material); } if (input.Transformations != null && input.Transformations.Any()) { foreach (var transform in input.Transformations) { var domainTransformAction = TransformationFactory.MapApiTransformToDomainAction(transform); domainTransformAction(output.Transformation); } } return(output); }
public IntersectionDto(Model.Ray ray, IBasicShape shape, float distanceT) { Ray = ray; Shape = shape; DistanceT = distanceT; TangentialIntersection = false; RayOrigin = RaysOrigin.Normal; }
public static void DrawSphere(string outputBitmapFilePath, IMatrixTransformationBuilder transformation) { // Rough and ready. Fully following the pseudocode from the text. // Basically: // For each pixel on the canvas, figure out the ray (direction) from there // back to the origin of the emitting ray (light source). // Then calculate the hit (first intersection), if any. If it's a hit then // that pixel on the canvas gets drawn. // The rest of the code is just pixel conversion e.g. determining what "1" // represents in terms of numbers of pixels and also converting the half above / // half below of the sphere to a non-negative set of pixels for drawing. // inputs: could encapsulate in class to cleanup the code. var ray_origin = new Vector4(0F, 0F, -5F, 1F); var wall_z = 10F; var wall_size = 7.0F; IBasicShape shape = Sphere.CreateDefaultInstance(); shape.Transformation = transformation; #pragma warning disable CS0618 // Type or member is obsolete var xs = new SceneIntersectionCalculator(new List <IBasicShape> { shape }); #pragma warning restore CS0618 // Type or member is obsolete var canvas_pixels = 100; var pixel_size = wall_size / canvas_pixels; var half = wall_size / 2; var color = Color.FromScRgb(1.0F, 0.0F, 0.0F, 1.0F).Simplify(); using var canvas = new System.Drawing.Bitmap(canvas_pixels, canvas_pixels); for (int y = 0; y < canvas_pixels; y++) { var world_y = half - pixel_size * y; for (int x = 0; x < canvas_pixels; x++) { var world_x = -half + pixel_size * x; var position = new Vector4(world_x, world_y, wall_z, 1F); var r = new Domain.Model.Ray( ray_origin, Vector4.Normalize(position - ray_origin)); if (xs.CalculateHit(r).HasValue) { canvas.SetPixel(x, y, color); } } } canvas.Save(outputBitmapFilePath); }
private IBasicShape MakeBackground() { IBasicShape backgroundShape = MakeShapeStub(_presentationInfo); backgroundShape.Width = _presentationInfo.Width; backgroundShape.ColorType = ShapeType.Inactive; return(backgroundShape); }
public void ComputeCalculations(IBasicShape basicShape) { NumberOf++; Area += basicShape.GetArea(); Perimeter += basicShape.GetPerimeter(); var textToPrint = TypeOfTheGrouppedShapes.GetProperty("TextToPrint"); var textToPrintValue = textToPrint?.GetValue(basicShape).ToString(); TextToPrint = string.Format(textToPrintValue, NumberOf, Area.ToString("#.##"), Perimeter.ToString("#.##")); }
private IBasicShape MakeProgressBar(int currentPosition) { IBasicShape backgroundShape = MakeShapeStub(_presentationInfo); if (_presentationInfo.DisableOnFirstSlide) { currentPosition -= 1; } backgroundShape.Width = (CalculateWidthOfBarOnOneSlide()) * currentPosition; backgroundShape.ColorType = ShapeType.Active; return(backgroundShape); }
private static Func <GrouppedShapes, bool> GrouppedShapesInList(IBasicShape basicShape) => grouppedShapes => grouppedShapes.TypeOfTheGrouppedShapes == basicShape.GetType();
public void ComputeCalculations(GrouppedShapes grouppedShapes, IBasicShape basicShape) { grouppedShapes.ComputeCalculations(basicShape); }
public GrouppedShapes GetGrouppedShapesElement(IBasicShape basicShape) => _instance.FirstOrDefault(GrouppedShapesInList(basicShape));
public bool HasGrouppedShapesInList(IBasicShape basicShape) => _instance.Any(GrouppedShapesInList(basicShape));
public void InitializationValues_SetOnSphereInstance() { _sphereInstance = Sphere.CreateDefaultInstance(true); }