19 float latitudeStep = (float)Math.PI / stacks;
20 float longitudeStep = 2.0f * (float)Math.PI / slices;
21 for (
int lat = 0; lat <= stacks; lat++) {
22 float a1 = (float)(-Math.PI / 2 + lat * latitudeStep);
23 float a2 = (float)(-Math.PI / 2 + (lat + 1) * latitudeStep);
24 for (
int lon = 0; lon <= slices; lon++) {
25 float b1 = lon * longitudeStep;
26 float b2 = (lon + 1) * longitudeStep;
31 (
float)(Math.Sin(a1) * Math.Cos(b1)) * radius,
32 (
float)Math.Cos(a1) * radius,
33 (
float)(Math.Sin(a1) * Math.Sin(b1)) * radius
37 (
float)(Math.Sin(a2) * Math.Cos(b1)) * radius,
38 (
float)Math.Cos(a2) * radius,
39 (
float)(Math.Sin(a2) * Math.Sin(b1)) * radius
43 (
float)(Math.Sin(a1) * Math.Cos(b2)) * radius,
44 (
float)Math.Cos(a1) * radius,
45 (
float)(Math.Sin(a1) * Math.Sin(b2)) * radius
49 (
float)(Math.Sin(a2) * Math.Cos(b2)) * radius,
50 (
float)Math.Cos(a2) * radius,
51 (
float)(Math.Sin(a2) * Math.Sin(b2)) * radius
57 (
float)(Math.Sin(-a1) * Math.Cos(b1)) * radius,
58 (
float)Math.Cos(-a1) * radius,
59 (
float)(Math.Sin(-a1) * Math.Sin(b1)) * radius
63 (
float)(Math.Sin(-a1) * Math.Cos(b2)) * radius,
64 (
float)Math.Cos(-a1) * radius,
65 (
float)(Math.Sin(-a1) * Math.Sin(b2)) * radius
69 (
float)(Math.Sin(-a2) * Math.Cos(b2)) * radius,
70 (
float)Math.Cos(-a2) * radius,
71 (
float)(Math.Sin(-a2) * Math.Sin(b2)) * radius
75 (
float)(Math.Sin(-a2) * Math.Cos(b1)) * radius,
76 (
float)Math.Cos(-a2) * radius,
77 (
float)(Math.Sin(-a2) * Math.Sin(b1)) * radius
102 int longitudeLines = 20,
103 int latitudeLines = 20,
105 if (longitudeLines < 3) {
108 if (latitudeLines < 2) {
114 for (
int lat = 0; lat <= latitudeLines; lat++) {
115 float angle = (float)(Math.PI / 2 - lat * Math.PI / latitudeLines);
116 float radiusAtLatitude = radius * (float)Math.Cos(angle);
117 Vector3 offset =
new(0, (float)(Math.Sin(angle) * radius), 0);
118 QueueCircle(center + offset, radiusAtLatitude, longitudeLines, color);
124 for (
int lon = 0; lon < longitudeLines; lon++)
126 float longitudeAngle = lon * 2 * (float)Math.PI / longitudeLines;
127 List<Vector3> points =
new();
128 for (
int lat = 0; lat <= latitudeLines; lat++) {
129 float latitudeAngle = (float)(Math.PI / 2 - lat * Math.PI / latitudeLines);
133 (
float)(Math.Cos(latitudeAngle) * Math.Cos(longitudeAngle)) * radius,
134 (
float)Math.Sin(latitudeAngle) * radius,
135 (
float)(Math.Cos(latitudeAngle) * Math.Sin(longitudeAngle)) * radius
152 float step = (float)(2 * Math.PI) / segments;
153 List<Vector3> points =
new();
154 for (
int i = 0; i <= segments; i++) {
155 float angle = step * i;
156 Vector3 point = center +
new Vector3((
float)Math.Cos(angle) * radius, 0, (
float)Math.Sin(angle) * radius);
163 for (
int i = 0; i < points.Count - 1; i++) {
164 QueueLine(points[i], points[i + 1], color);
180 Vector3 baseCenter = start + direction * (height / 2);
183 for (
int i = 0; i < segments; i++) {
184 float angle1 = (float)(2 * Math.PI * i / segments);
185 float angle2 = (float)(2 * Math.PI * (i + 1) / segments);
186 Vector3 point1 = baseCenter +
new Vector3(radius * MathF.Cos(angle1), -height / 2, radius * MathF.Sin(angle1));
187 Vector3 point2 = baseCenter +
new Vector3(radius * MathF.Cos(angle2), -height / 2, radius * MathF.Sin(angle2));
188 Vector3 point3 = baseCenter +
new Vector3(radius * MathF.Cos(angle1), height / 2, radius * MathF.Sin(angle1));
189 Vector3 point4 = baseCenter +
new Vector3(radius * MathF.Cos(angle2), height / 2, radius * MathF.Sin(angle2));
195 if (drawTopAndBottom) {
207 TriangleIndices.Count += count3;
208 for (
int i = 0; i < count3; i++) {
225 foreach (
Vector3 point
in points) {
254 LineIndices.Count += count3;
255 for (
int i = 0; i < count3; i++) {
272 foreach (
Vector3 point
in points) {
283 public void QueueLines(IEnumerable<VertexPositionColor> vertices) {
318 bool notFirst =
false;
319 foreach (
Vector3 point
in points) {
331 bool notFirst =
false;
464 ReadOnlyList<Vector3> array = boundingFrustum.
Corners;
480 float halfSize = size / 2f;
482 new Vector3(center.
X - halfSize, center.
Y - halfSize, center.
Z - halfSize),
483 new Vector3(center.
X + halfSize, center.
Y - halfSize, center.
Z - halfSize),
484 new Vector3(center.
X + halfSize, center.
Y + halfSize, center.
Z - halfSize),
485 new Vector3(center.
X - halfSize, center.
Y + halfSize, center.
Z - halfSize),
489 new Vector3(center.
X - halfSize, center.
Y - halfSize, center.
Z + halfSize),
490 new Vector3(center.
X + halfSize, center.
Y - halfSize, center.
Z + halfSize),
491 new Vector3(center.
X + halfSize, center.
Y + halfSize, center.
Z + halfSize),
492 new Vector3(center.
X - halfSize, center.
Y + halfSize, center.
Z + halfSize),
496 new Vector3(center.
X - halfSize, center.
Y - halfSize, center.
Z - halfSize),
497 new Vector3(center.
X - halfSize, center.
Y - halfSize, center.
Z + halfSize),
498 new Vector3(center.
X - halfSize, center.
Y + halfSize, center.
Z + halfSize),
499 new Vector3(center.
X - halfSize, center.
Y + halfSize, center.
Z - halfSize),
503 new Vector3(center.
X + halfSize, center.
Y - halfSize, center.
Z - halfSize),
504 new Vector3(center.
X + halfSize, center.
Y - halfSize, center.
Z + halfSize),
505 new Vector3(center.
X + halfSize, center.
Y + halfSize, center.
Z + halfSize),
506 new Vector3(center.
X + halfSize, center.
Y + halfSize, center.
Z - halfSize),
510 new Vector3(center.
X - halfSize, center.
Y - halfSize, center.
Z - halfSize),
511 new Vector3(center.
X + halfSize, center.
Y - halfSize, center.
Z - halfSize),
512 new Vector3(center.
X + halfSize, center.
Y - halfSize, center.
Z + halfSize),
513 new Vector3(center.
X - halfSize, center.
Y - halfSize, center.
Z + halfSize),
517 new Vector3(center.
X - halfSize, center.
Y + halfSize, center.
Z - halfSize),
518 new Vector3(center.
X + halfSize, center.
Y + halfSize, center.
Z - halfSize),
519 new Vector3(center.
X + halfSize, center.
Y + halfSize, center.
Z + halfSize),
520 new Vector3(center.
X - halfSize, center.
Y + halfSize, center.
Z + halfSize),
ReadOnlyList< Vector3 > Corners
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 Default
void QueueLines(IEnumerable< Vector3 > points, Color color)
每两个顶点为一个线段,请确保输入的顶点数量为 2 的倍数
void QueueBoundingBox(BoundingBox boundingBox, Color color)
void QueueBatch(FlatBatch3D batch, Matrix? matrix=null, Color? color=null)
void QueueLineStrip(IEnumerable< Vector3 > points, Color color)
void QueueLines(IEnumerable< VertexPositionColor > vertices)
每两个顶点为一个线段,请确保输入的顶点数量为 2 的倍数
void QueueCurvedCylinder(Vector3 start, Vector3 end, float radius, Color color, int segments=12, bool drawTopAndBottom=true)
绘制圆柱
void QueueSphere(Vector3 center, float radius, int slices, int stacks, Color color)
绘制球
void QueueBatchTriangles(FlatBatch3D batch, Matrix? matrix=null, Color? color=null)
void QueueBatchLines(FlatBatch3D batch, Matrix? matrix=null, Color? color=null)
void QueueTriangles(IEnumerable< VertexPositionColor > vertices)
每三个顶点为一个三角形,请确保输入的顶点数量为 3 的倍数
void QueueCircle(Vector3 center, float radius, int segments, Color color, bool useLineStrip=true)
绘制圆
void QueueQuad(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Color color)
void QueueLine(Vector3 p1, Vector3 p2, Color color)
void QueueLine(Vector3 p1, Vector3 p2, Color color1, Color color2)
void QueueLineStrip(IEnumerable< VertexPositionColor > vertices)
void QueueCube(Vector3 center, float size, Color color)
void QueueQuad(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Color color1, Color color2, Color color3, Color color4)
绘制矩形(支持渐变)
void QueueBoundingFrustum(BoundingFrustum boundingFrustum, Color color)
void QueueTriangle(Vector3 p1, Vector3 p2, Vector3 p3, Color color)
void QueueTriangle(Vector3 p1, Vector3 p2, Vector3 p3, Color color1, Color color2, Color color3)
void QueueTriangles(IEnumerable< Vector3 > points, Color color)
每三个顶点为一个三角形,请确保输入的顶点数量为 3 的倍数
void QueueSphereWithLines(Vector3 center, Color color, float radius=1, int longitudeLines=20, int latitudeLines=20, int draw=0)
绘制球线框
static readonly RasterizerState CullNoneScissor
static readonly Matrix Identity
static Vector3 Normalize(Vector3 v)
static float Distance(Vector3 v1, Vector3 v2)