Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
FlatBatch2D.cs
浏览该文件的文档.
1namespace Engine.Graphics {
2 public class FlatBatch2D : BaseFlatBatch {
8
9 public void QueueBatchTriangles(FlatBatch2D batch, Matrix? matrix = null, Color? color = null) {
10 int count = TriangleVertices.Count;
11 TriangleVertices.AddRange(batch.TriangleVertices);
12 int count2 = TriangleIndices.Count;
13 int count3 = batch.TriangleIndices.Count;
14 TriangleIndices.Count += count3;
15 for (int i = 0; i < count3; i++) {
16 TriangleIndices[i + count2] = batch.TriangleIndices[i] + count;
17 }
18 if (matrix.HasValue
19 && matrix != Matrix.Identity) {
20 TransformTriangles(matrix.Value, count);
21 }
22 if (color.HasValue
23 && color != Color.White) {
24 TransformTrianglesColors(color.Value, count);
25 }
26 }
27
29 public void QueueTriangles(IEnumerable<Vector3> points, Color color) {
30 int count = TriangleVertices.Count;
31 int i = 0;
32 foreach (Vector3 point in points) {
33 TriangleVertices.Add(new VertexPositionColor(point, color));
34 if (++i % 3 == 0) {
35 TriangleIndices.Add(count + i - 3);
36 TriangleIndices.Add(count + i - 2);
37 TriangleIndices.Add(count + i - 1);
38 }
39 }
40 }
41
43 public void QueueTriangles(IEnumerable<VertexPositionColor> vertices) {
44 int count = TriangleVertices.Count;
45 int i = 0;
46 foreach (VertexPositionColor vertex in vertices) {
47 TriangleVertices.Add(vertex);
48 if (++i % 3 == 0) {
49 TriangleIndices.Add(count + i - 3);
50 TriangleIndices.Add(count + i - 2);
51 TriangleIndices.Add(count + i - 1);
52 }
53 }
54 }
55
56 public void QueueBatchLines(FlatBatch2D batch, Matrix? matrix = null, Color? color = null) {
57 int count = LineVertices.Count;
58 LineVertices.AddRange(batch.LineVertices);
59 int count2 = LineIndices.Count;
60 int count3 = batch.LineIndices.Count;
61 LineIndices.Count += count3;
62 for (int i = 0; i < count3; i++) {
63 LineIndices[i + count2] = batch.LineIndices[i] + count;
64 }
65 if (matrix.HasValue
66 && matrix != Matrix.Identity) {
67 TransformLines(matrix.Value, count);
68 }
69 if (color.HasValue
70 && color != Color.White) {
71 TransformLinesColors(color.Value, count);
72 }
73 }
74
76 public void QueueLines(IEnumerable<Vector3> points, Color color) {
77 int count = LineVertices.Count;
78 int i = 0;
79 foreach (Vector3 point in points) {
80 LineVertices.Add(new VertexPositionColor(point, color));
81 if (++i % 2 == 0) {
82 LineIndices.Add(count + i - 2);
83 LineIndices.Add(count + i - 1);
84 }
85 }
86 }
87
88
90 public void QueueLines(IEnumerable<VertexPositionColor> vertices) {
91 int count = LineVertices.Count;
92 int i = 0;
93 foreach (VertexPositionColor vertex in vertices) {
94 LineVertices.Add(vertex);
95 if (++i % 2 == 0) {
96 LineIndices.Add(count + i - 2);
97 LineIndices.Add(count + i - 1);
98 }
99 }
100 }
101
102 public void QueueBatch(FlatBatch2D batch, Matrix? matrix = null, Color? color = null) {
103 QueueBatchLines(batch, matrix, color);
104 QueueBatchTriangles(batch, matrix, color);
105 }
106
107 public void QueueLine(Vector2 p1, Vector2 p2, float depth, Color color) {
108 int count = LineVertices.Count;
109 LineVertices.Add(new VertexPositionColor(new Vector3(p1, depth), color));
110 LineVertices.Add(new VertexPositionColor(new Vector3(p2, depth), color));
111 LineIndices.Add(count);
112 LineIndices.Add(count + 1);
113 }
114
115 public void QueueLineStrip(IEnumerable<Vector2> points, float depth, Color color) {
116 int i = LineVertices.Count;
117 bool notFirst = false;
118 foreach (Vector2 point in points) {
119 LineVertices.Add(new VertexPositionColor(new Vector3(point, depth), color));
120 if (notFirst) {
121 LineIndices.Add(i++);
122 LineIndices.Add(i);
123 }
124 notFirst = true;
125 }
126 }
127
128 public void QueueLineStrip(IEnumerable<VertexPositionColor> vertices) {
129 int i = LineVertices.Count;
130 bool notFirst = false;
131 foreach (VertexPositionColor vertex in vertices) {
132 LineVertices.Add(vertex);
133 if (notFirst) {
134 LineIndices.Add(i++);
135 LineIndices.Add(i);
136 }
137 notFirst = true;
138 }
139 }
140
141 public void QueueRectangle(Vector2 corner1, Vector2 corner2, float depth, Color color) {
142 int count = LineVertices.Count;
143 LineVertices.Add(new VertexPositionColor(new Vector3(corner1.X, corner1.Y, depth), color));
144 LineVertices.Add(new VertexPositionColor(new Vector3(corner1.X, corner2.Y, depth), color));
145 LineVertices.Add(new VertexPositionColor(new Vector3(corner2.X, corner2.Y, depth), color));
146 LineVertices.Add(new VertexPositionColor(new Vector3(corner2.X, corner1.Y, depth), color));
147 LineIndices.Add(count);
148 LineIndices.Add(count + 1);
149 LineIndices.Add(count + 1);
150 LineIndices.Add(count + 2);
151 LineIndices.Add(count + 2);
152 LineIndices.Add(count + 3);
153 LineIndices.Add(count + 3);
154 LineIndices.Add(count);
155 }
156
157 public void QueueEllipse(Vector2 center,
158 Vector2 radius,
159 float depth,
160 Color color,
161 int sides = 32,
162 float startAngle = 0f,
163 float endAngle = (float)Math.PI * 2f) {
164 Vector2 p = Vector2.Zero;
165 for (int i = 0; i <= sides; i++) {
166 float x = MathUtils.Lerp(startAngle, endAngle, i / (float)sides);
167 Vector2 vector = center + radius * new Vector2(MathF.Sin(x), 0f - MathF.Cos(x));
168 if (i > 0) {
169 QueueLine(p, vector, depth, color);
170 }
171 p = vector;
172 }
173 }
174
175 public void QueueDisc(Vector2 center,
176 Vector2 radius,
177 float depth,
178 Color color,
179 int sides = 32,
180 float startAngle = 0f,
181 float endAngle = (float)Math.PI * 2f) {
182 Vector2 p = Vector2.Zero;
183 for (int i = 0; i <= sides; i++) {
184 float x = MathUtils.Lerp(startAngle, endAngle, i / (float)sides);
185 Vector2 vector = center + radius * new Vector2(MathF.Sin(x), 0f - MathF.Cos(x));
186 if (i > 0) {
187 QueueTriangle(p, vector, center, depth, color);
188 }
189 p = vector;
190 }
191 }
192
193 public void QueueDisc(Vector2 center,
194 Vector2 outerRadius,
195 Vector2 innerRadius,
196 float depth,
197 Color outerColor,
198 Color innerColor,
199 int sides = 32,
200 float startAngle = 0f,
201 float endAngle = (float)Math.PI * 2f) {
202 Vector2 p = Vector2.Zero;
203 Vector2 p2 = Vector2.Zero;
204 for (int i = 0; i <= sides; i++) {
205 float x = MathUtils.Lerp(startAngle, endAngle, i / (float)sides);
206 Vector2 v = new(MathF.Sin(x), 0f - MathF.Cos(x));
207 Vector2 vector = center + outerRadius * v;
208 Vector2 vector2 = center + innerRadius * v;
209 if (i > 0) {
211 p,
212 vector,
213 p2,
214 depth,
215 outerColor,
216 outerColor,
217 innerColor
218 );
220 vector,
221 vector2,
222 p2,
223 depth,
224 outerColor,
225 innerColor,
226 innerColor
227 );
228 }
229 p = vector;
230 p2 = vector2;
231 }
232 }
233
234 public void QueueTriangle(Vector2 p1, Vector2 p2, Vector2 p3, float depth, Color color) {
235 int count = TriangleVertices.Count;
236 TriangleVertices.Add(new VertexPositionColor(new Vector3(p1.X, p1.Y, depth), color));
237 TriangleVertices.Add(new VertexPositionColor(new Vector3(p2.X, p2.Y, depth), color));
238 TriangleVertices.Add(new VertexPositionColor(new Vector3(p3.X, p3.Y, depth), color));
239 TriangleIndices.Add(count);
240 TriangleIndices.Add(count + 1);
241 TriangleIndices.Add(count + 2);
242 }
243
244 public void QueueTriangle(Vector2 p1,
245 Vector2 p2,
246 Vector2 p3,
247 float depth,
248 Color color1,
249 Color color2,
250 Color color3) {
251 int count = TriangleVertices.Count;
252 TriangleVertices.Add(new VertexPositionColor(new Vector3(p1.X, p1.Y, depth), color1));
253 TriangleVertices.Add(new VertexPositionColor(new Vector3(p2.X, p2.Y, depth), color2));
254 TriangleVertices.Add(new VertexPositionColor(new Vector3(p3.X, p3.Y, depth), color3));
255 TriangleIndices.Add(count);
256 TriangleIndices.Add(count + 1);
257 TriangleIndices.Add(count + 2);
258 }
259
260 public void QueueQuad(Vector2 corner1, Vector2 corner2, float depth, Color color) {
261 int count = TriangleVertices.Count;
262 TriangleVertices.Add(new VertexPositionColor(new Vector3(corner1.X, corner1.Y, depth), color));
263 TriangleVertices.Add(new VertexPositionColor(new Vector3(corner1.X, corner2.Y, depth), color));
264 TriangleVertices.Add(new VertexPositionColor(new Vector3(corner2.X, corner2.Y, depth), color));
265 TriangleVertices.Add(new VertexPositionColor(new Vector3(corner2.X, corner1.Y, depth), color));
266 TriangleIndices.Add(count);
267 TriangleIndices.Add(count + 1);
268 TriangleIndices.Add(count + 2);
269 TriangleIndices.Add(count + 2);
270 TriangleIndices.Add(count + 3);
271 TriangleIndices.Add(count);
272 }
273
274 public void QueueQuad(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float depth, Color color) {
275 int count = TriangleVertices.Count;
276 TriangleVertices.Count += 4;
277 TriangleVertices.Array[count] = new VertexPositionColor(new Vector3(p1.X, p1.Y, depth), color);
278 TriangleVertices.Array[count + 1] = new VertexPositionColor(new Vector3(p2.X, p2.Y, depth), color);
279 TriangleVertices.Array[count + 2] = new VertexPositionColor(new Vector3(p3.X, p3.Y, depth), color);
280 TriangleVertices.Array[count + 3] = new VertexPositionColor(new Vector3(p4.X, p4.Y, depth), color);
281 int count2 = TriangleIndices.Count;
282 TriangleIndices.Count += 6;
283 TriangleIndices.Array[count2] = count;
284 TriangleIndices.Array[count2 + 1] = count + 1;
285 TriangleIndices.Array[count2 + 2] = count + 2;
286 TriangleIndices.Array[count2 + 3] = count + 2;
287 TriangleIndices.Array[count2 + 4] = count + 3;
288 TriangleIndices.Array[count2 + 5] = count;
289 }
290
291 public void QueueQuad(Vector2 p1,
292 Vector2 p2,
293 Vector2 p3,
294 Vector2 p4,
295 float depth,
296 Color color1,
297 Color color2,
298 Color color3,
299 Color color4) {
300 int count = TriangleVertices.Count;
301 TriangleVertices.Count += 4;
302 TriangleVertices.Array[count] = new VertexPositionColor(new Vector3(p1.X, p1.Y, depth), color1);
303 TriangleVertices.Array[count + 1] = new VertexPositionColor(new Vector3(p2.X, p2.Y, depth), color2);
304 TriangleVertices.Array[count + 2] = new VertexPositionColor(new Vector3(p3.X, p3.Y, depth), color3);
305 TriangleVertices.Array[count + 3] = new VertexPositionColor(new Vector3(p4.X, p4.Y, depth), color4);
306 int count2 = TriangleIndices.Count;
307 TriangleIndices.Count += 6;
308 TriangleIndices.Array[count2] = count;
309 TriangleIndices.Array[count2 + 1] = count + 1;
310 TriangleIndices.Array[count2 + 2] = count + 2;
311 TriangleIndices.Array[count2 + 3] = count + 2;
312 TriangleIndices.Array[count2 + 4] = count + 3;
313 TriangleIndices.Array[count2 + 5] = count;
314 }
315
316 public void Flush(bool clearAfterFlush = true) {
317 Flush(PrimitivesRenderer2D.ViewportMatrix(), clearAfterFlush);
318 }
319 }
320}
Engine.Vector3 Vector3
readonly DynamicArray< int > LineIndices
readonly DynamicArray< int > TriangleIndices
void TransformLines(Matrix matrix, int start=0, int end=-1)
readonly DynamicArray< VertexPositionColor > TriangleVertices
void TransformTrianglesColors(Color color, int start=0, int end=-1)
void TransformLinesColors(Color color, int start=0, int end=-1)
readonly DynamicArray< VertexPositionColor > LineVertices
void TransformTriangles(Matrix matrix, int start=0, int end=-1)
static readonly BlendState AlphaBlend
static readonly DepthStencilState None
void QueueQuad(Vector2 corner1, Vector2 corner2, float depth, Color color)
void QueueQuad(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float depth, Color color1, Color color2, Color color3, Color color4)
void QueueDisc(Vector2 center, Vector2 outerRadius, Vector2 innerRadius, float depth, Color outerColor, Color innerColor, int sides=32, float startAngle=0f, float endAngle=(float) Math.PI *2f)
void QueueQuad(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float depth, Color color)
void QueueEllipse(Vector2 center, Vector2 radius, float depth, Color color, int sides=32, float startAngle=0f, float endAngle=(float) Math.PI *2f)
void QueueLine(Vector2 p1, Vector2 p2, float depth, Color color)
void QueueBatchTriangles(FlatBatch2D batch, Matrix? matrix=null, Color? color=null)
void Flush(bool clearAfterFlush=true)
void QueueBatchLines(FlatBatch2D batch, Matrix? matrix=null, Color? color=null)
void QueueTriangle(Vector2 p1, Vector2 p2, Vector2 p3, float depth, Color color)
void QueueDisc(Vector2 center, Vector2 radius, float depth, Color color, int sides=32, float startAngle=0f, float endAngle=(float) Math.PI *2f)
void QueueTriangles(IEnumerable< VertexPositionColor > vertices)
每三个顶点为一个三角形,请确保输入的顶点数量为 3 的倍数
void QueueLineStrip(IEnumerable< VertexPositionColor > vertices)
void QueueLineStrip(IEnumerable< Vector2 > points, float depth, Color color)
void QueueTriangle(Vector2 p1, Vector2 p2, Vector2 p3, float depth, Color color1, Color color2, Color color3)
void QueueLines(IEnumerable< Vector3 > points, Color color)
每两个顶点为一个线段,请确保输入的顶点数量为 2 的倍数
void QueueLines(IEnumerable< VertexPositionColor > vertices)
每两个顶点为一个线段,请确保输入的顶点数量为 2 的倍数
void QueueTriangles(IEnumerable< Vector3 > points, Color color)
每三个顶点为一个三角形,请确保输入的顶点数量为 3 的倍数
void QueueRectangle(Vector2 corner1, Vector2 corner2, float depth, Color color)
void QueueBatch(FlatBatch2D batch, Matrix? matrix=null, Color? color=null)
static readonly RasterizerState CullNoneScissor
static float Lerp(float x1, float x2, float f)
static Color White
static readonly Matrix Identity
static readonly Vector2 Zero