コード例 #1
0
        public List <IData3DSet> AddMapImages(FGEImage [] list)
        {
            if (list.Length > 0)
            {
                var datasetMapImg = Data3DSetClass <TexturedQuadData> .Create("mapimage", Color.White, 1.0f);

                for (int i = 0; i < list.Length; i++)
                {
                    FGEImage img = list[i];

                    if (_cachedTextures.ContainsKey(img.FileName))
                    {
                        datasetMapImg.Add(_cachedTextures[img.FileName]);
                    }
                    else
                    {
                        Bitmap bmp = (Bitmap)Bitmap.FromFile(img.FilePath);

                        Vector3 centre = new Vector3((img.TopLeft.X + img.BottomRight.X) / 2, 0, (img.TopRight.Y + img.BottomLeft.Y) / 2);
                        float   width  = img.TopRight.X - img.BottomLeft.X;
                        float   height = img.TopLeft.Y - img.BottomRight.Y;         // its rectangular.. so does not really matter which left/right/top/bot you use

                        var texture = TexturedQuadData.FromBitmap(bmp, centre, TexturedQuadData.NoRotation, width, height);

                        _cachedTextures[img.FileName] = texture;
                        datasetMapImg.Add(texture);
                    }
                }
                _datasets.Add(datasetMapImg);
            }

            return(_datasets);
        }
コード例 #2
0
        public static TexturedQuadData FromFGEImage(FGEImage img)
        {
            Bitmap bmp = (Bitmap)Bitmap.FromFile(img.FilePath);

            Vector3d[] vertices  = GetVertices(img);
            Vector4d[] texcoords = GetTexCoords(img, bmp.Width, bmp.Height);
            return(new TexturedQuadData(vertices, texcoords, bmp));
        }
コード例 #3
0
 protected static Vector3d[] GetVertices(FGEImage img)
 {
     return(new Vector3d[]
     {
         new Vector3d(img.TopLeft.X, 0.0, img.TopLeft.Y),
         new Vector3d(img.TopRight.X, 0.0, img.TopRight.Y),
         new Vector3d(img.BottomRight.X, 0.0, img.BottomRight.Y),
         new Vector3d(img.BottomLeft.X, 0.0, img.BottomLeft.Y)
     });
 }
コード例 #4
0
        protected static Vector4d[] GetTexCoords(FGEImage img, int width, int height)
        {
            Vector4d[] texcoords = new Vector4d[]
            {
                new Vector4d(img.pxTopLeft.X * 1.0 / width, img.pxTopLeft.Y * 1.0 / height, 0, 1),
                new Vector4d(img.pxTopRight.X * 1.0 / width, img.pxTopRight.Y * 1.0 / height, 0, 1),
                new Vector4d(img.pxBottomRight.X * 1.0 / width, img.pxBottomRight.Y * 1.0 / height, 0, 1),
                new Vector4d(img.pxBottomLeft.X * 1.0 / width, img.pxBottomRight.Y * 1.0 / height, 0, 1)
            };

            if (img.TopLeft.X == img.BottomLeft.X &&
                img.TopRight.X == img.BottomRight.X &&
                img.TopLeft.Y == img.TopRight.Y &&
                img.BottomLeft.Y == img.BottomRight.Y)
            {
                Vector2d a     = new Vector2d(img.pxTopRight.X - img.pxBottomLeft.X, img.pxTopRight.Y - img.pxBottomLeft.Y);
                Vector2d b     = new Vector2d(img.pxTopLeft.X - img.pxBottomRight.X, img.pxTopLeft.Y - img.pxBottomRight.Y);
                double   cross = a.X * b.Y - b.X * a.Y;

                if (cross != 0)
                {
                    Vector2d c  = new Vector2d(img.pxBottomLeft.X - img.pxBottomRight.X, img.pxBottomLeft.Y - img.pxBottomRight.Y);
                    double   qa = (a.X * c.Y - c.X * a.Y) / cross;
                    double   qb = (b.X * c.Y - c.X * b.Y) / cross;
                    if (qa > 0 && qa < 1 && qb > 0 && qb < 1)
                    {
                        texcoords = new Vector4d[]
                        {
                            texcoords[0] * qb,
                            texcoords[1] * qa,
                            texcoords[2] * (1 - qb),
                            texcoords[3] * (1 - qa)
                        };
                    }
                }
            }

            return(texcoords);
        }