Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
FontBatch3D.cs
浏览该文件的文档.
1using Engine.Media;
2
3namespace Engine.Graphics {
4 public class FontBatch3D : BaseFontBatch {
12
13 public void QueueText(string text, Vector3 position, Vector3 right, Vector3 down, Color color, TextAnchor anchor = TextAnchor.Default) {
15 text,
16 position,
17 right,
18 down,
19 color,
20 anchor,
22 );
23 }
24
25 public void QueueText(string text,
26 Vector3 position,
27 Vector3 right,
28 Vector3 down,
29 Color color,
30 TextAnchor anchor,
31 Vector2 spacing) {
32 Vector2 scale = new(right.Length(), down.Length());
33 Vector2 vector = CalculateTextOffset(text, 0, text.Length, anchor, scale, spacing);
34 Vector3 vector2 = position + vector.X * Vector3.Normalize(right) + vector.Y * Vector3.Normalize(down);
35 Vector3 v = vector2;
36 right *= Font.Scale;
37 down *= Font.Scale;
38 int num = 0;
39 for (int i = 0; i < text.Length; i++) {
40 char c = text[i];
41 if (c == '\u00a0') {
42 c = ' ';
43 }
44 switch (c) {
45 case '\n':
46 num++;
47 v = vector2 + num * (Font.GlyphHeight + Font.Spacing.Y + spacing.Y) * down;
48 continue;
49 case '\r':
50 case '\u200b': continue;
51 }
52 BitmapFont.Glyph glyph = Font.GetGlyph(c);
53 if (!glyph.IsBlank) {
54 Vector3 v2 = right * (glyph.TexCoord2.X - glyph.TexCoord1.X) * Font.Texture.Width;
55 Vector3 v3 = down * (glyph.TexCoord2.Y - glyph.TexCoord1.Y) * Font.Texture.Height;
56 Vector3 v4 = right * glyph.Offset.X + down * glyph.Offset.Y;
57 Vector3 v5 = v + v4;
58 Vector3 vector3 = v5 + v2;
59 Vector3 vector4 = v5 + v3;
60 Vector3 vector5 = v5 + v2 + v3;
61 int count = TriangleVertices.Count;
62 TriangleVertices.Count += 4;
64 new Vector3(v5.X, v5.Y, v5.Z),
65 color,
66 new Vector2(glyph.TexCoord1.X, glyph.TexCoord1.Y)
67 );
68 TriangleVertices.Array[count + 1] = new VertexPositionColorTexture(
69 new Vector3(vector3.X, vector3.Y, vector3.Z),
70 color,
71 new Vector2(glyph.TexCoord2.X, glyph.TexCoord1.Y)
72 );
73 TriangleVertices.Array[count + 2] = new VertexPositionColorTexture(
74 new Vector3(vector5.X, vector5.Y, vector5.Z),
75 color,
76 new Vector2(glyph.TexCoord2.X, glyph.TexCoord2.Y)
77 );
78 TriangleVertices.Array[count + 3] = new VertexPositionColorTexture(
79 new Vector3(vector4.X, vector4.Y, vector4.Z),
80 color,
81 new Vector2(glyph.TexCoord1.X, glyph.TexCoord2.Y)
82 );
83 int count2 = TriangleIndices.Count;
84 TriangleIndices.Count += 6;
85 TriangleIndices.Array[count2] = count;
86 TriangleIndices.Array[count2 + 1] = count + 1;
87 TriangleIndices.Array[count2 + 2] = count + 2;
88 TriangleIndices.Array[count2 + 3] = count + 2;
89 TriangleIndices.Array[count2 + 4] = count + 3;
90 TriangleIndices.Array[count2 + 5] = count;
91 }
92 float num2 = i < text.Length - 1 ? Font.GetKerning(c, text[i + 1]) : 0f;
93 v += right * (glyph.Width - num2 + Font.Spacing.X + spacing.X);
94 }
95 }
96 }
97}
Engine.Vector3 Vector3
readonly DynamicArray< int > TriangleIndices
readonly DynamicArray< VertexPositionColorTexture > TriangleVertices
Vector2 CalculateTextOffset(string text, int start, int count, TextAnchor anchor, Vector2 scale, Vector2 spacing)
static readonly BlendState AlphaBlend
static readonly DepthStencilState Default
void QueueText(string text, Vector3 position, Vector3 right, Vector3 down, Color color, TextAnchor anchor=TextAnchor.Default)
void QueueText(string text, Vector3 position, Vector3 right, Vector3 down, Color color, TextAnchor anchor, Vector2 spacing)
static readonly RasterizerState CullNoneScissor
static BitmapFont DebugFont
static readonly Vector2 Zero
static Vector3 Normalize(Vector3 v)