comparison examples/alotof_triangles.nim @ 21:316923e9247c

add: clean examples, update build configs
author Sam <sam@basx.dev>
date Tue, 10 Jan 2023 00:24:37 +0700
parents
children b45a5d338cd0
comparison
equal deleted inserted replaced
20:beb86492b178 21:316923e9247c
1 import std/random
2
3 import zamikongine/engine
4 import zamikongine/math/vector
5 import zamikongine/math/matrix
6 import zamikongine/vertex
7 import zamikongine/mesh
8 import zamikongine/thing
9 import zamikongine/shader
10
11 type
12 VertexDataA = object
13 position11: VertexAttribute[Vec2[float32]]
14 color22: VertexAttribute[Vec3[float32]]
15
16 when isMainModule:
17 randomize()
18 var myengine = igniteEngine()
19 const baseTriangle = [
20 Vec3([-0.3'f32, -0.3'f32, 1'f32]),
21 Vec3([ 0.3'f32, 0.3'f32, 1'f32]),
22 Vec3([-0.3'f32, 0.3'f32, 1'f32]),
23 ]
24
25 var scene = new Thing
26
27 for i in 1 .. 300:
28 var randommesh = new Mesh[VertexDataA]
29 # TODO: create randomized position11 from baseTriangle with random transformation matrix
30 var transform = (Mat33[float32]().randomized() * 2'f32) - 1'f32
31 randommesh.vertexData = VertexDataA(
32 position11: VertexAttribute[Vec2[float32]](
33 data: @[
34 Vec2[float32](transform * baseTriangle[0]),
35 Vec2[float32](transform * baseTriangle[1]),
36 Vec2[float32](transform * baseTriangle[2]),
37 ]
38 ),
39 color22: VertexAttribute[Vec3[float32]](
40 data: @[
41 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]),
42 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]),
43 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]),
44 ]
45 )
46 )
47
48 var randomindexedmesh = new IndexedMesh[VertexDataA, uint16]
49 randomindexedmesh.vertexData = VertexDataA(
50 position11: VertexAttribute[Vec2[float32]](
51 data: @[
52 Vec2[float32](transform * baseTriangle[0]),
53 Vec2[float32](transform * baseTriangle[1]),
54 Vec2[float32](transform * baseTriangle[2]),
55 ]
56 ),
57 color22: VertexAttribute[Vec3[float32]](
58 data: @[
59 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]),
60 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]),
61 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]),
62 ]
63 )
64 )
65 randomindexedmesh.indices = @[[0'u16, 1'u16, 2'u16], [0'u16, 2'u16, 1'u16]]
66 var childthing = new Thing
67 childthing.parts.add randommesh
68 childthing.parts.add randomindexedmesh
69 scene.children.add childthing
70
71 setupPipeline[VertexDataA, uint16](
72 myengine,
73 scene,
74 generateVertexShaderCode[VertexDataA]("main", "position11", "color22"),
75 generateFragmentShaderCode[VertexDataA]("main"),
76 )
77 myengine.fullThrottle()
78 myengine.trash()