Пример #1
0
            public IEnumerable <GLTK.Entity> GetEntities(Chunk xiRootChunk, eTextureMode xiTextureMode, eTexMetaDataEntries xiSelectedMetadata)
            {
                //a bit hacky:
                if (this.TreeNode.Checked)
                {
                    return(new Entity[0]);
                }

                Entity lWeaponEntity = ((Level)xiRootChunk).GetObjtById(TMDChunk.OBJT_ID_FOR_WEAPONS_BOX)
                                       .GetEntity(xiRootChunk, xiTextureMode, xiSelectedMetadata, this);

                // Set the position.
                Point lWeaponPosition = ThreeDeeViewer.Short3CoordToPoint(this.OriginPosition);

                lWeaponEntity.Position = new Point(lWeaponPosition.x, lWeaponPosition.y, -lWeaponPosition.z);

                List <GLTK.Entity> lRet = new List <Entity>();

                lRet.Add(lWeaponEntity);
                return(lRet);
            }
Пример #2
0
        private GLTK.Entity GetSurfaceEntity(Level xiLevel, eTextureMode xiTextureMode, eTexMetaDataEntries xiSelectedMetadata)
        {
            // notes:
            // invert the textures along the y-axis
            // use level co-ords, so z is down

            /////////////////////////////////////////////////////
            // The surface
            Entity lSurface = new MMEdEntity(this);

            Font  lNumberFont = null;
            Brush lNumberFGBrush = null, lNumberBGBrush = null;
            Pen   lWaypointPen = null, lKeyWaypointPen = null;

            if (xiTextureMode == eTextureMode.NormalTexturesWithMetadata)
            {
                lNumberFont     = new Font(FontFamily.GenericMonospace, 10);
                lNumberFGBrush  = new SolidBrush(Color.Black);
                lNumberBGBrush  = new SolidBrush(Color.White);
                lWaypointPen    = new Pen(Color.Black, 1f);
                lKeyWaypointPen = new Pen(Color.Red, 2f);
            }

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    Mesh lSquare = new OwnedMesh(this, PolygonMode.Quads);
                    lSquare.AddFace(
                        new Vertex(new Point(x, y, -GetTerrainHeightSafe(x, y)), 0, 0),
                        new Vertex(new Point(x + 1, y, -GetTerrainHeightSafe(x + 1, y)), 1, 0),
                        new Vertex(new Point(x + 1, y + 1, -GetTerrainHeightSafe(x + 1, y + 1)), 1, 1),
                        new Vertex(new Point(x, y + 1, -GetTerrainHeightSafe(x, y + 1)), 0, 1));

                    switch (xiTextureMode)
                    {
                    case eTextureMode.WireFrame:
                        lSquare.RenderMode = RenderMode.Wireframe;
                        break;

                    // normal textures, optionally with metadata drawn on
                    case eTextureMode.NormalTextures:
                    case eTextureMode.NormalTexturesWithMetadata:
                        TIMChunk lTIM = xiLevel.GetTileById(TextureIds[x][y]);

                        if (lTIM != null)
                        {
                            //some TIMs can't be loaded yet: they're null
                            Bitmap lTexture = lTIM.ToBitmap();
                            if (xiTextureMode == eTextureMode.NormalTexturesWithMetadata &&
                                TexMetaData != null)
                            {
                                byte lVal = TexMetaData[x][y][(int)xiSelectedMetadata];

                                if (lVal != 0)
                                {
                                    // we create a new bitmap based on the given texture
                                    // a) so that we can modify it freely
                                    // and b) to change it from indexed to full colour mode, to allow us
                                    // to draw on it (otherwise we'll get an exception)
                                    lTexture = new Bitmap(lTexture);

                                    Graphics g = Graphics.FromImage(lTexture);

                                    string lText = lVal.ToString();

                                    SizeF size = g.MeasureString(lText, lNumberFont);

                                    float xf = lTexture.Width / 2.0f - size.Width / 2.0f;
                                    float yf = lTexture.Height / 2.0f - size.Height / 2.0f;

                                    g.FillRectangle(lNumberBGBrush, xf, yf, size.Width, size.Height);

                                    g.DrawString(
                                        lText,
                                        lNumberFont,
                                        lNumberFGBrush,
                                        xf,
                                        yf);

                                    if (xiSelectedMetadata == eTexMetaDataEntries.Waypoint)
                                    {
                                        Pen lPen = xiLevel.WaypointIsKeyWaypoint(lVal)
                          ? lKeyWaypointPen
                          : lWaypointPen;

                                        g.DrawRectangle(
                                            lPen,
                                            0, 0, lTexture.Width - 1, lTexture.Height - 1);
                                    }
                                }
                            }

                            lSquare.Texture = AbstractRenderer.ImageToTextureId(lTexture);
                        }
                        break;

                    //draw the bumpmap textures on:
                    case eTextureMode.BumpmapTextures:
                        if (TexMetaData != null)
                        {
                            BumpImageChunk lBIC = xiLevel.GetBumpById(TexMetaData[x][y][(int)eTexMetaDataEntries.Bumpmap]);

                            if (lBIC != null)
                            {
                                Bitmap lTexture = lBIC.ToBitmap();
                                lSquare.Texture = AbstractRenderer.ImageToTextureId(lTexture);
                            }
                        }
                        break;

                    default: throw new Exception("Unexpected case");
                    } //end switch

                    lSurface.Meshes.Add(lSquare);
                }
            }

            lSurface.Scale(ScaleX, ScaleY, 1.0);
            if (RotationVector.Norm() != 0)
            {
                //the rotation is z-y-x
                lSurface.RotateAboutWorldOrigin(RotationVector.Z / 1024.0 * Math.PI / 2.0, Vector.ZAxis);
                lSurface.RotateAboutWorldOrigin(-RotationVector.Y / 1024.0 * Math.PI / 2.0, Vector.YAxis);
                lSurface.RotateAboutWorldOrigin(-RotationVector.X / 1024.0 * Math.PI / 2.0, Vector.XAxis);
            }

            Point lNewPos = ThreeDeeViewer.Short3CoordToPoint(OriginPosition);

            lSurface.Position = new Point(lNewPos.x, lNewPos.y, -lNewPos.z);

            return(lSurface);
        }