Mercurial > games > semicongine
annotate examples/alotof_triangles.nim @ 22:b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
author | Sam <sam@basx.dev> |
---|---|
date | Wed, 11 Jan 2023 00:43:17 +0700 |
parents | 316923e9247c |
children | b1b05d4efb52 |
rev | line source |
---|---|
22
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
1 import std/math |
21 | 2 import std/random |
3 | |
4 import zamikongine/engine | |
5 import zamikongine/math/vector | |
6 import zamikongine/math/matrix | |
7 import zamikongine/vertex | |
8 import zamikongine/mesh | |
9 import zamikongine/thing | |
10 import zamikongine/shader | |
11 | |
12 type | |
13 VertexDataA = object | |
14 position11: VertexAttribute[Vec2[float32]] | |
15 color22: VertexAttribute[Vec3[float32]] | |
16 | |
22
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
17 proc randomtransform(): Mat33[float32] = |
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
18 let randomscale = scale2d(float32(rand(1.0) + 0.5), float32(rand(1.0) + 0.5)) |
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
19 let randomrotate = rotate2d(float32(rand(2 * PI))) |
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
20 let randomtranslate = translate2d(float32(rand(1.6) - 0.8), float32(rand(1.6) - 0.8)) |
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
21 result = randomtranslate * randomrotate * randomscale |
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
22 |
21 | 23 when isMainModule: |
24 randomize() | |
25 var myengine = igniteEngine() | |
26 const baseTriangle = [ | |
22
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
27 Vec3([-0.1'f32, -0.1'f32, 1'f32]), |
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
28 Vec3([ 0.1'f32, 0.1'f32, 1'f32]), |
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
29 Vec3([-0.1'f32, 0.1'f32, 1'f32]), |
21 | 30 ] |
31 | |
32 var scene = new Thing | |
33 | |
34 for i in 1 .. 300: | |
35 var randommesh = new Mesh[VertexDataA] | |
36 # TODO: create randomized position11 from baseTriangle with random transformation matrix | |
22
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
37 let transform1 = randomtransform() |
21 | 38 randommesh.vertexData = VertexDataA( |
39 position11: VertexAttribute[Vec2[float32]]( | |
40 data: @[ | |
22
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
41 Vec2[float32](transform1 * baseTriangle[0]), |
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
42 Vec2[float32](transform1 * baseTriangle[1]), |
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
43 Vec2[float32](transform1 * baseTriangle[2]), |
21 | 44 ] |
45 ), | |
46 color22: VertexAttribute[Vec3[float32]]( | |
47 data: @[ | |
48 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]), | |
49 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]), | |
50 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]), | |
51 ] | |
52 ) | |
53 ) | |
54 | |
22
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
55 let transform2 = randomtransform() |
21 | 56 var randomindexedmesh = new IndexedMesh[VertexDataA, uint16] |
57 randomindexedmesh.vertexData = VertexDataA( | |
58 position11: VertexAttribute[Vec2[float32]]( | |
59 data: @[ | |
22
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
60 Vec2[float32](transform2 * baseTriangle[0]), |
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
61 Vec2[float32](transform2 * baseTriangle[1]), |
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
62 Vec2[float32](transform2 * baseTriangle[2]), |
21 | 63 ] |
64 ), | |
65 color22: VertexAttribute[Vec3[float32]]( | |
66 data: @[ | |
67 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]), | |
68 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]), | |
69 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]), | |
70 ] | |
71 ) | |
72 ) | |
22
b45a5d338cd0
did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
Sam <sam@basx.dev>
parents:
21
diff
changeset
|
73 randomindexedmesh.indices = @[[0'u16, 1'u16, 2'u16]] |
21 | 74 var childthing = new Thing |
75 childthing.parts.add randommesh | |
76 childthing.parts.add randomindexedmesh | |
77 scene.children.add childthing | |
78 | |
79 setupPipeline[VertexDataA, uint16]( | |
80 myengine, | |
81 scene, | |
82 generateVertexShaderCode[VertexDataA]("main", "position11", "color22"), | |
83 generateFragmentShaderCode[VertexDataA]("main"), | |
84 ) | |
85 myengine.fullThrottle() | |
86 myengine.trash() |