comparison examples/alotof_triangles.nim @ 518:5d406c17bbcb

did: refactor Vector names
author Sam <sam@basx.dev>
date Fri, 20 Jan 2023 16:13:32 +0700
parents 836790efab48
children 8287a91e5d56
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 Uniforms = object 13 Uniforms = object
14 dt: Descriptor[float32] 14 dt: Descriptor[float32]
15 15
16 proc globalUpdate(engine: var Engine, dt: float32) = 16 proc globalUpdate(engine: var Engine, dt: float32) =
17 discard 17 discard
24 24
25 when isMainModule: 25 when isMainModule:
26 randomize() 26 randomize()
27 var myengine = igniteEngine("A lot of triangles") 27 var myengine = igniteEngine("A lot of triangles")
28 const baseTriangle = [ 28 const baseTriangle = [
29 Vec3([-0.1'f32, -0.1'f32, 1'f32]), 29 TVec3([-0.1'f32, -0.1'f32, 1'f32]),
30 Vec3([ 0.1'f32, 0.1'f32, 1'f32]), 30 TVec3([ 0.1'f32, 0.1'f32, 1'f32]),
31 Vec3([-0.1'f32, 0.1'f32, 1'f32]), 31 TVec3([-0.1'f32, 0.1'f32, 1'f32]),
32 ] 32 ]
33 33
34 var scene = new Thing 34 var scene = new Thing
35 35
36 for i in 1 .. 300: 36 for i in 1 .. 300:
37 var randommesh = new Mesh[VertexDataA] 37 var randommesh = new Mesh[VertexDataA]
38 let randomcolor1 = Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]) 38 let randomcolor1 = TVec3([float32(rand(1)), float32(rand(1)), float32(rand(1))])
39 let transform1 = randomtransform() 39 let transform1 = randomtransform()
40 randommesh.vertexData = VertexDataA( 40 randommesh.vertexData = VertexDataA(
41 position11: PositionAttribute[Vec2[float32]]( 41 position11: PositionAttribute[TVec2[float32]](
42 data: @[ 42 data: @[
43 Vec2[float32](transform1 * baseTriangle[0]), 43 TVec2[float32](transform1 * baseTriangle[0]),
44 Vec2[float32](transform1 * baseTriangle[1]), 44 TVec2[float32](transform1 * baseTriangle[1]),
45 Vec2[float32](transform1 * baseTriangle[2]), 45 TVec2[float32](transform1 * baseTriangle[2]),
46 ] 46 ]
47 ), 47 ),
48 color22: ColorAttribute[Vec3[float32]]( 48 color22: ColorAttribute[TVec3[float32]](
49 data: @[randomcolor1, randomcolor1, randomcolor1] 49 data: @[randomcolor1, randomcolor1, randomcolor1]
50 ) 50 )
51 ) 51 )
52 52
53 let randomcolor2 = Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]) 53 let randomcolor2 = TVec3([float32(rand(1)), float32(rand(1)), float32(rand(1))])
54 let transform2 = randomtransform() 54 let transform2 = randomtransform()
55 var randomindexedmesh = new IndexedMesh[VertexDataA, uint16] 55 var randomindexedmesh = new IndexedMesh[VertexDataA, uint16]
56 randomindexedmesh.vertexData = VertexDataA( 56 randomindexedmesh.vertexData = VertexDataA(
57 position11: PositionAttribute[Vec2[float32]]( 57 position11: PositionAttribute[TVec2[float32]](
58 data: @[ 58 data: @[
59 Vec2[float32](transform2 * baseTriangle[0]), 59 TVec2[float32](transform2 * baseTriangle[0]),
60 Vec2[float32](transform2 * baseTriangle[1]), 60 TVec2[float32](transform2 * baseTriangle[1]),
61 Vec2[float32](transform2 * baseTriangle[2]), 61 TVec2[float32](transform2 * baseTriangle[2]),
62 ] 62 ]
63 ), 63 ),
64 color22: ColorAttribute[Vec3[float32]]( 64 color22: ColorAttribute[TVec3[float32]](
65 data: @[randomcolor2, randomcolor2, randomcolor2] 65 data: @[randomcolor2, randomcolor2, randomcolor2]
66 ) 66 )
67 ) 67 )
68 randomindexedmesh.indices = @[[0'u16, 1'u16, 2'u16]] 68 randomindexedmesh.indices = @[[0'u16, 1'u16, 2'u16]]
69 var childthing = new Thing 69 var childthing = new Thing