コード例 #1
0
ファイル: DDSGroup.cs プロジェクト: kjmikkel/NWN2_Multibrush
        public void ApplyTextureAsNewChannel(int x, int y, textureData texture, Multibrush.LineSegment linesegment, Rectangle coverRectangle, double inner)
        {
            Rectangle rec = new Rectangle(x, y, this.Width, this.Height);
            Random ran = new Random();

            int channel = 0;
            int coverage = 0;
            bool firstCheck = true;
            bool painted = false;

            double presure = (float)texture.Presure / 100.0;

            if (coverRectangle.IntersectsWith(rec)) {
                for(int xCoor = x; xCoor < x + this.Width ; xCoor++) {
                    double adjustedXCoor = xCoor * Constants.TextureSpacing;
                    painted = false;

                    for(int yCoor = y; yCoor < y + this.Height; yCoor++) {
                        double adjustedYCoor = yCoor * Constants.TextureSpacing;

                        Pair<double, double> point = new Multibrush.Pair<double, double>(adjustedXCoor, adjustedYCoor);

                        if (linesegment.distance(point) <= inner) {
                            coverage = ran.Next(1, 100);
                            if (coverage <= texture.Coverage) {

                                if (firstCheck) {
                                    firstCheck = false;
                                    painted = true;

                                    if (this.TextureNames.Count >= 6)
                                        return;

                                    this.TextureNames.Add(texture.ToString());
                                    channel = this.TextureNames.Count - 1;
                                }

                                try {
                                    this[xCoor % this.Width, yCoor % this.Height, channel] = (byte)(presure * 255f);
                                } catch (Exception e) {
                                    throw new Exception("DDSGroup error: X:" + xCoor + ", Y:" + yCoor +" Channel: " + channel + ". Error Message: " + e.Message);
                                }
                            }
                        /* Since we are going over this in a linear fashion, we if we ever paint something, and then stop painting,
              				then we can be sure that we do not need to paint any more
             			*/
                        }
                        else if (painted) {
                            break;
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: DDSGroup.cs プロジェクト: SeanWH/NWN2_Multibrush
        public void ApplyTextureAsNewChannel(int x, int y, textureData texture, Multibrush.LineSegment linesegment, Rectangle coverRectangle, double inner)
        {
            Rectangle rec = new Rectangle(x, y, this.Width, this.Height);
            Random    ran = new Random();

            int  channel    = 0;
            int  coverage   = 0;
            bool firstCheck = true;
            bool painted    = false;

            double presure = (float)texture.Presure / 100.0;

            if (coverRectangle.IntersectsWith(rec))
            {
                for (int xCoor = x; xCoor < x + this.Width; xCoor++)
                {
                    double adjustedXCoor = xCoor * Constants.TextureSpacing;
                    painted = false;

                    for (int yCoor = y; yCoor < y + this.Height; yCoor++)
                    {
                        double adjustedYCoor = yCoor * Constants.TextureSpacing;

                        Pair <double, double> point = new Multibrush.Pair <double, double>(adjustedXCoor, adjustedYCoor);

                        if (linesegment.distance(point) <= inner)
                        {
                            coverage = ran.Next(1, 100);
                            if (coverage <= texture.Coverage)
                            {
                                if (firstCheck)
                                {
                                    firstCheck = false;
                                    painted    = true;

                                    if (this.TextureNames.Count >= 6)
                                    {
                                        return;
                                    }

                                    this.TextureNames.Add(texture.ToString());
                                    channel = this.TextureNames.Count - 1;
                                }

                                try {
                                    this[xCoor % this.Width, yCoor % this.Height, channel] = (byte)(presure * 255f);
                                } catch (Exception e) {
                                    throw new Exception("DDSGroup error: X:" + xCoor + ", Y:" + yCoor + " Channel: " + channel + ". Error Message: " + e.Message);
                                }
                            }

                            /* Since we are going over this in a linear fashion, we if we ever paint something, and then stop painting,
                             *      then we can be sure that we do not need to paint any more
                             */
                        }
                        else if (painted)
                        {
                            break;
                        }
                    }
                }
            }
        }