Пример #1
0
        public void Reset()
        {
            Vector v0 = p01 - p00;
            Vector v1 = p10 - p00;

            for (int i = 0; i <= steps; i++)
            {
                double u = parameterBounds.RangeU.Span * i / steps;
                //		parameters.Add(new List<PointUV>());
                //		tabAngles.Add(new List<double>());
                //		points.Add(new List<Point>());
                for (int j = 0; j <= steps; j++)
                {
                    parameters[i, j] = PointUV.Create(u, parameterBounds.RangeV.Span * j / steps);
                    points[i, j]     = Interpolation.Bilinear(parameterBounds, boundaryValues, parameters[i, j]);

                    //			tabAngles[i].Add((double) Math.PI);
                }
            }
        }
Пример #2
0
        private double3 Bilinear(double2 t, int iLod)
        {
            double txW = t.x * Map.LodWidth(iLod);
            double tyH = t.y * Map.LodHeight(iLod);
            int    x1  = txW.PreciseRound();
            int    y1  = tyH.PreciseRound();
            int    x0  = x1 - 1;
            int    y0  = y1 - 1;
            double kx  = txW - x0 - 0.5;
            double ky  = tyH - y0 - 0.5;

            if (WrapMode <= TextureWrap.ClampToEdge ||
                WrapMode == TextureWrap.MirroredRepeat)
            {
                if (x0 == -1)
                {
                    x0 = 0;
                }
                else if (x1 == Map.LodWidth(iLod))
                {
                    x1 = Map.LodWidth(iLod) - 1;
                }

                if (y0 == -1)
                {
                    y0 = 0;
                }
                else if (y1 == Map.LodHeight(iLod))
                {
                    y1 = Map.LodHeight(iLod) - 1;
                }

                // FIXIT: there is no need to lerp in edge-cases
            }
            else if (WrapMode == TextureWrap.ClampToBorder)
            {
                double3 c00, c10, c01, c11;

                if (x0 == -1)
                {
                    if (y0 == -1)                               // Top left corner
                    {
                        c00 = c01 = c10 = BorderColor;
                        c11 = Map.Map(x1, y1, iLod);
                    }
                    else if (y1 == Map.LodHeight(iLod))                                 // Bottom left corner
                    {
                        c00 = c01 = c11 = BorderColor;
                        c10 = Map.Map(x1, y0, iLod);
                    }
                    else                                // Left side
                    {
                        c00 = c01 = BorderColor;
                        c10 = Map.Map(x1, y0, iLod);
                        c11 = Map.Map(x1, y1, iLod);
                    }
                }
                else if (x1 == Map.LodWidth(iLod))
                {
                    if (y0 == -1)                               // Top right corner
                    {
                        c00 = c10 = c11 = BorderColor;
                        c01 = Map.Map(x0, y1, iLod);
                    }
                    else if (y1 == Map.LodHeight(iLod))                                 // Bottom right corner
                    {
                        c10 = c11 = c01 = BorderColor;
                        c00 = Map.Map(x0, y0, iLod);
                    }
                    else                                // Right side
                    {
                        c10 = c11 = BorderColor;
                        c00 = Map.Map(x0, y0, iLod);
                        c01 = Map.Map(x0, y1, iLod);
                    }
                }
                else
                {
                    if (y0 == -1)                               // Top side
                    {
                        c00 = c10 = BorderColor;
                        c01 = Map.Map(x0, y1, iLod);
                        c11 = Map.Map(x1, y1, iLod);
                    }
                    else if (y1 == Map.LodHeight(iLod))                                 // Bottom side
                    {
                        c01 = c11 = BorderColor;
                        c00 = Map.Map(x0, y0, iLod);
                        c10 = Map.Map(x1, y0, iLod);
                    }
                    else
                    {
                        c00 = Map.Map(x0, y0, iLod);
                        c10 = Map.Map(x1, y0, iLod);
                        c01 = Map.Map(x0, y1, iLod);
                        c11 = Map.Map(x1, y1, iLod);
                    }
                }

                return(Interpolation.Bilinear(kx, ky,
                                              c00, c10,
                                              c01, c11
                                              ));
            }
            else if (WrapMode == TextureWrap.Repeat)
            {
                if (x0 == -1)
                {
                    x0 = Map.LodWidth(iLod) - 1;
                }
                else if (x1 == Map.LodWidth(iLod))
                {
                    x1 = 0;
                }

                if (y0 == -1)
                {
                    y0 = Map.LodHeight(iLod) - 1;
                }
                else if (y1 == Map.LodHeight(iLod))
                {
                    y1 = 0;
                }
            }

            double3 c = Interpolation.Bilinear(kx, ky,
                                               Map.Map(x0, y0, iLod), Map.Map(x1, y0, iLod),
                                               Map.Map(x0, y1, iLod), Map.Map(x1, y1, iLod)
                                               );

            return(c);
        }