Mercurial > games > semicongine
comparison examples/squares.nim @ 518:5d406c17bbcb
did: refactor Vector names
author | Sam <sam@basx.dev> |
---|---|
date | Fri, 20 Jan 2023 16:13:32 +0700 |
parents | 836790efab48 |
children | d7d9420ba675 |
comparison
equal
deleted
inserted
replaced
517:836790efab48 | 518:5d406c17bbcb |
---|---|
6 | 6 |
7 import semicongine | 7 import semicongine |
8 | 8 |
9 type | 9 type |
10 VertexDataA = object | 10 VertexDataA = object |
11 position11: PositionAttribute[Vec2[float32]] | 11 position11: PositionAttribute[TVec2[float32]] |
12 color22: ColorAttribute[Vec3[float32]] | 12 color22: ColorAttribute[TVec3[float32]] |
13 index: GenericAttribute[uint32] | 13 index: GenericAttribute[uint32] |
14 Uniforms = object | 14 Uniforms = object |
15 t: Descriptor[float32] | 15 t: Descriptor[float32] |
16 | 16 |
17 var | 17 var |
30 COLUMNS = 10 | 30 COLUMNS = 10 |
31 ROWS = 10 | 31 ROWS = 10 |
32 WIDTH = 2'f32 / COLUMNS | 32 WIDTH = 2'f32 / COLUMNS |
33 HEIGHT = 2'f32 / ROWS | 33 HEIGHT = 2'f32 / ROWS |
34 var | 34 var |
35 vertices: array[COLUMNS * ROWS * 4, Vec2[float32]] | 35 vertices: array[COLUMNS * ROWS * 4, TVec2[float32]] |
36 colors: array[COLUMNS * ROWS * 4, Vec3[float32]] | 36 colors: array[COLUMNS * ROWS * 4, TVec3[float32]] |
37 iValues: array[COLUMNS * ROWS * 4, uint32] | 37 iValues: array[COLUMNS * ROWS * 4, uint32] |
38 indices: array[COLUMNS * ROWS * 2, array[3, uint16]] | 38 indices: array[COLUMNS * ROWS * 2, array[3, uint16]] |
39 | 39 |
40 for row in 0 ..< ROWS: | 40 for row in 0 ..< ROWS: |
41 for col in 0 ..< COLUMNS: | 41 for col in 0 ..< COLUMNS: |
42 let | 42 let |
43 y: float32 = (row * 2 / COLUMNS) - 1 | 43 y: float32 = (row * 2 / COLUMNS) - 1 |
44 x: float32 = (col * 2 / ROWS) - 1 | 44 x: float32 = (col * 2 / ROWS) - 1 |
45 color = Vec3[float32]([(x + 1) / 2, (y + 1) / 2, 0'f32]) | 45 color = TVec3[float32]([(x + 1) / 2, (y + 1) / 2, 0'f32]) |
46 squareIndex = row * COLUMNS + col | 46 squareIndex = row * COLUMNS + col |
47 vertIndex = squareIndex * 4 | 47 vertIndex = squareIndex * 4 |
48 vertices[vertIndex + 0] = Vec2[float32]([x, y]) | 48 vertices[vertIndex + 0] = TVec2[float32]([x, y]) |
49 vertices[vertIndex + 1] = Vec2[float32]([x + WIDTH, y]) | 49 vertices[vertIndex + 1] = TVec2[float32]([x + WIDTH, y]) |
50 vertices[vertIndex + 2] = Vec2[float32]([x + WIDTH, y + HEIGHT]) | 50 vertices[vertIndex + 2] = TVec2[float32]([x + WIDTH, y + HEIGHT]) |
51 vertices[vertIndex + 3] = Vec2[float32]([x, y + HEIGHT]) | 51 vertices[vertIndex + 3] = TVec2[float32]([x, y + HEIGHT]) |
52 colors[vertIndex + 0] = color | 52 colors[vertIndex + 0] = color |
53 colors[vertIndex + 1] = color | 53 colors[vertIndex + 1] = color |
54 colors[vertIndex + 2] = color | 54 colors[vertIndex + 2] = color |
55 colors[vertIndex + 3] = color | 55 colors[vertIndex + 3] = color |
56 iValues[vertIndex + 0] = uint32(squareIndex) | 56 iValues[vertIndex + 0] = uint32(squareIndex) |
62 | 62 |
63 | 63 |
64 type PIndexedMesh = ref IndexedMesh[VertexDataA, uint16] # required so we can use ctor with ref/on heap | 64 type PIndexedMesh = ref IndexedMesh[VertexDataA, uint16] # required so we can use ctor with ref/on heap |
65 var squaremesh = PIndexedMesh( | 65 var squaremesh = PIndexedMesh( |
66 vertexData: VertexDataA( | 66 vertexData: VertexDataA( |
67 position11: PositionAttribute[Vec2[float32]](data: @vertices), | 67 position11: PositionAttribute[TVec2[float32]](data: @vertices), |
68 color22: ColorAttribute[Vec3[float32]](data: @colors), | 68 color22: ColorAttribute[TVec3[float32]](data: @colors), |
69 index: GenericAttribute[uint32](data: @iValues), | 69 index: GenericAttribute[uint32](data: @iValues), |
70 ), | 70 ), |
71 indices: @indices | 71 indices: @indices |
72 ) | 72 ) |
73 var scene = new Thing | 73 var scene = new Thing |