protected override void OnRender(float dt, float betweenFrameAlpha) { //var world = Matrix.Identity; //var view = Matrix.CreateLookAt(Vector3.Backward, Vector3.Forward, Vector3.Up); //var projection = Matrix.CreatePerspectiveFieldOfView( // MathHelper.PiOver2, // GameManager.GraphicsDevice.Viewport.Width / (float)GameManager.GraphicsDevice.Viewport.Height, // 0.01f, // 1000.0f); //var wvp = world * view * projection; /** Based on MonoGame SpriteBatch implementation!! **/ // Normal 3D cameras look into the -z direction (z = 1 is in front of z = 0). The // sprite batch layer depth is the opposite (z = 0 is in front of z = 1). // --> We get the correct matrix with near plane 0 and far plane -1. Matrix projection; //Matrix.CreateOrthographicOffCenter(0, GameManager.GraphicsDevice.Viewport.Width, GameManager.GraphicsDevice.Viewport.Height, // 0, 0, -1, out projection); Matrix.CreateOrthographicOffCenter(0, GameManager.GraphicsDevice.Viewport.Width, 0, GameManager.GraphicsDevice.Viewport.Height, -1, 1, out projection); Matrix wvp = Camera.GetInterpolatedTransformMatrix(1) * projection; int enableFrameSmoothingFlag = CVars.Get <bool>("graphics_frame_smoothing") ? 0 : 1; _textRenderer.Begin(wvp); foreach (Entity entity in Engine.GetEntitiesFor(fontFamily)) { TransformComponent transformComp = entity.GetComponent <TransformComponent>(); FieldFontComponent fieldFontComp = entity.GetComponent <FieldFontComponent>(); Vector2 position = transformComp.Position + (transformComp.LastPosition - transformComp.Position) * (1 - betweenFrameAlpha) * enableFrameSmoothingFlag; float rotation = transformComp.Rotation + MathHelper.WrapAngle(transformComp.LastRotation - transformComp.Rotation) * (1 - betweenFrameAlpha) * enableFrameSmoothingFlag; rotation *= -1; float transformScale = transformComp.Scale + (transformComp.LastScale - transformComp.Scale) * (1 - betweenFrameAlpha) * enableFrameSmoothingFlag; _textRenderer.Draw(fieldFontComp.Font, fieldFontComp.Content, position, rotation, fieldFontComp.Color, transformScale, fieldFontComp.EnableKerning); } _textRenderer.End(); base.OnRender(dt, betweenFrameAlpha); }
private void DrawFieldFontEntities(Camera camera, byte groupMask, float dt, float betweenFrameAlpha, Camera debugCamera) { Matrix transformMatrix = debugCamera == null?camera.GetInterpolatedTransformMatrix(betweenFrameAlpha) : debugCamera.GetInterpolatedTransformMatrix(betweenFrameAlpha); if (_fieldFontEntities.Count > 0) { CheckUpdateProjections(); Matrix wvp = transformMatrix * _fieldFontRendererProjection; FieldFontRenderer.Begin(wvp); foreach (Entity entity in _fieldFontEntities) { FieldFontComponent fieldFontComp = entity.GetComponent <FieldFontComponent>(); if (fieldFontComp.Hidden || (fieldFontComp.RenderGroup & groupMask) == 0) { continue; } TransformComponent transformComp = entity.GetComponent <TransformComponent>(); BoundingRect boundRect = new BoundingRect(transformComp.Position.X - (fieldFontComp.Font.MeasureString(fieldFontComp.Content).X *transformComp.Scale / 2), transformComp.Position.Y - (fieldFontComp.Font.MeasureString(fieldFontComp.Content).Y *transformComp.Scale / 2), fieldFontComp.Font.MeasureString(fieldFontComp.Content).X *transformComp.Scale, fieldFontComp.Font.MeasureString(fieldFontComp.Content).Y *transformComp.Scale); if (!boundRect.Intersects(camera.BoundingRect) && CVars.Get <bool>("debug_show_render_culling")) { continue; } Vector2 position; float rotation; float transformScale; transformComp.Interpolate(betweenFrameAlpha, out position, out rotation, out transformScale); FieldFontRenderer.Draw(fieldFontComp.Font, fieldFontComp.Content, position, rotation, fieldFontComp.Color, transformScale, fieldFontComp.EnableKerning); } FieldFontRenderer.End(); } }
public override void Render(SpriteBatch spriteBatch, FieldFontRenderer fieldFontRenderer) { if (!Hidden) { // Labels maintain aspect-ratio, so it shouldn't matter which // axis we get the scale from. float scale = (BottomRight.X - TopLeft.X) / _bounds.X; Vector2 position = (BottomRight - TopLeft) / 2 + TopLeft; position.Y = Root.Height - position.Y; fieldFontRenderer.Draw(_font, Content, position, 0, TintColor, scale, true); } }