Пример #1
0
        private string LoadSVG(string filePath)
        {
            XmlTextReader reader   = null;
            string        debugMsg = "";
            Point         min      = new System.Drawing.Point(int.MaxValue, int.MaxValue);
            Point         max      = new System.Drawing.Point(int.MinValue, int.MinValue);

            // Load the reader with the data file and ignore all white space nodes.
            reader = new XmlTextReader(filePath);
            reader.WhitespaceHandling = WhitespaceHandling.None;

            // Parse the file.
            svgList = new ArrayList();
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (reader.Name)
                    {
                    case "rect":
                    case "circle":
                    case "line":
                    case "polyline":
                    case "polygon":
                        SvgShape s = new SvgShape(reader);
                        svgList.Add(s);
                        min.X     = Math.Min(min.X, s.min.X);
                        min.Y     = Math.Min(min.Y, s.min.Y);
                        max.X     = Math.Max(max.X, s.max.X);
                        max.Y     = Math.Max(max.Y, s.max.Y);
                        debugMsg += s.debugMsg + " ";
                        break;
                    }
                    break;
                }
            }
            reader.Close();
            // compute size and offset
            int maxDimension = Math.Max(max.X - min.X, max.Y - min.Y);

            spriteSize   = new Rectangle(0, 0, maxDimension, maxDimension);
            spriteOffset = new Point((max.X - min.X) / 2 + min.X, (max.Y - min.Y) / 2 + min.Y);

            return(debugMsg);
        }
Пример #2
0
        /// <summary>
        /// This is where we do our rendering
        /// Called from UI thread = UI code safe in this function
        /// </summary>
        public override void Render(DrawArgs drawArgs)
        {
            if (!isInitialized)
            {
                return;
            }

            // Camera shortcut ;)
            CameraBase camera = drawArgs.WorldCamera;
            Device     device = drawArgs.device;

            // Save fog status
            bool origFog = device.RenderState.FogEnable;

            device.RenderState.FogEnable = false;

            if (drawArgs.device.RenderState.Lighting)
            {
                drawArgs.device.RenderState.Lighting = false;
                drawArgs.device.RenderState.Ambient  = World.Settings.StandardAmbientColor;
            }
            // Save original projection and change it to ortho
            // Note: using pixels as units produce a 1:1 projection of textures
            Matrix origProjection = device.Transform.Projection;

            // Save original View and change it to place compass
            Matrix origView = device.Transform.View;

            Matrix origWorld = device.Transform.World;

            device.Transform.Projection = Matrix.OrthoRH((float)device.Viewport.Width, (float)device.Viewport.Height, -(float)4e3, (float)4e3);

            // Note: the compass is centered on origin, the camera view moves.
            float offsetY = 0;
            float offsetZ = 0;

            switch (spritePos)
            {
            case "Bottom-Left":
                // lower left corner
                offsetY = (float)device.Viewport.Width / 2 - spriteSize.Width / 2 - 10;
                offsetZ = (float)device.Viewport.Height / 2 - spriteSize.Height / 2 - 10;
                break;

            case "Bottom-Center":
                // bottom centered
                offsetY = 0;
                offsetZ = (float)device.Viewport.Height / 2 - spriteSize.Height / 2 - 10;
                break;

            case "Screen-Center":
                // plain centered
                offsetY = 0;
                offsetZ = 0;
                break;

            case "Top-Right":
                // upper right corner
                offsetY = -((float)device.Viewport.Width / 2 - spriteSize.Width / 2 - 10);
                offsetZ = -((float)device.Viewport.Height / 2 - spriteSize.Height / 2 - 10);
                if (World.Settings.ShowToolbar)
                {
                    offsetZ += 50;
                }
                if (World.Settings.ShowPosition)
                {
                    offsetZ += 140;
                }
                break;

            case "Top-Center":
                // up center
                offsetY = 0;
                offsetZ = -((float)device.Viewport.Height / 2 - spriteSize.Height / 2 - 10);
                if (World.Settings.ShowToolbar)
                {
                    offsetZ += 50;
                }
                break;

            case "Top-Left":
                // upper left corner
                offsetY = ((float)device.Viewport.Width / 2 - spriteSize.Width / 2 - 6);
                offsetZ = -((float)device.Viewport.Height / 2 - spriteSize.Height / 2 - 4);
                if (World.Settings.ShowToolbar)
                {
                    offsetZ += 40;
                }
                break;
            }
            //offsetY += spriteOffset.X;
            //offsetZ += -spriteOffset.Y;
            device.Transform.View = Matrix.LookAtRH(
                new Vector3((float)1e3, offsetY, offsetZ),                      // Cam pos
                new Vector3(0, offsetY, offsetZ),                               // Cam target
                new Vector3(0, 0, 1));                                          // Up vector

            // Offset, rotate and tilt
            Matrix trans = Matrix.Translation(0, -(float)spriteOffset.X, (float)spriteOffset.Y);

            trans *= Matrix.RotationX((float)camera.Heading.Radians);
            if (tilt)
            {
                trans *= Matrix.RotationY((float)camera.Tilt.Radians);
            }
            device.Transform.World = trans;

            // Render Compass here
            if (svgList != null)                                        // ** SVG
            {
                for (int i = 0; i < svgList.Count; i++)
                {
                    SvgShape s = (SvgShape)svgList[i];
                    s.Render(drawArgs);
                }
            }

            if (texture != null)                                // ** Bitmap
            {
                // Calculate the triangle vertices (triangle 1)
                // Note: use pixels as unit for 1:1 ortho projection
                float y = (float)spriteSize.Width / 2;
                float z = (float)spriteSize.Height / 2;

                borderVertices[0].X  = 0;
                borderVertices[0].Y  = -y;
                borderVertices[0].Z  = -z;
                borderVertices[0].Tu = 0;
                borderVertices[0].Tv = 1;

                borderVertices[1].X  = 0;
                borderVertices[1].Y  = y;
                borderVertices[1].Z  = -z;
                borderVertices[1].Tu = 1;
                borderVertices[1].Tv = 1;

                borderVertices[2].X  = 0;
                borderVertices[2].Y  = -y;
                borderVertices[2].Z  = z;
                borderVertices[2].Tu = 0;
                borderVertices[2].Tv = 0;

                // Triangle 2 (uses previous 2 vertices as first 2 points (TriangleStrip))
                borderVertices[3].X  = 0;
                borderVertices[3].Y  = y;
                borderVertices[3].Z  = z;
                borderVertices[3].Tu = 1;
                borderVertices[3].Tv = 0;

                // Draw our 2 triangles
                device.VertexFormat = CustomVertex.PositionTextured.Format;
                device.SetTexture(0, texture);
                device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;
                device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
                device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;
                device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;

                device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, borderVertices);
            }
            // Restore device states
            device.Transform.World           = origWorld;
            device.Transform.Projection      = origProjection;
            device.Transform.View            = origView;
            device.RenderState.ZBufferEnable = true;
            device.RenderState.FogEnable     = origFog;
        }
Пример #3
0
        private string LoadSVG(string filePath)
        {
            XmlTextReader reader = null;
            string debugMsg = "";
            Point min = new System.Drawing.Point(int.MaxValue, int.MaxValue);
            Point max = new System.Drawing.Point(int.MinValue, int.MinValue);

            // Load the reader with the data file and ignore all white space nodes.
            reader = new XmlTextReader(filePath);
            reader.WhitespaceHandling = WhitespaceHandling.None;

            // Parse the file.
            svgList = new ArrayList();
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        switch (reader.Name)
                        {
                            case "rect":
                            case "circle":
                            case "line":
                            case "polyline":
                            case "polygon":
                                SvgShape s = new SvgShape(reader);
                                svgList.Add(s);
                                min.X = Math.Min(min.X, s.min.X);
                                min.Y = Math.Min(min.Y, s.min.Y);
                                max.X = Math.Max(max.X, s.max.X);
                                max.Y = Math.Max(max.Y, s.max.Y);
                                debugMsg += s.debugMsg + " ";
                                break;
                        }
                        break;
                }
            }
            reader.Close();
            // compute size and offset
            int maxDimension = Math.Max(max.X - min.X, max.Y - min.Y);
            spriteSize = new Rectangle(0, 0, maxDimension, maxDimension);
            spriteOffset = new Point((max.X - min.X) / 2 + min.X, (max.Y - min.Y) / 2 + min.Y);

            return debugMsg;
        }