Example #1
0
        protected override void OnRender()
        {
            if (currTransform == null)
                return;

            base.OnRender();
            Vector2 min = this.position - this.scale; // new Vector2(-0.25f, 0.6f);
            Vector2 max = this.position + this.scale; //new Vector2(0.25f, 0.7f);

            float pivot = (float)compassTickDelta / 65.0f;

            Vector3 dir = currTransform.GetTransform().Forward;
            float theta = 0.5f + 0.5f * (float)Math.Atan2(dir.Z, dir.X) / MathHelper.Pi;

            Vector2 minTC = new Vector2(theta - pivot, 0);
            Vector2 maxTC = new Vector2(theta + pivot, 1);

            GUIElementTC compass = new GUIElementTC(min, max, compassTexture, Vector4.One, minTC, maxTC);
            GFX.Inst.GetGUI().AddElement(compass);

            for (int i = 0; i < compassDirs.Length; i++)
            {
                float currDirTC = compassTCs[i];
                if (currDirTC < minTC.X)
                    currDirTC++;
                if (minTC.X < currDirTC && currDirTC < maxTC.X)
                {
                    float lerpAmount = (currDirTC - minTC.X) / (maxTC.X - minTC.X);
                    Vector2 textPos = Vector2.Lerp(min, max, lerpAmount);
                    textPos.Y = (min.Y + max.Y) * 0.5f;
                    GUITextElement cardinalDirection = new GUITextElement(textPos, compassDirs[i], Vector4.One);
                    GFX.Inst.GetGUI().AddElement(cardinalDirection);
                }
            }

            DrawMarkers(min, max, minTC, maxTC);

            const float offsetY = 0.045f;
            float offsetX = offsetY * GFX.Inst.DisplayRes.Y / GFX.Inst.DisplayRes.X;
            Vector2[] corners = { new Vector2(min.X-offsetX, min.Y), new Vector2(min.X, max.Y),
                                  new Vector2(max.X, min.Y), new Vector2(max.X+offsetX, max.Y),
                                  new Vector2(min.X-offsetX, min.Y-offsetY), new Vector2(max.X+offsetX, min.Y),
                                  new Vector2(min.X-offsetX, max.Y), new Vector2(max.X+offsetX, max.Y+offsetY)
                                };
            int quadCount = corners.Length / 2;
            for (int i = 0; i < quadCount; i++)
            {
                int index = i * 2;
                GUIElement box = new GUIElement(corners[index], corners[index + 1], null, Vector3.One * 0.15f);
                GFX.Inst.GetGUI().AddElement(box);
            }
        }
 public void AddElement(GUIElementTC element)
 {
     ElementsTC.Add(element);
 }
        void DrawCompass()
        {
            Vector2 min = new Vector2(-0.25f, 0.6f);
            Vector2 max = new Vector2(0.25f, 0.7f);

            float pivot = (float)compassTickDelta / 45.0f;
            Vector3 dir = Vector3.Zero;// currTank.GetCannonDirection();
            float theta = 0.5f + 0.5f*(float)Math.Atan2(dir.Z, dir.X)/MathHelper.Pi;

            Vector2 minTC = new Vector2(theta - pivot, 0);
            Vector2 maxTC = new Vector2(theta + pivot, 1);

            GUIElementTC compass = new GUIElementTC(min, max, compassTexture, Vector4.One, minTC, maxTC);
            GFX.Inst.GetGUI().AddElement(compass);

            for (int i = 0; i < compassDirs.Length; i++)
            {
                float currDirTC = compassTCs[i];
                if(currDirTC < minTC.X)
                    currDirTC++;
                if (minTC.X < currDirTC && currDirTC < maxTC.X)
                {
                    float lerpAmount = (currDirTC - minTC.X) / (maxTC.X - minTC.X);
                    Vector2 textPos = Vector2.Lerp(min, max, lerpAmount);
                    textPos.Y = (min.Y + max.Y) * 0.5f;
                    GUITextElement cardinalDirection = new GUITextElement(textPos, compassDirs[i], Vector4.One);
                    GFX.Inst.GetGUI().AddElement(cardinalDirection);
                }
            }

            const float offsetY = 0.045f;
            float offsetX = offsetY * GFX.Inst.DisplayRes.Y / GFX.Inst.DisplayRes.X;
            Vector2[] corners = { new Vector2(min.X-offsetX, min.Y), new Vector2(min.X, max.Y),
                                  new Vector2(max.X, min.Y), new Vector2(max.X+offsetX, max.Y),
                                  new Vector2(min.X-offsetX, min.Y-offsetY), new Vector2(max.X+offsetX, min.Y),
                                  new Vector2(min.X-offsetX, max.Y), new Vector2(max.X+offsetX, max.Y+offsetY)
                                };
            int quadCount = corners.Length / 2;
            for (int i = 0; i < quadCount; i++)
            {
                int index = i * 2;
                GUIElement box = new GUIElement(corners[index], corners[index + 1], null, Vector3.One * 0.15f);
                GFX.Inst.GetGUI().AddElement(box);
            }
        }
 public void AddElement(GUIElementTC element)
 {
     ElementsTC.Enqueue(element);
 }