示例#1
0
文件: Editor.cs 项目: Tokter/TokED
        public Editor()
        {
            _tools = new Tools(this);

            _manager = new RenderManager();
            if (_editorCamera == null)
            {
                _editorCamera = new Camera();
                _editorCamera.CameraType = CameraType.Orthogonal;
                _editorCamera.Position = new Vector3(0, 0, 200);
                _editorCamera.LookAt = new Vector3(0, 0, 0);
                _editorCamera.ZNear = 0;
                _editorCamera.ZFar = 10000;
                _editorCamera.Up = new Vector3(0, 1, 0);
                _editorCamera.Fov = 1.0f;
            }

            if (_guiCamera == null)
            {
                _guiCamera = new Camera();
                _guiCamera.CameraType = CameraType.HUD;
                _guiCamera.Position = new Vector3(0, 0, 200);
                _guiCamera.LookAt = new Vector3(0, 0, 0);
                _guiCamera.ZNear = 0;
                _guiCamera.ZFar = 10000;
                _guiCamera.Up = new Vector3(0, 1, 0);
            }
            _guiFont = new TokGL.Font(Plugins.LoadResourceStream("ArialWhite.png"), Plugins.LoadResourceStream("ArialWhite.info"));

            _spriteBatch = new SpriteBatch();
            _lineBatch = new LineBatch();
        }
示例#2
0
        public TokGLRenderer()
        {
            KeyboardLayout = GetKeyboardLayout(0);
            KeyStates = new byte[0x100];

            _charMap.Add(82, '0');
            _charMap.Add(79, '1');
            _charMap.Add(80, '2');
            _charMap.Add(81, '3');
            _charMap.Add(75, '4');
            _charMap.Add(76, '5');
            _charMap.Add(77, '6');
            _charMap.Add(71, '7');
            _charMap.Add(72, '8');
            _charMap.Add(73, '9');
            _charMap.Add(83, '.');

            _manager = new RenderManager();
            _manager.Camera = new Camera();
            _manager.Camera.CameraType = CameraType.HUD;

            _batch = new SpriteBatch();
            _font[0] = new TokGL.Font(Plugins.LoadResourceStream("ArialBlack.png"),Plugins.LoadResourceStream("ArialBlack.info"));
            _font[1] = new TokGL.Font(Plugins.LoadResourceStream("ArialWhite.png"), Plugins.LoadResourceStream("ArialWhite.info"));

            //Load all UI textures:
            var textures = Plugins.GetKeys<UITexture>();
            foreach (var texture in textures)
            {
                Plugins.Container.ResolveNamed<UITexture>(texture);
            }
            _whiteID = UITexture.GetID("white");
        }
示例#3
0
文件: Font.cs 项目: Tokter/TokED
        public void CreateSprite(SpriteBatch batch, int px, int py, string text, Color color, HorizontalAlignment horizontal, VerticalAlignment vertical)
        {
            int width = MeasureWidth(text);
            int height = MeasureHeight(text);
            int x = 0, y = 0;
            switch (horizontal)
            {
                case HorizontalAlignment.Left: x = px; break;
                case HorizontalAlignment.Center: x = px - width / 2; break;
                case HorizontalAlignment.Right: x = px - width; break;
            }
            switch (vertical)
            {
                case VerticalAlignment.Top: y = py; break;
                case VerticalAlignment.Center: y = py - height / 2 - 1; break;
                case VerticalAlignment.Bottom: y = py - height; break;
            }

            byte[] bytes = System.Text.Encoding.Default.GetBytes(text);
            for (int i = 0; i < bytes.Length; i++)
            {
                var b = bytes[i];
                if (b != 32)
                {
                    if (i > 0)
                    {
                        x -= _kerning[bytes[i - 1] * 256 + bytes[i]]-1;
                    }

                    batch.AddSprite(_material, new Vector2(x, y + _charInfo[b].YOffset), new Vector2(x + _charInfo[b].Width, y + _charInfo[b].YOffset + _charInfo[b].Height), _charInfo[b].U1, _charInfo[b].V1, _charInfo[b].U2, _charInfo[b].V2, color);
                }
                x += _charInfo[b].Width;
            }
        }
示例#4
0
 public override void DrawContent(LineBatch lineBatch, SpriteBatch spriteBatch)
 {
     base.DrawContent(lineBatch, spriteBatch);
     lineBatch.Add(_spriteDef.P1, _spriteDef.P2, Color.Green);
     lineBatch.Add(_spriteDef.P3);
     lineBatch.Add(_spriteDef.P4);
     lineBatch.Add(_spriteDef.P1);
 }
示例#5
0
 public override void DrawGui(LineBatch lineBatch, SpriteBatch spriteBatch)
 {
     var ray = Camera.GetWorldRay(MousePos);
     var plane = new Plane(new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 1, 0));
     float? distance;
     ray.Intersects(ref plane, out distance);
     if (distance != null)
     {
         var pos = ray.Position + Vector3.Multiply(ray.Direction, distance.Value);
         spriteBatch.AddText(GuiFont, 250, 0, string.Format("X={0:n2} Y={1:n2}", pos.X, pos.Y), Color.White, HorizontalAlignment.Left, VerticalAlignment.Top);
     }
 }
示例#6
0
 public override void DrawContent(LineBatch lineBatch, SpriteBatch spriteBatch)
 {
     if (_mat != null)
     {
         spriteBatch.AddSprite(_mat, 0, 0, 0, 0, _mat[TextureUnit.Texture0].Width, _mat[TextureUnit.Texture0].Height);
         lineBatch.AddBox(0, 0, _mat[TextureUnit.Texture0].Width, _mat[TextureUnit.Texture0].Height, Color.Red);
     }
     else
     {
         lineBatch.Add(new Vector2(-100, -100), new Vector2(100, 100), Color.Red);
         lineBatch.Add(new Vector2(100, -100), new Vector2(-100, 100), Color.Red);
     }
 }
示例#7
0
 public override void DrawContent(LineBatch lineBatch, SpriteBatch spriteBatch)
 {
     _lineBatch = lineBatch;
     _spriteBatch = spriteBatch;
     if (_scene != null) RenderGameObject(_scene, Matrix4.Identity);
 }
示例#8
0
文件: Renderer.cs 项目: Tokter/TokED
 public virtual void Draw(LineBatch lineBatch, SpriteBatch spriteBatch)
 {
 }