private void SetObjectColorFromTexture(ColorsForPolygonFill colForPolyFill) { if (colForPolyFill.ObjectColorOption != ObjectColorOption.FromTexture) { colForPolyFill.ObjectColorOption = ObjectColorOption.FromTexture; colForPolyFill.UpdateCache(); drawingArea.Refresh(); } }
private void SetConstantObjectColor(ColorsForPolygonFill colForPolyFill) { if (colForPolyFill.ObjectColorOption != ObjectColorOption.Constant) { colForPolyFill.ObjectColor = IoColorBox.BackColor; colForPolyFill.ObjectColorOption = ObjectColorOption.Constant; colForPolyFill.UpdateCache(); drawingArea.Refresh(); } }
public static DirectBitmap GetPolygonFillDirectBitmap(IPolygon polygon, ColorsForPolygonFill colorsForPolygonFill) { int xMin = polygon.Vertices.Min(v => v.Position.X); int yMin = polygon.Vertices.Min(v => v.Position.Y); DirectBitmap directBitmap = new DirectBitmap(polygon.Vertices.Max(v => v.Position.X) - xMin + 1, polygon.Vertices.Max(v => v.Position.Y) - yMin + 1) { BitmapLocationForDrawing = new Point(xMin, yMin) }; List <EdgeDetails>[] et = new List <EdgeDetails> [directBitmap.Height - 1]; PrepareEdgeDetails(et, polygon.Edges, xMin, yMin); List <EdgeDetails> aet = new List <EdgeDetails>(); EdgeDetailsComparer bucketComparer = new EdgeDetailsComparer(); for (int y = 0; y < et.Length; y++) { if (et[y] != null) { aet.AddRange(et[y]); } aet.Sort(bucketComparer); for (int i = 0; i < aet.Count - 1; i++) { int loopEnd = (int)aet[i + 1].XofSecondVertice; for (int j = (int)aet[i].XofSecondVertice; j < loopEnd; j++) { directBitmap.SetPixel(j, y, colorsForPolygonFill.GetColor(j + xMin, y + yMin)); } } aet.RemoveAll(b => b.YMax == y + yMin); foreach (var bucket in aet) { bucket.XofSecondVertice += bucket.Step; } } return(directBitmap); }
public PolygonFiller() { InitializeComponent(); StartPosition = FormStartPosition.CenterScreen; lastState = WindowState; polygons = new List <IPolygon> { PolygonCreator.GetTriangle(), PolygonCreator.GetTriangle() }; polygons[1].HandlePolygonMove(new Point(350, 0)); Vertice.ClickRadius = 10; Edge.ClickDistance = 5; inputHandler = new DrawingAreaInputHandler { HandledPolygons = polygons, OnSuccessfullElementMove = drawingArea.Refresh, OnElementSelection = OnElementSelection, OnElementUnselection = OnElementUnselection }; standardPolygonDrawer = new PolygonDrawer { EdgeColor = Color.Green, EdgeThickness = 2, VerticeBorderColor = Color.LightGray, VerticeInsideColor = Color.FromArgb(28, 28, 28), VerticeBorderThickness = 1, VerticeRadius = 10, }; selectedElementDrawer = new PolygonDrawer { EdgeColor = Color.Red, EdgeThickness = standardPolygonDrawer.EdgeThickness, VerticeBorderColor = Color.Red, VerticeInsideColor = standardPolygonDrawer.VerticeInsideColor, VerticeBorderThickness = standardPolygonDrawer.VerticeBorderThickness, VerticeRadius = standardPolygonDrawer.VerticeRadius, }; ColorsForPolygonFill.ConstantDisruptionVector = new Vector3(0, 0, 0); ColorsForPolygonFill.ConstantNormalVector = new Vector3(0, 0, 1); ColorsForPolygonFill.ConstantVectorToLight = new Vector3(0, 0, 1); ColorsForPolygonFill.AnimatedNormalVectorMatrixSize = new Size(300, 300); rgbHeadlights = new RBGHeadlights { CosinePower = 1000, HeadlightsHeight = 100 }; rgbHeadlights2 = new RBGHeadlights { CosinePower = rgbHeadlights.CosinePower, HeadlightsHeight = rgbHeadlights.HeadlightsHeight }; colorsForPolygonFill = new ColorsForPolygonFill { ObjectColorOption = ObjectColorOption.Constant, DisruptionVectorOption = DisruptionVectorOption.None, NormalVectorOption = NormalVectorOption.Constant, VectorToLightOption = VectorToLightOption.Constant, ObjectColor = ILColorBox.BackColor, LightColor = new Vector3(1, 1, 1), DrawingAreaSize = drawingArea.Size, RBGHeadlights = rgbHeadlights, AnimatedNormalVectorGenerator = new NormalVectorCustomGenerator { A = 0.1f, B = 0.1f } }; colorsForPolygonFill2 = new ColorsForPolygonFill { ObjectColorOption = colorsForPolygonFill.ObjectColorOption, DisruptionVectorOption = colorsForPolygonFill.DisruptionVectorOption, NormalVectorOption = colorsForPolygonFill.NormalVectorOption, VectorToLightOption = colorsForPolygonFill.VectorToLightOption, ObjectColor = colorsForPolygonFill.ObjectColor, LightColor = colorsForPolygonFill.LightColor, DrawingAreaSize = colorsForPolygonFill.DrawingAreaSize, RBGHeadlights = rgbHeadlights2, AnimatedNormalVectorGenerator = new NormalVectorCustomGenerator { A = colorsForPolygonFill.AnimatedNormalVectorGenerator.A, B = colorsForPolygonFill.AnimatedNormalVectorGenerator.B } }; DisruptionVectorTextureBox.BackgroundImage = Images.brick_heightmap; colorsForPolygonFill.SetHeightMap(Images.brick_heightmap); colorsForPolygonFill2.SetHeightMap(Images.brick_heightmap); NormalVectorTextureBox.BackgroundImage = Images.brick_normalmap; colorsForPolygonFill.SetNormalMap(Images.brick_normalmap); colorsForPolygonFill2.SetNormalMap(Images.brick_normalmap); IoTextureBox.BackgroundImage = Images.sampleTexture; colorsForPolygonFill.SetObjectTexture(Images.sampleTexture); IoTextureBox2.BackgroundImage = Images.sampleTexture; colorsForPolygonFill2.SetObjectTexture(Images.sampleTexture); UpdatePolygonsCache(); lightSourceGenerator = new LightSourceGenerator { AngleChange = 10, HeightStepChange = 10, MinHeight = 20, MaxHeight = 200, Radius = 300, Origin = new Vector2(drawingArea.Width / 2, drawingArea.Height / 2), StartingHeight = 100 }; radius = lightSourceGenerator.Radius; rgbCosinePower = rgbHeadlights.CosinePower; rgbHeight = rgbHeadlights.HeadlightsHeight; ResizeEnd += FormSizeChangedHandler; Resize += HandleWindowMaximization; drawingArea.Paint += Draw; drawingArea.MouseDown += inputHandler.HandleMouseDown; drawingArea.MouseUp += inputHandler.HandleMouseUp; drawingArea.MouseMove += inputHandler.HandleMouseMove; LightColorButton.Click += ChangeLightColor; SetObjectColorButton.Click += ChangeObjectColor; SetObjectColorButton2.Click += ChangeObjectColor2; SetObjectTextureButton.Click += ChangeObjectTexture; SetObjectTextureButton2.Click += ChangeObjectTexture2; SetNormalMapButton.Click += ChangeNormalMap; SetHeightMapButton.Click += ChangeHeightMap; ObjectColorFromTexture.Click += SetObjectColorFromTexture; ObjectColorFromTexture2.Click += SetObjectColorFromTexture2; ObjectColorSingle.Click += SetConstantObjectColor; ObjectColorSingle2.Click += SetConstatntObjectColor2; NormalVectorConstant.Click += SetNormalVectorConstant; NormalVectorFromTexture.Click += SetNormalVectorFromTexture; DisruptionVectorConstant.Click += SetDisruptionVectorConstant; DisruptionVectorFromTexture.Click += SetDisruptionVectorFromTexture; VectorToLightConstant.Click += SetVectorToLightConstant; VectorToLightAnimated.CheckedChanged += SetVectorToLightAnimated; TurnRgbHighlightsOn.Click += TurnRgbHighlightsOnHandler; TurnRgbHighlightsOff.Click += TurnRgbHighlightsOffHandler; RadiusTextBox.Text = lightSourceGenerator.Radius.ToString(); RadiusTextBox.TextChanged += RadiusTextboxTextChangedHandler; RadiusButtonAccept.Click += SetNewRadius; CosinePowerTextBox.Text = rgbHeadlights.CosinePower.ToString(); CosinePowerTextBox.TextChanged += CosineTextboxTextChangedHandler; HighlightsHeightTextBox.Text = rgbHeadlights.HeadlightsHeight.ToString(); HighlightsHeightTextBox.TextChanged += HighlightsHeightTextboxTextChangedHandler; RgbHeadlightsParameterAccept.Click += SetNewRgbHeadlightsParameters; NormalVectorAnimated.Click += SetNormalVectorAnimated; NormalVectorAnimatedParameterA.Text = colorsForPolygonFill.AnimatedNormalVectorGenerator.A.ToString(); NormalVectorAnimatedParameterB.Text = colorsForPolygonFill.AnimatedNormalVectorGenerator.B.ToString(); NormalVectorAnimatedParametersUpdate.Click += UpdateAnimatedNormalVectorParameters; }