/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { if (text3ds.Count > 0) { // Catch exception in case text3ds becomes empty after deletion in Update try { Text3DInfo[] text3DArray = new Text3DInfo[text3ds.Count]; // Copy the display list to an array since the display list can be modified // at any time text3ds.CopyTo(text3DArray); // Render the 3D texts in the display list in outline style with red color foreach (Text3DInfo text3d in text3DArray) { UI3DRenderer.Write3DText(text3d.Text, vectorFont, UI3DRenderer.Text3DStyle.Outline, Color.Red, text3d.Transform); } } catch (Exception) { } } scene.Draw(gameTime.ElapsedGameTime, gameTime.IsRunningSlowly); }
public void Dispose() { comp2Ds.Clear(); comp3Ds.Clear(); UI2DRenderer.Dispose(); UI3DRenderer.Dispose(); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { // If ground marker array is detected if (groundMarkerNode.MarkerFound) { // If the toolbar marker array is detected, then overlay the box model on top // of the toolbar marker array; otherwise, overlay the box model on top of // the ground marker array if (toolbarMarkerNode.MarkerFound) { // The box model is overlaid on the ground marker array, so in order to // make the box model appear overlaid on the toolbar marker array, we need // to offset the ground marker array's transformation. Thus, we multiply // the toolbar marker array's transformation with the inverse of the ground marker // array's transformation, which becomes T*G(inv)*G = T*I = T as a result, // where T is the transformation of the toolbar marker array, G is the // transformation of the ground marker array, and I is the identity matrix. // The Vector3(0, 0, 16.1) is a shift translation to make the box overlaid right // on top of the toolbar marker. The top-left corner of the left marker of the // toolbar marker array is defined as (0, 0, 0), so in order to make the box model // appear right on top of the left marker of the toolbar marker array, we shift by // half of each dimension of the 8x8x8 box model. The approach used here requires that // the ground marker array remains visible at all times. Vector3 shiftVector = new Vector3(0, 0, 5f); Matrix mat = Matrix.CreateTranslation(shiftVector) * toolbarMarkerNode.WorldTransformation * Matrix.Invert(groundMarkerNode.WorldTransformation); // Modify the transformation in the physics engine ((NewtonPhysics)scene.PhysicsEngine).SetTransform(boxNode.Physics, mat); } else { ((NewtonPhysics)scene.PhysicsEngine).SetTransform(boxNode.Physics, Matrix.CreateTranslation(0, 0, 5f)); } } UI3DRenderer.Write3DText("Score: " + score, vectorFont, UI3DRenderer.Text3DStyle.Extrude, Color.Lavender, toolbarMarkerNode.WorldTransformation); scene.Draw(gameTime.ElapsedGameTime, gameTime.IsRunningSlowly); }
/// <summary> /// Create a 3D text with the font name (the asset name of the spritefont file), the text to render, /// and the mesh style /// </summary> /// <param name="fontToUse">String of the font type to use (the asset name of the spritefont file)</param> /// <param name="textToRender">String of the text to render</param> /// <param name="styleToUse">Type of rendering to use in how we create the 3D mesh</param> /// public Text3D(String fontToUse, String textToRender, UI3DRenderer.Text3DStyle styleToUse) : base() { basicTextToRender = textToRender; basicTextVectorFont = State.Content.Load<VectorFont>(fontToUse); this.styleToUse = styleToUse; CreateText(); }
/// <summary> /// Create a 3D text with the font, the text to render, and the mesh style /// </summary> /// <param name="fontToUse">Font type to use</param> /// <param name="textToRender">String of the text to render</param> /// <param name="styleToUse">Type of rendering to use in how we create the 3D mesh</param> public Text3D(VectorFont fontToUse, String textToRender, UI3DRenderer.Text3DStyle styleToUse) : base() { basicTextToRender = textToRender; basicTextVectorFont = fontToUse; this.styleToUse = styleToUse; CreateText(); }
/// <summary> /// Draws all of the user interface components. /// </summary> /// <remarks>Do not call this method. This method will be called automatically</remarks> /// <param name="elapsedTime"></param> /// <param name="clear"></param> /// <param name="renderRightEye"></param> public void Draw(float elapsedTime, bool clear, bool renderRightEye) { State.Device.DepthStencilState = DepthStencilState.None; passedTime += elapsedTime; if (passedTime >= 1000) { passedTime = 0; prevCounter = counter; counter = 1; } else if (elapsedTime != 0) { counter++; } float y = 5; float x = 5; if (State.ShowFPS) { if (debugFont == null) { throw new GoblinException("You need to add 'DebugFont.spritefont' file to your " + "content directory before you can display debug information"); } UI2DRenderer.WriteText(new Vector2(x, y), prevCounter + " FPS", State.DebugTextColor, debugFont); y += 20; } if (State.ShowTriangleCount) { if (debugFont == null) { throw new GoblinException("You need to add 'DebugFont.spritefont' file to your " + "content directory before you can display debug information"); } UI2DRenderer.WriteText(new Vector2(x, y), triangleCount + " Triangles", State.DebugTextColor, debugFont); y += 20; } if (State.ShowNotifications) { if (debugFont == null) { throw new GoblinException("You need to add 'DebugFont.spritefont' file to your " + "content directory before you can display debug information"); } if (Notifier.MessageCount > 0) { messages.AddRange(Notifier.GetMessages()); } if (messages.Count > 0) { float yGap = Notifier.Font.MeasureString(messages[0].Message).Y; Color color; switch (Notifier.Placement) { case Notifier.NotifierPlacement.TopRight: y = 0; for (int i = messages.Count - 1; i >= 0; i--) { color = Notifier.Color; if (messages[i].StartFadeOut) { color = new Color(color.R, color.G, color.B, (byte)messages[i].FadeOutInterpolator.Value); } UI2DRenderer.WriteText(new Vector2(0, y), messages[i].Message, color, Notifier.Font, Vector2.One, GoblinEnums.HorizontalAlignment.Right, GoblinEnums.VerticalAlignment.None); y += yGap; } break; case Notifier.NotifierPlacement.TopMiddle: y = 0; for (int i = messages.Count - 1; i >= 0; i--) { color = Notifier.Color; if (messages[i].StartFadeOut) { color = new Color(color.R, color.G, color.B, (byte)messages[i].FadeOutInterpolator.Value); } UI2DRenderer.WriteText(new Vector2(0, y), messages[i].Message, color, Notifier.Font, Vector2.One, GoblinEnums.HorizontalAlignment.Center, GoblinEnums.VerticalAlignment.None); y += yGap; } break; case Notifier.NotifierPlacement.TopLeft: for (int i = messages.Count - 1; i >= 0; i--) { color = Notifier.Color; if (messages[i].StartFadeOut) { color = new Color(color.R, color.G, color.B, (byte)messages[i].FadeOutInterpolator.Value); } UI2DRenderer.WriteText(new Vector2(0, y), messages[i].Message, color, Notifier.Font, Vector2.One, GoblinEnums.HorizontalAlignment.Left, GoblinEnums.VerticalAlignment.None); y += yGap; } break; case Notifier.NotifierPlacement.BottomRight: y = State.Height - yGap; for (int i = messages.Count - 1; i >= 0; i--) { color = Notifier.Color; if (messages[i].StartFadeOut) { color = new Color(color.R, color.G, color.B, (byte)messages[i].FadeOutInterpolator.Value); } UI2DRenderer.WriteText(new Vector2(0, y), messages[i].Message, color, Notifier.Font, Vector2.One, GoblinEnums.HorizontalAlignment.Right, GoblinEnums.VerticalAlignment.None); y -= yGap; } break; case Notifier.NotifierPlacement.BottomMiddle: y = State.Height - yGap; for (int i = messages.Count - 1; i >= 0; i--) { color = Notifier.Color; if (messages[i].StartFadeOut) { color = new Color(color.R, color.G, color.B, (byte)messages[i].FadeOutInterpolator.Value); } UI2DRenderer.WriteText(new Vector2(0, y), messages[i].Message, color, Notifier.Font, Vector2.One, GoblinEnums.HorizontalAlignment.Center, GoblinEnums.VerticalAlignment.None); y -= yGap; } break; case Notifier.NotifierPlacement.BottomLeft: y = State.Height - yGap; for (int i = messages.Count - 1; i >= 0; i--) { color = Notifier.Color; if (messages[i].StartFadeOut) { color = new Color(color.R, color.G, color.B, (byte)messages[i].FadeOutInterpolator.Value); } UI2DRenderer.WriteText(new Vector2(0, y), messages[i].Message, color, Notifier.Font, Vector2.One, GoblinEnums.HorizontalAlignment.Left, GoblinEnums.VerticalAlignment.None); y -= yGap; } break; case Notifier.NotifierPlacement.Custom: x = Notifier.CustomStartLocation.X; y = Notifier.CustomStartLocation.Y; for (int i = messages.Count - 1; i >= 0; i--) { color = Notifier.Color; if (messages[i].StartFadeOut) { color = new Color(color.R, color.G, color.B, (byte)messages[i].FadeOutInterpolator.Value); } UI2DRenderer.WriteText(new Vector2(x, y), messages[i].Message, color, Notifier.Font, Vector2.One, GoblinEnums.HorizontalAlignment.Right, GoblinEnums.VerticalAlignment.None); x -= Notifier.CustomAppearDirection.X; y += Notifier.CustomAppearDirection.Y; } break; } if (Notifier.FadeOutTime > 0) { double currentTime = DateTime.Now.TimeOfDay.TotalMilliseconds; for (int i = 0; i < messages.Count; i++) { if (!messages[i].StartFadeOut) { if ((currentTime - messages[i].StartTime) >= Notifier.FadeOutTime) { messages[i].StartFadeOut = true; messages[i].FadeOutInterpolator.Start(); } else { break; } } } int deleteCount = 0; for (int i = 0; i < messages.Count; i++) { if (messages[i].StartFadeOut) { if (messages[i].FadeOutInterpolator.Done) { deleteCount++; } } else { break; } } messages.RemoveRange(0, deleteCount); } } } foreach (G2DComponent comp2d in comp2Ds) { comp2d.RenderWidget(); } if (renderRightEye) { UI2DRenderer.Flush(clear, -globalUIShift / 2); } else { UI2DRenderer.Flush(clear, globalUIShift / 2); } State.Device.DepthStencilState = DepthStencilState.Default; UI3DRenderer.Flush(clear); }