changeset 1003:2f92d7e80597

add: temporary helper function, maybe need to do this better anyways
author sam <sam@basx.dev>
date Sun, 14 Apr 2024 00:34:04 +0700
parents 892aa207a5b0
children e7a53442eab8
files semicongine/mesh.nim
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/semicongine/mesh.nim	Sat Apr 13 21:31:40 2024 +0700
+++ b/semicongine/mesh.nim	Sun Apr 14 00:34:04 2024 +0700
@@ -515,6 +515,20 @@
   result[].initVertexAttribute("uv", uv)
   `material=`(result[], material)
 
+proc circleMesh*(width = 1'f32, height = 1'f32, nSegments = 12): (seq[Vec3f], seq[array[3, uint16]]) =
+  assert nSegments >= 3
+  result[0] = newSeq[Vec3f](3 + nSegments)
+
+  let
+    rX = width / 2
+    rY = height / 2
+    step = (2'f32 * PI) / float32(nSegments)
+  result[0][0] = newVec3f(0, 0)
+  result[0][1] = newVec3f(rX, 0)
+  for i in 1 .. nSegments:
+    result[0][i + 1] = newVec3f(cos(float32(i) * step) * rX, sin(float32(i) * step) * rY)
+    result[1].add [uint16(0), uint16(i), uint16(i + 1)]
+
 proc grid*(columns, rows: uint16, cellSize = 1.0'f32, color = "ffffffff", material = EMPTY_MATERIAL.initMaterialData()): Mesh =
 
   result = Mesh(