Esempio n. 1
0
        private void PrintPixelLineFromTexture(Bitmap myBitmap)
        {
            Polygon polygon = Figure as Polygon;
            double  offset  = 0.0; // offset which we include when getting pixel from a texture

            //double textureWidth = polygon.FillTexture.Width;
            //double textureHeight = polygon.FillTexture.Height;
            if (polygon is RandomPolygon)
            {
                offset = myBitmap.Width - (polygon as RandomPolygon).WayGone;
            }
            for (int i = 0; i < AET.Count; i += 2)
            {
                for (double pixel = AET[i].x + 1; pixel < AET[i + 1].x; ++pixel)
                {
                    Color fillColor = polygon.FillTexture[(int)(pixel - offset) % polygon.FillTexture.GetLength(0), ((int)scanLinePosition - 1) % polygon.FillTexture.GetLength(1)];

                    if ((new Point(pixel, scanLinePosition)).IsPointInsideRectangle(myBitmap.Width, myBitmap.Height))
                    {
                        Vector3D lightVector = lightCoords - new Vector3D(pixel, scanLinePosition - 1, 0);
                        //Vector3D lightVector = new Vector3D(pixel, scanLinePosition - 1, 0) - lightCoords;
                        fillColor = LambertLightModel.GetColor(fillColor, lightColor, lightVector, (int)pixel, (int)scanLinePosition - 1, polygon.BumpMap, offset);
                        myBitmap.SetPixel((int)pixel, (int)scanLinePosition - 1, fillColor);
                    }
                }
            }
        }
Esempio n. 2
0
        private void PrintPixelLineFromColor(Bitmap myBitmap)
        {
            Polygon polygon = Figure as Polygon;

            for (int i = 0; i < AET.Count; i += 2)
            {
                for (double pixel = AET[i].x + 1; pixel < AET[i + 1].x; ++pixel)
                {
                    Color fillColor = polygon.FillColor;
                    if ((new Point(pixel, scanLinePosition)).IsPointInsideRectangle(myBitmap.Width, myBitmap.Height))
                    {
                        Vector3D lightVector = lightCoords - new Vector3D(pixel, scanLinePosition - 1, 0);
                        //Vector3D lightVector = new Vector3D(pixel, scanLinePosition - 1, 0) - lightCoords;
                        fillColor = LambertLightModel.GetColor(fillColor, lightColor, lightVector, (int)pixel, (int)scanLinePosition - 1, polygon.BumpMap);
                        myBitmap.SetPixel((int)pixel, (int)scanLinePosition - 1, fillColor);
                    }
                }
            }
        }