예제 #1
0
        private TRN ApplyColourLine(TRN trn, Pair<double, double> upper, Pair<double, double> lower)
        {
            Random ran = new Random();
            int coverage = 0;
            LineSegment linesegment = new LineSegment(upper, lower);

            foreach (Vertex vertex in trn.Vertices) {
                Pair<double, double> point = new Pair<double, double>(vertex.Position[0], vertex.Position[1]);

                if ((upper.X <= point.X && point.X <= lower.X) && (upper.Y <= point.Y && point.Y <= lower.Y)) {
                    if (linesegment.distance(point) <= Constants.VertexSpacing + newInner) {
                        coverage = ran.Next(1, 100);
                        if (coverage <= data.colourCoverage) {
                            vertex.Color = data.col;
                        }
                    }
                }
            }

            return trn;
        }
예제 #2
0
        private TRN ApplyTextureLine(TRN trn, Pair<double, double> upper, Pair<double, double> lower)
        {
            int xStart = (int)Math.Floor((Math.Min(upper.X, lower.X) - this.newInner) / Constants.TextureSpacing);
            int width = (int)(4 * this.newInner * Math.Abs(upper.X - lower.X));

            int yStart = (int)Math.Floor((Math.Min(upper.Y, lower.Y) - this.newInner) / Constants.TextureSpacing);
            int height = (int)(4 * this.newInner * Math.Abs(upper.Y - lower.Y));

            Rectangle coverRectangle = new Rectangle(xStart, yStart, width, height);

            LineSegment lineSegment = new LineSegment(upper, lower);
            foreach (textureData texture in data.textures) {
                int i = 0;
                foreach (DDSGroup ddsGroup in trn.DDSGroups)
                {
                    //Check whether the DDSGroup contain parts of the rectangle that surrounds the triangle
                    int x = ( i % trn.Width ) * ddsGroup.Width;
                    int y = ( ( i - ( i % trn.Width ) ) / trn.Width ) * ddsGroup.Height;
                    i++;

                    ddsGroup.ApplyTextureAsNewChannel(x, y, texture, lineSegment, coverRectangle, this.newInner);
                }
            }

            return trn;
        }
예제 #3
0
        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;
                        }
                    }
                }
            }
        }