Mercurial > games > semicongine
changeset 75:a7f950307d2d
add: circle mesh
author | Sam <sam@basx.dev> |
---|---|
date | Mon, 06 Feb 2023 23:33:10 +0700 |
parents | 779607656b12 |
children | e5be7a25634e |
files | src/semicongine/mesh.nim |
diffstat | 1 files changed, 17 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/semicongine/mesh.nim Mon Feb 06 23:32:59 2023 +0700 +++ b/src/semicongine/mesh.nim Mon Feb 06 23:33:10 2023 +0700 @@ -1,3 +1,4 @@ +import std/math import std/options import std/typetraits @@ -123,3 +124,19 @@ VecType([T(-0.5), T(+0.5), T(0)]), ] value.useOnDeviceMemory = true + +func circle*[VertexType, VecType, T](n = 16): Mesh[VertexType, uint16] = + result = new Mesh[VertexType, uint16] + result.indexed = true + let angleStep = (2'f * PI) / float32(n) + var data = @[VecType([T(0), T(0), T(0)])] + for i in 1 .. n: + data.add VecType([T(cos(float32(i) * angleStep)), T(sin(float32(i) * + angleStep)), T(0)]) + result.indices.add [0'u16, uint16(i), uint16(i mod (n) + 1)] + + result.vertexData = VertexType() + for attrname, value in result.vertexData.fieldPairs: + when typeof(value) is PositionAttribute: + value.data = data + value.useOnDeviceMemory = true