using System; using System.Collections.Generic; using System.Text; using Microsoft.DirectX.Direct3D; using Microsoft.DirectX; using System.Drawing; namespace SalsaModel { public class Message3D { Mesh TextMesh; Material TextMaterial; Material HiliteMaterial; private SizeF ComputeTextBounds(GlyphMetricsFloat[] gmfs) { float xextent = 0; float yextent = 0; float offsety = 0; foreach (GlyphMetricsFloat gmf in gmfs) { xextent += gmf.CellIncX; float y = offsety + gmf.BlackBoxY; if (y > yextent) { yextent = y; } offsety += gmf.CellIncY; } return new SizeF(xextent, yextent); } SizeF textSize; public Message3D(Device dev, string text) : this(dev, text, 0.25f) { } public Message3D(Device dev, string text, float extrusion) { GlyphMetricsFloat[] metrics; TextMesh = Mesh.TextFromFont(dev, new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, 12), text, 0.1f, extrusion, out metrics); TextMaterial = new Material(); TextMaterial.Ambient = Color.WhiteSmoke; TextMaterial.Specular = Color.White; TextMaterial.SpecularSharpness = 1000f; HiliteMaterial = new Material(); HiliteMaterial.Ambient = Color.HotPink; HiliteMaterial.Specular = Color.White; HiliteMaterial.SpecularSharpness = 1000f; textSize = ComputeTextBounds(metrics); } public void Draw(Device dev, Location loc, double size) { Draw(dev, loc, size, false); } public void Draw(Device dev, Location loc, double size, Material mat) { //Matrix transform = Matrix.Scaling(50, 50, 50); //transform.Translate(BasicDrawing.Vec3(loc)); dev.Material = mat; Matrix transform = Matrix.Identity; transform.Multiply(Matrix.Translation(-textSize.Width / 2f, -textSize.Height / 2f, 0.125f)); transform.Multiply(Matrix.Scaling((float)size, (float)size, (float)size)); transform.Multiply(Matrix.Translation(BasicDrawing.Vec3(loc))); Matrix oldTransform = dev.Transform.World; dev.Transform.World = transform; TextMesh.DrawSubset(0); dev.Transform.World = oldTransform; } public void DrawStartingAt(Device dev, Location loc, double size, Material mat) { //Matrix transform = Matrix.Scaling(50, 50, 50); //transform.Translate(BasicDrawing.Vec3(loc)); dev.Material = mat; Matrix transform = Matrix.Identity; transform.Multiply(Matrix.Translation(0, 0, 0.125f)); transform.Multiply(Matrix.Scaling((float)size, (float)size, (float)size)); transform.Multiply(Matrix.Translation(BasicDrawing.Vec3(loc))); Matrix oldTransform = dev.Transform.World; dev.Transform.World = transform; TextMesh.DrawSubset(0); dev.Transform.World = oldTransform; } public void Draw(Device dev, Location loc, double size, bool hilite) { Draw(dev, loc, size, hilite ? HiliteMaterial : TextMaterial); } } }